From 45dd0019c146aae1450e2f79d04ade57055859ca Mon Sep 17 00:00:00 2001 From: lihbr Date: Wed, 11 Sep 2024 22:52:47 +0200 Subject: [PATCH 01/13] refactor: use classes to detect migration field --- src/Client.ts | 2 +- src/Migration.ts | 213 +-- src/WriteClient.ts | 129 +- src/index.ts | 21 +- src/lib/isMigrationField.ts | 180 --- src/lib/isValue.ts | 215 +++ src/lib/patchMigrationDocumentData.ts | 447 ------ src/lib/prepareMigrationRecord.ts | 120 ++ src/lib/toField.ts | 106 -- src/types/migration/ContentRelationship.ts | 55 + src/types/migration/Field.ts | 48 + src/types/migration/asset.ts | 189 ++- src/types/migration/document.ts | 210 ++- src/types/migration/fields.ts | 57 - src/types/migration/richText.ts | 19 - ...te-patch-contentRelationship.test.ts.snap} | 723 +--------- ...iteClient-migrate-patch-image.test.ts.snap | 944 ++++--------- ...ent-migrate-patch-linkToMedia.test.ts.snap | 245 ++-- ...ent-migrate-patch-rtImageNode.test.ts.snap | 1253 +++++++++++++++++ test/__testutils__/mockPrismicAssetAPI.ts | 4 +- .../testMigrationFieldPatching.ts | 12 +- test/migration-createDocument.test.ts | 27 +- test/migration-getByUID.test.ts | 4 +- test/migration-getSingle.test.ts | 4 +- test/types/migration-document.types.ts | 44 +- test/types/migration.types.ts | 81 +- test/writeClient-migrate-documents.test.ts | 111 +- ...migrate-patch-contentRelationship.test.ts} | 39 +- test/writeClient-migrate-patch-image.test.ts | 34 +- ...teClient-migrate-patch-linkToMedia.test.ts | 17 +- ...teClient-migrate-patch-rtImageNode.test.ts | 43 + test/writeClient-migrate.test.ts | 6 +- 32 files changed, 2845 insertions(+), 2757 deletions(-) delete mode 100644 src/lib/isMigrationField.ts create mode 100644 src/lib/isValue.ts delete mode 100644 src/lib/patchMigrationDocumentData.ts create mode 100644 src/lib/prepareMigrationRecord.ts delete mode 100644 src/lib/toField.ts create mode 100644 src/types/migration/ContentRelationship.ts create mode 100644 src/types/migration/Field.ts delete mode 100644 src/types/migration/fields.ts delete mode 100644 src/types/migration/richText.ts rename test/__snapshots__/{writeClient-migrate-patch-link.test.ts.snap => writeClient-migrate-patch-contentRelationship.test.ts.snap} (54%) create mode 100644 test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap rename test/{writeClient-migrate-patch-link.test.ts => writeClient-migrate-patch-contentRelationship.test.ts} (57%) create mode 100644 test/writeClient-migrate-patch-rtImageNode.test.ts diff --git a/src/Client.ts b/src/Client.ts index a9d4e778..22fcd565 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -1738,7 +1738,7 @@ export class Client< throw new RepositoryNotFoundError( `Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`, url, - undefined, + url.startsWith(this.documentAPIEndpoint) ? undefined : res.text, ) } diff --git a/src/Migration.ts b/src/Migration.ts index 35b989b1..10faaf3e 100644 --- a/src/Migration.ts +++ b/src/Migration.ts @@ -1,119 +1,33 @@ -import * as is from "./lib/isMigrationField" +import { prepareMigrationRecord } from "./lib/prepareMigrationRecord" import { validateAssetMetadata } from "./lib/validateAssetMetadata" import type { Asset } from "./types/api/asset/asset" -import type { MigrationAsset } from "./types/migration/asset" +import type { MigrationAssetConfig } from "./types/migration/Asset" +import { MigrationImage } from "./types/migration/Asset" +import { MigrationDocument } from "./types/migration/Document" import type { - FieldsToMigrationFields, PrismicMigrationDocument, PrismicMigrationDocumentParams, -} from "./types/migration/document" -import { - type ImageMigrationField, - type LinkToMediaMigrationField, - MigrationFieldType, -} from "./types/migration/fields" +} from "./types/migration/Document" import type { PrismicDocument } from "./types/value/document" -import type { GroupField } from "./types/value/group" import type { FilledImageFieldImage } from "./types/value/image" -import { LinkType } from "./types/value/link" import type { FilledLinkToMediaField } from "./types/value/linkToMedia" -import { RichTextNodeType } from "./types/value/richText" -import type { SliceZone } from "./types/value/sliceZone" -import type { AnyRegularField } from "./types/value/types" - -import * as isFilled from "./helpers/isFilled" - -/** - * Discovers assets in a record of Prismic fields. - * - * @param record - Record of Prismic fields to loook for assets in. - * @param onAsset - Callback that is called for each asset found. - */ -const discoverAssets = ( - record: FieldsToMigrationFields< - Record - >, - onAsset: (asset: FilledImageFieldImage | FilledLinkToMediaField) => void, -) => { - for (const field of Object.values(record)) { - if (is.sliceZone(field)) { - for (const slice of field) { - discoverAssets(slice.primary, onAsset) - for (const item of slice.items) { - discoverAssets(item, onAsset) - } - } - } else if (is.richText(field)) { - for (const node of field) { - if ("type" in node) { - if (node.type === RichTextNodeType.image) { - onAsset(node) - if ( - node.linkTo && - "link_type" in node.linkTo && - node.linkTo.link_type === LinkType.Media - ) { - onAsset(node.linkTo) - } - } else if (node.type !== RichTextNodeType.embed) { - for (const span of node.spans) { - if ( - span.type === "hyperlink" && - span.data && - "link_type" in span.data && - span.data.link_type === LinkType.Media - ) { - onAsset(span.data) - } - } - } - } - } - } else if (is.group(field)) { - for (const item of field) { - discoverAssets(item, onAsset) - } - } else if ( - is.image(field) && - field && - "dimensions" in field && - isFilled.image(field) - ) { - onAsset(field) - } else if ( - is.link(field) && - field && - "link_type" in field && - field.link_type === LinkType.Media && - isFilled.linkToMedia(field) - ) { - onAsset(field) - } - } -} /** * 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 TMigrationDocuments - Prismic migration document types from which - * to extract. - * @typeParam TType - Type(s) to match `TMigrationDocuments` against. + * @typeParam TDocuments - Prismic document types from which to extract. + * @typeParam TDocumentType - Type(s) to match `TDocuments` against. */ -type ExtractMigrationDocumentType< - TMigrationDocuments extends PrismicMigrationDocument, - TType extends TMigrationDocuments["type"], +type ExtractDocumentType< + TDocuments extends PrismicDocument | PrismicMigrationDocument, + TDocumentType extends TDocuments["type"], > = - Extract extends never - ? TMigrationDocuments - : Extract - -type CreateAssetReturnType = ImageMigrationField & { - image: ImageMigrationField - linkToMedia: LinkToMediaMigrationField -} + Extract extends never + ? TDocuments + : Extract /** * The symbol used to index documents that are singletons. @@ -134,37 +48,37 @@ export class Migration< /** * @internal */ - _documents: { - document: TMigrationDocuments - params: PrismicMigrationDocumentParams - }[] = [] - #indexedDocuments: Record> = {} + _assets: Map = new Map() /** * @internal */ - _assets: Map = new Map() + _documents: MigrationDocument[] = [] + #indexedDocuments: Record< + string, + Record> + > = {} createAsset( asset: Asset | FilledImageFieldImage | FilledLinkToMediaField, - ): CreateAssetReturnType + ): MigrationImage createAsset( - file: MigrationAsset["file"], - filename: MigrationAsset["filename"], + file: MigrationAssetConfig["file"], + filename: MigrationAssetConfig["filename"], params?: { notes?: string credits?: string alt?: string tags?: string[] }, - ): CreateAssetReturnType + ): MigrationImage createAsset( fileOrAsset: - | MigrationAsset["file"] + | MigrationAssetConfig["file"] | Asset | FilledImageFieldImage | FilledLinkToMediaField, - filename?: MigrationAsset["filename"], + filename?: MigrationAssetConfig["filename"], { notes, credits, @@ -176,8 +90,9 @@ export class Migration< alt?: string tags?: string[] } = {}, - ): CreateAssetReturnType { - let asset: MigrationAsset + ): MigrationImage { + let asset: MigrationAssetConfig + let maybeInitialField: FilledImageFieldImage | undefined if (typeof fileOrAsset === "object" && "url" in fileOrAsset) { if ("dimensions" in fileOrAsset || "link_type" in fileOrAsset) { const url = fileOrAsset.url.split("?")[0] @@ -192,6 +107,10 @@ export class Migration< const alt = "alt" in fileOrAsset && fileOrAsset.alt ? fileOrAsset.alt : undefined + if ("dimensions" in fileOrAsset) { + maybeInitialField = fileOrAsset + } + asset = { id: fileOrAsset.id, file: url, @@ -243,64 +162,54 @@ export class Migration< this._assets.set(asset.id, asset) } - return { - migrationType: MigrationFieldType.Image, - ...asset, - image: { - migrationType: MigrationFieldType.Image, - ...asset, - }, - linkToMedia: { - migrationType: MigrationFieldType.LinkToMedia, - ...asset, - }, - } + return new MigrationImage(this._assets.get(asset.id)!, maybeInitialField) } createDocument( - document: ExtractMigrationDocumentType, + document: ExtractDocumentType, documentTitle: PrismicMigrationDocumentParams["documentTitle"], params: Omit = {}, - ): ExtractMigrationDocumentType { - this._documents.push({ - document, - params: { documentTitle, ...params }, - }) + ): MigrationDocument> { + const { record: data, dependencies } = prepareMigrationRecord( + document.data, + this.createAsset.bind(this), + ) + + const migrationDocument = new MigrationDocument( + { ...document, data }, + { + documentTitle, + ...params, + }, + dependencies, + ) + + this._documents.push(migrationDocument) // Index document if (!(document.type in this.#indexedDocuments)) { this.#indexedDocuments[document.type] = {} } this.#indexedDocuments[document.type][document.uid || SINGLE_INDEX] = - document - - // Find other assets in document - discoverAssets(document.data, this.createAsset.bind(this)) + migrationDocument - return document + return migrationDocument } - getByUID< - TType extends TMigrationDocuments["type"], - TMigrationDocument extends Extract< - TMigrationDocuments, - { type: TType } - > = Extract, - >(documentType: TType, uid: string): TMigrationDocument | undefined { + getByUID( + documentType: TType, + uid: string, + ): MigrationDocument> | undefined { return this.#indexedDocuments[documentType]?.[uid] as - | TMigrationDocument + | MigrationDocument | undefined } - getSingle< - TType extends TMigrationDocuments["type"], - TMigrationDocument extends Extract< - TMigrationDocuments, - { type: TType } - > = Extract, - >(documentType: TType): TMigrationDocument | undefined | undefined { + getSingle( + documentType: TType, + ): MigrationDocument> | undefined { return this.#indexedDocuments[documentType]?.[SINGLE_INDEX] as - | TMigrationDocument + | MigrationDocument | undefined } } diff --git a/src/WriteClient.ts b/src/WriteClient.ts index be5934e8..2dc6ac16 100644 --- a/src/WriteClient.ts +++ b/src/WriteClient.ts @@ -1,7 +1,5 @@ import { devMsg } from "./lib/devMsg" import { pLimit } from "./lib/pLimit" -import type { AssetMap, DocumentMap } from "./lib/patchMigrationDocumentData" -import { patchMigrationDocumentData } from "./lib/patchMigrationDocumentData" import type { Asset, @@ -24,11 +22,14 @@ import { type PostDocumentResult, type PutDocumentParams, } from "./types/api/migration/document" -import type { MigrationAsset } from "./types/migration/asset" +import type { AssetMap, MigrationAssetConfig } from "./types/migration/Asset" +import { MigrationContentRelationship } from "./types/migration/ContentRelationship" import type { + DocumentMap, + MigrationDocument, PrismicMigrationDocument, PrismicMigrationDocumentParams, -} from "./types/migration/document" +} from "./types/migration/Document" import type { PrismicDocument } from "./types/value/document" import { PrismicError } from "./errors/PrismicError" @@ -93,13 +94,13 @@ type MigrateReporterEventMap = { current: number remaining: number total: number - asset: MigrationAsset + asset: MigrationAssetConfig } "assets:creating": { current: number remaining: number total: number - asset: MigrationAsset + asset: MigrationAssetConfig } "assets:created": { created: number @@ -521,89 +522,77 @@ export class WriteClient< documents.set(document.id, document) } - const sortedDocuments: { - document: PrismicMigrationDocument - params: PrismicMigrationDocumentParams - }[] = [] + const sortedMigrationDocuments: MigrationDocument[] = [] // We create an array with non-master locale documents last because // we need their master locale document to be created first. - for (const { document, params } of migration._documents) { - if (document.lang === masterLocale) { - sortedDocuments.unshift({ document, params }) + for (const migrationDocument of migration._documents) { + if (migrationDocument.document.lang === masterLocale) { + sortedMigrationDocuments.unshift(migrationDocument) } else { - sortedDocuments.push({ document, params }) + sortedMigrationDocuments.push(migrationDocument) } } let i = 0 let created = 0 - for (const { document, params } of sortedDocuments) { - if (document.id && documents.has(document.id)) { + for (const migrationDocument of sortedMigrationDocuments) { + if ( + migrationDocument.document.id && + documents.has(migrationDocument.document.id) + ) { reporter?.({ type: "documents:skipping", data: { reason: "already exists", current: ++i, - remaining: sortedDocuments.length - i, - total: sortedDocuments.length, - document, - documentParams: params, + remaining: sortedMigrationDocuments.length - i, + total: sortedMigrationDocuments.length, + document: migrationDocument.document, + documentParams: migrationDocument.params, }, }) // Index the migration document - documents.set(document, documents.get(document.id)!) + documents.set( + migrationDocument, + documents.get(migrationDocument.document.id)!, + ) } else { created++ reporter?.({ type: "documents:creating", data: { current: ++i, - remaining: sortedDocuments.length - i, - total: sortedDocuments.length, - document, - documentParams: params, + remaining: sortedMigrationDocuments.length - i, + total: sortedMigrationDocuments.length, + document: migrationDocument.document, + documentParams: migrationDocument.params, }, }) // Resolve master language document ID for non-master locale documents let masterLanguageDocumentID: string | undefined - if (document.lang !== masterLocale) { - if (params.masterLanguageDocument) { - if (typeof params.masterLanguageDocument === "function") { - const masterLanguageDocument = - await params.masterLanguageDocument() - - if (masterLanguageDocument) { - // `masterLanguageDocument` is an existing document - if (masterLanguageDocument.id) { - masterLanguageDocumentID = documents.get( - masterLanguageDocument.id, - )?.id - } - - // `masterLanguageDocument` is a new document - if (!masterLanguageDocumentID) { - masterLanguageDocumentID = documents.get( - masterLanguageDocument, - )?.id - } - } - } else { - masterLanguageDocumentID = params.masterLanguageDocument.id - } - } else if (document.alternate_languages) { - masterLanguageDocumentID = document.alternate_languages.find( - ({ lang }) => lang === masterLocale, - )?.id + if (migrationDocument.document.lang !== masterLocale) { + if (migrationDocument.params.masterLanguageDocument) { + const link = new MigrationContentRelationship( + migrationDocument.params.masterLanguageDocument, + ) + + await link._prepare({ documents }) + masterLanguageDocumentID = link._field?.id + } else if (migrationDocument.document.alternate_languages) { + masterLanguageDocumentID = + migrationDocument.document.alternate_languages.find( + ({ lang }) => lang === masterLocale, + )?.id } } const { id } = await this.createDocument( // We'll upload docuements data later on. - { ...document, data: {} }, - params.documentTitle, + { ...migrationDocument.document, data: {} }, + migrationDocument.params.documentTitle, { masterLanguageDocumentID, ...fetchParams, @@ -611,10 +600,13 @@ export class WriteClient< ) // Index old ID for Prismic to Prismic migration - if (document.id) { - documents.set(document.id, { ...document, id }) + if (migrationDocument.document.id) { + documents.set(migrationDocument.document.id, { + ...migrationDocument.document, + id, + }) } - documents.set(document, { ...document, id }) + documents.set(migrationDocument, { ...migrationDocument.document, id }) } } @@ -650,30 +642,31 @@ export class WriteClient< }: { reporter?: (event: MigrateReporterEvents) => void } & FetchParams = {}, ): Promise { let i = 0 - for (const { document, params } of migration._documents) { + for (const migrationDocument of migration._documents) { reporter?.({ type: "documents:updating", data: { current: ++i, remaining: migration._documents.length - i, total: migration._documents.length, - document, - documentParams: params, + document: migrationDocument.document, + documentParams: migrationDocument.params, }, }) - const { id, uid } = documents.get(document)! - const data = await patchMigrationDocumentData( - document.data, - assets, - documents, - ) + const { id, uid } = documents.get(migrationDocument)! + await migrationDocument._prepare({ assets, documents }) await this.updateDocument( id, // We need to forward again document name and tags to update them // in case the document already existed during the previous step. - { documentTitle: params.documentTitle, uid, tags: document.tags, data }, + { + documentTitle: migrationDocument.params.documentTitle, + uid, + tags: migrationDocument.document.tags, + data: migrationDocument.document.data, + }, fetchParams, ) } diff --git a/src/index.ts b/src/index.ts index 45768631..8c1dfaf3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -326,24 +326,19 @@ export type { } from "./types/model/types" // Migrations - Types representing Prismic Migration API content values. -export { MigrationFieldType } from "./types/migration/fields" - export type { + MigrationDocument, PrismicMigrationDocument, - RichTextFieldToMigrationField, -} from "./types/migration/document" + RichTextFieldWithMigrationField, +} from "./types/migration/Document" export type { - ImageMigrationField, - LinkToMediaMigrationField, - ContentRelationshipMigrationField, - LinkMigrationField, -} from "./types/migration/fields" + MigrationImage, + MigrationLinkToMedia, + MigrationRTImageNode, +} from "./types/migration/Asset" -export type { - RTImageMigrationNode, - RTLinkMigrationNode, -} from "./types/migration/richText" +export type { MigrationContentRelationship } from "./types/migration/ContentRelationship" // API - Types representing Prismic Rest API V2 responses. export type { Query } from "./types/api/query" diff --git a/src/lib/isMigrationField.ts b/src/lib/isMigrationField.ts deleted file mode 100644 index 320f1fa6..00000000 --- a/src/lib/isMigrationField.ts +++ /dev/null @@ -1,180 +0,0 @@ -import type { - FieldToMigrationField, - GroupFieldToMigrationField, - RichTextFieldToMigrationField, - SliceZoneToMigrationField, -} from "../types/migration/document" -import type { - ImageMigrationField, - LinkMigrationField, -} from "../types/migration/fields" -import { MigrationFieldType } from "../types/migration/fields" -import type { GroupField } from "../types/value/group" -import type { ImageField } from "../types/value/image" -import type { LinkField } from "../types/value/link" -import { LinkType } from "../types/value/link" -import { type RichTextField, RichTextNodeType } from "../types/value/richText" -import type { SliceZone } from "../types/value/sliceZone" -import type { AnyRegularField } from "../types/value/types" - -/** - * Checks if a field is a slice zone. - * - * @param field - Field to check. - * - * @returns `true` if `field` is a slice zone migration field, `false` - * otherwise. - * - * @internal - * This is not an official helper function and it's only designed to work in the - * case of migration fields. - */ -export const sliceZone = ( - field: FieldToMigrationField, -): field is SliceZoneToMigrationField => { - return ( - Array.isArray(field) && - field.every((item) => "slice_type" in item && "id" in item) - ) -} - -/** - * Checks if a field is a rich text field. - * - * @param field - Field to check. - * - * @returns `true` if `field` is a rich text migration field, `false` otherwise. - * - * @internal - * This is not an official helper function and it's only designed to work in the - * case of migration fields. - */ -export const richText = ( - field: FieldToMigrationField, -): field is RichTextFieldToMigrationField => { - return ( - Array.isArray(field) && - field.every((item) => { - if ( - "migrationType" in item && - item.migrationType === MigrationFieldType.Image - ) { - return true - } else if ("type" in item && typeof item.type === "string") { - switch (item.type) { - case RichTextNodeType.heading1: - case RichTextNodeType.heading2: - case RichTextNodeType.heading3: - case RichTextNodeType.heading4: - case RichTextNodeType.heading5: - case RichTextNodeType.heading6: - case RichTextNodeType.paragraph: - case RichTextNodeType.preformatted: - case RichTextNodeType.listItem: - case RichTextNodeType.oListItem: - return "spans" in item && Array.isArray(item.spans) - - case RichTextNodeType.image: - return "dimensions" in item - - case RichTextNodeType.embed: - return "oembed" in item - } - } - - return false - }) - ) -} - -/** - * Checks if a field is a group field. - * - * @param field - Field to check. - * - * @returns `true` if `field` is a group migration field, `false` otherwise. - * - * @internal - * This is not an official helper function and it's only designed to work in the - * case of migration fields. - */ -export const group = ( - field: FieldToMigrationField, -): field is GroupFieldToMigrationField => { - return !sliceZone(field) && !richText(field) && Array.isArray(field) -} - -/** - * Checks if a field is a link field. - * - * @param field - Field to check. - * - * @returns `true` if `field` is a link migration field, `false` otherwise. - * - * @internal - * This is not an official helper function and it's only designed to work in the - * case of migration fields. - */ -export const link = ( - field: FieldToMigrationField, -): field is LinkMigrationField | LinkField => { - if (typeof field === "function") { - // Lazy content relationship field - return true - } else if (field && typeof field === "object" && !("version" in field)) { - if ( - "migrationType" in field && - field.migrationType === MigrationFieldType.LinkToMedia - ) { - // Migration link to media field - return true - } else if ( - "type" in field && - "lang" in field && - typeof field.lang === "string" - ) { - // Content relationship field declared using another repository document - return true - } else if ( - "link_type" in field && - (field.link_type === LinkType.Document || - field.link_type === LinkType.Media || - field.link_type === LinkType.Web) - ) { - // Regular link field - return true - } - } - - return false -} - -/** - * Checks if a field is an image field. - * - * @param field - Field to check. - * - * @returns `true` if `field` is an image migration field, `false` otherwise. - * - * @internal - * This is not an official helper function and it's only designed to work in the - * case of migration fields. - */ -export const image = ( - field: FieldToMigrationField, -): field is ImageMigrationField | ImageField => { - if (field && typeof field === "object" && !("version" in field)) { - if ( - "migrationType" in field && - field.migrationType === MigrationFieldType.Image - ) { - // Migration image field - return true - } else if ("id" in field && "url" in field && "dimensions" in field) { - // Regular image field - return true - } - } - - return false -} diff --git a/src/lib/isValue.ts b/src/lib/isValue.ts new file mode 100644 index 00000000..71f563f0 --- /dev/null +++ b/src/lib/isValue.ts @@ -0,0 +1,215 @@ +import type { + FieldWithMigrationField, + RichTextBlockNodeWithMigrationField, +} from "../types/migration/Document" +import type { FilledContentRelationshipField } from "../types/value/contentRelationship" +import type { PrismicDocument } from "../types/value/document" +import type { ImageField } from "../types/value/image" +import { LinkType } from "../types/value/link" +import type { FilledLinkToMediaField } from "../types/value/linkToMedia" +import { type RTImageNode, RichTextNodeType } from "../types/value/richText" + +/** + * Checks if a value is a link to media field. + * + * @param value - Value to check. + * + * @returns `true` if `value` is a link to media field, `false` otherwise. + * + * @internal + * This is not an official helper function and it's only designed to work with internal processes. + */ +export const linkToMedia = ( + value: + | PrismicDocument + | FieldWithMigrationField + | RichTextBlockNodeWithMigrationField + | unknown, +): value is FilledLinkToMediaField => { + if (value && typeof value === "object" && !("version" in value)) { + if ( + "link_type" in value && + value.link_type === LinkType.Media && + "id" in value && + "name" in value && + "kind" in value && + "url" in value && + "size" in value + ) { + return true + } + } + + return false +} + +/** + * Checks if a value is like an image field. + * + * @param value - Value to check. + * + * @returns `true` if `value` is like an image field, `false` otherwise. + * + * @internal + * This is not an official helper function and it's only designed to work with internal processes. + */ +const imageLike = ( + value: + | PrismicDocument + | FieldWithMigrationField + | RichTextBlockNodeWithMigrationField + | unknown, +): value is ImageField | RTImageNode => { + if ( + value && + typeof value === "object" && + (!("version" in value) || typeof value.version === "object") + ) { + if ( + "id" in value && + "url" in value && + typeof value.url === "string" && + "dimensions" in value && + "edit" in value && + "alt" in value && + "copyright" in value + ) { + return true + } + } + + return false +} + +/** + * Checks if a value is an image field. + * + * @param value - Value to check. + * + * @returns `true` if `value` is an image field, `false` otherwise. + * + * @internal + * This is not an official helper function and it's only designed to work with internal processes. + */ +export const image = ( + value: + | PrismicDocument + | FieldWithMigrationField + | RichTextBlockNodeWithMigrationField + | unknown, +): value is ImageField => { + if ( + imageLike(value) && + (!("type" in value) || value.type !== RichTextNodeType.image) + ) { + value + + return true + } + + return false +} + +/** + * Checks if a value is a rich text image node. + * + * @param value - Value to check. + * + * @returns `true` if `value` is a rich text image node, `false` otherwise. + * + * @internal + * This is not an official helper function and it's only designed to work with internal processes. + */ +export const rtImageNode = ( + value: + | PrismicDocument + | FieldWithMigrationField + | RichTextBlockNodeWithMigrationField + | unknown, +): value is RTImageNode => { + if ( + imageLike(value) && + "type" in value && + value.type === RichTextNodeType.image + ) { + value + + return true + } + + return false +} + +/** + * Checks if a value is a content relationship field. + * + * @param value - Value to check. + * + * @returns `true` if `value` is a content relationship, `false` otherwise. + * + * @internal + * This is not an official helper function and it's only designed to work with internal processes. + */ +export const contentRelationship = ( + value: + | PrismicDocument + | FieldWithMigrationField + | RichTextBlockNodeWithMigrationField + | unknown, +): value is FilledContentRelationshipField => { + if (value && typeof value === "object" && !("version" in value)) { + if ( + "link_type" in value && + value.link_type === LinkType.Document && + "id" in value && + "type" in value && + "tags" in value && + "lang" in value + ) { + return true + } + } + + return false +} + +/** + * Checks if a value is a Prismic document. + * + * @param value - Value to check. + * + * @returns `true` if `value` is a content relationship, `false` otherwise. + * + * @internal + * This is not an official helper function and it's only designed to work with internal processes. + */ +export const document = ( + value: + | PrismicDocument + | FieldWithMigrationField + | RichTextBlockNodeWithMigrationField + | unknown, +): value is PrismicDocument => { + if (value && typeof value === "object" && !("version" in value)) { + if ( + "id" in value && + "uid" in value && + "url" in value && + "type" in value && + typeof value.type === "string" && + "href" in value && + "tags" in value && + "first_publication_date" in value && + "last_publication_date" in value && + "slugs" in value && + "linked_documents" in value && + "lang" in value && + "alternate_languages" in value && + "data" in value + ) { + return true + } + } + + return false +} diff --git a/src/lib/patchMigrationDocumentData.ts b/src/lib/patchMigrationDocumentData.ts deleted file mode 100644 index d99b59b7..00000000 --- a/src/lib/patchMigrationDocumentData.ts +++ /dev/null @@ -1,447 +0,0 @@ -import type { Asset } from "../types/api/asset/asset" -import type { MigrationAsset } from "../types/migration/asset" -import type { - FieldsToMigrationFields, - GroupFieldToMigrationField, - PrismicMigrationDocument, - RichTextFieldToMigrationField, - SliceZoneToMigrationField, -} from "../types/migration/document" -import type { - ImageMigrationField, - LinkMigrationField, -} from "../types/migration/fields" -import { MigrationFieldType } from "../types/migration/fields" -import type { PrismicDocument } from "../types/value/document" -import type { GroupField, NestedGroupField } from "../types/value/group" -import type { FilledImageFieldImage, ImageField } from "../types/value/image" -import { LinkType } from "../types/value/link" -import type { LinkField } from "../types/value/link" -import type { RTInlineNode } from "../types/value/richText" -import { type RichTextField, RichTextNodeType } from "../types/value/richText" -import type { SharedSlice } from "../types/value/sharedSlice" -import type { Slice } from "../types/value/slice" -import type { SliceZone } from "../types/value/sliceZone" -import type { AnyRegularField } from "../types/value/types" - -import * as isFilled from "../helpers/isFilled" - -import * as is from "./isMigrationField" -import * as to from "./toField" - -/** - * A map of asset IDs to asset used to resolve assets when patching migration - * Prismic documents. - * - * @internal - */ -export type AssetMap = Map - -/** - * A map of document IDs, documents, and migraiton documents to content - * relationship field used to resolve content relationships when patching - * migration Prismic documents. - * - * @typeParam TDocuments - Type of Prismic documents in the repository. - * - * @internal - */ -export type DocumentMap = - Map< - | string - | TDocuments - | PrismicMigrationDocument - | PrismicMigrationDocument, - | PrismicDocument - | (Omit, "id"> & { id: string }) - > - -/** - * Inherits query parameters from an original URL to a new URL. - * - * @param url - The new URL. - * @param original - The original URL to inherit query parameters from. - * - * @returns The new URL with query parameters inherited from the original URL. - */ -const inheritQueryParams = (url: string, original: string): string => { - const queryParams = original.split("?")[1] || "" - - return `${url.split("?")[0]}${queryParams ? `?${queryParams}` : ""}` -} - -/** - * Patches references in a slice zone field. - * - * @typeParam TDocuments - Type of Prismic documents in the repository. - * - * @param sliceZone - The slice zone to patch. - * @param assets - A map of assets available in the Prismic repository. - * @param documents - A map of documents available in the Prismic repository. - * - * @returns The patched slice zone. - */ -const patchSliceZone = async < - TDocuments extends PrismicDocument = PrismicDocument, ->( - sliceZone: SliceZoneToMigrationField, - assets: AssetMap, - documents: DocumentMap, -): Promise => { - const result = [] as unknown as SliceZone - - for (const slice of sliceZone) { - const { primary, items, ...properties } = slice - const patchedPrimary = await patchRecord( - // We cast to `Slice["primary"]` which is stricter than `SharedSlice["primary"]` - // otherwise TypeScript gets confused while creating the patched slice below. - primary as Slice["primary"], - assets, - documents, - ) - const patchedItems = await patchGroup(items, assets, documents) - - result.push({ - ...properties, - primary: patchedPrimary, - items: patchedItems, - }) - } - - return result -} - -/** - * Patches references in a rich text field. - * - * @typeParam TDocuments - Type of Prismic documents in the repository. - * - * @param richText - The rich text field to patch. - * @param assets - A map of assets available in the Prismic repository. - * @param documents - A map of documents available in the Prismic repository. - * - * @returns The patched rich text field. - */ -const patchRichText = async < - TDocuments extends PrismicDocument = PrismicDocument, ->( - richText: RichTextFieldToMigrationField, - assets: AssetMap, - documents: DocumentMap, -): Promise => { - const result = [] as unknown as RichTextField<"filled"> - - for (const node of richText) { - if ("type" in node && typeof node.type === "string") { - if (node.type === RichTextNodeType.embed) { - result.push(node) - } else if (node.type === RichTextNodeType.image) { - const image = patchImage(node, assets) - - if (isFilled.image(image)) { - const linkTo = await patchLink(node.linkTo, assets, documents) - - result.push({ - ...image, - type: RichTextNodeType.image, - linkTo: isFilled.link(linkTo) ? linkTo : undefined, - }) - } - } else { - const { spans, ...properties } = node - - const patchedSpans: RTInlineNode[] = [] - - for (const span of spans) { - if (span.type === RichTextNodeType.hyperlink) { - const data = await patchLink(span.data, assets, documents) - - if (isFilled.link(data)) { - patchedSpans.push({ ...span, data }) - } - } else { - patchedSpans.push(span) - } - } - - result.push({ - ...properties, - spans: patchedSpans, - }) - } - } else { - // Migration image node - const asset = assets.get(node.id) - - const linkTo = await patchLink(node.linkTo, assets, documents) - - if (asset) { - result.push({ - ...to.rtImageNode(asset), - linkTo: isFilled.link(linkTo) ? linkTo : undefined, - }) - } - } - } - - return result -} - -/** - * Patches references in a group field. - * - * @typeParam TDocuments - Type of Prismic documents in the repository. - * - * @param group - The group field to patch. - * @param assets - A map of assets available in the Prismic repository. - * @param documents - A map of documents available in the Prismic repository. - * - * @returns The patched group field. - */ -const patchGroup = async < - TMigrationGroup extends GroupFieldToMigrationField< - GroupField | Slice["items"] | SharedSlice["items"] - >, - TDocuments extends PrismicDocument = PrismicDocument, ->( - group: TMigrationGroup, - assets: AssetMap, - documents: DocumentMap, -): Promise< - TMigrationGroup extends GroupFieldToMigrationField - ? TGroup - : never -> => { - const result = [] as unknown as GroupField< - Record, - "filled" - > - - for (const item of group) { - const patched = await patchRecord(item, assets, documents) - - result.push(patched) - } - - return result as TMigrationGroup extends GroupFieldToMigrationField< - infer TGroup - > - ? TGroup - : never -} - -/** - * Patches references in a link field. - * - * @typeParam TDocuments - Type of Prismic documents in the repository. - * - * @param link - The link field to patch. - * @param assets - A map of assets available in the Prismic repository. - * @param documents - A map of documents available in the Prismic repository. - * - * @returns The patched link field. - */ -const patchLink = async ( - link: LinkMigrationField | LinkField, - assets: AssetMap, - documents: DocumentMap, -): Promise => { - if (link) { - if ("migrationType" in link) { - // Migration link field - const asset = assets.get(link.id) - if (asset) { - return to.linkToMediaField(asset) - } - } else if ("link_type" in link) { - switch (link.link_type) { - case LinkType.Document: - // Existing content relationship - if (isFilled.contentRelationship(link)) { - const id = documents.get(link.id)?.id - if (id) { - return { ...link, id } - } else { - return { ...link, isBroken: true } - } - } - case LinkType.Media: - // Existing link to media - if (isFilled.linkToMedia(link)) { - const id = assets.get(link.id)?.id - if (id) { - return { ...link, id } - } - break - } - case LinkType.Web: - default: - return link - } - } else { - const resolved = typeof link === "function" ? await link() : link - - if (resolved) { - // Link might be represented by a document or a migration document... - let maybeRelationship = resolved.id - ? documents.get(resolved.id) - : undefined - - // ...or by a migration document - if (!maybeRelationship) { - maybeRelationship = documents.get(resolved) - } - - if (maybeRelationship) { - return to.contentRelationship(maybeRelationship) - } - } - } - } - - return { - link_type: LinkType.Any, - } -} - -/** - * Patches references in an image field. - * - * @param image - The image field to patch. - * @param assets - A map of assets available in the Prismic repository. - * - * @returns The patched image field. - */ -const patchImage = ( - image: ImageMigrationField | ImageField, - assets: AssetMap, -): ImageField => { - if (image) { - if ( - "migrationType" in image && - image.migrationType === MigrationFieldType.Image - ) { - // Migration image field - const asset = assets.get(image.id) - if (asset) { - return to.imageField(asset) - } - } else if ( - "dimensions" in image && - image.dimensions && - isFilled.image(image) - ) { - // Regular image field - const { - id, - url, - dimensions, - edit, - alt, - copyright: _, - ...thumbnails - } = image - const asset = assets.get(id) - - if (asset) { - const result = { - id: asset.id, - url: inheritQueryParams(asset.url, url), - dimensions, - edit, - alt: alt || null, - copyright: asset.credits || null, - } as ImageField - - if (Object.keys(thumbnails).length > 0) { - for (const name in thumbnails) { - const maybeThumbnail = ( - thumbnails as Record - )[name] - - if (is.image(maybeThumbnail)) { - const { url, dimensions, edit, alt } = ( - thumbnails as Record - )[name] - - result[name] = { - id: asset.id, - url: inheritQueryParams(asset.url, url), - dimensions, - edit, - alt: alt || null, - copyright: asset.credits || null, - } - } - } - } - - return result - } - } - } - - return {} -} - -/** - * Patches references in a record of Prismic field. - * - * @typeParam TFields - Type of the record of Prismic fields. - * @typeParam TDocuments - Type of Prismic documents in the repository. - * - * @param record - The link field to patch. - * @param assets - A map of assets available in the Prismic repository. - * @param documents - A map of documents available in the Prismic repository. - * - * @returns The patched record. - */ -const patchRecord = async < - TFields extends Record, - TDocuments extends PrismicDocument = PrismicDocument, ->( - record: FieldsToMigrationFields, - assets: AssetMap, - documents: DocumentMap, -): Promise => { - const result: Record = {} - - for (const [key, field] of Object.entries(record)) { - if (is.sliceZone(field)) { - result[key] = await patchSliceZone(field, assets, documents) - } else if (is.richText(field)) { - result[key] = await patchRichText(field, assets, documents) - } else if (is.group(field)) { - result[key] = await patchGroup(field, assets, documents) - } else if (is.link(field)) { - result[key] = await patchLink(field, assets, documents) - } else if (is.image(field)) { - result[key] = patchImage(field, assets) - } else { - result[key] = field - } - } - - return result as TFields -} - -/** - * Patches references in a document's data. - * - * @typeParam TDocuments - Type of Prismic documents in the repository. - * - * @param data - The document data to patch. - * @param assets - A map of assets available in the Prismic repository. - * @param documents - A map of documents available in the Prismic repository. - * - * @returns The patched document data. - */ -export const patchMigrationDocumentData = async < - TDocuments extends PrismicDocument = PrismicDocument, ->( - data: PrismicMigrationDocument["data"], - assets: AssetMap, - documents: DocumentMap, -): Promise => { - return patchRecord(data, assets, documents) -} diff --git a/src/lib/prepareMigrationRecord.ts b/src/lib/prepareMigrationRecord.ts new file mode 100644 index 00000000..26ea459e --- /dev/null +++ b/src/lib/prepareMigrationRecord.ts @@ -0,0 +1,120 @@ +import type { + MigrationImage, + MigrationLinkToMedia, +} from "../types/migration/Asset" +import type { UnresolvedMigrationContentRelationshipConfig } from "../types/migration/ContentRelationship" +import { MigrationContentRelationship } from "../types/migration/ContentRelationship" +import { MigrationDocument } from "../types/migration/Document" +import { MigrationField } from "../types/migration/Field" +import type { FilledImageFieldImage } from "../types/value/image" +import type { FilledLinkToWebField } from "../types/value/link" +import type { FilledLinkToMediaField } from "../types/value/linkToMedia" + +import * as is from "./isValue" + +/** + * Replaces existings assets and links in a record of Prismic fields get all + * dependencies to them. + * + * @typeParam TRecord - Record of values to work with. + * + * @param record - Record of Prismic fields to work with. + * @param onAsset - Callback that is called for each asset found. + * + * @returns An object containing the record with replaced assets and links and a + * list of dependencies found and/or created. + */ +export const prepareMigrationRecord = >( + record: TRecord, + onAsset: ( + asset: FilledImageFieldImage | FilledLinkToMediaField, + ) => MigrationImage, +): { record: TRecord; dependencies: MigrationField[] } => { + const result = {} as Record + const dependencies: MigrationField[] = [] + + for (const key in record) { + const field: unknown = record[key] + + if (field instanceof MigrationField) { + dependencies.push(field) + result[key] = field + } else if (is.linkToMedia(field)) { + const linkToMedia = onAsset(field).asLinkToMedia() + + dependencies.push(linkToMedia) + result[key] = linkToMedia + } else if (is.rtImageNode(field)) { + const rtImageNode = onAsset(field).asRTImageNode() + + if (field.linkTo) { + // Node `linkTo` dependency is tracked internally + rtImageNode.linkTo = prepareMigrationRecord( + { linkTo: field.linkTo }, + onAsset, + ).record.linkTo as + | MigrationContentRelationship + | MigrationLinkToMedia + | FilledLinkToWebField + } + + dependencies.push(rtImageNode) + result[key] = rtImageNode + } else if (is.image(field)) { + const image = onAsset(field).asImage() + + const { + id: _id, + url: _url, + dimensions: _dimensions, + edit: _edit, + alt: _alt, + copyright: _copyright, + ...thumbnails + } = field + + for (const name in thumbnails) { + if (is.image(thumbnails[name])) { + image.addThumbnail(name, onAsset(thumbnails[name]).asImage()) + } + } + + dependencies.push(image) + result[key] = image + } else if ( + is.contentRelationship(field) || + is.document(field) || + field instanceof MigrationDocument || + typeof field === "function" + ) { + const contentRelationship = new MigrationContentRelationship( + field as UnresolvedMigrationContentRelationshipConfig, + ) + + dependencies.push(contentRelationship) + result[key] = contentRelationship + } else if (Array.isArray(field)) { + const array = [] + + for (const item of field) { + const { record, dependencies: itemDependencies } = + prepareMigrationRecord({ item }, onAsset) + + array.push(record.item) + dependencies.push(...itemDependencies) + } + + result[key] = array + } else if (field && typeof field === "object") { + const { record, dependencies: fieldDependencies } = + prepareMigrationRecord({ ...field }, onAsset) + + dependencies.push(...fieldDependencies) + result[key] = record + } else { + result[key] = field + } + } + + return { record: result as TRecord, dependencies } +} diff --git a/src/lib/toField.ts b/src/lib/toField.ts deleted file mode 100644 index 84035a43..00000000 --- a/src/lib/toField.ts +++ /dev/null @@ -1,106 +0,0 @@ -import type { Asset } from "../types/api/asset/asset" -import type { PrismicMigrationDocument } from "../types/migration/document" -import type { FilledContentRelationshipField } from "../types/value/contentRelationship" -import type { PrismicDocument } from "../types/value/document" -import type { ImageField } from "../types/value/image" -import { LinkType } from "../types/value/link" -import type { LinkToMediaField } from "../types/value/linkToMedia" -import type { RTImageNode } from "../types/value/richText" -import { RichTextNodeType } from "../types/value/richText" - -/** - * Converts an asset to an image field. - * - * @param asset - Asset to convert. - * - * @returns Equivalent image field. - */ -export const imageField = ({ - id, - url, - width, - height, - alt, - credits, -}: Asset): ImageField => { - return { - id, - url, - dimensions: { width: width!, height: height! }, - edit: { x: 0, y: 0, zoom: 0, background: "transparent" }, - alt: alt || null, - copyright: credits || null, - } -} - -/** - * Converts an asset to a link to media field. - * - * @param asset - Asset to convert. - * - * @returns Equivalent link to media field. - */ -export const linkToMediaField = ({ - id, - filename, - kind, - url, - size, - width, - height, -}: Asset): LinkToMediaField<"filled"> => { - return { - id, - link_type: LinkType.Media, - name: filename, - kind, - url, - size: `${size}`, - width: width ? `${width}` : undefined, - height: height ? `${height}` : undefined, - } -} - -/** - * Converts an asset to an RT image node. - * - * @param asset - Asset to convert. - * - * @returns Equivalent rich text image node. - */ -export const rtImageNode = (asset: Asset): RTImageNode => { - return { - ...imageField(asset), - type: RichTextNodeType.image, - } -} - -/** - * Converts a document to a content relationship field. - * - * @typeParam TDocuments - Type of Prismic documents in the repository. - * - * @param document - Document to convert. - * - * @returns Equivalent content relationship. - */ -export const contentRelationship = < - TDocuments extends PrismicDocument = PrismicDocument, ->( - document: - | TDocuments - | (Omit & { id: string }), -): FilledContentRelationshipField => { - return { - link_type: LinkType.Document, - id: document.id, - uid: document.uid || undefined, - type: document.type, - tags: document.tags || [], - lang: document.lang, - url: undefined, - slug: undefined, - isBroken: false, - data: undefined, - } -} diff --git a/src/types/migration/ContentRelationship.ts b/src/types/migration/ContentRelationship.ts new file mode 100644 index 00000000..f9c0eff3 --- /dev/null +++ b/src/types/migration/ContentRelationship.ts @@ -0,0 +1,55 @@ +import type { FilledContentRelationshipField } from "../value/contentRelationship" +import type { PrismicDocument } from "../value/document" +import { LinkType } from "../value/link" + +import type { DocumentMap, MigrationDocument } from "./Document" +import { MigrationField } from "./Field" + +type MigrationContentRelationshipConfig = + | PrismicDocument + | MigrationDocument + | FilledContentRelationshipField + | undefined + +export type UnresolvedMigrationContentRelationshipConfig = + | MigrationContentRelationshipConfig + | (() => + | Promise + | MigrationContentRelationshipConfig) + +export class MigrationContentRelationship extends MigrationField { + unresolvedConfig: UnresolvedMigrationContentRelationshipConfig + + constructor( + unresolvedConfig: UnresolvedMigrationContentRelationshipConfig, + initialField?: FilledContentRelationshipField, + ) { + super(initialField) + + this.unresolvedConfig = unresolvedConfig + } + + async _prepare({ documents }: { documents: DocumentMap }): Promise { + const config = + typeof this.unresolvedConfig === "function" + ? await this.unresolvedConfig() + : this.unresolvedConfig + + if (config) { + const document = + "id" in config ? documents.get(config.id) : documents.get(config) + + if (document) { + this._field = { + link_type: LinkType.Document, + id: document.id, + uid: document.uid || undefined, + type: document.type, + tags: document.tags || [], + lang: document.lang, + isBroken: false, + } + } + } + } +} diff --git a/src/types/migration/Field.ts b/src/types/migration/Field.ts new file mode 100644 index 00000000..b70926a8 --- /dev/null +++ b/src/types/migration/Field.ts @@ -0,0 +1,48 @@ +import type { AnyRegularField } from "../value/types" + +import type { RTBlockNode, RTInlineNode } from "../value/richText" + +import type { AssetMap } from "./Asset" +import type { DocumentMap } from "./Document" + +interface Preparable { + /** + * @internal + */ + _prepare(args: { + assets: AssetMap + documents: DocumentMap + }): Promise | void +} + +export abstract class MigrationField< + TField extends AnyRegularField | RTBlockNode | RTInlineNode = + | AnyRegularField + | RTBlockNode + | RTInlineNode, + TInitialField = TField, +> implements Preparable +{ + /** + * @internal + */ + _field: TField | undefined + + /** + * @internal + */ + _initialField: TInitialField | undefined + + constructor(initialField?: TInitialField) { + this._initialField = initialField + } + + toJSON(): TField | undefined { + return this._field + } + + abstract _prepare(args: { + assets: AssetMap + documents: DocumentMap + }): Promise | void +} diff --git a/src/types/migration/asset.ts b/src/types/migration/asset.ts index f71ddd82..1bf3d934 100644 --- a/src/types/migration/asset.ts +++ b/src/types/migration/asset.ts @@ -1,7 +1,61 @@ +import type { Asset } from "../api/asset/asset" +import type { FilledImageFieldImage, ImageField } from "../value/image" +import { type FilledLinkToWebField, LinkType } from "../value/link" +import type { LinkToMediaField } from "../value/linkToMedia" +import { type RTImageNode, RichTextNodeType } from "../value/richText" + +import type { MigrationContentRelationship } from "./ContentRelationship" +import type { DocumentMap } from "./Document" +import { MigrationField } from "./Field" + +/** + * Converts an asset to an image field. + * + * @param asset - Asset to convert. + * @param maybeInitialField - Initial image field if available, used to preserve + * edits. + * + * @returns Equivalent image field. + */ +const assetToImage = ( + asset: Asset, + maybeInitialField?: + | FilledImageFieldImage + | LinkToMediaField<"filled"> + | RTImageNode, +): FilledImageFieldImage => { + const parameters = (maybeInitialField?.url || asset.url).split("?")[1] + const url = `${asset.url.split("?")[0]}${parameters ? `?${parameters}` : ""}` + const dimensions: FilledImageFieldImage["dimensions"] = { + width: asset.width!, + height: asset.height!, + } + const edit: FilledImageFieldImage["edit"] = + maybeInitialField && "edit" in maybeInitialField + ? maybeInitialField?.edit + : { x: 0, y: 0, zoom: 1, background: "transparent" } + + const alt = + (maybeInitialField && "alt" in maybeInitialField + ? maybeInitialField.alt + : undefined) || + asset.alt || + null + + return { + id: asset.id, + url, + dimensions, + edit, + alt: alt, + copyright: asset.credits || null, + } +} + /** * An asset to be uploaded to Prismic media library. */ -export type MigrationAsset = { +export type MigrationAssetConfig = { /** * ID of the asset used to reference it in Prismic documents. * @@ -43,3 +97,136 @@ export type MigrationAsset = { */ tags?: string[] } + +export abstract class MigrationAsset< + TField extends + | FilledImageFieldImage + | LinkToMediaField<"filled"> + | RTImageNode = + | FilledImageFieldImage + | LinkToMediaField<"filled"> + | RTImageNode, +> extends MigrationField< + TField, + FilledImageFieldImage | LinkToMediaField<"filled"> | RTImageNode +> { + config: MigrationAssetConfig + + constructor( + config: MigrationAssetConfig, + initialField?: + | FilledImageFieldImage + | LinkToMediaField<"filled"> + | RTImageNode, + ) { + super(initialField) + + this.config = config + } + + asImage(): MigrationImage { + return new MigrationImage(this.config, this._initialField) + } + + asLinkToMedia(): MigrationLinkToMedia { + return new MigrationLinkToMedia(this.config, this._initialField) + } + + asRTImageNode(): MigrationRTImageNode { + return new MigrationRTImageNode(this.config, this._initialField) + } +} + +export class MigrationImage extends MigrationAsset { + #thumbnails: Record = {} + + addThumbnail(name: string, thumbnail: MigrationImage): void { + this.#thumbnails[name] = thumbnail + } + + async _prepare({ + assets, + documents, + }: { + assets: AssetMap + documents: DocumentMap + }): Promise { + const asset = assets.get(this.config.id) + + if (asset) { + this._field = assetToImage(asset, this._initialField) + + for (const name in this.#thumbnails) { + await this.#thumbnails[name]._prepare({ assets, documents }) + + const thumbnail = this.#thumbnails[name]._field + if (thumbnail) { + ;(this._field as ImageField)[name] = thumbnail + } + } + } + } +} + +export class MigrationLinkToMedia extends MigrationAsset< + LinkToMediaField<"filled"> +> { + _prepare({ assets }: { assets: AssetMap }): void { + const asset = assets.get(this.config.id) + + if (asset) { + this._field = { + id: asset.id, + link_type: LinkType.Media, + name: asset.filename, + kind: asset.kind, + url: asset.url, + size: `${asset.size}`, + height: + typeof asset.height === "number" ? `${asset.height}` : undefined, + width: typeof asset.width === "number" ? `${asset.width}` : undefined, + } + } + } +} + +export class MigrationRTImageNode extends MigrationAsset { + linkTo: + | MigrationLinkToMedia + | MigrationContentRelationship + | FilledLinkToWebField + | undefined + + async _prepare({ + assets, + documents, + }: { + assets: AssetMap + documents: DocumentMap + }): Promise { + const asset = assets.get(this.config.id) + + if (this.linkTo instanceof MigrationField) { + await this.linkTo._prepare({ assets, documents }) + } + + if (asset) { + this._field = { + ...assetToImage(asset, this._initialField), + type: RichTextNodeType.image, + linkTo: + this.linkTo instanceof MigrationField + ? this.linkTo._field + : this.linkTo, + } + } + } +} + +/** + * A map of asset IDs to asset used to resolve assets when patching migration + * Prismic documents. + * + * @internal + */ +export type AssetMap = Map diff --git a/src/types/migration/document.ts b/src/types/migration/document.ts index 4d030122..aa381c77 100644 --- a/src/types/migration/document.ts +++ b/src/types/migration/document.ts @@ -1,13 +1,15 @@ import type { AnyRegularField } from "../value/types" +import type { FilledContentRelationshipField } from "../value/contentRelationship" import type { PrismicDocument } from "../value/document" import type { GroupField } from "../value/group" import type { ImageField } from "../value/image" -import type { LinkField } from "../value/link" +import type { FilledLinkToMediaField } from "../value/linkToMedia" import type { RTBlockNode, RTImageNode, RTInlineNode, + RTLinkNode, RTTextNode, RichTextField, } from "../value/richText" @@ -15,114 +17,147 @@ import type { SharedSlice } from "../value/sharedSlice" import type { Slice } from "../value/slice" import type { SliceZone } from "../value/sliceZone" -import type { ImageMigrationField, LinkMigrationField } from "./fields" -import type { RTImageMigrationNode, RTLinkMigrationNode } from "./richText" +import type { + AssetMap, + MigrationImage, + MigrationLinkToMedia, + MigrationRTImageNode, +} from "./Asset" +import type { + MigrationContentRelationship, + UnresolvedMigrationContentRelationshipConfig, +} from "./ContentRelationship" +import type { MigrationField } from "./Field" /** - * A utility type that converts a rich text text node to a rich text text - * migration node. + * A utility type that extends Rich text field node's spans with their migration + * node equivalent. * * @typeParam TRTNode - Rich text text node type to convert. */ -type RichTextTextNodeToMigrationField = Omit< - TRTNode, - "spans" -> & { - spans: (RTInlineNode | RTLinkMigrationNode)[] +type RichTextTextNodeWithMigrationField< + TRTNode extends RTTextNode = RTTextNode, +> = Omit & { + spans: ( + | RTInlineNode + | (Omit & { + data: + | MigrationLinkToMedia + | MigrationContentRelationship + | UnresolvedMigrationContentRelationshipConfig + }) + )[] } /** - * A utility type that converts a rich text block node to a rich text block - * migration node. + * A utility type that extends a Rich text field node with their migration node + * equivalent. * * @typeParam TRTNode - Rich text block node type to convert. */ -type RichTextBlockNodeToMigrationField = - TRTNode extends RTImageNode - ? - | RTImageMigrationNode - | (Omit & { - linkTo?: RTImageNode["linkTo"] | LinkMigrationField - }) - : TRTNode extends RTTextNode - ? RichTextTextNodeToMigrationField - : TRTNode +export type RichTextBlockNodeWithMigrationField< + TRTNode extends RTBlockNode = RTBlockNode, +> = TRTNode extends RTImageNode + ? RTImageNode | MigrationRTImageNode + : TRTNode extends RTTextNode + ? RichTextTextNodeWithMigrationField + : TRTNode /** - * A utility type that converts a rich text field to a rich text migration - * field. + * A utility type that extends a Rich text field's nodes with their migration + * node equivalent. * * @typeParam TField - Rich text field type to convert. */ -export type RichTextFieldToMigrationField = { - [Index in keyof TField]: RichTextBlockNodeToMigrationField +export type RichTextFieldWithMigrationField< + TField extends RichTextField = RichTextField, +> = { + [Index in keyof TField]: RichTextBlockNodeWithMigrationField } /** - * A utility type that converts a regular field to a regular migration field. + * A utility type that extends a regular field with their migration field + * equivalent. * * @typeParam TField - Regular field type to convert. */ -type RegularFieldToMigrationField = +type RegularFieldWithMigrationField< + TField extends AnyRegularField = AnyRegularField, +> = | (TField extends ImageField - ? ImageMigrationField - : TField extends LinkField - ? LinkMigrationField - : TField extends RichTextField - ? RichTextFieldToMigrationField - : never) + ? MigrationImage | undefined + : TField extends FilledLinkToMediaField + ? MigrationLinkToMedia | undefined + : TField extends FilledContentRelationshipField + ? + | MigrationContentRelationship + | UnresolvedMigrationContentRelationshipConfig + | undefined + : TField extends RichTextField + ? RichTextFieldWithMigrationField + : never) | TField /** - * A utility type that converts a group field to a group migration field. + * A utility type that extends a group's fields with their migration fields + * equivalent. * * @typeParam TField - Group field type to convert. */ -export type GroupFieldToMigrationField< - TField extends GroupField | Slice["items"] | SharedSlice["items"], -> = FieldsToMigrationFields[] - -type SliceToMigrationField = Omit< - TField, - "primary" | "items" -> & { - primary: FieldsToMigrationFields - items: GroupFieldToMigrationField +type GroupFieldWithMigrationField< + TField extends GroupField | Slice["items"] | SharedSlice["items"] = + | GroupField + | Slice["items"] + | SharedSlice["items"], +> = FieldsWithMigrationFields[] + +type SliceWithMigrationField< + TField extends Slice | SharedSlice = Slice | SharedSlice, +> = Omit & { + primary: FieldsWithMigrationFields + items: GroupFieldWithMigrationField } /** - * A utility type that converts a field to a migration field. + * A utility type that extends a SliceZone's slices fields with their migration + * fields equivalent. * * @typeParam TField - Field type to convert. */ -export type SliceZoneToMigrationField = - SliceToMigrationField[] +type SliceZoneWithMigrationField = + SliceWithMigrationField[] /** - * A utility type that converts a field to a migration field. + * A utility type that extends any field with their migration field equivalent. * * @typeParam TField - Field type to convert. */ -export type FieldToMigrationField< - TField extends AnyRegularField | GroupField | SliceZone, +export type FieldWithMigrationField< + TField extends AnyRegularField | GroupField | SliceZone = + | AnyRegularField + | GroupField + | SliceZone, > = TField extends AnyRegularField - ? RegularFieldToMigrationField + ? RegularFieldWithMigrationField : TField extends GroupField - ? GroupFieldToMigrationField + ? GroupFieldWithMigrationField : TField extends SliceZone - ? SliceZoneToMigrationField + ? SliceZoneWithMigrationField : never /** - * A utility type that converts a record of fields to a record of migration - * fields. + * A utility type that extends a record of fields with their migration fields + * equivalent. * * @typeParam TFields - Type of the record of Prismic fields. */ -export type FieldsToMigrationFields< - TFields extends Record, +export type FieldsWithMigrationFields< + TFields extends Record< + string, + AnyRegularField | GroupField | SliceZone + > = Record, > = { - [Key in keyof TFields]: FieldToMigrationField + [Key in keyof TFields]: FieldWithMigrationField } /** @@ -191,7 +226,7 @@ export type PrismicMigrationDocument< /** * Data contained in the document. */ - data: FieldsToMigrationFields + data: FieldsWithMigrationFields }> : never @@ -213,11 +248,52 @@ export type PrismicMigrationDocumentParams = { // it creates a circular reference to itself which makes TypeScript unhappy. // (but I think it's weird and it doesn't make sense :thinking:) masterLanguageDocument?: - | PrismicDocument - | PrismicMigrationDocument - | (() => - | Promise - | PrismicDocument - | PrismicMigrationDocument - | undefined) + | UnresolvedMigrationContentRelationshipConfig + | undefined +} + +export class MigrationDocument< + TDocument extends PrismicDocument = PrismicDocument, +> { + document: PrismicMigrationDocument + params: PrismicMigrationDocumentParams + dependencies: MigrationField[] + + constructor( + document: PrismicMigrationDocument, + params: PrismicMigrationDocumentParams, + dependencies: MigrationField[] = [], + ) { + this.document = document + this.params = params + this.dependencies = dependencies + } + + /** + * @internal + */ + async _prepare(args: { + assets: AssetMap + documents: DocumentMap + }): Promise { + for (const dependency of this.dependencies) { + await dependency._prepare(args) + } + } } + +/** + * A map of document IDs, documents, and migraiton documents to content + * relationship field used to resolve content relationships when patching + * migration Prismic documents. + * + * @typeParam TDocuments - Type of Prismic documents in the repository. + * + * @internal + */ +export type DocumentMap = + Map< + string | MigrationDocument | MigrationDocument, + | PrismicDocument + | (Omit, "id"> & { id: string }) + > diff --git a/src/types/migration/fields.ts b/src/types/migration/fields.ts deleted file mode 100644 index 6b83c53b..00000000 --- a/src/types/migration/fields.ts +++ /dev/null @@ -1,57 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import type { ContentRelationshipField } from "../value/contentRelationship" -import type { PrismicDocument } from "../value/document" -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import type { ImageField } from "../value/image" -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import type { LinkField } from "../value/link" -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import type { LinkToMediaField } from "../value/linkToMedia" - -import type { MigrationAsset } from "./asset" -import type { PrismicMigrationDocument } from "./document" - -export const MigrationFieldType = { - Image: "image", - LinkToMedia: "linkToMedia", -} as const - -/** - * An alternate version of the {@link ImageField} for use with the Migration API. - */ -export type ImageMigrationField = - | (MigrationAsset & { - migrationType: typeof MigrationFieldType.Image - }) - | undefined - -/** - * An alternate version of the {@link LinkToMediaField} for use with the - * Migration API. - */ -export type LinkToMediaMigrationField = - | (MigrationAsset & { - migrationType: typeof MigrationFieldType.LinkToMedia - }) - | undefined - -/** - * An alternate version of the {@link ContentRelationshipField} for use with the - * Migration API. - */ -export type ContentRelationshipMigrationField = - | PrismicDocument - | PrismicMigrationDocument - | (() => - | Promise - | PrismicDocument - | PrismicMigrationDocument - | undefined) - | undefined - -/** - * An alternate version of the {@link LinkField} for use with the Migration API. - */ -export type LinkMigrationField = - | LinkToMediaMigrationField - | ContentRelationshipMigrationField diff --git a/src/types/migration/richText.ts b/src/types/migration/richText.ts deleted file mode 100644 index 9196ee88..00000000 --- a/src/types/migration/richText.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { RTImageNode, RTLinkNode } from "../value/richText" - -import type { ImageMigrationField, LinkMigrationField } from "./fields" - -/** - * An alternate version of {@link RTLinkNode} that supports - * {@link LinkMigrationField} for use with the Migration API. - */ -export type RTLinkMigrationNode = Omit & { - data: LinkMigrationField -} - -/** - * An alternate version of {@link RTImageNode} that supports - * {@link ImageMigrationField} for use with the Migration API. - */ -export type RTImageMigrationNode = ImageMigrationField & { - linkTo?: RTImageNode["linkTo"] | LinkMigrationField -} diff --git a/test/__snapshots__/writeClient-migrate-patch-link.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap similarity index 54% rename from test/__snapshots__/writeClient-migrate-patch-link.test.ts.snap rename to test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap index 114003d9..739bcda2 100644 --- a/test/__snapshots__/writeClient-migrate-patch-link.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap @@ -3,19 +3,7 @@ exports[`patches link fields > brokenLink > group 1`] = ` { "group": [ - { - "field": { - "id": "adcdf90", - "isBroken": true, - "lang": "nulla", - "link_type": "Document", - "tags": [ - "Convallis Posuere", - ], - "type": "vitae", - "url": "https://ac.example", - }, - }, + {}, ], } `; @@ -26,42 +14,11 @@ exports[`patches link fields > brokenLink > shared slice 1`] = ` { "id": "2ff58c741ba", "items": [ - { - "field": { - "id": "9be9130", - "isBroken": true, - "lang": "faucibus", - "link_type": "Document", - "tags": [ - "Ultrices", - ], - "type": "egestas_integer", - "url": "https://scelerisque.example", - }, - }, + {}, ], "primary": { - "field": { - "id": "06ad9e3", - "isBroken": true, - "lang": "fringilla", - "link_type": "Document", - "tags": [], - "type": "amet", - "url": "https://nec.example", - }, "group": [ - { - "field": { - "id": "bd0255b", - "isBroken": true, - "lang": "neque", - "link_type": "Document", - "tags": [], - "type": "lacus", - "url": "https://cras.example", - }, - }, + {}, ], }, "slice_label": null, @@ -79,29 +36,9 @@ exports[`patches link fields > brokenLink > slice 1`] = ` { "id": "e93cc3e4f28", "items": [ - { - "field": { - "id": "5ec2f4d", - "isBroken": true, - "lang": "enim,", - "link_type": "Document", - "tags": [], - "type": "felis_donec", - "url": "https://sem.example", - }, - }, + {}, ], - "primary": { - "field": { - "id": "31a1bd2", - "isBroken": true, - "lang": "ac", - "link_type": "Document", - "tags": [], - "type": "enim_praesent", - "url": "https://sit.example", - }, - }, + "primary": {}, "slice_label": "Pellentesque", "slice_type": "nulla_posuere", }, @@ -109,19 +46,7 @@ exports[`patches link fields > brokenLink > slice 1`] = ` } `; -exports[`patches link fields > brokenLink > static zone 1`] = ` -{ - "field": { - "id": "2adafa9", - "isBroken": true, - "lang": "elementum", - "link_type": "Document", - "tags": [], - "type": "aenean", - "url": "https://volutpat.example", - }, -} -`; +exports[`patches link fields > brokenLink > static zone 1`] = `{}`; exports[`patches link fields > existing > group 1`] = ` { @@ -743,13 +668,13 @@ exports[`patches link fields > otherRepositoryContentRelationship > group 1`] = "field": { "id": "id-migration", "isBroken": false, - "lang": "nulla", + "lang": "a", "link_type": "Document", "tags": [ - "Convallis Posuere", + "Odio Eu", ], - "type": "vitae", - "url": "https://ac.example", + "type": "amet", + "uid": "Non sodales neque", }, }, ], @@ -766,13 +691,11 @@ exports[`patches link fields > otherRepositoryContentRelationship > shared slice "field": { "id": "id-migration", "isBroken": false, - "lang": "faucibus", + "lang": "gravida", "link_type": "Document", - "tags": [ - "Ultrices", - ], - "type": "egestas_integer", - "url": "https://scelerisque.example", + "tags": [], + "type": "leo", + "uid": "Blandit volutpat maecenas", }, }, ], @@ -780,22 +703,22 @@ exports[`patches link fields > otherRepositoryContentRelationship > shared slice "field": { "id": "id-migration", "isBroken": false, - "lang": "fringilla", + "lang": "gravida", "link_type": "Document", "tags": [], - "type": "amet", - "url": "https://nec.example", + "type": "leo", + "uid": "Blandit volutpat maecenas", }, "group": [ { "field": { "id": "id-migration", "isBroken": false, - "lang": "neque", + "lang": "gravida", "link_type": "Document", "tags": [], - "type": "lacus", - "url": "https://cras.example", + "type": "leo", + "uid": "Blandit volutpat maecenas", }, }, ], @@ -819,11 +742,13 @@ exports[`patches link fields > otherRepositoryContentRelationship > slice 1`] = "field": { "id": "id-migration", "isBroken": false, - "lang": "enim,", + "lang": "ultrices", "link_type": "Document", - "tags": [], - "type": "felis_donec", - "url": "https://sem.example", + "tags": [ + "Ipsum Consequat", + ], + "type": "eget", + "uid": "Amet dictum sit", }, }, ], @@ -831,11 +756,13 @@ exports[`patches link fields > otherRepositoryContentRelationship > slice 1`] = "field": { "id": "id-migration", "isBroken": false, - "lang": "ac", + "lang": "ultrices", "link_type": "Document", - "tags": [], - "type": "enim_praesent", - "url": "https://sit.example", + "tags": [ + "Ipsum Consequat", + ], + "type": "eget", + "uid": "Amet dictum sit", }, }, "slice_label": "Pellentesque", @@ -850,11 +777,11 @@ exports[`patches link fields > otherRepositoryContentRelationship > static zone "field": { "id": "id-migration", "isBroken": false, - "lang": "elementum", + "lang": "nisi,", "link_type": "Document", "tags": [], - "type": "aenean", - "url": "https://volutpat.example", + "type": "eros", + "uid": "Scelerisque mauris pellentesque", }, } `; @@ -1106,583 +1033,3 @@ exports[`patches link fields > richTextLinkNode > static zone 1`] = ` ], } `; - -exports[`patches link fields > richTextNewImageNodeLink > group 1`] = ` -{ - "group": [ - { - "field": [ - { - "spans": [], - "text": "Nulla Aliquet Porttitor Lacus Luctus", - "type": "heading2", - }, - { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, - }, - "id": "cdfdd322ca9", - "linkTo": { - "id": "id-existing", - "isBroken": false, - "lang": "laoreet", - "link_type": "Document", - "tags": [], - "type": "orci", - }, - "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c?w=6000&h=4000&fit=crop", - }, - ], - }, - ], -} -`; - -exports[`patches link fields > richTextNewImageNodeLink > shared slice 1`] = ` -{ - "slices": [ - { - "id": "2ff58c741ba", - "items": [ - { - "field": [ - { - "spans": [], - "text": "Eu Mi", - "type": "heading3", - }, - { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, - }, - "id": "bc31787853a", - "linkTo": { - "id": "id-existing", - "isBroken": false, - "lang": "tortor,", - "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", - }, - "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", - }, - ], - }, - ], - "primary": { - "field": [ - { - "spans": [], - "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", - "type": "heading3", - }, - { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, - }, - "id": "bc31787853a", - "linkTo": { - "id": "id-existing", - "isBroken": false, - "lang": "tortor,", - "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", - }, - "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", - }, - ], - "group": [ - { - "field": [ - { - "spans": [], - "text": "Arcu", - "type": "heading1", - }, - { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, - }, - "id": "bc31787853a", - "linkTo": { - "id": "id-existing", - "isBroken": false, - "lang": "tortor,", - "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", - }, - "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", - }, - ], - }, - ], - }, - "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", - }, - ], -} -`; - -exports[`patches link fields > richTextNewImageNodeLink > slice 1`] = ` -{ - "slices": [ - { - "id": "e93cc3e4f28", - "items": [ - { - "field": [ - { - "spans": [], - "text": "Habitasse platea dictumst quisque sagittis purus sit", - "type": "o-list-item", - }, - { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, - }, - "id": "7963dc361cc", - "linkTo": { - "id": "id-existing", - "isBroken": false, - "lang": "sapien", - "link_type": "Document", - "tags": [ - "Aenean", - ], - "type": "amet", - }, - "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", - }, - ], - }, - ], - "primary": { - "field": [ - { - "spans": [], - "text": "Ac Orci Phasellus Egestas Tellus", - "type": "heading5", - }, - { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, - }, - "id": "7963dc361cc", - "linkTo": { - "id": "id-existing", - "isBroken": false, - "lang": "sapien", - "link_type": "Document", - "tags": [ - "Aenean", - ], - "type": "amet", - }, - "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", - }, - ], - }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", - }, - ], -} -`; - -exports[`patches link fields > richTextNewImageNodeLink > static zone 1`] = ` -{ - "field": [ - { - "spans": [], - "text": "Elementum Integer", - "type": "heading6", - }, - { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, - }, - "id": "0bbad670dad", - "linkTo": { - "id": "id-existing", - "isBroken": false, - "lang": "eget", - "link_type": "Document", - "tags": [], - "type": "phasellus", - }, - "type": "image", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", - }, - ], -} -`; - -exports[`patches link fields > richTextOtherReposiotryImageNodeLink > group 1`] = ` -{ - "group": [ - { - "field": [ - { - "spans": [], - "text": "Nulla Aliquet Porttitor Lacus Luctus", - "type": "heading2", - }, - { - "alt": "Donec enim diam vulputate ut pharetra sit amet aliquam id diam", - "copyright": null, - "dimensions": { - "height": 4000, - "width": 6000, - }, - "edit": { - "background": "#7cfc26", - "x": 2977, - "y": -1163, - "zoom": 1.0472585898934068, - }, - "id": "e8d0985c099", - "linkTo": { - "id": "id-existing", - "isBroken": false, - "lang": "laoreet", - "link_type": "Document", - "tags": [], - "type": "orci", - }, - "type": "image", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b", - }, - ], - }, - ], -} -`; - -exports[`patches link fields > richTextOtherReposiotryImageNodeLink > shared slice 1`] = ` -{ - "slices": [ - { - "id": "2ff58c741ba", - "items": [ - { - "field": [ - { - "spans": [], - "text": "Facilisis", - "type": "heading3", - }, - { - "alt": "Nullam vehicula ipsum a arcu cursus vitae congue mauris rhoncus aenean vel elit scelerisque", - "copyright": null, - "dimensions": { - "height": 4392, - "width": 7372, - }, - "edit": { - "background": "#37ae3f", - "x": -1505, - "y": 902, - "zoom": 1.8328975606320652, - }, - "id": "3fc0dfa9fe9", - "linkTo": { - "id": "id-existing", - "isBroken": false, - "lang": "tortor,", - "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", - }, - "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", - }, - ], - }, - ], - "primary": { - "field": [ - { - "spans": [], - "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", - "type": "heading3", - }, - { - "alt": "Proin libero nunc consequat interdum varius", - "copyright": null, - "dimensions": { - "height": 3036, - "width": 4554, - }, - "edit": { - "background": "#904f4f", - "x": 1462, - "y": 1324, - "zoom": 1.504938844941775, - }, - "id": "3fc0dfa9fe9", - "linkTo": { - "id": "id-existing", - "isBroken": false, - "lang": "tortor,", - "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", - }, - "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", - }, - ], - "group": [ - { - "field": [ - { - "spans": [], - "text": "Egestas Integer Eget Aliquet Nibh", - "type": "heading5", - }, - { - "alt": "Arcu cursus vitae congue mauris", - "copyright": null, - "dimensions": { - "height": 4392, - "width": 7372, - }, - "edit": { - "background": "#5f7a9b", - "x": -119, - "y": -2667, - "zoom": 1.9681315715350518, - }, - "id": "3fc0dfa9fe9", - "linkTo": { - "id": "id-existing", - "isBroken": false, - "lang": "tortor,", - "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", - }, - "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", - }, - ], - }, - ], - }, - "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", - }, - ], -} -`; - -exports[`patches link fields > richTextOtherReposiotryImageNodeLink > slice 1`] = ` -{ - "slices": [ - { - "id": "e93cc3e4f28", - "items": [ - { - "field": [ - { - "spans": [], - "text": "Amet", - "type": "heading5", - }, - { - "alt": "Auctor neque vitae tempus quam", - "copyright": null, - "dimensions": { - "height": 1440, - "width": 2560, - }, - "edit": { - "background": "#5bc5aa", - "x": -1072, - "y": -281, - "zoom": 1.3767766101231744, - }, - "id": "f70ca27104d", - "linkTo": { - "id": "id-existing", - "isBroken": false, - "lang": "sapien", - "link_type": "Document", - "tags": [ - "Aenean", - ], - "type": "amet", - }, - "type": "image", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", - }, - ], - }, - ], - "primary": { - "field": [ - { - "spans": [], - "text": "Ac Orci Phasellus Egestas Tellus", - "type": "heading5", - }, - { - "alt": "Urna id volutpat lacus laoreet non curabitur gravida arcu ac tortor", - "copyright": null, - "dimensions": { - "height": 3036, - "width": 4554, - }, - "edit": { - "background": "#4860cb", - "x": 280, - "y": -379, - "zoom": 1.2389796902982004, - }, - "id": "f70ca27104d", - "linkTo": { - "id": "id-existing", - "isBroken": false, - "lang": "sapien", - "link_type": "Document", - "tags": [ - "Aenean", - ], - "type": "amet", - }, - "type": "image", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", - }, - ], - }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", - }, - ], -} -`; - -exports[`patches link fields > richTextOtherReposiotryImageNodeLink > static zone 1`] = ` -{ - "field": [ - { - "spans": [], - "text": "Elementum Integer", - "type": "heading6", - }, - { - "alt": "Interdum velit euismod in pellentesque", - "copyright": null, - "dimensions": { - "height": 4392, - "width": 7372, - }, - "edit": { - "background": "#ab1d17", - "x": 3605, - "y": 860, - "zoom": 1.9465488211593005, - }, - "id": "04a95cc61c3", - "linkTo": { - "id": "id-existing", - "isBroken": false, - "lang": "eget", - "link_type": "Document", - "tags": [], - "type": "phasellus", - }, - "type": "image", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", - }, - ], -} -`; diff --git a/test/__snapshots__/writeClient-migrate-patch-image.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-image.test.ts.snap index daa3e7f0..1a477d27 100644 --- a/test/__snapshots__/writeClient-migrate-patch-image.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-image.test.ts.snap @@ -15,7 +15,7 @@ exports[`patches image fields > existing > group 1`] = ` "background": "transparent", "x": 0, "y": 0, - "zoom": 0, + "zoom": 1, }, "id": "id-existing", "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", @@ -43,7 +43,7 @@ exports[`patches image fields > existing > shared slice 1`] = ` "background": "transparent", "x": 0, "y": 0, - "zoom": 0, + "zoom": 1, }, "id": "id-existing", "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", @@ -62,7 +62,7 @@ exports[`patches image fields > existing > shared slice 1`] = ` "background": "transparent", "x": 0, "y": 0, - "zoom": 0, + "zoom": 1, }, "id": "id-existing", "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", @@ -80,7 +80,7 @@ exports[`patches image fields > existing > shared slice 1`] = ` "background": "transparent", "x": 0, "y": 0, - "zoom": 0, + "zoom": 1, }, "id": "id-existing", "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", @@ -115,7 +115,7 @@ exports[`patches image fields > existing > slice 1`] = ` "background": "transparent", "x": 0, "y": 0, - "zoom": 0, + "zoom": 1, }, "id": "id-existing", "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", @@ -134,7 +134,7 @@ exports[`patches image fields > existing > slice 1`] = ` "background": "transparent", "x": 0, "y": 0, - "zoom": 0, + "zoom": 1, }, "id": "id-existing", "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", @@ -160,7 +160,7 @@ exports[`patches image fields > existing > static zone 1`] = ` "background": "transparent", "x": 0, "y": 0, - "zoom": 0, + "zoom": 1, }, "id": "id-existing", "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", @@ -183,7 +183,7 @@ exports[`patches image fields > new > group 1`] = ` "background": "transparent", "x": 0, "y": 0, - "zoom": 0, + "zoom": 1, }, "id": "ef95d5daa4d", "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?w=2560&h=1705&fit=crop", @@ -211,7 +211,7 @@ exports[`patches image fields > new > shared slice 1`] = ` "background": "transparent", "x": 0, "y": 0, - "zoom": 0, + "zoom": 1, }, "id": "f2c3f8bfc90", "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", @@ -230,7 +230,7 @@ exports[`patches image fields > new > shared slice 1`] = ` "background": "transparent", "x": 0, "y": 0, - "zoom": 0, + "zoom": 1, }, "id": "f2c3f8bfc90", "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", @@ -248,7 +248,7 @@ exports[`patches image fields > new > shared slice 1`] = ` "background": "transparent", "x": 0, "y": 0, - "zoom": 0, + "zoom": 1, }, "id": "f2c3f8bfc90", "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", @@ -283,7 +283,7 @@ exports[`patches image fields > new > slice 1`] = ` "background": "transparent", "x": 0, "y": 0, - "zoom": 0, + "zoom": 1, }, "id": "45306297c5e", "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", @@ -302,7 +302,7 @@ exports[`patches image fields > new > slice 1`] = ` "background": "transparent", "x": 0, "y": 0, - "zoom": 0, + "zoom": 1, }, "id": "45306297c5e", "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", @@ -328,7 +328,7 @@ exports[`patches image fields > new > static zone 1`] = ` "background": "transparent", "x": 0, "y": 0, - "zoom": 0, + "zoom": 1, }, "id": "c5c95f8d3ac", "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", @@ -344,8 +344,8 @@ exports[`patches image fields > otherRepository > group 1`] = ` "alt": "Odio ut enim blandit volutpat maecenas volutpat blandit", "copyright": null, "dimensions": { - "height": 1705, - "width": 2560, + "height": 1, + "width": 1, }, "edit": { "background": "#fdb338", @@ -372,8 +372,8 @@ exports[`patches image fields > otherRepository > shared slice 1`] = ` "alt": "Vitae et leo duis ut diam quam nulla porttitor massa id neque aliquam vestibulum", "copyright": null, "dimensions": { - "height": 4000, - "width": 6000, + "height": 1, + "width": 1, }, "edit": { "background": "#61adcf", @@ -391,8 +391,8 @@ exports[`patches image fields > otherRepository > shared slice 1`] = ` "alt": "Ut consequat semper viverra nam libero justo laoreet", "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#8efd5a", @@ -409,8 +409,8 @@ exports[`patches image fields > otherRepository > shared slice 1`] = ` "alt": "Porttitor massa id neque aliquam vestibulum morbi blandit", "copyright": null, "dimensions": { - "height": 4392, - "width": 7372, + "height": 1, + "width": 1, }, "edit": { "background": "#bc3178", @@ -444,8 +444,8 @@ exports[`patches image fields > otherRepository > slice 1`] = ` "alt": "Vitae sapien pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis", "copyright": null, "dimensions": { - "height": 4000, - "width": 6000, + "height": 1, + "width": 1, }, "edit": { "background": "#c361cc", @@ -463,8 +463,8 @@ exports[`patches image fields > otherRepository > slice 1`] = ` "alt": "Nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc consequat interdum varius sit", "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#55e3be", @@ -489,8 +489,8 @@ exports[`patches image fields > otherRepository > static zone 1`] = ` "alt": "Vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae elementum curabitur vitae nunc sed", "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#97acc6", @@ -508,7 +508,13 @@ exports[`patches image fields > otherRepositoryEmpty > group 1`] = ` { "group": [ { - "field": {}, + "field": { + "alt": null, + "copyright": null, + "dimensions": null, + "id": null, + "url": null, + }, }, ], } @@ -521,14 +527,32 @@ exports[`patches image fields > otherRepositoryEmpty > shared slice 1`] = ` "id": "2ff58c741ba", "items": [ { - "field": {}, + "field": { + "alt": null, + "copyright": null, + "dimensions": null, + "id": null, + "url": null, + }, }, ], "primary": { - "field": {}, + "field": { + "alt": null, + "copyright": null, + "dimensions": null, + "id": null, + "url": null, + }, "group": [ { - "field": {}, + "field": { + "alt": null, + "copyright": null, + "dimensions": null, + "id": null, + "url": null, + }, }, ], }, @@ -548,11 +572,23 @@ exports[`patches image fields > otherRepositoryEmpty > slice 1`] = ` "id": "e93cc3e4f28", "items": [ { - "field": {}, + "field": { + "alt": null, + "copyright": null, + "dimensions": null, + "id": null, + "url": null, + }, }, ], "primary": { - "field": {}, + "field": { + "alt": null, + "copyright": null, + "dimensions": null, + "id": null, + "url": null, + }, }, "slice_label": "Pellentesque", "slice_type": "nulla_posuere", @@ -563,7 +599,13 @@ exports[`patches image fields > otherRepositoryEmpty > slice 1`] = ` exports[`patches image fields > otherRepositoryEmpty > static zone 1`] = ` { - "field": {}, + "field": { + "alt": null, + "copyright": null, + "dimensions": null, + "id": null, + "url": null, + }, } `; @@ -575,8 +617,8 @@ exports[`patches image fields > otherRepositoryWithThumbnails > group 1`] = ` "alt": "Odio ut enim blandit volutpat maecenas volutpat blandit", "copyright": null, "dimensions": { - "height": 1705, - "width": 2560, + "height": 1, + "width": 1, }, "edit": { "background": "#fdb338", @@ -589,8 +631,8 @@ exports[`patches image fields > otherRepositoryWithThumbnails > group 1`] = ` "alt": "Odio ut enim blandit volutpat maecenas volutpat blandit", "copyright": null, "dimensions": { - "height": 1705, - "width": 2560, + "height": 1, + "width": 1, }, "edit": { "background": "#fdb338", @@ -619,8 +661,8 @@ exports[`patches image fields > otherRepositoryWithThumbnails > shared slice 1`] "alt": "Vitae et leo duis ut diam quam nulla porttitor massa id neque aliquam vestibulum", "copyright": null, "dimensions": { - "height": 4000, - "width": 6000, + "height": 1, + "width": 1, }, "edit": { "background": "#61adcf", @@ -633,8 +675,8 @@ exports[`patches image fields > otherRepositoryWithThumbnails > shared slice 1`] "alt": "Vitae et leo duis ut diam quam nulla porttitor massa id neque aliquam vestibulum", "copyright": null, "dimensions": { - "height": 4000, - "width": 6000, + "height": 1, + "width": 1, }, "edit": { "background": "#61adcf", @@ -654,8 +696,8 @@ exports[`patches image fields > otherRepositoryWithThumbnails > shared slice 1`] "alt": "Ut consequat semper viverra nam libero justo laoreet", "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#8efd5a", @@ -668,8 +710,8 @@ exports[`patches image fields > otherRepositoryWithThumbnails > shared slice 1`] "alt": "Ut consequat semper viverra nam libero justo laoreet", "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#8efd5a", @@ -688,8 +730,8 @@ exports[`patches image fields > otherRepositoryWithThumbnails > shared slice 1`] "alt": "Porttitor massa id neque aliquam vestibulum morbi blandit", "copyright": null, "dimensions": { - "height": 4392, - "width": 7372, + "height": 1, + "width": 1, }, "edit": { "background": "#bc3178", @@ -702,8 +744,8 @@ exports[`patches image fields > otherRepositoryWithThumbnails > shared slice 1`] "alt": "Porttitor massa id neque aliquam vestibulum morbi blandit", "copyright": null, "dimensions": { - "height": 4392, - "width": 7372, + "height": 1, + "width": 1, }, "edit": { "background": "#bc3178", @@ -739,8 +781,8 @@ exports[`patches image fields > otherRepositoryWithThumbnails > slice 1`] = ` "alt": "Vitae sapien pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis", "copyright": null, "dimensions": { - "height": 4000, - "width": 6000, + "height": 1, + "width": 1, }, "edit": { "background": "#c361cc", @@ -753,8 +795,8 @@ exports[`patches image fields > otherRepositoryWithThumbnails > slice 1`] = ` "alt": "Vitae sapien pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis", "copyright": null, "dimensions": { - "height": 4000, - "width": 6000, + "height": 1, + "width": 1, }, "edit": { "background": "#c361cc", @@ -774,8 +816,8 @@ exports[`patches image fields > otherRepositoryWithThumbnails > slice 1`] = ` "alt": "Nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc consequat interdum varius sit", "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#55e3be", @@ -788,8 +830,8 @@ exports[`patches image fields > otherRepositoryWithThumbnails > slice 1`] = ` "alt": "Nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc consequat interdum varius sit", "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#55e3be", @@ -816,8 +858,8 @@ exports[`patches image fields > otherRepositoryWithThumbnails > static zone 1`] "alt": "Vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae elementum curabitur vitae nunc sed", "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#97acc6", @@ -830,8 +872,8 @@ exports[`patches image fields > otherRepositoryWithThumbnails > static zone 1`] "alt": "Vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae elementum curabitur vitae nunc sed", "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#97acc6", @@ -855,8 +897,8 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > group 1`] = "alt": null, "copyright": null, "dimensions": { - "height": 1705, - "width": 2560, + "height": 1, + "width": 1, }, "edit": { "background": "#fdb338", @@ -869,8 +911,8 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > group 1`] = "alt": null, "copyright": null, "dimensions": { - "height": 1705, - "width": 2560, + "height": 1, + "width": 1, }, "edit": { "background": "#fdb338", @@ -899,8 +941,8 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "alt": null, "copyright": null, "dimensions": { - "height": 4000, - "width": 6000, + "height": 1, + "width": 1, }, "edit": { "background": "#61adcf", @@ -913,8 +955,8 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "alt": null, "copyright": null, "dimensions": { - "height": 4000, - "width": 6000, + "height": 1, + "width": 1, }, "edit": { "background": "#61adcf", @@ -934,8 +976,8 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "alt": null, "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#8efd5a", @@ -948,8 +990,8 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "alt": null, "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#8efd5a", @@ -968,8 +1010,8 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "alt": null, "copyright": null, "dimensions": { - "height": 4392, - "width": 7372, + "height": 1, + "width": 1, }, "edit": { "background": "#bc3178", @@ -982,8 +1024,8 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "alt": null, "copyright": null, "dimensions": { - "height": 4392, - "width": 7372, + "height": 1, + "width": 1, }, "edit": { "background": "#bc3178", @@ -1019,8 +1061,8 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > slice 1`] = "alt": null, "copyright": null, "dimensions": { - "height": 4000, - "width": 6000, + "height": 1, + "width": 1, }, "edit": { "background": "#c361cc", @@ -1033,8 +1075,8 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > slice 1`] = "alt": null, "copyright": null, "dimensions": { - "height": 4000, - "width": 6000, + "height": 1, + "width": 1, }, "edit": { "background": "#c361cc", @@ -1054,8 +1096,8 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > slice 1`] = "alt": null, "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#55e3be", @@ -1068,8 +1110,8 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > slice 1`] = "alt": null, "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#55e3be", @@ -1096,8 +1138,8 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > static zone "alt": null, "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#97acc6", @@ -1110,8 +1152,8 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > static zone "alt": null, "copyright": null, "dimensions": { - "height": 2832, - "width": 4240, + "height": 1, + "width": 1, }, "edit": { "background": "#97acc6", @@ -1127,123 +1169,155 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > static zone } `; -exports[`patches image fields > richTextExisting > group 1`] = ` +exports[`patches image fields > otherRepositoryWithTypeThumbnail > group 1`] = ` { "group": [ { - "field": [ - { - "spans": [], - "text": "Nulla Aliquet Porttitor Lacus Luctus", - "type": "heading2", + "field": { + "alt": "Odio ut enim blandit volutpat maecenas volutpat blandit", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, }, - { - "alt": null, + "edit": { + "background": "#fdb338", + "x": 349, + "y": 115, + "zoom": 1.5951464943576479, + }, + "id": "4dcf07cfc26", + "type": { + "alt": "Odio ut enim blandit volutpat maecenas volutpat blandit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, + "background": "#fdb338", + "x": 349, + "y": 115, + "zoom": 1.5951464943576479, }, - "id": "id-existing", - "type": "image", - "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", + "id": "4dcf07cfc26", + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?some=other&query=params", }, - ], + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?some=query", + }, }, ], } `; -exports[`patches image fields > richTextExisting > shared slice 1`] = ` +exports[`patches image fields > otherRepositoryWithTypeThumbnail > shared slice 1`] = ` { "slices": [ { "id": "2ff58c741ba", "items": [ { - "field": [ - { - "spans": [], - "text": "Eu Mi", - "type": "heading3", + "field": { + "alt": "Vitae et leo duis ut diam quam nulla porttitor massa id neque aliquam vestibulum", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, }, - { - "alt": null, + "edit": { + "background": "#61adcf", + "x": -1586, + "y": -2819, + "zoom": 1.9393723758262054, + }, + "id": "f5dbf0d9ed2", + "type": { + "alt": "Vitae et leo duis ut diam quam nulla porttitor massa id neque aliquam vestibulum", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, + "background": "#61adcf", + "x": -1586, + "y": -2819, + "zoom": 1.9393723758262054, }, - "id": "id-existing", - "type": "image", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "id": "f5dbf0d9ed2", + "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=other&query=params", }, - ], + "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=query", + }, }, ], "primary": { - "field": [ - { - "spans": [], - "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", - "type": "heading3", + "field": { + "alt": "Ut consequat semper viverra nam libero justo laoreet", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, }, - { - "alt": null, + "edit": { + "background": "#8efd5a", + "x": 466, + "y": -571, + "zoom": 1.394663850868741, + }, + "id": "f5dbf0d9ed2", + "type": { + "alt": "Ut consequat semper viverra nam libero justo laoreet", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, + "background": "#8efd5a", + "x": 466, + "y": -571, + "zoom": 1.394663850868741, }, - "id": "id-existing", - "type": "image", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "id": "f5dbf0d9ed2", + "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=other&query=params", }, - ], + "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=query", + }, "group": [ { - "field": [ - { - "spans": [], - "text": "Arcu", - "type": "heading1", + "field": { + "alt": "Porttitor massa id neque aliquam vestibulum morbi blandit", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, }, - { - "alt": null, + "edit": { + "background": "#bc3178", + "x": 1156, + "y": -2223, + "zoom": 1.602826201962965, + }, + "id": "f5dbf0d9ed2", + "type": { + "alt": "Porttitor massa id neque aliquam vestibulum morbi blandit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, + "background": "#bc3178", + "x": 1156, + "y": -2223, + "zoom": 1.602826201962965, }, - "id": "id-existing", - "type": "image", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "id": "f5dbf0d9ed2", + "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=other&query=params", }, - ], + "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=query", + }, }, ], }, @@ -1256,288 +1330,80 @@ exports[`patches image fields > richTextExisting > shared slice 1`] = ` } `; -exports[`patches image fields > richTextExisting > slice 1`] = ` +exports[`patches image fields > otherRepositoryWithTypeThumbnail > slice 1`] = ` { "slices": [ { "id": "e93cc3e4f28", "items": [ { - "field": [ - { - "spans": [], - "text": "Habitasse platea dictumst quisque sagittis purus sit", - "type": "o-list-item", + "field": { + "alt": "Vitae sapien pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, }, - { - "alt": null, + "edit": { + "background": "#c361cc", + "x": -751, + "y": -404, + "zoom": 1.6465649620272602, + }, + "id": "4f4a69ff72d", + "type": { + "alt": "Vitae sapien pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, + "background": "#c361cc", + "x": -751, + "y": -404, + "zoom": 1.6465649620272602, }, - "id": "id-existing", - "type": "image", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "id": "4f4a69ff72d", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=other&query=params", }, - ], + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=query", + }, }, ], "primary": { - "field": [ - { - "spans": [], - "text": "Ac Orci Phasellus Egestas Tellus", - "type": "heading5", + "field": { + "alt": "Nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc consequat interdum varius sit", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, }, - { - "alt": null, + "edit": { + "background": "#55e3be", + "x": -762, + "y": 991, + "zoom": 1.0207384987782544, + }, + "id": "4f4a69ff72d", + "type": { + "alt": "Nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc consequat interdum varius sit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, + "background": "#55e3be", + "x": -762, + "y": 991, + "zoom": 1.0207384987782544, }, - "id": "id-existing", - "type": "image", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", - }, - ], - }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", - }, - ], -} -`; - -exports[`patches image fields > richTextExisting > static zone 1`] = ` -{ - "field": [ - { - "spans": [], - "text": "Elementum Integer", - "type": "heading6", - }, - { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, - }, - "id": "id-existing", - "type": "image", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", - }, - ], -} -`; - -exports[`patches image fields > richTextNew > group 1`] = ` -{ - "group": [ - { - "field": [ - { - "spans": [], - "text": "Nulla Aliquet Porttitor Lacus Luctus", - "type": "heading2", - }, - { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, + "id": "4f4a69ff72d", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=other&query=params", }, - "id": "cdfdd322ca9", - "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c?w=6000&h=4000&fit=crop", - }, - ], - }, - ], -} -`; - -exports[`patches image fields > richTextNew > shared slice 1`] = ` -{ - "slices": [ - { - "id": "2ff58c741ba", - "items": [ - { - "field": [ - { - "spans": [], - "text": "Eu Mi", - "type": "heading3", - }, - { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, - }, - "id": "bc31787853a", - "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", - }, - ], + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=query", }, - ], - "primary": { - "field": [ - { - "spans": [], - "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", - "type": "heading3", - }, - { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, - }, - "id": "bc31787853a", - "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", - }, - ], - "group": [ - { - "field": [ - { - "spans": [], - "text": "Arcu", - "type": "heading1", - }, - { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, - }, - "id": "bc31787853a", - "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", - }, - ], - }, - ], - }, - "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", - }, - ], -} -`; - -exports[`patches image fields > richTextNew > slice 1`] = ` -{ - "slices": [ - { - "id": "e93cc3e4f28", - "items": [ - { - "field": [ - { - "spans": [], - "text": "Habitasse platea dictumst quisque sagittis purus sit", - "type": "o-list-item", - }, - { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, - }, - "id": "7963dc361cc", - "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", - }, - ], - }, - ], - "primary": { - "field": [ - { - "spans": [], - "text": "Ac Orci Phasellus Egestas Tellus", - "type": "heading5", - }, - { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, - }, - "id": "7963dc361cc", - "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", - }, - ], }, "slice_label": "Pellentesque", "slice_type": "nulla_posuere", @@ -1546,255 +1412,39 @@ exports[`patches image fields > richTextNew > slice 1`] = ` } `; -exports[`patches image fields > richTextNew > static zone 1`] = ` +exports[`patches image fields > otherRepositoryWithTypeThumbnail > static zone 1`] = ` { - "field": [ - { - "spans": [], - "text": "Elementum Integer", - "type": "heading6", + "field": { + "alt": "Vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae elementum curabitur vitae nunc sed", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, }, - { - "alt": null, + "edit": { + "background": "#97acc6", + "x": 1922, + "y": -967, + "zoom": 1.9765406541937358, + }, + "id": "9abffab1d17", + "type": { + "alt": "Vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae elementum curabitur vitae nunc sed", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 0, - }, - "id": "0bbad670dad", - "type": "image", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", - }, - ], -} -`; - -exports[`patches image fields > richTextOtherRepository > group 1`] = ` -{ - "group": [ - { - "field": [ - { - "spans": [], - "text": "Nulla Aliquet Porttitor Lacus Luctus", - "type": "heading2", - }, - { - "alt": "Donec enim diam vulputate ut pharetra sit amet aliquam id diam", - "copyright": null, - "dimensions": { - "height": 4000, - "width": 6000, - }, - "edit": { - "background": "#7cfc26", - "x": 2977, - "y": -1163, - "zoom": 1.0472585898934068, - }, - "id": "e8d0985c099", - "type": "image", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b", - }, - ], - }, - ], -} -`; - -exports[`patches image fields > richTextOtherRepository > shared slice 1`] = ` -{ - "slices": [ - { - "id": "2ff58c741ba", - "items": [ - { - "field": [ - { - "spans": [], - "text": "Facilisis", - "type": "heading3", - }, - { - "alt": "Nullam vehicula ipsum a arcu cursus vitae congue mauris rhoncus aenean vel elit scelerisque", - "copyright": null, - "dimensions": { - "height": 4392, - "width": 7372, - }, - "edit": { - "background": "#37ae3f", - "x": -1505, - "y": 902, - "zoom": 1.8328975606320652, - }, - "id": "3fc0dfa9fe9", - "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", - }, - ], - }, - ], - "primary": { - "field": [ - { - "spans": [], - "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", - "type": "heading3", - }, - { - "alt": "Proin libero nunc consequat interdum varius", - "copyright": null, - "dimensions": { - "height": 3036, - "width": 4554, - }, - "edit": { - "background": "#904f4f", - "x": 1462, - "y": 1324, - "zoom": 1.504938844941775, - }, - "id": "3fc0dfa9fe9", - "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", - }, - ], - "group": [ - { - "field": [ - { - "spans": [], - "text": "Egestas Integer Eget Aliquet Nibh", - "type": "heading5", - }, - { - "alt": "Arcu cursus vitae congue mauris", - "copyright": null, - "dimensions": { - "height": 4392, - "width": 7372, - }, - "edit": { - "background": "#5f7a9b", - "x": -119, - "y": -2667, - "zoom": 1.9681315715350518, - }, - "id": "3fc0dfa9fe9", - "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", - }, - ], - }, - ], - }, - "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", - }, - ], -} -`; - -exports[`patches image fields > richTextOtherRepository > slice 1`] = ` -{ - "slices": [ - { - "id": "e93cc3e4f28", - "items": [ - { - "field": [ - { - "spans": [], - "text": "Amet", - "type": "heading5", - }, - { - "alt": "Auctor neque vitae tempus quam", - "copyright": null, - "dimensions": { - "height": 1440, - "width": 2560, - }, - "edit": { - "background": "#5bc5aa", - "x": -1072, - "y": -281, - "zoom": 1.3767766101231744, - }, - "id": "f70ca27104d", - "type": "image", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", - }, - ], - }, - ], - "primary": { - "field": [ - { - "spans": [], - "text": "Ac Orci Phasellus Egestas Tellus", - "type": "heading5", - }, - { - "alt": "Urna id volutpat lacus laoreet non curabitur gravida arcu ac tortor", - "copyright": null, - "dimensions": { - "height": 3036, - "width": 4554, - }, - "edit": { - "background": "#4860cb", - "x": 280, - "y": -379, - "zoom": 1.2389796902982004, - }, - "id": "f70ca27104d", - "type": "image", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", - }, - ], - }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", - }, - ], -} -`; - -exports[`patches image fields > richTextOtherRepository > static zone 1`] = ` -{ - "field": [ - { - "spans": [], - "text": "Elementum Integer", - "type": "heading6", - }, - { - "alt": "Interdum velit euismod in pellentesque", - "copyright": null, - "dimensions": { - "height": 4392, - "width": 7372, - }, - "edit": { - "background": "#ab1d17", - "x": 3605, - "y": 860, - "zoom": 1.9465488211593005, + "background": "#97acc6", + "x": 1922, + "y": -967, + "zoom": 1.9765406541937358, }, - "id": "04a95cc61c3", - "type": "image", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", + "id": "9abffab1d17", + "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=other&query=params", }, - ], + "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=query", + }, } `; diff --git a/test/__snapshots__/writeClient-migrate-patch-linkToMedia.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-linkToMedia.test.ts.snap index 7abdb040..2624fb3a 100644 --- a/test/__snapshots__/writeClient-migrate-patch-linkToMedia.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-linkToMedia.test.ts.snap @@ -369,14 +369,14 @@ exports[`patches link to media fields > otherRepository > group 1`] = ` "group": [ { "field": { - "height": "1715", + "height": "1", "id": "fdb33894dcf", - "kind": "purus", + "kind": "image", "link_type": "Media", - "name": "nulla.example", - "size": "2039", - "url": "https://db0f6f37ebeb6ea09489124345af2a45.example.com/foo.png", - "width": "2091", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "width": "1", }, }, ], @@ -391,39 +391,39 @@ exports[`patches link to media fields > otherRepository > shared slice 1`] = ` "items": [ { "field": { - "height": "2741", + "height": "1", "id": "ba97bfb16bf", - "kind": "quis", + "kind": "image", "link_type": "Media", - "name": "senectus.example", - "size": "844", - "url": "https://515f7ca1126821ccd3eb8b013a857528.example.com/foo.png", - "width": "749", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "width": "1", }, }, ], "primary": { "field": { - "height": "1276", + "height": "1", "id": "ba97bfb16bf", - "kind": "ullamcorper", + "kind": "image", "link_type": "Media", - "name": "fringilla.example", - "size": "818", - "url": "https://515f7ca1126821ccd3eb8b013a857528.example.com/foo.png", - "width": "2024", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "width": "1", }, "group": [ { "field": { - "height": "2964", + "height": "1", "id": "ba97bfb16bf", - "kind": "pellentesque", + "kind": "image", "link_type": "Media", - "name": "cras.example", - "size": "1564", - "url": "https://515f7ca1126821ccd3eb8b013a857528.example.com/foo.png", - "width": "599", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "width": "1", }, }, ], @@ -445,27 +445,27 @@ exports[`patches link to media fields > otherRepository > slice 1`] = ` "items": [ { "field": { - "height": "1500", + "height": "1", "id": "a57963dc361", - "kind": "quam", + "kind": "image", "link_type": "Media", - "name": "integer.example", - "size": "1043", - "url": "https://6d52012dca4fc77aa554f25430aef501.example.com/foo.png", - "width": "737", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "width": "1", }, }, ], "primary": { "field": { - "height": "761", + "height": "1", "id": "a57963dc361", - "kind": "nibh", + "kind": "image", "link_type": "Media", - "name": "ac.example", - "size": "2757", - "url": "https://6d52012dca4fc77aa554f25430aef501.example.com/foo.png", - "width": "1300", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "width": "1", }, }, "slice_label": "Pellentesque", @@ -478,91 +478,14 @@ exports[`patches link to media fields > otherRepository > slice 1`] = ` exports[`patches link to media fields > otherRepository > static zone 1`] = ` { "field": { - "height": "740", + "height": "1", "id": "97acc6e9abf", - "kind": "suspendisse", + "kind": "image", "link_type": "Media", - "name": "elementum.example", - "size": "556", - "url": "https://7713b5e0c356963c79ccf86c6ff1710c.example.com/foo.png", - "width": "2883", - }, -} -`; - -exports[`patches link to media fields > otherRepositoryNotFoundID > group 1`] = ` -{ - "group": [ - { - "field": { - "link_type": "Any", - }, - }, - ], -} -`; - -exports[`patches link to media fields > otherRepositoryNotFoundID > shared slice 1`] = ` -{ - "slices": [ - { - "id": "2ff58c741ba", - "items": [ - { - "field": { - "link_type": "Any", - }, - }, - ], - "primary": { - "field": { - "link_type": "Any", - }, - "group": [ - { - "field": { - "link_type": "Any", - }, - }, - ], - }, - "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", - }, - ], -} -`; - -exports[`patches link to media fields > otherRepositoryNotFoundID > slice 1`] = ` -{ - "slices": [ - { - "id": "e93cc3e4f28", - "items": [ - { - "field": { - "link_type": "Any", - }, - }, - ], - "primary": { - "field": { - "link_type": "Any", - }, - }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", - }, - ], -} -`; - -exports[`patches link to media fields > otherRepositoryNotFoundID > static zone 1`] = ` -{ - "field": { - "link_type": "Any", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", + "width": "1", }, } `; @@ -1085,14 +1008,14 @@ exports[`patches link to media fields > richTextOtherRepository > group 1`] = ` }, { "data": { - "height": "1715", + "height": "1", "id": "fdb33894dcf", - "kind": "purus", + "kind": "image", "link_type": "Media", - "name": "nulla.example", - "size": "2039", - "url": "https://db0f6f37ebeb6ea09489124345af2a45.example.com/foo.png", - "width": "2091", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "width": "1", }, "end": 5, "start": 0, @@ -1125,14 +1048,14 @@ exports[`patches link to media fields > richTextOtherRepository > shared slice 1 }, { "data": { - "height": "2741", + "height": "1", "id": "ba97bfb16bf", - "kind": "quis", + "kind": "image", "link_type": "Media", - "name": "senectus.example", - "size": "844", - "url": "https://515f7ca1126821ccd3eb8b013a857528.example.com/foo.png", - "width": "749", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "width": "1", }, "end": 5, "start": 0, @@ -1156,14 +1079,14 @@ exports[`patches link to media fields > richTextOtherRepository > shared slice 1 }, { "data": { - "height": "1276", + "height": "1", "id": "ba97bfb16bf", - "kind": "ullamcorper", + "kind": "image", "link_type": "Media", - "name": "fringilla.example", - "size": "818", - "url": "https://515f7ca1126821ccd3eb8b013a857528.example.com/foo.png", - "width": "2024", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "width": "1", }, "end": 5, "start": 0, @@ -1186,14 +1109,14 @@ exports[`patches link to media fields > richTextOtherRepository > shared slice 1 }, { "data": { - "height": "2964", + "height": "1", "id": "ba97bfb16bf", - "kind": "pellentesque", + "kind": "image", "link_type": "Media", - "name": "cras.example", - "size": "1564", - "url": "https://515f7ca1126821ccd3eb8b013a857528.example.com/foo.png", - "width": "599", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "width": "1", }, "end": 5, "start": 0, @@ -1233,14 +1156,14 @@ exports[`patches link to media fields > richTextOtherRepository > slice 1`] = ` }, { "data": { - "height": "1500", + "height": "1", "id": "a57963dc361", - "kind": "quam", + "kind": "image", "link_type": "Media", - "name": "integer.example", - "size": "1043", - "url": "https://6d52012dca4fc77aa554f25430aef501.example.com/foo.png", - "width": "737", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "width": "1", }, "end": 5, "start": 0, @@ -1264,14 +1187,14 @@ exports[`patches link to media fields > richTextOtherRepository > slice 1`] = ` }, { "data": { - "height": "761", + "height": "1", "id": "a57963dc361", - "kind": "nibh", + "kind": "image", "link_type": "Media", - "name": "ac.example", - "size": "2757", - "url": "https://6d52012dca4fc77aa554f25430aef501.example.com/foo.png", - "width": "1300", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "width": "1", }, "end": 5, "start": 0, @@ -1302,14 +1225,14 @@ exports[`patches link to media fields > richTextOtherRepository > static zone 1` }, { "data": { - "height": "740", + "height": "1", "id": "97acc6e9abf", - "kind": "suspendisse", + "kind": "image", "link_type": "Media", - "name": "elementum.example", - "size": "556", - "url": "https://7713b5e0c356963c79ccf86c6ff1710c.example.com/foo.png", - "width": "2883", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", + "width": "1", }, "end": 5, "start": 0, diff --git a/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap new file mode 100644 index 00000000..28421765 --- /dev/null +++ b/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap @@ -0,0 +1,1253 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`patches rich text image nodes > existing > group 1`] = ` +{ + "group": [ + { + "field": [ + { + "spans": [], + "text": "Nulla Aliquet Porttitor Lacus Luctus", + "type": "heading2", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "id-existing", + "type": "image", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", + }, + ], + }, + ], +} +`; + +exports[`patches rich text image nodes > existing > shared slice 1`] = ` +{ + "slices": [ + { + "id": "2ff58c741ba", + "items": [ + { + "field": [ + { + "spans": [], + "text": "Eu Mi", + "type": "heading3", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "id-existing", + "type": "image", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + }, + ], + }, + ], + "primary": { + "field": [ + { + "spans": [], + "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", + "type": "heading3", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "id-existing", + "type": "image", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + }, + ], + "group": [ + { + "field": [ + { + "spans": [], + "text": "Arcu", + "type": "heading1", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "id-existing", + "type": "image", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + }, + ], + }, + ], + }, + "slice_label": null, + "slice_type": "at", + "variation": "tortor", + "version": "a79b9dd", + }, + ], +} +`; + +exports[`patches rich text image nodes > existing > slice 1`] = ` +{ + "slices": [ + { + "id": "e93cc3e4f28", + "items": [ + { + "field": [ + { + "spans": [], + "text": "Habitasse platea dictumst quisque sagittis purus sit", + "type": "o-list-item", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "id-existing", + "type": "image", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + }, + ], + }, + ], + "primary": { + "field": [ + { + "spans": [], + "text": "Ac Orci Phasellus Egestas Tellus", + "type": "heading5", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "id-existing", + "type": "image", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + }, + ], + }, + "slice_label": "Pellentesque", + "slice_type": "nulla_posuere", + }, + ], +} +`; + +exports[`patches rich text image nodes > existing > static zone 1`] = ` +{ + "field": [ + { + "spans": [], + "text": "Elementum Integer", + "type": "heading6", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "id-existing", + "type": "image", + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", + }, + ], +} +`; + +exports[`patches rich text image nodes > new > group 1`] = ` +{ + "group": [ + { + "field": [ + { + "spans": [], + "text": "Nulla Aliquet Porttitor Lacus Luctus", + "type": "heading2", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "cdfdd322ca9", + "type": "image", + "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c?w=6000&h=4000&fit=crop", + }, + ], + }, + ], +} +`; + +exports[`patches rich text image nodes > new > shared slice 1`] = ` +{ + "slices": [ + { + "id": "2ff58c741ba", + "items": [ + { + "field": [ + { + "spans": [], + "text": "Eu Mi", + "type": "heading3", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "bc31787853a", + "type": "image", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + }, + ], + }, + ], + "primary": { + "field": [ + { + "spans": [], + "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", + "type": "heading3", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "bc31787853a", + "type": "image", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + }, + ], + "group": [ + { + "field": [ + { + "spans": [], + "text": "Arcu", + "type": "heading1", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "bc31787853a", + "type": "image", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + }, + ], + }, + ], + }, + "slice_label": null, + "slice_type": "at", + "variation": "tortor", + "version": "a79b9dd", + }, + ], +} +`; + +exports[`patches rich text image nodes > new > slice 1`] = ` +{ + "slices": [ + { + "id": "e93cc3e4f28", + "items": [ + { + "field": [ + { + "spans": [], + "text": "Habitasse platea dictumst quisque sagittis purus sit", + "type": "o-list-item", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "7963dc361cc", + "type": "image", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + }, + ], + }, + ], + "primary": { + "field": [ + { + "spans": [], + "text": "Ac Orci Phasellus Egestas Tellus", + "type": "heading5", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "7963dc361cc", + "type": "image", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + }, + ], + }, + "slice_label": "Pellentesque", + "slice_type": "nulla_posuere", + }, + ], +} +`; + +exports[`patches rich text image nodes > new > static zone 1`] = ` +{ + "field": [ + { + "spans": [], + "text": "Elementum Integer", + "type": "heading6", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "0bbad670dad", + "type": "image", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", + }, + ], +} +`; + +exports[`patches rich text image nodes > newLinkTo > group 1`] = ` +{ + "group": [ + { + "field": [ + { + "spans": [], + "text": "Nulla Aliquet Porttitor Lacus Luctus", + "type": "heading2", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "cdfdd322ca9", + "linkTo": { + "id": "id-existing", + "isBroken": false, + "lang": "laoreet", + "link_type": "Document", + "tags": [], + "type": "orci", + }, + "type": "image", + "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c?w=6000&h=4000&fit=crop", + }, + ], + }, + ], +} +`; + +exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` +{ + "slices": [ + { + "id": "2ff58c741ba", + "items": [ + { + "field": [ + { + "spans": [], + "text": "Eu Mi", + "type": "heading3", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "bc31787853a", + "linkTo": { + "id": "id-existing", + "isBroken": false, + "lang": "tortor,", + "link_type": "Document", + "tags": [ + "Risus In", + ], + "type": "dui", + }, + "type": "image", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + }, + ], + }, + ], + "primary": { + "field": [ + { + "spans": [], + "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", + "type": "heading3", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "bc31787853a", + "linkTo": { + "id": "id-existing", + "isBroken": false, + "lang": "tortor,", + "link_type": "Document", + "tags": [ + "Risus In", + ], + "type": "dui", + }, + "type": "image", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + }, + ], + "group": [ + { + "field": [ + { + "spans": [], + "text": "Arcu", + "type": "heading1", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "bc31787853a", + "linkTo": { + "id": "id-existing", + "isBroken": false, + "lang": "tortor,", + "link_type": "Document", + "tags": [ + "Risus In", + ], + "type": "dui", + }, + "type": "image", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + }, + ], + }, + ], + }, + "slice_label": null, + "slice_type": "at", + "variation": "tortor", + "version": "a79b9dd", + }, + ], +} +`; + +exports[`patches rich text image nodes > newLinkTo > slice 1`] = ` +{ + "slices": [ + { + "id": "e93cc3e4f28", + "items": [ + { + "field": [ + { + "spans": [], + "text": "Habitasse platea dictumst quisque sagittis purus sit", + "type": "o-list-item", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "7963dc361cc", + "linkTo": { + "id": "id-existing", + "isBroken": false, + "lang": "sapien", + "link_type": "Document", + "tags": [ + "Aenean", + ], + "type": "amet", + }, + "type": "image", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + }, + ], + }, + ], + "primary": { + "field": [ + { + "spans": [], + "text": "Ac Orci Phasellus Egestas Tellus", + "type": "heading5", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "7963dc361cc", + "linkTo": { + "id": "id-existing", + "isBroken": false, + "lang": "sapien", + "link_type": "Document", + "tags": [ + "Aenean", + ], + "type": "amet", + }, + "type": "image", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + }, + ], + }, + "slice_label": "Pellentesque", + "slice_type": "nulla_posuere", + }, + ], +} +`; + +exports[`patches rich text image nodes > newLinkTo > static zone 1`] = ` +{ + "field": [ + { + "spans": [], + "text": "Elementum Integer", + "type": "heading6", + }, + { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "0bbad670dad", + "linkTo": { + "id": "id-existing", + "isBroken": false, + "lang": "eget", + "link_type": "Document", + "tags": [], + "type": "phasellus", + }, + "type": "image", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", + }, + ], +} +`; + +exports[`patches rich text image nodes > otherRepository > group 1`] = ` +{ + "group": [ + { + "field": [ + { + "spans": [], + "text": "Nulla Aliquet Porttitor Lacus Luctus", + "type": "heading2", + }, + { + "alt": "Donec enim diam vulputate ut pharetra sit amet aliquam id diam", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#7cfc26", + "x": 2977, + "y": -1163, + "zoom": 1.0472585898934068, + }, + "id": "e8d0985c099", + "type": "image", + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b", + }, + ], + }, + ], +} +`; + +exports[`patches rich text image nodes > otherRepository > shared slice 1`] = ` +{ + "slices": [ + { + "id": "2ff58c741ba", + "items": [ + { + "field": [ + { + "spans": [], + "text": "Facilisis", + "type": "heading3", + }, + { + "alt": "Nullam vehicula ipsum a arcu cursus vitae congue mauris rhoncus aenean vel elit scelerisque", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#37ae3f", + "x": -1505, + "y": 902, + "zoom": 1.8328975606320652, + }, + "id": "3fc0dfa9fe9", + "type": "image", + "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", + }, + ], + }, + ], + "primary": { + "field": [ + { + "spans": [], + "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", + "type": "heading3", + }, + { + "alt": "Proin libero nunc consequat interdum varius", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#904f4f", + "x": 1462, + "y": 1324, + "zoom": 1.504938844941775, + }, + "id": "3fc0dfa9fe9", + "type": "image", + "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", + }, + ], + "group": [ + { + "field": [ + { + "spans": [], + "text": "Egestas Integer Eget Aliquet Nibh", + "type": "heading5", + }, + { + "alt": "Arcu cursus vitae congue mauris", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#5f7a9b", + "x": -119, + "y": -2667, + "zoom": 1.9681315715350518, + }, + "id": "3fc0dfa9fe9", + "type": "image", + "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", + }, + ], + }, + ], + }, + "slice_label": null, + "slice_type": "at", + "variation": "tortor", + "version": "a79b9dd", + }, + ], +} +`; + +exports[`patches rich text image nodes > otherRepository > slice 1`] = ` +{ + "slices": [ + { + "id": "e93cc3e4f28", + "items": [ + { + "field": [ + { + "spans": [], + "text": "Amet", + "type": "heading5", + }, + { + "alt": "Auctor neque vitae tempus quam", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#5bc5aa", + "x": -1072, + "y": -281, + "zoom": 1.3767766101231744, + }, + "id": "f70ca27104d", + "type": "image", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", + }, + ], + }, + ], + "primary": { + "field": [ + { + "spans": [], + "text": "Ac Orci Phasellus Egestas Tellus", + "type": "heading5", + }, + { + "alt": "Urna id volutpat lacus laoreet non curabitur gravida arcu ac tortor", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#4860cb", + "x": 280, + "y": -379, + "zoom": 1.2389796902982004, + }, + "id": "f70ca27104d", + "type": "image", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", + }, + ], + }, + "slice_label": "Pellentesque", + "slice_type": "nulla_posuere", + }, + ], +} +`; + +exports[`patches rich text image nodes > otherRepository > static zone 1`] = ` +{ + "field": [ + { + "spans": [], + "text": "Elementum Integer", + "type": "heading6", + }, + { + "alt": "Interdum velit euismod in pellentesque", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#ab1d17", + "x": 3605, + "y": 860, + "zoom": 1.9465488211593005, + }, + "id": "04a95cc61c3", + "type": "image", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", + }, + ], +} +`; + +exports[`patches rich text image nodes > otherRepositoryLinkTo > group 1`] = ` +{ + "group": [ + { + "field": [ + { + "spans": [], + "text": "Nulla Aliquet Porttitor Lacus Luctus", + "type": "heading2", + }, + { + "alt": "Donec enim diam vulputate ut pharetra sit amet aliquam id diam", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#7cfc26", + "x": 2977, + "y": -1163, + "zoom": 1.0472585898934068, + }, + "id": "e8d0985c099", + "linkTo": { + "id": "id-existing", + "isBroken": false, + "lang": "laoreet", + "link_type": "Document", + "tags": [], + "type": "orci", + }, + "type": "image", + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b", + }, + ], + }, + ], +} +`; + +exports[`patches rich text image nodes > otherRepositoryLinkTo > shared slice 1`] = ` +{ + "slices": [ + { + "id": "2ff58c741ba", + "items": [ + { + "field": [ + { + "spans": [], + "text": "Facilisis", + "type": "heading3", + }, + { + "alt": "Nullam vehicula ipsum a arcu cursus vitae congue mauris rhoncus aenean vel elit scelerisque", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#37ae3f", + "x": -1505, + "y": 902, + "zoom": 1.8328975606320652, + }, + "id": "3fc0dfa9fe9", + "linkTo": { + "id": "id-existing", + "isBroken": false, + "lang": "tortor,", + "link_type": "Document", + "tags": [ + "Risus In", + ], + "type": "dui", + }, + "type": "image", + "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", + }, + ], + }, + ], + "primary": { + "field": [ + { + "spans": [], + "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", + "type": "heading3", + }, + { + "alt": "Proin libero nunc consequat interdum varius", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#904f4f", + "x": 1462, + "y": 1324, + "zoom": 1.504938844941775, + }, + "id": "3fc0dfa9fe9", + "linkTo": { + "id": "id-existing", + "isBroken": false, + "lang": "tortor,", + "link_type": "Document", + "tags": [ + "Risus In", + ], + "type": "dui", + }, + "type": "image", + "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", + }, + ], + "group": [ + { + "field": [ + { + "spans": [], + "text": "Egestas Integer Eget Aliquet Nibh", + "type": "heading5", + }, + { + "alt": "Arcu cursus vitae congue mauris", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#5f7a9b", + "x": -119, + "y": -2667, + "zoom": 1.9681315715350518, + }, + "id": "3fc0dfa9fe9", + "linkTo": { + "id": "id-existing", + "isBroken": false, + "lang": "tortor,", + "link_type": "Document", + "tags": [ + "Risus In", + ], + "type": "dui", + }, + "type": "image", + "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", + }, + ], + }, + ], + }, + "slice_label": null, + "slice_type": "at", + "variation": "tortor", + "version": "a79b9dd", + }, + ], +} +`; + +exports[`patches rich text image nodes > otherRepositoryLinkTo > slice 1`] = ` +{ + "slices": [ + { + "id": "e93cc3e4f28", + "items": [ + { + "field": [ + { + "spans": [], + "text": "Amet", + "type": "heading5", + }, + { + "alt": "Auctor neque vitae tempus quam", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#5bc5aa", + "x": -1072, + "y": -281, + "zoom": 1.3767766101231744, + }, + "id": "f70ca27104d", + "linkTo": { + "id": "id-existing", + "isBroken": false, + "lang": "sapien", + "link_type": "Document", + "tags": [ + "Aenean", + ], + "type": "amet", + }, + "type": "image", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", + }, + ], + }, + ], + "primary": { + "field": [ + { + "spans": [], + "text": "Ac Orci Phasellus Egestas Tellus", + "type": "heading5", + }, + { + "alt": "Urna id volutpat lacus laoreet non curabitur gravida arcu ac tortor", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#4860cb", + "x": 280, + "y": -379, + "zoom": 1.2389796902982004, + }, + "id": "f70ca27104d", + "linkTo": { + "id": "id-existing", + "isBroken": false, + "lang": "sapien", + "link_type": "Document", + "tags": [ + "Aenean", + ], + "type": "amet", + }, + "type": "image", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", + }, + ], + }, + "slice_label": "Pellentesque", + "slice_type": "nulla_posuere", + }, + ], +} +`; + +exports[`patches rich text image nodes > otherRepositoryLinkTo > static zone 1`] = ` +{ + "field": [ + { + "spans": [], + "text": "Elementum Integer", + "type": "heading6", + }, + { + "alt": "Interdum velit euismod in pellentesque", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#ab1d17", + "x": 3605, + "y": 860, + "zoom": 1.9465488211593005, + }, + "id": "04a95cc61c3", + "linkTo": { + "id": "id-existing", + "isBroken": false, + "lang": "eget", + "link_type": "Document", + "tags": [], + "type": "phasellus", + }, + "type": "image", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", + }, + ], +} +`; diff --git a/test/__testutils__/mockPrismicAssetAPI.ts b/test/__testutils__/mockPrismicAssetAPI.ts index 02187d2b..ab9ef6b1 100644 --- a/test/__testutils__/mockPrismicAssetAPI.ts +++ b/test/__testutils__/mockPrismicAssetAPI.ts @@ -108,7 +108,7 @@ export const mockPrismicAssetAPI = ( validateHeaders(req) - const index = Number.parseInt(req.url.searchParams.get("cursor") ?? "0") + const index = Number.parseInt(req.url.searchParams.get("cursor") || "0") const items: Asset[] = assetsDatabase[index] || [] let missing_ids: string[] | undefined @@ -143,7 +143,7 @@ export const mockPrismicAssetAPI = ( validateHeaders(req) const response: PostAssetResult = - args.newAssets?.shift() ?? mockAsset(args.ctx) + args.newAssets?.shift() || mockAsset(args.ctx) // Save the asset in DB assetsDatabase.push([response]) diff --git a/test/__testutils__/testMigrationFieldPatching.ts b/test/__testutils__/testMigrationFieldPatching.ts index be1a42a7..4a4c1a32 100644 --- a/test/__testutils__/testMigrationFieldPatching.ts +++ b/test/__testutils__/testMigrationFieldPatching.ts @@ -22,9 +22,7 @@ type GetDataArgs = { migration: prismic.Migration existingAssets: Asset[] existingDocuments: prismic.PrismicDocument[] - migrationDocuments: (Omit & { - uid: string - })[] + migrationDocuments: prismic.MigrationDocument[] mockedDomain: string } @@ -82,16 +80,20 @@ const internalTestMigrationFieldPatching = ( const migration = prismic.createMigration() + const migrationOtherDocument = migration.createDocument( + otherDocument, + "other", + ) + newDocument.data = args.getData({ ctx, migration, existingAssets: assetsDatabase.flat(), existingDocuments: queryResponse[0].results, - migrationDocuments: [otherDocument], + migrationDocuments: [migrationOtherDocument], mockedDomain, }) - migration.createDocument(otherDocument, "other") migration.createDocument(newDocument, "new") // We speed up the internal rate limiter to make these tests run faster (from 4500ms to nearly instant) diff --git a/test/migration-createDocument.test.ts b/test/migration-createDocument.test.ts index df7b98dc..960d2c0a 100644 --- a/test/migration-createDocument.test.ts +++ b/test/migration-createDocument.test.ts @@ -3,7 +3,8 @@ import { describe, expect, it } from "vitest" import type { MockFactory } from "@prismicio/mock" import * as prismic from "../src" -import type { MigrationAsset } from "../src/types/migration/asset" +import type { MigrationAssetConfig } from "../src/types/migration/Asset" +import { MigrationDocument } from "../src/types/migration/Document" it("creates a document", () => { const migration = prismic.createMigration() @@ -18,10 +19,9 @@ it("creates a document", () => { migration.createDocument(document, documentTitle) - expect(migration._documents[0]).toStrictEqual({ - document, - params: { documentTitle }, - }) + expect(migration._documents[0]).toStrictEqual( + new MigrationDocument(document, { documentTitle }), + ) }) it("creates a document from an existing Prismic document", (ctx) => { @@ -32,10 +32,9 @@ it("creates a document from an existing Prismic document", (ctx) => { migration.createDocument(document, documentTitle) - expect(migration._documents[0]).toStrictEqual({ - document, - params: { documentTitle }, - }) + expect(migration._documents[0]).toStrictEqual( + new MigrationDocument(document, { documentTitle }), + ) }) describe.each<{ @@ -46,7 +45,7 @@ describe.each<{ | prismic.FilledImageFieldImage | prismic.FilledLinkToMediaField | prismic.RichTextField<"filled"> - expected: MigrationAsset + expected: MigrationAssetConfig } }>([ { @@ -58,8 +57,8 @@ describe.each<{ id: image.id, field: image, expected: { - alt: image.alt ?? undefined, - credits: image.copyright ?? undefined, + alt: image.alt || undefined, + credits: image.copyright || undefined, file: image.url.split("?")[0], filename: image.url.split("/").pop()!.split("?")[0], id: image.id, @@ -104,8 +103,8 @@ describe.each<{ id: image.id, field: richText, expected: { - alt: image.alt ?? undefined, - credits: image.copyright ?? undefined, + alt: image.alt || undefined, + credits: image.copyright || undefined, file: image.url.split("?")[0], filename: image.url.split("/").pop()!.split("?")[0], id: image.id, diff --git a/test/migration-getByUID.test.ts b/test/migration-getByUID.test.ts index 0ac4d3ad..496e7b22 100644 --- a/test/migration-getByUID.test.ts +++ b/test/migration-getByUID.test.ts @@ -13,10 +13,10 @@ it("returns a document with a matching UID", () => { } const documentName = "documentName" - migration.createDocument(document, documentName) + const migrationDocument = migration.createDocument(document, documentName) expect(migration.getByUID(document.type, document.uid)).toStrictEqual( - document, + migrationDocument, ) }) diff --git a/test/migration-getSingle.test.ts b/test/migration-getSingle.test.ts index d2ff7359..4dbcc129 100644 --- a/test/migration-getSingle.test.ts +++ b/test/migration-getSingle.test.ts @@ -12,9 +12,9 @@ it("returns a document of a given singleton type", () => { } const documentName = "documentName" - migration.createDocument(document, documentName) + const migrationDocument = migration.createDocument(document, documentName) - expect(migration.getSingle(document.type)).toStrictEqual(document) + expect(migration.getSingle(document.type)).toStrictEqual(migrationDocument) }) it("returns `undefined` if a document is not found", () => { diff --git a/test/types/migration-document.types.ts b/test/types/migration-document.types.ts index 0d48cd56..14237c1a 100644 --- a/test/types/migration-document.types.ts +++ b/test/types/migration-document.types.ts @@ -100,8 +100,6 @@ expectType({ type Fields = { image: prismic.ImageField migrationImage: prismic.ImageField - link: prismic.LinkField - migrationLink: prismic.LinkField linkToMedia: prismic.LinkToMediaField migrationLinkToMedia: prismic.LinkToMediaField contentRelationship: prismic.ContentRelationshipField @@ -139,13 +137,11 @@ expectType({ lang: "", data: { image: {} as prismic.ImageField, - migrationImage: {} as prismic.ImageMigrationField, - link: {} as prismic.LinkField, - migrationLink: {} as prismic.LinkMigrationField, + migrationImage: {} as prismic.MigrationImage, linkToMedia: {} as prismic.LinkToMediaField, - migrationLinkToMedia: {} as prismic.LinkToMediaMigrationField, + migrationLinkToMedia: {} as prismic.MigrationLinkToMedia, contentRelationship: {} as prismic.ContentRelationshipField, - migrationContentRelationship: {} as prismic.ContentRelationshipField, + migrationContentRelationship: {} as prismic.MigrationContentRelationship, }, }) @@ -158,13 +154,12 @@ expectType({ group: [ { image: {} as prismic.ImageField, - migrationImage: {} as prismic.ImageMigrationField, - link: {} as prismic.LinkField, - migrationLink: {} as prismic.LinkMigrationField, + migrationImage: {} as prismic.MigrationImage, linkToMedia: {} as prismic.LinkToMediaField, - migrationLinkToMedia: {} as prismic.LinkToMediaMigrationField, + migrationLinkToMedia: {} as prismic.MigrationLinkToMedia, contentRelationship: {} as prismic.ContentRelationshipField, - migrationContentRelationship: {} as prismic.ContentRelationshipField, + migrationContentRelationship: + {} as prismic.MigrationContentRelationship, }, ], }, @@ -185,38 +180,33 @@ expectType({ version: "", primary: { image: {} as prismic.ImageField, - migrationImage: {} as prismic.ImageMigrationField, - link: {} as prismic.LinkField, - migrationLink: {} as prismic.LinkMigrationField, + migrationImage: {} as prismic.MigrationImage, linkToMedia: {} as prismic.LinkToMediaField, - migrationLinkToMedia: {} as prismic.LinkToMediaMigrationField, + migrationLinkToMedia: {} as prismic.MigrationLinkToMedia, contentRelationship: {} as prismic.ContentRelationshipField, - migrationContentRelationship: {} as prismic.ContentRelationshipField, + migrationContentRelationship: + {} as prismic.MigrationContentRelationship, group: [ { image: {} as prismic.ImageField, - migrationImage: {} as prismic.ImageMigrationField, - link: {} as prismic.LinkField, - migrationLink: {} as prismic.LinkMigrationField, + migrationImage: {} as prismic.MigrationImage, linkToMedia: {} as prismic.LinkToMediaField, - migrationLinkToMedia: {} as prismic.LinkToMediaMigrationField, + migrationLinkToMedia: {} as prismic.MigrationLinkToMedia, contentRelationship: {} as prismic.ContentRelationshipField, migrationContentRelationship: - {} as prismic.ContentRelationshipField, + {} as prismic.MigrationContentRelationship, }, ], }, items: [ { image: {} as prismic.ImageField, - migrationImage: {} as prismic.ImageMigrationField, - link: {} as prismic.LinkField, - migrationLink: {} as prismic.LinkMigrationField, + migrationImage: {} as prismic.MigrationImage, linkToMedia: {} as prismic.LinkToMediaField, - migrationLinkToMedia: {} as prismic.LinkToMediaMigrationField, + migrationLinkToMedia: {} as prismic.MigrationLinkToMedia, contentRelationship: {} as prismic.ContentRelationshipField, migrationContentRelationship: - {} as prismic.ContentRelationshipField, + {} as prismic.MigrationContentRelationship, }, ], }, diff --git a/test/types/migration.types.ts b/test/types/migration.types.ts index 91542ac2..f3c3bd2d 100644 --- a/test/types/migration.types.ts +++ b/test/types/migration.types.ts @@ -41,36 +41,85 @@ expectType>(false) // Default const defaultCreateAsset = defaultMigration.createAsset("url", "name") -expectType>(true) +expectType>(true) + +expectType< + TypeEqual< + ReturnType, + prismic.MigrationImage + > +>(true) expectType< - TypeEqual + TypeOf> >(true) + expectType< TypeEqual< - typeof defaultCreateAsset.linkToMedia, - prismic.LinkToMediaMigrationField + ReturnType, + prismic.MigrationLinkToMedia > >(true) expectType< - TypeOf + TypeOf< + prismic.MigrationLinkToMedia, + ReturnType + > +>(true) + +expectType< + TypeEqual< + ReturnType, + prismic.MigrationRTImageNode + > +>(true) +expectType< + TypeOf< + prismic.MigrationRTImageNode, + ReturnType + > >(true) // Documents const documentsCreateAsset = defaultMigration.createAsset("url", "name") -expectType>( - true, -) +expectType>(true) + expectType< - TypeEqual + TypeEqual< + ReturnType, + prismic.MigrationImage + > +>(true) +expectType< + TypeOf< + prismic.MigrationImage, + ReturnType + > +>(true) + +expectType< + TypeEqual< + ReturnType, + prismic.MigrationLinkToMedia + > >(true) +expectType< + TypeOf< + prismic.MigrationLinkToMedia, + ReturnType + > +>(true) + expectType< TypeEqual< - typeof documentsCreateAsset.linkToMedia, - prismic.LinkToMediaMigrationField + ReturnType, + prismic.MigrationRTImageNode > >(true) expectType< - TypeOf + TypeOf< + prismic.MigrationRTImageNode, + ReturnType + > >(true) /** @@ -87,9 +136,9 @@ const defaultCreateDocument = defaultMigration.createDocument( }, "", ) -expectType< - TypeEqual ->(true) +expectType>( + true, +) // Documents const documentsCreateDocument = documentsMigration.createDocument( @@ -104,6 +153,6 @@ const documentsCreateDocument = documentsMigration.createDocument( expectType< TypeEqual< typeof documentsCreateDocument, - prismic.PrismicMigrationDocument + prismic.MigrationDocument > >(true) diff --git a/test/writeClient-migrate-documents.test.ts b/test/writeClient-migrate-documents.test.ts index 28ce988d..fcb75ae7 100644 --- a/test/writeClient-migrate-documents.test.ts +++ b/test/writeClient-migrate-documents.test.ts @@ -8,7 +8,7 @@ import { mockPrismicMigrationAPI } from "./__testutils__/mockPrismicMigrationAPI import { mockPrismicRestAPIV2 } from "./__testutils__/mockPrismicRestAPIV2" import * as prismic from "../src" -import type { DocumentMap } from "../src/lib/patchMigrationDocumentData" +import type { DocumentMap } from "../src/types/migration/Document" // Skip test on Node 16 and 18 (File and FormData support) const isNode16 = process.version.startsWith("v16") @@ -137,7 +137,7 @@ it.concurrent("creates new documents", async (ctx) => { const migration = prismic.createMigration() - migration.createDocument(document, "foo") + const migrationDocument = migration.createDocument(document, "foo") let documents: DocumentMap | undefined const reporter = vi.fn<(event: prismic.MigrateReporterEvents) => void>( @@ -162,28 +162,36 @@ it.concurrent("creates new documents", async (ctx) => { }, }, }) - expect(documents?.get(document)?.id).toBe(newDocument.id) + expect(documents?.get(migrationDocument)?.id).toBe(newDocument.id) }) it.concurrent( - "creates new non-master locale document with direct reference", + "creates new non-master locale document with direct reference (existing document)", async (ctx) => { const client = createTestWriteClient({ ctx }) - const masterLanguageDocument = ctx.mock.value.document() + const queryResponse = createPagedQueryResponses({ + ctx, + pages: 1, + pageSize: 1, + }) + + const masterLanguageDocument = queryResponse[0].results[0] const document = ctx.mock.value.document() const newDocument = { id: "foo", masterLanguageDocumentID: masterLanguageDocument.id, } - mockPrismicRestAPIV2({ ctx }) + mockPrismicRestAPIV2({ ctx, queryResponse }) mockPrismicAssetAPI({ ctx, client }) mockPrismicMigrationAPI({ ctx, client, newDocuments: [newDocument] }) const migration = prismic.createMigration() - migration.createDocument(document, "foo", { masterLanguageDocument }) + const migrationDocument = migration.createDocument(document, "foo", { + masterLanguageDocument, + }) let documents: DocumentMap | undefined const reporter = vi.fn<(event: prismic.MigrateReporterEvents) => void>( @@ -209,7 +217,62 @@ it.concurrent( }, }, }) - ctx.expect(documents?.get(document)?.id).toBe(newDocument.id) + ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocument.id) + ctx.expect.assertions(3) + }, +) + +it.concurrent( + "creates new non-master locale document with direct reference (new document)", + async (ctx) => { + const client = createTestWriteClient({ ctx }) + + const masterLanguageDocument = + ctx.mock.value.document() as prismic.PrismicMigrationDocument + const document = + ctx.mock.value.document() as prismic.PrismicMigrationDocument + const newDocuments = [ + { + id: masterLanguageDocument.id!, + }, + { + id: document.id!, + masterLanguageDocumentID: masterLanguageDocument.id!, + }, + ] + + delete masterLanguageDocument.id + delete document.id + + mockPrismicRestAPIV2({ ctx }) + mockPrismicAssetAPI({ ctx, client }) + mockPrismicMigrationAPI({ ctx, client, newDocuments: [...newDocuments] }) + + const migration = prismic.createMigration() + + const masterLanguageMigrationDocument = migration.createDocument( + masterLanguageDocument, + "foo", + ) + const migrationDocument = migration.createDocument(document, "bar", { + masterLanguageDocument: masterLanguageMigrationDocument, + }) + + let documents: DocumentMap | undefined + const reporter = vi.fn<(event: prismic.MigrateReporterEvents) => void>( + (event) => { + if (event.type === "documents:created") { + documents = event.data.documents + } + }, + ) + + await client.migrate(migration, { reporter }) + + ctx + .expect(documents?.get(masterLanguageMigrationDocument)?.id) + .toBe(newDocuments[0].id) + ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocuments[1].id) ctx.expect.assertions(3) }, ) @@ -238,7 +301,7 @@ it.concurrent( const migration = prismic.createMigration() - migration.createDocument(document, "foo", { + const migrationDocument = migration.createDocument(document, "foo", { masterLanguageDocument: () => masterLanguageDocument, }) @@ -266,7 +329,7 @@ it.concurrent( }, }, }) - ctx.expect(documents?.get(document)?.id).toBe(newDocument.id) + ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocument.id) ctx.expect.assertions(3) }, ) @@ -299,9 +362,12 @@ it.concurrent( const migration = prismic.createMigration() - migration.createDocument(masterLanguageDocument, "foo") - migration.createDocument(document, "bar", { - masterLanguageDocument: () => masterLanguageDocument, + const masterLanguageMigrationDocument = migration.createDocument( + masterLanguageDocument, + "foo", + ) + const migrationDocument = migration.createDocument(document, "bar", { + masterLanguageDocument: () => masterLanguageMigrationDocument, }) let documents: DocumentMap | undefined @@ -316,9 +382,9 @@ it.concurrent( await client.migrate(migration, { reporter }) ctx - .expect(documents?.get(masterLanguageDocument)?.id) + .expect(documents?.get(masterLanguageMigrationDocument)?.id) .toBe(newDocuments[0].id) - ctx.expect(documents?.get(document)?.id).toBe(newDocuments[1].id) + ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocuments[1].id) ctx.expect.assertions(3) }, ) @@ -351,7 +417,7 @@ it.concurrent( const migration = prismic.createMigration() - migration.createDocument(document, "foo") + const migrationDocument = migration.createDocument(document, "foo") let documents: DocumentMap | undefined const reporter = vi.fn<(event: prismic.MigrateReporterEvents) => void>( @@ -376,7 +442,7 @@ it.concurrent( }, }, }) - ctx.expect(documents?.get(document)?.id).toBe(newDocument.id) + ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocument.id) ctx.expect.assertions(3) }, ) @@ -404,8 +470,11 @@ it.concurrent("creates master locale documents first", async (ctx) => { const migration = prismic.createMigration() - migration.createDocument(document, "bar") - migration.createDocument(masterLanguageDocument, "foo") + const migrationDocument = migration.createDocument(document, "bar") + const masterLanguageMigrationDocument = migration.createDocument( + masterLanguageDocument, + "foo", + ) let documents: DocumentMap | undefined const reporter = vi.fn<(event: prismic.MigrateReporterEvents) => void>( @@ -419,7 +488,7 @@ it.concurrent("creates master locale documents first", async (ctx) => { await client.migrate(migration, { reporter }) ctx - .expect(documents?.get(masterLanguageDocument)?.id) + .expect(documents?.get(masterLanguageMigrationDocument)?.id) .toBe(newDocuments[0].id) - ctx.expect(documents?.get(document)?.id).toBe(newDocuments[1].id) + ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocuments[1].id) }) diff --git a/test/writeClient-migrate-patch-link.test.ts b/test/writeClient-migrate-patch-contentRelationship.test.ts similarity index 57% rename from test/writeClient-migrate-patch-link.test.ts rename to test/writeClient-migrate-patch-contentRelationship.test.ts index 51cb64ef..5cd030b8 100644 --- a/test/writeClient-migrate-patch-link.test.ts +++ b/test/writeClient-migrate-patch-contentRelationship.test.ts @@ -5,7 +5,7 @@ import { RichTextNodeType } from "../src" testMigrationFieldPatching("patches link fields", { existing: ({ existingDocuments }) => existingDocuments[0], migration: ({ migrationDocuments }) => { - delete migrationDocuments[0].id + delete migrationDocuments[0].document.id return migrationDocuments[0] }, @@ -13,21 +13,27 @@ testMigrationFieldPatching("patches link fields", { return () => existingDocuments[0] }, lazyMigration: ({ migration, migrationDocuments }) => { - delete migrationDocuments[0].id + delete migrationDocuments[0].document.id return () => - migration.getByUID(migrationDocuments[0].type, migrationDocuments[0].uid) + migration.getByUID( + migrationDocuments[0].document.type, + migrationDocuments[0].document.uid!, + ) }, migrationNoTags: ({ migration, migrationDocuments }) => { - migrationDocuments[0].tags = undefined + migrationDocuments[0].document.tags = undefined return () => - migration.getByUID(migrationDocuments[0].type, migrationDocuments[0].uid) + migration.getByUID( + migrationDocuments[0].document.type, + migrationDocuments[0].document.uid!, + ) }, otherRepositoryContentRelationship: ({ ctx, migrationDocuments }) => { const contentRelationship = ctx.mock.value.link({ type: "Document" }) // `migrationDocuments` contains documents from "another repository" - contentRelationship.id = migrationDocuments[0].id! + contentRelationship.id = migrationDocuments[0].document.id! return contentRelationship }, @@ -47,25 +53,4 @@ testMigrationFieldPatching("patches link fields", { ], }, ], - richTextNewImageNodeLink: ({ ctx, migration, existingDocuments }) => [ - ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), - { - ...migration.createAsset("foo", "foo.png"), - linkTo: existingDocuments[0], - }, - ], - richTextOtherReposiotryImageNodeLink: ({ - ctx, - mockedDomain, - existingDocuments, - }) => [ - ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), - { - type: RichTextNodeType.image, - ...ctx.mock.value.image({ state: "filled" }), - id: "foo-id", - url: `${mockedDomain}/foo.png`, - linkTo: existingDocuments[0], - }, - ], }) diff --git a/test/writeClient-migrate-patch-image.test.ts b/test/writeClient-migrate-patch-image.test.ts index 39efa933..f0897927 100644 --- a/test/writeClient-migrate-patch-image.test.ts +++ b/test/writeClient-migrate-patch-image.test.ts @@ -1,7 +1,5 @@ import { testMigrationFieldPatching } from "./__testutils__/testMigrationFieldPatching" -import { RichTextNodeType } from "../src" - testMigrationFieldPatching("patches image fields", { new: ({ migration }) => migration.createAsset("foo", "foo.png"), existing: ({ migration, existingAssets }) => @@ -44,22 +42,20 @@ testMigrationFieldPatching("patches image fields", { }, } }, + otherRepositoryWithTypeThumbnail: ({ ctx, mockedDomain }) => { + const image = ctx.mock.value.image({ state: "filled" }) + const id = "foo-id" + + return { + ...image, + id, + url: `${mockedDomain}/foo.png?some=query`, + type: { + ...image, + id, + url: `${mockedDomain}/foo.png?some=other&query=params`, + }, + } + }, otherRepositoryEmpty: ({ ctx }) => ctx.mock.value.image({ state: "empty" }), - richTextNew: ({ ctx, migration }) => [ - ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), - migration.createAsset("foo", "foo.png"), - ], - richTextExisting: ({ ctx, migration, existingAssets }) => [ - ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), - migration.createAsset(existingAssets[0]), - ], - richTextOtherRepository: ({ ctx, mockedDomain }) => [ - ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), - { - type: RichTextNodeType.image, - ...ctx.mock.value.image({ state: "filled" }), - id: "foo-id", - url: `${mockedDomain}/foo.png`, - }, - ], }) diff --git a/test/writeClient-migrate-patch-linkToMedia.test.ts b/test/writeClient-migrate-patch-linkToMedia.test.ts index abe49fa0..8a19025c 100644 --- a/test/writeClient-migrate-patch-linkToMedia.test.ts +++ b/test/writeClient-migrate-patch-linkToMedia.test.ts @@ -4,9 +4,10 @@ import { RichTextNodeType } from "../src" import { AssetType } from "../src/types/api/asset/asset" testMigrationFieldPatching("patches link to media fields", { - new: ({ migration }) => migration.createAsset("foo", "foo.png").linkToMedia, + new: ({ migration }) => + migration.createAsset("foo", "foo.png").asLinkToMedia(), existing: ({ migration, existingAssets }) => - migration.createAsset(existingAssets[0]).linkToMedia, + migration.createAsset(existingAssets[0]).asLinkToMedia(), existingNonImage: ({ migration, existingAssets }) => { existingAssets[0].filename = "foo.pdf" existingAssets[0].extension = "pdf" @@ -14,7 +15,7 @@ testMigrationFieldPatching("patches link to media fields", { existingAssets[0].width = undefined existingAssets[0].height = undefined - return migration.createAsset(existingAssets[0]).linkToMedia + return migration.createAsset(existingAssets[0]).asLinkToMedia() }, otherRepository: ({ ctx, mockedDomain }) => { return { @@ -23,12 +24,6 @@ testMigrationFieldPatching("patches link to media fields", { url: `${mockedDomain}/foo.png`, } }, - otherRepositoryNotFoundID: ({ ctx }) => { - return { - ...ctx.mock.value.linkToMedia({ state: "empty" }), - id: null, - } - }, richTextNew: ({ migration }) => [ { type: RichTextNodeType.paragraph, @@ -39,7 +34,7 @@ testMigrationFieldPatching("patches link to media fields", { type: RichTextNodeType.hyperlink, start: 0, end: 5, - data: migration.createAsset("foo", "foo.png").linkToMedia, + data: migration.createAsset("foo", "foo.png").asLinkToMedia(), }, ], }, @@ -54,7 +49,7 @@ testMigrationFieldPatching("patches link to media fields", { type: RichTextNodeType.hyperlink, start: 0, end: 5, - data: migration.createAsset(existingAssets[0]).linkToMedia, + data: migration.createAsset(existingAssets[0]).asLinkToMedia(), }, ], }, diff --git a/test/writeClient-migrate-patch-rtImageNode.test.ts b/test/writeClient-migrate-patch-rtImageNode.test.ts new file mode 100644 index 00000000..4d69bc1e --- /dev/null +++ b/test/writeClient-migrate-patch-rtImageNode.test.ts @@ -0,0 +1,43 @@ +import { testMigrationFieldPatching } from "./__testutils__/testMigrationFieldPatching" + +import { RichTextNodeType } from "../src" +import { MigrationContentRelationship } from "../src/types/migration/ContentRelationship" + +testMigrationFieldPatching("patches rich text image nodes", { + new: ({ ctx, migration }) => [ + ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), + migration.createAsset("foo", "foo.png").asRTImageNode(), + ], + existing: ({ ctx, migration, existingAssets }) => [ + ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), + migration.createAsset(existingAssets[0]).asRTImageNode(), + ], + otherRepository: ({ ctx, mockedDomain }) => [ + ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), + { + type: RichTextNodeType.image, + ...ctx.mock.value.image({ state: "filled" }), + id: "foo-id", + url: `${mockedDomain}/foo.png`, + }, + ], + newLinkTo: ({ ctx, migration, existingDocuments }) => { + const rtImageNode = migration.createAsset("foo", "foo.png").asRTImageNode() + rtImageNode.linkTo = new MigrationContentRelationship(existingDocuments[0]) + + return [ + ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), + rtImageNode, + ] + }, + otherRepositoryLinkTo: ({ ctx, mockedDomain, existingDocuments }) => [ + ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), + { + type: RichTextNodeType.image, + ...ctx.mock.value.image({ state: "filled" }), + id: "foo-id", + url: `${mockedDomain}/foo.png`, + linkTo: existingDocuments[0], + }, + ], +}) diff --git a/test/writeClient-migrate.test.ts b/test/writeClient-migrate.test.ts index db2a5137..3f6bb056 100644 --- a/test/writeClient-migrate.test.ts +++ b/test/writeClient-migrate.test.ts @@ -9,10 +9,8 @@ import { mockPrismicMigrationAPI } from "./__testutils__/mockPrismicMigrationAPI import { mockPrismicRestAPIV2 } from "./__testutils__/mockPrismicRestAPIV2" import * as prismic from "../src" -import type { - AssetMap, - DocumentMap, -} from "../src/lib/patchMigrationDocumentData" +import type { AssetMap } from "../src/types/migration/Asset" +import type { DocumentMap } from "../src/types/migration/Document" // Skip test on Node 16 and 18 (File and FormData support) const isNode16 = process.version.startsWith("v16") From c7655f8bb2b76fda071424d85edf75e7cbb73144 Mon Sep 17 00:00:00 2001 From: lihbr Date: Wed, 11 Sep 2024 22:58:54 +0200 Subject: [PATCH 02/13] chore: rename file casing --- src/types/migration/{asset.ts => Asset.ts} | 0 src/types/migration/{document.ts => Document.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/types/migration/{asset.ts => Asset.ts} (100%) rename src/types/migration/{document.ts => Document.ts} (100%) diff --git a/src/types/migration/asset.ts b/src/types/migration/Asset.ts similarity index 100% rename from src/types/migration/asset.ts rename to src/types/migration/Asset.ts diff --git a/src/types/migration/document.ts b/src/types/migration/Document.ts similarity index 100% rename from src/types/migration/document.ts rename to src/types/migration/Document.ts From a6788f111a65db9e980b340b2d7475ce75da4499 Mon Sep 17 00:00:00 2001 From: lihbr Date: Wed, 11 Sep 2024 23:05:11 +0200 Subject: [PATCH 03/13] refactor: rename `_prepare` to `_resolve` --- src/WriteClient.ts | 4 ++-- src/types/migration/Asset.ts | 10 +++++----- src/types/migration/ContentRelationship.ts | 2 +- src/types/migration/Document.ts | 4 ++-- src/types/migration/Field.ts | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/WriteClient.ts b/src/WriteClient.ts index 2dc6ac16..badf149f 100644 --- a/src/WriteClient.ts +++ b/src/WriteClient.ts @@ -579,7 +579,7 @@ export class WriteClient< migrationDocument.params.masterLanguageDocument, ) - await link._prepare({ documents }) + await link._resolve({ documents }) masterLanguageDocumentID = link._field?.id } else if (migrationDocument.document.alternate_languages) { masterLanguageDocumentID = @@ -655,7 +655,7 @@ export class WriteClient< }) const { id, uid } = documents.get(migrationDocument)! - await migrationDocument._prepare({ assets, documents }) + await migrationDocument._resolve({ assets, documents }) await this.updateDocument( id, diff --git a/src/types/migration/Asset.ts b/src/types/migration/Asset.ts index 1bf3d934..98b7bd17 100644 --- a/src/types/migration/Asset.ts +++ b/src/types/migration/Asset.ts @@ -144,7 +144,7 @@ export class MigrationImage extends MigrationAsset { this.#thumbnails[name] = thumbnail } - async _prepare({ + async _resolve({ assets, documents, }: { @@ -157,7 +157,7 @@ export class MigrationImage extends MigrationAsset { this._field = assetToImage(asset, this._initialField) for (const name in this.#thumbnails) { - await this.#thumbnails[name]._prepare({ assets, documents }) + await this.#thumbnails[name]._resolve({ assets, documents }) const thumbnail = this.#thumbnails[name]._field if (thumbnail) { @@ -171,7 +171,7 @@ export class MigrationImage extends MigrationAsset { export class MigrationLinkToMedia extends MigrationAsset< LinkToMediaField<"filled"> > { - _prepare({ assets }: { assets: AssetMap }): void { + _resolve({ assets }: { assets: AssetMap }): void { const asset = assets.get(this.config.id) if (asset) { @@ -197,7 +197,7 @@ export class MigrationRTImageNode extends MigrationAsset { | FilledLinkToWebField | undefined - async _prepare({ + async _resolve({ assets, documents, }: { @@ -207,7 +207,7 @@ export class MigrationRTImageNode extends MigrationAsset { const asset = assets.get(this.config.id) if (this.linkTo instanceof MigrationField) { - await this.linkTo._prepare({ assets, documents }) + await this.linkTo._resolve({ assets, documents }) } if (asset) { diff --git a/src/types/migration/ContentRelationship.ts b/src/types/migration/ContentRelationship.ts index f9c0eff3..6ada005a 100644 --- a/src/types/migration/ContentRelationship.ts +++ b/src/types/migration/ContentRelationship.ts @@ -29,7 +29,7 @@ export class MigrationContentRelationship extends MigrationField { + async _resolve({ documents }: { documents: DocumentMap }): Promise { const config = typeof this.unresolvedConfig === "function" ? await this.unresolvedConfig() diff --git a/src/types/migration/Document.ts b/src/types/migration/Document.ts index aa381c77..e18704cd 100644 --- a/src/types/migration/Document.ts +++ b/src/types/migration/Document.ts @@ -272,12 +272,12 @@ export class MigrationDocument< /** * @internal */ - async _prepare(args: { + async _resolve(args: { assets: AssetMap documents: DocumentMap }): Promise { for (const dependency of this.dependencies) { - await dependency._prepare(args) + await dependency._resolve(args) } } } diff --git a/src/types/migration/Field.ts b/src/types/migration/Field.ts index b70926a8..edf4618c 100644 --- a/src/types/migration/Field.ts +++ b/src/types/migration/Field.ts @@ -9,7 +9,7 @@ interface Preparable { /** * @internal */ - _prepare(args: { + _resolve(args: { assets: AssetMap documents: DocumentMap }): Promise | void @@ -41,7 +41,7 @@ export abstract class MigrationField< return this._field } - abstract _prepare(args: { + abstract _resolve(args: { assets: AssetMap documents: DocumentMap }): Promise | void From 895c86cc69dc57fb2611760825cfef97db5bd098 Mon Sep 17 00:00:00 2001 From: lihbr Date: Thu, 12 Sep 2024 12:19:27 +0200 Subject: [PATCH 04/13] refactor: abstract thunks under `Migration#createContentRelationship` --- src/Migration.ts | 21 ++- src/WriteClient.ts | 64 ++++------ src/index.ts | 3 +- src/lib/isValue.ts | 41 ------ src/lib/prepareMigrationRecord.ts | 22 ++-- src/types/migration/Asset.ts | 120 ++++++++++-------- src/types/migration/ContentRelationship.ts | 29 +++-- src/types/migration/Document.ts | 47 +++---- src/types/migration/Field.ts | 19 ++- .../testMigrationFieldPatching.ts | 4 +- test/migration-createDocument.test.ts | 10 +- test/types/migration-document.types.ts | 14 +- test/writeClient-migrate-documents.test.ts | 55 ++++---- ...-migrate-patch-contentRelationship.test.ts | 41 +++--- ...teClient-migrate-patch-rtImageNode.test.ts | 24 ++-- test/writeClient-migrate.test.ts | 3 +- 16 files changed, 237 insertions(+), 280 deletions(-) diff --git a/src/Migration.ts b/src/Migration.ts index 10faaf3e..c0e09732 100644 --- a/src/Migration.ts +++ b/src/Migration.ts @@ -4,10 +4,12 @@ import { validateAssetMetadata } from "./lib/validateAssetMetadata" import type { Asset } from "./types/api/asset/asset" import type { MigrationAssetConfig } from "./types/migration/Asset" import { MigrationImage } from "./types/migration/Asset" +import type { UnresolvedMigrationContentRelationshipConfig } from "./types/migration/ContentRelationship" +import { MigrationContentRelationship } from "./types/migration/ContentRelationship" import { MigrationDocument } from "./types/migration/Document" import type { - PrismicMigrationDocument, - PrismicMigrationDocumentParams, + MigrationDocumentParams, + MigrationDocumentValue, } from "./types/migration/Document" import type { PrismicDocument } from "./types/value/document" import type { FilledImageFieldImage } from "./types/value/image" @@ -22,7 +24,7 @@ import type { FilledLinkToMediaField } from "./types/value/linkToMedia" * @typeParam TDocumentType - Type(s) to match `TDocuments` against. */ type ExtractDocumentType< - TDocuments extends PrismicDocument | PrismicMigrationDocument, + TDocuments extends PrismicDocument | MigrationDocumentValue, TDocumentType extends TDocuments["type"], > = Extract extends never @@ -43,7 +45,7 @@ const SINGLE_INDEX = "__SINGLE__" export class Migration< TDocuments extends PrismicDocument = PrismicDocument, TMigrationDocuments extends - PrismicMigrationDocument = PrismicMigrationDocument, + MigrationDocumentValue = MigrationDocumentValue, > { /** * @internal @@ -167,8 +169,8 @@ export class Migration< createDocument( document: ExtractDocumentType, - documentTitle: PrismicMigrationDocumentParams["documentTitle"], - params: Omit = {}, + documentTitle: string, + params: Omit = {}, ): MigrationDocument> { const { record: data, dependencies } = prepareMigrationRecord( document.data, @@ -196,6 +198,13 @@ export class Migration< return migrationDocument } + createContentRelationship( + config: UnresolvedMigrationContentRelationshipConfig, + text?: string, + ): MigrationContentRelationship { + return new MigrationContentRelationship(config, undefined, text) + } + getByUID( documentType: TType, uid: string, diff --git a/src/WriteClient.ts b/src/WriteClient.ts index badf149f..03b1a50c 100644 --- a/src/WriteClient.ts +++ b/src/WriteClient.ts @@ -23,12 +23,10 @@ import { type PutDocumentParams, } from "./types/api/migration/document" import type { AssetMap, MigrationAssetConfig } from "./types/migration/Asset" -import { MigrationContentRelationship } from "./types/migration/ContentRelationship" import type { DocumentMap, MigrationDocument, - PrismicMigrationDocument, - PrismicMigrationDocumentParams, + MigrationDocumentValue, } from "./types/migration/Document" import type { PrismicDocument } from "./types/value/document" @@ -117,15 +115,13 @@ type MigrateReporterEventMap = { current: number remaining: number total: number - document: PrismicMigrationDocument - documentParams: PrismicMigrationDocumentParams + document: MigrationDocument } "documents:creating": { current: number remaining: number total: number - document: PrismicMigrationDocument - documentParams: PrismicMigrationDocumentParams + document: MigrationDocument } "documents:created": { created: number @@ -135,8 +131,7 @@ type MigrateReporterEventMap = { current: number remaining: number total: number - document: PrismicMigrationDocument - documentParams: PrismicMigrationDocumentParams + document: MigrationDocument } "documents:updated": { updated: number @@ -527,7 +522,7 @@ export class WriteClient< // We create an array with non-master locale documents last because // we need their master locale document to be created first. for (const migrationDocument of migration._documents) { - if (migrationDocument.document.lang === masterLocale) { + if (migrationDocument.value.lang === masterLocale) { sortedMigrationDocuments.unshift(migrationDocument) } else { sortedMigrationDocuments.push(migrationDocument) @@ -538,8 +533,8 @@ export class WriteClient< let created = 0 for (const migrationDocument of sortedMigrationDocuments) { if ( - migrationDocument.document.id && - documents.has(migrationDocument.document.id) + migrationDocument.value.id && + documents.has(migrationDocument.value.id) ) { reporter?.({ type: "documents:skipping", @@ -548,15 +543,14 @@ export class WriteClient< current: ++i, remaining: sortedMigrationDocuments.length - i, total: sortedMigrationDocuments.length, - document: migrationDocument.document, - documentParams: migrationDocument.params, + document: migrationDocument, }, }) // Index the migration document documents.set( migrationDocument, - documents.get(migrationDocument.document.id)!, + documents.get(migrationDocument.value.id)!, ) } else { created++ @@ -566,24 +560,21 @@ export class WriteClient< current: ++i, remaining: sortedMigrationDocuments.length - i, total: sortedMigrationDocuments.length, - document: migrationDocument.document, - documentParams: migrationDocument.params, + document: migrationDocument, }, }) // Resolve master language document ID for non-master locale documents let masterLanguageDocumentID: string | undefined - if (migrationDocument.document.lang !== masterLocale) { + if (migrationDocument.value.lang !== masterLocale) { if (migrationDocument.params.masterLanguageDocument) { - const link = new MigrationContentRelationship( - migrationDocument.params.masterLanguageDocument, - ) + const link = migrationDocument.params.masterLanguageDocument - await link._resolve({ documents }) + await link._resolve({ documents, assets: new Map() }) masterLanguageDocumentID = link._field?.id - } else if (migrationDocument.document.alternate_languages) { + } else if (migrationDocument.value.alternate_languages) { masterLanguageDocumentID = - migrationDocument.document.alternate_languages.find( + migrationDocument.value.alternate_languages.find( ({ lang }) => lang === masterLocale, )?.id } @@ -591,7 +582,7 @@ export class WriteClient< const { id } = await this.createDocument( // We'll upload docuements data later on. - { ...migrationDocument.document, data: {} }, + { ...migrationDocument.value, data: {} }, migrationDocument.params.documentTitle, { masterLanguageDocumentID, @@ -600,13 +591,13 @@ export class WriteClient< ) // Index old ID for Prismic to Prismic migration - if (migrationDocument.document.id) { - documents.set(migrationDocument.document.id, { - ...migrationDocument.document, + if (migrationDocument.value.id) { + documents.set(migrationDocument.value.id, { + ...migrationDocument.value, id, }) } - documents.set(migrationDocument, { ...migrationDocument.document, id }) + documents.set(migrationDocument, { ...migrationDocument.value, id }) } } @@ -649,8 +640,7 @@ export class WriteClient< current: ++i, remaining: migration._documents.length - i, total: migration._documents.length, - document: migrationDocument.document, - documentParams: migrationDocument.params, + document: migrationDocument, }, }) @@ -664,8 +654,8 @@ export class WriteClient< { documentTitle: migrationDocument.params.documentTitle, uid, - tags: migrationDocument.document.tags, - data: migrationDocument.document.data, + tags: migrationDocument.value.tags, + data: migrationDocument.value.data, }, fetchParams, ) @@ -1046,8 +1036,8 @@ export class WriteClient< * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference} */ private async createDocument( - document: PrismicMigrationDocument>, - documentTitle: PrismicMigrationDocumentParams["documentTitle"], + document: MigrationDocumentValue>, + documentTitle: string, { masterLanguageDocumentID, ...params @@ -1089,10 +1079,10 @@ export class WriteClient< private async updateDocument( id: string, document: Pick< - PrismicMigrationDocument>, + MigrationDocumentValue>, "uid" | "tags" | "data" > & { - documentTitle?: PrismicMigrationDocumentParams["documentTitle"] + documentTitle?: string }, params?: FetchParams, ): Promise { diff --git a/src/index.ts b/src/index.ts index 8c1dfaf3..68187114 100644 --- a/src/index.ts +++ b/src/index.ts @@ -328,7 +328,7 @@ export type { // Migrations - Types representing Prismic Migration API content values. export type { MigrationDocument, - PrismicMigrationDocument, + MigrationDocumentValue, RichTextFieldWithMigrationField, } from "./types/migration/Document" @@ -337,7 +337,6 @@ export type { MigrationLinkToMedia, MigrationRTImageNode, } from "./types/migration/Asset" - export type { MigrationContentRelationship } from "./types/migration/ContentRelationship" // API - Types representing Prismic Rest API V2 responses. diff --git a/src/lib/isValue.ts b/src/lib/isValue.ts index 71f563f0..805ac593 100644 --- a/src/lib/isValue.ts +++ b/src/lib/isValue.ts @@ -172,44 +172,3 @@ export const contentRelationship = ( return false } - -/** - * Checks if a value is a Prismic document. - * - * @param value - Value to check. - * - * @returns `true` if `value` is a content relationship, `false` otherwise. - * - * @internal - * This is not an official helper function and it's only designed to work with internal processes. - */ -export const document = ( - value: - | PrismicDocument - | FieldWithMigrationField - | RichTextBlockNodeWithMigrationField - | unknown, -): value is PrismicDocument => { - if (value && typeof value === "object" && !("version" in value)) { - if ( - "id" in value && - "uid" in value && - "url" in value && - "type" in value && - typeof value.type === "string" && - "href" in value && - "tags" in value && - "first_publication_date" in value && - "last_publication_date" in value && - "slugs" in value && - "linked_documents" in value && - "lang" in value && - "alternate_languages" in value && - "data" in value - ) { - return true - } - } - - return false -} diff --git a/src/lib/prepareMigrationRecord.ts b/src/lib/prepareMigrationRecord.ts index 26ea459e..618d4c7f 100644 --- a/src/lib/prepareMigrationRecord.ts +++ b/src/lib/prepareMigrationRecord.ts @@ -2,9 +2,7 @@ import type { MigrationImage, MigrationLinkToMedia, } from "../types/migration/Asset" -import type { UnresolvedMigrationContentRelationshipConfig } from "../types/migration/ContentRelationship" import { MigrationContentRelationship } from "../types/migration/ContentRelationship" -import { MigrationDocument } from "../types/migration/Document" import { MigrationField } from "../types/migration/Field" import type { FilledImageFieldImage } from "../types/value/image" import type { FilledLinkToWebField } from "../types/value/link" @@ -37,14 +35,17 @@ export const prepareMigrationRecord = >( const field: unknown = record[key] if (field instanceof MigrationField) { + // Existing migration fields dependencies.push(field) result[key] = field } else if (is.linkToMedia(field)) { + // Link to media const linkToMedia = onAsset(field).asLinkToMedia() dependencies.push(linkToMedia) result[key] = linkToMedia } else if (is.rtImageNode(field)) { + // Rich text image nodes const rtImageNode = onAsset(field).asRTImageNode() if (field.linkTo) { @@ -61,6 +62,7 @@ export const prepareMigrationRecord = >( dependencies.push(rtImageNode) result[key] = rtImageNode } else if (is.image(field)) { + // Image fields const image = onAsset(field).asImage() const { @@ -75,25 +77,21 @@ export const prepareMigrationRecord = >( for (const name in thumbnails) { if (is.image(thumbnails[name])) { + // Node thumbnails dependencies are tracked internally image.addThumbnail(name, onAsset(thumbnails[name]).asImage()) } } dependencies.push(image) result[key] = image - } else if ( - is.contentRelationship(field) || - is.document(field) || - field instanceof MigrationDocument || - typeof field === "function" - ) { - const contentRelationship = new MigrationContentRelationship( - field as UnresolvedMigrationContentRelationshipConfig, - ) + } else if (is.contentRelationship(field)) { + // Content relationships + const contentRelationship = new MigrationContentRelationship(field) dependencies.push(contentRelationship) result[key] = contentRelationship } else if (Array.isArray(field)) { + // Traverse arrays const array = [] for (const item of field) { @@ -106,12 +104,14 @@ export const prepareMigrationRecord = >( result[key] = array } else if (field && typeof field === "object") { + // Traverse objects const { record, dependencies: fieldDependencies } = prepareMigrationRecord({ ...field }, onAsset) dependencies.push(...fieldDependencies) result[key] = record } else { + // Primitives result[key] = field } } diff --git a/src/types/migration/Asset.ts b/src/types/migration/Asset.ts index 98b7bd17..a784ffb5 100644 --- a/src/types/migration/Asset.ts +++ b/src/types/migration/Asset.ts @@ -5,9 +5,17 @@ import type { LinkToMediaField } from "../value/linkToMedia" import { type RTImageNode, RichTextNodeType } from "../value/richText" import type { MigrationContentRelationship } from "./ContentRelationship" -import type { DocumentMap } from "./Document" +import type { ResolveArgs } from "./Field" import { MigrationField } from "./Field" +/** + * Any type of image field handled by {@link MigrationAsset} + */ +type ImageLike = + | FilledImageFieldImage + | LinkToMediaField<"filled"> + | RTImageNode + /** * Converts an asset to an image field. * @@ -19,10 +27,7 @@ import { MigrationField } from "./Field" */ const assetToImage = ( asset: Asset, - maybeInitialField?: - | FilledImageFieldImage - | LinkToMediaField<"filled"> - | RTImageNode, + maybeInitialField?: ImageLike, ): FilledImageFieldImage => { const parameters = (maybeInitialField?.url || asset.url).split("?")[1] const url = `${asset.url.split("?")[0]}${parameters ? `?${parameters}` : ""}` @@ -99,26 +104,11 @@ export type MigrationAssetConfig = { } export abstract class MigrationAsset< - TField extends - | FilledImageFieldImage - | LinkToMediaField<"filled"> - | RTImageNode = - | FilledImageFieldImage - | LinkToMediaField<"filled"> - | RTImageNode, -> extends MigrationField< - TField, - FilledImageFieldImage | LinkToMediaField<"filled"> | RTImageNode -> { + TField extends ImageLike = ImageLike, +> extends MigrationField { config: MigrationAssetConfig - constructor( - config: MigrationAssetConfig, - initialField?: - | FilledImageFieldImage - | LinkToMediaField<"filled"> - | RTImageNode, - ) { + constructor(config: MigrationAssetConfig, initialField?: ImageLike) { super(initialField) this.config = config @@ -128,29 +118,38 @@ export abstract class MigrationAsset< return new MigrationImage(this.config, this._initialField) } - asLinkToMedia(): MigrationLinkToMedia { - return new MigrationLinkToMedia(this.config, this._initialField) + asLinkToMedia(text?: string): MigrationLinkToMedia { + return new MigrationLinkToMedia(this.config, this._initialField, text) } - asRTImageNode(): MigrationRTImageNode { - return new MigrationRTImageNode(this.config, this._initialField) + asRTImageNode( + linkTo?: + | MigrationLinkToMedia + | MigrationContentRelationship + | FilledLinkToWebField, + ): MigrationRTImageNode { + return new MigrationRTImageNode(this.config, this._initialField, linkTo) } } +/** + * A map of asset IDs to asset used to resolve assets when patching migration + * Prismic documents. + * + * @internal + */ +export type AssetMap = Map + export class MigrationImage extends MigrationAsset { #thumbnails: Record = {} - addThumbnail(name: string, thumbnail: MigrationImage): void { + addThumbnail(name: string, thumbnail: MigrationImage): this { this.#thumbnails[name] = thumbnail + + return this } - async _resolve({ - assets, - documents, - }: { - assets: AssetMap - documents: DocumentMap - }): Promise { + async _resolve({ assets, documents }: ResolveArgs): Promise { const asset = assets.get(this.config.id) if (asset) { @@ -171,7 +170,19 @@ export class MigrationImage extends MigrationAsset { export class MigrationLinkToMedia extends MigrationAsset< LinkToMediaField<"filled"> > { - _resolve({ assets }: { assets: AssetMap }): void { + text?: string + + constructor( + config: MigrationAssetConfig, + initialField?: ImageLike, + text?: string, + ) { + super(config, initialField) + + this.text = text + } + + _resolve({ assets }: ResolveArgs): void { const asset = assets.get(this.config.id) if (asset) { @@ -185,25 +196,34 @@ export class MigrationLinkToMedia extends MigrationAsset< height: typeof asset.height === "number" ? `${asset.height}` : undefined, width: typeof asset.width === "number" ? `${asset.width}` : undefined, + // TODO: Remove when link text PR is merged + // @ts-expect-error - Future-proofing for link text + text: this.text, } } } } export class MigrationRTImageNode extends MigrationAsset { - linkTo: + linkTo?: | MigrationLinkToMedia | MigrationContentRelationship | FilledLinkToWebField - | undefined - - async _resolve({ - assets, - documents, - }: { - assets: AssetMap - documents: DocumentMap - }): Promise { + + constructor( + config: MigrationAssetConfig, + initialField?: ImageLike, + linkTo?: + | MigrationLinkToMedia + | MigrationContentRelationship + | FilledLinkToWebField, + ) { + super(config, initialField) + + this.linkTo = linkTo + } + + async _resolve({ assets, documents }: ResolveArgs): Promise { const asset = assets.get(this.config.id) if (this.linkTo instanceof MigrationField) { @@ -222,11 +242,3 @@ export class MigrationRTImageNode extends MigrationAsset { } } } - -/** - * A map of asset IDs to asset used to resolve assets when patching migration - * Prismic documents. - * - * @internal - */ -export type AssetMap = Map diff --git a/src/types/migration/ContentRelationship.ts b/src/types/migration/ContentRelationship.ts index 6ada005a..cc5fb6ad 100644 --- a/src/types/migration/ContentRelationship.ts +++ b/src/types/migration/ContentRelationship.ts @@ -2,34 +2,42 @@ import type { FilledContentRelationshipField } from "../value/contentRelationshi import type { PrismicDocument } from "../value/document" import { LinkType } from "../value/link" -import type { DocumentMap, MigrationDocument } from "./Document" +import type { MigrationDocument } from "./Document" +import type { ResolveArgs } from "./Field" import { MigrationField } from "./Field" -type MigrationContentRelationshipConfig = - | PrismicDocument - | MigrationDocument +type MigrationContentRelationshipConfig< + TDocuments extends PrismicDocument = PrismicDocument, +> = + | TDocuments + | MigrationDocument | FilledContentRelationshipField | undefined -export type UnresolvedMigrationContentRelationshipConfig = - | MigrationContentRelationshipConfig +export type UnresolvedMigrationContentRelationshipConfig< + TDocuments extends PrismicDocument = PrismicDocument, +> = + | MigrationContentRelationshipConfig | (() => - | Promise - | MigrationContentRelationshipConfig) + | Promise> + | MigrationContentRelationshipConfig) export class MigrationContentRelationship extends MigrationField { unresolvedConfig: UnresolvedMigrationContentRelationshipConfig + text?: string constructor( unresolvedConfig: UnresolvedMigrationContentRelationshipConfig, initialField?: FilledContentRelationshipField, + text?: string, ) { super(initialField) this.unresolvedConfig = unresolvedConfig + this.text = text } - async _resolve({ documents }: { documents: DocumentMap }): Promise { + async _resolve({ documents }: ResolveArgs): Promise { const config = typeof this.unresolvedConfig === "function" ? await this.unresolvedConfig() @@ -48,6 +56,9 @@ export class MigrationContentRelationship extends MigrationField & { - data: - | MigrationLinkToMedia - | MigrationContentRelationship - | UnresolvedMigrationContentRelationshipConfig + data: MigrationLinkToMedia | MigrationContentRelationship }) )[] } @@ -89,10 +82,7 @@ type RegularFieldWithMigrationField< : TField extends FilledLinkToMediaField ? MigrationLinkToMedia | undefined : TField extends FilledContentRelationshipField - ? - | MigrationContentRelationship - | UnresolvedMigrationContentRelationshipConfig - | undefined + ? MigrationContentRelationship | undefined : TField extends RichTextField ? RichTextFieldWithMigrationField : never) @@ -161,8 +151,8 @@ export type FieldsWithMigrationFields< } /** - * Makes the UID of `PrismicMigrationDocument` optional on custom types without - * UID. TypeScript fails to infer correct types if done with a type + * Makes the UID of {@link MigrationDocumentValue} optional on custom types + * without UID. TypeScript fails to infer correct types if done with a type * intersection. * * @internal @@ -177,7 +167,7 @@ type MakeUIDOptional = * * @see More details on the migraiton API: {@link https://prismic.io/docs/migration-api-technical-reference} */ -export type PrismicMigrationDocument< +export type MigrationDocumentValue< TDocument extends PrismicDocument = PrismicDocument, > = TDocument extends PrismicDocument @@ -235,7 +225,7 @@ export type PrismicMigrationDocument< * * @see More details on the migraiton API: {@link https://prismic.io/docs/migration-api-technical-reference} */ -export type PrismicMigrationDocumentParams = { +export type MigrationDocumentParams = { /** * Name of the document displayed in the editor. */ @@ -247,24 +237,22 @@ export type PrismicMigrationDocumentParams = { // We're forced to inline `ContentRelationshipMigrationField` here, otherwise // it creates a circular reference to itself which makes TypeScript unhappy. // (but I think it's weird and it doesn't make sense :thinking:) - masterLanguageDocument?: - | UnresolvedMigrationContentRelationshipConfig - | undefined + masterLanguageDocument?: MigrationContentRelationship } export class MigrationDocument< TDocument extends PrismicDocument = PrismicDocument, > { - document: PrismicMigrationDocument - params: PrismicMigrationDocumentParams + value: MigrationDocumentValue + params: MigrationDocumentParams dependencies: MigrationField[] constructor( - document: PrismicMigrationDocument, - params: PrismicMigrationDocumentParams, + value: MigrationDocumentValue, + params: MigrationDocumentParams, dependencies: MigrationField[] = [], ) { - this.document = document + this.value = value this.params = params this.dependencies = dependencies } @@ -272,10 +260,7 @@ export class MigrationDocument< /** * @internal */ - async _resolve(args: { - assets: AssetMap - documents: DocumentMap - }): Promise { + async _resolve(args: ResolveArgs): Promise { for (const dependency of this.dependencies) { await dependency._resolve(args) } @@ -295,5 +280,5 @@ export type DocumentMap = Map< string | MigrationDocument | MigrationDocument, | PrismicDocument - | (Omit, "id"> & { id: string }) + | (Omit, "id"> & { id: string }) > diff --git a/src/types/migration/Field.ts b/src/types/migration/Field.ts index edf4618c..df11e3fd 100644 --- a/src/types/migration/Field.ts +++ b/src/types/migration/Field.ts @@ -5,14 +5,16 @@ import type { RTBlockNode, RTInlineNode } from "../value/richText" import type { AssetMap } from "./Asset" import type { DocumentMap } from "./Document" +export type ResolveArgs = { + assets: AssetMap + documents: DocumentMap +} + interface Preparable { /** * @internal */ - _resolve(args: { - assets: AssetMap - documents: DocumentMap - }): Promise | void + _resolve(args: ResolveArgs): Promise | void } export abstract class MigrationField< @@ -26,12 +28,12 @@ export abstract class MigrationField< /** * @internal */ - _field: TField | undefined + _field?: TField /** * @internal */ - _initialField: TInitialField | undefined + _initialField?: TInitialField constructor(initialField?: TInitialField) { this._initialField = initialField @@ -41,8 +43,5 @@ export abstract class MigrationField< return this._field } - abstract _resolve(args: { - assets: AssetMap - documents: DocumentMap - }): Promise | void + abstract _resolve(args: ResolveArgs): Promise | void } diff --git a/test/__testutils__/testMigrationFieldPatching.ts b/test/__testutils__/testMigrationFieldPatching.ts index 4a4c1a32..e9650ea5 100644 --- a/test/__testutils__/testMigrationFieldPatching.ts +++ b/test/__testutils__/testMigrationFieldPatching.ts @@ -27,7 +27,7 @@ type GetDataArgs = { } type InternalTestMigrationFieldPatchingArgs = { - getData: (args: GetDataArgs) => prismic.PrismicMigrationDocument["data"] + getData: (args: GetDataArgs) => prismic.MigrationDocumentValue["data"] expectStrictEqual?: boolean } @@ -115,7 +115,7 @@ const internalTestMigrationFieldPatching = ( type TestMigrationFieldPatchingFactoryCases = Record< string, - (args: GetDataArgs) => prismic.PrismicMigrationDocument["data"][string] + (args: GetDataArgs) => prismic.MigrationDocumentValue["data"][string] > export const testMigrationFieldPatching = ( diff --git a/test/migration-createDocument.test.ts b/test/migration-createDocument.test.ts index 960d2c0a..0877330b 100644 --- a/test/migration-createDocument.test.ts +++ b/test/migration-createDocument.test.ts @@ -9,7 +9,7 @@ import { MigrationDocument } from "../src/types/migration/Document" it("creates a document", () => { const migration = prismic.createMigration() - const document: prismic.PrismicMigrationDocument = { + const document: prismic.MigrationDocumentValue = { type: "type", uid: "uid", lang: "lang", @@ -184,7 +184,7 @@ describe.each<{ const { id, field, expected } = getField(mock) - const document: prismic.PrismicMigrationDocument = { + const document: prismic.MigrationDocumentValue = { type: "type", uid: "uid", lang: "lang", @@ -204,7 +204,7 @@ describe.each<{ const { id, field, expected } = getField(mock) - const document: prismic.PrismicMigrationDocument = { + const document: prismic.MigrationDocumentValue = { type: "type", uid: "uid", lang: "lang", @@ -234,7 +234,7 @@ describe.each<{ }, ] - const document: prismic.PrismicMigrationDocument = { + const document: prismic.MigrationDocumentValue = { type: "type", uid: "uid", lang: "lang", @@ -264,7 +264,7 @@ describe.each<{ }, ] - const document: prismic.PrismicMigrationDocument = { + const document: prismic.MigrationDocumentValue = { type: "type", uid: "uid", lang: "lang", diff --git a/test/types/migration-document.types.ts b/test/types/migration-document.types.ts index 14237c1a..e43626a3 100644 --- a/test/types/migration-document.types.ts +++ b/test/types/migration-document.types.ts @@ -3,7 +3,7 @@ import { expectNever, expectType } from "ts-expect" import type * as prismic from "../../src" -;(value: prismic.PrismicMigrationDocument): true => { +;(value: prismic.MigrationDocumentValue): true => { switch (typeof value) { case "object": { if (value === null) { @@ -19,7 +19,7 @@ import type * as prismic from "../../src" } } -expectType({ +expectType({ uid: "", type: "", lang: "", @@ -29,7 +29,7 @@ expectType({ /** * Supports any field when generic. */ -expectType({ +expectType({ uid: "", type: "", lang: "", @@ -39,12 +39,12 @@ expectType({ }) /** - * `PrismicDocument` is assignable to `PrismicMigrationDocument` with added + * `PrismicDocument` is assignable to `MigrationDocumentValue` with added * `title`. */ expectType< TypeOf< - prismic.PrismicMigrationDocument, + prismic.MigrationDocumentValue, prismic.PrismicDocument & { title: string } > >(true) @@ -55,7 +55,7 @@ type BarDocument = prismic.PrismicDocument<{ bar: prismic.KeyTextField }, "bar"> type BazDocument = prismic.PrismicDocument, "baz"> type Documents = FooDocument | BarDocument | BazDocument -type MigrationDocuments = prismic.PrismicMigrationDocument +type MigrationDocuments = prismic.MigrationDocumentValue /** * Infers data type from document type. @@ -128,7 +128,7 @@ type SliceDocument = prismic.PrismicDocument< > type AdvancedDocuments = StaticDocument | GroupDocument | SliceDocument type MigrationAdvancedDocuments = - prismic.PrismicMigrationDocument + prismic.MigrationDocumentValue // Static expectType({ diff --git a/test/writeClient-migrate-documents.test.ts b/test/writeClient-migrate-documents.test.ts index fcb75ae7..a1197304 100644 --- a/test/writeClient-migrate-documents.test.ts +++ b/test/writeClient-migrate-documents.test.ts @@ -93,7 +93,7 @@ it.concurrent("skips creating existing documents", async (ctx) => { const migration = prismic.createMigration() - migration.createDocument(document, "foo") + const migrationDocument = migration.createDocument(document, "foo") const reporter = vi.fn() @@ -106,10 +106,7 @@ it.concurrent("skips creating existing documents", async (ctx) => { current: 1, remaining: 0, total: 1, - document, - documentParams: { - documentTitle: "foo", - }, + document: migrationDocument, }, }) expect(reporter).toHaveBeenCalledWith({ @@ -156,10 +153,7 @@ it.concurrent("creates new documents", async (ctx) => { current: 1, remaining: 0, total: 1, - document, - documentParams: { - documentTitle: "foo", - }, + document: migrationDocument, }, }) expect(documents?.get(migrationDocument)?.id).toBe(newDocument.id) @@ -190,7 +184,9 @@ it.concurrent( const migration = prismic.createMigration() const migrationDocument = migration.createDocument(document, "foo", { - masterLanguageDocument, + masterLanguageDocument: migration.createContentRelationship( + masterLanguageDocument, + ), }) let documents: DocumentMap | undefined @@ -210,11 +206,7 @@ it.concurrent( current: 1, remaining: 0, total: 1, - document, - documentParams: { - documentTitle: "foo", - masterLanguageDocument, - }, + document: migrationDocument, }, }) ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocument.id) @@ -228,9 +220,8 @@ it.concurrent( const client = createTestWriteClient({ ctx }) const masterLanguageDocument = - ctx.mock.value.document() as prismic.PrismicMigrationDocument - const document = - ctx.mock.value.document() as prismic.PrismicMigrationDocument + ctx.mock.value.document() as prismic.MigrationDocumentValue + const document = ctx.mock.value.document() as prismic.MigrationDocumentValue const newDocuments = [ { id: masterLanguageDocument.id!, @@ -255,7 +246,9 @@ it.concurrent( "foo", ) const migrationDocument = migration.createDocument(document, "bar", { - masterLanguageDocument: masterLanguageMigrationDocument, + masterLanguageDocument: migration.createContentRelationship( + masterLanguageMigrationDocument, + ), }) let documents: DocumentMap | undefined @@ -302,7 +295,9 @@ it.concurrent( const migration = prismic.createMigration() const migrationDocument = migration.createDocument(document, "foo", { - masterLanguageDocument: () => masterLanguageDocument, + masterLanguageDocument: migration.createContentRelationship( + () => masterLanguageDocument, + ), }) let documents: DocumentMap | undefined @@ -322,11 +317,7 @@ it.concurrent( current: 1, remaining: 0, total: 1, - document, - documentParams: { - documentTitle: "foo", - masterLanguageDocument: expect.any(Function), - }, + document: migrationDocument, }, }) ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocument.id) @@ -340,9 +331,8 @@ it.concurrent( const client = createTestWriteClient({ ctx }) const masterLanguageDocument = - ctx.mock.value.document() as prismic.PrismicMigrationDocument - const document = - ctx.mock.value.document() as prismic.PrismicMigrationDocument + ctx.mock.value.document() as prismic.MigrationDocumentValue + const document = ctx.mock.value.document() as prismic.MigrationDocumentValue const newDocuments = [ { id: masterLanguageDocument.id!, @@ -367,7 +357,9 @@ it.concurrent( "foo", ) const migrationDocument = migration.createDocument(document, "bar", { - masterLanguageDocument: () => masterLanguageMigrationDocument, + masterLanguageDocument: migration.createContentRelationship( + () => masterLanguageMigrationDocument, + ), }) let documents: DocumentMap | undefined @@ -436,10 +428,7 @@ it.concurrent( current: 1, remaining: 0, total: 1, - document, - documentParams: { - documentTitle: "foo", - }, + document: migrationDocument, }, }) ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocument.id) diff --git a/test/writeClient-migrate-patch-contentRelationship.test.ts b/test/writeClient-migrate-patch-contentRelationship.test.ts index 5cd030b8..98713761 100644 --- a/test/writeClient-migrate-patch-contentRelationship.test.ts +++ b/test/writeClient-migrate-patch-contentRelationship.test.ts @@ -3,42 +3,45 @@ import { testMigrationFieldPatching } from "./__testutils__/testMigrationFieldPa import { RichTextNodeType } from "../src" testMigrationFieldPatching("patches link fields", { - existing: ({ existingDocuments }) => existingDocuments[0], - migration: ({ migrationDocuments }) => { - delete migrationDocuments[0].document.id + existing: ({ migration, existingDocuments }) => + migration.createContentRelationship(existingDocuments[0]), + migration: ({ migration, migrationDocuments }) => { + delete migrationDocuments[0].value.id - return migrationDocuments[0] + return migration.createContentRelationship(migrationDocuments[0]) }, - lazyExisting: ({ existingDocuments }) => { - return () => existingDocuments[0] + lazyExisting: ({ migration, existingDocuments }) => { + return migration.createContentRelationship(() => existingDocuments[0]) }, lazyMigration: ({ migration, migrationDocuments }) => { - delete migrationDocuments[0].document.id + delete migrationDocuments[0].value.id - return () => + return migration.createContentRelationship(() => migration.getByUID( - migrationDocuments[0].document.type, - migrationDocuments[0].document.uid!, - ) + migrationDocuments[0].value.type, + migrationDocuments[0].value.uid!, + ), + ) }, migrationNoTags: ({ migration, migrationDocuments }) => { - migrationDocuments[0].document.tags = undefined + migrationDocuments[0].value.tags = undefined - return () => + return migration.createContentRelationship(() => migration.getByUID( - migrationDocuments[0].document.type, - migrationDocuments[0].document.uid!, - ) + migrationDocuments[0].value.type, + migrationDocuments[0].value.uid!, + ), + ) }, otherRepositoryContentRelationship: ({ ctx, migrationDocuments }) => { const contentRelationship = ctx.mock.value.link({ type: "Document" }) // `migrationDocuments` contains documents from "another repository" - contentRelationship.id = migrationDocuments[0].document.id! + contentRelationship.id = migrationDocuments[0].value.id! return contentRelationship }, brokenLink: ({ ctx }) => ctx.mock.value.link({ type: "Document" }), - richTextLinkNode: ({ existingDocuments }) => [ + richTextLinkNode: ({ migration, existingDocuments }) => [ { type: RichTextNodeType.paragraph, text: "lorem", @@ -48,7 +51,7 @@ testMigrationFieldPatching("patches link fields", { type: RichTextNodeType.hyperlink, start: 0, end: 5, - data: existingDocuments[0], + data: migration.createContentRelationship(existingDocuments[0]), }, ], }, diff --git a/test/writeClient-migrate-patch-rtImageNode.test.ts b/test/writeClient-migrate-patch-rtImageNode.test.ts index 4d69bc1e..47d9ace3 100644 --- a/test/writeClient-migrate-patch-rtImageNode.test.ts +++ b/test/writeClient-migrate-patch-rtImageNode.test.ts @@ -21,23 +21,25 @@ testMigrationFieldPatching("patches rich text image nodes", { url: `${mockedDomain}/foo.png`, }, ], - newLinkTo: ({ ctx, migration, existingDocuments }) => { - const rtImageNode = migration.createAsset("foo", "foo.png").asRTImageNode() - rtImageNode.linkTo = new MigrationContentRelationship(existingDocuments[0]) - - return [ - ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), - rtImageNode, - ] - }, - otherRepositoryLinkTo: ({ ctx, mockedDomain, existingDocuments }) => [ + newLinkTo: ({ ctx, migration, existingDocuments }) => [ + ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), + migration + .createAsset("foo", "foo.png") + .asRTImageNode(new MigrationContentRelationship(existingDocuments[0])), + ], + otherRepositoryLinkTo: ({ + ctx, + migration, + mockedDomain, + existingDocuments, + }) => [ ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), { type: RichTextNodeType.image, ...ctx.mock.value.image({ state: "filled" }), id: "foo-id", url: `${mockedDomain}/foo.png`, - linkTo: existingDocuments[0], + linkTo: migration.createContentRelationship(existingDocuments[0]), }, ], }) diff --git a/test/writeClient-migrate.test.ts b/test/writeClient-migrate.test.ts index 3f6bb056..4d70c967 100644 --- a/test/writeClient-migrate.test.ts +++ b/test/writeClient-migrate.test.ts @@ -37,8 +37,7 @@ it.concurrent("performs migration", async (ctx) => { const migration = prismic.createMigration() - const documentFoo: prismic.PrismicMigrationDocument = - ctx.mock.value.document() + const documentFoo: prismic.MigrationDocumentValue = ctx.mock.value.document() documentFoo.data = { image: migration.createAsset("foo", "foo.png"), link: () => migration.getByUID("bar", "bar"), From 9a072778e19dbb175a178e6c593d3cddc28056b4 Mon Sep 17 00:00:00 2001 From: lihbr Date: Thu, 12 Sep 2024 16:05:08 +0200 Subject: [PATCH 05/13] docs: document new types --- src/Migration.ts | 218 ++++++++++++++++++--- src/WriteClient.ts | 62 +++--- src/lib/pLimit.ts | 10 +- src/lib/prepareMigrationRecord.ts | 13 +- src/types/migration/Asset.ts | 121 ++++++++++-- src/types/migration/ContentRelationship.ts | 42 +++- src/types/migration/Document.ts | 63 +++++- src/types/migration/Field.ts | 49 ++++- test/migration-updateDocument.test.ts | 17 ++ test/writeClient-migrate-documents.test.ts | 43 +++- 10 files changed, 538 insertions(+), 100 deletions(-) create mode 100644 test/migration-updateDocument.test.ts diff --git a/src/Migration.ts b/src/Migration.ts index c0e09732..bbd78244 100644 --- a/src/Migration.ts +++ b/src/Migration.ts @@ -48,22 +48,77 @@ export class Migration< MigrationDocumentValue = MigrationDocumentValue, > { /** + * Assets registered in the migration. + * * @internal */ _assets: Map = new Map() /** + * Documents registered in the migration. + * * @internal */ _documents: MigrationDocument[] = [] + + /** + * A map indexing documents by their type and UID used for quick lookups by + * the {@link getByUID} and {@link getSingle} methods. + */ #indexedDocuments: Record< string, Record> > = {} + /** + * 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 configured to be serialized as an + * image field by default. + */ + createAsset(asset: Asset): MigrationImage + + /** + * 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 configured to be serialized as an + * image field by default. + */ createAsset( - asset: Asset | FilledImageFieldImage | FilledLinkToMediaField, + imageOrLinkToMediaField: FilledImageFieldImage | FilledLinkToMediaField, ): MigrationImage + + /** + * 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 configured to be serialized as an + * image field by default. + */ createAsset( file: MigrationAssetConfig["file"], filename: MigrationAssetConfig["filename"], @@ -74,8 +129,21 @@ export class Migration< tags?: string[] }, ): MigrationImage + + /** + * Registers an asset to be created in the migration from a file, an asset + * object, or 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. + * + * @returns A migration asset field instance configured to be serialized as an + * image field by default. + */ createAsset( - fileOrAsset: + fileOrAssetOrField: | MigrationAssetConfig["file"] | Asset | FilledImageFieldImage @@ -95,26 +163,31 @@ export class Migration< ): MigrationImage { let asset: MigrationAssetConfig let maybeInitialField: FilledImageFieldImage | undefined - if (typeof fileOrAsset === "object" && "url" in fileOrAsset) { - if ("dimensions" in fileOrAsset || "link_type" in fileOrAsset) { - const url = fileOrAsset.url.split("?")[0] + if (typeof fileOrAssetOrField === "object" && "url" in fileOrAssetOrField) { + if ( + "dimensions" in fileOrAssetOrField || + "link_type" in fileOrAssetOrField + ) { + const url = fileOrAssetOrField.url.split("?")[0] const filename = - "name" in fileOrAsset - ? fileOrAsset.name + "name" in fileOrAssetOrField + ? fileOrAssetOrField.name : url.split("/").pop()!.split("_").pop()! const credits = - "copyright" in fileOrAsset && fileOrAsset.copyright - ? fileOrAsset.copyright + "copyright" in fileOrAssetOrField && fileOrAssetOrField.copyright + ? fileOrAssetOrField.copyright : undefined const alt = - "alt" in fileOrAsset && fileOrAsset.alt ? fileOrAsset.alt : undefined + "alt" in fileOrAssetOrField && fileOrAssetOrField.alt + ? fileOrAssetOrField.alt + : undefined - if ("dimensions" in fileOrAsset) { - maybeInitialField = fileOrAsset + if ("dimensions" in fileOrAssetOrField) { + maybeInitialField = fileOrAssetOrField } asset = { - id: fileOrAsset.id, + id: fileOrAssetOrField.id, file: url, filename, notes: undefined, @@ -124,19 +197,19 @@ export class Migration< } } else { asset = { - id: fileOrAsset.id, - file: fileOrAsset.url, - filename: fileOrAsset.filename, - notes: fileOrAsset.notes, - credits: fileOrAsset.credits, - alt: fileOrAsset.alt, - tags: fileOrAsset.tags?.map(({ name }) => name), + id: fileOrAssetOrField.id, + file: fileOrAssetOrField.url, + filename: fileOrAssetOrField.filename, + notes: fileOrAssetOrField.notes, + credits: fileOrAssetOrField.credits, + alt: fileOrAssetOrField.alt, + tags: fileOrAssetOrField.tags?.map(({ name }) => name), } } } else { asset = { - id: fileOrAsset, - file: fileOrAsset, + id: fileOrAssetOrField, + file: fileOrAssetOrField, filename: filename!, notes, credits, @@ -167,6 +240,23 @@ export class Migration< return new MigrationImage(this._assets.get(asset.id)!, maybeInitialField) } + /** + * 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 Prismic documents to create. + * + * @param document - The document to create. + * @param documentTitle - 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( document: ExtractDocumentType, documentTitle: string, @@ -198,13 +288,76 @@ export class Migration< return migrationDocument } + /** + * 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 documentTitle - The title of the document to update which will be + * displayed in the editor. + * + * @returns A migration document instance. + */ + updateDocument( + document: Omit, "id"> & { + id: string + }, + documentTitle: string, + ): MigrationDocument> { + const migrationDocument = this.createDocument( + document as ExtractDocumentType, + documentTitle, + ) + + migrationDocument._mode = "update" + + return migrationDocument + } + + /** + * Creates a content relationship fields that can be used in documents to link + * to other documents. + * + * @param config - A Prismic document, a migration document instance, an + * existing content relationship field's content, or a function that returns + * one of the previous. + * @param text - Link text associated with the content relationship field. + * + * @returns A migration content relationship field instance. + */ createContentRelationship( config: UnresolvedMigrationContentRelationshipConfig, text?: string, ): MigrationContentRelationship { - return new MigrationContentRelationship(config, undefined, text) + return new MigrationContentRelationship(config, text, undefined) } + /** + * 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 documentType - 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( documentType: TType, uid: string, @@ -214,6 +367,25 @@ export class Migration< | 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 documentType - The API ID of the singleton custom type. + * + * @returns The migration document instance for the custom type, if a matching + * document is found. + */ getSingle( documentType: TType, ): MigrationDocument> | undefined { diff --git a/src/WriteClient.ts b/src/WriteClient.ts index 03b1a50c..451b25f5 100644 --- a/src/WriteClient.ts +++ b/src/WriteClient.ts @@ -531,10 +531,10 @@ export class WriteClient< let i = 0 let created = 0 - for (const migrationDocument of sortedMigrationDocuments) { + for (const document of sortedMigrationDocuments) { if ( - migrationDocument.value.id && - documents.has(migrationDocument.value.id) + document.value.id && + (document._mode === "update" || documents.has(document.value.id)) ) { reporter?.({ type: "documents:skipping", @@ -543,15 +543,12 @@ export class WriteClient< current: ++i, remaining: sortedMigrationDocuments.length - i, total: sortedMigrationDocuments.length, - document: migrationDocument, + document: document, }, }) // Index the migration document - documents.set( - migrationDocument, - documents.get(migrationDocument.value.id)!, - ) + documents.set(document, documents.get(document.value.id)!) } else { created++ reporter?.({ @@ -560,30 +557,29 @@ export class WriteClient< current: ++i, remaining: sortedMigrationDocuments.length - i, total: sortedMigrationDocuments.length, - document: migrationDocument, + document: document, }, }) // Resolve master language document ID for non-master locale documents let masterLanguageDocumentID: string | undefined - if (migrationDocument.value.lang !== masterLocale) { - if (migrationDocument.params.masterLanguageDocument) { - const link = migrationDocument.params.masterLanguageDocument + if (document.value.lang !== masterLocale) { + if (document.params.masterLanguageDocument) { + const link = document.params.masterLanguageDocument await link._resolve({ documents, assets: new Map() }) masterLanguageDocumentID = link._field?.id - } else if (migrationDocument.value.alternate_languages) { - masterLanguageDocumentID = - migrationDocument.value.alternate_languages.find( - ({ lang }) => lang === masterLocale, - )?.id + } else if (document.value.alternate_languages) { + masterLanguageDocumentID = document.value.alternate_languages.find( + ({ lang }) => lang === masterLocale, + )?.id } } const { id } = await this.createDocument( // We'll upload docuements data later on. - { ...migrationDocument.value, data: {} }, - migrationDocument.params.documentTitle, + { ...document.value, data: {} }, + document.params.documentTitle, { masterLanguageDocumentID, ...fetchParams, @@ -591,13 +587,13 @@ export class WriteClient< ) // Index old ID for Prismic to Prismic migration - if (migrationDocument.value.id) { - documents.set(migrationDocument.value.id, { - ...migrationDocument.value, + if (document.value.id) { + documents.set(document.value.id, { + ...document.value, id, }) } - documents.set(migrationDocument, { ...migrationDocument.value, id }) + documents.set(document, { ...document.value, id }) } } @@ -633,29 +629,29 @@ export class WriteClient< }: { reporter?: (event: MigrateReporterEvents) => void } & FetchParams = {}, ): Promise { let i = 0 - for (const migrationDocument of migration._documents) { + for (const document of migration._documents) { reporter?.({ type: "documents:updating", data: { current: ++i, remaining: migration._documents.length - i, total: migration._documents.length, - document: migrationDocument, + document: document, }, }) - const { id, uid } = documents.get(migrationDocument)! - await migrationDocument._resolve({ assets, documents }) + const { id, uid } = documents.get(document)! + await document._resolve({ assets, documents }) await this.updateDocument( id, // We need to forward again document name and tags to update them // in case the document already existed during the previous step. { - documentTitle: migrationDocument.params.documentTitle, + documentTitle: document.params.documentTitle, uid, - tags: migrationDocument.value.tags, - data: migrationDocument.value.data, + tags: document.value.tags, + data: document.value.data, }, fetchParams, ) @@ -1025,8 +1021,8 @@ export class WriteClient< * * @typeParam TType - Type of Prismic documents to create. * - * @param document - The document data to create. - * @param documentTitle - The name of the document to create which will be + * @param document - The document to create. + * @param documentTitle - The title of the document to create which will be * displayed in the editor. * @param params - Document master language document ID and additional fetch * parameters. @@ -1071,7 +1067,7 @@ export class WriteClient< * @typeParam TType - Type of Prismic documents to update. * * @param id - The ID of the document to update. - * @param document - The document data to update. + * @param document - The document content to update. * @param params - Additional fetch parameters. * * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference} diff --git a/src/lib/pLimit.ts b/src/lib/pLimit.ts index 40aba216..13eab709 100644 --- a/src/lib/pLimit.ts +++ b/src/lib/pLimit.ts @@ -37,18 +37,18 @@ export const pLimit = ({ interval, }: { interval?: number } = {}): LimitFunction => { const queue: AnyFunction[] = [] - let activeCount = 0 + let busy = false let lastCompletion = 0 const resumeNext = () => { - if (activeCount === 0 && queue.length > 0) { + if (!busy && queue.length > 0) { queue.shift()?.() - activeCount++ + busy = true } } const next = () => { - activeCount-- + busy = false resumeNext() } @@ -93,7 +93,7 @@ export const pLimit = ({ // needs to happen asynchronously as well to get an up-to-date value for `activeCount`. await Promise.resolve() - if (activeCount === 0) { + if (!busy) { resumeNext() } })() diff --git a/src/lib/prepareMigrationRecord.ts b/src/lib/prepareMigrationRecord.ts index 618d4c7f..64055503 100644 --- a/src/lib/prepareMigrationRecord.ts +++ b/src/lib/prepareMigrationRecord.ts @@ -11,7 +11,7 @@ import type { FilledLinkToMediaField } from "../types/value/linkToMedia" import * as is from "./isValue" /** - * Replaces existings assets and links in a record of Prismic fields get all + * Replaces existings assets and links in a record of Prismic fields and get all * dependencies to them. * * @typeParam TRecord - Record of values to work with. @@ -40,7 +40,9 @@ export const prepareMigrationRecord = >( result[key] = field } else if (is.linkToMedia(field)) { // Link to media - const linkToMedia = onAsset(field).asLinkToMedia() + // TODO: Remove when link text PR is merged + // @ts-expect-error - Future-proofing for link text + const linkToMedia = onAsset(field).asLinkToMedia(field.text) dependencies.push(linkToMedia) result[key] = linkToMedia @@ -86,7 +88,12 @@ export const prepareMigrationRecord = >( result[key] = image } else if (is.contentRelationship(field)) { // Content relationships - const contentRelationship = new MigrationContentRelationship(field) + const contentRelationship = new MigrationContentRelationship( + field, + // TODO: Remove when link text PR is merged + // @ts-expect-error - Future-proofing for link text + field.text, + ) dependencies.push(contentRelationship) result[key] = contentRelationship diff --git a/src/types/migration/Asset.ts b/src/types/migration/Asset.ts index a784ffb5..3ba70c93 100644 --- a/src/types/migration/Asset.ts +++ b/src/types/migration/Asset.ts @@ -103,46 +103,91 @@ export type MigrationAssetConfig = { tags?: string[] } +/** + * A migration asset used with the Prismic Migration API. + * + * @typeParam TImageLike - Type of the image-like value. + */ export abstract class MigrationAsset< - TField extends ImageLike = ImageLike, -> extends MigrationField { - config: MigrationAssetConfig + TImageLike extends ImageLike = ImageLike, +> extends MigrationField { + /** + * Configuration of the asset. + * + * @internal + */ + _config: MigrationAssetConfig + /** + * Creates a migration asset used with the Prismic Migration API. + * + * @param config - Configuration of the asset. + * @param initialField - The initial field value if any. + * + * @returns A migration asset instance. + */ constructor(config: MigrationAssetConfig, initialField?: ImageLike) { super(initialField) - this.config = config + this._config = config } + /** + * Marks the migration asset instance to be serialized as an image field. + * + * @returns A migration image instance. + */ asImage(): MigrationImage { - return new MigrationImage(this.config, this._initialField) + return new MigrationImage(this._config, this._initialField) } + /** + * Marks the migration asset instance to be serialized as a link to media + * field. + * + * @param text - Link text for the link to media field if any. + * + * @returns A migration link to media instance. + */ asLinkToMedia(text?: string): MigrationLinkToMedia { - return new MigrationLinkToMedia(this.config, this._initialField, text) + return new MigrationLinkToMedia(this._config, text, this._initialField) } + /** + * Marks the migration asset instance to be serialized as a rich text image + * node. + * + * @param linkTo - Image node's link if any. + * + * @returns A migration rich text image node instance. + */ asRTImageNode( linkTo?: | MigrationLinkToMedia | MigrationContentRelationship | FilledLinkToWebField, ): MigrationRTImageNode { - return new MigrationRTImageNode(this.config, this._initialField, linkTo) + return new MigrationRTImageNode(this._config, linkTo, this._initialField) } } /** - * A map of asset IDs to asset used to resolve assets when patching migration - * Prismic documents. - * - * @internal + * A migration image used with the Prismic Migration API. */ -export type AssetMap = Map - export class MigrationImage extends MigrationAsset { + /** + * Thumbnails of the image. + */ #thumbnails: Record = {} + /** + * Adds a thumbnail to the migration image instance. + * + * @param name - Name of the thumbnail. + * @param thumbnail - Thumbnail to add as a migration image instance. + * + * @returns The current migration image instance, useful for chaining. + */ addThumbnail(name: string, thumbnail: MigrationImage): this { this.#thumbnails[name] = thumbnail @@ -150,7 +195,7 @@ export class MigrationImage extends MigrationAsset { } async _resolve({ assets, documents }: ResolveArgs): Promise { - const asset = assets.get(this.config.id) + const asset = assets.get(this._config.id) if (asset) { this._field = assetToImage(asset, this._initialField) @@ -167,15 +212,31 @@ export class MigrationImage extends MigrationAsset { } } +/** + * A migration link to media used with the Prismic Migration API. + */ export class MigrationLinkToMedia extends MigrationAsset< LinkToMediaField<"filled"> > { + /** + * Link text for the link to media field if any. + */ text?: string + /** + * Creates a migration link to media instance used with the Prismic Migration + * API. + * + * @param config - Configuration of the asset. + * @param text - Link text for the link to media field if any. + * @param initialField - The initial field value if any. + * + * @returns A migration link to media instance. + */ constructor( config: MigrationAssetConfig, - initialField?: ImageLike, text?: string, + initialField?: ImageLike, ) { super(config, initialField) @@ -183,7 +244,7 @@ export class MigrationLinkToMedia extends MigrationAsset< } _resolve({ assets }: ResolveArgs): void { - const asset = assets.get(this.config.id) + const asset = assets.get(this._config.id) if (asset) { this._field = { @@ -204,19 +265,35 @@ export class MigrationLinkToMedia extends MigrationAsset< } } +/** + * A migration rich text image node used with the Prismic Migration API. + */ export class MigrationRTImageNode extends MigrationAsset { + /** + * Image node's link if any. + */ linkTo?: | MigrationLinkToMedia | MigrationContentRelationship | FilledLinkToWebField + /** + * Creates a migration rich text image node instance used with the Prismic + * Migration API. + * + * @param config - Configuration of the asset. + * @param linkTo - Image node's link if any. + * @param initialField - The initial field value if any. + * + * @returns A migration rich text image node instance. + */ constructor( config: MigrationAssetConfig, - initialField?: ImageLike, linkTo?: | MigrationLinkToMedia | MigrationContentRelationship | FilledLinkToWebField, + initialField?: ImageLike, ) { super(config, initialField) @@ -224,7 +301,7 @@ export class MigrationRTImageNode extends MigrationAsset { } async _resolve({ assets, documents }: ResolveArgs): Promise { - const asset = assets.get(this.config.id) + const asset = assets.get(this._config.id) if (this.linkTo instanceof MigrationField) { await this.linkTo._resolve({ assets, documents }) @@ -242,3 +319,11 @@ export class MigrationRTImageNode extends MigrationAsset { } } } + +/** + * A map of asset IDs to asset used to resolve assets when patching migration + * Prismic documents. + * + * @internal + */ +export type AssetMap = Map diff --git a/src/types/migration/ContentRelationship.ts b/src/types/migration/ContentRelationship.ts index cc5fb6ad..cc56c1ae 100644 --- a/src/types/migration/ContentRelationship.ts +++ b/src/types/migration/ContentRelationship.ts @@ -6,6 +6,9 @@ import type { MigrationDocument } from "./Document" import type { ResolveArgs } from "./Field" import { MigrationField } from "./Field" +/** + * Configuration used to create a content relationship field in a migration. + */ type MigrationContentRelationshipConfig< TDocuments extends PrismicDocument = PrismicDocument, > = @@ -14,6 +17,10 @@ type MigrationContentRelationshipConfig< | FilledContentRelationshipField | undefined +/** + * Unresolved configuration used to create a content relationship field in a + * migration allowing for lazy resolution. + */ export type UnresolvedMigrationContentRelationshipConfig< TDocuments extends PrismicDocument = PrismicDocument, > = @@ -22,26 +29,49 @@ export type UnresolvedMigrationContentRelationshipConfig< | Promise> | MigrationContentRelationshipConfig) +/** + * A migration content relationship field used with the Prismic Migration API. + */ export class MigrationContentRelationship extends MigrationField { - unresolvedConfig: UnresolvedMigrationContentRelationshipConfig + /** + * Unresolved configuration used to resolve the content relationship field's + * value + */ + #unresolvedConfig: UnresolvedMigrationContentRelationshipConfig + + /** + * Link text for the content relationship if any. + */ text?: string + /** + * Creates a migration content relationship field used with the Prismic + * Migration API. + * + * @param unresolvedConfig - A Prismic document, a migration document + * instance, an existing content relationship field's content, or a function + * that returns one of the previous. + * @param text - Link text for the content relationship if any. + * @param initialField - The initial field value if any. + * + * @returns A migration content relationship field instance. + */ constructor( unresolvedConfig: UnresolvedMigrationContentRelationshipConfig, - initialField?: FilledContentRelationshipField, text?: string, + initialField?: FilledContentRelationshipField, ) { super(initialField) - this.unresolvedConfig = unresolvedConfig + this.#unresolvedConfig = unresolvedConfig this.text = text } async _resolve({ documents }: ResolveArgs): Promise { const config = - typeof this.unresolvedConfig === "function" - ? await this.unresolvedConfig() - : this.unresolvedConfig + typeof this.#unresolvedConfig === "function" + ? await this.#unresolvedConfig() + : this.#unresolvedConfig if (config) { const document = diff --git a/src/types/migration/Document.ts b/src/types/migration/Document.ts index 550a5e2f..c109bcbe 100644 --- a/src/types/migration/Document.ts +++ b/src/types/migration/Document.ts @@ -3,7 +3,7 @@ import type { AnyRegularField } from "../value/types" import type { FilledContentRelationshipField } from "../value/contentRelationship" import type { PrismicDocument } from "../value/document" import type { GroupField } from "../value/group" -import type { ImageField } from "../value/image" +import type { FilledImageFieldImage } from "../value/image" import type { FilledLinkToMediaField } from "../value/linkToMedia" import type { RTBlockNode, @@ -77,7 +77,7 @@ export type RichTextFieldWithMigrationField< type RegularFieldWithMigrationField< TField extends AnyRegularField = AnyRegularField, > = - | (TField extends ImageField + | (TField extends FilledImageFieldImage ? MigrationImage | undefined : TField extends FilledLinkToMediaField ? MigrationLinkToMedia | undefined @@ -163,9 +163,9 @@ type MakeUIDOptional = : Omit & Partial> /** - * A Prismic document compatible with the Migration API. + * A Prismic document value compatible with the Migration API. * - * @see More details on the migraiton API: {@link https://prismic.io/docs/migration-api-technical-reference} + * @see More details on the Migration API: {@link https://prismic.io/docs/migration-api-technical-reference} */ export type MigrationDocumentValue< TDocument extends PrismicDocument = PrismicDocument, @@ -223,7 +223,7 @@ export type MigrationDocumentValue< /** * Parameters used when creating a Prismic document with the Migration API. * - * @see More details on the migraiton API: {@link https://prismic.io/docs/migration-api-technical-reference} + * @see More details on the Migration API: {@link https://prismic.io/docs/migration-api-technical-reference} */ export type MigrationDocumentParams = { /** @@ -240,13 +240,53 @@ export type MigrationDocumentParams = { masterLanguageDocument?: MigrationContentRelationship } +/** + * A Prismic migration document instance. + * + * @see More details on the Migration API: {@link https://prismic.io/docs/migration-api-technical-reference} + */ export class MigrationDocument< TDocument extends PrismicDocument = PrismicDocument, > { + /** + * The document value to be sent to the Migration API. + */ value: MigrationDocumentValue + + /** + * Parameters to create/update the document with on the Migration API. + */ params: MigrationDocumentParams - dependencies: MigrationField[] + /** + * Asset and content relationship fields that this document depends on. + */ + #dependencies: MigrationField[] + + /** + * The mode to use when creating or updating the document. + * + * - `auto`: Automatically determines if the document should be created or + * updated on the document's existence on the repository's Document API. + * - `update`: Forces the document to only be updated. This is useful when the + * document only exists within the migration release which cannot be + * queried. + * + * @internal + */ + _mode: "auto" | "update" = "auto" + + /** + * Creates a Prismic migration document instance. + * + * @param value - The document value to be sent to the Migration API. + * @param params - Parameters to create/update the document with on the + * Migration API. + * @param dependencies - Asset and content relationship fields that this + * document depends on. + * + * @returns A Prismic migration document instance. + */ constructor( value: MigrationDocumentValue, params: MigrationDocumentParams, @@ -254,21 +294,26 @@ export class MigrationDocument< ) { this.value = value this.params = params - this.dependencies = dependencies + this.#dependencies = dependencies } /** + * Resolves each dependencies of the document with the provided maps. + * + * @param args - A map of documents and a map of assets to resolve content + * with. + * * @internal */ async _resolve(args: ResolveArgs): Promise { - for (const dependency of this.dependencies) { + for (const dependency of this.#dependencies) { await dependency._resolve(args) } } } /** - * A map of document IDs, documents, and migraiton documents to content + * A map of document IDs, documents, and migration documents to content * relationship field used to resolve content relationships when patching * migration Prismic documents. * diff --git a/src/types/migration/Field.ts b/src/types/migration/Field.ts index df11e3fd..0f559a01 100644 --- a/src/types/migration/Field.ts +++ b/src/types/migration/Field.ts @@ -5,40 +5,85 @@ import type { RTBlockNode, RTInlineNode } from "../value/richText" import type { AssetMap } from "./Asset" import type { DocumentMap } from "./Document" +/** + * Arguments passed to the `_resolve` method of a migration field. + */ export type ResolveArgs = { + /** + * A map of asset IDs to asset used to resolve assets when patching migration + * Prismic documents. + */ assets: AssetMap + + /** + * A map of document IDs, documents, and migration documents to content + * relationship field used to resolve content relationships when patching + * migration Prismic documents. + */ documents: DocumentMap } -interface Preparable { +/** + * Interface for migration fields that can be resolved. + */ +interface Resolvable { /** + * Resolves the field's value with the provided maps. + * + * @param args - A map of documents and a map of assets to resolve content + * with. + * * @internal */ _resolve(args: ResolveArgs): Promise | void } +/** + * A migration field used with the Prismic Migration API. + * + * @typeParam TField - Type of the field value. + * @typeParam TInitialField - Type of the initial field value. + */ export abstract class MigrationField< TField extends AnyRegularField | RTBlockNode | RTInlineNode = | AnyRegularField | RTBlockNode | RTInlineNode, TInitialField = TField, -> implements Preparable +> implements Resolvable { /** + * The resolved field value. + * * @internal */ _field?: TField /** + * The initial field value this migration field was created with. + * * @internal */ _initialField?: TInitialField + /** + * Creates a migration field used with the Prismic Migration API. + * + * @param initialField - The initial field value if any. + * + * @returns A migration field instance. + */ constructor(initialField?: TInitialField) { this._initialField = initialField } + /** + * Prepares the field to be stringified with {@link JSON.stringify} + * + * @returns The value of the field to be stringified. + * + * @internal + */ toJSON(): TField | undefined { return this._field } diff --git a/test/migration-updateDocument.test.ts b/test/migration-updateDocument.test.ts new file mode 100644 index 00000000..d48aaf58 --- /dev/null +++ b/test/migration-updateDocument.test.ts @@ -0,0 +1,17 @@ +import { expect, it } from "vitest" + +import * as prismic from "../src" +import { MigrationDocument } from "../src/types/migration/Document" + +it("updates a document", (ctx) => { + const migration = prismic.createMigration() + + const document = ctx.mock.value.document() + const documentTitle = "documentTitle" + + migration.updateDocument(document, documentTitle) + + const expectedDocument = new MigrationDocument(document, { documentTitle }) + expectedDocument._mode = "update" + expect(migration._documents[0]).toStrictEqual(expectedDocument) +}) diff --git a/test/writeClient-migrate-documents.test.ts b/test/writeClient-migrate-documents.test.ts index a1197304..a16c6028 100644 --- a/test/writeClient-migrate-documents.test.ts +++ b/test/writeClient-migrate-documents.test.ts @@ -77,7 +77,48 @@ it.concurrent("discovers existing documents", async (ctx) => { }) }) -it.concurrent("skips creating existing documents", async (ctx) => { +it.concurrent("skips creating existing documents (update)", async (ctx) => { + const client = createTestWriteClient({ ctx }) + + const queryResponse = createPagedQueryResponses({ + ctx, + pages: 1, + pageSize: 1, + }) + const document = queryResponse[0].results[0] + + mockPrismicRestAPIV2({ ctx, queryResponse }) + mockPrismicAssetAPI({ ctx, client }) + mockPrismicMigrationAPI({ ctx, client, existingDocuments: [document] }) + + const migration = prismic.createMigration() + + const migrationDocument = migration.updateDocument(document, "foo") + + const reporter = vi.fn() + + await client.migrate(migration, { reporter }) + + expect(reporter).toHaveBeenCalledWith({ + type: "documents:skipping", + data: { + reason: "already exists", + current: 1, + remaining: 0, + total: 1, + document: migrationDocument, + }, + }) + expect(reporter).toHaveBeenCalledWith({ + type: "documents:created", + data: { + created: 0, + documents: expect.anything(), + }, + }) +}) + +it.concurrent("skips creating existing documents (auto)", async (ctx) => { const client = createTestWriteClient({ ctx }) const queryResponse = createPagedQueryResponses({ From f244807c4c874bb4c740d9e20a7773cb12324c07 Mon Sep 17 00:00:00 2001 From: lihbr Date: Fri, 13 Sep 2024 19:11:17 +0200 Subject: [PATCH 06/13] refactor: simplify migration documents traversing --- src/Migration.ts | 211 +++-- src/WriteClient.ts | 82 +- src/index.ts | 7 +- src/lib/isValue.ts | 53 +- ...ord.ts => prepareMigrationDocumentData.ts} | 11 +- src/types/migration/ContentRelationship.ts | 4 +- src/types/migration/Document.ts | 323 ++----- ...ate-patch-contentRelationship.test.ts.snap | 230 ++--- ...iteClient-migrate-patch-image.test.ts.snap | 794 +++++++++--------- ...ent-migrate-patch-linkToMedia.test.ts.snap | 240 +++--- ...ent-migrate-patch-rtImageNode.test.ts.snap | 474 ++++++----- .../testMigrationFieldPatching.ts | 34 +- test/migration-createDocument.test.ts | 16 +- test/migration-updateDocument.test.ts | 8 +- test/types/migration-document.types.ts | 14 +- test/types/migration.types.ts | 418 ++++++++- test/writeClient-migrate-documents.test.ts | 95 +-- ...-migrate-patch-contentRelationship.test.ts | 19 +- ...teClient-migrate-patch-simpleField.test.ts | 6 +- test/writeClient-migrate.test.ts | 8 +- test/writeClient-updateDocument.test.ts | 2 + 21 files changed, 1680 insertions(+), 1369 deletions(-) rename src/lib/{prepareMigrationRecord.ts => prepareMigrationDocumentData.ts} (91%) diff --git a/src/Migration.ts b/src/Migration.ts index bbd78244..303ca967 100644 --- a/src/Migration.ts +++ b/src/Migration.ts @@ -1,4 +1,4 @@ -import { prepareMigrationRecord } from "./lib/prepareMigrationRecord" +import { prepareMigrationDocumentData } from "./lib/prepareMigrationDocumentData" import { validateAssetMetadata } from "./lib/validateAssetMetadata" import type { Asset } from "./types/api/asset/asset" @@ -6,10 +6,10 @@ import type { MigrationAssetConfig } from "./types/migration/Asset" import { MigrationImage } from "./types/migration/Asset" import type { UnresolvedMigrationContentRelationshipConfig } from "./types/migration/ContentRelationship" import { MigrationContentRelationship } from "./types/migration/ContentRelationship" -import { MigrationDocument } from "./types/migration/Document" +import { PrismicMigrationDocument } from "./types/migration/Document" import type { - MigrationDocumentParams, - MigrationDocumentValue, + ExistingPrismicDocument, + PendingPrismicDocument, } from "./types/migration/Document" import type { PrismicDocument } from "./types/value/document" import type { FilledImageFieldImage } from "./types/value/image" @@ -24,29 +24,20 @@ import type { FilledLinkToMediaField } from "./types/value/linkToMedia" * @typeParam TDocumentType - Type(s) to match `TDocuments` against. */ type ExtractDocumentType< - TDocuments extends PrismicDocument | MigrationDocumentValue, + TDocuments extends { type: string }, TDocumentType extends TDocuments["type"], > = Extract extends never ? TDocuments : Extract -/** - * The symbol used to index documents that are singletons. - */ -const SINGLE_INDEX = "__SINGLE__" - /** * 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 class Migration< - TDocuments extends PrismicDocument = PrismicDocument, - TMigrationDocuments extends - MigrationDocumentValue = MigrationDocumentValue, -> { +export class Migration { /** * Assets registered in the migration. * @@ -59,16 +50,7 @@ export class Migration< * * @internal */ - _documents: MigrationDocument[] = [] - - /** - * A map indexing documents by their type and UID used for quick lookups by - * the {@link getByUID} and {@link getSingle} methods. - */ - #indexedDocuments: Record< - string, - Record> - > = {} + _documents: PrismicMigrationDocument[] = [] /** * Registers an asset to be created in the migration from an asset object. @@ -248,43 +230,33 @@ export class Migration< * registers it in your migration. The document will be created when the * migration is executed through the `writeClient.migrate()` method. * - * @typeParam TType - Type of Prismic documents to create. + * @typeParam TType - Type of the Prismic document to create. * * @param document - The document to create. - * @param documentTitle - The title of the document to create which will be - * displayed in the editor. - * @param params - Document master language document ID. + * @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. */ - createDocument( - document: ExtractDocumentType, - documentTitle: string, - params: Omit = {}, - ): MigrationDocument> { - const { record: data, dependencies } = prepareMigrationRecord( - document.data, + createDocument( + document: ExtractDocumentType, TType>, + title: string, + options?: { + masterLanguageDocument?: MigrationContentRelationship + }, + ): PrismicMigrationDocument> { + const { record: data, dependencies } = prepareMigrationDocumentData( + document.data!, this.createAsset.bind(this), ) - const migrationDocument = new MigrationDocument( - { ...document, data }, - { - documentTitle, - ...params, - }, - dependencies, - ) + const migrationDocument = new PrismicMigrationDocument< + ExtractDocumentType + >({ ...document, data }, title, { ...options, dependencies }) this._documents.push(migrationDocument) - // Index document - if (!(document.type in this.#indexedDocuments)) { - this.#indexedDocuments[document.type] = {} - } - this.#indexedDocuments[document.type][document.uid || SINGLE_INDEX] = - migrationDocument - return migrationDocument } @@ -304,18 +276,63 @@ export class Migration< * * @returns A migration document instance. */ - updateDocument( - document: Omit, "id"> & { - id: string - }, - documentTitle: string, - ): MigrationDocument> { - const migrationDocument = this.createDocument( - document as ExtractDocumentType, - documentTitle, + updateDocument( + document: ExtractDocumentType, TType>, + title: string, + ): PrismicMigrationDocument> { + const { record: data, dependencies } = prepareMigrationDocumentData( + document.data, + this.createAsset.bind(this), ) - migrationDocument._mode = "update" + const migrationDocument = new PrismicMigrationDocument< + ExtractDocumentType + >({ ...document, data }, title, { dependencies }) + + this._documents.push(migrationDocument) + + return migrationDocument + } + + /** + * 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. + * + * @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. + * + * @returns A migration document instance. + */ + createDocumentFromPrismic( + document: ExtractDocumentType, TType>, + title: string, + ): PrismicMigrationDocument> { + const { record: data, dependencies } = prepareMigrationDocumentData( + document.data, + this.createAsset.bind(this), + ) + + const migrationDocument = new PrismicMigrationDocument( + { + type: document.type, + lang: document.lang, + uid: document.uid, + tags: document.tags, + data: data, + } as unknown as PendingPrismicDocument< + ExtractDocumentType + >, + title, + { originalPrismicDocument: document, dependencies }, + ) + + this._documents.push(migrationDocument) return migrationDocument } @@ -352,19 +369,25 @@ export class Migration< * * @typeParam TType - Type of the Prismic document returned. * - * @param documentType - The API ID of the document's custom type. + * @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( - documentType: TType, + getByUID( + type: TType, uid: string, - ): MigrationDocument> | undefined { - return this.#indexedDocuments[documentType]?.[uid] as - | MigrationDocument - | undefined + ): + | PrismicMigrationDocument> + | undefined { + return this._documents.find( + ( + doc, + ): doc is PrismicMigrationDocument< + ExtractDocumentType + > => doc.document.type === type && doc.document.uid === uid, + ) } /** @@ -381,16 +404,54 @@ export class Migration< * * @typeParam TType - Type of the Prismic document returned. * - * @param documentType - The API ID of the singleton custom type. + * @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( - documentType: TType, - ): MigrationDocument> | undefined { - return this.#indexedDocuments[documentType]?.[SINGLE_INDEX] as - | MigrationDocument - | undefined + getSingle( + type: TType, + ): + | PrismicMigrationDocument> + | undefined { + return this._documents.find( + ( + doc, + ): doc is PrismicMigrationDocument< + ExtractDocumentType + > => doc.document.type === type, + ) } + + /** + * 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. + */ + // getByOriginalID( + // id: string, + // ): + // | PrismicMigrationDocument> + // | undefined { + // return this._documents.find( + // ( + // doc, + // ): doc is PrismicMigrationDocument< + // ExtractDocumentType + // > => doc.originalPrismicDocument?.id === id, + // ) + // } } diff --git a/src/WriteClient.ts b/src/WriteClient.ts index 451b25f5..c46c6fd0 100644 --- a/src/WriteClient.ts +++ b/src/WriteClient.ts @@ -26,7 +26,8 @@ import type { AssetMap, MigrationAssetConfig } from "./types/migration/Asset" import type { DocumentMap, MigrationDocument, - MigrationDocumentValue, + PendingPrismicDocument, + PrismicMigrationDocument, } from "./types/migration/Document" import type { PrismicDocument } from "./types/value/document" @@ -115,13 +116,13 @@ type MigrateReporterEventMap = { current: number remaining: number total: number - document: MigrationDocument + document: PrismicMigrationDocument } "documents:creating": { current: number remaining: number total: number - document: MigrationDocument + document: PrismicMigrationDocument } "documents:created": { created: number @@ -131,7 +132,7 @@ type MigrateReporterEventMap = { current: number remaining: number total: number - document: MigrationDocument + document: PrismicMigrationDocument } "documents:updated": { updated: number @@ -517,12 +518,12 @@ export class WriteClient< documents.set(document.id, document) } - const sortedMigrationDocuments: MigrationDocument[] = [] + const sortedMigrationDocuments: PrismicMigrationDocument[] = [] // We create an array with non-master locale documents last because // we need their master locale document to be created first. for (const migrationDocument of migration._documents) { - if (migrationDocument.value.lang === masterLocale) { + if (migrationDocument.document.lang === masterLocale) { sortedMigrationDocuments.unshift(migrationDocument) } else { sortedMigrationDocuments.push(migrationDocument) @@ -531,24 +532,24 @@ export class WriteClient< let i = 0 let created = 0 - for (const document of sortedMigrationDocuments) { - if ( - document.value.id && - (document._mode === "update" || documents.has(document.value.id)) - ) { + for (const migrationDocument of sortedMigrationDocuments) { + if (migrationDocument.document.id) { reporter?.({ type: "documents:skipping", data: { - reason: "already exists", + reason: "exists", current: ++i, remaining: sortedMigrationDocuments.length - i, total: sortedMigrationDocuments.length, - document: document, + document: migrationDocument, }, }) // Index the migration document - documents.set(document, documents.get(document.value.id)!) + documents.set( + migrationDocument, + documents.get(migrationDocument.document.id)!, + ) } else { created++ reporter?.({ @@ -557,29 +558,28 @@ export class WriteClient< current: ++i, remaining: sortedMigrationDocuments.length - i, total: sortedMigrationDocuments.length, - document: document, + document: migrationDocument, }, }) // Resolve master language document ID for non-master locale documents let masterLanguageDocumentID: string | undefined - if (document.value.lang !== masterLocale) { - if (document.params.masterLanguageDocument) { - const link = document.params.masterLanguageDocument - - await link._resolve({ documents, assets: new Map() }) - masterLanguageDocumentID = link._field?.id - } else if (document.value.alternate_languages) { - masterLanguageDocumentID = document.value.alternate_languages.find( + if (migrationDocument.masterLanguageDocument) { + const link = migrationDocument.masterLanguageDocument + + await link._resolve({ documents, assets: new Map() }) + masterLanguageDocumentID = link._field?.id + } else if (migrationDocument.originalPrismicDocument) { + masterLanguageDocumentID = + migrationDocument.originalPrismicDocument.alternate_languages.find( ({ lang }) => lang === masterLocale, )?.id - } } const { id } = await this.createDocument( // We'll upload docuements data later on. - { ...document.value, data: {} }, - document.params.documentTitle, + { ...migrationDocument.document, data: {} }, + migrationDocument.title, { masterLanguageDocumentID, ...fetchParams, @@ -587,13 +587,13 @@ export class WriteClient< ) // Index old ID for Prismic to Prismic migration - if (document.value.id) { - documents.set(document.value.id, { - ...document.value, + if (migrationDocument.originalPrismicDocument) { + documents.set(migrationDocument.originalPrismicDocument.id, { + ...migrationDocument.document, id, }) } - documents.set(document, { ...document.value, id }) + documents.set(migrationDocument, { ...migrationDocument.document, id }) } } @@ -629,30 +629,25 @@ export class WriteClient< }: { reporter?: (event: MigrateReporterEvents) => void } & FetchParams = {}, ): Promise { let i = 0 - for (const document of migration._documents) { + for (const migrationDocument of migration._documents) { reporter?.({ type: "documents:updating", data: { current: ++i, remaining: migration._documents.length - i, total: migration._documents.length, - document: document, + document: migrationDocument, }, }) - const { id, uid } = documents.get(document)! - await document._resolve({ assets, documents }) + const { id } = documents.get(migrationDocument)! + await migrationDocument._resolve({ assets, documents }) await this.updateDocument( id, // We need to forward again document name and tags to update them // in case the document already existed during the previous step. - { - documentTitle: document.params.documentTitle, - uid, - tags: document.value.tags, - data: document.value.data, - }, + migrationDocument.document, fetchParams, ) } @@ -1032,7 +1027,7 @@ export class WriteClient< * @see Prismic Migration API technical reference: {@link https://prismic.io/docs/migration-api-technical-reference} */ private async createDocument( - document: MigrationDocumentValue>, + document: PendingPrismicDocument>, documentTitle: string, { masterLanguageDocumentID, @@ -1074,10 +1069,7 @@ export class WriteClient< */ private async updateDocument( id: string, - document: Pick< - MigrationDocumentValue>, - "uid" | "tags" | "data" - > & { + document: MigrationDocument> & { documentTitle?: string }, params?: FetchParams, diff --git a/src/index.ts b/src/index.ts index 68187114..6750f34a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -327,9 +327,10 @@ export type { // Migrations - Types representing Prismic Migration API content values. export type { - MigrationDocument, - MigrationDocumentValue, - RichTextFieldWithMigrationField, + PrismicMigrationDocument, + PendingPrismicDocument, + ExistingPrismicDocument, + InjectMigrationSpecificTypes, } from "./types/migration/Document" export type { diff --git a/src/lib/isValue.ts b/src/lib/isValue.ts index 805ac593..90b72cbc 100644 --- a/src/lib/isValue.ts +++ b/src/lib/isValue.ts @@ -1,13 +1,24 @@ -import type { - FieldWithMigrationField, - RichTextBlockNodeWithMigrationField, -} from "../types/migration/Document" +import type { InjectMigrationSpecificTypes } from "../types/migration/Document" import type { FilledContentRelationshipField } from "../types/value/contentRelationship" import type { PrismicDocument } from "../types/value/document" +import type { GroupField } from "../types/value/group" import type { ImageField } from "../types/value/image" import { LinkType } from "../types/value/link" import type { FilledLinkToMediaField } from "../types/value/linkToMedia" import { type RTImageNode, RichTextNodeType } from "../types/value/richText" +import type { SliceZone } from "../types/value/sliceZone" +import type { AnyRegularField } from "../types/value/types" + +/** + * Unknown value to check if it's a specific field type. + * + * @remarks + * Explicit types are added to help ensure narrowing is done effectively. + */ +type UnknownValue = + | PrismicDocument + | InjectMigrationSpecificTypes + | unknown /** * Checks if a value is a link to media field. @@ -20,11 +31,7 @@ import { type RTImageNode, RichTextNodeType } from "../types/value/richText" * This is not an official helper function and it's only designed to work with internal processes. */ export const linkToMedia = ( - value: - | PrismicDocument - | FieldWithMigrationField - | RichTextBlockNodeWithMigrationField - | unknown, + value: UnknownValue, ): value is FilledLinkToMediaField => { if (value && typeof value === "object" && !("version" in value)) { if ( @@ -36,6 +43,8 @@ export const linkToMedia = ( "url" in value && "size" in value ) { + value + return true } } @@ -54,11 +63,7 @@ export const linkToMedia = ( * This is not an official helper function and it's only designed to work with internal processes. */ const imageLike = ( - value: - | PrismicDocument - | FieldWithMigrationField - | RichTextBlockNodeWithMigrationField - | unknown, + value: UnknownValue, ): value is ImageField | RTImageNode => { if ( value && @@ -92,11 +97,7 @@ const imageLike = ( * This is not an official helper function and it's only designed to work with internal processes. */ export const image = ( - value: - | PrismicDocument - | FieldWithMigrationField - | RichTextBlockNodeWithMigrationField - | unknown, + value: UnknownValue, ): value is ImageField => { if ( imageLike(value) && @@ -120,13 +121,7 @@ export const image = ( * @internal * This is not an official helper function and it's only designed to work with internal processes. */ -export const rtImageNode = ( - value: - | PrismicDocument - | FieldWithMigrationField - | RichTextBlockNodeWithMigrationField - | unknown, -): value is RTImageNode => { +export const rtImageNode = (value: UnknownValue): value is RTImageNode => { if ( imageLike(value) && "type" in value && @@ -151,11 +146,7 @@ export const rtImageNode = ( * This is not an official helper function and it's only designed to work with internal processes. */ export const contentRelationship = ( - value: - | PrismicDocument - | FieldWithMigrationField - | RichTextBlockNodeWithMigrationField - | unknown, + value: UnknownValue, ): value is FilledContentRelationshipField => { if (value && typeof value === "object" && !("version" in value)) { if ( diff --git a/src/lib/prepareMigrationRecord.ts b/src/lib/prepareMigrationDocumentData.ts similarity index 91% rename from src/lib/prepareMigrationRecord.ts rename to src/lib/prepareMigrationDocumentData.ts index 64055503..4bfd01de 100644 --- a/src/lib/prepareMigrationRecord.ts +++ b/src/lib/prepareMigrationDocumentData.ts @@ -22,7 +22,10 @@ import * as is from "./isValue" * @returns An object containing the record with replaced assets and links and a * list of dependencies found and/or created. */ -export const prepareMigrationRecord = >( +export const prepareMigrationDocumentData = < + // eslint-disable-next-line @typescript-eslint/no-explicit-any + TRecord extends Record, +>( record: TRecord, onAsset: ( asset: FilledImageFieldImage | FilledLinkToMediaField, @@ -52,7 +55,7 @@ export const prepareMigrationRecord = >( if (field.linkTo) { // Node `linkTo` dependency is tracked internally - rtImageNode.linkTo = prepareMigrationRecord( + rtImageNode.linkTo = prepareMigrationDocumentData( { linkTo: field.linkTo }, onAsset, ).record.linkTo as @@ -103,7 +106,7 @@ export const prepareMigrationRecord = >( for (const item of field) { const { record, dependencies: itemDependencies } = - prepareMigrationRecord({ item }, onAsset) + prepareMigrationDocumentData({ item }, onAsset) array.push(record.item) dependencies.push(...itemDependencies) @@ -113,7 +116,7 @@ export const prepareMigrationRecord = >( } else if (field && typeof field === "object") { // Traverse objects const { record, dependencies: fieldDependencies } = - prepareMigrationRecord({ ...field }, onAsset) + prepareMigrationDocumentData({ ...field }, onAsset) dependencies.push(...fieldDependencies) result[key] = record diff --git a/src/types/migration/ContentRelationship.ts b/src/types/migration/ContentRelationship.ts index cc56c1ae..33abf26a 100644 --- a/src/types/migration/ContentRelationship.ts +++ b/src/types/migration/ContentRelationship.ts @@ -2,7 +2,7 @@ import type { FilledContentRelationshipField } from "../value/contentRelationshi import type { PrismicDocument } from "../value/document" import { LinkType } from "../value/link" -import type { MigrationDocument } from "./Document" +import type { PrismicMigrationDocument } from "./Document" import type { ResolveArgs } from "./Field" import { MigrationField } from "./Field" @@ -13,7 +13,7 @@ type MigrationContentRelationshipConfig< TDocuments extends PrismicDocument = PrismicDocument, > = | TDocuments - | MigrationDocument + | PrismicMigrationDocument | FilledContentRelationshipField | undefined diff --git a/src/types/migration/Document.ts b/src/types/migration/Document.ts index c109bcbe..54df4497 100644 --- a/src/types/migration/Document.ts +++ b/src/types/migration/Document.ts @@ -1,21 +1,8 @@ -import type { AnyRegularField } from "../value/types" - import type { FilledContentRelationshipField } from "../value/contentRelationship" -import type { PrismicDocument } from "../value/document" -import type { GroupField } from "../value/group" +import type { PrismicDocument, PrismicDocumentWithUID } from "../value/document" import type { FilledImageFieldImage } from "../value/image" import type { FilledLinkToMediaField } from "../value/linkToMedia" -import type { - RTBlockNode, - RTImageNode, - RTInlineNode, - RTLinkNode, - RTTextNode, - RichTextField, -} from "../value/richText" -import type { SharedSlice } from "../value/sharedSlice" -import type { Slice } from "../value/slice" -import type { SliceZone } from "../value/sliceZone" +import type { RTImageNode } from "../value/richText" import type { MigrationImage, @@ -26,261 +13,122 @@ import type { MigrationContentRelationship } from "./ContentRelationship" import type { MigrationField, ResolveArgs } from "./Field" /** - * A utility type that extends Rich text field node's spans with their migration - * node equivalent. - * - * @typeParam TRTNode - Rich text text node type to convert. - */ -type RichTextTextNodeWithMigrationField< - TRTNode extends RTTextNode = RTTextNode, -> = Omit & { - spans: ( - | RTInlineNode - | (Omit & { - data: MigrationLinkToMedia | MigrationContentRelationship - }) - )[] -} - -/** - * A utility type that extends a Rich text field node with their migration node - * equivalent. - * - * @typeParam TRTNode - Rich text block node type to convert. - */ -export type RichTextBlockNodeWithMigrationField< - TRTNode extends RTBlockNode = RTBlockNode, -> = TRTNode extends RTImageNode - ? RTImageNode | MigrationRTImageNode - : TRTNode extends RTTextNode - ? RichTextTextNodeWithMigrationField - : TRTNode - -/** - * A utility type that extends a Rich text field's nodes with their migration - * node equivalent. - * - * @typeParam TField - Rich text field type to convert. - */ -export type RichTextFieldWithMigrationField< - TField extends RichTextField = RichTextField, -> = { - [Index in keyof TField]: RichTextBlockNodeWithMigrationField -} - -/** - * A utility type that extends a regular field with their migration field - * equivalent. - * - * @typeParam TField - Regular field type to convert. - */ -type RegularFieldWithMigrationField< - TField extends AnyRegularField = AnyRegularField, -> = - | (TField extends FilledImageFieldImage - ? MigrationImage | undefined - : TField extends FilledLinkToMediaField - ? MigrationLinkToMedia | undefined - : TField extends FilledContentRelationshipField - ? MigrationContentRelationship | undefined - : TField extends RichTextField - ? RichTextFieldWithMigrationField - : never) - | TField - -/** - * A utility type that extends a group's fields with their migration fields - * equivalent. - * - * @typeParam TField - Group field type to convert. - */ -type GroupFieldWithMigrationField< - TField extends GroupField | Slice["items"] | SharedSlice["items"] = - | GroupField - | Slice["items"] - | SharedSlice["items"], -> = FieldsWithMigrationFields[] - -type SliceWithMigrationField< - TField extends Slice | SharedSlice = Slice | SharedSlice, -> = Omit & { - primary: FieldsWithMigrationFields - items: GroupFieldWithMigrationField -} - -/** - * A utility type that extends a SliceZone's slices fields with their migration + * A utility type that extends any fields in a record with their migration * fields equivalent. * - * @typeParam TField - Field type to convert. + * @typeParam T - Type of the record to extend. */ -type SliceZoneWithMigrationField = - SliceWithMigrationField[] +export type InjectMigrationSpecificTypes = T extends RTImageNode + ? T | MigrationRTImageNode | undefined + : T extends FilledImageFieldImage + ? T | MigrationImage | undefined + : T extends FilledLinkToMediaField + ? T | MigrationLinkToMedia | undefined + : T extends FilledContentRelationshipField + ? T | MigrationContentRelationship | undefined + : // eslint-disable-next-line @typescript-eslint/no-explicit-any + T extends Record + ? { [P in keyof T]: InjectMigrationSpecificTypes } + : T extends Array + ? Array> + : T /** - * A utility type that extends any field with their migration field equivalent. - * - * @typeParam TField - Field type to convert. + * A utility type that ties the type and data of a Prismic document, creating a + * strict union. */ -export type FieldWithMigrationField< - TField extends AnyRegularField | GroupField | SliceZone = - | AnyRegularField - | GroupField - | SliceZone, -> = TField extends AnyRegularField - ? RegularFieldWithMigrationField - : TField extends GroupField - ? GroupFieldWithMigrationField - : TField extends SliceZone - ? SliceZoneWithMigrationField - : never +type TiedDocumentTypeAndData = + TDocument extends PrismicDocument + ? { + /** + * Type of the document. + */ + type: TType + + /** + * Data contained in the document. + */ + data: InjectMigrationSpecificTypes + } & (TDocument extends PrismicDocumentWithUID + ? Pick + : Partial>) + : never /** - * A utility type that extends a record of fields with their migration fields - * equivalent. + * A pending Prismic document to be created with the Migration API. * - * @typeParam TFields - Type of the record of Prismic fields. + * @typeParam TDocument - Type of the Prismic document. */ -export type FieldsWithMigrationFields< - TFields extends Record< - string, - AnyRegularField | GroupField | SliceZone - > = Record, -> = { - [Key in keyof TFields]: FieldWithMigrationField -} +export type PendingPrismicDocument< + TDocument extends PrismicDocument = PrismicDocument, +> = Pick & + Partial> & + TiedDocumentTypeAndData /** - * Makes the UID of {@link MigrationDocumentValue} optional on custom types - * without UID. TypeScript fails to infer correct types if done with a type - * intersection. + * An existing Prismic document to be updated with the Migration API. * - * @internal + * @typeParam TDocument - Type of the Prismic document. */ -type MakeUIDOptional = - TMigrationDocument["uid"] extends string - ? TMigrationDocument - : Omit & Partial> +export type ExistingPrismicDocument< + TDocument extends PrismicDocument = PrismicDocument, +> = Omit & + TiedDocumentTypeAndData /** - * A Prismic document value compatible with the Migration API. + * A Prismic document to be sent to the Migration API. * - * @see More details on the Migration API: {@link https://prismic.io/docs/migration-api-technical-reference} + * @typeParam TDocument - Type of the Prismic document. */ -export type MigrationDocumentValue< +export type MigrationDocument< TDocument extends PrismicDocument = PrismicDocument, -> = - TDocument extends PrismicDocument - ? MakeUIDOptional<{ - /** - * Type of the document. - */ - type: TType - - /** - * The unique identifier for the document. Guaranteed to be unique among - * all Prismic documents of the same type. - */ - uid: TDocument["uid"] - - /** - * Language of document. - */ - lang: TLang - - /** - * The identifier for the document. Used for compatibily with the - * content API. - * - * @internal - */ - // Made optional compared to the original type. - id?: TDocument["id"] - - /** - * Alternate language documents from Prismic content API. Used as a - * substitute to the `masterLanguageDocument` options when the latter is - * not available. - * - * @internal - */ - // Made optional compared to the original type. - alternate_languages?: TDocument["alternate_languages"] - - /** - * Tags associated with document. - */ - // Made optional compared to the original type. - tags?: TDocument["tags"] - - /** - * Data contained in the document. - */ - data: FieldsWithMigrationFields - }> - : never +> = PendingPrismicDocument | ExistingPrismicDocument /** - * Parameters used when creating a Prismic document with the Migration API. + * A Prismic migration document instance. * - * @see More details on the Migration API: {@link https://prismic.io/docs/migration-api-technical-reference} + * @typeParam TDocument - Type of the Prismic document. */ -export type MigrationDocumentParams = { +export class PrismicMigrationDocument< + TDocument extends PrismicDocument = PrismicDocument, +> { /** - * Name of the document displayed in the editor. + * The document to be sent to the Migration API. */ - documentTitle: string + document: MigrationDocument & Partial> /** - * A link to the master language document. + * The name of the document displayed in the editor. */ + title: string + // We're forced to inline `ContentRelationshipMigrationField` here, otherwise // it creates a circular reference to itself which makes TypeScript unhappy. // (but I think it's weird and it doesn't make sense :thinking:) masterLanguageDocument?: MigrationContentRelationship -} -/** - * A Prismic migration document instance. - * - * @see More details on the Migration API: {@link https://prismic.io/docs/migration-api-technical-reference} - */ -export class MigrationDocument< - TDocument extends PrismicDocument = PrismicDocument, -> { /** - * The document value to be sent to the Migration API. - */ - value: MigrationDocumentValue - - /** - * Parameters to create/update the document with on the Migration API. + * Original Prismic document when the migration document came from another + * Prismic repository. + * + * @remarks + * When migrating a document from another repository, one might want to alter + * it with migration specific types, hence accepting an + * `ExistingPrismicDocument` instead of a regular `PrismicDocument`. */ - params: MigrationDocumentParams + originalPrismicDocument?: ExistingPrismicDocument /** * Asset and content relationship fields that this document depends on. */ #dependencies: MigrationField[] - /** - * The mode to use when creating or updating the document. - * - * - `auto`: Automatically determines if the document should be created or - * updated on the document's existence on the repository's Document API. - * - `update`: Forces the document to only be updated. This is useful when the - * document only exists within the migration release which cannot be - * queried. - * - * @internal - */ - _mode: "auto" | "update" = "auto" - /** * Creates a Prismic migration document instance. * - * @param value - The document value to be sent to the Migration API. - * @param params - Parameters to create/update the document with on the + * @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 * Migration API. * @param dependencies - Asset and content relationship fields that this * document depends on. @@ -288,13 +136,19 @@ export class MigrationDocument< * @returns A Prismic migration document instance. */ constructor( - value: MigrationDocumentValue, - params: MigrationDocumentParams, - dependencies: MigrationField[] = [], + document: MigrationDocument, + title: string, + options: { + masterLanguageDocument?: MigrationContentRelationship + originalPrismicDocument?: ExistingPrismicDocument + dependencies: MigrationField[] + }, ) { - this.value = value - this.params = params - this.#dependencies = dependencies + this.document = document + this.title = title + this.masterLanguageDocument = options.masterLanguageDocument + this.originalPrismicDocument = options.originalPrismicDocument + this.#dependencies = options.dependencies } /** @@ -323,7 +177,6 @@ export class MigrationDocument< */ export type DocumentMap = Map< - string | MigrationDocument | MigrationDocument, - | PrismicDocument - | (Omit, "id"> & { id: string }) + string | PrismicMigrationDocument, + PrismicDocument | (MigrationDocument & Pick) > diff --git a/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap index 739bcda2..c15c15c2 100644 --- a/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap @@ -12,7 +12,7 @@ exports[`patches link fields > brokenLink > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ {}, ], @@ -22,9 +22,9 @@ exports[`patches link fields > brokenLink > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -34,13 +34,13 @@ exports[`patches link fields > brokenLink > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ {}, ], "primary": {}, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -69,7 +69,7 @@ exports[`patches link fields > existing > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { @@ -111,9 +111,9 @@ exports[`patches link fields > existing > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -123,7 +123,7 @@ exports[`patches link fields > existing > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { @@ -150,8 +150,8 @@ exports[`patches link fields > existing > slice 1`] = ` "type": "amet", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -191,7 +191,7 @@ exports[`patches link fields > lazyExisting > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { @@ -233,9 +233,9 @@ exports[`patches link fields > lazyExisting > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -245,7 +245,7 @@ exports[`patches link fields > lazyExisting > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { @@ -272,8 +272,8 @@ exports[`patches link fields > lazyExisting > slice 1`] = ` "type": "amet", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -297,7 +297,7 @@ exports[`patches link fields > lazyMigration > group 1`] = ` "group": [ { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "a", "link_type": "Document", @@ -316,11 +316,11 @@ exports[`patches link fields > lazyMigration > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "gravida", "link_type": "Document", @@ -332,7 +332,7 @@ exports[`patches link fields > lazyMigration > shared slice 1`] = ` ], "primary": { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "gravida", "link_type": "Document", @@ -343,7 +343,7 @@ exports[`patches link fields > lazyMigration > shared slice 1`] = ` "group": [ { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "gravida", "link_type": "Document", @@ -355,9 +355,9 @@ exports[`patches link fields > lazyMigration > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -367,11 +367,11 @@ exports[`patches link fields > lazyMigration > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "ultrices", "link_type": "Document", @@ -385,7 +385,7 @@ exports[`patches link fields > lazyMigration > slice 1`] = ` ], "primary": { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "ultrices", "link_type": "Document", @@ -396,8 +396,8 @@ exports[`patches link fields > lazyMigration > slice 1`] = ` "uid": "Amet dictum sit", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -406,7 +406,7 @@ exports[`patches link fields > lazyMigration > slice 1`] = ` exports[`patches link fields > lazyMigration > static zone 1`] = ` { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "nisi,", "link_type": "Document", @@ -422,7 +422,7 @@ exports[`patches link fields > migration > group 1`] = ` "group": [ { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "a", "link_type": "Document", @@ -441,11 +441,11 @@ exports[`patches link fields > migration > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "gravida", "link_type": "Document", @@ -457,7 +457,7 @@ exports[`patches link fields > migration > shared slice 1`] = ` ], "primary": { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "gravida", "link_type": "Document", @@ -468,7 +468,7 @@ exports[`patches link fields > migration > shared slice 1`] = ` "group": [ { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "gravida", "link_type": "Document", @@ -480,9 +480,9 @@ exports[`patches link fields > migration > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -492,11 +492,11 @@ exports[`patches link fields > migration > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "ultrices", "link_type": "Document", @@ -510,7 +510,7 @@ exports[`patches link fields > migration > slice 1`] = ` ], "primary": { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "ultrices", "link_type": "Document", @@ -521,8 +521,8 @@ exports[`patches link fields > migration > slice 1`] = ` "uid": "Amet dictum sit", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -531,7 +531,7 @@ exports[`patches link fields > migration > slice 1`] = ` exports[`patches link fields > migration > static zone 1`] = ` { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "nisi,", "link_type": "Document", @@ -547,7 +547,7 @@ exports[`patches link fields > migrationNoTags > group 1`] = ` "group": [ { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "a", "link_type": "Document", @@ -564,11 +564,11 @@ exports[`patches link fields > migrationNoTags > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "gravida", "link_type": "Document", @@ -580,7 +580,7 @@ exports[`patches link fields > migrationNoTags > shared slice 1`] = ` ], "primary": { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "gravida", "link_type": "Document", @@ -591,7 +591,7 @@ exports[`patches link fields > migrationNoTags > shared slice 1`] = ` "group": [ { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "gravida", "link_type": "Document", @@ -603,9 +603,9 @@ exports[`patches link fields > migrationNoTags > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -615,11 +615,11 @@ exports[`patches link fields > migrationNoTags > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "ultrices", "link_type": "Document", @@ -631,7 +631,7 @@ exports[`patches link fields > migrationNoTags > slice 1`] = ` ], "primary": { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "ultrices", "link_type": "Document", @@ -640,8 +640,8 @@ exports[`patches link fields > migrationNoTags > slice 1`] = ` "uid": "Amet dictum sit", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -650,7 +650,7 @@ exports[`patches link fields > migrationNoTags > slice 1`] = ` exports[`patches link fields > migrationNoTags > static zone 1`] = ` { "field": { - "id": "id-migration", + "id": "id-other", "isBroken": false, "lang": "nisi,", "link_type": "Document", @@ -666,15 +666,13 @@ exports[`patches link fields > otherRepositoryContentRelationship > group 1`] = "group": [ { "field": { - "id": "id-migration", + "id": "id-other-repository", "isBroken": false, - "lang": "a", + "lang": "faucibus", "link_type": "Document", - "tags": [ - "Odio Eu", - ], - "type": "amet", - "uid": "Non sodales neque", + "tags": [], + "type": "lorem", + "uid": "Pharetra et ultrices", }, }, ], @@ -685,48 +683,54 @@ exports[`patches link fields > otherRepositoryContentRelationship > shared slice { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { - "id": "id-migration", + "id": "id-other-repository", "isBroken": false, - "lang": "gravida", + "lang": "eu", "link_type": "Document", - "tags": [], - "type": "leo", - "uid": "Blandit volutpat maecenas", + "tags": [ + "Pharetra", + ], + "type": "pellentesque", + "uid": "Volutpat ac tincidunt", }, }, ], "primary": { "field": { - "id": "id-migration", + "id": "id-other-repository", "isBroken": false, - "lang": "gravida", + "lang": "eu", "link_type": "Document", - "tags": [], - "type": "leo", - "uid": "Blandit volutpat maecenas", + "tags": [ + "Pharetra", + ], + "type": "pellentesque", + "uid": "Volutpat ac tincidunt", }, "group": [ { "field": { - "id": "id-migration", + "id": "id-other-repository", "isBroken": false, - "lang": "gravida", + "lang": "eu", "link_type": "Document", - "tags": [], - "type": "leo", - "uid": "Blandit volutpat maecenas", + "tags": [ + "Pharetra", + ], + "type": "pellentesque", + "uid": "Volutpat ac tincidunt", }, }, ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -736,37 +740,37 @@ exports[`patches link fields > otherRepositoryContentRelationship > slice 1`] = { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { - "id": "id-migration", + "id": "id-other-repository", "isBroken": false, - "lang": "ultrices", + "lang": "dignissim", "link_type": "Document", "tags": [ - "Ipsum Consequat", + "Arcu Vitae", ], - "type": "eget", - "uid": "Amet dictum sit", + "type": "a", + "uid": "Tristique senectus et", }, }, ], "primary": { "field": { - "id": "id-migration", + "id": "id-other-repository", "isBroken": false, - "lang": "ultrices", + "lang": "dignissim", "link_type": "Document", "tags": [ - "Ipsum Consequat", + "Arcu Vitae", ], - "type": "eget", - "uid": "Amet dictum sit", + "type": "a", + "uid": "Tristique senectus et", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -775,13 +779,13 @@ exports[`patches link fields > otherRepositoryContentRelationship > slice 1`] = exports[`patches link fields > otherRepositoryContentRelationship > static zone 1`] = ` { "field": { - "id": "id-migration", + "id": "id-other-repository", "isBroken": false, - "lang": "nisi,", + "lang": "quam", "link_type": "Document", "tags": [], - "type": "eros", - "uid": "Scelerisque mauris pellentesque", + "type": "semper", + "uid": "Sed viverra ipsum", }, } `; @@ -825,7 +829,7 @@ exports[`patches link fields > richTextLinkNode > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": [ @@ -921,9 +925,9 @@ exports[`patches link fields > richTextLinkNode > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -933,7 +937,7 @@ exports[`patches link fields > richTextLinkNode > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": [ @@ -996,8 +1000,8 @@ exports[`patches link fields > richTextLinkNode > slice 1`] = ` }, ], }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } diff --git a/test/__snapshots__/writeClient-migrate-patch-image.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-image.test.ts.snap index 1a477d27..98f4ebb3 100644 --- a/test/__snapshots__/writeClient-migrate-patch-image.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-image.test.ts.snap @@ -18,7 +18,7 @@ exports[`patches image fields > existing > group 1`] = ` "zoom": 1, }, "id": "id-existing", - "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", }, }, ], @@ -29,7 +29,7 @@ exports[`patches image fields > existing > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { @@ -46,7 +46,7 @@ exports[`patches image fields > existing > shared slice 1`] = ` "zoom": 1, }, "id": "id-existing", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, }, ], @@ -65,7 +65,7 @@ exports[`patches image fields > existing > shared slice 1`] = ` "zoom": 1, }, "id": "id-existing", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, "group": [ { @@ -83,15 +83,15 @@ exports[`patches image fields > existing > shared slice 1`] = ` "zoom": 1, }, "id": "id-existing", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, }, ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -101,7 +101,7 @@ exports[`patches image fields > existing > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { @@ -140,8 +140,8 @@ exports[`patches image fields > existing > slice 1`] = ` "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -163,7 +163,7 @@ exports[`patches image fields > existing > static zone 1`] = ` "zoom": 1, }, "id": "id-existing", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", }, } `; @@ -185,8 +185,8 @@ exports[`patches image fields > new > group 1`] = ` "y": 0, "zoom": 1, }, - "id": "ef95d5daa4d", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?w=2560&h=1705&fit=crop", + "id": "dfdd322ca9d", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", }, }, ], @@ -197,7 +197,7 @@ exports[`patches image fields > new > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { @@ -213,8 +213,8 @@ exports[`patches image fields > new > shared slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "f2c3f8bfc90", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "id": "0eddbd0255b", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", }, }, ], @@ -232,8 +232,8 @@ exports[`patches image fields > new > shared slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "f2c3f8bfc90", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "id": "0eddbd0255b", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", }, "group": [ { @@ -250,16 +250,16 @@ exports[`patches image fields > new > shared slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "f2c3f8bfc90", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "id": "0eddbd0255b", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", }, }, ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -269,7 +269,7 @@ exports[`patches image fields > new > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { @@ -285,8 +285,8 @@ exports[`patches image fields > new > slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "45306297c5e", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "id": "2beb55ec2f4", + "url": "https://images.unsplash.com/photo-1444464666168-49d633b86797?w=4844&h=3234&fit=crop", }, }, ], @@ -304,12 +304,12 @@ exports[`patches image fields > new > slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "45306297c5e", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "id": "2beb55ec2f4", + "url": "https://images.unsplash.com/photo-1444464666168-49d633b86797?w=4844&h=3234&fit=crop", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -330,8 +330,8 @@ exports[`patches image fields > new > static zone 1`] = ` "y": 0, "zoom": 1, }, - "id": "c5c95f8d3ac", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "id": "bbad670dad7", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", }, } `; @@ -341,20 +341,20 @@ exports[`patches image fields > otherRepository > group 1`] = ` "group": [ { "field": { - "alt": "Odio ut enim blandit volutpat maecenas volutpat blandit", + "alt": "Massa id neque aliquam vestibulum morbi blandit cursus risus", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#fdb338", - "x": 349, - "y": 115, - "zoom": 1.5951464943576479, + "background": "#cfc26f", + "x": -2885, + "y": -2419, + "zoom": 1.7509753524211642, }, - "id": "4dcf07cfc26", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b", + "id": "8d0985c0990", + "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f", }, }, ], @@ -365,69 +365,69 @@ exports[`patches image fields > otherRepository > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { - "alt": "Vitae et leo duis ut diam quam nulla porttitor massa id neque aliquam vestibulum", + "alt": "Fermentum odio eu feugiat pretium nibh ipsum consequat", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#61adcf", - "x": -1586, - "y": -2819, - "zoom": 1.9393723758262054, + "background": "#9ed252", + "x": -1720, + "y": -191, + "zoom": 1.6165685319845957, }, - "id": "f5dbf0d9ed2", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e", + "id": "35eaa8ebee4", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", }, }, ], "primary": { "field": { - "alt": "Ut consequat semper viverra nam libero justo laoreet", + "alt": "Pellentesque pulvinar pellentesque habitant morbi tristique senectus et netus et malesuada fames ac", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#8efd5a", - "x": 466, - "y": -571, - "zoom": 1.394663850868741, + "background": "#4f4f59", + "x": 3094, + "y": -2976, + "zoom": 1.0855120641844143, }, - "id": "f5dbf0d9ed2", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e", + "id": "35eaa8ebee4", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", }, "group": [ { "field": { - "alt": "Porttitor massa id neque aliquam vestibulum morbi blandit", + "alt": "Id aliquet risus feugiat in", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#bc3178", - "x": 1156, - "y": -2223, - "zoom": 1.602826201962965, + "background": "#42f5cf", + "x": 427, + "y": 731, + "zoom": 1.6417661415510265, }, - "id": "f5dbf0d9ed2", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e", + "id": "35eaa8ebee4", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", }, }, ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -437,47 +437,47 @@ exports[`patches image fields > otherRepository > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { - "alt": "Vitae sapien pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis", + "alt": "Pellentesque nec nam aliquam sem", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#c361cc", - "x": -751, - "y": -404, - "zoom": 1.6465649620272602, + "background": "#f72dec", + "x": 2027, + "y": 7, + "zoom": 1.9216652845315787, }, - "id": "4f4a69ff72d", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c", + "id": "7a35bc5aa2f", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05", }, }, ], "primary": { "field": { - "alt": "Nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc consequat interdum varius sit", + "alt": "Quam nulla porttitor massa id neque aliquam vestibulum morbi blandit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#55e3be", - "x": -762, - "y": 991, - "zoom": 1.0207384987782544, + "background": "#60cbac", + "x": -484, + "y": -2038, + "zoom": 1.8400009569805118, }, - "id": "4f4a69ff72d", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c", + "id": "7a35bc5aa2f", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -486,20 +486,20 @@ exports[`patches image fields > otherRepository > slice 1`] = ` exports[`patches image fields > otherRepository > static zone 1`] = ` { "field": { - "alt": "Vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae elementum curabitur vitae nunc sed", + "alt": "Gravida rutrum quisque non tellus orci", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#97acc6", - "x": 1922, - "y": -967, - "zoom": 1.9765406541937358, + "background": "#b1d17b", + "x": 3291, + "y": -730, + "zoom": 1.061566393836766, }, - "id": "9abffab1d17", - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f", + "id": "4a95cc61c37", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d", }, } `; @@ -524,7 +524,7 @@ exports[`patches image fields > otherRepositoryEmpty > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { @@ -557,9 +557,9 @@ exports[`patches image fields > otherRepositoryEmpty > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -569,7 +569,7 @@ exports[`patches image fields > otherRepositoryEmpty > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { @@ -590,8 +590,8 @@ exports[`patches image fields > otherRepositoryEmpty > slice 1`] = ` "url": null, }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -614,36 +614,36 @@ exports[`patches image fields > otherRepositoryWithThumbnails > group 1`] = ` "group": [ { "field": { - "alt": "Odio ut enim blandit volutpat maecenas volutpat blandit", + "alt": "Massa id neque aliquam vestibulum morbi blandit cursus risus", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#fdb338", - "x": 349, - "y": 115, - "zoom": 1.5951464943576479, + "background": "#cfc26f", + "x": -2885, + "y": -2419, + "zoom": 1.7509753524211642, }, - "id": "4dcf07cfc26", + "id": "8d0985c0990", "square": { - "alt": "Odio ut enim blandit volutpat maecenas volutpat blandit", + "alt": "Massa id neque aliquam vestibulum morbi blandit cursus risus", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#fdb338", - "x": 349, - "y": 115, - "zoom": 1.5951464943576479, + "background": "#cfc26f", + "x": -2885, + "y": -2419, + "zoom": 1.7509753524211642, }, - "id": "4dcf07cfc26", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?some=other&query=params", + "id": "8d0985c0990", + "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?some=query", + "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=query", }, }, ], @@ -654,117 +654,117 @@ exports[`patches image fields > otherRepositoryWithThumbnails > shared slice 1`] { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { - "alt": "Vitae et leo duis ut diam quam nulla porttitor massa id neque aliquam vestibulum", + "alt": "Fermentum odio eu feugiat pretium nibh ipsum consequat", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#61adcf", - "x": -1586, - "y": -2819, - "zoom": 1.9393723758262054, + "background": "#9ed252", + "x": -1720, + "y": -191, + "zoom": 1.6165685319845957, }, - "id": "f5dbf0d9ed2", + "id": "35eaa8ebee4", "square": { - "alt": "Vitae et leo duis ut diam quam nulla porttitor massa id neque aliquam vestibulum", + "alt": "Fermentum odio eu feugiat pretium nibh ipsum consequat", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#61adcf", - "x": -1586, - "y": -2819, - "zoom": 1.9393723758262054, + "background": "#9ed252", + "x": -1720, + "y": -191, + "zoom": 1.6165685319845957, }, - "id": "f5dbf0d9ed2", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=other&query=params", + "id": "35eaa8ebee4", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=query", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, }, ], "primary": { "field": { - "alt": "Ut consequat semper viverra nam libero justo laoreet", + "alt": "Pellentesque pulvinar pellentesque habitant morbi tristique senectus et netus et malesuada fames ac", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#8efd5a", - "x": 466, - "y": -571, - "zoom": 1.394663850868741, + "background": "#4f4f59", + "x": 3094, + "y": -2976, + "zoom": 1.0855120641844143, }, - "id": "f5dbf0d9ed2", + "id": "35eaa8ebee4", "square": { - "alt": "Ut consequat semper viverra nam libero justo laoreet", + "alt": "Pellentesque pulvinar pellentesque habitant morbi tristique senectus et netus et malesuada fames ac", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#8efd5a", - "x": 466, - "y": -571, - "zoom": 1.394663850868741, + "background": "#4f4f59", + "x": 3094, + "y": -2976, + "zoom": 1.0855120641844143, }, - "id": "f5dbf0d9ed2", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=other&query=params", + "id": "35eaa8ebee4", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=query", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, "group": [ { "field": { - "alt": "Porttitor massa id neque aliquam vestibulum morbi blandit", + "alt": "Id aliquet risus feugiat in", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#bc3178", - "x": 1156, - "y": -2223, - "zoom": 1.602826201962965, + "background": "#42f5cf", + "x": 427, + "y": 731, + "zoom": 1.6417661415510265, }, - "id": "f5dbf0d9ed2", + "id": "35eaa8ebee4", "square": { - "alt": "Porttitor massa id neque aliquam vestibulum morbi blandit", + "alt": "Id aliquet risus feugiat in", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#bc3178", - "x": 1156, - "y": -2223, - "zoom": 1.602826201962965, + "background": "#42f5cf", + "x": 427, + "y": 731, + "zoom": 1.6417661415510265, }, - "id": "f5dbf0d9ed2", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=other&query=params", + "id": "35eaa8ebee4", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=query", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, }, ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -774,79 +774,79 @@ exports[`patches image fields > otherRepositoryWithThumbnails > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { - "alt": "Vitae sapien pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis", + "alt": "Pellentesque nec nam aliquam sem", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#c361cc", - "x": -751, - "y": -404, - "zoom": 1.6465649620272602, + "background": "#f72dec", + "x": 2027, + "y": 7, + "zoom": 1.9216652845315787, }, - "id": "4f4a69ff72d", + "id": "7a35bc5aa2f", "square": { - "alt": "Vitae sapien pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis", + "alt": "Pellentesque nec nam aliquam sem", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#c361cc", - "x": -751, - "y": -404, - "zoom": 1.6465649620272602, + "background": "#f72dec", + "x": 2027, + "y": 7, + "zoom": 1.9216652845315787, }, - "id": "4f4a69ff72d", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=other&query=params", + "id": "7a35bc5aa2f", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=query", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=query", }, }, ], "primary": { "field": { - "alt": "Nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc consequat interdum varius sit", + "alt": "Quam nulla porttitor massa id neque aliquam vestibulum morbi blandit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#55e3be", - "x": -762, - "y": 991, - "zoom": 1.0207384987782544, + "background": "#60cbac", + "x": -484, + "y": -2038, + "zoom": 1.8400009569805118, }, - "id": "4f4a69ff72d", + "id": "7a35bc5aa2f", "square": { - "alt": "Nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc consequat interdum varius sit", + "alt": "Quam nulla porttitor massa id neque aliquam vestibulum morbi blandit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#55e3be", - "x": -762, - "y": 991, - "zoom": 1.0207384987782544, + "background": "#60cbac", + "x": -484, + "y": -2038, + "zoom": 1.8400009569805118, }, - "id": "4f4a69ff72d", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=other&query=params", + "id": "7a35bc5aa2f", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=query", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=query", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -855,36 +855,36 @@ exports[`patches image fields > otherRepositoryWithThumbnails > slice 1`] = ` exports[`patches image fields > otherRepositoryWithThumbnails > static zone 1`] = ` { "field": { - "alt": "Vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae elementum curabitur vitae nunc sed", + "alt": "Gravida rutrum quisque non tellus orci", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#97acc6", - "x": 1922, - "y": -967, - "zoom": 1.9765406541937358, + "background": "#b1d17b", + "x": 3291, + "y": -730, + "zoom": 1.061566393836766, }, - "id": "9abffab1d17", + "id": "4a95cc61c37", "square": { - "alt": "Vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae elementum curabitur vitae nunc sed", + "alt": "Gravida rutrum quisque non tellus orci", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#97acc6", - "x": 1922, - "y": -967, - "zoom": 1.9765406541937358, + "background": "#b1d17b", + "x": 3291, + "y": -730, + "zoom": 1.061566393836766, }, - "id": "9abffab1d17", - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=other&query=params", + "id": "4a95cc61c37", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=query", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?some=query", }, } `; @@ -901,12 +901,12 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > group 1`] = "width": 1, }, "edit": { - "background": "#fdb338", - "x": 349, - "y": 115, - "zoom": 1.5951464943576479, + "background": "#cfc26f", + "x": -2885, + "y": -2419, + "zoom": 1.7509753524211642, }, - "id": "4dcf07cfc26", + "id": "8d0985c0990", "square": { "alt": null, "copyright": null, @@ -915,15 +915,15 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > group 1`] = "width": 1, }, "edit": { - "background": "#fdb338", - "x": 349, - "y": 115, - "zoom": 1.5951464943576479, + "background": "#cfc26f", + "x": -2885, + "y": -2419, + "zoom": 1.7509753524211642, }, - "id": "4dcf07cfc26", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?some=other&query=params", + "id": "8d0985c0990", + "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?some=query", + "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=query", }, }, ], @@ -934,7 +934,7 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { @@ -945,12 +945,12 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "width": 1, }, "edit": { - "background": "#61adcf", - "x": -1586, - "y": -2819, - "zoom": 1.9393723758262054, + "background": "#9ed252", + "x": -1720, + "y": -191, + "zoom": 1.6165685319845957, }, - "id": "f5dbf0d9ed2", + "id": "35eaa8ebee4", "square": { "alt": null, "copyright": null, @@ -959,15 +959,15 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "width": 1, }, "edit": { - "background": "#61adcf", - "x": -1586, - "y": -2819, - "zoom": 1.9393723758262054, + "background": "#9ed252", + "x": -1720, + "y": -191, + "zoom": 1.6165685319845957, }, - "id": "f5dbf0d9ed2", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=other&query=params", + "id": "35eaa8ebee4", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=query", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, }, ], @@ -980,12 +980,12 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "width": 1, }, "edit": { - "background": "#8efd5a", - "x": 466, - "y": -571, - "zoom": 1.394663850868741, + "background": "#4f4f59", + "x": 3094, + "y": -2976, + "zoom": 1.0855120641844143, }, - "id": "f5dbf0d9ed2", + "id": "35eaa8ebee4", "square": { "alt": null, "copyright": null, @@ -994,15 +994,15 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "width": 1, }, "edit": { - "background": "#8efd5a", - "x": 466, - "y": -571, - "zoom": 1.394663850868741, + "background": "#4f4f59", + "x": 3094, + "y": -2976, + "zoom": 1.0855120641844143, }, - "id": "f5dbf0d9ed2", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=other&query=params", + "id": "35eaa8ebee4", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=query", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, "group": [ { @@ -1014,12 +1014,12 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "width": 1, }, "edit": { - "background": "#bc3178", - "x": 1156, - "y": -2223, - "zoom": 1.602826201962965, + "background": "#42f5cf", + "x": 427, + "y": 731, + "zoom": 1.6417661415510265, }, - "id": "f5dbf0d9ed2", + "id": "35eaa8ebee4", "square": { "alt": null, "copyright": null, @@ -1028,23 +1028,23 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "width": 1, }, "edit": { - "background": "#bc3178", - "x": 1156, - "y": -2223, - "zoom": 1.602826201962965, + "background": "#42f5cf", + "x": 427, + "y": 731, + "zoom": 1.6417661415510265, }, - "id": "f5dbf0d9ed2", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=other&query=params", + "id": "35eaa8ebee4", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=query", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, }, ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -1054,7 +1054,7 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > slice 1`] = { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { @@ -1065,12 +1065,12 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > slice 1`] = "width": 1, }, "edit": { - "background": "#c361cc", - "x": -751, - "y": -404, - "zoom": 1.6465649620272602, + "background": "#f72dec", + "x": 2027, + "y": 7, + "zoom": 1.9216652845315787, }, - "id": "4f4a69ff72d", + "id": "7a35bc5aa2f", "square": { "alt": null, "copyright": null, @@ -1079,15 +1079,15 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > slice 1`] = "width": 1, }, "edit": { - "background": "#c361cc", - "x": -751, - "y": -404, - "zoom": 1.6465649620272602, + "background": "#f72dec", + "x": 2027, + "y": 7, + "zoom": 1.9216652845315787, }, - "id": "4f4a69ff72d", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=other&query=params", + "id": "7a35bc5aa2f", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=query", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=query", }, }, ], @@ -1100,12 +1100,12 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > slice 1`] = "width": 1, }, "edit": { - "background": "#55e3be", - "x": -762, - "y": 991, - "zoom": 1.0207384987782544, + "background": "#60cbac", + "x": -484, + "y": -2038, + "zoom": 1.8400009569805118, }, - "id": "4f4a69ff72d", + "id": "7a35bc5aa2f", "square": { "alt": null, "copyright": null, @@ -1114,19 +1114,19 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > slice 1`] = "width": 1, }, "edit": { - "background": "#55e3be", - "x": -762, - "y": 991, - "zoom": 1.0207384987782544, + "background": "#60cbac", + "x": -484, + "y": -2038, + "zoom": 1.8400009569805118, }, - "id": "4f4a69ff72d", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=other&query=params", + "id": "7a35bc5aa2f", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=query", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=query", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -1142,12 +1142,12 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > static zone "width": 1, }, "edit": { - "background": "#97acc6", - "x": 1922, - "y": -967, - "zoom": 1.9765406541937358, + "background": "#b1d17b", + "x": 3291, + "y": -730, + "zoom": 1.061566393836766, }, - "id": "9abffab1d17", + "id": "4a95cc61c37", "square": { "alt": null, "copyright": null, @@ -1156,15 +1156,15 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > static zone "width": 1, }, "edit": { - "background": "#97acc6", - "x": 1922, - "y": -967, - "zoom": 1.9765406541937358, + "background": "#b1d17b", + "x": 3291, + "y": -730, + "zoom": 1.061566393836766, }, - "id": "9abffab1d17", - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=other&query=params", + "id": "4a95cc61c37", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=query", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?some=query", }, } `; @@ -1174,36 +1174,36 @@ exports[`patches image fields > otherRepositoryWithTypeThumbnail > group 1`] = ` "group": [ { "field": { - "alt": "Odio ut enim blandit volutpat maecenas volutpat blandit", + "alt": "Massa id neque aliquam vestibulum morbi blandit cursus risus", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#fdb338", - "x": 349, - "y": 115, - "zoom": 1.5951464943576479, + "background": "#cfc26f", + "x": -2885, + "y": -2419, + "zoom": 1.7509753524211642, }, - "id": "4dcf07cfc26", + "id": "8d0985c0990", "type": { - "alt": "Odio ut enim blandit volutpat maecenas volutpat blandit", + "alt": "Massa id neque aliquam vestibulum morbi blandit cursus risus", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#fdb338", - "x": 349, - "y": 115, - "zoom": 1.5951464943576479, + "background": "#cfc26f", + "x": -2885, + "y": -2419, + "zoom": 1.7509753524211642, }, - "id": "4dcf07cfc26", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?some=other&query=params", + "id": "8d0985c0990", + "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?some=query", + "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=query", }, }, ], @@ -1214,117 +1214,117 @@ exports[`patches image fields > otherRepositoryWithTypeThumbnail > shared slice { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { - "alt": "Vitae et leo duis ut diam quam nulla porttitor massa id neque aliquam vestibulum", + "alt": "Fermentum odio eu feugiat pretium nibh ipsum consequat", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#61adcf", - "x": -1586, - "y": -2819, - "zoom": 1.9393723758262054, + "background": "#9ed252", + "x": -1720, + "y": -191, + "zoom": 1.6165685319845957, }, - "id": "f5dbf0d9ed2", + "id": "35eaa8ebee4", "type": { - "alt": "Vitae et leo duis ut diam quam nulla porttitor massa id neque aliquam vestibulum", + "alt": "Fermentum odio eu feugiat pretium nibh ipsum consequat", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#61adcf", - "x": -1586, - "y": -2819, - "zoom": 1.9393723758262054, + "background": "#9ed252", + "x": -1720, + "y": -191, + "zoom": 1.6165685319845957, }, - "id": "f5dbf0d9ed2", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=other&query=params", + "id": "35eaa8ebee4", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=query", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, }, ], "primary": { "field": { - "alt": "Ut consequat semper viverra nam libero justo laoreet", + "alt": "Pellentesque pulvinar pellentesque habitant morbi tristique senectus et netus et malesuada fames ac", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#8efd5a", - "x": 466, - "y": -571, - "zoom": 1.394663850868741, + "background": "#4f4f59", + "x": 3094, + "y": -2976, + "zoom": 1.0855120641844143, }, - "id": "f5dbf0d9ed2", + "id": "35eaa8ebee4", "type": { - "alt": "Ut consequat semper viverra nam libero justo laoreet", + "alt": "Pellentesque pulvinar pellentesque habitant morbi tristique senectus et netus et malesuada fames ac", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#8efd5a", - "x": 466, - "y": -571, - "zoom": 1.394663850868741, + "background": "#4f4f59", + "x": 3094, + "y": -2976, + "zoom": 1.0855120641844143, }, - "id": "f5dbf0d9ed2", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=other&query=params", + "id": "35eaa8ebee4", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=query", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, "group": [ { "field": { - "alt": "Porttitor massa id neque aliquam vestibulum morbi blandit", + "alt": "Id aliquet risus feugiat in", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#bc3178", - "x": 1156, - "y": -2223, - "zoom": 1.602826201962965, + "background": "#42f5cf", + "x": 427, + "y": 731, + "zoom": 1.6417661415510265, }, - "id": "f5dbf0d9ed2", + "id": "35eaa8ebee4", "type": { - "alt": "Porttitor massa id neque aliquam vestibulum morbi blandit", + "alt": "Id aliquet risus feugiat in", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#bc3178", - "x": 1156, - "y": -2223, - "zoom": 1.602826201962965, + "background": "#42f5cf", + "x": 427, + "y": 731, + "zoom": 1.6417661415510265, }, - "id": "f5dbf0d9ed2", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=other&query=params", + "id": "35eaa8ebee4", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?some=query", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, }, ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -1334,79 +1334,79 @@ exports[`patches image fields > otherRepositoryWithTypeThumbnail > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { - "alt": "Vitae sapien pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis", + "alt": "Pellentesque nec nam aliquam sem", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#c361cc", - "x": -751, - "y": -404, - "zoom": 1.6465649620272602, + "background": "#f72dec", + "x": 2027, + "y": 7, + "zoom": 1.9216652845315787, }, - "id": "4f4a69ff72d", + "id": "7a35bc5aa2f", "type": { - "alt": "Vitae sapien pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis", + "alt": "Pellentesque nec nam aliquam sem", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#c361cc", - "x": -751, - "y": -404, - "zoom": 1.6465649620272602, + "background": "#f72dec", + "x": 2027, + "y": 7, + "zoom": 1.9216652845315787, }, - "id": "4f4a69ff72d", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=other&query=params", + "id": "7a35bc5aa2f", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=query", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=query", }, }, ], "primary": { "field": { - "alt": "Nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc consequat interdum varius sit", + "alt": "Quam nulla porttitor massa id neque aliquam vestibulum morbi blandit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#55e3be", - "x": -762, - "y": 991, - "zoom": 1.0207384987782544, + "background": "#60cbac", + "x": -484, + "y": -2038, + "zoom": 1.8400009569805118, }, - "id": "4f4a69ff72d", + "id": "7a35bc5aa2f", "type": { - "alt": "Nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc consequat interdum varius sit", + "alt": "Quam nulla porttitor massa id neque aliquam vestibulum morbi blandit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#55e3be", - "x": -762, - "y": 991, - "zoom": 1.0207384987782544, + "background": "#60cbac", + "x": -484, + "y": -2038, + "zoom": 1.8400009569805118, }, - "id": "4f4a69ff72d", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=other&query=params", + "id": "7a35bc5aa2f", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?some=query", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=query", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -1415,36 +1415,36 @@ exports[`patches image fields > otherRepositoryWithTypeThumbnail > slice 1`] = ` exports[`patches image fields > otherRepositoryWithTypeThumbnail > static zone 1`] = ` { "field": { - "alt": "Vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae elementum curabitur vitae nunc sed", + "alt": "Gravida rutrum quisque non tellus orci", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#97acc6", - "x": 1922, - "y": -967, - "zoom": 1.9765406541937358, + "background": "#b1d17b", + "x": 3291, + "y": -730, + "zoom": 1.061566393836766, }, - "id": "9abffab1d17", + "id": "4a95cc61c37", "type": { - "alt": "Vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae elementum curabitur vitae nunc sed", + "alt": "Gravida rutrum quisque non tellus orci", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#97acc6", - "x": 1922, - "y": -967, - "zoom": 1.9765406541937358, + "background": "#b1d17b", + "x": 3291, + "y": -730, + "zoom": 1.061566393836766, }, - "id": "9abffab1d17", - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=other&query=params", + "id": "4a95cc61c37", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=query", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?some=query", }, } `; diff --git a/test/__snapshots__/writeClient-migrate-patch-linkToMedia.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-linkToMedia.test.ts.snap index 2624fb3a..a6d213fd 100644 --- a/test/__snapshots__/writeClient-migrate-patch-linkToMedia.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-linkToMedia.test.ts.snap @@ -11,7 +11,7 @@ exports[`patches link to media fields > existing > group 1`] = ` "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", "width": "1", }, }, @@ -23,7 +23,7 @@ exports[`patches link to media fields > existing > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { @@ -33,7 +33,7 @@ exports[`patches link to media fields > existing > shared slice 1`] = ` "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, }, @@ -46,7 +46,7 @@ exports[`patches link to media fields > existing > shared slice 1`] = ` "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, "group": [ @@ -58,16 +58,16 @@ exports[`patches link to media fields > existing > shared slice 1`] = ` "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, }, ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -77,7 +77,7 @@ exports[`patches link to media fields > existing > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { @@ -104,8 +104,8 @@ exports[`patches link to media fields > existing > slice 1`] = ` "width": "1", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -120,7 +120,7 @@ exports[`patches link to media fields > existing > static zone 1`] = ` "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", "width": "1", }, } @@ -136,7 +136,7 @@ exports[`patches link to media fields > existingNonImage > group 1`] = ` "link_type": "Media", "name": "foo.pdf", "size": "1", - "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", }, }, ], @@ -147,7 +147,7 @@ exports[`patches link to media fields > existingNonImage > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { @@ -156,7 +156,7 @@ exports[`patches link to media fields > existingNonImage > shared slice 1`] = ` "link_type": "Media", "name": "foo.pdf", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, }, ], @@ -167,7 +167,7 @@ exports[`patches link to media fields > existingNonImage > shared slice 1`] = ` "link_type": "Media", "name": "foo.pdf", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, "group": [ { @@ -177,15 +177,15 @@ exports[`patches link to media fields > existingNonImage > shared slice 1`] = ` "link_type": "Media", "name": "foo.pdf", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, }, ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -195,7 +195,7 @@ exports[`patches link to media fields > existingNonImage > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { @@ -218,8 +218,8 @@ exports[`patches link to media fields > existingNonImage > slice 1`] = ` "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -233,7 +233,7 @@ exports[`patches link to media fields > existingNonImage > static zone 1`] = ` "link_type": "Media", "name": "foo.pdf", "size": "1", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", }, } `; @@ -244,12 +244,12 @@ exports[`patches link to media fields > new > group 1`] = ` { "field": { "height": "1", - "id": "ef95d5daa4d", + "id": "dfdd322ca9d", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?w=2560&h=1705&fit=crop", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", "width": "1", }, }, @@ -261,17 +261,17 @@ exports[`patches link to media fields > new > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { "height": "1", - "id": "f2c3f8bfc90", + "id": "0eddbd0255b", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", "width": "1", }, }, @@ -279,33 +279,33 @@ exports[`patches link to media fields > new > shared slice 1`] = ` "primary": { "field": { "height": "1", - "id": "f2c3f8bfc90", + "id": "0eddbd0255b", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", "width": "1", }, "group": [ { "field": { "height": "1", - "id": "f2c3f8bfc90", + "id": "0eddbd0255b", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", "width": "1", }, }, ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -315,17 +315,17 @@ exports[`patches link to media fields > new > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { "height": "1", - "id": "45306297c5e", + "id": "2beb55ec2f4", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1444464666168-49d633b86797?w=4844&h=3234&fit=crop", "width": "1", }, }, @@ -333,17 +333,17 @@ exports[`patches link to media fields > new > slice 1`] = ` "primary": { "field": { "height": "1", - "id": "45306297c5e", + "id": "2beb55ec2f4", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1444464666168-49d633b86797?w=4844&h=3234&fit=crop", "width": "1", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -353,12 +353,12 @@ exports[`patches link to media fields > new > static zone 1`] = ` { "field": { "height": "1", - "id": "c5c95f8d3ac", + "id": "bbad670dad7", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", "width": "1", }, } @@ -370,12 +370,12 @@ exports[`patches link to media fields > otherRepository > group 1`] = ` { "field": { "height": "1", - "id": "fdb33894dcf", + "id": "cfc26fe8d09", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?w=6000&h=4000&fit=crop", "width": "1", }, }, @@ -387,17 +387,17 @@ exports[`patches link to media fields > otherRepository > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": { "height": "1", - "id": "ba97bfb16bf", + "id": "61adcf1f5db", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", "width": "1", }, }, @@ -405,33 +405,33 @@ exports[`patches link to media fields > otherRepository > shared slice 1`] = ` "primary": { "field": { "height": "1", - "id": "ba97bfb16bf", + "id": "61adcf1f5db", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", "width": "1", }, "group": [ { "field": { "height": "1", - "id": "ba97bfb16bf", + "id": "61adcf1f5db", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", "width": "1", }, }, ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -441,17 +441,17 @@ exports[`patches link to media fields > otherRepository > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": { "height": "1", - "id": "a57963dc361", + "id": "4f4a69ff72d", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", "width": "1", }, }, @@ -459,17 +459,17 @@ exports[`patches link to media fields > otherRepository > slice 1`] = ` "primary": { "field": { "height": "1", - "id": "a57963dc361", + "id": "4f4a69ff72d", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", "width": "1", }, }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -479,12 +479,12 @@ exports[`patches link to media fields > otherRepository > static zone 1`] = ` { "field": { "height": "1", - "id": "97acc6e9abf", + "id": "b1d17b04a95", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", "width": "1", }, } @@ -510,7 +510,7 @@ exports[`patches link to media fields > richTextExisting > group 1`] = ` "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", "width": "1", }, "end": 5, @@ -531,7 +531,7 @@ exports[`patches link to media fields > richTextExisting > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": [ @@ -550,7 +550,7 @@ exports[`patches link to media fields > richTextExisting > shared slice 1`] = ` "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, "end": 5, @@ -581,7 +581,7 @@ exports[`patches link to media fields > richTextExisting > shared slice 1`] = ` "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, "end": 5, @@ -611,7 +611,7 @@ exports[`patches link to media fields > richTextExisting > shared slice 1`] = ` "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, "end": 5, @@ -627,9 +627,9 @@ exports[`patches link to media fields > richTextExisting > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -639,7 +639,7 @@ exports[`patches link to media fields > richTextExisting > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": [ @@ -702,8 +702,8 @@ exports[`patches link to media fields > richTextExisting > slice 1`] = ` }, ], }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -727,7 +727,7 @@ exports[`patches link to media fields > richTextExisting > static zone 1`] = ` "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", "width": "1", }, "end": 5, @@ -757,12 +757,12 @@ exports[`patches link to media fields > richTextNew > group 1`] = ` { "data": { "height": "1", - "id": "ef95d5daa4d", + "id": "dfdd322ca9d", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?w=2560&h=1705&fit=crop", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", "width": "1", }, "end": 5, @@ -783,7 +783,7 @@ exports[`patches link to media fields > richTextNew > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": [ @@ -797,12 +797,12 @@ exports[`patches link to media fields > richTextNew > shared slice 1`] = ` { "data": { "height": "1", - "id": "f2c3f8bfc90", + "id": "0eddbd0255b", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", "width": "1", }, "end": 5, @@ -828,12 +828,12 @@ exports[`patches link to media fields > richTextNew > shared slice 1`] = ` { "data": { "height": "1", - "id": "f2c3f8bfc90", + "id": "0eddbd0255b", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", "width": "1", }, "end": 5, @@ -858,12 +858,12 @@ exports[`patches link to media fields > richTextNew > shared slice 1`] = ` { "data": { "height": "1", - "id": "f2c3f8bfc90", + "id": "0eddbd0255b", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", "width": "1", }, "end": 5, @@ -879,9 +879,9 @@ exports[`patches link to media fields > richTextNew > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -891,7 +891,7 @@ exports[`patches link to media fields > richTextNew > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": [ @@ -905,12 +905,12 @@ exports[`patches link to media fields > richTextNew > slice 1`] = ` { "data": { "height": "1", - "id": "45306297c5e", + "id": "2beb55ec2f4", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1444464666168-49d633b86797?w=4844&h=3234&fit=crop", "width": "1", }, "end": 5, @@ -936,12 +936,12 @@ exports[`patches link to media fields > richTextNew > slice 1`] = ` { "data": { "height": "1", - "id": "45306297c5e", + "id": "2beb55ec2f4", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1444464666168-49d633b86797?w=4844&h=3234&fit=crop", "width": "1", }, "end": 5, @@ -954,8 +954,8 @@ exports[`patches link to media fields > richTextNew > slice 1`] = ` }, ], }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -974,12 +974,12 @@ exports[`patches link to media fields > richTextNew > static zone 1`] = ` { "data": { "height": "1", - "id": "c5c95f8d3ac", + "id": "bbad670dad7", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", "width": "1", }, "end": 5, @@ -1009,12 +1009,12 @@ exports[`patches link to media fields > richTextOtherRepository > group 1`] = ` { "data": { "height": "1", - "id": "fdb33894dcf", + "id": "cfc26fe8d09", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?w=6000&h=4000&fit=crop", "width": "1", }, "end": 5, @@ -1035,7 +1035,7 @@ exports[`patches link to media fields > richTextOtherRepository > shared slice 1 { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": [ @@ -1049,12 +1049,12 @@ exports[`patches link to media fields > richTextOtherRepository > shared slice 1 { "data": { "height": "1", - "id": "ba97bfb16bf", + "id": "61adcf1f5db", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", "width": "1", }, "end": 5, @@ -1080,12 +1080,12 @@ exports[`patches link to media fields > richTextOtherRepository > shared slice 1 { "data": { "height": "1", - "id": "ba97bfb16bf", + "id": "61adcf1f5db", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", "width": "1", }, "end": 5, @@ -1110,12 +1110,12 @@ exports[`patches link to media fields > richTextOtherRepository > shared slice 1 { "data": { "height": "1", - "id": "ba97bfb16bf", + "id": "61adcf1f5db", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", "width": "1", }, "end": 5, @@ -1131,9 +1131,9 @@ exports[`patches link to media fields > richTextOtherRepository > shared slice 1 ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -1143,7 +1143,7 @@ exports[`patches link to media fields > richTextOtherRepository > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": [ @@ -1157,12 +1157,12 @@ exports[`patches link to media fields > richTextOtherRepository > slice 1`] = ` { "data": { "height": "1", - "id": "a57963dc361", + "id": "4f4a69ff72d", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", "width": "1", }, "end": 5, @@ -1188,12 +1188,12 @@ exports[`patches link to media fields > richTextOtherRepository > slice 1`] = ` { "data": { "height": "1", - "id": "a57963dc361", + "id": "4f4a69ff72d", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", "width": "1", }, "end": 5, @@ -1206,8 +1206,8 @@ exports[`patches link to media fields > richTextOtherRepository > slice 1`] = ` }, ], }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -1226,12 +1226,12 @@ exports[`patches link to media fields > richTextOtherRepository > static zone 1` { "data": { "height": "1", - "id": "97acc6e9abf", + "id": "b1d17b04a95", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", "width": "1", }, "end": 5, diff --git a/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap index 28421765..6e445ca2 100644 --- a/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap @@ -7,8 +7,8 @@ exports[`patches rich text image nodes > existing > group 1`] = ` "field": [ { "spans": [], - "text": "Nulla Aliquet Porttitor Lacus Luctus", - "type": "heading2", + "text": "Donec Enim Diam Vulputate Ut Pharetra Sit Amet Aliquam", + "type": "heading4", }, { "alt": null, @@ -25,7 +25,7 @@ exports[`patches rich text image nodes > existing > group 1`] = ` }, "id": "id-existing", "type": "image", - "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", }, ], }, @@ -37,14 +37,14 @@ exports[`patches rich text image nodes > existing > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": [ { "spans": [], - "text": "Eu Mi", - "type": "heading3", + "text": "A molestie lorem ipsum dolor sit amet consectetur adipiscing elit ut", + "type": "list-item", }, { "alt": null, @@ -61,7 +61,7 @@ exports[`patches rich text image nodes > existing > shared slice 1`] = ` }, "id": "id-existing", "type": "image", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, ], }, @@ -70,8 +70,8 @@ exports[`patches rich text image nodes > existing > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", - "type": "heading3", + "text": "Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium.", + "type": "preformatted", }, { "alt": null, @@ -88,7 +88,7 @@ exports[`patches rich text image nodes > existing > shared slice 1`] = ` }, "id": "id-existing", "type": "image", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, ], "group": [ @@ -96,8 +96,8 @@ exports[`patches rich text image nodes > existing > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Arcu", - "type": "heading1", + "text": "Vel Elit Scelerisque Mauris Pellentesque Pulvinar Pellentesque", + "type": "heading3", }, { "alt": null, @@ -114,16 +114,16 @@ exports[`patches rich text image nodes > existing > shared slice 1`] = ` }, "id": "id-existing", "type": "image", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, ], }, ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -133,14 +133,14 @@ exports[`patches rich text image nodes > existing > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": [ { "spans": [], - "text": "Habitasse platea dictumst quisque sagittis purus sit", - "type": "o-list-item", + "text": "Diam Ut Venenatis Tellus", + "type": "heading6", }, { "alt": null, @@ -166,8 +166,8 @@ exports[`patches rich text image nodes > existing > slice 1`] = ` "field": [ { "spans": [], - "text": "Ac Orci Phasellus Egestas Tellus", - "type": "heading5", + "text": "Tincidunt Vitae Semper Quis Lectus Nulla", + "type": "heading4", }, { "alt": null, @@ -188,8 +188,8 @@ exports[`patches rich text image nodes > existing > slice 1`] = ` }, ], }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -200,8 +200,8 @@ exports[`patches rich text image nodes > existing > static zone 1`] = ` "field": [ { "spans": [], - "text": "Elementum Integer", - "type": "heading6", + "text": "Interdum Velit Euismod", + "type": "heading5", }, { "alt": null, @@ -218,7 +218,7 @@ exports[`patches rich text image nodes > existing > static zone 1`] = ` }, "id": "id-existing", "type": "image", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", }, ], } @@ -231,8 +231,8 @@ exports[`patches rich text image nodes > new > group 1`] = ` "field": [ { "spans": [], - "text": "Nulla Aliquet Porttitor Lacus Luctus", - "type": "heading2", + "text": "Donec Enim Diam Vulputate Ut Pharetra Sit Amet Aliquam", + "type": "heading4", }, { "alt": null, @@ -247,9 +247,9 @@ exports[`patches rich text image nodes > new > group 1`] = ` "y": 0, "zoom": 1, }, - "id": "cdfdd322ca9", + "id": "c1d5d24feae", "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c?w=6000&h=4000&fit=crop", + "url": "https://images.unsplash.com/photo-1504198266287-1659872e6590?w=4272&h=2848&fit=crop", }, ], }, @@ -261,14 +261,14 @@ exports[`patches rich text image nodes > new > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": [ { "spans": [], - "text": "Eu Mi", - "type": "heading3", + "text": "A molestie lorem ipsum dolor sit amet consectetur adipiscing elit ut", + "type": "list-item", }, { "alt": null, @@ -283,9 +283,9 @@ exports[`patches rich text image nodes > new > shared slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "bc31787853a", + "id": "961adcf1f5d", "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", }, ], }, @@ -294,8 +294,8 @@ exports[`patches rich text image nodes > new > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", - "type": "heading3", + "text": "Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium.", + "type": "preformatted", }, { "alt": null, @@ -310,9 +310,9 @@ exports[`patches rich text image nodes > new > shared slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "bc31787853a", + "id": "961adcf1f5d", "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", }, ], "group": [ @@ -320,8 +320,8 @@ exports[`patches rich text image nodes > new > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Arcu", - "type": "heading1", + "text": "Vel Elit Scelerisque Mauris Pellentesque Pulvinar Pellentesque", + "type": "heading3", }, { "alt": null, @@ -336,18 +336,18 @@ exports[`patches rich text image nodes > new > shared slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "bc31787853a", + "id": "961adcf1f5d", "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", }, ], }, ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -357,14 +357,14 @@ exports[`patches rich text image nodes > new > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": [ { "spans": [], - "text": "Habitasse platea dictumst quisque sagittis purus sit", - "type": "o-list-item", + "text": "Diam Ut Venenatis Tellus", + "type": "heading6", }, { "alt": null, @@ -379,9 +379,9 @@ exports[`patches rich text image nodes > new > slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "7963dc361cc", + "id": "61cc54f4a69", "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, ], }, @@ -390,8 +390,8 @@ exports[`patches rich text image nodes > new > slice 1`] = ` "field": [ { "spans": [], - "text": "Ac Orci Phasellus Egestas Tellus", - "type": "heading5", + "text": "Tincidunt Vitae Semper Quis Lectus Nulla", + "type": "heading4", }, { "alt": null, @@ -406,14 +406,14 @@ exports[`patches rich text image nodes > new > slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "7963dc361cc", + "id": "61cc54f4a69", "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, ], }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -424,8 +424,8 @@ exports[`patches rich text image nodes > new > static zone 1`] = ` "field": [ { "spans": [], - "text": "Elementum Integer", - "type": "heading6", + "text": "Interdum Velit Euismod", + "type": "heading5", }, { "alt": null, @@ -440,9 +440,9 @@ exports[`patches rich text image nodes > new > static zone 1`] = ` "y": 0, "zoom": 1, }, - "id": "0bbad670dad", + "id": "ed908b1e225", "type": "image", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", + "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?w=6000&h=4000&fit=crop", }, ], } @@ -455,8 +455,8 @@ exports[`patches rich text image nodes > newLinkTo > group 1`] = ` "field": [ { "spans": [], - "text": "Nulla Aliquet Porttitor Lacus Luctus", - "type": "heading2", + "text": "Donec Enim Diam Vulputate Ut Pharetra Sit Amet Aliquam", + "type": "heading4", }, { "alt": null, @@ -471,7 +471,7 @@ exports[`patches rich text image nodes > newLinkTo > group 1`] = ` "y": 0, "zoom": 1, }, - "id": "cdfdd322ca9", + "id": "c1d5d24feae", "linkTo": { "id": "id-existing", "isBroken": false, @@ -481,7 +481,7 @@ exports[`patches rich text image nodes > newLinkTo > group 1`] = ` "type": "orci", }, "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c?w=6000&h=4000&fit=crop", + "url": "https://images.unsplash.com/photo-1504198266287-1659872e6590?w=4272&h=2848&fit=crop", }, ], }, @@ -493,14 +493,14 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": [ { "spans": [], - "text": "Eu Mi", - "type": "heading3", + "text": "A molestie lorem ipsum dolor sit amet consectetur adipiscing elit ut", + "type": "list-item", }, { "alt": null, @@ -515,7 +515,7 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "bc31787853a", + "id": "961adcf1f5d", "linkTo": { "id": "id-existing", "isBroken": false, @@ -527,7 +527,7 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "type": "dui", }, "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", }, ], }, @@ -536,8 +536,8 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", - "type": "heading3", + "text": "Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium.", + "type": "preformatted", }, { "alt": null, @@ -552,7 +552,7 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "bc31787853a", + "id": "961adcf1f5d", "linkTo": { "id": "id-existing", "isBroken": false, @@ -564,7 +564,7 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "type": "dui", }, "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", }, ], "group": [ @@ -572,8 +572,8 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Arcu", - "type": "heading1", + "text": "Vel Elit Scelerisque Mauris Pellentesque Pulvinar Pellentesque", + "type": "heading3", }, { "alt": null, @@ -588,7 +588,7 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "bc31787853a", + "id": "961adcf1f5d", "linkTo": { "id": "id-existing", "isBroken": false, @@ -600,16 +600,16 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "type": "dui", }, "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", }, ], }, ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -619,14 +619,14 @@ exports[`patches rich text image nodes > newLinkTo > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": [ { "spans": [], - "text": "Habitasse platea dictumst quisque sagittis purus sit", - "type": "o-list-item", + "text": "Diam Ut Venenatis Tellus", + "type": "heading6", }, { "alt": null, @@ -641,7 +641,7 @@ exports[`patches rich text image nodes > newLinkTo > slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "7963dc361cc", + "id": "61cc54f4a69", "linkTo": { "id": "id-existing", "isBroken": false, @@ -653,7 +653,7 @@ exports[`patches rich text image nodes > newLinkTo > slice 1`] = ` "type": "amet", }, "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, ], }, @@ -662,8 +662,8 @@ exports[`patches rich text image nodes > newLinkTo > slice 1`] = ` "field": [ { "spans": [], - "text": "Ac Orci Phasellus Egestas Tellus", - "type": "heading5", + "text": "Tincidunt Vitae Semper Quis Lectus Nulla", + "type": "heading4", }, { "alt": null, @@ -678,7 +678,7 @@ exports[`patches rich text image nodes > newLinkTo > slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "7963dc361cc", + "id": "61cc54f4a69", "linkTo": { "id": "id-existing", "isBroken": false, @@ -690,12 +690,12 @@ exports[`patches rich text image nodes > newLinkTo > slice 1`] = ` "type": "amet", }, "type": "image", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, ], }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -706,8 +706,8 @@ exports[`patches rich text image nodes > newLinkTo > static zone 1`] = ` "field": [ { "spans": [], - "text": "Elementum Integer", - "type": "heading6", + "text": "Interdum Velit Euismod", + "type": "heading5", }, { "alt": null, @@ -722,7 +722,7 @@ exports[`patches rich text image nodes > newLinkTo > static zone 1`] = ` "y": 0, "zoom": 1, }, - "id": "0bbad670dad", + "id": "ed908b1e225", "linkTo": { "id": "id-existing", "isBroken": false, @@ -732,7 +732,7 @@ exports[`patches rich text image nodes > newLinkTo > static zone 1`] = ` "type": "phasellus", }, "type": "image", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", + "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?w=6000&h=4000&fit=crop", }, ], } @@ -745,25 +745,25 @@ exports[`patches rich text image nodes > otherRepository > group 1`] = ` "field": [ { "spans": [], - "text": "Nulla Aliquet Porttitor Lacus Luctus", - "type": "heading2", + "text": "Donec Enim Diam Vulputate Ut Pharetra Sit Amet Aliquam", + "type": "heading4", }, { - "alt": "Donec enim diam vulputate ut pharetra sit amet aliquam id diam", + "alt": "Feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper morbi", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#7cfc26", - "x": 2977, - "y": -1163, - "zoom": 1.0472585898934068, + "background": "#5c0990", + "x": 2090, + "y": -1492, + "zoom": 1.854310159304717, }, - "id": "e8d0985c099", + "id": "6442e21ad60", "type": "image", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05", }, ], }, @@ -775,29 +775,40 @@ exports[`patches rich text image nodes > otherRepository > shared slice 1`] = ` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": [ { - "spans": [], - "text": "Facilisis", - "type": "heading3", + "oembed": { + "embed_url": "https://twitter.com/prismicio/status/1354835716430319617", + "height": 113, + "html": " + +", + "thumbnail_height": null, + "thumbnail_url": null, + "thumbnail_width": null, + "type": "rich", + "version": "1.0", + "width": 200, + }, + "type": "embed", }, { - "alt": "Nullam vehicula ipsum a arcu cursus vitae congue mauris rhoncus aenean vel elit scelerisque", + "alt": "Eros donec ac odio tempor orci dapibus", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#37ae3f", - "x": -1505, - "y": 902, - "zoom": 1.8328975606320652, + "background": "#1eeca0", + "x": 1722, + "y": 1820, + "zoom": 1.8326837750693512, }, - "id": "3fc0dfa9fe9", + "id": "3a8ec9378bc", "type": "image", "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", }, @@ -808,23 +819,23 @@ exports[`patches rich text image nodes > otherRepository > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", - "type": "heading3", + "text": "Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium.", + "type": "preformatted", }, { - "alt": "Proin libero nunc consequat interdum varius", + "alt": "Aliquet lectus proin nibh nisl condimentum id venenatis a", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#904f4f", - "x": 1462, - "y": 1324, - "zoom": 1.504938844941775, + "background": "#87853a", + "x": -1429, + "y": -2019, + "zoom": 1.75840565859303, }, - "id": "3fc0dfa9fe9", + "id": "3a8ec9378bc", "type": "image", "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", }, @@ -834,23 +845,23 @@ exports[`patches rich text image nodes > otherRepository > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Egestas Integer Eget Aliquet Nibh", + "text": "Nunc Non Blandit Massa Enim", "type": "heading5", }, { - "alt": "Arcu cursus vitae congue mauris", + "alt": "Id faucibus nisl tincidunt eget nullam non nisi est sit amet", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#5f7a9b", - "x": -119, - "y": -2667, - "zoom": 1.9681315715350518, + "background": "#252b35", + "x": 855, + "y": 1518, + "zoom": 1.5250952426635416, }, - "id": "3fc0dfa9fe9", + "id": "3a8ec9378bc", "type": "image", "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", }, @@ -859,9 +870,9 @@ exports[`patches rich text image nodes > otherRepository > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -871,29 +882,29 @@ exports[`patches rich text image nodes > otherRepository > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": [ { "spans": [], - "text": "Amet", - "type": "heading5", + "text": "At Ultrices Mi Tempus Imperdiet", + "type": "heading2", }, { - "alt": "Auctor neque vitae tempus quam", + "alt": "Sed id semper risus in hendrerit gravida rutrum", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#5bc5aa", - "x": -1072, - "y": -281, - "zoom": 1.3767766101231744, + "background": "#104dde", + "x": -1621, + "y": -870, + "zoom": 1.7278759511485409, }, - "id": "f70ca27104d", + "id": "2003a644c30", "type": "image", "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", }, @@ -904,30 +915,30 @@ exports[`patches rich text image nodes > otherRepository > slice 1`] = ` "field": [ { "spans": [], - "text": "Ac Orci Phasellus Egestas Tellus", - "type": "heading5", + "text": "Tincidunt Vitae Semper Quis Lectus Nulla", + "type": "heading4", }, { - "alt": "Urna id volutpat lacus laoreet non curabitur gravida arcu ac tortor", + "alt": "Sed nisi lacus sed viverra tellus in hac habitasse", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#4860cb", - "x": 280, - "y": -379, - "zoom": 1.2389796902982004, + "background": "#63a6c9", + "x": -1609, + "y": -1609, + "zoom": 1.7054690955452316, }, - "id": "f70ca27104d", + "id": "2003a644c30", "type": "image", "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", }, ], }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -938,25 +949,25 @@ exports[`patches rich text image nodes > otherRepository > static zone 1`] = ` "field": [ { "spans": [], - "text": "Elementum Integer", - "type": "heading6", + "text": "Interdum Velit Euismod", + "type": "heading5", }, { - "alt": "Interdum velit euismod in pellentesque", + "alt": "Tortor consequat id porta nibh", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#ab1d17", - "x": 3605, - "y": 860, - "zoom": 1.9465488211593005, + "background": "#c61c37", + "x": 349, + "y": -429, + "zoom": 1.4911347686990943, }, - "id": "04a95cc61c3", + "id": "ff1efb2b271", "type": "image", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1", }, ], } @@ -969,23 +980,23 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > group 1`] = ` "field": [ { "spans": [], - "text": "Nulla Aliquet Porttitor Lacus Luctus", - "type": "heading2", + "text": "Donec Enim Diam Vulputate Ut Pharetra Sit Amet Aliquam", + "type": "heading4", }, { - "alt": "Donec enim diam vulputate ut pharetra sit amet aliquam id diam", + "alt": "Feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper morbi", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#7cfc26", - "x": 2977, - "y": -1163, - "zoom": 1.0472585898934068, + "background": "#5c0990", + "x": 2090, + "y": -1492, + "zoom": 1.854310159304717, }, - "id": "e8d0985c099", + "id": "6442e21ad60", "linkTo": { "id": "id-existing", "isBroken": false, @@ -995,7 +1006,7 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > group 1`] = ` "type": "orci", }, "type": "image", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05", }, ], }, @@ -1007,29 +1018,40 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > shared slice 1` { "slices": [ { - "id": "2ff58c741ba", + "id": "b9dd0f2c3f8", "items": [ { "field": [ { - "spans": [], - "text": "Facilisis", - "type": "heading3", + "oembed": { + "embed_url": "https://twitter.com/prismicio/status/1354835716430319617", + "height": 113, + "html": " + +", + "thumbnail_height": null, + "thumbnail_url": null, + "thumbnail_width": null, + "type": "rich", + "version": "1.0", + "width": 200, + }, + "type": "embed", }, { - "alt": "Nullam vehicula ipsum a arcu cursus vitae congue mauris rhoncus aenean vel elit scelerisque", + "alt": "Eros donec ac odio tempor orci dapibus", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#37ae3f", - "x": -1505, - "y": 902, - "zoom": 1.8328975606320652, + "background": "#1eeca0", + "x": 1722, + "y": 1820, + "zoom": 1.8326837750693512, }, - "id": "3fc0dfa9fe9", + "id": "3a8ec9378bc", "linkTo": { "id": "id-existing", "isBroken": false, @@ -1050,23 +1072,23 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > shared slice 1` "field": [ { "spans": [], - "text": "Fringilla Phasellus Faucibus Scelerisque Eleifend Donec Pretium", - "type": "heading3", + "text": "Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium.", + "type": "preformatted", }, { - "alt": "Proin libero nunc consequat interdum varius", + "alt": "Aliquet lectus proin nibh nisl condimentum id venenatis a", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#904f4f", - "x": 1462, - "y": 1324, - "zoom": 1.504938844941775, + "background": "#87853a", + "x": -1429, + "y": -2019, + "zoom": 1.75840565859303, }, - "id": "3fc0dfa9fe9", + "id": "3a8ec9378bc", "linkTo": { "id": "id-existing", "isBroken": false, @@ -1086,23 +1108,23 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > shared slice 1` "field": [ { "spans": [], - "text": "Egestas Integer Eget Aliquet Nibh", + "text": "Nunc Non Blandit Massa Enim", "type": "heading5", }, { - "alt": "Arcu cursus vitae congue mauris", + "alt": "Id faucibus nisl tincidunt eget nullam non nisi est sit amet", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#5f7a9b", - "x": -119, - "y": -2667, - "zoom": 1.9681315715350518, + "background": "#252b35", + "x": 855, + "y": 1518, + "zoom": 1.5250952426635416, }, - "id": "3fc0dfa9fe9", + "id": "3a8ec9378bc", "linkTo": { "id": "id-existing", "isBroken": false, @@ -1121,9 +1143,9 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > shared slice 1` ], }, "slice_label": null, - "slice_type": "at", - "variation": "tortor", - "version": "a79b9dd", + "slice_type": "dignissim", + "variation": "vitae", + "version": "bfc9053", }, ], } @@ -1133,29 +1155,29 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > slice 1`] = ` { "slices": [ { - "id": "e93cc3e4f28", + "id": "306297c5eda", "items": [ { "field": [ { "spans": [], - "text": "Amet", - "type": "heading5", + "text": "At Ultrices Mi Tempus Imperdiet", + "type": "heading2", }, { - "alt": "Auctor neque vitae tempus quam", + "alt": "Sed id semper risus in hendrerit gravida rutrum", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#5bc5aa", - "x": -1072, - "y": -281, - "zoom": 1.3767766101231744, + "background": "#104dde", + "x": -1621, + "y": -870, + "zoom": 1.7278759511485409, }, - "id": "f70ca27104d", + "id": "2003a644c30", "linkTo": { "id": "id-existing", "isBroken": false, @@ -1176,23 +1198,23 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > slice 1`] = ` "field": [ { "spans": [], - "text": "Ac Orci Phasellus Egestas Tellus", - "type": "heading5", + "text": "Tincidunt Vitae Semper Quis Lectus Nulla", + "type": "heading4", }, { - "alt": "Urna id volutpat lacus laoreet non curabitur gravida arcu ac tortor", + "alt": "Sed nisi lacus sed viverra tellus in hac habitasse", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#4860cb", - "x": 280, - "y": -379, - "zoom": 1.2389796902982004, + "background": "#63a6c9", + "x": -1609, + "y": -1609, + "zoom": 1.7054690955452316, }, - "id": "f70ca27104d", + "id": "2003a644c30", "linkTo": { "id": "id-existing", "isBroken": false, @@ -1208,8 +1230,8 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > slice 1`] = ` }, ], }, - "slice_label": "Pellentesque", - "slice_type": "nulla_posuere", + "slice_label": "Aliquet", + "slice_type": "vel", }, ], } @@ -1220,23 +1242,23 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > static zone 1`] "field": [ { "spans": [], - "text": "Elementum Integer", - "type": "heading6", + "text": "Interdum Velit Euismod", + "type": "heading5", }, { - "alt": "Interdum velit euismod in pellentesque", + "alt": "Tortor consequat id porta nibh", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#ab1d17", - "x": 3605, - "y": 860, - "zoom": 1.9465488211593005, + "background": "#c61c37", + "x": 349, + "y": -429, + "zoom": 1.4911347686990943, }, - "id": "04a95cc61c3", + "id": "ff1efb2b271", "linkTo": { "id": "id-existing", "isBroken": false, @@ -1246,7 +1268,7 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > static zone 1`] "type": "phasellus", }, "type": "image", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1", }, ], } diff --git a/test/__testutils__/testMigrationFieldPatching.ts b/test/__testutils__/testMigrationFieldPatching.ts index e9650ea5..3dd88d58 100644 --- a/test/__testutils__/testMigrationFieldPatching.ts +++ b/test/__testutils__/testMigrationFieldPatching.ts @@ -22,12 +22,15 @@ type GetDataArgs = { migration: prismic.Migration existingAssets: Asset[] existingDocuments: prismic.PrismicDocument[] - migrationDocuments: prismic.MigrationDocument[] + migrationDocuments: { + other: prismic.PrismicMigrationDocument + otherRepository: prismic.PrismicMigrationDocument + } mockedDomain: string } type InternalTestMigrationFieldPatchingArgs = { - getData: (args: GetDataArgs) => prismic.MigrationDocumentValue["data"] + getData: (args: GetDataArgs) => prismic.ExistingPrismicDocument["data"] expectStrictEqual?: boolean } @@ -51,11 +54,15 @@ const internalTestMigrationFieldPatching = ( }) queryResponse[0].results[0].id = "id-existing" - const otherDocument = { + const { id: _id, ...otherDocument } = { ...ctx.mock.value.document(), uid: ctx.mock.value.keyText(), } - const newDocument = ctx.mock.value.document() + const otherRepositoryDocument = { + ...ctx.mock.value.document(), + uid: ctx.mock.value.keyText(), + } + const { id: __id, ...newDocument } = ctx.mock.value.document() const newID = "id-new" @@ -68,7 +75,11 @@ const internalTestMigrationFieldPatching = ( const { documentsDatabase } = mockPrismicMigrationAPI({ ctx, client, - newDocuments: [{ id: "id-migration" }, { id: newID }], + newDocuments: [ + { id: "id-other" }, + { id: "id-other-repository" }, + { id: newID }, + ], }) const mockedDomain = `https://${client.repositoryName}.example.com` @@ -85,12 +96,21 @@ const internalTestMigrationFieldPatching = ( "other", ) + const migrationOtherRepositoryDocument = + migration.createDocumentFromPrismic( + otherRepositoryDocument, + "other-repository", + ) + newDocument.data = args.getData({ ctx, migration, existingAssets: assetsDatabase.flat(), existingDocuments: queryResponse[0].results, - migrationDocuments: [migrationOtherDocument], + migrationDocuments: { + other: migrationOtherDocument, + otherRepository: migrationOtherRepositoryDocument, + }, mockedDomain, }) @@ -115,7 +135,7 @@ const internalTestMigrationFieldPatching = ( type TestMigrationFieldPatchingFactoryCases = Record< string, - (args: GetDataArgs) => prismic.MigrationDocumentValue["data"][string] + (args: GetDataArgs) => prismic.ExistingPrismicDocument["data"][string] > export const testMigrationFieldPatching = ( diff --git a/test/migration-createDocument.test.ts b/test/migration-createDocument.test.ts index 0877330b..7affcaca 100644 --- a/test/migration-createDocument.test.ts +++ b/test/migration-createDocument.test.ts @@ -4,12 +4,12 @@ import type { MockFactory } from "@prismicio/mock" import * as prismic from "../src" import type { MigrationAssetConfig } from "../src/types/migration/Asset" -import { MigrationDocument } from "../src/types/migration/Document" +import { PrismicMigrationDocument } from "../src/types/migration/Document" it("creates a document", () => { const migration = prismic.createMigration() - const document: prismic.MigrationDocumentValue = { + const document: prismic.PendingPrismicDocument = { type: "type", uid: "uid", lang: "lang", @@ -20,7 +20,7 @@ it("creates a document", () => { migration.createDocument(document, documentTitle) expect(migration._documents[0]).toStrictEqual( - new MigrationDocument(document, { documentTitle }), + new PrismicMigrationDocument(document, documentTitle, { dependencies: [] }), ) }) @@ -33,7 +33,7 @@ it("creates a document from an existing Prismic document", (ctx) => { migration.createDocument(document, documentTitle) expect(migration._documents[0]).toStrictEqual( - new MigrationDocument(document, { documentTitle }), + new PrismicMigrationDocument(document, documentTitle, { dependencies: [] }), ) }) @@ -184,7 +184,7 @@ describe.each<{ const { id, field, expected } = getField(mock) - const document: prismic.MigrationDocumentValue = { + const document: prismic.PendingPrismicDocument = { type: "type", uid: "uid", lang: "lang", @@ -204,7 +204,7 @@ describe.each<{ const { id, field, expected } = getField(mock) - const document: prismic.MigrationDocumentValue = { + const document: prismic.PendingPrismicDocument = { type: "type", uid: "uid", lang: "lang", @@ -234,7 +234,7 @@ describe.each<{ }, ] - const document: prismic.MigrationDocumentValue = { + const document: prismic.PendingPrismicDocument = { type: "type", uid: "uid", lang: "lang", @@ -264,7 +264,7 @@ describe.each<{ }, ] - const document: prismic.MigrationDocumentValue = { + const document: prismic.PendingPrismicDocument = { type: "type", uid: "uid", lang: "lang", diff --git a/test/migration-updateDocument.test.ts b/test/migration-updateDocument.test.ts index d48aaf58..ea93fcdb 100644 --- a/test/migration-updateDocument.test.ts +++ b/test/migration-updateDocument.test.ts @@ -1,7 +1,7 @@ import { expect, it } from "vitest" import * as prismic from "../src" -import { MigrationDocument } from "../src/types/migration/Document" +import { PrismicMigrationDocument } from "../src/types/migration/Document" it("updates a document", (ctx) => { const migration = prismic.createMigration() @@ -11,7 +11,7 @@ it("updates a document", (ctx) => { migration.updateDocument(document, documentTitle) - const expectedDocument = new MigrationDocument(document, { documentTitle }) - expectedDocument._mode = "update" - expect(migration._documents[0]).toStrictEqual(expectedDocument) + expect(migration._documents[0]).toStrictEqual( + new PrismicMigrationDocument(document, documentTitle, { dependencies: [] }), + ) }) diff --git a/test/types/migration-document.types.ts b/test/types/migration-document.types.ts index e43626a3..afe5ccea 100644 --- a/test/types/migration-document.types.ts +++ b/test/types/migration-document.types.ts @@ -3,7 +3,7 @@ import { expectNever, expectType } from "ts-expect" import type * as prismic from "../../src" -;(value: prismic.MigrationDocumentValue): true => { +;(value: prismic.PendingPrismicDocument): true => { switch (typeof value) { case "object": { if (value === null) { @@ -19,7 +19,7 @@ import type * as prismic from "../../src" } } -expectType({ +expectType({ uid: "", type: "", lang: "", @@ -29,7 +29,7 @@ expectType({ /** * Supports any field when generic. */ -expectType({ +expectType({ uid: "", type: "", lang: "", @@ -39,12 +39,12 @@ expectType({ }) /** - * `PrismicDocument` is assignable to `MigrationDocumentValue` with added + * `PrismicDocument` is assignable to `PendingPrismicDocument` with added * `title`. */ expectType< TypeOf< - prismic.MigrationDocumentValue, + prismic.PendingPrismicDocument, prismic.PrismicDocument & { title: string } > >(true) @@ -55,7 +55,7 @@ type BarDocument = prismic.PrismicDocument<{ bar: prismic.KeyTextField }, "bar"> type BazDocument = prismic.PrismicDocument, "baz"> type Documents = FooDocument | BarDocument | BazDocument -type MigrationDocuments = prismic.MigrationDocumentValue +type MigrationDocuments = prismic.PendingPrismicDocument /** * Infers data type from document type. @@ -128,7 +128,7 @@ type SliceDocument = prismic.PrismicDocument< > type AdvancedDocuments = StaticDocument | GroupDocument | SliceDocument type MigrationAdvancedDocuments = - prismic.MigrationDocumentValue + prismic.PendingPrismicDocument // Static expectType({ diff --git a/test/types/migration.types.ts b/test/types/migration.types.ts index f3c3bd2d..ca79adab 100644 --- a/test/types/migration.types.ts +++ b/test/types/migration.types.ts @@ -7,9 +7,18 @@ import * as prismic from "../../src" const defaultMigration = prismic.createMigration() // Migration Documents -type FooDocument = prismic.PrismicDocument, "foo"> -type BarDocument = prismic.PrismicDocument, "bar"> -type BazDocument = prismic.PrismicDocument, "baz"> +type FooDocument = prismic.PrismicDocumentWithUID< + { foo: prismic.KeyTextField }, + "foo" +> +type BarDocument = prismic.PrismicDocumentWithUID< + { bar: prismic.KeyTextField }, + "bar" +> +type BazDocument = prismic.PrismicDocumentWithoutUID< + { baz: prismic.KeyTextField }, + "baz" +> type Documents = FooDocument | BarDocument | BazDocument const documentsMigration = prismic.createMigration() @@ -123,7 +132,7 @@ expectType< >(true) /** - * createDocument - basic + * createDocument */ // Default @@ -136,9 +145,9 @@ const defaultCreateDocument = defaultMigration.createDocument( }, "", ) -expectType>( - true, -) +expectType< + TypeEqual +>(true) // Documents const documentsCreateDocument = documentsMigration.createDocument( @@ -146,13 +155,404 @@ const documentsCreateDocument = documentsMigration.createDocument( type: "foo", uid: "", lang: "", - data: {}, + data: { + foo: "", + }, }, "", ) expectType< TypeEqual< typeof documentsCreateDocument, - prismic.MigrationDocument + prismic.PrismicMigrationDocument + > +>(true) + +documentsMigration.createDocument( + { + type: "baz", + lang: "", + data: { + baz: "", + }, + }, + "", +) + +documentsMigration.createDocument( + { + type: "baz", + // @ts-expect-error - Type 'string' is not assignable to type 'null | undefined'. + uid: "", + lang: "", + data: { + baz: "", + }, + }, + "", +) + +documentsMigration.createDocument( + { + type: "foo", + uid: "", + lang: "", + // @ts-expect-error - Property 'foo' is missing + data: {}, + }, + "", +) + +documentsMigration.createDocument( + { + type: "foo", + uid: "", + lang: "", + data: { + // @ts-expect-error - Type 'number' is not assignable to type 'KeyTextField' + foo: 1, + }, + }, + "", +) + +documentsMigration.createDocument( + { + type: "foo", + uid: "", + lang: "", + data: { + foo: "", + // @ts-expect-error - Object literal may only specify known properties + bar: "", + }, + }, + "", +) +/** + * updateDocument + */ + +// Default +const defaultUpdateDocument = defaultMigration.updateDocument( + { + id: "", + type: "", + lang: "", + data: {}, + tags: [], + href: "", + url: "", + last_publication_date: `0-0-0T0:0:0+0`, + first_publication_date: `0-0-0T0:0:0+0`, + slugs: [], + alternate_languages: [], + linked_documents: [], + }, + "", +) +expectType< + TypeEqual +>(true) + +// Documents +const documentsUpdateDocument = documentsMigration.updateDocument( + { + id: "", + type: "foo", + uid: "", + lang: "", + data: { + foo: "", + }, + tags: [], + href: "", + url: "", + last_publication_date: `0-0-0T0:0:0+0`, + first_publication_date: `0-0-0T0:0:0+0`, + slugs: [], + alternate_languages: [], + linked_documents: [], + }, + "", +) +expectType< + TypeEqual< + typeof documentsUpdateDocument, + prismic.PrismicMigrationDocument > >(true) + +documentsMigration.updateDocument( + { + id: "", + type: "baz", + lang: "", + data: { + baz: "", + }, + tags: [], + href: "", + url: "", + last_publication_date: `0-0-0T0:0:0+0`, + first_publication_date: `0-0-0T0:0:0+0`, + slugs: [], + alternate_languages: [], + linked_documents: [], + }, + "", +) + +documentsMigration.updateDocument( + { + id: "", + type: "baz", + // @ts-expect-error - Type 'string' is not assignable to type 'null | undefined'. + uid: "", + lang: "", + data: { + baz: "", + }, + tags: [], + href: "", + url: "", + last_publication_date: `0-0-0T0:0:0+0`, + first_publication_date: `0-0-0T0:0:0+0`, + slugs: [], + alternate_languages: [], + linked_documents: [], + }, + "", +) + +documentsMigration.updateDocument( + { + id: "", + type: "foo", + uid: "", + lang: "", + // @ts-expect-error - Property 'foo' is missing + data: {}, + tags: [], + href: "", + url: "", + last_publication_date: `0-0-0T0:0:0+0`, + first_publication_date: `0-0-0T0:0:0+0`, + slugs: [], + alternate_languages: [], + linked_documents: [], + }, + "", +) + +documentsMigration.updateDocument( + { + id: "", + type: "foo", + uid: "", + lang: "", + data: { + // @ts-expect-error - Type 'number' is not assignable to type 'KeyTextField' + foo: 1, + }, + tags: [], + href: "", + url: "", + last_publication_date: `0-0-0T0:0:0+0`, + first_publication_date: `0-0-0T0:0:0+0`, + slugs: [], + alternate_languages: [], + linked_documents: [], + }, + "", +) + +documentsMigration.updateDocument( + { + id: "", + type: "foo", + uid: "", + lang: "", + data: { + foo: "", + // @ts-expect-error - Object literal may only specify known properties + bar: "", + }, + tags: [], + href: "", + url: "", + last_publication_date: `0-0-0T0:0:0+0`, + first_publication_date: `0-0-0T0:0:0+0`, + slugs: [], + alternate_languages: [], + linked_documents: [], + }, + "", +) + +/** + * createDocumentFromPrismic + */ + +// Default +const defaultCreateFromPrismicDocument = + defaultMigration.createDocumentFromPrismic( + { + id: "", + type: "", + uid: "", + lang: "", + data: {}, + tags: [], + href: "", + url: "", + last_publication_date: `0-0-0T0:0:0+0`, + first_publication_date: `0-0-0T0:0:0+0`, + slugs: [], + alternate_languages: [], + linked_documents: [], + }, + "", + ) +expectType< + TypeEqual< + typeof defaultCreateFromPrismicDocument, + prismic.PrismicMigrationDocument + > +>(true) + +// Documents +const documentsCreateFromPrismicDocument = + documentsMigration.createDocumentFromPrismic( + { + id: "", + type: "foo", + uid: "", + lang: "", + data: { + foo: "", + }, + tags: [], + href: "", + url: "", + last_publication_date: `0-0-0T0:0:0+0`, + first_publication_date: `0-0-0T0:0:0+0`, + slugs: [], + alternate_languages: [], + linked_documents: [], + }, + "", + ) +expectType< + TypeEqual< + typeof documentsCreateFromPrismicDocument, + prismic.PrismicMigrationDocument + > +>(true) + +documentsMigration.createDocumentFromPrismic( + { + id: "", + type: "baz", + lang: "", + data: { + baz: "", + }, + tags: [], + href: "", + url: "", + last_publication_date: `0-0-0T0:0:0+0`, + first_publication_date: `0-0-0T0:0:0+0`, + slugs: [], + alternate_languages: [], + linked_documents: [], + }, + "", +) + +documentsMigration.createDocumentFromPrismic( + { + id: "", + type: "baz", + // @ts-expect-error - Type 'string' is not assignable to type 'null | undefined'. + uid: "", + lang: "", + data: { + baz: "", + }, + tags: [], + href: "", + url: "", + last_publication_date: `0-0-0T0:0:0+0`, + first_publication_date: `0-0-0T0:0:0+0`, + slugs: [], + alternate_languages: [], + linked_documents: [], + }, + "", +) + +documentsMigration.createDocumentFromPrismic( + { + id: "", + type: "foo", + uid: "", + lang: "", + // @ts-expect-error - Property 'foo' is missing + data: {}, + tags: [], + href: "", + url: "", + last_publication_date: `0-0-0T0:0:0+0`, + first_publication_date: `0-0-0T0:0:0+0`, + slugs: [], + alternate_languages: [], + linked_documents: [], + }, + "", +) + +documentsMigration.createDocumentFromPrismic( + { + id: "", + type: "foo", + uid: "", + lang: "", + data: { + // @ts-expect-error - Type 'number' is not assignable to type 'KeyTextField' + foo: 1, + }, + tags: [], + href: "", + url: "", + last_publication_date: `0-0-0T0:0:0+0`, + first_publication_date: `0-0-0T0:0:0+0`, + slugs: [], + alternate_languages: [], + linked_documents: [], + }, + "", +) + +documentsMigration.createDocumentFromPrismic( + { + id: "", + type: "foo", + uid: "", + lang: "", + data: { + foo: "", + // @ts-expect-error - Object literal may only specify known properties + bar: "", + }, + tags: [], + href: "", + url: "", + last_publication_date: `0-0-0T0:0:0+0`, + first_publication_date: `0-0-0T0:0:0+0`, + slugs: [], + alternate_languages: [], + linked_documents: [], + }, + "", +) diff --git a/test/writeClient-migrate-documents.test.ts b/test/writeClient-migrate-documents.test.ts index a16c6028..73e25803 100644 --- a/test/writeClient-migrate-documents.test.ts +++ b/test/writeClient-migrate-documents.test.ts @@ -77,7 +77,7 @@ it.concurrent("discovers existing documents", async (ctx) => { }) }) -it.concurrent("skips creating existing documents (update)", async (ctx) => { +it.concurrent("skips creating existing documents", async (ctx) => { const client = createTestWriteClient({ ctx }) const queryResponse = createPagedQueryResponses({ @@ -102,48 +102,7 @@ it.concurrent("skips creating existing documents (update)", async (ctx) => { expect(reporter).toHaveBeenCalledWith({ type: "documents:skipping", data: { - reason: "already exists", - current: 1, - remaining: 0, - total: 1, - document: migrationDocument, - }, - }) - expect(reporter).toHaveBeenCalledWith({ - type: "documents:created", - data: { - created: 0, - documents: expect.anything(), - }, - }) -}) - -it.concurrent("skips creating existing documents (auto)", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - const queryResponse = createPagedQueryResponses({ - ctx, - pages: 1, - pageSize: 1, - }) - const document = queryResponse[0].results[0] - - mockPrismicRestAPIV2({ ctx, queryResponse }) - mockPrismicAssetAPI({ ctx, client }) - mockPrismicMigrationAPI({ ctx, client, existingDocuments: [document] }) - - const migration = prismic.createMigration() - - const migrationDocument = migration.createDocument(document, "foo") - - const reporter = vi.fn() - - await client.migrate(migration, { reporter }) - - expect(reporter).toHaveBeenCalledWith({ - type: "documents:skipping", - data: { - reason: "already exists", + reason: "exists", current: 1, remaining: 0, total: 1, @@ -162,7 +121,7 @@ it.concurrent("skips creating existing documents (auto)", async (ctx) => { it.concurrent("creates new documents", async (ctx) => { const client = createTestWriteClient({ ctx }) - const document = ctx.mock.value.document() + const { id: _id, ...document } = ctx.mock.value.document() const newDocument = { id: "foo" } mockPrismicRestAPIV2({ ctx }) @@ -212,7 +171,7 @@ it.concurrent( }) const masterLanguageDocument = queryResponse[0].results[0] - const document = ctx.mock.value.document() + const { id: _id, ...document } = ctx.mock.value.document() const newDocument = { id: "foo", masterLanguageDocumentID: masterLanguageDocument.id, @@ -260,22 +219,19 @@ it.concurrent( async (ctx) => { const client = createTestWriteClient({ ctx }) - const masterLanguageDocument = - ctx.mock.value.document() as prismic.MigrationDocumentValue - const document = ctx.mock.value.document() as prismic.MigrationDocumentValue + const { id: masterLanguageDocumentID, ...masterLanguageDocument } = + ctx.mock.value.document() + const { id: documentID, ...document } = ctx.mock.value.document() const newDocuments = [ { - id: masterLanguageDocument.id!, + id: masterLanguageDocumentID, }, { - id: document.id!, - masterLanguageDocumentID: masterLanguageDocument.id!, + id: documentID, + masterLanguageDocumentID: masterLanguageDocumentID, }, ] - delete masterLanguageDocument.id - delete document.id - mockPrismicRestAPIV2({ ctx }) mockPrismicAssetAPI({ ctx, client }) mockPrismicMigrationAPI({ ctx, client, newDocuments: [...newDocuments] }) @@ -323,7 +279,7 @@ it.concurrent( }) const masterLanguageDocument = queryResponse[0].results[0] - const document = ctx.mock.value.document() + const { id: _id, ...document } = ctx.mock.value.document() const newDocument = { id: "foo", masterLanguageDocumentID: masterLanguageDocument.id, @@ -371,22 +327,19 @@ it.concurrent( async (ctx) => { const client = createTestWriteClient({ ctx }) - const masterLanguageDocument = - ctx.mock.value.document() as prismic.MigrationDocumentValue - const document = ctx.mock.value.document() as prismic.MigrationDocumentValue + const { id: masterLanguageDocumentID, ...masterLanguageDocument } = + ctx.mock.value.document() + const { id: documentID, ...document } = ctx.mock.value.document() const newDocuments = [ { - id: masterLanguageDocument.id!, + id: masterLanguageDocumentID, }, { - id: document.id!, - masterLanguageDocumentID: masterLanguageDocument.id!, + id: documentID, + masterLanguageDocumentID: masterLanguageDocumentID, }, ] - delete masterLanguageDocument.id - delete document.id - mockPrismicRestAPIV2({ ctx }) mockPrismicAssetAPI({ ctx, client }) mockPrismicMigrationAPI({ ctx, client, newDocuments: [...newDocuments] }) @@ -450,7 +403,10 @@ it.concurrent( const migration = prismic.createMigration() - const migrationDocument = migration.createDocument(document, "foo") + const migrationDocument = migration.createDocumentFromPrismic( + document, + "foo", + ) let documents: DocumentMap | undefined const reporter = vi.fn<(event: prismic.MigrateReporterEvents) => void>( @@ -482,15 +438,16 @@ it.concurrent("creates master locale documents first", async (ctx) => { const { repository, masterLocale } = createRepository(ctx) - const masterLanguageDocument = ctx.mock.value.document() + const { id: masterLanguageDocumentID, ...masterLanguageDocument } = + ctx.mock.value.document() masterLanguageDocument.lang = masterLocale - const document = ctx.mock.value.document() + const { id: documentID, ...document } = ctx.mock.value.document() const newDocuments = [ { - id: masterLanguageDocument.id, + id: masterLanguageDocumentID, }, { - id: document.id, + id: documentID, }, ] diff --git a/test/writeClient-migrate-patch-contentRelationship.test.ts b/test/writeClient-migrate-patch-contentRelationship.test.ts index 98713761..0bfc830d 100644 --- a/test/writeClient-migrate-patch-contentRelationship.test.ts +++ b/test/writeClient-migrate-patch-contentRelationship.test.ts @@ -6,37 +6,38 @@ testMigrationFieldPatching("patches link fields", { existing: ({ migration, existingDocuments }) => migration.createContentRelationship(existingDocuments[0]), migration: ({ migration, migrationDocuments }) => { - delete migrationDocuments[0].value.id + delete migrationDocuments.other.document.id - return migration.createContentRelationship(migrationDocuments[0]) + return migration.createContentRelationship(migrationDocuments.other) }, lazyExisting: ({ migration, existingDocuments }) => { return migration.createContentRelationship(() => existingDocuments[0]) }, lazyMigration: ({ migration, migrationDocuments }) => { - delete migrationDocuments[0].value.id + delete migrationDocuments.other.document.id return migration.createContentRelationship(() => migration.getByUID( - migrationDocuments[0].value.type, - migrationDocuments[0].value.uid!, + migrationDocuments.other.document.type, + migrationDocuments.other.document.uid!, ), ) }, migrationNoTags: ({ migration, migrationDocuments }) => { - migrationDocuments[0].value.tags = undefined + migrationDocuments.other.document.tags = undefined return migration.createContentRelationship(() => migration.getByUID( - migrationDocuments[0].value.type, - migrationDocuments[0].value.uid!, + migrationDocuments.other.document.type, + migrationDocuments.other.document.uid!, ), ) }, otherRepositoryContentRelationship: ({ ctx, migrationDocuments }) => { const contentRelationship = ctx.mock.value.link({ type: "Document" }) // `migrationDocuments` contains documents from "another repository" - contentRelationship.id = migrationDocuments[0].value.id! + contentRelationship.id = + migrationDocuments.otherRepository.originalPrismicDocument!.id return contentRelationship }, diff --git a/test/writeClient-migrate-patch-simpleField.test.ts b/test/writeClient-migrate-patch-simpleField.test.ts index d21619f3..0e6268cc 100644 --- a/test/writeClient-migrate-patch-simpleField.test.ts +++ b/test/writeClient-migrate-patch-simpleField.test.ts @@ -1,5 +1,7 @@ import { testMigrationFieldPatching } from "./__testutils__/testMigrationFieldPatching" +import { RichTextNodeType } from "../src" + testMigrationFieldPatching( "does not patch simple fields", { @@ -10,7 +12,9 @@ testMigrationFieldPatching( number: ({ ctx }) => ctx.mock.value.number({ state: "filled" }), keyText: ({ ctx }) => ctx.mock.value.keyText({ state: "filled" }), richTextSimple: ({ ctx }) => - ctx.mock.value.richText({ state: "filled", pattern: "long" }), + ctx.mock.value + .richText({ state: "filled", pattern: "long" }) + .filter((node) => node.type !== RichTextNodeType.image), select: ({ ctx }) => ctx.mock.value.select({ model: ctx.mock.model.select({ options: ["foo", "bar"] }), diff --git a/test/writeClient-migrate.test.ts b/test/writeClient-migrate.test.ts index 4d70c967..d9e024f9 100644 --- a/test/writeClient-migrate.test.ts +++ b/test/writeClient-migrate.test.ts @@ -37,13 +37,14 @@ it.concurrent("performs migration", async (ctx) => { const migration = prismic.createMigration() - const documentFoo: prismic.MigrationDocumentValue = ctx.mock.value.document() + const { id: _id, ...documentFoo } = + ctx.mock.value.document() as prismic.ExistingPrismicDocument documentFoo.data = { image: migration.createAsset("foo", "foo.png"), link: () => migration.getByUID("bar", "bar"), } - const documentBar = ctx.mock.value.document() + const { id: __id, ...documentBar } = ctx.mock.value.document() documentBar.type = "bar" documentBar.uid = "bar" @@ -66,8 +67,7 @@ it.concurrent("performs migration", async (ctx) => { expect(assets?.size).toBe(1) expect(assetsDatabase.flat()).toHaveLength(1) - // Documents are indexed twice, on ID, and on reference - expect(documents?.size).toBe(4) + expect(documents?.size).toBe(2) expect(Object.keys(documentsDatabase)).toHaveLength(2) expect(reporter).toHaveBeenCalledWith({ diff --git a/test/writeClient-updateDocument.test.ts b/test/writeClient-updateDocument.test.ts index 4ac07452..6e6ee357 100644 --- a/test/writeClient-updateDocument.test.ts +++ b/test/writeClient-updateDocument.test.ts @@ -107,6 +107,7 @@ it.skip("is abortable with an AbortController", async (ctx) => { client.updateDocument( document.id, { + ...document, uid: "uid", data: {}, }, @@ -135,6 +136,7 @@ it.concurrent("supports custom headers", async (ctx) => { client.updateDocument( document.id, { + ...document, uid: "uid", data: {}, }, From ed42798b91062d9998669d00a5eba00914503ce9 Mon Sep 17 00:00:00 2001 From: lihbr Date: Sun, 15 Sep 2024 21:33:46 +0200 Subject: [PATCH 07/13] refactor: remove documents and assets maps --- src/Migration.ts | 81 ++++--- src/WriteClient.ts | 210 ++++++------------ src/types/migration/Asset.ts | 46 ++-- src/types/migration/ContentRelationship.ts | 14 +- src/types/migration/Document.ts | 27 +-- src/types/migration/Field.ts | 31 +-- ...ate-patch-contentRelationship.test.ts.snap | 48 +++- test/migration-createAsset.test.ts | 18 +- test/migration-createDocument.test.ts | 8 +- test/migration-getByUID.test.ts | 6 +- test/migration-getSingle.test.ts | 4 +- test/writeClient-migrate-assets.test.ts | 59 ++--- test/writeClient-migrate-documents.test.ts | 149 +++---------- ...-migrate-patch-contentRelationship.test.ts | 4 +- test/writeClient-migrate.test.ts | 22 +- 15 files changed, 269 insertions(+), 458 deletions(-) diff --git a/src/Migration.ts b/src/Migration.ts index 303ca967..e7bba6e0 100644 --- a/src/Migration.ts +++ b/src/Migration.ts @@ -3,6 +3,7 @@ import { validateAssetMetadata } from "./lib/validateAssetMetadata" import type { Asset } from "./types/api/asset/asset" import type { MigrationAssetConfig } from "./types/migration/Asset" +import type { MigrationAsset } from "./types/migration/Asset" import { MigrationImage } from "./types/migration/Asset" import type { UnresolvedMigrationContentRelationshipConfig } from "./types/migration/ContentRelationship" import { MigrationContentRelationship } from "./types/migration/ContentRelationship" @@ -43,7 +44,7 @@ export class Migration { * * @internal */ - _assets: Map = new Map() + _assets: Map = new Map() /** * Documents registered in the migration. @@ -143,7 +144,7 @@ export class Migration { tags?: string[] } = {}, ): MigrationImage { - let asset: MigrationAssetConfig + let config: MigrationAssetConfig let maybeInitialField: FilledImageFieldImage | undefined if (typeof fileOrAssetOrField === "object" && "url" in fileOrAssetOrField) { if ( @@ -168,7 +169,7 @@ export class Migration { maybeInitialField = fileOrAssetOrField } - asset = { + config = { id: fileOrAssetOrField.id, file: url, filename, @@ -178,7 +179,7 @@ export class Migration { tags: undefined, } } else { - asset = { + config = { id: fileOrAssetOrField.id, file: fileOrAssetOrField.url, filename: fileOrAssetOrField.filename, @@ -189,7 +190,7 @@ export class Migration { } } } else { - asset = { + config = { id: fileOrAssetOrField, file: fileOrAssetOrField, filename: filename!, @@ -200,26 +201,24 @@ export class Migration { } } - validateAssetMetadata(asset) - - const maybeAsset = this._assets.get(asset.id) + validateAssetMetadata(config) + const migrationAsset = new MigrationImage(config, maybeInitialField) + const maybeAsset = this._assets.get(config.id) if (maybeAsset) { // Consolidate existing asset with new asset value if possible - this._assets.set(asset.id, { - ...maybeAsset, - notes: asset.notes || maybeAsset.notes, - credits: asset.credits || maybeAsset.credits, - alt: asset.alt || maybeAsset.alt, - tags: Array.from( - new Set([...(maybeAsset.tags || []), ...(asset.tags || [])]), - ), - }) + maybeAsset.config.notes = config.notes || maybeAsset.config.notes + maybeAsset.config.credits = config.credits || maybeAsset.config.credits + maybeAsset.config.alt = config.alt || maybeAsset.config.alt + maybeAsset.config.tags = Array.from( + new Set([...(config.tags || []), ...(maybeAsset.config.tags || [])]), + ) } else { - this._assets.set(asset.id, asset) + this._assets.set(config.id, migrationAsset) } - return new MigrationImage(this._assets.get(asset.id)!, maybeInitialField) + // We returned a detached instance of the asset to serialize it properly + return migrationAsset } /** @@ -251,13 +250,13 @@ export class Migration { this.createAsset.bind(this), ) - const migrationDocument = new PrismicMigrationDocument< + const doc = new PrismicMigrationDocument< ExtractDocumentType >({ ...document, data }, title, { ...options, dependencies }) - this._documents.push(migrationDocument) + this._documents.push(doc) - return migrationDocument + return doc } /** @@ -285,13 +284,13 @@ export class Migration { this.createAsset.bind(this), ) - const migrationDocument = new PrismicMigrationDocument< + const doc = new PrismicMigrationDocument< ExtractDocumentType >({ ...document, data }, title, { dependencies }) - this._documents.push(migrationDocument) + this._documents.push(doc) - return migrationDocument + return doc } /** @@ -318,7 +317,7 @@ export class Migration { this.createAsset.bind(this), ) - const migrationDocument = new PrismicMigrationDocument( + const doc = new PrismicMigrationDocument( { type: document.type, lang: document.lang, @@ -332,9 +331,9 @@ export class Migration { { originalPrismicDocument: document, dependencies }, ) - this._documents.push(migrationDocument) + this._documents.push(doc) - return migrationDocument + return doc } /** @@ -441,17 +440,17 @@ export class Migration { * @returns The migration document instance for the original ID, if a matching * document is found. */ - // getByOriginalID( - // id: string, - // ): - // | PrismicMigrationDocument> - // | undefined { - // return this._documents.find( - // ( - // doc, - // ): doc is PrismicMigrationDocument< - // ExtractDocumentType - // > => doc.originalPrismicDocument?.id === id, - // ) - // } + getByOriginalID( + id: string, + ): + | PrismicMigrationDocument> + | undefined { + return this._documents.find( + ( + doc, + ): doc is PrismicMigrationDocument< + ExtractDocumentType + > => doc.originalPrismicDocument?.id === id, + ) + } } diff --git a/src/WriteClient.ts b/src/WriteClient.ts index c46c6fd0..0759ab06 100644 --- a/src/WriteClient.ts +++ b/src/WriteClient.ts @@ -22,9 +22,8 @@ import { type PostDocumentResult, type PutDocumentParams, } from "./types/api/migration/document" -import type { AssetMap, MigrationAssetConfig } from "./types/migration/Asset" +import type { MigrationAsset } from "./types/migration/Asset" import type { - DocumentMap, MigrationDocument, PendingPrismicDocument, PrismicMigrationDocument, @@ -93,31 +92,20 @@ type MigrateReporterEventMap = { current: number remaining: number total: number - asset: MigrationAssetConfig + asset: MigrationAsset } "assets:creating": { current: number remaining: number total: number - asset: MigrationAssetConfig + asset: MigrationAsset } "assets:created": { created: number - assets: AssetMap } "documents:masterLocale": { masterLocale: string } - "documents:existing": { - existing: number - } - "documents:skipping": { - reason: string - current: number - remaining: number - total: number - document: PrismicMigrationDocument - } "documents:creating": { current: number remaining: number @@ -126,7 +114,6 @@ type MigrateReporterEventMap = { } "documents:created": { created: number - documents: DocumentMap } "documents:updating": { current: number @@ -338,11 +325,9 @@ export class WriteClient< }, }) - const assets = await this.migrateCreateAssets(migration, params) - - const documents = await this.migrateCreateDocuments(migration, params) - - await this.migrateUpdateDocuments(migration, assets, documents, params) + await this.migrateCreateAssets(migration, params) + await this.migrateCreateDocuments(migration, params) + await this.migrateUpdateDocuments(migration, params) params.reporter?.({ type: "end", @@ -361,8 +346,6 @@ export class WriteClient< * @param migration - A migration prepared with {@link createMigration}. * @param params - An event listener and additional fetch parameters. * - * @returns A map of assets available in the Prismic repository. - * * @internal This method is one of the step performed by the {@link migrate} method. */ private async migrateCreateAssets( @@ -371,8 +354,8 @@ export class WriteClient< reporter, ...fetchParams }: { reporter?: (event: MigrateReporterEvents) => void } & FetchParams = {}, - ): Promise { - const assets: AssetMap = new Map() + ): Promise { + const existingAssets = new Map() // Get all existing assets let getAssetsResult: GetAssetsReturnType | undefined = undefined @@ -387,14 +370,14 @@ export class WriteClient< } for (const asset of getAssetsResult.results) { - assets.set(asset.id, asset) + existingAssets.set(asset.id, asset) } } while (getAssetsResult?.next) reporter?.({ type: "assets:existing", data: { - existing: assets.size, + existing: existingAssets.size, }, }) @@ -402,10 +385,10 @@ export class WriteClient< let i = 0 let created = 0 for (const [_, migrationAsset] of migration._assets) { - if ( - typeof migrationAsset.id === "string" && - assets.has(migrationAsset.id) - ) { + if (existingAssets.has(migrationAsset.config.id)) { + migrationAsset.asset = existingAssets.get(migrationAsset.config.id) + + // Is this essential for deduplication? reporter?.({ type: "assets:skipping", data: { @@ -428,7 +411,8 @@ export class WriteClient< }, }) - const { id, file, filename, ...params } = migrationAsset + const { file, filename, notes, credits, alt, tags } = + migrationAsset.config let resolvedFile: PostAssetParams["file"] | File if (typeof file === "string") { @@ -436,18 +420,21 @@ export class WriteClient< try { url = new URL(file) } catch (error) { - // noop + // noop only on invalid URL, fetch errors will throw in the next if statement } if (url) { + // File is a URL, fetch it resolvedFile = await this.fetchForeignAsset( url.toString(), fetchParams, ) } else { + // File is actual file content, use it as-is resolvedFile = file } } else if (file instanceof URL) { + // File is a URL instance, fetch it resolvedFile = await this.fetchForeignAsset( file.toString(), fetchParams, @@ -457,11 +444,11 @@ export class WriteClient< } const asset = await this.createAsset(resolvedFile, filename, { - ...params, + ...{ notes, credits, alt, tags }, ...fetchParams, }) - assets.set(id, asset) + migrationAsset.asset = asset } } @@ -469,11 +456,8 @@ export class WriteClient< type: "assets:created", data: { created, - assets, }, }) - - return assets } /** @@ -482,8 +466,6 @@ export class WriteClient< * @param migration - A migration prepared with {@link createMigration}. * @param params - An event listener and additional fetch parameters. * - * @returns A map of documents available in the Prismic repository. - * * @internal This method is one of the step performed by the {@link migrate} method. */ private async migrateCreateDocuments( @@ -492,7 +474,7 @@ export class WriteClient< reporter, ...fetchParams }: { reporter?: (event: MigrateReporterEvents) => void } & FetchParams = {}, - ): Promise> { + ): Promise { // Resolve master locale const repository = await this.getRepository(fetchParams) const masterLocale = repository.languages.find((lang) => lang.is_master)!.id @@ -503,109 +485,62 @@ export class WriteClient< }, }) - // Get all existing documents - const existingDocuments = await this.dangerouslyGetAll(fetchParams) - reporter?.({ - type: "documents:existing", - data: { - existing: existingDocuments.length, - }, - }) - - const documents: DocumentMap = new Map() - for (const document of existingDocuments) { - // Index on document ID - documents.set(document.id, document) - } - - const sortedMigrationDocuments: PrismicMigrationDocument[] = [] - + const documentsToCreate: PrismicMigrationDocument[] = [] // We create an array with non-master locale documents last because // we need their master locale document to be created first. - for (const migrationDocument of migration._documents) { - if (migrationDocument.document.lang === masterLocale) { - sortedMigrationDocuments.unshift(migrationDocument) - } else { - sortedMigrationDocuments.push(migrationDocument) + for (const doc of migration._documents) { + if (!doc.document.id) { + if (doc.document.lang === masterLocale) { + documentsToCreate.unshift(doc) + } else { + documentsToCreate.push(doc) + } } } - let i = 0 let created = 0 - for (const migrationDocument of sortedMigrationDocuments) { - if (migrationDocument.document.id) { - reporter?.({ - type: "documents:skipping", - data: { - reason: "exists", - current: ++i, - remaining: sortedMigrationDocuments.length - i, - total: sortedMigrationDocuments.length, - document: migrationDocument, - }, - }) + for (const doc of documentsToCreate) { + reporter?.({ + type: "documents:creating", + data: { + current: ++created, + remaining: documentsToCreate.length - created, + total: documentsToCreate.length, + document: doc, + }, + }) - // Index the migration document - documents.set( - migrationDocument, - documents.get(migrationDocument.document.id)!, - ) - } else { - created++ - reporter?.({ - type: "documents:creating", - data: { - current: ++i, - remaining: sortedMigrationDocuments.length - i, - total: sortedMigrationDocuments.length, - document: migrationDocument, - }, - }) + // Resolve master language document ID for non-master locale documents + let masterLanguageDocumentID: string | undefined + if (doc.masterLanguageDocument) { + const link = doc.masterLanguageDocument + + await link._resolve(migration) + masterLanguageDocumentID = link._field?.id + } else if (doc.originalPrismicDocument) { + masterLanguageDocumentID = + doc.originalPrismicDocument.alternate_languages.find( + ({ lang }) => lang === masterLocale, + )?.id + } - // Resolve master language document ID for non-master locale documents - let masterLanguageDocumentID: string | undefined - if (migrationDocument.masterLanguageDocument) { - const link = migrationDocument.masterLanguageDocument - - await link._resolve({ documents, assets: new Map() }) - masterLanguageDocumentID = link._field?.id - } else if (migrationDocument.originalPrismicDocument) { - masterLanguageDocumentID = - migrationDocument.originalPrismicDocument.alternate_languages.find( - ({ lang }) => lang === masterLocale, - )?.id - } + const { id } = await this.createDocument( + // We'll upload docuements data later on. + { ...doc.document, data: {} }, + doc.title, + { + masterLanguageDocumentID, + ...fetchParams, + }, + ) - const { id } = await this.createDocument( - // We'll upload docuements data later on. - { ...migrationDocument.document, data: {} }, - migrationDocument.title, - { - masterLanguageDocumentID, - ...fetchParams, - }, - ) - - // Index old ID for Prismic to Prismic migration - if (migrationDocument.originalPrismicDocument) { - documents.set(migrationDocument.originalPrismicDocument.id, { - ...migrationDocument.document, - id, - }) - } - documents.set(migrationDocument, { ...migrationDocument.document, id }) - } + doc.document.id = id } reporter?.({ type: "documents:created", - data: { - created, - documents, - }, + data: { created }, }) - - return documents } /** @@ -613,41 +548,36 @@ export class WriteClient< * patched data. * * @param migration - A migration prepared with {@link createMigration}. - * @param assets - A map of assets available in the Prismic repository. - * @param documents - A map of documents available in the Prismic repository. * @param params - An event listener and additional fetch parameters. * * @internal This method is one of the step performed by the {@link migrate} method. */ private async migrateUpdateDocuments( migration: Migration, - assets: AssetMap, - documents: DocumentMap, { reporter, ...fetchParams }: { reporter?: (event: MigrateReporterEvents) => void } & FetchParams = {}, ): Promise { let i = 0 - for (const migrationDocument of migration._documents) { + for (const doc of migration._documents) { reporter?.({ type: "documents:updating", data: { current: ++i, remaining: migration._documents.length - i, total: migration._documents.length, - document: migrationDocument, + document: doc, }, }) - const { id } = documents.get(migrationDocument)! - await migrationDocument._resolve({ assets, documents }) + await doc._resolve(migration) await this.updateDocument( - id, + doc.document.id!, // We need to forward again document name and tags to update them // in case the document already existed during the previous step. - migrationDocument.document, + doc.document, fetchParams, ) } diff --git a/src/types/migration/Asset.ts b/src/types/migration/Asset.ts index 3ba70c93..62403de9 100644 --- a/src/types/migration/Asset.ts +++ b/src/types/migration/Asset.ts @@ -1,3 +1,5 @@ +import type { Migration } from "../../Migration" + import type { Asset } from "../api/asset/asset" import type { FilledImageFieldImage, ImageField } from "../value/image" import { type FilledLinkToWebField, LinkType } from "../value/link" @@ -5,7 +7,6 @@ import type { LinkToMediaField } from "../value/linkToMedia" import { type RTImageNode, RichTextNodeType } from "../value/richText" import type { MigrationContentRelationship } from "./ContentRelationship" -import type { ResolveArgs } from "./Field" import { MigrationField } from "./Field" /** @@ -62,9 +63,7 @@ const assetToImage = ( */ export type MigrationAssetConfig = { /** - * ID of the asset used to reference it in Prismic documents. - * - * @internal + * ID the assets is indexed with on the migration instance. */ id: string | URL | File | NonNullable[0]>[0] @@ -116,7 +115,12 @@ export abstract class MigrationAsset< * * @internal */ - _config: MigrationAssetConfig + config: MigrationAssetConfig + + /** + * Asset object from Prismic available once created. + */ + asset?: Asset /** * Creates a migration asset used with the Prismic Migration API. @@ -129,7 +133,7 @@ export abstract class MigrationAsset< constructor(config: MigrationAssetConfig, initialField?: ImageLike) { super(initialField) - this._config = config + this.config = config } /** @@ -138,7 +142,7 @@ export abstract class MigrationAsset< * @returns A migration image instance. */ asImage(): MigrationImage { - return new MigrationImage(this._config, this._initialField) + return new MigrationImage(this.config, this._initialField) } /** @@ -150,7 +154,7 @@ export abstract class MigrationAsset< * @returns A migration link to media instance. */ asLinkToMedia(text?: string): MigrationLinkToMedia { - return new MigrationLinkToMedia(this._config, text, this._initialField) + return new MigrationLinkToMedia(this.config, text, this._initialField) } /** @@ -167,7 +171,7 @@ export abstract class MigrationAsset< | MigrationContentRelationship | FilledLinkToWebField, ): MigrationRTImageNode { - return new MigrationRTImageNode(this._config, linkTo, this._initialField) + return new MigrationRTImageNode(this.config, linkTo, this._initialField) } } @@ -194,14 +198,14 @@ export class MigrationImage extends MigrationAsset { return this } - async _resolve({ assets, documents }: ResolveArgs): Promise { - const asset = assets.get(this._config.id) + async _resolve(migration: Migration): Promise { + const asset = migration._assets.get(this.config.id)?.asset if (asset) { this._field = assetToImage(asset, this._initialField) for (const name in this.#thumbnails) { - await this.#thumbnails[name]._resolve({ assets, documents }) + await this.#thumbnails[name]._resolve(migration) const thumbnail = this.#thumbnails[name]._field if (thumbnail) { @@ -243,8 +247,8 @@ export class MigrationLinkToMedia extends MigrationAsset< this.text = text } - _resolve({ assets }: ResolveArgs): void { - const asset = assets.get(this._config.id) + _resolve(migration: Migration): void { + const asset = migration._assets.get(this.config.id)?.asset if (asset) { this._field = { @@ -300,11 +304,11 @@ export class MigrationRTImageNode extends MigrationAsset { this.linkTo = linkTo } - async _resolve({ assets, documents }: ResolveArgs): Promise { - const asset = assets.get(this._config.id) + async _resolve(migration: Migration): Promise { + const asset = migration._assets.get(this.config.id)?.asset if (this.linkTo instanceof MigrationField) { - await this.linkTo._resolve({ assets, documents }) + await this.linkTo._resolve(migration) } if (asset) { @@ -319,11 +323,3 @@ export class MigrationRTImageNode extends MigrationAsset { } } } - -/** - * A map of asset IDs to asset used to resolve assets when patching migration - * Prismic documents. - * - * @internal - */ -export type AssetMap = Map diff --git a/src/types/migration/ContentRelationship.ts b/src/types/migration/ContentRelationship.ts index 33abf26a..b3357da7 100644 --- a/src/types/migration/ContentRelationship.ts +++ b/src/types/migration/ContentRelationship.ts @@ -1,9 +1,10 @@ +import type { Migration } from "../../Migration" + import type { FilledContentRelationshipField } from "../value/contentRelationship" import type { PrismicDocument } from "../value/document" import { LinkType } from "../value/link" -import type { PrismicMigrationDocument } from "./Document" -import type { ResolveArgs } from "./Field" +import { PrismicMigrationDocument } from "./Document" import { MigrationField } from "./Field" /** @@ -67,7 +68,7 @@ export class MigrationContentRelationship extends MigrationField { + async _resolve(migration: Migration): Promise { const config = typeof this.#unresolvedConfig === "function" ? await this.#unresolvedConfig() @@ -75,9 +76,12 @@ export class MigrationContentRelationship extends MigrationField { + async _resolve(migration: Migration): Promise { for (const dependency of this.#dependencies) { - await dependency._resolve(args) + await dependency._resolve(migration) } } } - -/** - * A map of document IDs, documents, and migration documents to content - * relationship field used to resolve content relationships when patching - * migration Prismic documents. - * - * @typeParam TDocuments - Type of Prismic documents in the repository. - * - * @internal - */ -export type DocumentMap = - Map< - string | PrismicMigrationDocument, - PrismicDocument | (MigrationDocument & Pick) - > diff --git a/src/types/migration/Field.ts b/src/types/migration/Field.ts index 0f559a01..2c098747 100644 --- a/src/types/migration/Field.ts +++ b/src/types/migration/Field.ts @@ -1,27 +1,8 @@ import type { AnyRegularField } from "../value/types" -import type { RTBlockNode, RTInlineNode } from "../value/richText" - -import type { AssetMap } from "./Asset" -import type { DocumentMap } from "./Document" +import type { Migration } from "../../Migration" -/** - * Arguments passed to the `_resolve` method of a migration field. - */ -export type ResolveArgs = { - /** - * A map of asset IDs to asset used to resolve assets when patching migration - * Prismic documents. - */ - assets: AssetMap - - /** - * A map of document IDs, documents, and migration documents to content - * relationship field used to resolve content relationships when patching - * migration Prismic documents. - */ - documents: DocumentMap -} +import type { RTBlockNode, RTInlineNode } from "../value/richText" /** * Interface for migration fields that can be resolved. @@ -30,12 +11,12 @@ interface Resolvable { /** * Resolves the field's value with the provided maps. * - * @param args - A map of documents and a map of assets to resolve content - * with. + * @param migration - A migration instance with documents and assets to use + * for resolving the field's value * * @internal */ - _resolve(args: ResolveArgs): Promise | void + _resolve(migration: Migration): Promise | void } /** @@ -88,5 +69,5 @@ export abstract class MigrationField< return this._field } - abstract _resolve(args: ResolveArgs): Promise | void + abstract _resolve(migration: Migration): Promise | void } diff --git a/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap index c15c15c2..01048f6a 100644 --- a/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap @@ -3,7 +3,12 @@ exports[`patches link fields > brokenLink > group 1`] = ` { "group": [ - {}, + { + "field": { + "isBroken": true, + "type": "Document", + }, + }, ], } `; @@ -14,11 +19,25 @@ exports[`patches link fields > brokenLink > shared slice 1`] = ` { "id": "b9dd0f2c3f8", "items": [ - {}, + { + "field": { + "isBroken": true, + "type": "Document", + }, + }, ], "primary": { + "field": { + "isBroken": true, + "type": "Document", + }, "group": [ - {}, + { + "field": { + "isBroken": true, + "type": "Document", + }, + }, ], }, "slice_label": null, @@ -36,9 +55,19 @@ exports[`patches link fields > brokenLink > slice 1`] = ` { "id": "306297c5eda", "items": [ - {}, + { + "field": { + "isBroken": true, + "type": "Document", + }, + }, ], - "primary": {}, + "primary": { + "field": { + "isBroken": true, + "type": "Document", + }, + }, "slice_label": "Aliquet", "slice_type": "vel", }, @@ -46,7 +75,14 @@ exports[`patches link fields > brokenLink > slice 1`] = ` } `; -exports[`patches link fields > brokenLink > static zone 1`] = `{}`; +exports[`patches link fields > brokenLink > static zone 1`] = ` +{ + "field": { + "isBroken": true, + "type": "Document", + }, +} +`; exports[`patches link fields > existing > group 1`] = ` { diff --git a/test/migration-createAsset.test.ts b/test/migration-createAsset.test.ts index ce3749e5..b6c57773 100644 --- a/test/migration-createAsset.test.ts +++ b/test/migration-createAsset.test.ts @@ -17,7 +17,7 @@ it("creates an asset from a url", () => { migration.createAsset(file, filename) - expect(migration._assets.get(file)).toEqual({ + expect(migration._assets.get(file)?.config).toEqual({ id: file, file, filename, @@ -32,7 +32,7 @@ it("creates an asset from a file", () => { migration.createAsset(file, filename) - expect(migration._assets.get(file)).toEqual({ + expect(migration._assets.get(file)?.config).toEqual({ id: file, file, filename, @@ -69,7 +69,7 @@ it("creates an asset from an existing asset", () => { migration.createAsset(asset) - expect(migration._assets.get(asset.id)).toStrictEqual({ + expect(migration._assets.get(asset.id)?.config).toStrictEqual({ id: asset.id, file: asset.url, filename: asset.filename, @@ -94,7 +94,7 @@ it("creates an asset from an image field", () => { migration.createAsset(image) - expect(migration._assets.get(image.id)).toEqual({ + expect(migration._assets.get(image.id)?.config).toEqual({ id: image.id, file: image.url, filename: image.url.split("/").pop(), @@ -119,7 +119,7 @@ it("creates an asset from a link to media field", () => { migration.createAsset(link) - expect(migration._assets.get(link.id)).toEqual({ + expect(migration._assets.get(link.id)?.config).toEqual({ id: link.id, file: link.url, filename: link.name, @@ -169,7 +169,7 @@ it("consolidates existing assets with additional metadata", () => { migration.createAsset(file, filename) - expect(migration._assets.get(file)).toStrictEqual({ + expect(migration._assets.get(file)?.config).toStrictEqual({ id: file, file, filename, @@ -186,7 +186,7 @@ it("consolidates existing assets with additional metadata", () => { tags: ["tag"], }) - expect(migration._assets.get(file)).toStrictEqual({ + expect(migration._assets.get(file)?.config).toStrictEqual({ id: file, file, filename, @@ -203,7 +203,7 @@ it("consolidates existing assets with additional metadata", () => { tags: ["tag", "tag 2"], }) - expect(migration._assets.get(file)).toStrictEqual({ + expect(migration._assets.get(file)?.config).toStrictEqual({ id: file, file, filename, @@ -215,7 +215,7 @@ it("consolidates existing assets with additional metadata", () => { migration.createAsset(file, filename) - expect(migration._assets.get(file)).toStrictEqual({ + expect(migration._assets.get(file)?.config).toStrictEqual({ id: file, file, filename, diff --git a/test/migration-createDocument.test.ts b/test/migration-createDocument.test.ts index 7affcaca..796d48ad 100644 --- a/test/migration-createDocument.test.ts +++ b/test/migration-createDocument.test.ts @@ -196,7 +196,7 @@ describe.each<{ migration.createDocument(document, documentTitle) - expect(migration._assets.get(id)).toStrictEqual(expected) + expect(migration._assets.get(id)?.config).toStrictEqual(expected) }) it("group fields", ({ mock }) => { @@ -216,7 +216,7 @@ describe.each<{ migration.createDocument(document, documentTitle) - expect(migration._assets.get(id)).toStrictEqual(expected) + expect(migration._assets.get(id)?.config).toStrictEqual(expected) }) it("slice's primary zone", ({ mock }) => { @@ -246,7 +246,7 @@ describe.each<{ migration.createDocument(document, documentTitle) - expect(migration._assets.get(id)).toStrictEqual(expected) + expect(migration._assets.get(id)?.config).toStrictEqual(expected) }) it("slice's repeatable zone", ({ mock }) => { @@ -276,6 +276,6 @@ describe.each<{ migration.createDocument(document, documentTitle) - expect(migration._assets.get(id)).toStrictEqual(expected) + expect(migration._assets.get(id)?.config).toStrictEqual(expected) }) }) diff --git a/test/migration-getByUID.test.ts b/test/migration-getByUID.test.ts index 496e7b22..e60ad352 100644 --- a/test/migration-getByUID.test.ts +++ b/test/migration-getByUID.test.ts @@ -13,11 +13,9 @@ it("returns a document with a matching UID", () => { } const documentName = "documentName" - const migrationDocument = migration.createDocument(document, documentName) + const doc = migration.createDocument(document, documentName) - expect(migration.getByUID(document.type, document.uid)).toStrictEqual( - migrationDocument, - ) + expect(migration.getByUID(document.type, document.uid)).toStrictEqual(doc) }) it("returns `undefined` if a document is not found", () => { diff --git a/test/migration-getSingle.test.ts b/test/migration-getSingle.test.ts index 4dbcc129..ff173cb5 100644 --- a/test/migration-getSingle.test.ts +++ b/test/migration-getSingle.test.ts @@ -12,9 +12,9 @@ it("returns a document of a given singleton type", () => { } const documentName = "documentName" - const migrationDocument = migration.createDocument(document, documentName) + const doc = migration.createDocument(document, documentName) - expect(migration.getSingle(document.type)).toStrictEqual(migrationDocument) + expect(migration.getSingle(document.type)).toStrictEqual(doc) }) it("returns `undefined` if a document is not found", () => { diff --git a/test/writeClient-migrate-assets.test.ts b/test/writeClient-migrate-assets.test.ts index 298fe6e5..5c9ed198 100644 --- a/test/writeClient-migrate-assets.test.ts +++ b/test/writeClient-migrate-assets.test.ts @@ -76,7 +76,7 @@ it.concurrent("skips creating existing assets", async (ctx) => { const migration = prismic.createMigration() const asset = assetsDatabase[0][0] - migration.createAsset(asset) + const migrationAsset = migration.createAsset(asset) const reporter = vi.fn() @@ -89,7 +89,7 @@ it.concurrent("skips creating existing assets", async (ctx) => { current: 1, remaining: 0, total: 1, - asset: expect.objectContaining({ id: asset.id, file: asset.url }), + asset: migrationAsset, }, }) }) @@ -109,7 +109,7 @@ it.concurrent("creates new asset from string file data", async (ctx) => { mockPrismicMigrationAPI({ ctx, client }) const migration = prismic.createMigration() - migration.createAsset(dummyFileData, asset.filename) + const migrationAsset = migration.createAsset(dummyFileData, asset.filename) const reporter = vi.fn() @@ -123,10 +123,7 @@ it.concurrent("creates new asset from string file data", async (ctx) => { current: 1, remaining: 0, total: 1, - asset: expect.objectContaining({ - file: dummyFileData, - filename: asset.filename, - }), + asset: migrationAsset, }, }) expect(assetsDatabase.flat()).toHaveLength(1) @@ -147,7 +144,7 @@ it.concurrent("creates new asset from a File instance", async (ctx) => { mockPrismicMigrationAPI({ ctx, client }) const migration = prismic.createMigration() - migration.createAsset(dummyFile, asset.filename) + const migrationAsset = migration.createAsset(dummyFile, asset.filename) const reporter = vi.fn() @@ -161,10 +158,7 @@ it.concurrent("creates new asset from a File instance", async (ctx) => { current: 1, remaining: 0, total: 1, - asset: expect.objectContaining({ - file: dummyFile, - filename: asset.filename, - }), + asset: migrationAsset, }, }) expect(assetsDatabase.flat()).toHaveLength(1) @@ -192,7 +186,10 @@ it.concurrent( ) const migration = prismic.createMigration() - migration.createAsset(new URL(asset.url), asset.filename) + const migrationAsset = migration.createAsset( + new URL(asset.url), + asset.filename, + ) const reporter = vi.fn() @@ -206,10 +203,7 @@ it.concurrent( current: 1, remaining: 0, total: 1, - asset: expect.objectContaining({ - file: new URL(asset.url), - filename: asset.filename, - }), + asset: migrationAsset, }, }) expect(assetsDatabase.flat()).toHaveLength(1) @@ -238,7 +232,7 @@ it.concurrent( ) const migration = prismic.createMigration() - migration.createAsset(asset.url, asset.filename) + const migrationAsset = migration.createAsset(asset.url, asset.filename) const reporter = vi.fn() @@ -252,10 +246,7 @@ it.concurrent( current: 1, remaining: 0, total: 1, - asset: expect.objectContaining({ - file: asset.url, - filename: asset.filename, - }), + asset: migrationAsset, }, }) expect(assetsDatabase.flat()).toHaveLength(1) @@ -284,7 +275,10 @@ it.concurrent( ) const migration = prismic.createMigration() - migration.createAsset(new URL(asset.url), asset.filename) + const migrationAsset = migration.createAsset( + new URL(asset.url), + asset.filename, + ) const reporter = vi.fn() @@ -298,10 +292,7 @@ it.concurrent( current: 1, remaining: 0, total: 1, - asset: expect.objectContaining({ - file: new URL(asset.url), - filename: asset.filename, - }), + asset: migrationAsset, }, }) expect(assetsDatabase.flat()).toHaveLength(1) @@ -330,7 +321,7 @@ it.concurrent( ) const migration = prismic.createMigration() - migration.createAsset(asset.url, asset.filename) + const migrationAsset = migration.createAsset(asset.url, asset.filename) const reporter = vi.fn() @@ -344,10 +335,7 @@ it.concurrent( current: 1, remaining: 0, total: 1, - asset: expect.objectContaining({ - file: asset.url, - filename: asset.filename, - }), + asset: migrationAsset, }, }) expect(assetsDatabase.flat()).toHaveLength(1) @@ -418,7 +406,7 @@ it.concurrent( ) const migration = prismic.createMigration() - migration.createAsset(asset.url, asset.filename) + const migrationAsset = migration.createAsset(asset.url, asset.filename) const reporter = vi.fn() @@ -432,10 +420,7 @@ it.concurrent( current: 1, remaining: 0, total: 1, - asset: expect.objectContaining({ - file: asset.url, - filename: asset.filename, - }), + asset: migrationAsset, }, }) }, diff --git a/test/writeClient-migrate-documents.test.ts b/test/writeClient-migrate-documents.test.ts index 73e25803..8d10f287 100644 --- a/test/writeClient-migrate-documents.test.ts +++ b/test/writeClient-migrate-documents.test.ts @@ -8,7 +8,6 @@ import { mockPrismicMigrationAPI } from "./__testutils__/mockPrismicMigrationAPI import { mockPrismicRestAPIV2 } from "./__testutils__/mockPrismicRestAPIV2" import * as prismic from "../src" -import type { DocumentMap } from "../src/types/migration/Document" // Skip test on Node 16 and 18 (File and FormData support) const isNode16 = process.version.startsWith("v16") @@ -50,33 +49,6 @@ it.concurrent("infers master locale", async (ctx) => { }) }) -it.concurrent("discovers existing documents", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - const queryResponse = createPagedQueryResponses({ - ctx, - pages: 2, - pageSize: 1, - }) - - mockPrismicRestAPIV2({ ctx, queryResponse }) - mockPrismicAssetAPI({ ctx, client }) - mockPrismicMigrationAPI({ ctx, client }) - - const migration = prismic.createMigration() - - const reporter = vi.fn() - - await client.migrate(migration, { reporter }) - - expect(reporter).toHaveBeenCalledWith({ - type: "documents:existing", - data: { - existing: 2, - }, - }) -}) - it.concurrent("skips creating existing documents", async (ctx) => { const client = createTestWriteClient({ ctx }) @@ -93,27 +65,16 @@ it.concurrent("skips creating existing documents", async (ctx) => { const migration = prismic.createMigration() - const migrationDocument = migration.updateDocument(document, "foo") + migration.updateDocument(document, "foo") const reporter = vi.fn() await client.migrate(migration, { reporter }) - expect(reporter).toHaveBeenCalledWith({ - type: "documents:skipping", - data: { - reason: "exists", - current: 1, - remaining: 0, - total: 1, - document: migrationDocument, - }, - }) expect(reporter).toHaveBeenCalledWith({ type: "documents:created", data: { created: 0, - documents: expect.anything(), }, }) }) @@ -134,16 +95,9 @@ it.concurrent("creates new documents", async (ctx) => { const migration = prismic.createMigration() - const migrationDocument = migration.createDocument(document, "foo") + const doc = migration.createDocument(document, "foo") - let documents: DocumentMap | undefined - const reporter = vi.fn<(event: prismic.MigrateReporterEvents) => void>( - (event) => { - if (event.type === "documents:created") { - documents = event.data.documents - } - }, - ) + const reporter = vi.fn() await client.migrate(migration, { reporter }) @@ -153,10 +107,10 @@ it.concurrent("creates new documents", async (ctx) => { current: 1, remaining: 0, total: 1, - document: migrationDocument, + document: doc, }, }) - expect(documents?.get(migrationDocument)?.id).toBe(newDocument.id) + expect(doc.document.id).toBe(newDocument.id) }) it.concurrent( @@ -183,20 +137,13 @@ it.concurrent( const migration = prismic.createMigration() - const migrationDocument = migration.createDocument(document, "foo", { + const doc = migration.createDocument(document, "foo", { masterLanguageDocument: migration.createContentRelationship( masterLanguageDocument, ), }) - let documents: DocumentMap | undefined - const reporter = vi.fn<(event: prismic.MigrateReporterEvents) => void>( - (event) => { - if (event.type === "documents:created") { - documents = event.data.documents - } - }, - ) + const reporter = vi.fn() await client.migrate(migration, { reporter }) @@ -206,10 +153,10 @@ it.concurrent( current: 1, remaining: 0, total: 1, - document: migrationDocument, + document: doc, }, }) - ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocument.id) + ctx.expect(migration._documents[0].document.id).toBe(newDocument.id) ctx.expect.assertions(3) }, ) @@ -242,27 +189,20 @@ it.concurrent( masterLanguageDocument, "foo", ) - const migrationDocument = migration.createDocument(document, "bar", { + const doc = migration.createDocument(document, "bar", { masterLanguageDocument: migration.createContentRelationship( masterLanguageMigrationDocument, ), }) - let documents: DocumentMap | undefined - const reporter = vi.fn<(event: prismic.MigrateReporterEvents) => void>( - (event) => { - if (event.type === "documents:created") { - documents = event.data.documents - } - }, - ) + const reporter = vi.fn() await client.migrate(migration, { reporter }) ctx - .expect(documents?.get(masterLanguageMigrationDocument)?.id) + .expect(masterLanguageMigrationDocument.document.id) .toBe(newDocuments[0].id) - ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocuments[1].id) + ctx.expect(doc.document.id).toBe(newDocuments[1].id) ctx.expect.assertions(3) }, ) @@ -291,20 +231,13 @@ it.concurrent( const migration = prismic.createMigration() - const migrationDocument = migration.createDocument(document, "foo", { + const doc = migration.createDocument(document, "foo", { masterLanguageDocument: migration.createContentRelationship( () => masterLanguageDocument, ), }) - let documents: DocumentMap | undefined - const reporter = vi.fn<(event: prismic.MigrateReporterEvents) => void>( - (event) => { - if (event.type === "documents:created") { - documents = event.data.documents - } - }, - ) + const reporter = vi.fn() await client.migrate(migration, { reporter }) @@ -314,10 +247,10 @@ it.concurrent( current: 1, remaining: 0, total: 1, - document: migrationDocument, + document: doc, }, }) - ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocument.id) + ctx.expect(doc.document.id).toBe(newDocument.id) ctx.expect.assertions(3) }, ) @@ -350,27 +283,20 @@ it.concurrent( masterLanguageDocument, "foo", ) - const migrationDocument = migration.createDocument(document, "bar", { + const doc = migration.createDocument(document, "bar", { masterLanguageDocument: migration.createContentRelationship( () => masterLanguageMigrationDocument, ), }) - let documents: DocumentMap | undefined - const reporter = vi.fn<(event: prismic.MigrateReporterEvents) => void>( - (event) => { - if (event.type === "documents:created") { - documents = event.data.documents - } - }, - ) + const reporter = vi.fn() await client.migrate(migration, { reporter }) ctx - .expect(documents?.get(masterLanguageMigrationDocument)?.id) + .expect(masterLanguageMigrationDocument.document.id) .toBe(newDocuments[0].id) - ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocuments[1].id) + ctx.expect(doc.document.id).toBe(newDocuments[1].id) ctx.expect.assertions(3) }, ) @@ -403,19 +329,9 @@ it.concurrent( const migration = prismic.createMigration() - const migrationDocument = migration.createDocumentFromPrismic( - document, - "foo", - ) + const doc = migration.createDocumentFromPrismic(document, "foo") - let documents: DocumentMap | undefined - const reporter = vi.fn<(event: prismic.MigrateReporterEvents) => void>( - (event) => { - if (event.type === "documents:created") { - documents = event.data.documents - } - }, - ) + const reporter = vi.fn() await client.migrate(migration, { reporter }) @@ -425,10 +341,10 @@ it.concurrent( current: 1, remaining: 0, total: 1, - document: migrationDocument, + document: doc, }, }) - ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocument.id) + ctx.expect(doc.document.id).toBe(newDocument.id) ctx.expect.assertions(3) }, ) @@ -457,25 +373,18 @@ it.concurrent("creates master locale documents first", async (ctx) => { const migration = prismic.createMigration() - const migrationDocument = migration.createDocument(document, "bar") + const doc = migration.createDocument(document, "bar") const masterLanguageMigrationDocument = migration.createDocument( masterLanguageDocument, "foo", ) - let documents: DocumentMap | undefined - const reporter = vi.fn<(event: prismic.MigrateReporterEvents) => void>( - (event) => { - if (event.type === "documents:created") { - documents = event.data.documents - } - }, - ) + const reporter = vi.fn() await client.migrate(migration, { reporter }) ctx - .expect(documents?.get(masterLanguageMigrationDocument)?.id) + .expect(masterLanguageMigrationDocument.document.id) .toBe(newDocuments[0].id) - ctx.expect(documents?.get(migrationDocument)?.id).toBe(newDocuments[1].id) + ctx.expect(doc.document.id).toBe(newDocuments[1].id) }) diff --git a/test/writeClient-migrate-patch-contentRelationship.test.ts b/test/writeClient-migrate-patch-contentRelationship.test.ts index 0bfc830d..73a5def5 100644 --- a/test/writeClient-migrate-patch-contentRelationship.test.ts +++ b/test/writeClient-migrate-patch-contentRelationship.test.ts @@ -41,7 +41,9 @@ testMigrationFieldPatching("patches link fields", { return contentRelationship }, - brokenLink: ({ ctx }) => ctx.mock.value.link({ type: "Document" }), + brokenLink: () => { + return { type: "Document", isBroken: true } + }, richTextLinkNode: ({ migration, existingDocuments }) => [ { type: RichTextNodeType.paragraph, diff --git a/test/writeClient-migrate.test.ts b/test/writeClient-migrate.test.ts index d9e024f9..660aafdf 100644 --- a/test/writeClient-migrate.test.ts +++ b/test/writeClient-migrate.test.ts @@ -9,8 +9,6 @@ import { mockPrismicMigrationAPI } from "./__testutils__/mockPrismicMigrationAPI import { mockPrismicRestAPIV2 } from "./__testutils__/mockPrismicRestAPIV2" import * as prismic from "../src" -import type { AssetMap } from "../src/types/migration/Asset" -import type { DocumentMap } from "../src/types/migration/Document" // Skip test on Node 16 and 18 (File and FormData support) const isNode16 = process.version.startsWith("v16") @@ -51,23 +49,13 @@ it.concurrent("performs migration", async (ctx) => { migration.createDocument(documentFoo, "foo") migration.createDocument(documentBar, "bar") - let documents: DocumentMap | undefined - let assets: AssetMap | undefined - const reporter = vi.fn<(event: prismic.MigrateReporterEvents) => void>( - (event) => { - if (event.type === "assets:created") { - assets = event.data.assets - } else if (event.type === "documents:created") { - documents = event.data.documents - } - }, - ) + const reporter = vi.fn() await client.migrate(migration, { reporter }) - expect(assets?.size).toBe(1) + expect(migration._assets?.size).toBe(1) expect(assetsDatabase.flat()).toHaveLength(1) - expect(documents?.size).toBe(2) + expect(migration._documents.length).toBe(2) expect(Object.keys(documentsDatabase)).toHaveLength(2) expect(reporter).toHaveBeenCalledWith({ @@ -84,7 +72,6 @@ it.concurrent("performs migration", async (ctx) => { type: "assets:created", data: { created: 1, - assets: expect.any(Map), }, }) @@ -92,7 +79,6 @@ it.concurrent("performs migration", async (ctx) => { type: "documents:created", data: { created: 2, - documents: expect.any(Map), }, }) @@ -142,7 +128,6 @@ it.concurrent("migrates nothing when migration is empty", async (ctx) => { type: "assets:created", data: { created: 0, - assets: expect.any(Map), }, }) @@ -150,7 +135,6 @@ it.concurrent("migrates nothing when migration is empty", async (ctx) => { type: "documents:created", data: { created: 0, - documents: expect.any(Map), }, }) From 54056ef80e701d1abecb0352fb786453cbc4905e Mon Sep 17 00:00:00 2001 From: lihbr Date: Sun, 15 Sep 2024 22:21:14 +0200 Subject: [PATCH 08/13] refactor: remove existing assets querying --- src/Migration.ts | 1 + src/WriteClient.ts | 288 +++-------------- src/lib/prepareMigrationDocumentData.ts | 16 +- src/types/migration/Asset.ts | 44 ++- .../testMigrationFieldPatching.ts | 12 +- test/migration-createDocument.test.ts | 261 +--------------- ...igration-createDocumentFromPrismic.test.ts | 256 +++++++++++++++ test/writeClient-getAssets.test.ts | 295 ------------------ test/writeClient-migrate-assets.test.ts | 77 ----- ...-migrate-patch-contentRelationship.test.ts | 23 +- test/writeClient-migrate-patch-image.test.ts | 102 +++--- ...teClient-migrate-patch-linkToMedia.test.ts | 71 +++-- ...teClient-migrate-patch-rtImageNode.test.ts | 57 ++-- 13 files changed, 489 insertions(+), 1014 deletions(-) create mode 100644 test/migration-createDocumentFromPrismic.test.ts delete mode 100644 test/writeClient-getAssets.test.ts diff --git a/src/Migration.ts b/src/Migration.ts index e7bba6e0..0fe7d838 100644 --- a/src/Migration.ts +++ b/src/Migration.ts @@ -315,6 +315,7 @@ export class Migration { const { record: data, dependencies } = prepareMigrationDocumentData( document.data, this.createAsset.bind(this), + true, ) const doc = new PrismicMigrationDocument( diff --git a/src/WriteClient.ts b/src/WriteClient.ts index 0759ab06..d1c46adc 100644 --- a/src/WriteClient.ts +++ b/src/WriteClient.ts @@ -3,8 +3,6 @@ import { pLimit } from "./lib/pLimit" import type { Asset, - GetAssetsParams, - GetAssetsResult, PatchAssetParams, PatchAssetResult, PostAssetParams, @@ -84,16 +82,6 @@ type MigrateReporterEventMap = { assets: number } } - "assets:existing": { - existing: number - } - "assets:skipping": { - reason: string - current: number - remaining: number - total: number - asset: MigrationAsset - } "assets:creating": { current: number remaining: number @@ -142,32 +130,6 @@ export type MigrateReporterEvents = { > }[MigrateReporterEventTypes] -/** - * A query response from the Prismic Asset API. The response contains pagination - * metadata and a list of matching results for the query. - */ -type GetAssetsReturnType = { - /** - * Found assets for the query. - */ - results: Asset[] - - /** - * Total number of assets found for the query. - */ - total_results_size: number - - /** - * IDs of assets that were not found when filtering by IDs. - */ - missing_ids?: string[] - - /** - * A function to fectch the next page of assets if available. - */ - next?: () => Promise -} - /** * Additional parameters for creating an asset in the Prismic media library. */ @@ -355,101 +317,56 @@ export class WriteClient< ...fetchParams }: { reporter?: (event: MigrateReporterEvents) => void } & FetchParams = {}, ): Promise { - const existingAssets = new Map() - - // Get all existing assets - let getAssetsResult: GetAssetsReturnType | undefined = undefined - do { - if (getAssetsResult) { - getAssetsResult = await getAssetsResult.next!() - } else { - getAssetsResult = await this.getAssets({ - pageSize: 100, - ...fetchParams, - }) - } + let created = 0 + for (const [_, migrationAsset] of migration._assets) { + reporter?.({ + type: "assets:creating", + data: { + current: ++created, + remaining: migration._assets.size - created, + total: migration._assets.size, + asset: migrationAsset, + }, + }) - for (const asset of getAssetsResult.results) { - existingAssets.set(asset.id, asset) - } - } while (getAssetsResult?.next) + const { file, filename, notes, credits, alt, tags } = + migrationAsset.config - reporter?.({ - type: "assets:existing", - data: { - existing: existingAssets.size, - }, - }) + let resolvedFile: PostAssetParams["file"] | File + if (typeof file === "string") { + let url: URL | undefined + try { + url = new URL(file) + } catch (error) { + // noop only on invalid URL, fetch errors will throw in the next if statement + } - // Create assets - let i = 0 - let created = 0 - for (const [_, migrationAsset] of migration._assets) { - if (existingAssets.has(migrationAsset.config.id)) { - migrationAsset.asset = existingAssets.get(migrationAsset.config.id) - - // Is this essential for deduplication? - reporter?.({ - type: "assets:skipping", - data: { - reason: "already exists", - current: ++i, - remaining: migration._assets.size - i, - total: migration._assets.size, - asset: migrationAsset, - }, - }) - } else { - created++ - reporter?.({ - type: "assets:creating", - data: { - current: ++i, - remaining: migration._assets.size - i, - total: migration._assets.size, - asset: migrationAsset, - }, - }) - - const { file, filename, notes, credits, alt, tags } = - migrationAsset.config - - let resolvedFile: PostAssetParams["file"] | File - if (typeof file === "string") { - let url: URL | undefined - try { - url = new URL(file) - } catch (error) { - // noop only on invalid URL, fetch errors will throw in the next if statement - } - - if (url) { - // File is a URL, fetch it - resolvedFile = await this.fetchForeignAsset( - url.toString(), - fetchParams, - ) - } else { - // File is actual file content, use it as-is - resolvedFile = file - } - } else if (file instanceof URL) { - // File is a URL instance, fetch it + if (url) { + // File is a URL, fetch it resolvedFile = await this.fetchForeignAsset( - file.toString(), + url.toString(), fetchParams, ) } else { + // File is actual file content, use it as-is resolvedFile = file } + } else if (file instanceof URL) { + // File is a URL instance, fetch it + resolvedFile = await this.fetchForeignAsset( + file.toString(), + fetchParams, + ) + } else { + resolvedFile = file + } - const asset = await this.createAsset(resolvedFile, filename, { - ...{ notes, credits, alt, tags }, - ...fetchParams, - }) + const asset = await this.createAsset(resolvedFile, filename, { + ...{ notes, credits, alt, tags }, + ...fetchParams, + }) - migrationAsset.asset = asset - } + migrationAsset.asset = asset } reporter?.({ @@ -590,83 +507,6 @@ export class WriteClient< }) } - /** - * Queries assets from the Prismic repository's media library. - * - * @param params - Parameters to filter, sort, and paginate results. - * - * @returns A paginated response containing the result of the query. - */ - private async getAssets({ - pageSize, - cursor, - // assetType, - // keyword, - // ids, - // tags, - ...params - }: Pick & - FetchParams = {}): Promise { - // Resolve tags if any - // if (tags && tags.length) { - // tags = await this.resolveAssetTagIDs(tags, params) - // } - - const url = new URL("assets", this.assetAPIEndpoint) - - if (pageSize) { - url.searchParams.set("pageSize", pageSize.toString()) - } - - if (cursor) { - url.searchParams.set("cursor", cursor) - } - - // if (assetType) { - // url.searchParams.set("assetType", assetType) - // } - - // if (keyword) { - // url.searchParams.set("keyword", keyword) - // } - - // if (ids) { - // ids.forEach((id) => url.searchParams.append("ids", id)) - // } - - // if (tags) { - // tags.forEach((tag) => url.searchParams.append("tags", tag)) - // } - - const { - items, - total, - // missing_ids, - cursor: nextCursor, - } = await this.fetch( - url.toString(), - this.buildAssetAPIQueryParams({ params }), - ) - - return { - results: items, - total_results_size: total, - // missing_ids: missing_ids || [], - next: nextCursor - ? () => - this.getAssets({ - pageSize, - cursor: nextCursor, - // assetType, - // keyword, - // ids, - // tags, - ...params, - }) - : undefined, - } - } - /** * Creates an asset in the Prismic media library. * @@ -770,56 +610,6 @@ export class WriteClient< ) } - // We don't want to expose those utilities for now, - // and we don't have any internal use for them yet. - - /** - * Deletes an asset from the Prismic media library. - * - * @param assetOrID - The asset or ID of the asset to delete. - * @param params - Additional fetch parameters. - */ - // private async deleteAsset( - // assetOrID: string | Asset, - // params?: FetchParams, - // ): Promise { - // const url = new URL( - // `assets/${typeof assetOrID === "string" ? assetOrID : assetOrID.id}`, - // this.assetAPIEndpoint, - // ) - - // await this.fetch( - // url.toString(), - // this.buildAssetAPIQueryParams({ method: "DELETE", params }), - // ) - // } - - /** - * Deletes multiple assets from the Prismic media library. - * - * @param assetsOrIDs - An array of asset IDs or assets to delete. - * @param params - Additional fetch parameters. - */ - // private async deleteAssets( - // assetsOrIDs: (string | Asset)[], - // params?: FetchParams, - // ): Promise { - // const url = new URL("assets/bulk-delete", this.assetAPIEndpoint) - - // await this.fetch( - // url.toString(), - // this.buildAssetAPIQueryParams({ - // method: "POST", - // body: { - // ids: assetsOrIDs.map((assetOrID) => - // typeof assetOrID === "string" ? assetOrID : assetOrID.id, - // ), - // }, - // params, - // }), - // ) - // } - /** * Fetches a foreign asset from a URL. * diff --git a/src/lib/prepareMigrationDocumentData.ts b/src/lib/prepareMigrationDocumentData.ts index 4bfd01de..89dbcb18 100644 --- a/src/lib/prepareMigrationDocumentData.ts +++ b/src/lib/prepareMigrationDocumentData.ts @@ -18,6 +18,8 @@ import * as is from "./isValue" * * @param record - Record of Prismic fields to work with. * @param onAsset - Callback that is called for each asset found. + * @param fromPrismic - Whether the record is from another Prismic repository or + * not. * * @returns An object containing the record with replaced assets and links and a * list of dependencies found and/or created. @@ -30,6 +32,7 @@ export const prepareMigrationDocumentData = < onAsset: ( asset: FilledImageFieldImage | FilledLinkToMediaField, ) => MigrationImage, + fromPrismic?: boolean, ): { record: TRecord; dependencies: MigrationField[] } => { const result = {} as Record const dependencies: MigrationField[] = [] @@ -41,7 +44,7 @@ export const prepareMigrationDocumentData = < // Existing migration fields dependencies.push(field) result[key] = field - } else if (is.linkToMedia(field)) { + } else if (fromPrismic && is.linkToMedia(field)) { // Link to media // TODO: Remove when link text PR is merged // @ts-expect-error - Future-proofing for link text @@ -49,7 +52,7 @@ export const prepareMigrationDocumentData = < dependencies.push(linkToMedia) result[key] = linkToMedia - } else if (is.rtImageNode(field)) { + } else if (fromPrismic && is.rtImageNode(field)) { // Rich text image nodes const rtImageNode = onAsset(field).asRTImageNode() @@ -58,6 +61,7 @@ export const prepareMigrationDocumentData = < rtImageNode.linkTo = prepareMigrationDocumentData( { linkTo: field.linkTo }, onAsset, + fromPrismic, ).record.linkTo as | MigrationContentRelationship | MigrationLinkToMedia @@ -66,7 +70,7 @@ export const prepareMigrationDocumentData = < dependencies.push(rtImageNode) result[key] = rtImageNode - } else if (is.image(field)) { + } else if (fromPrismic && is.image(field)) { // Image fields const image = onAsset(field).asImage() @@ -89,7 +93,7 @@ export const prepareMigrationDocumentData = < dependencies.push(image) result[key] = image - } else if (is.contentRelationship(field)) { + } else if (fromPrismic && is.contentRelationship(field)) { // Content relationships const contentRelationship = new MigrationContentRelationship( field, @@ -106,7 +110,7 @@ export const prepareMigrationDocumentData = < for (const item of field) { const { record, dependencies: itemDependencies } = - prepareMigrationDocumentData({ item }, onAsset) + prepareMigrationDocumentData({ item }, onAsset, fromPrismic) array.push(record.item) dependencies.push(...itemDependencies) @@ -116,7 +120,7 @@ export const prepareMigrationDocumentData = < } else if (field && typeof field === "object") { // Traverse objects const { record, dependencies: fieldDependencies } = - prepareMigrationDocumentData({ ...field }, onAsset) + prepareMigrationDocumentData({ ...field }, onAsset, fromPrismic) dependencies.push(...fieldDependencies) result[key] = record diff --git a/src/types/migration/Asset.ts b/src/types/migration/Asset.ts index 62403de9..a3eaafd9 100644 --- a/src/types/migration/Asset.ts +++ b/src/types/migration/Asset.ts @@ -26,7 +26,7 @@ type ImageLike = * * @returns Equivalent image field. */ -const assetToImage = ( +export const assetToImage = ( asset: Asset, maybeInitialField?: ImageLike, ): FilledImageFieldImage => { @@ -58,6 +58,33 @@ const assetToImage = ( } } +/** + * Converts an asset to a link to media field. + * + * @param asset - Asset to convert. + * @param text - Link text for the link to media field if any. + * + * @returns Equivalent link to media field. + */ +export const assetToLinkToMedia = ( + asset: Asset, + text?: string, +): LinkToMediaField<"filled"> => { + return { + id: asset.id, + link_type: LinkType.Media, + name: asset.filename, + kind: asset.kind, + url: asset.url, + size: `${asset.size}`, + height: typeof asset.height === "number" ? `${asset.height}` : undefined, + width: typeof asset.width === "number" ? `${asset.width}` : undefined, + // TODO: Remove when link text PR is merged + // @ts-expect-error - Future-proofing for link text + text, + } +} + /** * An asset to be uploaded to Prismic media library. */ @@ -251,20 +278,7 @@ export class MigrationLinkToMedia extends MigrationAsset< const asset = migration._assets.get(this.config.id)?.asset if (asset) { - this._field = { - id: asset.id, - link_type: LinkType.Media, - name: asset.filename, - kind: asset.kind, - url: asset.url, - size: `${asset.size}`, - height: - typeof asset.height === "number" ? `${asset.height}` : undefined, - width: typeof asset.width === "number" ? `${asset.width}` : undefined, - // TODO: Remove when link text PR is merged - // @ts-expect-error - Future-proofing for link text - text: this.text, - } + this._field = assetToLinkToMedia(asset, this.text) } } } diff --git a/test/__testutils__/testMigrationFieldPatching.ts b/test/__testutils__/testMigrationFieldPatching.ts index 3dd88d58..3f59b0c2 100644 --- a/test/__testutils__/testMigrationFieldPatching.ts +++ b/test/__testutils__/testMigrationFieldPatching.ts @@ -32,6 +32,7 @@ type GetDataArgs = { type InternalTestMigrationFieldPatchingArgs = { getData: (args: GetDataArgs) => prismic.ExistingPrismicDocument["data"] expectStrictEqual?: boolean + mode?: "new" | "fromPrismic" } const internalTestMigrationFieldPatching = ( @@ -62,7 +63,7 @@ const internalTestMigrationFieldPatching = ( ...ctx.mock.value.document(), uid: ctx.mock.value.keyText(), } - const { id: __id, ...newDocument } = ctx.mock.value.document() + const { id: originalID, ...newDocument } = ctx.mock.value.document() const newID = "id-new" @@ -114,7 +115,14 @@ const internalTestMigrationFieldPatching = ( mockedDomain, }) - migration.createDocument(newDocument, "new") + if (!args.mode || args.mode === "new") { + migration.createDocument(newDocument, "new") + } else { + migration.createDocumentFromPrismic( + { ...newDocument, id: originalID }, + args.mode, + ) + } // We speed up the internal rate limiter to make these tests run faster (from 4500ms to nearly instant) const migrationProcess = client.migrate(migration) diff --git a/test/migration-createDocument.test.ts b/test/migration-createDocument.test.ts index 796d48ad..c1199258 100644 --- a/test/migration-createDocument.test.ts +++ b/test/migration-createDocument.test.ts @@ -1,9 +1,6 @@ -import { describe, expect, it } from "vitest" - -import type { MockFactory } from "@prismicio/mock" +import { expect, it } from "vitest" import * as prismic from "../src" -import type { MigrationAssetConfig } from "../src/types/migration/Asset" import { PrismicMigrationDocument } from "../src/types/migration/Document" it("creates a document", () => { @@ -23,259 +20,3 @@ it("creates a document", () => { new PrismicMigrationDocument(document, documentTitle, { dependencies: [] }), ) }) - -it("creates a document from an existing Prismic document", (ctx) => { - const migration = prismic.createMigration() - - const document = ctx.mock.value.document() - const documentTitle = "documentTitle" - - migration.createDocument(document, documentTitle) - - expect(migration._documents[0]).toStrictEqual( - new PrismicMigrationDocument(document, documentTitle, { dependencies: [] }), - ) -}) - -describe.each<{ - fieldType: string - getField: (mock: MockFactory) => { - id: string - field: - | prismic.FilledImageFieldImage - | prismic.FilledLinkToMediaField - | prismic.RichTextField<"filled"> - expected: MigrationAssetConfig - } -}>([ - { - fieldType: "image", - getField: (mock) => { - const image = mock.value.image({ state: "filled" }) - - return { - id: image.id, - field: image, - expected: { - alt: image.alt || undefined, - credits: image.copyright || undefined, - file: image.url.split("?")[0], - filename: image.url.split("/").pop()!.split("?")[0], - id: image.id, - notes: undefined, - tags: undefined, - }, - } - }, - }, - { - fieldType: "link to media", - getField: (mock) => { - const linkToMedia = mock.value.linkToMedia({ state: "filled" }) - - return { - id: linkToMedia.id, - field: linkToMedia, - expected: { - alt: undefined, - credits: undefined, - file: linkToMedia.url.split("?")[0], - filename: linkToMedia.name, - id: linkToMedia.id, - notes: undefined, - tags: undefined, - }, - } - }, - }, - { - fieldType: "rich text (image)", - getField: (mock) => { - const image = mock.value.image({ state: "filled" }) - const richText: prismic.RichTextField<"filled"> = [ - { - type: prismic.RichTextNodeType.image, - ...image, - }, - ] - - return { - id: image.id, - field: richText, - expected: { - alt: image.alt || undefined, - credits: image.copyright || undefined, - file: image.url.split("?")[0], - filename: image.url.split("/").pop()!.split("?")[0], - id: image.id, - notes: undefined, - tags: undefined, - }, - } - }, - }, - { - fieldType: "rich text (link to media span)", - getField: (mock) => { - const linkToMedia = mock.value.linkToMedia({ state: "filled" }) - const richText = mock.value.richText({ - state: "filled", - }) as prismic.RichTextField<"filled"> - - richText.push({ - type: prismic.RichTextNodeType.paragraph, - text: "lorem", - spans: [ - { - start: 0, - end: 5, - type: prismic.RichTextNodeType.hyperlink, - data: linkToMedia, - }, - ], - }) - - return { - id: linkToMedia.id, - field: richText, - expected: { - alt: undefined, - credits: undefined, - file: linkToMedia.url.split("?")[0], - filename: linkToMedia.name, - id: linkToMedia.id, - notes: undefined, - tags: undefined, - }, - } - }, - }, - { - fieldType: "rich text (image's link to media)", - getField: (mock) => { - const image = mock.value.image({ state: "filled" }) - const linkToMedia = mock.value.linkToMedia({ state: "filled" }) - const richText: prismic.RichTextField<"filled"> = [ - { - type: prismic.RichTextNodeType.image, - linkTo: linkToMedia, - ...image, - }, - ] - - return { - id: linkToMedia.id, - field: richText, - expected: { - alt: undefined, - credits: undefined, - file: linkToMedia.url.split("?")[0], - filename: linkToMedia.name, - id: linkToMedia.id, - notes: undefined, - tags: undefined, - }, - } - }, - }, -])("extracts assets from image fields ($fieldType)", ({ getField }) => { - it("regular fields", ({ mock }) => { - const migration = prismic.createMigration() - - const { id, field, expected } = getField(mock) - - const document: prismic.PendingPrismicDocument = { - type: "type", - uid: "uid", - lang: "lang", - data: { field }, - } - const documentTitle = "documentTitle" - - expect(migration._assets.size).toBe(0) - - migration.createDocument(document, documentTitle) - - expect(migration._assets.get(id)?.config).toStrictEqual(expected) - }) - - it("group fields", ({ mock }) => { - const migration = prismic.createMigration() - - const { id, field, expected } = getField(mock) - - const document: prismic.PendingPrismicDocument = { - type: "type", - uid: "uid", - lang: "lang", - data: { group: [{ field }] }, - } - const documentTitle = "documentTitle" - - expect(migration._assets.size).toBe(0) - - migration.createDocument(document, documentTitle) - - expect(migration._assets.get(id)?.config).toStrictEqual(expected) - }) - - it("slice's primary zone", ({ mock }) => { - const migration = prismic.createMigration() - - const { id, field, expected } = getField(mock) - - const slices: prismic.SliceZone = [ - { - id: "id", - slice_type: "slice_type", - slice_label: "slice_label", - primary: { field }, - items: [], - }, - ] - - const document: prismic.PendingPrismicDocument = { - type: "type", - uid: "uid", - lang: "lang", - data: { slices }, - } - const documentTitle = "documentTitle" - - expect(migration._assets.size).toBe(0) - - migration.createDocument(document, documentTitle) - - expect(migration._assets.get(id)?.config).toStrictEqual(expected) - }) - - it("slice's repeatable zone", ({ mock }) => { - const migration = prismic.createMigration() - - const { id, field, expected } = getField(mock) - - const slices: prismic.SliceZone = [ - { - id: "id", - slice_type: "slice_type", - slice_label: "slice_label", - primary: {}, - items: [{ field }], - }, - ] - - const document: prismic.PendingPrismicDocument = { - type: "type", - uid: "uid", - lang: "lang", - data: { slices }, - } - const documentTitle = "documentTitle" - - expect(migration._assets.size).toBe(0) - - migration.createDocument(document, documentTitle) - - expect(migration._assets.get(id)?.config).toStrictEqual(expected) - }) -}) diff --git a/test/migration-createDocumentFromPrismic.test.ts b/test/migration-createDocumentFromPrismic.test.ts new file mode 100644 index 00000000..d26af3ea --- /dev/null +++ b/test/migration-createDocumentFromPrismic.test.ts @@ -0,0 +1,256 @@ +import { describe, expect, it } from "vitest" + +import type { MockFactory } from "@prismicio/mock" + +import * as prismic from "../src" +import type { MigrationAssetConfig } from "../src/types/migration/Asset" +import { PrismicMigrationDocument } from "../src/types/migration/Document" + +it("creates a document from an existing Prismic document", (ctx) => { + const migration = prismic.createMigration() + + const document = ctx.mock.value.document() + const documentTitle = "documentTitle" + + const { type, uid, lang, tags, data } = document + + migration.createDocumentFromPrismic(document, documentTitle) + + expect(migration._documents[0]).toStrictEqual( + new PrismicMigrationDocument( + { type, uid, lang, tags, data }, + documentTitle, + { + dependencies: [], + originalPrismicDocument: document, + }, + ), + ) +}) + +describe.each<{ + fieldType: string + getField: (mock: MockFactory) => { + id: string + field: + | prismic.FilledImageFieldImage + | prismic.FilledLinkToMediaField + | prismic.RichTextField<"filled"> + expected: MigrationAssetConfig + } +}>([ + { + fieldType: "image", + getField: (mock) => { + const image = mock.value.image({ state: "filled" }) + + return { + id: image.id, + field: image, + expected: { + alt: image.alt || undefined, + credits: image.copyright || undefined, + file: image.url.split("?")[0], + filename: image.url.split("/").pop()!.split("?")[0], + id: image.id, + notes: undefined, + tags: undefined, + }, + } + }, + }, + { + fieldType: "link to media", + getField: (mock) => { + const linkToMedia = mock.value.linkToMedia({ state: "filled" }) + + return { + id: linkToMedia.id, + field: linkToMedia, + expected: { + alt: undefined, + credits: undefined, + file: linkToMedia.url.split("?")[0], + filename: linkToMedia.name, + id: linkToMedia.id, + notes: undefined, + tags: undefined, + }, + } + }, + }, + { + fieldType: "rich text (image)", + getField: (mock) => { + const image = mock.value.image({ state: "filled" }) + const richText: prismic.RichTextField<"filled"> = [ + { + type: prismic.RichTextNodeType.image, + ...image, + }, + ] + + return { + id: image.id, + field: richText, + expected: { + alt: image.alt || undefined, + credits: image.copyright || undefined, + file: image.url.split("?")[0], + filename: image.url.split("/").pop()!.split("?")[0], + id: image.id, + notes: undefined, + tags: undefined, + }, + } + }, + }, + { + fieldType: "rich text (link to media span)", + getField: (mock) => { + const linkToMedia = mock.value.linkToMedia({ state: "filled" }) + const richText = mock.value.richText({ + state: "filled", + }) as prismic.RichTextField<"filled"> + + richText.push({ + type: prismic.RichTextNodeType.paragraph, + text: "lorem", + spans: [ + { + start: 0, + end: 5, + type: prismic.RichTextNodeType.hyperlink, + data: linkToMedia, + }, + ], + }) + + return { + id: linkToMedia.id, + field: richText, + expected: { + alt: undefined, + credits: undefined, + file: linkToMedia.url.split("?")[0], + filename: linkToMedia.name, + id: linkToMedia.id, + notes: undefined, + tags: undefined, + }, + } + }, + }, + { + fieldType: "rich text (image's link to media)", + getField: (mock) => { + const image = mock.value.image({ state: "filled" }) + const linkToMedia = mock.value.linkToMedia({ state: "filled" }) + const richText: prismic.RichTextField<"filled"> = [ + { + type: prismic.RichTextNodeType.image, + linkTo: linkToMedia, + ...image, + }, + ] + + return { + id: linkToMedia.id, + field: richText, + expected: { + alt: undefined, + credits: undefined, + file: linkToMedia.url.split("?")[0], + filename: linkToMedia.name, + id: linkToMedia.id, + notes: undefined, + tags: undefined, + }, + } + }, + }, +])("extracts assets from image fields ($fieldType)", ({ getField }) => { + it("regular fields", ({ mock }) => { + const migration = prismic.createMigration() + + const { id, field, expected } = getField(mock) + + const document: prismic.PrismicDocument = mock.value.document() + document.data = { field } + const documentTitle = "documentTitle" + + expect(migration._assets.size).toBe(0) + + migration.createDocumentFromPrismic(document, documentTitle) + + expect(migration._assets.get(id)?.config).toStrictEqual(expected) + }) + + it("group fields", ({ mock }) => { + const migration = prismic.createMigration() + + const { id, field, expected } = getField(mock) + + const document: prismic.PrismicDocument = mock.value.document() + document.data = { group: [{ field }] } + const documentTitle = "documentTitle" + + expect(migration._assets.size).toBe(0) + + migration.createDocumentFromPrismic(document, documentTitle) + + expect(migration._assets.get(id)?.config).toStrictEqual(expected) + }) + + it("slice's primary zone", ({ mock }) => { + const migration = prismic.createMigration() + + const { id, field, expected } = getField(mock) + + const slices: prismic.SliceZone = [ + { + id: "id", + slice_type: "slice_type", + slice_label: "slice_label", + primary: { field }, + items: [], + }, + ] + + const document: prismic.PrismicDocument = mock.value.document() + document.data = { slices } + const documentTitle = "documentTitle" + + expect(migration._assets.size).toBe(0) + + migration.createDocumentFromPrismic(document, documentTitle) + + expect(migration._assets.get(id)?.config).toStrictEqual(expected) + }) + + it("slice's repeatable zone", ({ mock }) => { + const migration = prismic.createMigration() + + const { id, field, expected } = getField(mock) + + const slices: prismic.SliceZone = [ + { + id: "id", + slice_type: "slice_type", + slice_label: "slice_label", + primary: {}, + items: [{ field }], + }, + ] + + const document: prismic.PrismicDocument = mock.value.document() + document.data = { slices } + const documentTitle = "documentTitle" + + expect(migration._assets.size).toBe(0) + + migration.createDocumentFromPrismic(document, documentTitle) + + expect(migration._assets.get(id)?.config).toStrictEqual(expected) + }) +}) diff --git a/test/writeClient-getAssets.test.ts b/test/writeClient-getAssets.test.ts deleted file mode 100644 index 34186fe4..00000000 --- a/test/writeClient-getAssets.test.ts +++ /dev/null @@ -1,295 +0,0 @@ -import { it as _it, expect } from "vitest" - -import { createTestWriteClient } from "./__testutils__/createWriteClient" -import { mockPrismicAssetAPI } from "./__testutils__/mockPrismicAssetAPI" - -import { ForbiddenError } from "../src" -import { AssetType } from "../src/types/api/asset/asset" - -// Skip test on Node 16 (FormData support) -const isNode16 = process.version.startsWith("v16") -const it = _it.skipIf(isNode16) - -it.concurrent("get assets", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - const { assetsDatabase } = mockPrismicAssetAPI({ - ctx, - client, - existingAssets: [2], - }) - - // @ts-expect-error - testing purposes - const { results } = await client.getAssets() - - expect(results).toStrictEqual(assetsDatabase[0]) -}) - -it.concurrent("supports `pageSize` parameter", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - const { assetsDatabase } = mockPrismicAssetAPI({ - ctx, - client, - existingAssets: [2], - }) - - ctx.server.events.on("request:start", (req) => { - if (req.url.hostname.startsWith(client.repositoryName)) { - ctx.expect(req.url.searchParams.get("pageSize")).toBe("10") - } - }) - - // @ts-expect-error - testing purposes - const { results } = await client.getAssets({ - pageSize: 10, - }) - - ctx.expect(results).toStrictEqual(assetsDatabase[0]) - ctx.expect.assertions(2) -}) - -it.concurrent("supports `cursor` parameter", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - const { assetsDatabase } = mockPrismicAssetAPI({ - ctx, - client, - existingAssets: [2, 2], - }) - - ctx.server.events.on("request:start", (req) => { - if (req.url.hostname.startsWith(client.repositoryName)) { - ctx.expect(req.url.searchParams.get("cursor")).toBe("1") - } - }) - - // @ts-expect-error - testing purposes - const { results } = await client.getAssets({ cursor: "1" }) - - ctx.expect(results).toStrictEqual(assetsDatabase[1]) - ctx.expect.assertions(2) -}) - -it.concurrent.skip("supports `assetType` parameter", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - const { assetsDatabase } = mockPrismicAssetAPI({ - ctx, - client, - existingAssets: [2], - }) - - ctx.server.events.on("request:start", (req) => { - if (req.url.hostname.startsWith(client.repositoryName)) { - ctx.expect(req.url.searchParams.get("assetType")).toBe(AssetType.Image) - } - }) - - // @ts-expect-error - testing purposes - const { results } = await client.getAssets({ assetType: AssetType.Image }) - - ctx.expect(results).toStrictEqual(assetsDatabase[0]) - ctx.expect.assertions(2) -}) - -it.concurrent.skip("supports `keyword` parameter", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - const { assetsDatabase } = mockPrismicAssetAPI({ - ctx, - client, - existingAssets: [2], - }) - - ctx.server.events.on("request:start", (req) => { - if (req.url.hostname.startsWith(client.repositoryName)) { - ctx.expect(req.url.searchParams.get("keyword")).toBe("foo") - } - }) - - // @ts-expect-error - testing purposes - const { results } = await client.getAssets({ keyword: "foo" }) - - ctx.expect(results).toStrictEqual(assetsDatabase[0]) - ctx.expect.assertions(2) -}) - -it.concurrent.skip("supports `ids` parameter", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - const { assetsDatabase } = mockPrismicAssetAPI({ - ctx, - client, - existingAssets: [2], - }) - - const ids = ["foo", "bar"] - - ctx.server.events.on("request:start", (req) => { - if (req.url.hostname.startsWith(client.repositoryName)) { - ctx.expect(req.url.searchParams.getAll("ids")).toStrictEqual(ids) - } - }) - - // @ts-expect-error - testing purposes - const { results } = await client.getAssets({ ids }) - - ctx.expect(results).toStrictEqual(assetsDatabase[0]) - ctx.expect.assertions(2) -}) - -it.concurrent.skip("supports `tags` parameter", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - const { assetsDatabase } = mockPrismicAssetAPI({ - ctx, - client, - existingAssets: [2], - existingTags: [ - { - id: "00000000-4444-4444-4444-121212121212", - name: "foo", - created_at: 0, - last_modified: 0, - }, - { - id: "10000000-4444-4444-4444-121212121212", - name: "bar", - created_at: 0, - last_modified: 0, - }, - ], - }) - - ctx.server.events.on("request:start", (req) => { - if (req.url.hostname.startsWith(client.repositoryName)) { - ctx - .expect(req.url.searchParams.getAll("tags")) - .toStrictEqual([ - "00000000-4444-4444-4444-121212121212", - "10000000-4444-4444-4444-121212121212", - ]) - } - }) - - // @ts-expect-error - testing purposes - const { results } = await client.getAssets({ tags: ["foo", "bar"] }) - - ctx.expect(results).toStrictEqual(assetsDatabase[0]) - ctx.expect.assertions(2) -}) - -it.concurrent.skip("supports `tags` parameter (missing)", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - const { assetsDatabase } = mockPrismicAssetAPI({ - ctx, - client, - existingAssets: [2], - existingTags: [ - { - id: "00000000-4444-4444-4444-121212121212", - name: "foo", - created_at: 0, - last_modified: 0, - }, - ], - }) - - ctx.server.events.on("request:start", (req) => { - if (req.url.hostname.startsWith(client.repositoryName)) { - ctx - .expect(req.url.searchParams.getAll("tags")) - .toStrictEqual(["00000000-4444-4444-4444-121212121212"]) - } - }) - - // @ts-expect-error - testing purposes - const { results } = await client.getAssets({ tags: ["foo", "bar"] }) - - ctx.expect(results).toStrictEqual(assetsDatabase[0]) - ctx.expect.assertions(2) -}) - -it.concurrent("returns `next` when next `cursor` is available", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - mockPrismicAssetAPI({ ctx, client }) - - // @ts-expect-error - testing purposes - const { next: next1 } = await client.getAssets() - - ctx.expect(next1).toBeUndefined() - - mockPrismicAssetAPI({ - ctx, - client, - existingAssets: [2, 2], - }) - - // @ts-expect-error - testing purposes - const { next: next2 } = await client.getAssets() - - ctx.expect(next2).toBeInstanceOf(Function) - - const { assetsDatabase } = mockPrismicAssetAPI({ - ctx, - client, - existingAssets: [2, 2], - }) - - ctx.server.events.on("request:start", (req) => { - if (req.url.hostname.startsWith(client.repositoryName)) { - ctx.expect(req.url.searchParams.get("cursor")).toBe("1") - } - }) - - const { results } = await next2!() - ctx.expect(results).toStrictEqual(assetsDatabase[1]) - ctx.expect.assertions(4) -}) - -it.concurrent("throws forbidden error on invalid credentials", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - mockPrismicAssetAPI({ ctx, client, writeToken: "invalid" }) - - // @ts-expect-error - testing purposes - await expect(() => client.getAssets()).rejects.toThrow(ForbiddenError) -}) - -it.concurrent("is abortable with an AbortController", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - const controller = new AbortController() - controller.abort() - - mockPrismicAssetAPI({ ctx, client }) - - await expect(() => - // @ts-expect-error - testing purposes - client.getAssets({ - fetchOptions: { signal: controller.signal }, - }), - ).rejects.toThrow(/aborted/i) -}) - -it.concurrent("supports custom headers", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - const headers = { "x-custom": "foo" } - - const { assetsDatabase } = mockPrismicAssetAPI({ - ctx, - client, - existingAssets: [2], - requiredHeaders: headers, - }) - - // @ts-expect-error - testing purposes - const { results } = await client.getAssets({ fetchOptions: { headers } }) - - ctx.expect(results).toStrictEqual(assetsDatabase[0]) - ctx.expect.assertions(2) -}) diff --git a/test/writeClient-migrate-assets.test.ts b/test/writeClient-migrate-assets.test.ts index 5c9ed198..e9ac1a0c 100644 --- a/test/writeClient-migrate-assets.test.ts +++ b/test/writeClient-migrate-assets.test.ts @@ -17,83 +17,6 @@ const isNode16 = process.version.startsWith("v16") const isNode18 = process.version.startsWith("v18") const it = _it.skipIf(isNode16 || isNode18) -it.concurrent("discovers existing assets", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - mockPrismicRestAPIV2({ ctx }) - mockPrismicAssetAPI({ ctx, client, existingAssets: [2] }) - mockPrismicMigrationAPI({ ctx, client }) - - const migration = prismic.createMigration() - - const reporter = vi.fn() - - await client.migrate(migration, { reporter }) - - expect(reporter).toHaveBeenCalledWith({ - type: "assets:existing", - data: { - existing: 2, - }, - }) -}) - -it.concurrent( - "discovers existing assets and crawl pages if any", - async (ctx) => { - const client = createTestWriteClient({ ctx }) - - mockPrismicRestAPIV2({ ctx }) - mockPrismicAssetAPI({ ctx, client, existingAssets: [2, 3] }) - mockPrismicMigrationAPI({ ctx, client }) - - const migration = prismic.createMigration() - - const reporter = vi.fn() - - await client.migrate(migration, { reporter }) - - expect(reporter).toHaveBeenCalledWith({ - type: "assets:existing", - data: { - existing: 5, - }, - }) - }, -) - -it.concurrent("skips creating existing assets", async (ctx) => { - const client = createTestWriteClient({ ctx }) - - mockPrismicRestAPIV2({ ctx }) - const { assetsDatabase } = mockPrismicAssetAPI({ - ctx, - client, - existingAssets: [1], - }) - mockPrismicMigrationAPI({ ctx, client }) - - const migration = prismic.createMigration() - - const asset = assetsDatabase[0][0] - const migrationAsset = migration.createAsset(asset) - - const reporter = vi.fn() - - await client.migrate(migration, { reporter }) - - expect(reporter).toHaveBeenCalledWith({ - type: "assets:skipping", - data: { - reason: "already exists", - current: 1, - remaining: 0, - total: 1, - asset: migrationAsset, - }, - }) -}) - it.concurrent("creates new asset from string file data", async (ctx) => { const client = createTestWriteClient({ ctx }) diff --git a/test/writeClient-migrate-patch-contentRelationship.test.ts b/test/writeClient-migrate-patch-contentRelationship.test.ts index 73a5def5..78491393 100644 --- a/test/writeClient-migrate-patch-contentRelationship.test.ts +++ b/test/writeClient-migrate-patch-contentRelationship.test.ts @@ -33,14 +33,6 @@ testMigrationFieldPatching("patches link fields", { ), ) }, - otherRepositoryContentRelationship: ({ ctx, migrationDocuments }) => { - const contentRelationship = ctx.mock.value.link({ type: "Document" }) - // `migrationDocuments` contains documents from "another repository" - contentRelationship.id = - migrationDocuments.otherRepository.originalPrismicDocument!.id - - return contentRelationship - }, brokenLink: () => { return { type: "Document", isBroken: true } }, @@ -60,3 +52,18 @@ testMigrationFieldPatching("patches link fields", { }, ], }) + +testMigrationFieldPatching( + "patches link fields", + { + otherRepositoryContentRelationship: ({ ctx, migrationDocuments }) => { + const contentRelationship = ctx.mock.value.link({ type: "Document" }) + // `migrationDocuments` contains documents from "another repository" + contentRelationship.id = + migrationDocuments.otherRepository.originalPrismicDocument!.id + + return contentRelationship + }, + }, + { mode: "fromPrismic" }, +) diff --git a/test/writeClient-migrate-patch-image.test.ts b/test/writeClient-migrate-patch-image.test.ts index f0897927..e0bdc7fe 100644 --- a/test/writeClient-migrate-patch-image.test.ts +++ b/test/writeClient-migrate-patch-image.test.ts @@ -1,61 +1,69 @@ import { testMigrationFieldPatching } from "./__testutils__/testMigrationFieldPatching" +import { assetToImage } from "../src/types/migration/Asset" + testMigrationFieldPatching("patches image fields", { new: ({ migration }) => migration.createAsset("foo", "foo.png"), - existing: ({ migration, existingAssets }) => - migration.createAsset(existingAssets[0]), - otherRepository: ({ ctx, mockedDomain }) => { - return { - ...ctx.mock.value.image({ state: "filled" }), - id: "foo-id", - url: `${mockedDomain}/foo.png`, - } - }, - otherRepositoryWithThumbnails: ({ ctx, mockedDomain }) => { - const image = ctx.mock.value.image({ state: "filled" }) - const id = "foo-id" + existing: ({ existingAssets }) => assetToImage(existingAssets[0]), +}) + +testMigrationFieldPatching( + "patches image fields", + { + otherRepository: ({ ctx, mockedDomain }) => { + return { + ...ctx.mock.value.image({ state: "filled" }), + id: "foo-id", + url: `${mockedDomain}/foo.png`, + } + }, + otherRepositoryWithThumbnails: ({ ctx, mockedDomain }) => { + const image = ctx.mock.value.image({ state: "filled" }) + const id = "foo-id" - return { - ...image, - id, - url: `${mockedDomain}/foo.png?some=query`, - square: { + return { ...image, id, - url: `${mockedDomain}/foo.png?some=other&query=params`, - }, - } - }, - otherRepositoryWithThumbnailsNoAlt: ({ ctx, mockedDomain }) => { - const image = ctx.mock.value.image({ state: "filled" }) - image.alt = null - const id = "foo-id" + url: `${mockedDomain}/foo.png?some=query`, + square: { + ...image, + id, + url: `${mockedDomain}/foo.png?some=other&query=params`, + }, + } + }, + otherRepositoryWithThumbnailsNoAlt: ({ ctx, mockedDomain }) => { + const image = ctx.mock.value.image({ state: "filled" }) + image.alt = null + const id = "foo-id" - return { - ...image, - id, - url: `${mockedDomain}/foo.png?some=query`, - square: { + return { ...image, id, - url: `${mockedDomain}/foo.png?some=other&query=params`, - }, - } - }, - otherRepositoryWithTypeThumbnail: ({ ctx, mockedDomain }) => { - const image = ctx.mock.value.image({ state: "filled" }) - const id = "foo-id" + url: `${mockedDomain}/foo.png?some=query`, + square: { + ...image, + id, + url: `${mockedDomain}/foo.png?some=other&query=params`, + }, + } + }, + otherRepositoryWithTypeThumbnail: ({ ctx, mockedDomain }) => { + const image = ctx.mock.value.image({ state: "filled" }) + const id = "foo-id" - return { - ...image, - id, - url: `${mockedDomain}/foo.png?some=query`, - type: { + return { ...image, id, - url: `${mockedDomain}/foo.png?some=other&query=params`, - }, - } + url: `${mockedDomain}/foo.png?some=query`, + type: { + ...image, + id, + url: `${mockedDomain}/foo.png?some=other&query=params`, + }, + } + }, + otherRepositoryEmpty: ({ ctx }) => ctx.mock.value.image({ state: "empty" }), }, - otherRepositoryEmpty: ({ ctx }) => ctx.mock.value.image({ state: "empty" }), -}) + { mode: "fromPrismic" }, +) diff --git a/test/writeClient-migrate-patch-linkToMedia.test.ts b/test/writeClient-migrate-patch-linkToMedia.test.ts index 8a19025c..5f01837a 100644 --- a/test/writeClient-migrate-patch-linkToMedia.test.ts +++ b/test/writeClient-migrate-patch-linkToMedia.test.ts @@ -2,27 +2,20 @@ import { testMigrationFieldPatching } from "./__testutils__/testMigrationFieldPa import { RichTextNodeType } from "../src" import { AssetType } from "../src/types/api/asset/asset" +import { assetToLinkToMedia } from "../src/types/migration/Asset" testMigrationFieldPatching("patches link to media fields", { new: ({ migration }) => migration.createAsset("foo", "foo.png").asLinkToMedia(), - existing: ({ migration, existingAssets }) => - migration.createAsset(existingAssets[0]).asLinkToMedia(), - existingNonImage: ({ migration, existingAssets }) => { + existing: ({ existingAssets }) => assetToLinkToMedia(existingAssets[0]), + existingNonImage: ({ existingAssets }) => { existingAssets[0].filename = "foo.pdf" existingAssets[0].extension = "pdf" existingAssets[0].kind = AssetType.Document existingAssets[0].width = undefined existingAssets[0].height = undefined - return migration.createAsset(existingAssets[0]).asLinkToMedia() - }, - otherRepository: ({ ctx, mockedDomain }) => { - return { - ...ctx.mock.value.linkToMedia({ state: "filled" }), - id: "foo-id", - url: `${mockedDomain}/foo.png`, - } + return assetToLinkToMedia(existingAssets[0]) }, richTextNew: ({ migration }) => [ { @@ -39,7 +32,7 @@ testMigrationFieldPatching("patches link to media fields", { ], }, ], - richTextExisting: ({ migration, existingAssets }) => [ + richTextExisting: ({ existingAssets }) => [ { type: RichTextNodeType.paragraph, text: "lorem", @@ -49,28 +42,42 @@ testMigrationFieldPatching("patches link to media fields", { type: RichTextNodeType.hyperlink, start: 0, end: 5, - data: migration.createAsset(existingAssets[0]).asLinkToMedia(), - }, - ], - }, - ], - richTextOtherRepository: ({ ctx, mockedDomain }) => [ - { - type: RichTextNodeType.paragraph, - text: "lorem", - spans: [ - { type: RichTextNodeType.strong, start: 0, end: 5 }, - { - type: RichTextNodeType.hyperlink, - start: 0, - end: 5, - data: { - ...ctx.mock.value.linkToMedia({ state: "filled" }), - id: "foo-id", - url: `${mockedDomain}/foo.png`, - }, + data: assetToLinkToMedia(existingAssets[0]), }, ], }, ], }) + +testMigrationFieldPatching( + "patches link to media fields", + { + otherRepository: ({ ctx, mockedDomain }) => { + return { + ...ctx.mock.value.linkToMedia({ state: "filled" }), + id: "foo-id", + url: `${mockedDomain}/foo.png`, + } + }, + richTextOtherRepository: ({ ctx, mockedDomain }) => [ + { + type: RichTextNodeType.paragraph, + text: "lorem", + spans: [ + { type: RichTextNodeType.strong, start: 0, end: 5 }, + { + type: RichTextNodeType.hyperlink, + start: 0, + end: 5, + data: { + ...ctx.mock.value.linkToMedia({ state: "filled" }), + id: "foo-id", + url: `${mockedDomain}/foo.png`, + }, + }, + ], + }, + ], + }, + { mode: "fromPrismic" }, +) diff --git a/test/writeClient-migrate-patch-rtImageNode.test.ts b/test/writeClient-migrate-patch-rtImageNode.test.ts index 47d9ace3..b4138805 100644 --- a/test/writeClient-migrate-patch-rtImageNode.test.ts +++ b/test/writeClient-migrate-patch-rtImageNode.test.ts @@ -1,6 +1,7 @@ import { testMigrationFieldPatching } from "./__testutils__/testMigrationFieldPatching" import { RichTextNodeType } from "../src" +import { assetToImage } from "../src/types/migration/Asset" import { MigrationContentRelationship } from "../src/types/migration/ContentRelationship" testMigrationFieldPatching("patches rich text image nodes", { @@ -8,17 +9,11 @@ testMigrationFieldPatching("patches rich text image nodes", { ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), migration.createAsset("foo", "foo.png").asRTImageNode(), ], - existing: ({ ctx, migration, existingAssets }) => [ - ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), - migration.createAsset(existingAssets[0]).asRTImageNode(), - ], - otherRepository: ({ ctx, mockedDomain }) => [ + existing: ({ ctx, existingAssets }) => [ ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), { type: RichTextNodeType.image, - ...ctx.mock.value.image({ state: "filled" }), - id: "foo-id", - url: `${mockedDomain}/foo.png`, + ...assetToImage(existingAssets[0]), }, ], newLinkTo: ({ ctx, migration, existingDocuments }) => [ @@ -27,19 +22,35 @@ testMigrationFieldPatching("patches rich text image nodes", { .createAsset("foo", "foo.png") .asRTImageNode(new MigrationContentRelationship(existingDocuments[0])), ], - otherRepositoryLinkTo: ({ - ctx, - migration, - mockedDomain, - existingDocuments, - }) => [ - ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), - { - type: RichTextNodeType.image, - ...ctx.mock.value.image({ state: "filled" }), - id: "foo-id", - url: `${mockedDomain}/foo.png`, - linkTo: migration.createContentRelationship(existingDocuments[0]), - }, - ], }) + +testMigrationFieldPatching( + "patches rich text image nodes", + { + otherRepository: ({ ctx, mockedDomain }) => [ + ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), + { + type: RichTextNodeType.image, + ...ctx.mock.value.image({ state: "filled" }), + id: "foo-id", + url: `${mockedDomain}/foo.png`, + }, + ], + otherRepositoryLinkTo: ({ + ctx, + migration, + mockedDomain, + existingDocuments, + }) => [ + ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), + { + type: RichTextNodeType.image, + ...ctx.mock.value.image({ state: "filled" }), + id: "foo-id", + url: `${mockedDomain}/foo.png`, + linkTo: migration.createContentRelationship(existingDocuments[0]), + }, + ], + }, + { mode: "fromPrismic" }, +) From db4e8a733223be91cf36826560dc273ea3a742d4 Mon Sep 17 00:00:00 2001 From: lihbr Date: Mon, 16 Sep 2024 10:38:05 +0200 Subject: [PATCH 09/13] refactor: remove `dependencies` concept --- src/Migration.ts | 14 +++--- src/WriteClient.ts | 14 ++++-- src/lib/prepareMigrationDocumentData.ts | 34 ++++++------- src/lib/resolveMigrationDocumentData.ts | 49 +++++++++++++++++++ src/types/migration/Asset.ts | 28 +++++------ src/types/migration/ContentRelationship.ts | 6 ++- src/types/migration/Document.ts | 32 ++---------- src/types/migration/Field.ts | 33 +++++-------- test/migration-createDocument.test.ts | 2 +- ...igration-createDocumentFromPrismic.test.ts | 1 - test/migration-updateDocument.test.ts | 2 +- 11 files changed, 114 insertions(+), 101 deletions(-) create mode 100644 src/lib/resolveMigrationDocumentData.ts diff --git a/src/Migration.ts b/src/Migration.ts index 0fe7d838..dce1be98 100644 --- a/src/Migration.ts +++ b/src/Migration.ts @@ -245,14 +245,14 @@ export class Migration { masterLanguageDocument?: MigrationContentRelationship }, ): PrismicMigrationDocument> { - const { record: data, dependencies } = prepareMigrationDocumentData( + const data = prepareMigrationDocumentData( document.data!, this.createAsset.bind(this), ) const doc = new PrismicMigrationDocument< ExtractDocumentType - >({ ...document, data }, title, { ...options, dependencies }) + >({ ...document, data }, title, options) this._documents.push(doc) @@ -279,14 +279,14 @@ export class Migration { document: ExtractDocumentType, TType>, title: string, ): PrismicMigrationDocument> { - const { record: data, dependencies } = prepareMigrationDocumentData( + const data = prepareMigrationDocumentData( document.data, this.createAsset.bind(this), ) const doc = new PrismicMigrationDocument< ExtractDocumentType - >({ ...document, data }, title, { dependencies }) + >({ ...document, data }, title) this._documents.push(doc) @@ -312,7 +312,7 @@ export class Migration { document: ExtractDocumentType, TType>, title: string, ): PrismicMigrationDocument> { - const { record: data, dependencies } = prepareMigrationDocumentData( + const data = prepareMigrationDocumentData( document.data, this.createAsset.bind(this), true, @@ -324,12 +324,12 @@ export class Migration { lang: document.lang, uid: document.uid, tags: document.tags, - data: data, + data, } as unknown as PendingPrismicDocument< ExtractDocumentType >, title, - { originalPrismicDocument: document, dependencies }, + { originalPrismicDocument: document }, ) this._documents.push(doc) diff --git a/src/WriteClient.ts b/src/WriteClient.ts index d1c46adc..5d29300f 100644 --- a/src/WriteClient.ts +++ b/src/WriteClient.ts @@ -1,5 +1,6 @@ import { devMsg } from "./lib/devMsg" import { pLimit } from "./lib/pLimit" +import { resolveMigrationDocumentData } from "./lib/resolveMigrationDocumentData" import type { Asset, @@ -432,8 +433,7 @@ export class WriteClient< if (doc.masterLanguageDocument) { const link = doc.masterLanguageDocument - await link._resolve(migration) - masterLanguageDocumentID = link._field?.id + masterLanguageDocumentID = (await link._resolve(migration))?.id } else if (doc.originalPrismicDocument) { masterLanguageDocumentID = doc.originalPrismicDocument.alternate_languages.find( @@ -488,13 +488,17 @@ export class WriteClient< }, }) - await doc._resolve(migration) - await this.updateDocument( doc.document.id!, // We need to forward again document name and tags to update them // in case the document already existed during the previous step. - doc.document, + { + ...doc.document, + data: await resolveMigrationDocumentData( + doc.document.data, + migration, + ), + }, fetchParams, ) } diff --git a/src/lib/prepareMigrationDocumentData.ts b/src/lib/prepareMigrationDocumentData.ts index 89dbcb18..0d0730e0 100644 --- a/src/lib/prepareMigrationDocumentData.ts +++ b/src/lib/prepareMigrationDocumentData.ts @@ -11,8 +11,7 @@ import type { FilledLinkToMediaField } from "../types/value/linkToMedia" import * as is from "./isValue" /** - * Replaces existings assets and links in a record of Prismic fields and get all - * dependencies to them. + * Replaces existings assets and links in a record of Prismic fields. * * @typeParam TRecord - Record of values to work with. * @@ -21,8 +20,7 @@ import * as is from "./isValue" * @param fromPrismic - Whether the record is from another Prismic repository or * not. * - * @returns An object containing the record with replaced assets and links and a - * list of dependencies found and/or created. + * @returns An object containing the record with replaced assets and links. */ export const prepareMigrationDocumentData = < // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -33,16 +31,14 @@ export const prepareMigrationDocumentData = < asset: FilledImageFieldImage | FilledLinkToMediaField, ) => MigrationImage, fromPrismic?: boolean, -): { record: TRecord; dependencies: MigrationField[] } => { +): TRecord => { const result = {} as Record - const dependencies: MigrationField[] = [] for (const key in record) { const field: unknown = record[key] if (field instanceof MigrationField) { // Existing migration fields - dependencies.push(field) result[key] = field } else if (fromPrismic && is.linkToMedia(field)) { // Link to media @@ -50,7 +46,6 @@ export const prepareMigrationDocumentData = < // @ts-expect-error - Future-proofing for link text const linkToMedia = onAsset(field).asLinkToMedia(field.text) - dependencies.push(linkToMedia) result[key] = linkToMedia } else if (fromPrismic && is.rtImageNode(field)) { // Rich text image nodes @@ -62,13 +57,12 @@ export const prepareMigrationDocumentData = < { linkTo: field.linkTo }, onAsset, fromPrismic, - ).record.linkTo as + ).linkTo as | MigrationContentRelationship | MigrationLinkToMedia | FilledLinkToWebField } - dependencies.push(rtImageNode) result[key] = rtImageNode } else if (fromPrismic && is.image(field)) { // Image fields @@ -91,7 +85,6 @@ export const prepareMigrationDocumentData = < } } - dependencies.push(image) result[key] = image } else if (fromPrismic && is.contentRelationship(field)) { // Content relationships @@ -102,27 +95,30 @@ export const prepareMigrationDocumentData = < field.text, ) - dependencies.push(contentRelationship) result[key] = contentRelationship } else if (Array.isArray(field)) { // Traverse arrays const array = [] for (const item of field) { - const { record, dependencies: itemDependencies } = - prepareMigrationDocumentData({ item }, onAsset, fromPrismic) + const record = prepareMigrationDocumentData( + { item }, + onAsset, + fromPrismic, + ) array.push(record.item) - dependencies.push(...itemDependencies) } result[key] = array } else if (field && typeof field === "object") { // Traverse objects - const { record, dependencies: fieldDependencies } = - prepareMigrationDocumentData({ ...field }, onAsset, fromPrismic) + const record = prepareMigrationDocumentData( + { ...field }, + onAsset, + fromPrismic, + ) - dependencies.push(...fieldDependencies) result[key] = record } else { // Primitives @@ -130,5 +126,5 @@ export const prepareMigrationDocumentData = < } } - return { record: result as TRecord, dependencies } + return result as TRecord } diff --git a/src/lib/resolveMigrationDocumentData.ts b/src/lib/resolveMigrationDocumentData.ts new file mode 100644 index 00000000..adbc4bf7 --- /dev/null +++ b/src/lib/resolveMigrationDocumentData.ts @@ -0,0 +1,49 @@ +import { MigrationField } from "../types/migration/Field" + +import type { Migration } from "../Migration" + +export async function resolveMigrationDocumentData( + input: unknown, + migration: Migration, +): Promise { + if (input === null) { + return input + } + + if (input instanceof MigrationField) { + return input._resolve(migration) + } + + // if (input instanceof PrismicMigrationDocument || isPrismicDocument(input)) { + // return resolveMigrationContentRelationship(input) + // } + + // if (typeof input === "function") { + // return await resolveMigrationDocumentData(await input()) + // } + + if (Array.isArray(input)) { + const res = [] + + for (const element of input) { + res.push(await resolveMigrationDocumentData(element, migration)) + } + + return res + } + + if (typeof input === "object") { + const res: Record = {} + + for (const key in input) { + res[key] = await resolveMigrationDocumentData( + input[key as keyof typeof input], + migration, + ) + } + + return res + } + + return input +} diff --git a/src/types/migration/Asset.ts b/src/types/migration/Asset.ts index a3eaafd9..3d4d3856 100644 --- a/src/types/migration/Asset.ts +++ b/src/types/migration/Asset.ts @@ -225,20 +225,22 @@ export class MigrationImage extends MigrationAsset { return this } - async _resolve(migration: Migration): Promise { + async _resolve( + migration: Migration, + ): Promise { const asset = migration._assets.get(this.config.id)?.asset if (asset) { - this._field = assetToImage(asset, this._initialField) + const field = assetToImage(asset, this._initialField) for (const name in this.#thumbnails) { - await this.#thumbnails[name]._resolve(migration) - - const thumbnail = this.#thumbnails[name]._field + const thumbnail = await this.#thumbnails[name]._resolve(migration) if (thumbnail) { - ;(this._field as ImageField)[name] = thumbnail + ;(field as ImageField)[name] = thumbnail } } + + return field } } } @@ -274,11 +276,11 @@ export class MigrationLinkToMedia extends MigrationAsset< this.text = text } - _resolve(migration: Migration): void { + _resolve(migration: Migration): LinkToMediaField<"filled"> | undefined { const asset = migration._assets.get(this.config.id)?.asset if (asset) { - this._field = assetToLinkToMedia(asset, this.text) + return assetToLinkToMedia(asset, this.text) } } } @@ -318,20 +320,16 @@ export class MigrationRTImageNode extends MigrationAsset { this.linkTo = linkTo } - async _resolve(migration: Migration): Promise { + async _resolve(migration: Migration): Promise { const asset = migration._assets.get(this.config.id)?.asset - if (this.linkTo instanceof MigrationField) { - await this.linkTo._resolve(migration) - } - if (asset) { - this._field = { + return { ...assetToImage(asset, this._initialField), type: RichTextNodeType.image, linkTo: this.linkTo instanceof MigrationField - ? this.linkTo._field + ? await this.linkTo._resolve(migration) : this.linkTo, } } diff --git a/src/types/migration/ContentRelationship.ts b/src/types/migration/ContentRelationship.ts index b3357da7..946da3e6 100644 --- a/src/types/migration/ContentRelationship.ts +++ b/src/types/migration/ContentRelationship.ts @@ -68,7 +68,9 @@ export class MigrationContentRelationship extends MigrationField { + async _resolve( + migration: Migration, + ): Promise { const config = typeof this.#unresolvedConfig === "function" ? await this.#unresolvedConfig() @@ -82,7 +84,7 @@ export class MigrationContentRelationship extends MigrationField - /** - * Asset and content relationship fields that this document depends on. - */ - #dependencies: MigrationField[] - /** * Creates a Prismic migration document instance. * @@ -132,38 +124,20 @@ export class PrismicMigrationDocument< * @param title - The name of the document displayed in the editor. * @param options - Parameters to create/update the document with on the * Migration API. - * @param dependencies - Asset and content relationship fields that this - * document depends on. * * @returns A Prismic migration document instance. */ constructor( document: MigrationDocument, title: string, - options: { + options?: { masterLanguageDocument?: MigrationContentRelationship originalPrismicDocument?: ExistingPrismicDocument - dependencies: MigrationField[] }, ) { this.document = document this.title = title - this.masterLanguageDocument = options.masterLanguageDocument - this.originalPrismicDocument = options.originalPrismicDocument - this.#dependencies = options.dependencies - } - - /** - * Resolves each dependencies of the document with the provided maps. - * - * @param migration - A migration instance with documents and assets to use - * for resolving the field's value - * - * @internal - */ - async _resolve(migration: Migration): Promise { - for (const dependency of this.#dependencies) { - await dependency._resolve(migration) - } + this.masterLanguageDocument = options?.masterLanguageDocument + this.originalPrismicDocument = options?.originalPrismicDocument } } diff --git a/src/types/migration/Field.ts b/src/types/migration/Field.ts index 2c098747..a53984ec 100644 --- a/src/types/migration/Field.ts +++ b/src/types/migration/Field.ts @@ -7,7 +7,12 @@ import type { RTBlockNode, RTInlineNode } from "../value/richText" /** * Interface for migration fields that can be resolved. */ -interface Resolvable { +interface Resolvable< + TField extends AnyRegularField | RTBlockNode | RTInlineNode = + | AnyRegularField + | RTBlockNode + | RTInlineNode, +> { /** * Resolves the field's value with the provided maps. * @@ -16,7 +21,9 @@ interface Resolvable { * * @internal */ - _resolve(migration: Migration): Promise | void + _resolve( + migration: Migration, + ): Promise | TField | undefined } /** @@ -33,13 +40,6 @@ export abstract class MigrationField< TInitialField = TField, > implements Resolvable { - /** - * The resolved field value. - * - * @internal - */ - _field?: TField - /** * The initial field value this migration field was created with. * @@ -58,16 +58,7 @@ export abstract class MigrationField< this._initialField = initialField } - /** - * Prepares the field to be stringified with {@link JSON.stringify} - * - * @returns The value of the field to be stringified. - * - * @internal - */ - toJSON(): TField | undefined { - return this._field - } - - abstract _resolve(migration: Migration): Promise | void + abstract _resolve( + migration: Migration, + ): Promise | TField | undefined } diff --git a/test/migration-createDocument.test.ts b/test/migration-createDocument.test.ts index c1199258..3ee412c4 100644 --- a/test/migration-createDocument.test.ts +++ b/test/migration-createDocument.test.ts @@ -17,6 +17,6 @@ it("creates a document", () => { migration.createDocument(document, documentTitle) expect(migration._documents[0]).toStrictEqual( - new PrismicMigrationDocument(document, documentTitle, { dependencies: [] }), + new PrismicMigrationDocument(document, documentTitle), ) }) diff --git a/test/migration-createDocumentFromPrismic.test.ts b/test/migration-createDocumentFromPrismic.test.ts index d26af3ea..d453f022 100644 --- a/test/migration-createDocumentFromPrismic.test.ts +++ b/test/migration-createDocumentFromPrismic.test.ts @@ -21,7 +21,6 @@ it("creates a document from an existing Prismic document", (ctx) => { { type, uid, lang, tags, data }, documentTitle, { - dependencies: [], originalPrismicDocument: document, }, ), diff --git a/test/migration-updateDocument.test.ts b/test/migration-updateDocument.test.ts index ea93fcdb..8c553c04 100644 --- a/test/migration-updateDocument.test.ts +++ b/test/migration-updateDocument.test.ts @@ -12,6 +12,6 @@ it("updates a document", (ctx) => { migration.updateDocument(document, documentTitle) expect(migration._documents[0]).toStrictEqual( - new PrismicMigrationDocument(document, documentTitle, { dependencies: [] }), + new PrismicMigrationDocument(document, documentTitle), ) }) From 3577499354e019bf1d62dd827ed1f74f9938cdd2 Mon Sep 17 00:00:00 2001 From: lihbr Date: Mon, 16 Sep 2024 11:49:29 +0200 Subject: [PATCH 10/13] refactor: remove `MigrationContentRelationship` class --- src/Migration.ts | 130 +++++--- src/WriteClient.ts | 10 +- src/lib/isValue.ts | 37 ++- src/lib/prepareMigrationDocumentData.ts | 130 -------- src/lib/resolveMigrationDocumentData.ts | 43 ++- src/types/migration/Asset.ts | 17 +- src/types/migration/ContentRelationship.ts | 101 +----- src/types/migration/Document.ts | 2 +- ...ate-patch-contentRelationship.test.ts.snap | 297 +----------------- ...ent-migrate-patch-rtImageNode.test.ts.snap | 76 ----- test/writeClient-migrate-documents.test.ts | 16 +- ...-migrate-patch-contentRelationship.test.ts | 38 ++- ...teClient-migrate-patch-rtImageNode.test.ts | 14 +- 13 files changed, 222 insertions(+), 689 deletions(-) delete mode 100644 src/lib/prepareMigrationDocumentData.ts diff --git a/src/Migration.ts b/src/Migration.ts index dce1be98..4f44ae6b 100644 --- a/src/Migration.ts +++ b/src/Migration.ts @@ -1,12 +1,14 @@ -import { prepareMigrationDocumentData } from "./lib/prepareMigrationDocumentData" +import * as is from "./lib/isValue" import { validateAssetMetadata } from "./lib/validateAssetMetadata" import type { Asset } from "./types/api/asset/asset" -import type { MigrationAssetConfig } from "./types/migration/Asset" +import type { + MigrationAssetConfig, + MigrationLinkToMedia, +} from "./types/migration/Asset" import type { MigrationAsset } from "./types/migration/Asset" import { MigrationImage } from "./types/migration/Asset" -import type { UnresolvedMigrationContentRelationshipConfig } from "./types/migration/ContentRelationship" -import { MigrationContentRelationship } from "./types/migration/ContentRelationship" +import type { MigrationContentRelationship } from "./types/migration/ContentRelationship" import { PrismicMigrationDocument } from "./types/migration/Document" import type { ExistingPrismicDocument, @@ -14,6 +16,7 @@ import type { } from "./types/migration/Document" import type { PrismicDocument } from "./types/value/document" import type { FilledImageFieldImage } from "./types/value/image" +import type { FilledLinkToWebField } from "./types/value/link" import type { FilledLinkToMediaField } from "./types/value/linkToMedia" /** @@ -245,14 +248,9 @@ export class Migration { masterLanguageDocument?: MigrationContentRelationship }, ): PrismicMigrationDocument> { - const data = prepareMigrationDocumentData( - document.data!, - this.createAsset.bind(this), - ) - const doc = new PrismicMigrationDocument< ExtractDocumentType - >({ ...document, data }, title, options) + >(document, title, options) this._documents.push(doc) @@ -279,14 +277,9 @@ export class Migration { document: ExtractDocumentType, TType>, title: string, ): PrismicMigrationDocument> { - const data = prepareMigrationDocumentData( - document.data, - this.createAsset.bind(this), - ) - const doc = new PrismicMigrationDocument< ExtractDocumentType - >({ ...document, data }, title) + >(document, title) this._documents.push(doc) @@ -312,22 +305,14 @@ export class Migration { document: ExtractDocumentType, TType>, title: string, ): PrismicMigrationDocument> { - const data = prepareMigrationDocumentData( - document.data, - this.createAsset.bind(this), - true, - ) - const doc = new PrismicMigrationDocument( - { + this.#migratePrismicDocumentData({ type: document.type, lang: document.lang, uid: document.uid, tags: document.tags, - data, - } as unknown as PendingPrismicDocument< - ExtractDocumentType - >, + data: document.data, + }) as PendingPrismicDocument>, title, { originalPrismicDocument: document }, ) @@ -337,24 +322,6 @@ export class Migration { return doc } - /** - * Creates a content relationship fields that can be used in documents to link - * to other documents. - * - * @param config - A Prismic document, a migration document instance, an - * existing content relationship field's content, or a function that returns - * one of the previous. - * @param text - Link text associated with the content relationship field. - * - * @returns A migration content relationship field instance. - */ - createContentRelationship( - config: UnresolvedMigrationContentRelationshipConfig, - text?: string, - ): MigrationContentRelationship { - return new MigrationContentRelationship(config, text, undefined) - } - /** * Queries a document from the migration instance with a specific UID and * custom type. @@ -423,6 +390,77 @@ export class Migration { ) } + #migratePrismicDocumentData(input: unknown): unknown { + if (is.filledContentRelationship(input)) { + if (input.isBroken) { + return { link_type: "Document", id: "__broken__", isBroken: true } + } + + return () => this.#getByOriginalID(input.id) + } + + if (is.filledLinkToMedia(input)) { + // TODO: Remove when link text PR is merged + // @ts-expect-error - Future-proofing for link text + return this.createAsset(input).asLinkToMedia(input.text) + } + + if (is.rtImageNode(input)) { + // Rich text image nodes + const rtImageNode = this.createAsset(input).asRTImageNode() + + if (input.linkTo) { + // Node `linkTo` dependency is tracked internally + rtImageNode.linkTo = this.#migratePrismicDocumentData(input.linkTo) as + | MigrationContentRelationship + | MigrationLinkToMedia + | FilledLinkToWebField + } + + return rtImageNode + } + + if (is.filledImage(input)) { + const image = this.createAsset(input) + + const { + id: _id, + url: _url, + dimensions: _dimensions, + edit: _edit, + alt: _alt, + copyright: _copyright, + ...thumbnails + } = input + + for (const name in thumbnails) { + if (is.filledImage(thumbnails[name])) { + image.addThumbnail(name, this.createAsset(thumbnails[name])) + } + } + + return image + } + + if (Array.isArray(input)) { + return input.map((element) => this.#migratePrismicDocumentData(element)) + } + + if (input && typeof input === "object") { + const res: Record = {} + + for (const key in input) { + res[key] = this.#migratePrismicDocumentData( + input[key as keyof typeof input], + ) + } + + return res + } + + return input + } + /** * Queries a document from the migration instance for a specific original ID. * @@ -441,7 +479,7 @@ export class Migration { * @returns The migration document instance for the original ID, if a matching * document is found. */ - getByOriginalID( + #getByOriginalID( id: string, ): | PrismicMigrationDocument> diff --git a/src/WriteClient.ts b/src/WriteClient.ts index 5d29300f..32cce269 100644 --- a/src/WriteClient.ts +++ b/src/WriteClient.ts @@ -1,6 +1,9 @@ import { devMsg } from "./lib/devMsg" import { pLimit } from "./lib/pLimit" -import { resolveMigrationDocumentData } from "./lib/resolveMigrationDocumentData" +import { + resolveMigrationContentRelationship, + resolveMigrationDocumentData, +} from "./lib/resolveMigrationDocumentData" import type { Asset, @@ -431,9 +434,10 @@ export class WriteClient< // Resolve master language document ID for non-master locale documents let masterLanguageDocumentID: string | undefined if (doc.masterLanguageDocument) { - const link = doc.masterLanguageDocument + const masterLanguageDocument = + await resolveMigrationContentRelationship(doc.masterLanguageDocument) - masterLanguageDocumentID = (await link._resolve(migration))?.id + masterLanguageDocumentID = masterLanguageDocument?.id } else if (doc.originalPrismicDocument) { masterLanguageDocumentID = doc.originalPrismicDocument.alternate_languages.find( diff --git a/src/lib/isValue.ts b/src/lib/isValue.ts index 90b72cbc..c4b5bd11 100644 --- a/src/lib/isValue.ts +++ b/src/lib/isValue.ts @@ -30,7 +30,7 @@ type UnknownValue = * @internal * This is not an official helper function and it's only designed to work with internal processes. */ -export const linkToMedia = ( +export const filledLinkToMedia = ( value: UnknownValue, ): value is FilledLinkToMediaField => { if (value && typeof value === "object" && !("version" in value)) { @@ -96,7 +96,7 @@ const imageLike = ( * @internal * This is not an official helper function and it's only designed to work with internal processes. */ -export const image = ( +export const filledImage = ( value: UnknownValue, ): value is ImageField => { if ( @@ -145,7 +145,7 @@ export const rtImageNode = (value: UnknownValue): value is RTImageNode => { * @internal * This is not an official helper function and it's only designed to work with internal processes. */ -export const contentRelationship = ( +export const filledContentRelationship = ( value: UnknownValue, ): value is FilledContentRelationshipField => { if (value && typeof value === "object" && !("version" in value)) { @@ -163,3 +163,34 @@ export const contentRelationship = ( return false } + +/** + * Checks if a value is a Prismic document. + * + * @param value - Value to check. + * + * @returns `true` if `value` is a Prismic document, `false` otherwise. + * + * @internal + * This is not an official helper function and it's only designed to work with internal processes. + */ +export const prismicDocument = ( + value: UnknownValue, +): value is PrismicDocument => { + try { + return ( + typeof value === "object" && + value !== null && + "id" in value && + "href" in value && + typeof value.href === "string" && + new URL(value.href) && + "type" in value && + "lang" in value && + "tags" in value && + Array.isArray(value.tags) + ) + } catch { + return false + } +} diff --git a/src/lib/prepareMigrationDocumentData.ts b/src/lib/prepareMigrationDocumentData.ts deleted file mode 100644 index 0d0730e0..00000000 --- a/src/lib/prepareMigrationDocumentData.ts +++ /dev/null @@ -1,130 +0,0 @@ -import type { - MigrationImage, - MigrationLinkToMedia, -} from "../types/migration/Asset" -import { MigrationContentRelationship } from "../types/migration/ContentRelationship" -import { MigrationField } from "../types/migration/Field" -import type { FilledImageFieldImage } from "../types/value/image" -import type { FilledLinkToWebField } from "../types/value/link" -import type { FilledLinkToMediaField } from "../types/value/linkToMedia" - -import * as is from "./isValue" - -/** - * Replaces existings assets and links in a record of Prismic fields. - * - * @typeParam TRecord - Record of values to work with. - * - * @param record - Record of Prismic fields to work with. - * @param onAsset - Callback that is called for each asset found. - * @param fromPrismic - Whether the record is from another Prismic repository or - * not. - * - * @returns An object containing the record with replaced assets and links. - */ -export const prepareMigrationDocumentData = < - // eslint-disable-next-line @typescript-eslint/no-explicit-any - TRecord extends Record, ->( - record: TRecord, - onAsset: ( - asset: FilledImageFieldImage | FilledLinkToMediaField, - ) => MigrationImage, - fromPrismic?: boolean, -): TRecord => { - const result = {} as Record - - for (const key in record) { - const field: unknown = record[key] - - if (field instanceof MigrationField) { - // Existing migration fields - result[key] = field - } else if (fromPrismic && is.linkToMedia(field)) { - // Link to media - // TODO: Remove when link text PR is merged - // @ts-expect-error - Future-proofing for link text - const linkToMedia = onAsset(field).asLinkToMedia(field.text) - - result[key] = linkToMedia - } else if (fromPrismic && is.rtImageNode(field)) { - // Rich text image nodes - const rtImageNode = onAsset(field).asRTImageNode() - - if (field.linkTo) { - // Node `linkTo` dependency is tracked internally - rtImageNode.linkTo = prepareMigrationDocumentData( - { linkTo: field.linkTo }, - onAsset, - fromPrismic, - ).linkTo as - | MigrationContentRelationship - | MigrationLinkToMedia - | FilledLinkToWebField - } - - result[key] = rtImageNode - } else if (fromPrismic && is.image(field)) { - // Image fields - const image = onAsset(field).asImage() - - const { - id: _id, - url: _url, - dimensions: _dimensions, - edit: _edit, - alt: _alt, - copyright: _copyright, - ...thumbnails - } = field - - for (const name in thumbnails) { - if (is.image(thumbnails[name])) { - // Node thumbnails dependencies are tracked internally - image.addThumbnail(name, onAsset(thumbnails[name]).asImage()) - } - } - - result[key] = image - } else if (fromPrismic && is.contentRelationship(field)) { - // Content relationships - const contentRelationship = new MigrationContentRelationship( - field, - // TODO: Remove when link text PR is merged - // @ts-expect-error - Future-proofing for link text - field.text, - ) - - result[key] = contentRelationship - } else if (Array.isArray(field)) { - // Traverse arrays - const array = [] - - for (const item of field) { - const record = prepareMigrationDocumentData( - { item }, - onAsset, - fromPrismic, - ) - - array.push(record.item) - } - - result[key] = array - } else if (field && typeof field === "object") { - // Traverse objects - const record = prepareMigrationDocumentData( - { ...field }, - onAsset, - fromPrismic, - ) - - result[key] = record - } else { - // Primitives - result[key] = field - } - } - - return result as TRecord -} diff --git a/src/lib/resolveMigrationDocumentData.ts b/src/lib/resolveMigrationDocumentData.ts index adbc4bf7..7df8b8f0 100644 --- a/src/lib/resolveMigrationDocumentData.ts +++ b/src/lib/resolveMigrationDocumentData.ts @@ -1,26 +1,47 @@ +import type { + MigrationContentRelationship, + MigrationContentRelationshipField, +} from "../types/migration/ContentRelationship" +import { PrismicMigrationDocument } from "../types/migration/Document" import { MigrationField } from "../types/migration/Field" import type { Migration } from "../Migration" +import * as is from "./isValue" + +export async function resolveMigrationContentRelationship( + relation: MigrationContentRelationship, +): Promise { + if (typeof relation === "function") { + return resolveMigrationContentRelationship(await relation()) + } + + if (relation instanceof PrismicMigrationDocument) { + return relation.document.id + ? { link_type: "Document", id: relation.document.id } + : undefined + } + + if (relation) { + return { link_type: "Document", id: relation.id } + } +} + export async function resolveMigrationDocumentData( input: unknown, migration: Migration, ): Promise { - if (input === null) { - return input - } - if (input instanceof MigrationField) { return input._resolve(migration) } - // if (input instanceof PrismicMigrationDocument || isPrismicDocument(input)) { - // return resolveMigrationContentRelationship(input) - // } + if (input instanceof PrismicMigrationDocument || is.prismicDocument(input)) { + return resolveMigrationContentRelationship(input) + } - // if (typeof input === "function") { - // return await resolveMigrationDocumentData(await input()) - // } + if (typeof input === "function") { + return await resolveMigrationDocumentData(await input(), migration) + } if (Array.isArray(input)) { const res = [] @@ -32,7 +53,7 @@ export async function resolveMigrationDocumentData( return res } - if (typeof input === "object") { + if (input && typeof input === "object") { const res: Record = {} for (const key in input) { diff --git a/src/types/migration/Asset.ts b/src/types/migration/Asset.ts index 3d4d3856..e6a1e069 100644 --- a/src/types/migration/Asset.ts +++ b/src/types/migration/Asset.ts @@ -1,9 +1,15 @@ +import { resolveMigrationDocumentData } from "../../lib/resolveMigrationDocumentData" + import type { Migration } from "../../Migration" import type { Asset } from "../api/asset/asset" +import type { FilledContentRelationshipField } from "../value/contentRelationship" import type { FilledImageFieldImage, ImageField } from "../value/image" import { type FilledLinkToWebField, LinkType } from "../value/link" -import type { LinkToMediaField } from "../value/linkToMedia" +import type { + FilledLinkToMediaField, + LinkToMediaField, +} from "../value/linkToMedia" import { type RTImageNode, RichTextNodeType } from "../value/richText" import type { MigrationContentRelationship } from "./ContentRelationship" @@ -327,10 +333,11 @@ export class MigrationRTImageNode extends MigrationAsset { return { ...assetToImage(asset, this._initialField), type: RichTextNodeType.image, - linkTo: - this.linkTo instanceof MigrationField - ? await this.linkTo._resolve(migration) - : this.linkTo, + linkTo: (await resolveMigrationDocumentData(this.linkTo, migration)) as + | FilledLinkToWebField + | FilledLinkToMediaField + | FilledContentRelationshipField + | undefined, } } } diff --git a/src/types/migration/ContentRelationship.ts b/src/types/migration/ContentRelationship.ts index 946da3e6..17177672 100644 --- a/src/types/migration/ContentRelationship.ts +++ b/src/types/migration/ContentRelationship.ts @@ -1,102 +1,21 @@ -import type { Migration } from "../../Migration" - import type { FilledContentRelationshipField } from "../value/contentRelationship" import type { PrismicDocument } from "../value/document" -import { LinkType } from "../value/link" -import { PrismicMigrationDocument } from "./Document" -import { MigrationField } from "./Field" +import type { PrismicMigrationDocument } from "./Document" -/** - * Configuration used to create a content relationship field in a migration. - */ -type MigrationContentRelationshipConfig< - TDocuments extends PrismicDocument = PrismicDocument, -> = - | TDocuments - | PrismicMigrationDocument - | FilledContentRelationshipField - | undefined +type ValueOrThunk = T | (() => Promise | T) /** - * Unresolved configuration used to create a content relationship field in a - * migration allowing for lazy resolution. + * A content relationship field in a migration. */ -export type UnresolvedMigrationContentRelationshipConfig< +export type MigrationContentRelationship< TDocuments extends PrismicDocument = PrismicDocument, -> = - | MigrationContentRelationshipConfig - | (() => - | Promise> - | MigrationContentRelationshipConfig) +> = ValueOrThunk | undefined> /** - * A migration content relationship field used with the Prismic Migration API. + * The minimum amount of information needed to represent a content relationship + * field with the migration API. */ -export class MigrationContentRelationship extends MigrationField { - /** - * Unresolved configuration used to resolve the content relationship field's - * value - */ - #unresolvedConfig: UnresolvedMigrationContentRelationshipConfig - - /** - * Link text for the content relationship if any. - */ - text?: string - - /** - * Creates a migration content relationship field used with the Prismic - * Migration API. - * - * @param unresolvedConfig - A Prismic document, a migration document - * instance, an existing content relationship field's content, or a function - * that returns one of the previous. - * @param text - Link text for the content relationship if any. - * @param initialField - The initial field value if any. - * - * @returns A migration content relationship field instance. - */ - constructor( - unresolvedConfig: UnresolvedMigrationContentRelationshipConfig, - text?: string, - initialField?: FilledContentRelationshipField, - ) { - super(initialField) - - this.#unresolvedConfig = unresolvedConfig - this.text = text - } - - async _resolve( - migration: Migration, - ): Promise { - const config = - typeof this.#unresolvedConfig === "function" - ? await this.#unresolvedConfig() - : this.#unresolvedConfig - - if (config) { - const document = - config instanceof PrismicMigrationDocument - ? config.document - : // Not sure we need `getByOriginalID` here - migration.getByOriginalID(config.id)?.document || config - - if (document?.id) { - return { - link_type: LinkType.Document, - id: document.id, - uid: document.uid || undefined, - type: document.type, - tags: document.tags || [], - lang: document.lang, - isBroken: false, - // TODO: Remove when link text PR is merged - // @ts-expect-error - Future-proofing for link text - text: this.text, - } - } - } - } -} +export type MigrationContentRelationshipField = + | Pick + | undefined diff --git a/src/types/migration/Document.ts b/src/types/migration/Document.ts index fd1d0889..2bd1b5ea 100644 --- a/src/types/migration/Document.ts +++ b/src/types/migration/Document.ts @@ -24,7 +24,7 @@ export type InjectMigrationSpecificTypes = T extends RTImageNode : T extends FilledLinkToMediaField ? T | MigrationLinkToMedia | undefined : T extends FilledContentRelationshipField - ? T | MigrationContentRelationship | undefined + ? T | MigrationContentRelationship : // eslint-disable-next-line @typescript-eslint/no-explicit-any T extends Record ? { [P in keyof T]: InjectMigrationSpecificTypes } diff --git a/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap index 01048f6a..ff7b4689 100644 --- a/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap @@ -5,8 +5,9 @@ exports[`patches link fields > brokenLink > group 1`] = ` "group": [ { "field": { + "id": "__broken__", "isBroken": true, - "type": "Document", + "link_type": "Document", }, }, ], @@ -21,21 +22,24 @@ exports[`patches link fields > brokenLink > shared slice 1`] = ` "items": [ { "field": { + "id": "__broken__", "isBroken": true, - "type": "Document", + "link_type": "Document", }, }, ], "primary": { "field": { + "id": "__broken__", "isBroken": true, - "type": "Document", + "link_type": "Document", }, "group": [ { "field": { + "id": "__broken__", "isBroken": true, - "type": "Document", + "link_type": "Document", }, }, ], @@ -57,15 +61,17 @@ exports[`patches link fields > brokenLink > slice 1`] = ` "items": [ { "field": { + "id": "__broken__", "isBroken": true, - "type": "Document", + "link_type": "Document", }, }, ], "primary": { "field": { + "id": "__broken__", "isBroken": true, - "type": "Document", + "link_type": "Document", }, }, "slice_label": "Aliquet", @@ -78,8 +84,9 @@ exports[`patches link fields > brokenLink > slice 1`] = ` exports[`patches link fields > brokenLink > static zone 1`] = ` { "field": { + "id": "__broken__", "isBroken": true, - "type": "Document", + "link_type": "Document", }, } `; @@ -90,11 +97,7 @@ exports[`patches link fields > existing > group 1`] = ` { "field": { "id": "id-existing", - "isBroken": false, - "lang": "laoreet", "link_type": "Document", - "tags": [], - "type": "orci", }, }, ], @@ -110,38 +113,20 @@ exports[`patches link fields > existing > shared slice 1`] = ` { "field": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, }, ], "primary": { "field": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, "group": [ { "field": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, }, ], @@ -164,26 +149,14 @@ exports[`patches link fields > existing > slice 1`] = ` { "field": { "id": "id-existing", - "isBroken": false, - "lang": "sapien", "link_type": "Document", - "tags": [ - "Aenean", - ], - "type": "amet", }, }, ], "primary": { "field": { "id": "id-existing", - "isBroken": false, - "lang": "sapien", "link_type": "Document", - "tags": [ - "Aenean", - ], - "type": "amet", }, }, "slice_label": "Aliquet", @@ -197,11 +170,7 @@ exports[`patches link fields > existing > static zone 1`] = ` { "field": { "id": "id-existing", - "isBroken": false, - "lang": "eget", "link_type": "Document", - "tags": [], - "type": "phasellus", }, } `; @@ -212,11 +181,7 @@ exports[`patches link fields > lazyExisting > group 1`] = ` { "field": { "id": "id-existing", - "isBroken": false, - "lang": "laoreet", "link_type": "Document", - "tags": [], - "type": "orci", }, }, ], @@ -232,38 +197,20 @@ exports[`patches link fields > lazyExisting > shared slice 1`] = ` { "field": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, }, ], "primary": { "field": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, "group": [ { "field": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, }, ], @@ -286,26 +233,14 @@ exports[`patches link fields > lazyExisting > slice 1`] = ` { "field": { "id": "id-existing", - "isBroken": false, - "lang": "sapien", "link_type": "Document", - "tags": [ - "Aenean", - ], - "type": "amet", }, }, ], "primary": { "field": { "id": "id-existing", - "isBroken": false, - "lang": "sapien", "link_type": "Document", - "tags": [ - "Aenean", - ], - "type": "amet", }, }, "slice_label": "Aliquet", @@ -319,11 +254,7 @@ exports[`patches link fields > lazyExisting > static zone 1`] = ` { "field": { "id": "id-existing", - "isBroken": false, - "lang": "eget", "link_type": "Document", - "tags": [], - "type": "phasellus", }, } `; @@ -334,14 +265,7 @@ exports[`patches link fields > lazyMigration > group 1`] = ` { "field": { "id": "id-other", - "isBroken": false, - "lang": "a", "link_type": "Document", - "tags": [ - "Odio Eu", - ], - "type": "amet", - "uid": "Non sodales neque", }, }, ], @@ -357,35 +281,20 @@ exports[`patches link fields > lazyMigration > shared slice 1`] = ` { "field": { "id": "id-other", - "isBroken": false, - "lang": "gravida", "link_type": "Document", - "tags": [], - "type": "leo", - "uid": "Blandit volutpat maecenas", }, }, ], "primary": { "field": { "id": "id-other", - "isBroken": false, - "lang": "gravida", "link_type": "Document", - "tags": [], - "type": "leo", - "uid": "Blandit volutpat maecenas", }, "group": [ { "field": { "id": "id-other", - "isBroken": false, - "lang": "gravida", "link_type": "Document", - "tags": [], - "type": "leo", - "uid": "Blandit volutpat maecenas", }, }, ], @@ -408,28 +317,14 @@ exports[`patches link fields > lazyMigration > slice 1`] = ` { "field": { "id": "id-other", - "isBroken": false, - "lang": "ultrices", "link_type": "Document", - "tags": [ - "Ipsum Consequat", - ], - "type": "eget", - "uid": "Amet dictum sit", }, }, ], "primary": { "field": { "id": "id-other", - "isBroken": false, - "lang": "ultrices", "link_type": "Document", - "tags": [ - "Ipsum Consequat", - ], - "type": "eget", - "uid": "Amet dictum sit", }, }, "slice_label": "Aliquet", @@ -443,12 +338,7 @@ exports[`patches link fields > lazyMigration > static zone 1`] = ` { "field": { "id": "id-other", - "isBroken": false, - "lang": "nisi,", "link_type": "Document", - "tags": [], - "type": "eros", - "uid": "Scelerisque mauris pellentesque", }, } `; @@ -459,14 +349,7 @@ exports[`patches link fields > migration > group 1`] = ` { "field": { "id": "id-other", - "isBroken": false, - "lang": "a", "link_type": "Document", - "tags": [ - "Odio Eu", - ], - "type": "amet", - "uid": "Non sodales neque", }, }, ], @@ -482,35 +365,20 @@ exports[`patches link fields > migration > shared slice 1`] = ` { "field": { "id": "id-other", - "isBroken": false, - "lang": "gravida", "link_type": "Document", - "tags": [], - "type": "leo", - "uid": "Blandit volutpat maecenas", }, }, ], "primary": { "field": { "id": "id-other", - "isBroken": false, - "lang": "gravida", "link_type": "Document", - "tags": [], - "type": "leo", - "uid": "Blandit volutpat maecenas", }, "group": [ { "field": { "id": "id-other", - "isBroken": false, - "lang": "gravida", "link_type": "Document", - "tags": [], - "type": "leo", - "uid": "Blandit volutpat maecenas", }, }, ], @@ -533,28 +401,14 @@ exports[`patches link fields > migration > slice 1`] = ` { "field": { "id": "id-other", - "isBroken": false, - "lang": "ultrices", "link_type": "Document", - "tags": [ - "Ipsum Consequat", - ], - "type": "eget", - "uid": "Amet dictum sit", }, }, ], "primary": { "field": { "id": "id-other", - "isBroken": false, - "lang": "ultrices", "link_type": "Document", - "tags": [ - "Ipsum Consequat", - ], - "type": "eget", - "uid": "Amet dictum sit", }, }, "slice_label": "Aliquet", @@ -568,12 +422,7 @@ exports[`patches link fields > migration > static zone 1`] = ` { "field": { "id": "id-other", - "isBroken": false, - "lang": "nisi,", "link_type": "Document", - "tags": [], - "type": "eros", - "uid": "Scelerisque mauris pellentesque", }, } `; @@ -584,12 +433,7 @@ exports[`patches link fields > migrationNoTags > group 1`] = ` { "field": { "id": "id-other", - "isBroken": false, - "lang": "a", "link_type": "Document", - "tags": [], - "type": "amet", - "uid": "Non sodales neque", }, }, ], @@ -605,35 +449,20 @@ exports[`patches link fields > migrationNoTags > shared slice 1`] = ` { "field": { "id": "id-other", - "isBroken": false, - "lang": "gravida", "link_type": "Document", - "tags": [], - "type": "leo", - "uid": "Blandit volutpat maecenas", }, }, ], "primary": { "field": { "id": "id-other", - "isBroken": false, - "lang": "gravida", "link_type": "Document", - "tags": [], - "type": "leo", - "uid": "Blandit volutpat maecenas", }, "group": [ { "field": { "id": "id-other", - "isBroken": false, - "lang": "gravida", "link_type": "Document", - "tags": [], - "type": "leo", - "uid": "Blandit volutpat maecenas", }, }, ], @@ -656,24 +485,14 @@ exports[`patches link fields > migrationNoTags > slice 1`] = ` { "field": { "id": "id-other", - "isBroken": false, - "lang": "ultrices", "link_type": "Document", - "tags": [], - "type": "eget", - "uid": "Amet dictum sit", }, }, ], "primary": { "field": { "id": "id-other", - "isBroken": false, - "lang": "ultrices", "link_type": "Document", - "tags": [], - "type": "eget", - "uid": "Amet dictum sit", }, }, "slice_label": "Aliquet", @@ -687,12 +506,7 @@ exports[`patches link fields > migrationNoTags > static zone 1`] = ` { "field": { "id": "id-other", - "isBroken": false, - "lang": "nisi,", "link_type": "Document", - "tags": [], - "type": "eros", - "uid": "Scelerisque mauris pellentesque", }, } `; @@ -703,12 +517,7 @@ exports[`patches link fields > otherRepositoryContentRelationship > group 1`] = { "field": { "id": "id-other-repository", - "isBroken": false, - "lang": "faucibus", "link_type": "Document", - "tags": [], - "type": "lorem", - "uid": "Pharetra et ultrices", }, }, ], @@ -724,41 +533,20 @@ exports[`patches link fields > otherRepositoryContentRelationship > shared slice { "field": { "id": "id-other-repository", - "isBroken": false, - "lang": "eu", "link_type": "Document", - "tags": [ - "Pharetra", - ], - "type": "pellentesque", - "uid": "Volutpat ac tincidunt", }, }, ], "primary": { "field": { "id": "id-other-repository", - "isBroken": false, - "lang": "eu", "link_type": "Document", - "tags": [ - "Pharetra", - ], - "type": "pellentesque", - "uid": "Volutpat ac tincidunt", }, "group": [ { "field": { "id": "id-other-repository", - "isBroken": false, - "lang": "eu", "link_type": "Document", - "tags": [ - "Pharetra", - ], - "type": "pellentesque", - "uid": "Volutpat ac tincidunt", }, }, ], @@ -781,28 +569,14 @@ exports[`patches link fields > otherRepositoryContentRelationship > slice 1`] = { "field": { "id": "id-other-repository", - "isBroken": false, - "lang": "dignissim", "link_type": "Document", - "tags": [ - "Arcu Vitae", - ], - "type": "a", - "uid": "Tristique senectus et", }, }, ], "primary": { "field": { "id": "id-other-repository", - "isBroken": false, - "lang": "dignissim", "link_type": "Document", - "tags": [ - "Arcu Vitae", - ], - "type": "a", - "uid": "Tristique senectus et", }, }, "slice_label": "Aliquet", @@ -816,12 +590,7 @@ exports[`patches link fields > otherRepositoryContentRelationship > static zone { "field": { "id": "id-other-repository", - "isBroken": false, - "lang": "quam", "link_type": "Document", - "tags": [], - "type": "semper", - "uid": "Sed viverra ipsum", }, } `; @@ -841,11 +610,7 @@ exports[`patches link fields > richTextLinkNode > group 1`] = ` { "data": { "id": "id-existing", - "isBroken": false, - "lang": "laoreet", "link_type": "Document", - "tags": [], - "type": "orci", }, "end": 5, "start": 0, @@ -879,13 +644,7 @@ exports[`patches link fields > richTextLinkNode > shared slice 1`] = ` { "data": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, "end": 5, "start": 0, @@ -910,13 +669,7 @@ exports[`patches link fields > richTextLinkNode > shared slice 1`] = ` { "data": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, "end": 5, "start": 0, @@ -940,13 +693,7 @@ exports[`patches link fields > richTextLinkNode > shared slice 1`] = ` { "data": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, "end": 5, "start": 0, @@ -987,13 +734,7 @@ exports[`patches link fields > richTextLinkNode > slice 1`] = ` { "data": { "id": "id-existing", - "isBroken": false, - "lang": "sapien", "link_type": "Document", - "tags": [ - "Aenean", - ], - "type": "amet", }, "end": 5, "start": 0, @@ -1018,13 +759,7 @@ exports[`patches link fields > richTextLinkNode > slice 1`] = ` { "data": { "id": "id-existing", - "isBroken": false, - "lang": "sapien", "link_type": "Document", - "tags": [ - "Aenean", - ], - "type": "amet", }, "end": 5, "start": 0, @@ -1056,11 +791,7 @@ exports[`patches link fields > richTextLinkNode > static zone 1`] = ` { "data": { "id": "id-existing", - "isBroken": false, - "lang": "eget", "link_type": "Document", - "tags": [], - "type": "phasellus", }, "end": 5, "start": 0, diff --git a/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap index 6e445ca2..5df8c17c 100644 --- a/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap @@ -474,11 +474,7 @@ exports[`patches rich text image nodes > newLinkTo > group 1`] = ` "id": "c1d5d24feae", "linkTo": { "id": "id-existing", - "isBroken": false, - "lang": "laoreet", "link_type": "Document", - "tags": [], - "type": "orci", }, "type": "image", "url": "https://images.unsplash.com/photo-1504198266287-1659872e6590?w=4272&h=2848&fit=crop", @@ -518,13 +514,7 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "id": "961adcf1f5d", "linkTo": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, "type": "image", "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", @@ -555,13 +545,7 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "id": "961adcf1f5d", "linkTo": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, "type": "image", "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", @@ -591,13 +575,7 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "id": "961adcf1f5d", "linkTo": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, "type": "image", "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", @@ -644,13 +622,7 @@ exports[`patches rich text image nodes > newLinkTo > slice 1`] = ` "id": "61cc54f4a69", "linkTo": { "id": "id-existing", - "isBroken": false, - "lang": "sapien", "link_type": "Document", - "tags": [ - "Aenean", - ], - "type": "amet", }, "type": "image", "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", @@ -681,13 +653,7 @@ exports[`patches rich text image nodes > newLinkTo > slice 1`] = ` "id": "61cc54f4a69", "linkTo": { "id": "id-existing", - "isBroken": false, - "lang": "sapien", "link_type": "Document", - "tags": [ - "Aenean", - ], - "type": "amet", }, "type": "image", "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", @@ -725,11 +691,7 @@ exports[`patches rich text image nodes > newLinkTo > static zone 1`] = ` "id": "ed908b1e225", "linkTo": { "id": "id-existing", - "isBroken": false, - "lang": "eget", "link_type": "Document", - "tags": [], - "type": "phasellus", }, "type": "image", "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?w=6000&h=4000&fit=crop", @@ -999,11 +961,7 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > group 1`] = ` "id": "6442e21ad60", "linkTo": { "id": "id-existing", - "isBroken": false, - "lang": "laoreet", "link_type": "Document", - "tags": [], - "type": "orci", }, "type": "image", "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05", @@ -1054,13 +1012,7 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > shared slice 1` "id": "3a8ec9378bc", "linkTo": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, "type": "image", "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", @@ -1091,13 +1043,7 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > shared slice 1` "id": "3a8ec9378bc", "linkTo": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, "type": "image", "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", @@ -1127,13 +1073,7 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > shared slice 1` "id": "3a8ec9378bc", "linkTo": { "id": "id-existing", - "isBroken": false, - "lang": "tortor,", "link_type": "Document", - "tags": [ - "Risus In", - ], - "type": "dui", }, "type": "image", "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", @@ -1180,13 +1120,7 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > slice 1`] = ` "id": "2003a644c30", "linkTo": { "id": "id-existing", - "isBroken": false, - "lang": "sapien", "link_type": "Document", - "tags": [ - "Aenean", - ], - "type": "amet", }, "type": "image", "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", @@ -1217,13 +1151,7 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > slice 1`] = ` "id": "2003a644c30", "linkTo": { "id": "id-existing", - "isBroken": false, - "lang": "sapien", "link_type": "Document", - "tags": [ - "Aenean", - ], - "type": "amet", }, "type": "image", "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", @@ -1261,11 +1189,7 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > static zone 1`] "id": "ff1efb2b271", "linkTo": { "id": "id-existing", - "isBroken": false, - "lang": "eget", "link_type": "Document", - "tags": [], - "type": "phasellus", }, "type": "image", "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1", diff --git a/test/writeClient-migrate-documents.test.ts b/test/writeClient-migrate-documents.test.ts index 8d10f287..af48bfc9 100644 --- a/test/writeClient-migrate-documents.test.ts +++ b/test/writeClient-migrate-documents.test.ts @@ -138,9 +138,7 @@ it.concurrent( const migration = prismic.createMigration() const doc = migration.createDocument(document, "foo", { - masterLanguageDocument: migration.createContentRelationship( - masterLanguageDocument, - ), + masterLanguageDocument, }) const reporter = vi.fn() @@ -190,9 +188,7 @@ it.concurrent( "foo", ) const doc = migration.createDocument(document, "bar", { - masterLanguageDocument: migration.createContentRelationship( - masterLanguageMigrationDocument, - ), + masterLanguageDocument: masterLanguageMigrationDocument, }) const reporter = vi.fn() @@ -232,9 +228,7 @@ it.concurrent( const migration = prismic.createMigration() const doc = migration.createDocument(document, "foo", { - masterLanguageDocument: migration.createContentRelationship( - () => masterLanguageDocument, - ), + masterLanguageDocument: () => masterLanguageDocument, }) const reporter = vi.fn() @@ -284,9 +278,7 @@ it.concurrent( "foo", ) const doc = migration.createDocument(document, "bar", { - masterLanguageDocument: migration.createContentRelationship( - () => masterLanguageMigrationDocument, - ), + masterLanguageDocument: () => masterLanguageMigrationDocument, }) const reporter = vi.fn() diff --git a/test/writeClient-migrate-patch-contentRelationship.test.ts b/test/writeClient-migrate-patch-contentRelationship.test.ts index 78491393..56a87278 100644 --- a/test/writeClient-migrate-patch-contentRelationship.test.ts +++ b/test/writeClient-migrate-patch-contentRelationship.test.ts @@ -3,40 +3,34 @@ import { testMigrationFieldPatching } from "./__testutils__/testMigrationFieldPa import { RichTextNodeType } from "../src" testMigrationFieldPatching("patches link fields", { - existing: ({ migration, existingDocuments }) => - migration.createContentRelationship(existingDocuments[0]), - migration: ({ migration, migrationDocuments }) => { + existing: ({ existingDocuments }) => existingDocuments[0], + migration: ({ migrationDocuments }) => { delete migrationDocuments.other.document.id - return migration.createContentRelationship(migrationDocuments.other) + return migrationDocuments.other }, - lazyExisting: ({ migration, existingDocuments }) => { - return migration.createContentRelationship(() => existingDocuments[0]) + lazyExisting: ({ existingDocuments }) => { + return () => existingDocuments[0] }, lazyMigration: ({ migration, migrationDocuments }) => { delete migrationDocuments.other.document.id - return migration.createContentRelationship(() => + return () => migration.getByUID( migrationDocuments.other.document.type, migrationDocuments.other.document.uid!, - ), - ) + ) }, migrationNoTags: ({ migration, migrationDocuments }) => { migrationDocuments.other.document.tags = undefined - return migration.createContentRelationship(() => + return () => migration.getByUID( migrationDocuments.other.document.type, migrationDocuments.other.document.uid!, - ), - ) + ) }, - brokenLink: () => { - return { type: "Document", isBroken: true } - }, - richTextLinkNode: ({ migration, existingDocuments }) => [ + richTextLinkNode: ({ existingDocuments }) => [ { type: RichTextNodeType.paragraph, text: "lorem", @@ -46,7 +40,7 @@ testMigrationFieldPatching("patches link fields", { type: RichTextNodeType.hyperlink, start: 0, end: 5, - data: migration.createContentRelationship(existingDocuments[0]), + data: existingDocuments[0], }, ], }, @@ -56,6 +50,16 @@ testMigrationFieldPatching("patches link fields", { testMigrationFieldPatching( "patches link fields", { + brokenLink: () => { + return { + link_type: "Document", + id: "id", + type: "type", + tags: [], + lang: "lang", + isBroken: true, + } + }, otherRepositoryContentRelationship: ({ ctx, migrationDocuments }) => { const contentRelationship = ctx.mock.value.link({ type: "Document" }) // `migrationDocuments` contains documents from "another repository" diff --git a/test/writeClient-migrate-patch-rtImageNode.test.ts b/test/writeClient-migrate-patch-rtImageNode.test.ts index b4138805..41d36393 100644 --- a/test/writeClient-migrate-patch-rtImageNode.test.ts +++ b/test/writeClient-migrate-patch-rtImageNode.test.ts @@ -2,7 +2,6 @@ import { testMigrationFieldPatching } from "./__testutils__/testMigrationFieldPa import { RichTextNodeType } from "../src" import { assetToImage } from "../src/types/migration/Asset" -import { MigrationContentRelationship } from "../src/types/migration/ContentRelationship" testMigrationFieldPatching("patches rich text image nodes", { new: ({ ctx, migration }) => [ @@ -18,9 +17,7 @@ testMigrationFieldPatching("patches rich text image nodes", { ], newLinkTo: ({ ctx, migration, existingDocuments }) => [ ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), - migration - .createAsset("foo", "foo.png") - .asRTImageNode(new MigrationContentRelationship(existingDocuments[0])), + migration.createAsset("foo", "foo.png").asRTImageNode(existingDocuments[0]), ], }) @@ -36,19 +33,14 @@ testMigrationFieldPatching( url: `${mockedDomain}/foo.png`, }, ], - otherRepositoryLinkTo: ({ - ctx, - migration, - mockedDomain, - existingDocuments, - }) => [ + otherRepositoryLinkTo: ({ ctx, mockedDomain, existingDocuments }) => [ ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), { type: RichTextNodeType.image, ...ctx.mock.value.image({ state: "filled" }), id: "foo-id", url: `${mockedDomain}/foo.png`, - linkTo: migration.createContentRelationship(existingDocuments[0]), + linkTo: existingDocuments[0], }, ], }, From c0c4419c3e63026decc5e3f5b885f4ab36034181 Mon Sep 17 00:00:00 2001 From: lihbr Date: Mon, 16 Sep 2024 16:47:17 +0200 Subject: [PATCH 11/13] refactor: remove all child asset classes --- src/Migration.ts | 58 +++- src/WriteClient.ts | 11 +- src/index.ts | 3 +- src/lib/isMigrationValue.ts | 118 +++++++ src/lib/resolveMigrationDocumentData.ts | 185 +++++++++- src/types/migration/Asset.ts | 322 ++++-------------- src/types/migration/ContentRelationship.ts | 19 +- src/types/migration/Document.ts | 6 +- src/types/migration/Field.ts | 64 ---- .../testMigrationFieldPatching.ts | 13 +- test/migration-createAsset.test.ts | 18 +- ...igration-createDocumentFromPrismic.test.ts | 8 +- test/types/migration.types.ts | 81 +---- ...-migrate-patch-contentRelationship.test.ts | 20 +- test/writeClient-migrate-patch-image.test.ts | 26 +- ...teClient-migrate-patch-linkToMedia.test.ts | 50 ++- ...teClient-migrate-patch-rtImageNode.test.ts | 56 +-- ...teClient-migrate-patch-simpleField.test.ts | 7 +- 18 files changed, 586 insertions(+), 479 deletions(-) create mode 100644 src/lib/isMigrationValue.ts delete mode 100644 src/types/migration/Field.ts diff --git a/src/Migration.ts b/src/Migration.ts index 4f44ae6b..968748ac 100644 --- a/src/Migration.ts +++ b/src/Migration.ts @@ -5,9 +5,10 @@ import type { Asset } from "./types/api/asset/asset" import type { MigrationAssetConfig, MigrationLinkToMedia, + MigrationRTImageNode, } from "./types/migration/Asset" -import type { MigrationAsset } from "./types/migration/Asset" -import { MigrationImage } from "./types/migration/Asset" +import { PrismicMigrationAsset } from "./types/migration/Asset" +import type { MigrationImage } from "./types/migration/Asset" import type { MigrationContentRelationship } from "./types/migration/ContentRelationship" import { PrismicMigrationDocument } from "./types/migration/Document" import type { @@ -16,8 +17,9 @@ import type { } from "./types/migration/Document" import type { PrismicDocument } from "./types/value/document" import type { FilledImageFieldImage } from "./types/value/image" -import type { FilledLinkToWebField } from "./types/value/link" +import { type FilledLinkToWebField, LinkType } from "./types/value/link" import type { FilledLinkToMediaField } from "./types/value/linkToMedia" +import { RichTextNodeType } from "./types/value/richText" /** * Extracts one or more Prismic document types that match a given Prismic @@ -47,7 +49,7 @@ export class Migration { * * @internal */ - _assets: Map = new Map() + _assets: Map = new Map() /** * Documents registered in the migration. @@ -205,22 +207,23 @@ export class Migration { } validateAssetMetadata(config) - const migrationAsset = new MigrationImage(config, maybeInitialField) + + // We create a detached instance of the asset each time to serialize it properly + const migrationAsset = new PrismicMigrationAsset(config, maybeInitialField) const maybeAsset = this._assets.get(config.id) if (maybeAsset) { // Consolidate existing asset with new asset value if possible - maybeAsset.config.notes = config.notes || maybeAsset.config.notes - maybeAsset.config.credits = config.credits || maybeAsset.config.credits - maybeAsset.config.alt = config.alt || maybeAsset.config.alt - maybeAsset.config.tags = Array.from( - new Set([...(config.tags || []), ...(maybeAsset.config.tags || [])]), + maybeAsset._config.notes = config.notes || maybeAsset._config.notes + maybeAsset._config.credits = config.credits || maybeAsset._config.credits + maybeAsset._config.alt = config.alt || maybeAsset._config.alt + maybeAsset._config.tags = Array.from( + new Set([...(config.tags || []), ...(maybeAsset._config.tags || [])]), ) } else { this._assets.set(config.id, migrationAsset) } - // We returned a detached instance of the asset to serialize it properly return migrationAsset } @@ -393,24 +396,43 @@ export class Migration { #migratePrismicDocumentData(input: unknown): unknown { if (is.filledContentRelationship(input)) { if (input.isBroken) { - return { link_type: "Document", id: "__broken__", isBroken: true } + return { + link_type: LinkType.Document, + id: "__broken__", + isBroken: true, + // TODO: Remove when link text PR is merged + // @ts-expect-error - Future-proofing for link text + text: input.text, + } } - return () => this.#getByOriginalID(input.id) + return { + link_type: LinkType.Document, + id: () => this.#getByOriginalID(input.id), + // TODO: Remove when link text PR is merged + // @ts-expect-error - Future-proofing for link text + text: input.text, + } } if (is.filledLinkToMedia(input)) { - // TODO: Remove when link text PR is merged - // @ts-expect-error - Future-proofing for link text - return this.createAsset(input).asLinkToMedia(input.text) + return { + link_type: LinkType.Media, + id: this.createAsset(input), + // TODO: Remove when link text PR is merged + // @ts-expect-error - Future-proofing for link text + text: input.text, + } } if (is.rtImageNode(input)) { // Rich text image nodes - const rtImageNode = this.createAsset(input).asRTImageNode() + const rtImageNode: MigrationRTImageNode = { + type: RichTextNodeType.image, + id: this.createAsset(input), + } if (input.linkTo) { - // Node `linkTo` dependency is tracked internally rtImageNode.linkTo = this.#migratePrismicDocumentData(input.linkTo) as | MigrationContentRelationship | MigrationLinkToMedia diff --git a/src/WriteClient.ts b/src/WriteClient.ts index 32cce269..96609182 100644 --- a/src/WriteClient.ts +++ b/src/WriteClient.ts @@ -24,7 +24,7 @@ import { type PostDocumentResult, type PutDocumentParams, } from "./types/api/migration/document" -import type { MigrationAsset } from "./types/migration/Asset" +import type { PrismicMigrationAsset } from "./types/migration/Asset" import type { MigrationDocument, PendingPrismicDocument, @@ -90,7 +90,7 @@ type MigrateReporterEventMap = { current: number remaining: number total: number - asset: MigrationAsset + asset: PrismicMigrationAsset } "assets:created": { created: number @@ -334,7 +334,7 @@ export class WriteClient< }) const { file, filename, notes, credits, alt, tags } = - migrationAsset.config + migrationAsset._config let resolvedFile: PostAssetParams["file"] | File if (typeof file === "string") { @@ -370,7 +370,7 @@ export class WriteClient< ...fetchParams, }) - migrationAsset.asset = asset + migrationAsset._asset = asset } reporter?.({ @@ -437,7 +437,8 @@ export class WriteClient< const masterLanguageDocument = await resolveMigrationContentRelationship(doc.masterLanguageDocument) - masterLanguageDocumentID = masterLanguageDocument?.id + masterLanguageDocumentID = + "id" in masterLanguageDocument ? masterLanguageDocument.id : undefined } else if (doc.originalPrismicDocument) { masterLanguageDocumentID = doc.originalPrismicDocument.alternate_languages.find( diff --git a/src/index.ts b/src/index.ts index 6750f34a..81ebb0ce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -326,13 +326,14 @@ export type { } from "./types/model/types" // Migrations - Types representing Prismic Migration API content values. +export { PrismicMigrationDocument } from "./types/migration/Document" export type { - PrismicMigrationDocument, PendingPrismicDocument, ExistingPrismicDocument, InjectMigrationSpecificTypes, } from "./types/migration/Document" +export { PrismicMigrationAsset } from "./types/migration/Asset" export type { MigrationImage, MigrationLinkToMedia, diff --git a/src/lib/isMigrationValue.ts b/src/lib/isMigrationValue.ts new file mode 100644 index 00000000..d95907be --- /dev/null +++ b/src/lib/isMigrationValue.ts @@ -0,0 +1,118 @@ +import type { + MigrationImage, + MigrationLinkToMedia, + MigrationRTImageNode, +} from "../types/migration/Asset" +import { PrismicMigrationAsset } from "../types/migration/Asset" +import type { MigrationContentRelationship } from "../types/migration/ContentRelationship" +import { + type InjectMigrationSpecificTypes, + PrismicMigrationDocument, +} from "../types/migration/Document" +import type { PrismicDocument } from "../types/value/document" +import type { GroupField } from "../types/value/group" +import { LinkType } from "../types/value/link" +import { RichTextNodeType } from "../types/value/richText" +import type { SliceZone } from "../types/value/sliceZone" +import type { AnyRegularField } from "../types/value/types" + +import * as is from "./isValue" + +/** + * Unknown value to check if it's a specific field type. + * + * @remarks + * Explicit types are added to help ensure narrowing is done effectively. + */ +type UnknownValue = + | PrismicDocument + | InjectMigrationSpecificTypes + | unknown + +/** + * Checks if a value is a migration content relationship field. + * + * @param value - Value to check. + * + * @returns `true` if `value` is a migration content relationship field, `false` + * otherwise. + * + * @internal + * This is not an official helper function and it's only designed to work with internal processes. + */ +export const contentRelationship = ( + value: UnknownValue, +): value is MigrationContentRelationship => { + return ( + value instanceof PrismicMigrationDocument || + is.prismicDocument(value) || + (typeof value === "object" && + value !== null && + "link_type" in value && + value.link_type === LinkType.Document && + "id" in value && + (contentRelationship(value.id) || typeof value.id === "function")) + ) +} + +/** + * Checks if a value is a migration image field. + * + * @param value - Value to check. + * + * @returns `true` if `value` is a migration image field, `false` otherwise. + * + * @internal + * This is not an official helper function and it's only designed to work with internal processes. + */ +export const image = (value: UnknownValue): value is MigrationImage => { + return value instanceof PrismicMigrationAsset +} + +/** + * Checks if a value is a migration link to media field. + * + * @param value - Value to check. + * + * @returns `true` if `value` is a migration link to media field, `false` + * otherwise. + * + * @internal + * This is not an official helper function and it's only designed to work with internal processes. + */ +export const linkToMedia = ( + value: UnknownValue, +): value is MigrationLinkToMedia => { + return ( + typeof value === "object" && + value !== null && + "id" in value && + value.id instanceof PrismicMigrationAsset && + "link_type" in value && + value.link_type === LinkType.Media + ) +} + +/** + * Checks if a value is a migration rich text image node. + * + * @param value - Value to check. + * + * @returns `true` if `value` is a migration rich text image node, `false` + * otherwise. + * + * @internal + * This is not an official helper function and it's only designed to work with internal processes. + */ +export const rtImageNode = ( + value: UnknownValue, +): value is MigrationRTImageNode => { + return ( + typeof value === "object" && + value !== null && + "id" in value && + value.id instanceof PrismicMigrationAsset && + "type" in value && + value.type === RichTextNodeType.image + ) +} diff --git a/src/lib/resolveMigrationDocumentData.ts b/src/lib/resolveMigrationDocumentData.ts index 7df8b8f0..7bba2ea8 100644 --- a/src/lib/resolveMigrationDocumentData.ts +++ b/src/lib/resolveMigrationDocumentData.ts @@ -1,14 +1,32 @@ +import type { + MigrationImage, + MigrationLinkToMedia, + MigrationRTImageNode, +} from "../types/migration/Asset" import type { MigrationContentRelationship, MigrationContentRelationshipField, } from "../types/migration/ContentRelationship" import { PrismicMigrationDocument } from "../types/migration/Document" -import { MigrationField } from "../types/migration/Field" +import type { FilledImageFieldImage } from "../types/value/image" +import type { LinkField } from "../types/value/link" +import { LinkType } from "../types/value/link" +import type { LinkToMediaField } from "../types/value/linkToMedia" +import type { RTImageNode } from "../types/value/richText" +import { RichTextNodeType } from "../types/value/richText" +import * as isFilled from "../helpers/isFilled" import type { Migration } from "../Migration" -import * as is from "./isValue" +import * as isMigration from "./isMigrationValue" +/** + * Resolves a migration content relationship to a content relationship field. + * + * @param relation - Content relationship to resolve. + * + * @returns Resolved content relationship field. + */ export async function resolveMigrationContentRelationship( relation: MigrationContentRelationship, ): Promise { @@ -19,30 +37,180 @@ export async function resolveMigrationContentRelationship( if (relation instanceof PrismicMigrationDocument) { return relation.document.id ? { link_type: "Document", id: relation.document.id } - : undefined + : { link_type: "Document" } } if (relation) { + if ( + isMigration.contentRelationship(relation.id) || + typeof relation.id === "function" + ) { + return { + ...(await resolveMigrationContentRelationship(relation.id)), + // TODO: Remove when link text PR is merged + // @ts-expect-error - Future-proofing for link text + text: relation.text, + } + } + return { link_type: "Document", id: relation.id } } + + return { link_type: "Document" } +} + +/** + * Resolves a migration image to an image field. + * + * @param migrationAsset - Asset to resolve. + * @param migration - Migration instance. + * @param withThumbnails - Whether to include thumbnails. + * + * @returns Resolved image field. + */ +export const resolveMigrationImage = ( + image: MigrationImage, + migration: Migration, + withThumbnails?: boolean, +): FilledImageFieldImage | undefined => { + const asset = migration._assets.get(image._config.id)?._asset + const maybeInitialField = image._initialField + + if (asset) { + const parameters = (maybeInitialField?.url || asset.url).split("?")[1] + const url = `${asset.url.split("?")[0]}${parameters ? `?${parameters}` : ""}` + const dimensions: FilledImageFieldImage["dimensions"] = { + width: asset.width!, + height: asset.height!, + } + const edit: FilledImageFieldImage["edit"] = + maybeInitialField && "edit" in maybeInitialField + ? maybeInitialField?.edit + : { x: 0, y: 0, zoom: 1, background: "transparent" } + + const alt = + (maybeInitialField && "alt" in maybeInitialField + ? maybeInitialField.alt + : undefined) || + asset.alt || + null + + const thumbnails: Record = {} + if (withThumbnails) { + for (const [name, thumbnail] of Object.entries(image._thumbnails)) { + const resolvedThumbnail = resolveMigrationImage(thumbnail, migration) + if (resolvedThumbnail) { + thumbnails[name] = resolvedThumbnail + } + } + } + + return { + id: asset.id, + url, + dimensions, + edit, + alt: alt, + copyright: asset.credits || null, + ...thumbnails, + } + } } +/** + * Resolves a migration rich text image node to a regular rich text image node. + * + * @param rtImageNode - Migration rich text image node to resolve. + * @param migration - Migration instance. + * + * @returns Resolved rich text image node. + */ +export const resolveMigrationRTImageNode = async ( + rtImageNode: MigrationRTImageNode, + migration: Migration, +): Promise => { + const image = resolveMigrationImage(rtImageNode.id, migration) + + if (image) { + const linkTo = (await resolveMigrationDocumentData( + rtImageNode.linkTo, + migration, + )) as LinkField + + return { + ...image, + type: RichTextNodeType.image, + linkTo: isFilled.link(linkTo) ? linkTo : undefined, + } + } +} + +/** + * Resolves a migration link to media to a regular link to media field. + * + * @param linkToMedia - Migration link to media to resolve. + * @param migration - Migration instance. + * + * @returns Resolved link to media field. + */ +export const resolveMigrationLinkToMedia = ( + linkToMedia: MigrationLinkToMedia, + migration: Migration, +): LinkToMediaField<"filled"> | undefined => { + const asset = migration._assets.get(linkToMedia.id._config.id)?._asset + + if (asset) { + return { + id: asset.id, + link_type: LinkType.Media, + name: asset.filename, + kind: asset.kind, + url: asset.url, + size: `${asset.size}`, + height: typeof asset.height === "number" ? `${asset.height}` : undefined, + width: typeof asset.width === "number" ? `${asset.width}` : undefined, + // TODO: Remove when link text PR is merged + // @ts-expect-error - Future-proofing for link text + text: linkToMedia.text, + } + } +} + +/** + * Resolves a migration document data to actual data ready to be sent to the + * Migration API. + * + * @param input - Migration link to media to resolve. + * @param migration - Migration instance. + * + * @returns Resolved data. + */ export async function resolveMigrationDocumentData( input: unknown, migration: Migration, ): Promise { - if (input instanceof MigrationField) { - return input._resolve(migration) + // Migration fields + if (isMigration.contentRelationship(input)) { + return resolveMigrationContentRelationship(input) } - if (input instanceof PrismicMigrationDocument || is.prismicDocument(input)) { - return resolveMigrationContentRelationship(input) + if (isMigration.image(input)) { + return resolveMigrationImage(input, migration, true) + } + + if (isMigration.linkToMedia(input)) { + return resolveMigrationLinkToMedia(input, migration) + } + + if (isMigration.rtImageNode(input)) { + return resolveMigrationRTImageNode(input, migration) } if (typeof input === "function") { return await resolveMigrationDocumentData(await input(), migration) } + // Object traversing if (Array.isArray(input)) { const res = [] @@ -50,7 +218,7 @@ export async function resolveMigrationDocumentData( res.push(await resolveMigrationDocumentData(element, migration)) } - return res + return res.filter(Boolean) } if (input && typeof input === "object") { @@ -66,5 +234,6 @@ export async function resolveMigrationDocumentData( return res } + // Primitives return input } diff --git a/src/types/migration/Asset.ts b/src/types/migration/Asset.ts index e6a1e069..225dc4f9 100644 --- a/src/types/migration/Asset.ts +++ b/src/types/migration/Asset.ts @@ -1,96 +1,18 @@ -import { resolveMigrationDocumentData } from "../../lib/resolveMigrationDocumentData" - -import type { Migration } from "../../Migration" - import type { Asset } from "../api/asset/asset" -import type { FilledContentRelationshipField } from "../value/contentRelationship" -import type { FilledImageFieldImage, ImageField } from "../value/image" -import { type FilledLinkToWebField, LinkType } from "../value/link" -import type { - FilledLinkToMediaField, - LinkToMediaField, -} from "../value/linkToMedia" -import { type RTImageNode, RichTextNodeType } from "../value/richText" +import type { FilledImageFieldImage } from "../value/image" +import type { LinkToMediaField } from "../value/linkToMedia" +import { type RTImageNode } from "../value/richText" -import type { MigrationContentRelationship } from "./ContentRelationship" -import { MigrationField } from "./Field" +import type { InjectMigrationSpecificTypes } from "./Document" /** - * Any type of image field handled by {@link MigrationAsset} + * Any type of image field handled by {@link PrismicMigrationAsset} */ type ImageLike = | FilledImageFieldImage | LinkToMediaField<"filled"> | RTImageNode -/** - * Converts an asset to an image field. - * - * @param asset - Asset to convert. - * @param maybeInitialField - Initial image field if available, used to preserve - * edits. - * - * @returns Equivalent image field. - */ -export const assetToImage = ( - asset: Asset, - maybeInitialField?: ImageLike, -): FilledImageFieldImage => { - const parameters = (maybeInitialField?.url || asset.url).split("?")[1] - const url = `${asset.url.split("?")[0]}${parameters ? `?${parameters}` : ""}` - const dimensions: FilledImageFieldImage["dimensions"] = { - width: asset.width!, - height: asset.height!, - } - const edit: FilledImageFieldImage["edit"] = - maybeInitialField && "edit" in maybeInitialField - ? maybeInitialField?.edit - : { x: 0, y: 0, zoom: 1, background: "transparent" } - - const alt = - (maybeInitialField && "alt" in maybeInitialField - ? maybeInitialField.alt - : undefined) || - asset.alt || - null - - return { - id: asset.id, - url, - dimensions, - edit, - alt: alt, - copyright: asset.credits || null, - } -} - -/** - * Converts an asset to a link to media field. - * - * @param asset - Asset to convert. - * @param text - Link text for the link to media field if any. - * - * @returns Equivalent link to media field. - */ -export const assetToLinkToMedia = ( - asset: Asset, - text?: string, -): LinkToMediaField<"filled"> => { - return { - id: asset.id, - link_type: LinkType.Media, - name: asset.filename, - kind: asset.kind, - url: asset.url, - size: `${asset.size}`, - height: typeof asset.height === "number" ? `${asset.height}` : undefined, - width: typeof asset.width === "number" ? `${asset.width}` : undefined, - // TODO: Remove when link text PR is merged - // @ts-expect-error - Future-proofing for link text - text, - } -} - /** * An asset to be uploaded to Prismic media library. */ @@ -136,209 +58,107 @@ export type MigrationAssetConfig = { } /** - * A migration asset used with the Prismic Migration API. - * - * @typeParam TImageLike - Type of the image-like value. + * An image field in a migration. */ -export abstract class MigrationAsset< - TImageLike extends ImageLike = ImageLike, -> extends MigrationField { - /** - * Configuration of the asset. - * - * @internal - */ - config: MigrationAssetConfig +export type MigrationImage = PrismicMigrationAsset - /** - * Asset object from Prismic available once created. - */ - asset?: Asset +/** + * A link to media field in a migration. + */ +export type MigrationLinkToMedia = Pick< + LinkToMediaField<"filled">, + "link_type" +> & + Partial< + Pick< + LinkToMediaField<"filled">, + // TODO: Remove when link text PR is merged + // @ts-expect-error - Future-proofing for link text + "text" + > + > & { + /** + * A reference to the migration asset used to resolve the link to media + * field's value. + */ + id: PrismicMigrationAsset + } +/** + * A rich text image node in a migration. + */ +export type MigrationRTImageNode = InjectMigrationSpecificTypes< + Pick +> & { /** - * Creates a migration asset used with the Prismic Migration API. - * - * @param config - Configuration of the asset. - * @param initialField - The initial field value if any. - * - * @returns A migration asset instance. + * A reference to the migration asset used to resolve the rich text image + * node's value. */ - constructor(config: MigrationAssetConfig, initialField?: ImageLike) { - super(initialField) - - this.config = config - } + id: PrismicMigrationAsset +} +/** + * A migration asset used with the Prismic Migration API. + * + * @typeParam TImageLike - Type of the image-like value. + */ +export class PrismicMigrationAsset { /** - * Marks the migration asset instance to be serialized as an image field. + * The initial field value this migration field was created with. * - * @returns A migration image instance. + * @internal */ - asImage(): MigrationImage { - return new MigrationImage(this.config, this._initialField) - } + _initialField?: ImageLike /** - * Marks the migration asset instance to be serialized as a link to media - * field. - * - * @param text - Link text for the link to media field if any. + * Configuration of the asset. * - * @returns A migration link to media instance. + * @internal */ - asLinkToMedia(text?: string): MigrationLinkToMedia { - return new MigrationLinkToMedia(this.config, text, this._initialField) - } + _config: MigrationAssetConfig /** - * Marks the migration asset instance to be serialized as a rich text image - * node. - * - * @param linkTo - Image node's link if any. + * Asset object from Prismic, available once created. * - * @returns A migration rich text image node instance. + * @internal */ - asRTImageNode( - linkTo?: - | MigrationLinkToMedia - | MigrationContentRelationship - | FilledLinkToWebField, - ): MigrationRTImageNode { - return new MigrationRTImageNode(this.config, linkTo, this._initialField) - } -} + _asset?: Asset -/** - * A migration image used with the Prismic Migration API. - */ -export class MigrationImage extends MigrationAsset { /** * Thumbnails of the image. - */ - #thumbnails: Record = {} - - /** - * Adds a thumbnail to the migration image instance. * - * @param name - Name of the thumbnail. - * @param thumbnail - Thumbnail to add as a migration image instance. - * - * @returns The current migration image instance, useful for chaining. - */ - addThumbnail(name: string, thumbnail: MigrationImage): this { - this.#thumbnails[name] = thumbnail - - return this - } - - async _resolve( - migration: Migration, - ): Promise { - const asset = migration._assets.get(this.config.id)?.asset - - if (asset) { - const field = assetToImage(asset, this._initialField) - - for (const name in this.#thumbnails) { - const thumbnail = await this.#thumbnails[name]._resolve(migration) - if (thumbnail) { - ;(field as ImageField)[name] = thumbnail - } - } - - return field - } - } -} - -/** - * A migration link to media used with the Prismic Migration API. - */ -export class MigrationLinkToMedia extends MigrationAsset< - LinkToMediaField<"filled"> -> { - /** - * Link text for the link to media field if any. + * @internal */ - text?: string + _thumbnails: Record = {} /** - * Creates a migration link to media instance used with the Prismic Migration - * API. + * Creates a migration asset used with the Prismic Migration API. * * @param config - Configuration of the asset. - * @param text - Link text for the link to media field if any. * @param initialField - The initial field value if any. * - * @returns A migration link to media instance. + * @returns A migration asset instance. */ - constructor( - config: MigrationAssetConfig, - text?: string, - initialField?: ImageLike, - ) { - super(config, initialField) - - this.text = text - } - - _resolve(migration: Migration): LinkToMediaField<"filled"> | undefined { - const asset = migration._assets.get(this.config.id)?.asset - - if (asset) { - return assetToLinkToMedia(asset, this.text) - } + constructor(config: MigrationAssetConfig, initialField?: ImageLike) { + this._config = config + this._initialField = initialField } -} -/** - * A migration rich text image node used with the Prismic Migration API. - */ -export class MigrationRTImageNode extends MigrationAsset { /** - * Image node's link if any. - */ - linkTo?: - | MigrationLinkToMedia - | MigrationContentRelationship - | FilledLinkToWebField - - /** - * Creates a migration rich text image node instance used with the Prismic - * Migration API. + * Adds a thumbnail to the migration asset instance. * - * @param config - Configuration of the asset. - * @param linkTo - Image node's link if any. - * @param initialField - The initial field value if any. + * @remarks + * This is only useful if the migration asset instance represents an image + * field. * - * @returns A migration rich text image node instance. + * @param name - Name of the thumbnail. + * @param thumbnail - Thumbnail to add as a migration image instance. + * + * @returns The current migration image instance, useful for chaining. */ - constructor( - config: MigrationAssetConfig, - linkTo?: - | MigrationLinkToMedia - | MigrationContentRelationship - | FilledLinkToWebField, - initialField?: ImageLike, - ) { - super(config, initialField) - - this.linkTo = linkTo - } - - async _resolve(migration: Migration): Promise { - const asset = migration._assets.get(this.config.id)?.asset + addThumbnail(name: string, thumbnail: PrismicMigrationAsset): this { + this._thumbnails[name] = thumbnail - if (asset) { - return { - ...assetToImage(asset, this._initialField), - type: RichTextNodeType.image, - linkTo: (await resolveMigrationDocumentData(this.linkTo, migration)) as - | FilledLinkToWebField - | FilledLinkToMediaField - | FilledContentRelationshipField - | undefined, - } - } + return this } } diff --git a/src/types/migration/ContentRelationship.ts b/src/types/migration/ContentRelationship.ts index 17177672..44255fc6 100644 --- a/src/types/migration/ContentRelationship.ts +++ b/src/types/migration/ContentRelationship.ts @@ -1,5 +1,6 @@ import type { FilledContentRelationshipField } from "../value/contentRelationship" import type { PrismicDocument } from "../value/document" +import type { EmptyLinkField } from "../value/link" import type { PrismicMigrationDocument } from "./Document" @@ -10,7 +11,21 @@ type ValueOrThunk = T | (() => Promise | T) */ export type MigrationContentRelationship< TDocuments extends PrismicDocument = PrismicDocument, -> = ValueOrThunk | undefined> +> = + | ValueOrThunk | undefined> + | (Pick & + Partial< + Pick< + FilledContentRelationshipField, + // TODO: Remove when link text PR is merged + // @ts-expect-error - Future-proofing for link text + "text" + > + > & { + id: ValueOrThunk< + TDocuments | PrismicMigrationDocument | undefined + > + }) /** * The minimum amount of information needed to represent a content relationship @@ -18,4 +33,4 @@ export type MigrationContentRelationship< */ export type MigrationContentRelationshipField = | Pick - | undefined + | EmptyLinkField<"Document"> diff --git a/src/types/migration/Document.ts b/src/types/migration/Document.ts index 2bd1b5ea..65897c77 100644 --- a/src/types/migration/Document.ts +++ b/src/types/migration/Document.ts @@ -18,7 +18,11 @@ import type { MigrationContentRelationship } from "./ContentRelationship" * @typeParam T - Type of the record to extend. */ export type InjectMigrationSpecificTypes = T extends RTImageNode - ? T | MigrationRTImageNode | undefined + ? + | T + | (Omit & InjectMigrationSpecificTypes>) + | MigrationRTImageNode + | undefined : T extends FilledImageFieldImage ? T | MigrationImage | undefined : T extends FilledLinkToMediaField diff --git a/src/types/migration/Field.ts b/src/types/migration/Field.ts deleted file mode 100644 index a53984ec..00000000 --- a/src/types/migration/Field.ts +++ /dev/null @@ -1,64 +0,0 @@ -import type { AnyRegularField } from "../value/types" - -import type { Migration } from "../../Migration" - -import type { RTBlockNode, RTInlineNode } from "../value/richText" - -/** - * Interface for migration fields that can be resolved. - */ -interface Resolvable< - TField extends AnyRegularField | RTBlockNode | RTInlineNode = - | AnyRegularField - | RTBlockNode - | RTInlineNode, -> { - /** - * Resolves the field's value with the provided maps. - * - * @param migration - A migration instance with documents and assets to use - * for resolving the field's value - * - * @internal - */ - _resolve( - migration: Migration, - ): Promise | TField | undefined -} - -/** - * A migration field used with the Prismic Migration API. - * - * @typeParam TField - Type of the field value. - * @typeParam TInitialField - Type of the initial field value. - */ -export abstract class MigrationField< - TField extends AnyRegularField | RTBlockNode | RTInlineNode = - | AnyRegularField - | RTBlockNode - | RTInlineNode, - TInitialField = TField, -> implements Resolvable -{ - /** - * The initial field value this migration field was created with. - * - * @internal - */ - _initialField?: TInitialField - - /** - * Creates a migration field used with the Prismic Migration API. - * - * @param initialField - The initial field value if any. - * - * @returns A migration field instance. - */ - constructor(initialField?: TInitialField) { - this._initialField = initialField - } - - abstract _resolve( - migration: Migration, - ): Promise | TField | undefined -} diff --git a/test/__testutils__/testMigrationFieldPatching.ts b/test/__testutils__/testMigrationFieldPatching.ts index 3f59b0c2..74a141b0 100644 --- a/test/__testutils__/testMigrationFieldPatching.ts +++ b/test/__testutils__/testMigrationFieldPatching.ts @@ -141,14 +141,15 @@ const internalTestMigrationFieldPatching = ( }) } -type TestMigrationFieldPatchingFactoryCases = Record< - string, - (args: GetDataArgs) => prismic.ExistingPrismicDocument["data"][string] -> +type TestMigrationFieldPatchingFactoryCases< + TField extends prismic.ExistingPrismicDocument["data"][string], +> = Record TField> -export const testMigrationFieldPatching = ( +export const testMigrationFieldPatching = < + TField extends prismic.ExistingPrismicDocument["data"][string], +>( description: string, - cases: TestMigrationFieldPatchingFactoryCases, + cases: TestMigrationFieldPatchingFactoryCases, args: Omit = {}, ): void => { describe(description, () => { diff --git a/test/migration-createAsset.test.ts b/test/migration-createAsset.test.ts index b6c57773..317d6e66 100644 --- a/test/migration-createAsset.test.ts +++ b/test/migration-createAsset.test.ts @@ -17,7 +17,7 @@ it("creates an asset from a url", () => { migration.createAsset(file, filename) - expect(migration._assets.get(file)?.config).toEqual({ + expect(migration._assets.get(file)?._config).toEqual({ id: file, file, filename, @@ -32,7 +32,7 @@ it("creates an asset from a file", () => { migration.createAsset(file, filename) - expect(migration._assets.get(file)?.config).toEqual({ + expect(migration._assets.get(file)?._config).toEqual({ id: file, file, filename, @@ -69,7 +69,7 @@ it("creates an asset from an existing asset", () => { migration.createAsset(asset) - expect(migration._assets.get(asset.id)?.config).toStrictEqual({ + expect(migration._assets.get(asset.id)?._config).toStrictEqual({ id: asset.id, file: asset.url, filename: asset.filename, @@ -94,7 +94,7 @@ it("creates an asset from an image field", () => { migration.createAsset(image) - expect(migration._assets.get(image.id)?.config).toEqual({ + expect(migration._assets.get(image.id)?._config).toEqual({ id: image.id, file: image.url, filename: image.url.split("/").pop(), @@ -119,7 +119,7 @@ it("creates an asset from a link to media field", () => { migration.createAsset(link) - expect(migration._assets.get(link.id)?.config).toEqual({ + expect(migration._assets.get(link.id)?._config).toEqual({ id: link.id, file: link.url, filename: link.name, @@ -169,7 +169,7 @@ it("consolidates existing assets with additional metadata", () => { migration.createAsset(file, filename) - expect(migration._assets.get(file)?.config).toStrictEqual({ + expect(migration._assets.get(file)?._config).toStrictEqual({ id: file, file, filename, @@ -186,7 +186,7 @@ it("consolidates existing assets with additional metadata", () => { tags: ["tag"], }) - expect(migration._assets.get(file)?.config).toStrictEqual({ + expect(migration._assets.get(file)?._config).toStrictEqual({ id: file, file, filename, @@ -203,7 +203,7 @@ it("consolidates existing assets with additional metadata", () => { tags: ["tag", "tag 2"], }) - expect(migration._assets.get(file)?.config).toStrictEqual({ + expect(migration._assets.get(file)?._config).toStrictEqual({ id: file, file, filename, @@ -215,7 +215,7 @@ it("consolidates existing assets with additional metadata", () => { migration.createAsset(file, filename) - expect(migration._assets.get(file)?.config).toStrictEqual({ + expect(migration._assets.get(file)?._config).toStrictEqual({ id: file, file, filename, diff --git a/test/migration-createDocumentFromPrismic.test.ts b/test/migration-createDocumentFromPrismic.test.ts index d453f022..1c45b5f7 100644 --- a/test/migration-createDocumentFromPrismic.test.ts +++ b/test/migration-createDocumentFromPrismic.test.ts @@ -182,7 +182,7 @@ describe.each<{ migration.createDocumentFromPrismic(document, documentTitle) - expect(migration._assets.get(id)?.config).toStrictEqual(expected) + expect(migration._assets.get(id)?._config).toStrictEqual(expected) }) it("group fields", ({ mock }) => { @@ -198,7 +198,7 @@ describe.each<{ migration.createDocumentFromPrismic(document, documentTitle) - expect(migration._assets.get(id)?.config).toStrictEqual(expected) + expect(migration._assets.get(id)?._config).toStrictEqual(expected) }) it("slice's primary zone", ({ mock }) => { @@ -224,7 +224,7 @@ describe.each<{ migration.createDocumentFromPrismic(document, documentTitle) - expect(migration._assets.get(id)?.config).toStrictEqual(expected) + expect(migration._assets.get(id)?._config).toStrictEqual(expected) }) it("slice's repeatable zone", ({ mock }) => { @@ -250,6 +250,6 @@ describe.each<{ migration.createDocumentFromPrismic(document, documentTitle) - expect(migration._assets.get(id)?.config).toStrictEqual(expected) + expect(migration._assets.get(id)?._config).toStrictEqual(expected) }) }) diff --git a/test/types/migration.types.ts b/test/types/migration.types.ts index ca79adab..04c69e83 100644 --- a/test/types/migration.types.ts +++ b/test/types/migration.types.ts @@ -52,84 +52,23 @@ expectType>(false) const defaultCreateAsset = defaultMigration.createAsset("url", "name") expectType>(true) -expectType< - TypeEqual< - ReturnType, - prismic.MigrationImage - > ->(true) -expectType< - TypeOf> ->(true) - -expectType< - TypeEqual< - ReturnType, - prismic.MigrationLinkToMedia - > ->(true) -expectType< - TypeOf< - prismic.MigrationLinkToMedia, - ReturnType - > ->(true) - -expectType< - TypeEqual< - ReturnType, - prismic.MigrationRTImageNode - > ->(true) -expectType< - TypeOf< - prismic.MigrationRTImageNode, - ReturnType - > ->(true) +expectType>( + true, +) +expectType>( + true, +) // Documents const documentsCreateAsset = defaultMigration.createAsset("url", "name") expectType>(true) expectType< - TypeEqual< - ReturnType, - prismic.MigrationImage - > ->(true) -expectType< - TypeOf< - prismic.MigrationImage, - ReturnType - > ->(true) - -expectType< - TypeEqual< - ReturnType, - prismic.MigrationLinkToMedia - > ->(true) -expectType< - TypeOf< - prismic.MigrationLinkToMedia, - ReturnType - > ->(true) - -expectType< - TypeEqual< - ReturnType, - prismic.MigrationRTImageNode - > ->(true) -expectType< - TypeOf< - prismic.MigrationRTImageNode, - ReturnType - > + TypeEqual >(true) +expectType>( + true, +) /** * createDocument diff --git a/test/writeClient-migrate-patch-contentRelationship.test.ts b/test/writeClient-migrate-patch-contentRelationship.test.ts index 56a87278..bc0c2344 100644 --- a/test/writeClient-migrate-patch-contentRelationship.test.ts +++ b/test/writeClient-migrate-patch-contentRelationship.test.ts @@ -1,8 +1,16 @@ import { testMigrationFieldPatching } from "./__testutils__/testMigrationFieldPatching" -import { RichTextNodeType } from "../src" +import type { + ContentRelationshipField, + InjectMigrationSpecificTypes, + MigrationContentRelationship, + RichTextField, +} from "../src" +import { LinkType, RichTextNodeType } from "../src" -testMigrationFieldPatching("patches link fields", { +testMigrationFieldPatching< + MigrationContentRelationship | InjectMigrationSpecificTypes +>("patches link fields", { existing: ({ existingDocuments }) => existingDocuments[0], migration: ({ migrationDocuments }) => { delete migrationDocuments.other.document.id @@ -47,12 +55,12 @@ testMigrationFieldPatching("patches link fields", { ], }) -testMigrationFieldPatching( +testMigrationFieldPatching( "patches link fields", { brokenLink: () => { return { - link_type: "Document", + link_type: LinkType.Document, id: "id", type: "type", tags: [], @@ -61,7 +69,9 @@ testMigrationFieldPatching( } }, otherRepositoryContentRelationship: ({ ctx, migrationDocuments }) => { - const contentRelationship = ctx.mock.value.link({ type: "Document" }) + const contentRelationship = ctx.mock.value.link({ + type: LinkType.Document, + }) // `migrationDocuments` contains documents from "another repository" contentRelationship.id = migrationDocuments.otherRepository.originalPrismicDocument!.id diff --git a/test/writeClient-migrate-patch-image.test.ts b/test/writeClient-migrate-patch-image.test.ts index e0bdc7fe..52c485e8 100644 --- a/test/writeClient-migrate-patch-image.test.ts +++ b/test/writeClient-migrate-patch-image.test.ts @@ -1,13 +1,27 @@ import { testMigrationFieldPatching } from "./__testutils__/testMigrationFieldPatching" -import { assetToImage } from "../src/types/migration/Asset" +import type { ImageField, MigrationImage } from "../src" -testMigrationFieldPatching("patches image fields", { - new: ({ migration }) => migration.createAsset("foo", "foo.png"), - existing: ({ existingAssets }) => assetToImage(existingAssets[0]), -}) +testMigrationFieldPatching( + "patches image fields", + { + new: ({ migration }) => migration.createAsset("foo", "foo.png"), + existing: ({ existingAssets }) => { + const asset = existingAssets[0] + + return { + id: asset.id, + url: asset.url, + dimensions: { width: asset.width!, height: asset.height! }, + edit: { x: 0, y: 0, zoom: 1, background: "transparent" }, + alt: asset.alt || null, + copyright: asset.credits || null, + } + }, + }, +) -testMigrationFieldPatching( +testMigrationFieldPatching( "patches image fields", { otherRepository: ({ ctx, mockedDomain }) => { diff --git a/test/writeClient-migrate-patch-linkToMedia.test.ts b/test/writeClient-migrate-patch-linkToMedia.test.ts index 5f01837a..90ad2b3e 100644 --- a/test/writeClient-migrate-patch-linkToMedia.test.ts +++ b/test/writeClient-migrate-patch-linkToMedia.test.ts @@ -1,12 +1,45 @@ import { testMigrationFieldPatching } from "./__testutils__/testMigrationFieldPatching" -import { RichTextNodeType } from "../src" +import type { + InjectMigrationSpecificTypes, + LinkToMediaField, + RichTextField, +} from "../src" +import { LinkType, RichTextNodeType } from "../src" +import type { Asset } from "../src/types/api/asset/asset" import { AssetType } from "../src/types/api/asset/asset" -import { assetToLinkToMedia } from "../src/types/migration/Asset" +import type { MigrationLinkToMedia } from "../src/types/migration/Asset" -testMigrationFieldPatching("patches link to media fields", { - new: ({ migration }) => - migration.createAsset("foo", "foo.png").asLinkToMedia(), +const assetToLinkToMedia = ( + asset: Asset, + text?: string, +): LinkToMediaField<"filled"> => { + return { + id: asset.id, + link_type: LinkType.Media, + name: asset.filename, + kind: asset.kind, + url: asset.url, + size: `${asset.size}`, + height: typeof asset.height === "number" ? `${asset.height}` : undefined, + width: typeof asset.width === "number" ? `${asset.width}` : undefined, + // TODO: Remove when link text PR is merged + // @ts-expect-error - Future-proofing for link text + text, + } +} + +testMigrationFieldPatching< + | MigrationLinkToMedia + | LinkToMediaField + | InjectMigrationSpecificTypes +>("patches link to media fields", { + new: ({ migration }) => { + return { + link_type: LinkType.Media, + id: migration.createAsset("foo", "foo.png"), + } + }, existing: ({ existingAssets }) => assetToLinkToMedia(existingAssets[0]), existingNonImage: ({ existingAssets }) => { existingAssets[0].filename = "foo.pdf" @@ -27,7 +60,10 @@ testMigrationFieldPatching("patches link to media fields", { type: RichTextNodeType.hyperlink, start: 0, end: 5, - data: migration.createAsset("foo", "foo.png").asLinkToMedia(), + data: { + link_type: LinkType.Media, + id: migration.createAsset("foo", "foo.png"), + }, }, ], }, @@ -49,7 +85,7 @@ testMigrationFieldPatching("patches link to media fields", { ], }) -testMigrationFieldPatching( +testMigrationFieldPatching( "patches link to media fields", { otherRepository: ({ ctx, mockedDomain }) => { diff --git a/test/writeClient-migrate-patch-rtImageNode.test.ts b/test/writeClient-migrate-patch-rtImageNode.test.ts index 41d36393..d483e056 100644 --- a/test/writeClient-migrate-patch-rtImageNode.test.ts +++ b/test/writeClient-migrate-patch-rtImageNode.test.ts @@ -1,27 +1,45 @@ import { testMigrationFieldPatching } from "./__testutils__/testMigrationFieldPatching" +import type { InjectMigrationSpecificTypes, RichTextField } from "../src" import { RichTextNodeType } from "../src" -import { assetToImage } from "../src/types/migration/Asset" -testMigrationFieldPatching("patches rich text image nodes", { - new: ({ ctx, migration }) => [ - ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), - migration.createAsset("foo", "foo.png").asRTImageNode(), - ], - existing: ({ ctx, existingAssets }) => [ - ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), - { - type: RichTextNodeType.image, - ...assetToImage(existingAssets[0]), - }, - ], - newLinkTo: ({ ctx, migration, existingDocuments }) => [ - ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), - migration.createAsset("foo", "foo.png").asRTImageNode(existingDocuments[0]), - ], -}) +testMigrationFieldPatching>( + "patches rich text image nodes", + { + new: ({ ctx, migration }) => [ + ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), + { + type: RichTextNodeType.image, + id: migration.createAsset("foo", "foo.png"), + }, + ], + existing: ({ ctx, existingAssets }) => [ + ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), + { + type: RichTextNodeType.image, + id: existingAssets[0].id, + url: existingAssets[0].url, + dimensions: { + width: existingAssets[0].width!, + height: existingAssets[0].height!, + }, + edit: { x: 0, y: 0, zoom: 1, background: "transparent" }, + alt: existingAssets[0].alt || null, + copyright: existingAssets[0].credits || null, + }, + ], + newLinkTo: ({ ctx, migration, existingDocuments }) => [ + ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), + { + type: RichTextNodeType.image, + id: migration.createAsset("foo", "foo.png"), + linkTo: existingDocuments[0], + }, + ], + }, +) -testMigrationFieldPatching( +testMigrationFieldPatching>( "patches rich text image nodes", { otherRepository: ({ ctx, mockedDomain }) => [ diff --git a/test/writeClient-migrate-patch-simpleField.test.ts b/test/writeClient-migrate-patch-simpleField.test.ts index 0e6268cc..848fa844 100644 --- a/test/writeClient-migrate-patch-simpleField.test.ts +++ b/test/writeClient-migrate-patch-simpleField.test.ts @@ -1,8 +1,9 @@ import { testMigrationFieldPatching } from "./__testutils__/testMigrationFieldPatching" +import type { AnyRegularField, GroupField, RichTextField } from "../src" import { RichTextNodeType } from "../src" -testMigrationFieldPatching( +testMigrationFieldPatching( "does not patch simple fields", { embed: ({ ctx }) => ctx.mock.value.embed({ state: "filled" }), @@ -14,7 +15,9 @@ testMigrationFieldPatching( richTextSimple: ({ ctx }) => ctx.mock.value .richText({ state: "filled", pattern: "long" }) - .filter((node) => node.type !== RichTextNodeType.image), + .filter( + (node) => node.type !== RichTextNodeType.image, + ) as RichTextField, select: ({ ctx }) => ctx.mock.value.select({ model: ctx.mock.model.select({ options: ["foo", "bar"] }), From 51db286791288283ca37c7a599ccf97b21124287 Mon Sep 17 00:00:00 2001 From: lihbr Date: Mon, 16 Sep 2024 17:55:23 +0200 Subject: [PATCH 12/13] refactor: remove `addThumbnail` method --- src/Migration.ts | 38 +++++----- src/WriteClient.ts | 4 +- src/lib/isMigrationValue.ts | 10 ++- src/lib/resolveMigrationDocumentData.ts | 34 ++++----- src/types/migration/Asset.ts | 76 +++++++------------ src/types/migration/Document.ts | 6 +- test/migration-createAsset.test.ts | 30 ++++---- ...igration-createDocumentFromPrismic.test.ts | 8 +- 8 files changed, 94 insertions(+), 112 deletions(-) diff --git a/src/Migration.ts b/src/Migration.ts index 968748ac..e138b16b 100644 --- a/src/Migration.ts +++ b/src/Migration.ts @@ -4,11 +4,11 @@ import { validateAssetMetadata } from "./lib/validateAssetMetadata" import type { Asset } from "./types/api/asset/asset" import type { MigrationAssetConfig, + MigrationImage, MigrationLinkToMedia, MigrationRTImageNode, } from "./types/migration/Asset" import { PrismicMigrationAsset } from "./types/migration/Asset" -import type { MigrationImage } from "./types/migration/Asset" import type { MigrationContentRelationship } from "./types/migration/ContentRelationship" import { PrismicMigrationDocument } from "./types/migration/Document" import type { @@ -68,10 +68,9 @@ export class Migration { * * @param asset - An asset object from Prismic Asset API. * - * @returns A migration asset field instance configured to be serialized as an - * image field by default. + * @returns A migration asset field instance. */ - createAsset(asset: Asset): MigrationImage + createAsset(asset: Asset): PrismicMigrationAsset /** * Registers an asset to be created in the migration from an image or link to @@ -85,12 +84,11 @@ export class Migration { * @param imageOrLinkToMediaField - An image or link to media field from * Prismic Document API. * - * @returns A migration asset field instance configured to be serialized as an - * image field by default. + * @returns A migration asset field instance. */ createAsset( imageOrLinkToMediaField: FilledImageFieldImage | FilledLinkToMediaField, - ): MigrationImage + ): PrismicMigrationAsset /** * Registers an asset to be created in the migration from a file. @@ -104,8 +102,7 @@ export class Migration { * @param filename - The filename of the asset. * @param params - Additional asset data. * - * @returns A migration asset field instance configured to be serialized as an - * image field by default. + * @returns A migration asset field instance. */ createAsset( file: MigrationAssetConfig["file"], @@ -116,7 +113,7 @@ export class Migration { alt?: string tags?: string[] }, - ): MigrationImage + ): PrismicMigrationAsset /** * Registers an asset to be created in the migration from a file, an asset @@ -127,8 +124,7 @@ export class Migration { * 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 configured to be serialized as an - * image field by default. + * @returns A migration asset field instance. */ createAsset( fileOrAssetOrField: @@ -148,7 +144,7 @@ export class Migration { alt?: string tags?: string[] } = {}, - ): MigrationImage { + ): PrismicMigrationAsset { let config: MigrationAssetConfig let maybeInitialField: FilledImageFieldImage | undefined if (typeof fileOrAssetOrField === "object" && "url" in fileOrAssetOrField) { @@ -214,11 +210,11 @@ export class Migration { const maybeAsset = this._assets.get(config.id) if (maybeAsset) { // Consolidate existing asset with new asset value if possible - maybeAsset._config.notes = config.notes || maybeAsset._config.notes - maybeAsset._config.credits = config.credits || maybeAsset._config.credits - maybeAsset._config.alt = config.alt || maybeAsset._config.alt - maybeAsset._config.tags = Array.from( - new Set([...(config.tags || []), ...(maybeAsset._config.tags || [])]), + maybeAsset.config.notes = maybeAsset.config.notes || config.notes + maybeAsset.config.credits = maybeAsset.config.credits || config.credits + maybeAsset.config.alt = maybeAsset.config.alt || config.alt + maybeAsset.config.tags = Array.from( + new Set([...(maybeAsset.config.tags || []), ...(config.tags || [])]), ) } else { this._assets.set(config.id, migrationAsset) @@ -443,7 +439,9 @@ export class Migration { } if (is.filledImage(input)) { - const image = this.createAsset(input) + const image: MigrationImage = { + id: this.createAsset(input), + } const { id: _id, @@ -457,7 +455,7 @@ export class Migration { for (const name in thumbnails) { if (is.filledImage(thumbnails[name])) { - image.addThumbnail(name, this.createAsset(thumbnails[name])) + image[name] = this.createAsset(thumbnails[name]) } } diff --git a/src/WriteClient.ts b/src/WriteClient.ts index 96609182..202f7ab8 100644 --- a/src/WriteClient.ts +++ b/src/WriteClient.ts @@ -334,7 +334,7 @@ export class WriteClient< }) const { file, filename, notes, credits, alt, tags } = - migrationAsset._config + migrationAsset.config let resolvedFile: PostAssetParams["file"] | File if (typeof file === "string") { @@ -370,7 +370,7 @@ export class WriteClient< ...fetchParams, }) - migrationAsset._asset = asset + migrationAsset.asset = asset } reporter?.({ diff --git a/src/lib/isMigrationValue.ts b/src/lib/isMigrationValue.ts index d95907be..28a442e1 100644 --- a/src/lib/isMigrationValue.ts +++ b/src/lib/isMigrationValue.ts @@ -66,7 +66,15 @@ export const contentRelationship = ( * This is not an official helper function and it's only designed to work with internal processes. */ export const image = (value: UnknownValue): value is MigrationImage => { - return value instanceof PrismicMigrationAsset + return ( + value instanceof PrismicMigrationAsset || + (typeof value === "object" && + value !== null && + "id" in value && + Object.values(value).every( + (maybeThumbnail) => maybeThumbnail instanceof PrismicMigrationAsset, + )) + ) } /** diff --git a/src/lib/resolveMigrationDocumentData.ts b/src/lib/resolveMigrationDocumentData.ts index 7bba2ea8..f25f95d4 100644 --- a/src/lib/resolveMigrationDocumentData.ts +++ b/src/lib/resolveMigrationDocumentData.ts @@ -1,7 +1,8 @@ -import type { - MigrationImage, - MigrationLinkToMedia, - MigrationRTImageNode, +import { + type MigrationImage, + type MigrationLinkToMedia, + type MigrationRTImageNode, + PrismicMigrationAsset, } from "../types/migration/Asset" import type { MigrationContentRelationship, @@ -73,8 +74,11 @@ export const resolveMigrationImage = ( migration: Migration, withThumbnails?: boolean, ): FilledImageFieldImage | undefined => { - const asset = migration._assets.get(image._config.id)?._asset - const maybeInitialField = image._initialField + const { id: master, ...thumbnails } = + image instanceof PrismicMigrationAsset ? { id: image } : image + + const asset = migration._assets.get(master.config.id)?.asset + const maybeInitialField = master.originalField if (asset) { const parameters = (maybeInitialField?.url || asset.url).split("?")[1] @@ -88,19 +92,15 @@ export const resolveMigrationImage = ( ? maybeInitialField?.edit : { x: 0, y: 0, zoom: 1, background: "transparent" } - const alt = - (maybeInitialField && "alt" in maybeInitialField - ? maybeInitialField.alt - : undefined) || - asset.alt || - null + // We give priority to the asset's specific alt text, then the image's general alt text + const alt = master.config.alt || asset.alt || null - const thumbnails: Record = {} + const resolvedThumbnails: Record = {} if (withThumbnails) { - for (const [name, thumbnail] of Object.entries(image._thumbnails)) { + for (const [name, thumbnail] of Object.entries(thumbnails)) { const resolvedThumbnail = resolveMigrationImage(thumbnail, migration) if (resolvedThumbnail) { - thumbnails[name] = resolvedThumbnail + resolvedThumbnails[name] = resolvedThumbnail } } } @@ -112,7 +112,7 @@ export const resolveMigrationImage = ( edit, alt: alt, copyright: asset.credits || null, - ...thumbnails, + ...resolvedThumbnails, } } } @@ -157,7 +157,7 @@ export const resolveMigrationLinkToMedia = ( linkToMedia: MigrationLinkToMedia, migration: Migration, ): LinkToMediaField<"filled"> | undefined => { - const asset = migration._assets.get(linkToMedia.id._config.id)?._asset + const asset = migration._assets.get(linkToMedia.id.config.id)?.asset if (asset) { return { diff --git a/src/types/migration/Asset.ts b/src/types/migration/Asset.ts index 225dc4f9..a6242e3a 100644 --- a/src/types/migration/Asset.ts +++ b/src/types/migration/Asset.ts @@ -5,14 +5,6 @@ import { type RTImageNode } from "../value/richText" import type { InjectMigrationSpecificTypes } from "./Document" -/** - * Any type of image field handled by {@link PrismicMigrationAsset} - */ -type ImageLike = - | FilledImageFieldImage - | LinkToMediaField<"filled"> - | RTImageNode - /** * An asset to be uploaded to Prismic media library. */ @@ -60,7 +52,15 @@ export type MigrationAssetConfig = { /** * An image field in a migration. */ -export type MigrationImage = PrismicMigrationAsset +export type MigrationImage = + | PrismicMigrationAsset + | ({ + /** + * A reference to the migration asset used to resolve the image field's + * value. + */ + id: PrismicMigrationAsset + } & Record) /** * A link to media field in a migration. @@ -99,37 +99,25 @@ export type MigrationRTImageNode = InjectMigrationSpecificTypes< /** * A migration asset used with the Prismic Migration API. - * - * @typeParam TImageLike - Type of the image-like value. */ export class PrismicMigrationAsset { /** - * The initial field value this migration field was created with. - * - * @internal + * Asset object from Prismic, available once created. */ - _initialField?: ImageLike + asset?: Asset /** * Configuration of the asset. - * - * @internal - */ - _config: MigrationAssetConfig - - /** - * Asset object from Prismic, available once created. - * - * @internal */ - _asset?: Asset + config: MigrationAssetConfig /** - * Thumbnails of the image. - * - * @internal + * The initial field value this migration field was created with. */ - _thumbnails: Record = {} + originalField?: + | FilledImageFieldImage + | LinkToMediaField<"filled"> + | RTImageNode /** * Creates a migration asset used with the Prismic Migration API. @@ -139,26 +127,14 @@ export class PrismicMigrationAsset { * * @returns A migration asset instance. */ - constructor(config: MigrationAssetConfig, initialField?: ImageLike) { - this._config = config - this._initialField = initialField - } - - /** - * Adds a thumbnail to the migration asset instance. - * - * @remarks - * This is only useful if the migration asset instance represents an image - * field. - * - * @param name - Name of the thumbnail. - * @param thumbnail - Thumbnail to add as a migration image instance. - * - * @returns The current migration image instance, useful for chaining. - */ - addThumbnail(name: string, thumbnail: PrismicMigrationAsset): this { - this._thumbnails[name] = thumbnail - - return this + constructor( + config: MigrationAssetConfig, + initialField?: + | FilledImageFieldImage + | LinkToMediaField<"filled"> + | RTImageNode, + ) { + this.config = config + this.originalField = initialField } } diff --git a/src/types/migration/Document.ts b/src/types/migration/Document.ts index 65897c77..45d0a007 100644 --- a/src/types/migration/Document.ts +++ b/src/types/migration/Document.ts @@ -105,9 +105,9 @@ export class PrismicMigrationDocument< */ title: string - // We're forced to inline `ContentRelationshipMigrationField` here, otherwise - // it creates a circular reference to itself which makes TypeScript unhappy. - // (but I think it's weird and it doesn't make sense :thinking:) + /** + * The link to the master language document to relate the document to if any. + */ masterLanguageDocument?: MigrationContentRelationship /** diff --git a/test/migration-createAsset.test.ts b/test/migration-createAsset.test.ts index 317d6e66..9d8e205a 100644 --- a/test/migration-createAsset.test.ts +++ b/test/migration-createAsset.test.ts @@ -17,7 +17,7 @@ it("creates an asset from a url", () => { migration.createAsset(file, filename) - expect(migration._assets.get(file)?._config).toEqual({ + expect(migration._assets.get(file)?.config).toEqual({ id: file, file, filename, @@ -32,7 +32,7 @@ it("creates an asset from a file", () => { migration.createAsset(file, filename) - expect(migration._assets.get(file)?._config).toEqual({ + expect(migration._assets.get(file)?.config).toEqual({ id: file, file, filename, @@ -69,7 +69,7 @@ it("creates an asset from an existing asset", () => { migration.createAsset(asset) - expect(migration._assets.get(asset.id)?._config).toStrictEqual({ + expect(migration._assets.get(asset.id)?.config).toStrictEqual({ id: asset.id, file: asset.url, filename: asset.filename, @@ -94,7 +94,7 @@ it("creates an asset from an image field", () => { migration.createAsset(image) - expect(migration._assets.get(image.id)?._config).toEqual({ + expect(migration._assets.get(image.id)?.config).toEqual({ id: image.id, file: image.url, filename: image.url.split("/").pop(), @@ -119,7 +119,7 @@ it("creates an asset from a link to media field", () => { migration.createAsset(link) - expect(migration._assets.get(link.id)?._config).toEqual({ + expect(migration._assets.get(link.id)?.config).toEqual({ id: link.id, file: link.url, filename: link.name, @@ -169,7 +169,7 @@ it("consolidates existing assets with additional metadata", () => { migration.createAsset(file, filename) - expect(migration._assets.get(file)?._config).toStrictEqual({ + expect(migration._assets.get(file)?.config).toStrictEqual({ id: file, file, filename, @@ -186,7 +186,7 @@ it("consolidates existing assets with additional metadata", () => { tags: ["tag"], }) - expect(migration._assets.get(file)?._config).toStrictEqual({ + expect(migration._assets.get(file)?.config).toStrictEqual({ id: file, file, filename, @@ -203,25 +203,25 @@ it("consolidates existing assets with additional metadata", () => { tags: ["tag", "tag 2"], }) - expect(migration._assets.get(file)?._config).toStrictEqual({ + expect(migration._assets.get(file)?.config).toStrictEqual({ id: file, file, filename, - notes: "notes 2", - alt: "alt 2", - credits: "credits 2", + notes: "notes", + alt: "alt", + credits: "credits", tags: ["tag", "tag 2"], }) migration.createAsset(file, filename) - expect(migration._assets.get(file)?._config).toStrictEqual({ + expect(migration._assets.get(file)?.config).toStrictEqual({ id: file, file, filename, - notes: "notes 2", - alt: "alt 2", - credits: "credits 2", + notes: "notes", + alt: "alt", + credits: "credits", tags: ["tag", "tag 2"], }) }) diff --git a/test/migration-createDocumentFromPrismic.test.ts b/test/migration-createDocumentFromPrismic.test.ts index 1c45b5f7..d453f022 100644 --- a/test/migration-createDocumentFromPrismic.test.ts +++ b/test/migration-createDocumentFromPrismic.test.ts @@ -182,7 +182,7 @@ describe.each<{ migration.createDocumentFromPrismic(document, documentTitle) - expect(migration._assets.get(id)?._config).toStrictEqual(expected) + expect(migration._assets.get(id)?.config).toStrictEqual(expected) }) it("group fields", ({ mock }) => { @@ -198,7 +198,7 @@ describe.each<{ migration.createDocumentFromPrismic(document, documentTitle) - expect(migration._assets.get(id)?._config).toStrictEqual(expected) + expect(migration._assets.get(id)?.config).toStrictEqual(expected) }) it("slice's primary zone", ({ mock }) => { @@ -224,7 +224,7 @@ describe.each<{ migration.createDocumentFromPrismic(document, documentTitle) - expect(migration._assets.get(id)?._config).toStrictEqual(expected) + expect(migration._assets.get(id)?.config).toStrictEqual(expected) }) it("slice's repeatable zone", ({ mock }) => { @@ -250,6 +250,6 @@ describe.each<{ migration.createDocumentFromPrismic(document, documentTitle) - expect(migration._assets.get(id)?._config).toStrictEqual(expected) + expect(migration._assets.get(id)?.config).toStrictEqual(expected) }) }) From 397b04c75ba98a4353e37b8af71290129d52ac4c Mon Sep 17 00:00:00 2001 From: lihbr Date: Mon, 16 Sep 2024 21:09:01 +0200 Subject: [PATCH 13/13] refactor: tests naming --- src/Migration.ts | 8 + src/lib/resolveMigrationDocumentData.ts | 8 +- ...ate-patch-contentRelationship.test.ts.snap | 533 +++-- ...iteClient-migrate-patch-image.test.ts.snap | 1800 ++++++++++------- ...ent-migrate-patch-linkToMedia.test.ts.snap | 961 +++++---- ...ent-migrate-patch-rtImageNode.test.ts.snap | 766 ++++--- test/__testutils__/mockPrismicAssetAPI.ts | 8 + .../testMigrationFieldPatching.ts | 80 +- test/writeClient-migrate-documents.test.ts | 32 + ...-migrate-patch-contentRelationship.test.ts | 82 +- test/writeClient-migrate-patch-image.test.ts | 23 +- ...teClient-migrate-patch-linkToMedia.test.ts | 31 +- ...teClient-migrate-patch-rtImageNode.test.ts | 6 +- ...teClient-migrate-patch-simpleField.test.ts | 6 + 14 files changed, 2632 insertions(+), 1712 deletions(-) diff --git a/src/Migration.ts b/src/Migration.ts index e138b16b..d821641f 100644 --- a/src/Migration.ts +++ b/src/Migration.ts @@ -389,6 +389,14 @@ export class Migration { ) } + /** + * Migrates a Prismic document data from another repository so that it can be + * created through the current repository's Migration API. + * + * @param input - The Prismic document data to migrate. + * + * @returns The migrated Prismic document data. + */ #migratePrismicDocumentData(input: unknown): unknown { if (is.filledContentRelationship(input)) { if (input.isBroken) { diff --git a/src/lib/resolveMigrationDocumentData.ts b/src/lib/resolveMigrationDocumentData.ts index f25f95d4..8bfd9fbf 100644 --- a/src/lib/resolveMigrationDocumentData.ts +++ b/src/lib/resolveMigrationDocumentData.ts @@ -37,8 +37,8 @@ export async function resolveMigrationContentRelationship( if (relation instanceof PrismicMigrationDocument) { return relation.document.id - ? { link_type: "Document", id: relation.document.id } - : { link_type: "Document" } + ? { link_type: LinkType.Document, id: relation.document.id } + : { link_type: LinkType.Document } } if (relation) { @@ -54,10 +54,10 @@ export async function resolveMigrationContentRelationship( } } - return { link_type: "Document", id: relation.id } + return { link_type: LinkType.Document, id: relation.id } } - return { link_type: "Document" } + return { link_type: LinkType.Document } } /** diff --git a/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap index ff7b4689..ae564060 100644 --- a/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`patches link fields > brokenLink > group 1`] = ` +exports[`patches content relationship fields (from Prismic) > broken > group 1`] = ` { "group": [ { @@ -14,11 +14,11 @@ exports[`patches link fields > brokenLink > group 1`] = ` } `; -exports[`patches link fields > brokenLink > shared slice 1`] = ` +exports[`patches content relationship fields (from Prismic) > broken > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { @@ -45,19 +45,19 @@ exports[`patches link fields > brokenLink > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches link fields > brokenLink > slice 1`] = ` +exports[`patches content relationship fields (from Prismic) > broken > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { @@ -74,14 +74,14 @@ exports[`patches link fields > brokenLink > slice 1`] = ` "link_type": "Document", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches link fields > brokenLink > static zone 1`] = ` +exports[`patches content relationship fields (from Prismic) > broken > static zone 1`] = ` { "field": { "id": "__broken__", @@ -91,12 +91,12 @@ exports[`patches link fields > brokenLink > static zone 1`] = ` } `; -exports[`patches link fields > existing > group 1`] = ` +exports[`patches content relationship fields (from Prismic) > simple > group 1`] = ` { "group": [ { "field": { - "id": "id-existing", + "id": "other.id-fromPrismic", "link_type": "Document", }, }, @@ -104,167 +104,174 @@ exports[`patches link fields > existing > group 1`] = ` } `; -exports[`patches link fields > existing > shared slice 1`] = ` +exports[`patches content relationship fields (from Prismic) > simple > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { - "id": "id-existing", + "id": "other.id-fromPrismic", "link_type": "Document", }, }, ], "primary": { "field": { - "id": "id-existing", + "id": "other.id-fromPrismic", "link_type": "Document", }, "group": [ { "field": { - "id": "id-existing", + "id": "other.id-fromPrismic", "link_type": "Document", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches link fields > existing > slice 1`] = ` +exports[`patches content relationship fields (from Prismic) > simple > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { - "id": "id-existing", + "id": "other.id-fromPrismic", "link_type": "Document", }, }, ], "primary": { "field": { - "id": "id-existing", + "id": "other.id-fromPrismic", "link_type": "Document", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches link fields > existing > static zone 1`] = ` +exports[`patches content relationship fields (from Prismic) > simple > static zone 1`] = ` { "field": { - "id": "id-existing", + "id": "other.id-fromPrismic", "link_type": "Document", }, } `; -exports[`patches link fields > lazyExisting > group 1`] = ` +exports[`patches content relationship fields (from Prismic) > withText > group 1`] = ` { "group": [ { "field": { - "id": "id-existing", + "id": "other.id-fromPrismic", "link_type": "Document", + "text": "foo", }, }, ], } `; -exports[`patches link fields > lazyExisting > shared slice 1`] = ` +exports[`patches content relationship fields (from Prismic) > withText > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { - "id": "id-existing", + "id": "other.id-fromPrismic", "link_type": "Document", + "text": "foo", }, }, ], "primary": { "field": { - "id": "id-existing", + "id": "other.id-fromPrismic", "link_type": "Document", + "text": "foo", }, "group": [ { "field": { - "id": "id-existing", + "id": "other.id-fromPrismic", "link_type": "Document", + "text": "foo", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches link fields > lazyExisting > slice 1`] = ` +exports[`patches content relationship fields (from Prismic) > withText > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { - "id": "id-existing", + "id": "other.id-fromPrismic", "link_type": "Document", + "text": "foo", }, }, ], "primary": { "field": { - "id": "id-existing", + "id": "other.id-fromPrismic", "link_type": "Document", + "text": "foo", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches link fields > lazyExisting > static zone 1`] = ` +exports[`patches content relationship fields (from Prismic) > withText > static zone 1`] = ` { "field": { - "id": "id-existing", + "id": "other.id-fromPrismic", "link_type": "Document", + "text": "foo", }, } `; -exports[`patches link fields > lazyMigration > group 1`] = ` +exports[`patches content relationship fields > existing > group 1`] = ` { "group": [ { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", }, }, @@ -272,83 +279,83 @@ exports[`patches link fields > lazyMigration > group 1`] = ` } `; -exports[`patches link fields > lazyMigration > shared slice 1`] = ` +exports[`patches content relationship fields > existing > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", }, }, ], "primary": { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", }, "group": [ { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches link fields > lazyMigration > slice 1`] = ` +exports[`patches content relationship fields > existing > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", }, }, ], "primary": { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches link fields > lazyMigration > static zone 1`] = ` +exports[`patches content relationship fields > existing > static zone 1`] = ` { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", }, } `; -exports[`patches link fields > migration > group 1`] = ` +exports[`patches content relationship fields > existingLongForm > group 1`] = ` { "group": [ { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", }, }, @@ -356,167 +363,174 @@ exports[`patches link fields > migration > group 1`] = ` } `; -exports[`patches link fields > migration > shared slice 1`] = ` +exports[`patches content relationship fields > existingLongForm > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", }, }, ], "primary": { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", }, "group": [ { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches link fields > migration > slice 1`] = ` +exports[`patches content relationship fields > existingLongForm > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", }, }, ], "primary": { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches link fields > migration > static zone 1`] = ` +exports[`patches content relationship fields > existingLongForm > static zone 1`] = ` { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", }, } `; -exports[`patches link fields > migrationNoTags > group 1`] = ` +exports[`patches content relationship fields > existingLongFormWithText > group 1`] = ` { "group": [ { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", + "text": "foo", }, }, ], } `; -exports[`patches link fields > migrationNoTags > shared slice 1`] = ` +exports[`patches content relationship fields > existingLongFormWithText > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", + "text": "foo", }, }, ], "primary": { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", + "text": "foo", }, "group": [ { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", + "text": "foo", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches link fields > migrationNoTags > slice 1`] = ` +exports[`patches content relationship fields > existingLongFormWithText > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", + "text": "foo", }, }, ], "primary": { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", + "text": "foo", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches link fields > migrationNoTags > static zone 1`] = ` +exports[`patches content relationship fields > existingLongFormWithText > static zone 1`] = ` { "field": { - "id": "id-other", + "id": "other.id-existing", "link_type": "Document", + "text": "foo", }, } `; -exports[`patches link fields > otherRepositoryContentRelationship > group 1`] = ` +exports[`patches content relationship fields > lazyExisting > group 1`] = ` { "group": [ { "field": { - "id": "id-other-repository", + "id": "other.id-existing", "link_type": "Document", }, }, @@ -524,78 +538,323 @@ exports[`patches link fields > otherRepositoryContentRelationship > group 1`] = } `; -exports[`patches link fields > otherRepositoryContentRelationship > shared slice 1`] = ` +exports[`patches content relationship fields > lazyExisting > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { - "id": "id-other-repository", + "id": "other.id-existing", "link_type": "Document", }, }, ], "primary": { "field": { - "id": "id-other-repository", + "id": "other.id-existing", "link_type": "Document", }, "group": [ { "field": { - "id": "id-other-repository", + "id": "other.id-existing", "link_type": "Document", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches link fields > otherRepositoryContentRelationship > slice 1`] = ` +exports[`patches content relationship fields > lazyExisting > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { - "id": "id-other-repository", + "id": "other.id-existing", "link_type": "Document", }, }, ], "primary": { "field": { - "id": "id-other-repository", + "id": "other.id-existing", "link_type": "Document", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches link fields > otherRepositoryContentRelationship > static zone 1`] = ` +exports[`patches content relationship fields > lazyExisting > static zone 1`] = ` { "field": { - "id": "id-other-repository", + "id": "other.id-existing", "link_type": "Document", }, } `; -exports[`patches link fields > richTextLinkNode > group 1`] = ` +exports[`patches content relationship fields > lazyOtherCreate > group 1`] = ` +{ + "group": [ + { + "field": { + "id": "other.id-create", + "link_type": "Document", + }, + }, + ], +} +`; + +exports[`patches content relationship fields > lazyOtherCreate > shared slice 1`] = ` +{ + "slices": [ + { + "id": "9b9dd0f2c3f", + "items": [ + { + "field": { + "id": "other.id-create", + "link_type": "Document", + }, + }, + ], + "primary": { + "field": { + "id": "other.id-create", + "link_type": "Document", + }, + "group": [ + { + "field": { + "id": "other.id-create", + "link_type": "Document", + }, + }, + ], + }, + "slice_label": null, + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", + }, + ], +} +`; + +exports[`patches content relationship fields > lazyOtherCreate > slice 1`] = ` +{ + "slices": [ + { + "id": "5306297c5ed", + "items": [ + { + "field": { + "id": "other.id-create", + "link_type": "Document", + }, + }, + ], + "primary": { + "field": { + "id": "other.id-create", + "link_type": "Document", + }, + }, + "slice_label": "Vel", + "slice_type": "hac_habitasse", + }, + ], +} +`; + +exports[`patches content relationship fields > lazyOtherCreate > static zone 1`] = ` +{ + "field": { + "id": "other.id-create", + "link_type": "Document", + }, +} +`; + +exports[`patches content relationship fields > lazyOtherCreateMissingID > group 1`] = ` +{ + "group": [ + { + "field": { + "link_type": "Document", + }, + }, + ], +} +`; + +exports[`patches content relationship fields > lazyOtherCreateMissingID > shared slice 1`] = ` +{ + "slices": [ + { + "id": "9b9dd0f2c3f", + "items": [ + { + "field": { + "link_type": "Document", + }, + }, + ], + "primary": { + "field": { + "link_type": "Document", + }, + "group": [ + { + "field": { + "link_type": "Document", + }, + }, + ], + }, + "slice_label": null, + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", + }, + ], +} +`; + +exports[`patches content relationship fields > lazyOtherCreateMissingID > slice 1`] = ` +{ + "slices": [ + { + "id": "5306297c5ed", + "items": [ + { + "field": { + "link_type": "Document", + }, + }, + ], + "primary": { + "field": { + "link_type": "Document", + }, + }, + "slice_label": "Vel", + "slice_type": "hac_habitasse", + }, + ], +} +`; + +exports[`patches content relationship fields > lazyOtherCreateMissingID > static zone 1`] = ` +{ + "field": { + "link_type": "Document", + }, +} +`; + +exports[`patches content relationship fields > otherCreate > group 1`] = ` +{ + "group": [ + { + "field": { + "id": "other.id-create", + "link_type": "Document", + }, + }, + ], +} +`; + +exports[`patches content relationship fields > otherCreate > shared slice 1`] = ` +{ + "slices": [ + { + "id": "9b9dd0f2c3f", + "items": [ + { + "field": { + "id": "other.id-create", + "link_type": "Document", + }, + }, + ], + "primary": { + "field": { + "id": "other.id-create", + "link_type": "Document", + }, + "group": [ + { + "field": { + "id": "other.id-create", + "link_type": "Document", + }, + }, + ], + }, + "slice_label": null, + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", + }, + ], +} +`; + +exports[`patches content relationship fields > otherCreate > slice 1`] = ` +{ + "slices": [ + { + "id": "5306297c5ed", + "items": [ + { + "field": { + "id": "other.id-create", + "link_type": "Document", + }, + }, + ], + "primary": { + "field": { + "id": "other.id-create", + "link_type": "Document", + }, + }, + "slice_label": "Vel", + "slice_type": "hac_habitasse", + }, + ], +} +`; + +exports[`patches content relationship fields > otherCreate > static zone 1`] = ` +{ + "field": { + "id": "other.id-create", + "link_type": "Document", + }, +} +`; + +exports[`patches content relationship fields > richTextLinkNode > group 1`] = ` { "group": [ { @@ -609,7 +868,7 @@ exports[`patches link fields > richTextLinkNode > group 1`] = ` }, { "data": { - "id": "id-existing", + "id": "other.id-existing", "link_type": "Document", }, "end": 5, @@ -626,11 +885,11 @@ exports[`patches link fields > richTextLinkNode > group 1`] = ` } `; -exports[`patches link fields > richTextLinkNode > shared slice 1`] = ` +exports[`patches content relationship fields > richTextLinkNode > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": [ @@ -643,7 +902,7 @@ exports[`patches link fields > richTextLinkNode > shared slice 1`] = ` }, { "data": { - "id": "id-existing", + "id": "other.id-existing", "link_type": "Document", }, "end": 5, @@ -668,7 +927,7 @@ exports[`patches link fields > richTextLinkNode > shared slice 1`] = ` }, { "data": { - "id": "id-existing", + "id": "other.id-existing", "link_type": "Document", }, "end": 5, @@ -692,7 +951,7 @@ exports[`patches link fields > richTextLinkNode > shared slice 1`] = ` }, { "data": { - "id": "id-existing", + "id": "other.id-existing", "link_type": "Document", }, "end": 5, @@ -708,19 +967,19 @@ exports[`patches link fields > richTextLinkNode > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches link fields > richTextLinkNode > slice 1`] = ` +exports[`patches content relationship fields > richTextLinkNode > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": [ @@ -733,7 +992,7 @@ exports[`patches link fields > richTextLinkNode > slice 1`] = ` }, { "data": { - "id": "id-existing", + "id": "other.id-existing", "link_type": "Document", }, "end": 5, @@ -758,7 +1017,7 @@ exports[`patches link fields > richTextLinkNode > slice 1`] = ` }, { "data": { - "id": "id-existing", + "id": "other.id-existing", "link_type": "Document", }, "end": 5, @@ -771,14 +1030,14 @@ exports[`patches link fields > richTextLinkNode > slice 1`] = ` }, ], }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches link fields > richTextLinkNode > static zone 1`] = ` +exports[`patches content relationship fields > richTextLinkNode > static zone 1`] = ` { "field": [ { @@ -790,7 +1049,7 @@ exports[`patches link fields > richTextLinkNode > static zone 1`] = ` }, { "data": { - "id": "id-existing", + "id": "other.id-existing", "link_type": "Document", }, "end": 5, diff --git a/test/__snapshots__/writeClient-migrate-patch-image.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-image.test.ts.snap index 98f4ebb3..3662a201 100644 --- a/test/__snapshots__/writeClient-migrate-patch-image.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-image.test.ts.snap @@ -1,52 +1,34 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`patches image fields > existing > group 1`] = ` +exports[`patches image fields (from Prismic) > empty > group 1`] = ` { "group": [ { "field": { "alt": null, "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, - }, - "id": "id-existing", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "dimensions": null, + "id": null, + "url": null, }, }, ], } `; -exports[`patches image fields > existing > shared slice 1`] = ` +exports[`patches image fields (from Prismic) > empty > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { "alt": null, "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, - }, - "id": "id-existing", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "dimensions": null, + "id": null, + "url": null, }, }, ], @@ -54,71 +36,44 @@ exports[`patches image fields > existing > shared slice 1`] = ` "field": { "alt": null, "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, - }, - "id": "id-existing", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "dimensions": null, + "id": null, + "url": null, }, "group": [ { "field": { "alt": null, "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, - }, - "id": "id-existing", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "dimensions": null, + "id": null, + "url": null, }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches image fields > existing > slice 1`] = ` +exports[`patches image fields (from Prismic) > empty > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { "alt": null, "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, - }, - "id": "id-existing", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "dimensions": null, + "id": null, + "url": null, }, }, ], @@ -126,565 +81,834 @@ exports[`patches image fields > existing > slice 1`] = ` "field": { "alt": null, "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, - }, - "id": "id-existing", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "dimensions": null, + "id": null, + "url": null, }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches image fields > existing > static zone 1`] = ` +exports[`patches image fields (from Prismic) > empty > static zone 1`] = ` { "field": { "alt": null, "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, - }, - "id": "id-existing", - "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", + "dimensions": null, + "id": null, + "url": null, }, } `; -exports[`patches image fields > new > group 1`] = ` +exports[`patches image fields (from Prismic) > simple > group 1`] = ` { "group": [ { "field": { - "alt": null, + "alt": "Morbi tincidunt ornare massa eget egestas purus viverra accumsan in nisl nisi scelerisque eu", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#fc26fe", + "x": 1643, + "y": -110, + "zoom": 1.3701173345023108, }, - "id": "dfdd322ca9d", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "id": "d0985c09900", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724", }, }, ], } `; -exports[`patches image fields > new > shared slice 1`] = ` +exports[`patches image fields (from Prismic) > simple > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { - "alt": null, + "alt": "Nam libero justo laoreet sit amet cursus sit amet dictum sit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#d9ed25", + "x": 1472, + "y": -1646, + "zoom": 1.0945668828428181, }, - "id": "0eddbd0255b", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "id": "b35eaa8ebee", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", }, }, ], "primary": { "field": { - "alt": null, + "alt": "Massa massa ultricies mi quis hendrerit dolor magna eget est lorem ipsum dolor sit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#04f4f5", + "x": 27, + "y": -816, + "zoom": 1.9856937117841313, }, - "id": "0eddbd0255b", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "id": "b35eaa8ebee", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", }, "group": [ { "field": { - "alt": null, + "alt": "Egestas maecenas pharetra convallis posuere morbi leo urna", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#d42f5c", + "x": 1778, + "y": -875, + "zoom": 1.6943119181539659, }, - "id": "0eddbd0255b", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "id": "b35eaa8ebee", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches image fields > new > slice 1`] = ` +exports[`patches image fields (from Prismic) > simple > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { - "alt": null, + "alt": "Molestie lorem ipsum dolor sit amet consectetur adipiscing elit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#ff72de", + "x": 329, + "y": -450, + "zoom": 1.9747006336633817, }, - "id": "2beb55ec2f4", - "url": "https://images.unsplash.com/photo-1444464666168-49d633b86797?w=4844&h=3234&fit=crop", + "id": "07a35bc5aa2", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg", }, }, ], "primary": { "field": { - "alt": null, + "alt": "Tincidunt vitae semper quis lectus", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#860cba", + "x": -1925, + "y": -2408, + "zoom": 1.4001176423393464, }, - "id": "2beb55ec2f4", - "url": "https://images.unsplash.com/photo-1444464666168-49d633b86797?w=4844&h=3234&fit=crop", + "id": "07a35bc5aa2", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches image fields > new > static zone 1`] = ` +exports[`patches image fields (from Prismic) > simple > static zone 1`] = ` { "field": { - "alt": null, + "alt": "Velit laoreet id donec ultrices tincidunt arcu non sodales neque sodales ut etiam sit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#1d17b0", + "x": -1859, + "y": 1185, + "zoom": 1.2989647419422317, }, - "id": "bbad670dad7", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", + "id": "a95cc61c373", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg", }, } `; -exports[`patches image fields > otherRepository > group 1`] = ` +exports[`patches image fields (from Prismic) > withSpecialTypeThumbnail > group 1`] = ` { "group": [ { "field": { - "alt": "Massa id neque aliquam vestibulum morbi blandit cursus risus", + "alt": "Morbi tincidunt ornare massa eget egestas purus viverra accumsan in nisl nisi scelerisque eu", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#cfc26f", - "x": -2885, - "y": -2419, - "zoom": 1.7509753524211642, + "background": "#fc26fe", + "x": 1643, + "y": -110, + "zoom": 1.3701173345023108, + }, + "id": "d0985c09900", + "type": { + "alt": "Morbi tincidunt ornare massa eget egestas purus viverra accumsan in nisl nisi scelerisque eu", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#fc26fe", + "x": 1643, + "y": -110, + "zoom": 1.3701173345023108, + }, + "id": "d0985c09900", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?some=other&query=params", }, - "id": "8d0985c0990", - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?some=query", }, }, ], } `; -exports[`patches image fields > otherRepository > shared slice 1`] = ` +exports[`patches image fields (from Prismic) > withSpecialTypeThumbnail > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { - "alt": "Fermentum odio eu feugiat pretium nibh ipsum consequat", + "alt": "Nam libero justo laoreet sit amet cursus sit amet dictum sit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#9ed252", - "x": -1720, - "y": -191, - "zoom": 1.6165685319845957, + "background": "#d9ed25", + "x": 1472, + "y": -1646, + "zoom": 1.0945668828428181, }, - "id": "35eaa8ebee4", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", + "id": "b35eaa8ebee", + "type": { + "alt": "Nam libero justo laoreet sit amet cursus sit amet dictum sit", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#d9ed25", + "x": 1472, + "y": -1646, + "zoom": 1.0945668828428181, + }, + "id": "b35eaa8ebee", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", + }, + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, }, ], "primary": { "field": { - "alt": "Pellentesque pulvinar pellentesque habitant morbi tristique senectus et netus et malesuada fames ac", + "alt": "Massa massa ultricies mi quis hendrerit dolor magna eget est lorem ipsum dolor sit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#4f4f59", - "x": 3094, - "y": -2976, - "zoom": 1.0855120641844143, + "background": "#04f4f5", + "x": 27, + "y": -816, + "zoom": 1.9856937117841313, }, - "id": "35eaa8ebee4", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", + "id": "b35eaa8ebee", + "type": { + "alt": "Massa massa ultricies mi quis hendrerit dolor magna eget est lorem ipsum dolor sit", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#04f4f5", + "x": 27, + "y": -816, + "zoom": 1.9856937117841313, + }, + "id": "b35eaa8ebee", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", + }, + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, "group": [ { "field": { - "alt": "Id aliquet risus feugiat in", + "alt": "Egestas maecenas pharetra convallis posuere morbi leo urna", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#42f5cf", - "x": 427, - "y": 731, - "zoom": 1.6417661415510265, + "background": "#d42f5c", + "x": 1778, + "y": -875, + "zoom": 1.6943119181539659, }, - "id": "35eaa8ebee4", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5", + "id": "b35eaa8ebee", + "type": { + "alt": "Egestas maecenas pharetra convallis posuere morbi leo urna", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#d42f5c", + "x": 1778, + "y": -875, + "zoom": 1.6943119181539659, + }, + "id": "b35eaa8ebee", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", + }, + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches image fields > otherRepository > slice 1`] = ` +exports[`patches image fields (from Prismic) > withSpecialTypeThumbnail > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { - "alt": "Pellentesque nec nam aliquam sem", + "alt": "Molestie lorem ipsum dolor sit amet consectetur adipiscing elit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#f72dec", - "x": 2027, - "y": 7, - "zoom": 1.9216652845315787, + "background": "#ff72de", + "x": 329, + "y": -450, + "zoom": 1.9747006336633817, + }, + "id": "07a35bc5aa2", + "type": { + "alt": "Molestie lorem ipsum dolor sit amet consectetur adipiscing elit", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#ff72de", + "x": 329, + "y": -450, + "zoom": 1.9747006336633817, + }, + "id": "07a35bc5aa2", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=other&query=params", }, - "id": "7a35bc5aa2f", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=query", }, }, ], "primary": { "field": { - "alt": "Quam nulla porttitor massa id neque aliquam vestibulum morbi blandit", + "alt": "Tincidunt vitae semper quis lectus", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#60cbac", - "x": -484, - "y": -2038, - "zoom": 1.8400009569805118, + "background": "#860cba", + "x": -1925, + "y": -2408, + "zoom": 1.4001176423393464, + }, + "id": "07a35bc5aa2", + "type": { + "alt": "Tincidunt vitae semper quis lectus", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#860cba", + "x": -1925, + "y": -2408, + "zoom": 1.4001176423393464, + }, + "id": "07a35bc5aa2", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=other&query=params", }, - "id": "7a35bc5aa2f", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=query", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches image fields > otherRepository > static zone 1`] = ` +exports[`patches image fields (from Prismic) > withSpecialTypeThumbnail > static zone 1`] = ` { "field": { - "alt": "Gravida rutrum quisque non tellus orci", + "alt": "Velit laoreet id donec ultrices tincidunt arcu non sodales neque sodales ut etiam sit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#b1d17b", - "x": 3291, - "y": -730, - "zoom": 1.061566393836766, + "background": "#1d17b0", + "x": -1859, + "y": 1185, + "zoom": 1.2989647419422317, + }, + "id": "a95cc61c373", + "type": { + "alt": "Velit laoreet id donec ultrices tincidunt arcu non sodales neque sodales ut etiam sit", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#1d17b0", + "x": -1859, + "y": 1185, + "zoom": 1.2989647419422317, + }, + "id": "a95cc61c373", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=other&query=params", }, - "id": "4a95cc61c37", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=query", }, } `; -exports[`patches image fields > otherRepositoryEmpty > group 1`] = ` +exports[`patches image fields (from Prismic) > withThumbnails > group 1`] = ` { "group": [ { "field": { - "alt": null, + "alt": "Morbi tincidunt ornare massa eget egestas purus viverra accumsan in nisl nisi scelerisque eu", "copyright": null, - "dimensions": null, - "id": null, - "url": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#fc26fe", + "x": 1643, + "y": -110, + "zoom": 1.3701173345023108, + }, + "id": "d0985c09900", + "square": { + "alt": "Morbi tincidunt ornare massa eget egestas purus viverra accumsan in nisl nisi scelerisque eu", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#fc26fe", + "x": 1643, + "y": -110, + "zoom": 1.3701173345023108, + }, + "id": "d0985c09900", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?some=other&query=params", + }, + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?some=query", }, }, ], } `; -exports[`patches image fields > otherRepositoryEmpty > shared slice 1`] = ` +exports[`patches image fields (from Prismic) > withThumbnails > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { - "alt": null, + "alt": "Nam libero justo laoreet sit amet cursus sit amet dictum sit", "copyright": null, - "dimensions": null, - "id": null, - "url": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#d9ed25", + "x": 1472, + "y": -1646, + "zoom": 1.0945668828428181, + }, + "id": "b35eaa8ebee", + "square": { + "alt": "Nam libero justo laoreet sit amet cursus sit amet dictum sit", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#d9ed25", + "x": 1472, + "y": -1646, + "zoom": 1.0945668828428181, + }, + "id": "b35eaa8ebee", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", + }, + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, }, ], "primary": { "field": { - "alt": null, + "alt": "Massa massa ultricies mi quis hendrerit dolor magna eget est lorem ipsum dolor sit", "copyright": null, - "dimensions": null, - "id": null, - "url": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#04f4f5", + "x": 27, + "y": -816, + "zoom": 1.9856937117841313, + }, + "id": "b35eaa8ebee", + "square": { + "alt": "Massa massa ultricies mi quis hendrerit dolor magna eget est lorem ipsum dolor sit", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#04f4f5", + "x": 27, + "y": -816, + "zoom": 1.9856937117841313, + }, + "id": "b35eaa8ebee", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", + }, + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, "group": [ { "field": { - "alt": null, + "alt": "Egestas maecenas pharetra convallis posuere morbi leo urna", "copyright": null, - "dimensions": null, - "id": null, - "url": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#d42f5c", + "x": 1778, + "y": -875, + "zoom": 1.6943119181539659, + }, + "id": "b35eaa8ebee", + "square": { + "alt": "Egestas maecenas pharetra convallis posuere morbi leo urna", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#d42f5c", + "x": 1778, + "y": -875, + "zoom": 1.6943119181539659, + }, + "id": "b35eaa8ebee", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", + }, + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches image fields > otherRepositoryEmpty > slice 1`] = ` +exports[`patches image fields (from Prismic) > withThumbnails > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { - "alt": null, + "alt": "Molestie lorem ipsum dolor sit amet consectetur adipiscing elit", "copyright": null, - "dimensions": null, - "id": null, - "url": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#ff72de", + "x": 329, + "y": -450, + "zoom": 1.9747006336633817, + }, + "id": "07a35bc5aa2", + "square": { + "alt": "Molestie lorem ipsum dolor sit amet consectetur adipiscing elit", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#ff72de", + "x": 329, + "y": -450, + "zoom": 1.9747006336633817, + }, + "id": "07a35bc5aa2", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=other&query=params", + }, + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=query", }, }, ], "primary": { "field": { - "alt": null, + "alt": "Tincidunt vitae semper quis lectus", "copyright": null, - "dimensions": null, - "id": null, - "url": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#860cba", + "x": -1925, + "y": -2408, + "zoom": 1.4001176423393464, + }, + "id": "07a35bc5aa2", + "square": { + "alt": "Tincidunt vitae semper quis lectus", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#860cba", + "x": -1925, + "y": -2408, + "zoom": 1.4001176423393464, + }, + "id": "07a35bc5aa2", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=other&query=params", + }, + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=query", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches image fields > otherRepositoryEmpty > static zone 1`] = ` +exports[`patches image fields (from Prismic) > withThumbnails > static zone 1`] = ` { "field": { - "alt": null, + "alt": "Velit laoreet id donec ultrices tincidunt arcu non sodales neque sodales ut etiam sit", "copyright": null, - "dimensions": null, - "id": null, - "url": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#1d17b0", + "x": -1859, + "y": 1185, + "zoom": 1.2989647419422317, + }, + "id": "a95cc61c373", + "square": { + "alt": "Velit laoreet id donec ultrices tincidunt arcu non sodales neque sodales ut etiam sit", + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#1d17b0", + "x": -1859, + "y": 1185, + "zoom": 1.2989647419422317, + }, + "id": "a95cc61c373", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=other&query=params", + }, + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=query", }, } `; -exports[`patches image fields > otherRepositoryWithThumbnails > group 1`] = ` +exports[`patches image fields (from Prismic) > withThumbnailsNoAlt > group 1`] = ` { "group": [ { "field": { - "alt": "Massa id neque aliquam vestibulum morbi blandit cursus risus", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#cfc26f", - "x": -2885, - "y": -2419, - "zoom": 1.7509753524211642, + "background": "#fc26fe", + "x": 1643, + "y": -110, + "zoom": 1.3701173345023108, }, - "id": "8d0985c0990", + "id": "d0985c09900", "square": { - "alt": "Massa id neque aliquam vestibulum morbi blandit cursus risus", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#cfc26f", - "x": -2885, - "y": -2419, - "zoom": 1.7509753524211642, + "background": "#fc26fe", + "x": 1643, + "y": -110, + "zoom": 1.3701173345023108, }, - "id": "8d0985c0990", - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=other&query=params", + "id": "d0985c09900", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?some=other&query=params", }, - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=query", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?some=query", }, }, ], } `; -exports[`patches image fields > otherRepositoryWithThumbnails > shared slice 1`] = ` +exports[`patches image fields (from Prismic) > withThumbnailsNoAlt > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { - "alt": "Fermentum odio eu feugiat pretium nibh ipsum consequat", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#9ed252", - "x": -1720, - "y": -191, - "zoom": 1.6165685319845957, + "background": "#d9ed25", + "x": 1472, + "y": -1646, + "zoom": 1.0945668828428181, }, - "id": "35eaa8ebee4", + "id": "b35eaa8ebee", "square": { - "alt": "Fermentum odio eu feugiat pretium nibh ipsum consequat", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#9ed252", - "x": -1720, - "y": -191, - "zoom": 1.6165685319845957, + "background": "#d9ed25", + "x": 1472, + "y": -1646, + "zoom": 1.0945668828428181, }, - "id": "35eaa8ebee4", + "id": "b35eaa8ebee", "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", }, "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", @@ -693,33 +917,33 @@ exports[`patches image fields > otherRepositoryWithThumbnails > shared slice 1`] ], "primary": { "field": { - "alt": "Pellentesque pulvinar pellentesque habitant morbi tristique senectus et netus et malesuada fames ac", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#4f4f59", - "x": 3094, - "y": -2976, - "zoom": 1.0855120641844143, + "background": "#04f4f5", + "x": 27, + "y": -816, + "zoom": 1.9856937117841313, }, - "id": "35eaa8ebee4", + "id": "b35eaa8ebee", "square": { - "alt": "Pellentesque pulvinar pellentesque habitant morbi tristique senectus et netus et malesuada fames ac", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#4f4f59", - "x": 3094, - "y": -2976, - "zoom": 1.0855120641844143, + "background": "#04f4f5", + "x": 27, + "y": -816, + "zoom": 1.9856937117841313, }, - "id": "35eaa8ebee4", + "id": "b35eaa8ebee", "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", }, "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", @@ -727,169 +951,505 @@ exports[`patches image fields > otherRepositoryWithThumbnails > shared slice 1`] "group": [ { "field": { - "alt": "Id aliquet risus feugiat in", + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#d42f5c", + "x": 1778, + "y": -875, + "zoom": 1.6943119181539659, + }, + "id": "b35eaa8ebee", + "square": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#d42f5c", + "x": 1778, + "y": -875, + "zoom": 1.6943119181539659, + }, + "id": "b35eaa8ebee", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", + }, + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", + }, + }, + ], + }, + "slice_label": null, + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", + }, + ], +} +`; + +exports[`patches image fields (from Prismic) > withThumbnailsNoAlt > slice 1`] = ` +{ + "slices": [ + { + "id": "5306297c5ed", + "items": [ + { + "field": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#ff72de", + "x": 329, + "y": -450, + "zoom": 1.9747006336633817, + }, + "id": "07a35bc5aa2", + "square": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#ff72de", + "x": 329, + "y": -450, + "zoom": 1.9747006336633817, + }, + "id": "07a35bc5aa2", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=other&query=params", + }, + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=query", + }, + }, + ], + "primary": { + "field": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#860cba", + "x": -1925, + "y": -2408, + "zoom": 1.4001176423393464, + }, + "id": "07a35bc5aa2", + "square": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#860cba", + "x": -1925, + "y": -2408, + "zoom": 1.4001176423393464, + }, + "id": "07a35bc5aa2", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=other&query=params", + }, + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=query", + }, + }, + "slice_label": "Vel", + "slice_type": "hac_habitasse", + }, + ], +} +`; + +exports[`patches image fields (from Prismic) > withThumbnailsNoAlt > static zone 1`] = ` +{ + "field": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#1d17b0", + "x": -1859, + "y": 1185, + "zoom": 1.2989647419422317, + }, + "id": "a95cc61c373", + "square": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "#1d17b0", + "x": -1859, + "y": 1185, + "zoom": 1.2989647419422317, + }, + "id": "a95cc61c373", + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=other&query=params", + }, + "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?some=query", + }, +} +`; + +exports[`patches image fields > existing > group 1`] = ` +{ + "group": [ + { + "field": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "asset.id-existing", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + }, + }, + ], +} +`; + +exports[`patches image fields > existing > shared slice 1`] = ` +{ + "slices": [ + { + "id": "9b9dd0f2c3f", + "items": [ + { + "field": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "asset.id-existing", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?w=4608&h=3456&fit=crop", + }, + }, + ], + "primary": { + "field": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "asset.id-existing", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?w=4608&h=3456&fit=crop", + }, + "group": [ + { + "field": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "asset.id-existing", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?w=4608&h=3456&fit=crop", + }, + }, + ], + }, + "slice_label": null, + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", + }, + ], +} +`; + +exports[`patches image fields > existing > slice 1`] = ` +{ + "slices": [ + { + "id": "5306297c5ed", + "items": [ + { + "field": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "asset.id-existing", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", + }, + }, + ], + "primary": { + "field": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "asset.id-existing", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", + }, + }, + "slice_label": "Vel", + "slice_type": "hac_habitasse", + }, + ], +} +`; + +exports[`patches image fields > existing > static zone 1`] = ` +{ + "field": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "asset.id-existing", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + }, +} +`; + +exports[`patches image fields > new > group 1`] = ` +{ + "group": [ + { + "field": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "fdd322ca9d5", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", + }, + }, + ], +} +`; + +exports[`patches image fields > new > shared slice 1`] = ` +{ + "slices": [ + { + "id": "9b9dd0f2c3f", + "items": [ + { + "field": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "c0eddbd0255", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + }, + }, + ], + "primary": { + "field": { + "alt": null, + "copyright": null, + "dimensions": { + "height": 1, + "width": 1, + }, + "edit": { + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, + }, + "id": "c0eddbd0255", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + }, + "group": [ + { + "field": { + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#42f5cf", - "x": 427, - "y": 731, - "zoom": 1.6417661415510265, - }, - "id": "35eaa8ebee4", - "square": { - "alt": "Id aliquet risus feugiat in", - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "#42f5cf", - "x": 427, - "y": 731, - "zoom": 1.6417661415510265, - }, - "id": "35eaa8ebee4", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", + "id": "c0eddbd0255", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches image fields > otherRepositoryWithThumbnails > slice 1`] = ` +exports[`patches image fields > new > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { - "alt": "Pellentesque nec nam aliquam sem", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#f72dec", - "x": 2027, - "y": 7, - "zoom": 1.9216652845315787, - }, - "id": "7a35bc5aa2f", - "square": { - "alt": "Pellentesque nec nam aliquam sem", - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "#f72dec", - "x": 2027, - "y": 7, - "zoom": 1.9216652845315787, - }, - "id": "7a35bc5aa2f", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=other&query=params", + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=query", + "id": "82beb55ec2f", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", }, }, ], "primary": { "field": { - "alt": "Quam nulla porttitor massa id neque aliquam vestibulum morbi blandit", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#60cbac", - "x": -484, - "y": -2038, - "zoom": 1.8400009569805118, - }, - "id": "7a35bc5aa2f", - "square": { - "alt": "Quam nulla porttitor massa id neque aliquam vestibulum morbi blandit", - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "#60cbac", - "x": -484, - "y": -2038, - "zoom": 1.8400009569805118, - }, - "id": "7a35bc5aa2f", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=other&query=params", + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=query", + "id": "82beb55ec2f", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches image fields > otherRepositoryWithThumbnails > static zone 1`] = ` +exports[`patches image fields > new > static zone 1`] = ` { "field": { - "alt": "Gravida rutrum quisque non tellus orci", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#b1d17b", - "x": 3291, - "y": -730, - "zoom": 1.061566393836766, - }, - "id": "4a95cc61c37", - "square": { - "alt": "Gravida rutrum quisque non tellus orci", - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "#b1d17b", - "x": 3291, - "y": -730, - "zoom": 1.061566393836766, - }, - "id": "4a95cc61c37", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?some=other&query=params", + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?some=query", + "id": "bad670dad77", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, } `; -exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > group 1`] = ` +exports[`patches image fields > newLongForm > group 1`] = ` { "group": [ { @@ -901,40 +1461,24 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > group 1`] = "width": 1, }, "edit": { - "background": "#cfc26f", - "x": -2885, - "y": -2419, - "zoom": 1.7509753524211642, - }, - "id": "8d0985c0990", - "square": { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "#cfc26f", - "x": -2885, - "y": -2419, - "zoom": 1.7509753524211642, - }, - "id": "8d0985c0990", - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=other&query=params", + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=query", + "id": "fdd322ca9d5", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", }, }, ], } `; -exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slice 1`] = ` +exports[`patches image fields > newLongForm > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { @@ -945,29 +1489,13 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "width": 1, }, "edit": { - "background": "#9ed252", - "x": -1720, - "y": -191, - "zoom": 1.6165685319845957, - }, - "id": "35eaa8ebee4", - "square": { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "#9ed252", - "x": -1720, - "y": -191, - "zoom": 1.6165685319845957, - }, - "id": "35eaa8ebee4", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", + "id": "c0eddbd0255", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, }, ], @@ -980,29 +1508,13 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "width": 1, }, "edit": { - "background": "#4f4f59", - "x": 3094, - "y": -2976, - "zoom": 1.0855120641844143, - }, - "id": "35eaa8ebee4", - "square": { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "#4f4f59", - "x": 3094, - "y": -2976, - "zoom": 1.0855120641844143, - }, - "id": "35eaa8ebee4", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", + "id": "c0eddbd0255", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, "group": [ { @@ -1014,47 +1526,31 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > shared slic "width": 1, }, "edit": { - "background": "#42f5cf", - "x": 427, - "y": 731, - "zoom": 1.6417661415510265, - }, - "id": "35eaa8ebee4", - "square": { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "#42f5cf", - "x": 427, - "y": 731, - "zoom": 1.6417661415510265, - }, - "id": "35eaa8ebee4", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", + "id": "c0eddbd0255", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > slice 1`] = ` +exports[`patches image fields > newLongForm > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { @@ -1065,29 +1561,13 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > slice 1`] = "width": 1, }, "edit": { - "background": "#f72dec", - "x": 2027, - "y": 7, - "zoom": 1.9216652845315787, - }, - "id": "7a35bc5aa2f", - "square": { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "#f72dec", - "x": 2027, - "y": 7, - "zoom": 1.9216652845315787, - }, - "id": "7a35bc5aa2f", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=other&query=params", + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=query", + "id": "82beb55ec2f", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", }, }, ], @@ -1100,39 +1580,23 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > slice 1`] = "width": 1, }, "edit": { - "background": "#60cbac", - "x": -484, - "y": -2038, - "zoom": 1.8400009569805118, - }, - "id": "7a35bc5aa2f", - "square": { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "#60cbac", - "x": -484, - "y": -2038, - "zoom": 1.8400009569805118, - }, - "id": "7a35bc5aa2f", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=other&query=params", + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=query", + "id": "82beb55ec2f", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > static zone 1`] = ` +exports[`patches image fields > newLongForm > static zone 1`] = ` { "field": { "alt": null, @@ -1142,309 +1606,293 @@ exports[`patches image fields > otherRepositoryWithThumbnailsNoAlt > static zone "width": 1, }, "edit": { - "background": "#b1d17b", - "x": 3291, - "y": -730, - "zoom": 1.061566393836766, - }, - "id": "4a95cc61c37", - "square": { - "alt": null, - "copyright": null, - "dimensions": { - "height": 1, - "width": 1, - }, - "edit": { - "background": "#b1d17b", - "x": 3291, - "y": -730, - "zoom": 1.061566393836766, - }, - "id": "4a95cc61c37", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?some=other&query=params", + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?some=query", + "id": "bad670dad77", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, } `; -exports[`patches image fields > otherRepositoryWithTypeThumbnail > group 1`] = ` +exports[`patches image fields > newThumbnails > group 1`] = ` { "group": [ { "field": { - "alt": "Massa id neque aliquam vestibulum morbi blandit cursus risus", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#cfc26f", - "x": -2885, - "y": -2419, - "zoom": 1.7509753524211642, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "8d0985c0990", - "type": { - "alt": "Massa id neque aliquam vestibulum morbi blandit cursus risus", + "id": "fdd322ca9d5", + "square": { + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#cfc26f", - "x": -2885, - "y": -2419, - "zoom": 1.7509753524211642, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "8d0985c0990", - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=other&query=params", + "id": "fdd322ca9d5", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", }, - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?some=query", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", }, }, ], } `; -exports[`patches image fields > otherRepositoryWithTypeThumbnail > shared slice 1`] = ` +exports[`patches image fields > newThumbnails > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { - "alt": "Fermentum odio eu feugiat pretium nibh ipsum consequat", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#9ed252", - "x": -1720, - "y": -191, - "zoom": 1.6165685319845957, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "35eaa8ebee4", - "type": { - "alt": "Fermentum odio eu feugiat pretium nibh ipsum consequat", + "id": "c0eddbd0255", + "square": { + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#9ed252", - "x": -1720, - "y": -191, - "zoom": 1.6165685319845957, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "35eaa8ebee4", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", + "id": "c0eddbd0255", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, }, ], "primary": { "field": { - "alt": "Pellentesque pulvinar pellentesque habitant morbi tristique senectus et netus et malesuada fames ac", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#4f4f59", - "x": 3094, - "y": -2976, - "zoom": 1.0855120641844143, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "35eaa8ebee4", - "type": { - "alt": "Pellentesque pulvinar pellentesque habitant morbi tristique senectus et netus et malesuada fames ac", + "id": "c0eddbd0255", + "square": { + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#4f4f59", - "x": 3094, - "y": -2976, - "zoom": 1.0855120641844143, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "35eaa8ebee4", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", + "id": "c0eddbd0255", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, "group": [ { "field": { - "alt": "Id aliquet risus feugiat in", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#42f5cf", - "x": 427, - "y": 731, - "zoom": 1.6417661415510265, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "35eaa8ebee4", - "type": { - "alt": "Id aliquet risus feugiat in", + "id": "c0eddbd0255", + "square": { + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#42f5cf", - "x": 427, - "y": 731, - "zoom": 1.6417661415510265, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "35eaa8ebee4", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=other&query=params", + "id": "c0eddbd0255", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?some=query", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches image fields > otherRepositoryWithTypeThumbnail > slice 1`] = ` +exports[`patches image fields > newThumbnails > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { - "alt": "Pellentesque nec nam aliquam sem", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#f72dec", - "x": 2027, - "y": 7, - "zoom": 1.9216652845315787, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "7a35bc5aa2f", - "type": { - "alt": "Pellentesque nec nam aliquam sem", + "id": "82beb55ec2f", + "square": { + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#f72dec", - "x": 2027, - "y": 7, - "zoom": 1.9216652845315787, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "7a35bc5aa2f", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=other&query=params", + "id": "82beb55ec2f", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", }, - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=query", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", }, }, ], "primary": { "field": { - "alt": "Quam nulla porttitor massa id neque aliquam vestibulum morbi blandit", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#60cbac", - "x": -484, - "y": -2038, - "zoom": 1.8400009569805118, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "7a35bc5aa2f", - "type": { - "alt": "Quam nulla porttitor massa id neque aliquam vestibulum morbi blandit", + "id": "82beb55ec2f", + "square": { + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#60cbac", - "x": -484, - "y": -2038, - "zoom": 1.8400009569805118, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "7a35bc5aa2f", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=other&query=params", + "id": "82beb55ec2f", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", }, - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?some=query", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches image fields > otherRepositoryWithTypeThumbnail > static zone 1`] = ` +exports[`patches image fields > newThumbnails > static zone 1`] = ` { "field": { - "alt": "Gravida rutrum quisque non tellus orci", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#b1d17b", - "x": 3291, - "y": -730, - "zoom": 1.061566393836766, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "4a95cc61c37", - "type": { - "alt": "Gravida rutrum quisque non tellus orci", + "id": "bad670dad77", + "square": { + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#b1d17b", - "x": 3291, - "y": -730, - "zoom": 1.061566393836766, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "4a95cc61c37", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?some=other&query=params", + "id": "bad670dad77", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?some=query", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, } `; diff --git a/test/__snapshots__/writeClient-migrate-patch-linkToMedia.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-linkToMedia.test.ts.snap index a6d213fd..ceb749b4 100644 --- a/test/__snapshots__/writeClient-migrate-patch-linkToMedia.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-linkToMedia.test.ts.snap @@ -1,17 +1,269 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`patches link to media fields > existing > group 1`] = ` +exports[`patches link to media fields (from Prismic) > inRichText > group 1`] = ` +{ + "group": [ + { + "field": [ + { + "spans": [ + { + "end": 5, + "start": 0, + "type": "strong", + }, + { + "data": { + "height": "1", + "id": "fc26fe8d098", + "kind": "image", + "link_type": "Media", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "width": "1", + }, + "end": 5, + "start": 0, + "type": "hyperlink", + }, + ], + "text": "lorem", + "type": "paragraph", + }, + ], + }, + ], +} +`; + +exports[`patches link to media fields (from Prismic) > inRichText > shared slice 1`] = ` +{ + "slices": [ + { + "id": "9b9dd0f2c3f", + "items": [ + { + "field": [ + { + "spans": [ + { + "end": 5, + "start": 0, + "type": "strong", + }, + { + "data": { + "height": "1", + "id": "961adcf1f5d", + "kind": "image", + "link_type": "Media", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", + "width": "1", + }, + "end": 5, + "start": 0, + "type": "hyperlink", + }, + ], + "text": "lorem", + "type": "paragraph", + }, + ], + }, + ], + "primary": { + "field": [ + { + "spans": [ + { + "end": 5, + "start": 0, + "type": "strong", + }, + { + "data": { + "height": "1", + "id": "961adcf1f5d", + "kind": "image", + "link_type": "Media", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", + "width": "1", + }, + "end": 5, + "start": 0, + "type": "hyperlink", + }, + ], + "text": "lorem", + "type": "paragraph", + }, + ], + "group": [ + { + "field": [ + { + "spans": [ + { + "end": 5, + "start": 0, + "type": "strong", + }, + { + "data": { + "height": "1", + "id": "961adcf1f5d", + "kind": "image", + "link_type": "Media", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", + "width": "1", + }, + "end": 5, + "start": 0, + "type": "hyperlink", + }, + ], + "text": "lorem", + "type": "paragraph", + }, + ], + }, + ], + }, + "slice_label": null, + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", + }, + ], +} +`; + +exports[`patches link to media fields (from Prismic) > inRichText > slice 1`] = ` +{ + "slices": [ + { + "id": "5306297c5ed", + "items": [ + { + "field": [ + { + "spans": [ + { + "end": 5, + "start": 0, + "type": "strong", + }, + { + "data": { + "height": "1", + "id": "54f4a69ff72", + "kind": "image", + "link_type": "Media", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", + "width": "1", + }, + "end": 5, + "start": 0, + "type": "hyperlink", + }, + ], + "text": "lorem", + "type": "paragraph", + }, + ], + }, + ], + "primary": { + "field": [ + { + "spans": [ + { + "end": 5, + "start": 0, + "type": "strong", + }, + { + "data": { + "height": "1", + "id": "54f4a69ff72", + "kind": "image", + "link_type": "Media", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", + "width": "1", + }, + "end": 5, + "start": 0, + "type": "hyperlink", + }, + ], + "text": "lorem", + "type": "paragraph", + }, + ], + }, + "slice_label": "Vel", + "slice_type": "hac_habitasse", + }, + ], +} +`; + +exports[`patches link to media fields (from Prismic) > inRichText > static zone 1`] = ` +{ + "field": [ + { + "spans": [ + { + "end": 5, + "start": 0, + "type": "strong", + }, + { + "data": { + "height": "1", + "id": "1d17b04a95c", + "kind": "image", + "link_type": "Media", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "width": "1", + }, + "end": 5, + "start": 0, + "type": "hyperlink", + }, + ], + "text": "lorem", + "type": "paragraph", + }, + ], +} +`; + +exports[`patches link to media fields (from Prismic) > simple > group 1`] = ` { "group": [ { "field": { "height": "1", - "id": "id-existing", + "id": "fc26fe8d098", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", "width": "1", }, }, @@ -19,21 +271,21 @@ exports[`patches link to media fields > existing > group 1`] = ` } `; -exports[`patches link to media fields > existing > shared slice 1`] = ` +exports[`patches link to media fields (from Prismic) > simple > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { "height": "1", - "id": "id-existing", + "id": "961adcf1f5d", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", "width": "1", }, }, @@ -41,53 +293,53 @@ exports[`patches link to media fields > existing > shared slice 1`] = ` "primary": { "field": { "height": "1", - "id": "id-existing", + "id": "961adcf1f5d", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", "width": "1", }, "group": [ { "field": { "height": "1", - "id": "id-existing", + "id": "961adcf1f5d", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", "width": "1", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches link to media fields > existing > slice 1`] = ` +exports[`patches link to media fields (from Prismic) > simple > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { "height": "1", - "id": "id-existing", + "id": "54f4a69ff72", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", "width": "1", }, }, @@ -95,145 +347,159 @@ exports[`patches link to media fields > existing > slice 1`] = ` "primary": { "field": { "height": "1", - "id": "id-existing", + "id": "54f4a69ff72", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", "width": "1", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches link to media fields > existing > static zone 1`] = ` +exports[`patches link to media fields (from Prismic) > simple > static zone 1`] = ` { "field": { "height": "1", - "id": "id-existing", + "id": "1d17b04a95c", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, } `; -exports[`patches link to media fields > existingNonImage > group 1`] = ` +exports[`patches link to media fields > existing > group 1`] = ` { "group": [ { "field": { - "id": "id-existing", - "kind": "document", + "height": "1", + "id": "asset.id-existing", + "kind": "image", "link_type": "Media", - "name": "foo.pdf", + "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "width": "1", }, }, ], } `; -exports[`patches link to media fields > existingNonImage > shared slice 1`] = ` +exports[`patches link to media fields > existing > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { - "id": "id-existing", - "kind": "document", + "height": "1", + "id": "asset.id-existing", + "kind": "image", "link_type": "Media", - "name": "foo.pdf", + "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?w=4608&h=3456&fit=crop", + "width": "1", }, }, ], "primary": { "field": { - "id": "id-existing", - "kind": "document", + "height": "1", + "id": "asset.id-existing", + "kind": "image", "link_type": "Media", - "name": "foo.pdf", + "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?w=4608&h=3456&fit=crop", + "width": "1", }, "group": [ { "field": { - "id": "id-existing", - "kind": "document", + "height": "1", + "id": "asset.id-existing", + "kind": "image", "link_type": "Media", - "name": "foo.pdf", + "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?w=4608&h=3456&fit=crop", + "width": "1", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches link to media fields > existingNonImage > slice 1`] = ` +exports[`patches link to media fields > existing > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { - "id": "id-existing", - "kind": "document", + "height": "1", + "id": "asset.id-existing", + "kind": "image", "link_type": "Media", - "name": "foo.pdf", + "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", + "width": "1", }, }, ], "primary": { "field": { - "id": "id-existing", - "kind": "document", + "height": "1", + "id": "asset.id-existing", + "kind": "image", "link_type": "Media", - "name": "foo.pdf", + "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", + "width": "1", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches link to media fields > existingNonImage > static zone 1`] = ` +exports[`patches link to media fields > existing > static zone 1`] = ` { "field": { - "id": "id-existing", - "kind": "document", + "height": "1", + "id": "asset.id-existing", + "kind": "image", "link_type": "Media", - "name": "foo.pdf", + "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "width": "1", }, } `; @@ -244,12 +510,12 @@ exports[`patches link to media fields > new > group 1`] = ` { "field": { "height": "1", - "id": "dfdd322ca9d", + "id": "fdd322ca9d5", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", "width": "1", }, }, @@ -261,17 +527,17 @@ exports[`patches link to media fields > new > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { "height": "1", - "id": "0eddbd0255b", + "id": "c0eddbd0255", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, }, @@ -279,33 +545,33 @@ exports[`patches link to media fields > new > shared slice 1`] = ` "primary": { "field": { "height": "1", - "id": "0eddbd0255b", + "id": "c0eddbd0255", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, "group": [ { "field": { "height": "1", - "id": "0eddbd0255b", + "id": "c0eddbd0255", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } @@ -315,67 +581,180 @@ exports[`patches link to media fields > new > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", + "items": [ + { + "field": { + "height": "1", + "id": "82beb55ec2f", + "kind": "image", + "link_type": "Media", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", + "width": "1", + }, + }, + ], + "primary": { + "field": { + "height": "1", + "id": "82beb55ec2f", + "kind": "image", + "link_type": "Media", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", + "width": "1", + }, + }, + "slice_label": "Vel", + "slice_type": "hac_habitasse", + }, + ], +} +`; + +exports[`patches link to media fields > new > static zone 1`] = ` +{ + "field": { + "height": "1", + "id": "bad670dad77", + "kind": "image", + "link_type": "Media", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "width": "1", + }, +} +`; + +exports[`patches link to media fields > newNonImage > group 1`] = ` +{ + "group": [ + { + "field": { + "id": "fdd322ca9d5", + "kind": "document", + "link_type": "Media", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", + }, + }, + ], +} +`; + +exports[`patches link to media fields > newNonImage > shared slice 1`] = ` +{ + "slices": [ + { + "id": "9b9dd0f2c3f", + "items": [ + { + "field": { + "id": "c0eddbd0255", + "kind": "document", + "link_type": "Media", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + }, + }, + ], + "primary": { + "field": { + "id": "c0eddbd0255", + "kind": "document", + "link_type": "Media", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + }, + "group": [ + { + "field": { + "id": "c0eddbd0255", + "kind": "document", + "link_type": "Media", + "name": "default.jpg", + "size": "1", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + }, + }, + ], + }, + "slice_label": null, + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", + }, + ], +} +`; + +exports[`patches link to media fields > newNonImage > slice 1`] = ` +{ + "slices": [ + { + "id": "5306297c5ed", "items": [ { "field": { - "height": "1", - "id": "2beb55ec2f4", - "kind": "image", + "id": "82beb55ec2f", + "kind": "document", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1444464666168-49d633b86797?w=4844&h=3234&fit=crop", - "width": "1", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", }, }, ], "primary": { "field": { - "height": "1", - "id": "2beb55ec2f4", - "kind": "image", + "id": "82beb55ec2f", + "kind": "document", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1444464666168-49d633b86797?w=4844&h=3234&fit=crop", - "width": "1", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches link to media fields > new > static zone 1`] = ` +exports[`patches link to media fields > newNonImage > static zone 1`] = ` { "field": { - "height": "1", - "id": "bbad670dad7", - "kind": "image", + "id": "bad670dad77", + "kind": "document", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", - "width": "1", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, } `; -exports[`patches link to media fields > otherRepository > group 1`] = ` +exports[`patches link to media fields > newWithText > group 1`] = ` { "group": [ { "field": { "height": "1", - "id": "cfc26fe8d09", + "id": "fdd322ca9d5", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?w=6000&h=4000&fit=crop", + "text": "foo", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", "width": "1", }, }, @@ -383,21 +762,22 @@ exports[`patches link to media fields > otherRepository > group 1`] = ` } `; -exports[`patches link to media fields > otherRepository > shared slice 1`] = ` +exports[`patches link to media fields > newWithText > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": { "height": "1", - "id": "61adcf1f5db", + "id": "c0eddbd0255", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", + "text": "foo", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, }, @@ -405,53 +785,56 @@ exports[`patches link to media fields > otherRepository > shared slice 1`] = ` "primary": { "field": { "height": "1", - "id": "61adcf1f5db", + "id": "c0eddbd0255", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", + "text": "foo", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, "group": [ { "field": { "height": "1", - "id": "61adcf1f5db", + "id": "c0eddbd0255", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", + "text": "foo", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches link to media fields > otherRepository > slice 1`] = ` +exports[`patches link to media fields > newWithText > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": { "height": "1", - "id": "4f4a69ff72d", + "id": "82beb55ec2f", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "text": "foo", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", "width": "1", }, }, @@ -459,32 +842,34 @@ exports[`patches link to media fields > otherRepository > slice 1`] = ` "primary": { "field": { "height": "1", - "id": "4f4a69ff72d", + "id": "82beb55ec2f", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", + "text": "foo", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", "width": "1", }, }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches link to media fields > otherRepository > static zone 1`] = ` +exports[`patches link to media fields > newWithText > static zone 1`] = ` { "field": { "height": "1", - "id": "b1d17b04a95", + "id": "bad670dad77", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "text": "foo", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", "width": "1", }, } @@ -505,12 +890,12 @@ exports[`patches link to media fields > richTextExisting > group 1`] = ` { "data": { "height": "1", - "id": "id-existing", + "id": "asset.id-existing", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", "width": "1", }, "end": 5, @@ -531,7 +916,7 @@ exports[`patches link to media fields > richTextExisting > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": [ @@ -545,12 +930,12 @@ exports[`patches link to media fields > richTextExisting > shared slice 1`] = ` { "data": { "height": "1", - "id": "id-existing", + "id": "asset.id-existing", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?w=4608&h=3456&fit=crop", "width": "1", }, "end": 5, @@ -576,12 +961,12 @@ exports[`patches link to media fields > richTextExisting > shared slice 1`] = ` { "data": { "height": "1", - "id": "id-existing", + "id": "asset.id-existing", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?w=4608&h=3456&fit=crop", "width": "1", }, "end": 5, @@ -606,12 +991,12 @@ exports[`patches link to media fields > richTextExisting > shared slice 1`] = ` { "data": { "height": "1", - "id": "id-existing", + "id": "asset.id-existing", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?w=4608&h=3456&fit=crop", "width": "1", }, "end": 5, @@ -627,9 +1012,9 @@ exports[`patches link to media fields > richTextExisting > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } @@ -639,7 +1024,7 @@ exports[`patches link to media fields > richTextExisting > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": [ @@ -653,12 +1038,12 @@ exports[`patches link to media fields > richTextExisting > slice 1`] = ` { "data": { "height": "1", - "id": "id-existing", + "id": "asset.id-existing", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", "width": "1", }, "end": 5, @@ -684,12 +1069,12 @@ exports[`patches link to media fields > richTextExisting > slice 1`] = ` { "data": { "height": "1", - "id": "id-existing", + "id": "asset.id-existing", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", "width": "1", }, "end": 5, @@ -702,8 +1087,8 @@ exports[`patches link to media fields > richTextExisting > slice 1`] = ` }, ], }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } @@ -722,12 +1107,12 @@ exports[`patches link to media fields > richTextExisting > static zone 1`] = ` { "data": { "height": "1", - "id": "id-existing", + "id": "asset.id-existing", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", "width": "1", }, "end": 5, @@ -757,12 +1142,12 @@ exports[`patches link to media fields > richTextNew > group 1`] = ` { "data": { "height": "1", - "id": "dfdd322ca9d", + "id": "fdd322ca9d5", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", "width": "1", }, "end": 5, @@ -783,7 +1168,7 @@ exports[`patches link to media fields > richTextNew > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": [ @@ -797,12 +1182,12 @@ exports[`patches link to media fields > richTextNew > shared slice 1`] = ` { "data": { "height": "1", - "id": "0eddbd0255b", + "id": "c0eddbd0255", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, "end": 5, @@ -828,12 +1213,12 @@ exports[`patches link to media fields > richTextNew > shared slice 1`] = ` { "data": { "height": "1", - "id": "0eddbd0255b", + "id": "c0eddbd0255", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, "end": 5, @@ -858,12 +1243,12 @@ exports[`patches link to media fields > richTextNew > shared slice 1`] = ` { "data": { "height": "1", - "id": "0eddbd0255b", + "id": "c0eddbd0255", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", "width": "1", }, "end": 5, @@ -879,9 +1264,9 @@ exports[`patches link to media fields > richTextNew > shared slice 1`] = ` ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } @@ -891,7 +1276,7 @@ exports[`patches link to media fields > richTextNew > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": [ @@ -905,12 +1290,12 @@ exports[`patches link to media fields > richTextNew > slice 1`] = ` { "data": { "height": "1", - "id": "2beb55ec2f4", + "id": "82beb55ec2f", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1444464666168-49d633b86797?w=4844&h=3234&fit=crop", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", "width": "1", }, "end": 5, @@ -936,12 +1321,12 @@ exports[`patches link to media fields > richTextNew > slice 1`] = ` { "data": { "height": "1", - "id": "2beb55ec2f4", + "id": "82beb55ec2f", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1444464666168-49d633b86797?w=4844&h=3234&fit=crop", + "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", "width": "1", }, "end": 5, @@ -954,8 +1339,8 @@ exports[`patches link to media fields > richTextNew > slice 1`] = ` }, ], }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } @@ -974,264 +1359,12 @@ exports[`patches link to media fields > richTextNew > static zone 1`] = ` { "data": { "height": "1", - "id": "bbad670dad7", - "kind": "image", - "link_type": "Media", - "name": "default.jpg", - "size": "1", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=7372&h=4392&fit=crop", - "width": "1", - }, - "end": 5, - "start": 0, - "type": "hyperlink", - }, - ], - "text": "lorem", - "type": "paragraph", - }, - ], -} -`; - -exports[`patches link to media fields > richTextOtherRepository > group 1`] = ` -{ - "group": [ - { - "field": [ - { - "spans": [ - { - "end": 5, - "start": 0, - "type": "strong", - }, - { - "data": { - "height": "1", - "id": "cfc26fe8d09", - "kind": "image", - "link_type": "Media", - "name": "default.jpg", - "size": "1", - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?w=6000&h=4000&fit=crop", - "width": "1", - }, - "end": 5, - "start": 0, - "type": "hyperlink", - }, - ], - "text": "lorem", - "type": "paragraph", - }, - ], - }, - ], -} -`; - -exports[`patches link to media fields > richTextOtherRepository > shared slice 1`] = ` -{ - "slices": [ - { - "id": "b9dd0f2c3f8", - "items": [ - { - "field": [ - { - "spans": [ - { - "end": 5, - "start": 0, - "type": "strong", - }, - { - "data": { - "height": "1", - "id": "61adcf1f5db", - "kind": "image", - "link_type": "Media", - "name": "default.jpg", - "size": "1", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", - "width": "1", - }, - "end": 5, - "start": 0, - "type": "hyperlink", - }, - ], - "text": "lorem", - "type": "paragraph", - }, - ], - }, - ], - "primary": { - "field": [ - { - "spans": [ - { - "end": 5, - "start": 0, - "type": "strong", - }, - { - "data": { - "height": "1", - "id": "61adcf1f5db", - "kind": "image", - "link_type": "Media", - "name": "default.jpg", - "size": "1", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", - "width": "1", - }, - "end": 5, - "start": 0, - "type": "hyperlink", - }, - ], - "text": "lorem", - "type": "paragraph", - }, - ], - "group": [ - { - "field": [ - { - "spans": [ - { - "end": 5, - "start": 0, - "type": "strong", - }, - { - "data": { - "height": "1", - "id": "61adcf1f5db", - "kind": "image", - "link_type": "Media", - "name": "default.jpg", - "size": "1", - "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", - "width": "1", - }, - "end": 5, - "start": 0, - "type": "hyperlink", - }, - ], - "text": "lorem", - "type": "paragraph", - }, - ], - }, - ], - }, - "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", - }, - ], -} -`; - -exports[`patches link to media fields > richTextOtherRepository > slice 1`] = ` -{ - "slices": [ - { - "id": "306297c5eda", - "items": [ - { - "field": [ - { - "spans": [ - { - "end": 5, - "start": 0, - "type": "strong", - }, - { - "data": { - "height": "1", - "id": "4f4a69ff72d", - "kind": "image", - "link_type": "Media", - "name": "default.jpg", - "size": "1", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", - "width": "1", - }, - "end": 5, - "start": 0, - "type": "hyperlink", - }, - ], - "text": "lorem", - "type": "paragraph", - }, - ], - }, - ], - "primary": { - "field": [ - { - "spans": [ - { - "end": 5, - "start": 0, - "type": "strong", - }, - { - "data": { - "height": "1", - "id": "4f4a69ff72d", - "kind": "image", - "link_type": "Media", - "name": "default.jpg", - "size": "1", - "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", - "width": "1", - }, - "end": 5, - "start": 0, - "type": "hyperlink", - }, - ], - "text": "lorem", - "type": "paragraph", - }, - ], - }, - "slice_label": "Aliquet", - "slice_type": "vel", - }, - ], -} -`; - -exports[`patches link to media fields > richTextOtherRepository > static zone 1`] = ` -{ - "field": [ - { - "spans": [ - { - "end": 5, - "start": 0, - "type": "strong", - }, - { - "data": { - "height": "1", - "id": "b1d17b04a95", + "id": "bad670dad77", "kind": "image", "link_type": "Media", "name": "default.jpg", "size": "1", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", "width": "1", }, "end": 5, diff --git a/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap index 5df8c17c..0aa39cff 100644 --- a/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-rtImageNode.test.ts.snap @@ -1,31 +1,31 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`patches rich text image nodes > existing > group 1`] = ` +exports[`patches rich text image nodes (from Prismic) > simple > group 1`] = ` { "group": [ { "field": [ { "spans": [], - "text": "Donec Enim Diam Vulputate Ut Pharetra Sit Amet Aliquam", - "type": "heading4", + "text": "Pulvinar elementum integer enim neque volutpat ac tincidunt vitae semper quis. Gravida hendrerit lectus a molestie lorem ipsum dolor sit amet. Mauris sit amet massa vitae tortor condimentum lacinia. Blandit volutpat maecenas volutpat blandit aliquam. Massa eget egestas purus viverra accumsan in nisl nisi scelerisque. Imperdiet dui accumsan sit amet nulla facilisi morbi tempus iaculis.", + "type": "paragraph", }, { - "alt": null, + "alt": "Phasellus faucibus scelerisque eleifend donec pretium vulputate", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#14a045", + "x": -1057, + "y": 1363, + "zoom": 1.3020761265191427, }, - "id": "id-existing", + "id": "097ac4a7efe", "type": "image", - "url": "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg?w=6373&h=4253&fit=crop", + "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e", }, ], }, @@ -33,35 +33,35 @@ exports[`patches rich text image nodes > existing > group 1`] = ` } `; -exports[`patches rich text image nodes > existing > shared slice 1`] = ` +exports[`patches rich text image nodes (from Prismic) > simple > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": [ { "spans": [], - "text": "A molestie lorem ipsum dolor sit amet consectetur adipiscing elit ut", - "type": "list-item", + "text": "Ultrices In Iaculis Nunc Sed Augue Lacus Viverra Vitae Congue Eu", + "type": "heading4", }, { - "alt": null, + "alt": "Dolor morbi non arcu risus quis varius quam quisque id diam vel", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#073a8e", + "x": -531, + "y": 1549, + "zoom": 1.1496011393958705, }, - "id": "id-existing", + "id": "9378bc2e4da", "type": "image", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1", }, ], }, @@ -70,25 +70,25 @@ exports[`patches rich text image nodes > existing > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium.", - "type": "preformatted", + "text": "Eget magna fermentum iaculis eu non diam phasellus vestibulum lorem. Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium. Neque aliquam vestibulum morbi blandit cursus risus at ultrices mi tempus imperdiet nulla malesuada. Fermentum posuere urna nec tincidunt praesent semper feugiat nibh. Eleifend donec pretium vulputate sapien.", + "type": "paragraph", }, { - "alt": null, + "alt": "A scelerisque purus semper eget duis at tellus at urna condimentum mattis", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#53af6d", + "x": 1608, + "y": -790, + "zoom": 1.8290852631509968, }, - "id": "id-existing", + "id": "9378bc2e4da", "type": "image", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1", }, ], "group": [ @@ -96,68 +96,68 @@ exports[`patches rich text image nodes > existing > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Vel Elit Scelerisque Mauris Pellentesque Pulvinar Pellentesque", - "type": "heading3", + "text": "Consectetur adipiscing elit duis tristique sollicitudin nibh sit amet commodo", + "type": "o-list-item", }, { - "alt": null, + "alt": "Lorem mollis aliquam ut porttitor leo a", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#35eaa8", + "x": -757, + "y": -123, + "zoom": 1.2194779259663722, }, - "id": "id-existing", + "id": "9378bc2e4da", "type": "image", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff?w=5616&h=3744&fit=crop", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1", }, ], }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches rich text image nodes > existing > slice 1`] = ` +exports[`patches rich text image nodes (from Prismic) > simple > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": [ { "spans": [], - "text": "Diam Ut Venenatis Tellus", - "type": "heading6", + "text": "Auctor neque vitae tempus quam. At ultrices mi tempus imperdiet nulla malesuada pellentesque elit eget gravida cum.", + "type": "paragraph", }, { - "alt": null, + "alt": "Sed id semper risus in hendrerit gravida rutrum", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#104dde", + "x": -1621, + "y": -870, + "zoom": 1.7278759511485409, }, - "id": "id-existing", + "id": "2003a644c30", "type": "image", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", }, ], }, @@ -166,90 +166,94 @@ exports[`patches rich text image nodes > existing > slice 1`] = ` "field": [ { "spans": [], - "text": "Tincidunt Vitae Semper Quis Lectus Nulla", - "type": "heading4", + "text": "Pharetra et ultrices neque ornare aenean euismod. Mauris sit amet massa vitae tortor condimentum lacinia quis vel eros donec ac.", + "type": "preformatted", }, { - "alt": null, + "alt": "Vitae et leo duis ut diam quam nulla porttitor", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#cc54f4", + "x": 637, + "y": -1697, + "zoom": 1.1481742186351154, }, - "id": "id-existing", + "id": "2003a644c30", "type": "image", - "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", }, ], }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches rich text image nodes > existing > static zone 1`] = ` +exports[`patches rich text image nodes (from Prismic) > simple > static zone 1`] = ` { "field": [ { "spans": [], - "text": "Interdum Velit Euismod", - "type": "heading5", + "text": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis. Tincidunt praesent semper feugiat nibh sed pulvinar proin gravida hendrerit lectus a.", + "type": "paragraph", }, { - "alt": null, + "alt": "Adipiscing bibendum est ultricies integer quis auctor elit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#b943c8", + "x": 592, + "y": 260, + "zoom": 1.3971999251277185, }, - "id": "id-existing", + "id": "b5df4522c1a", "type": "image", - "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", + "url": "https://images.unsplash.com/photo-1504198266287-1659872e6590", }, ], } `; -exports[`patches rich text image nodes > new > group 1`] = ` +exports[`patches rich text image nodes (from Prismic) > withLinkTo > group 1`] = ` { "group": [ { "field": [ { "spans": [], - "text": "Donec Enim Diam Vulputate Ut Pharetra Sit Amet Aliquam", - "type": "heading4", + "text": "Pulvinar elementum integer enim neque volutpat ac tincidunt vitae semper quis. Gravida hendrerit lectus a molestie lorem ipsum dolor sit amet. Mauris sit amet massa vitae tortor condimentum lacinia. Blandit volutpat maecenas volutpat blandit aliquam. Massa eget egestas purus viverra accumsan in nisl nisi scelerisque. Imperdiet dui accumsan sit amet nulla facilisi morbi tempus iaculis.", + "type": "paragraph", }, { - "alt": null, + "alt": "Phasellus faucibus scelerisque eleifend donec pretium vulputate", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#14a045", + "x": -1057, + "y": 1363, + "zoom": 1.3020761265191427, + }, + "id": "097ac4a7efe", + "linkTo": { + "id": "other.id-existing", + "link_type": "Document", }, - "id": "c1d5d24feae", "type": "image", - "url": "https://images.unsplash.com/photo-1504198266287-1659872e6590?w=4272&h=2848&fit=crop", + "url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e", }, ], }, @@ -257,35 +261,39 @@ exports[`patches rich text image nodes > new > group 1`] = ` } `; -exports[`patches rich text image nodes > new > shared slice 1`] = ` +exports[`patches rich text image nodes (from Prismic) > withLinkTo > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": [ { "spans": [], - "text": "A molestie lorem ipsum dolor sit amet consectetur adipiscing elit ut", - "type": "list-item", + "text": "Ultrices In Iaculis Nunc Sed Augue Lacus Viverra Vitae Congue Eu", + "type": "heading4", }, { - "alt": null, + "alt": "Dolor morbi non arcu risus quis varius quam quisque id diam vel", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#073a8e", + "x": -531, + "y": 1549, + "zoom": 1.1496011393958705, + }, + "id": "9378bc2e4da", + "linkTo": { + "id": "other.id-existing", + "link_type": "Document", }, - "id": "961adcf1f5d", "type": "image", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1", }, ], }, @@ -294,25 +302,29 @@ exports[`patches rich text image nodes > new > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium.", - "type": "preformatted", + "text": "Eget magna fermentum iaculis eu non diam phasellus vestibulum lorem. Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium. Neque aliquam vestibulum morbi blandit cursus risus at ultrices mi tempus imperdiet nulla malesuada. Fermentum posuere urna nec tincidunt praesent semper feugiat nibh. Eleifend donec pretium vulputate sapien.", + "type": "paragraph", }, { - "alt": null, + "alt": "A scelerisque purus semper eget duis at tellus at urna condimentum mattis", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#53af6d", + "x": 1608, + "y": -790, + "zoom": 1.8290852631509968, + }, + "id": "9378bc2e4da", + "linkTo": { + "id": "other.id-existing", + "link_type": "Document", }, - "id": "961adcf1f5d", "type": "image", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1", }, ], "group": [ @@ -320,68 +332,76 @@ exports[`patches rich text image nodes > new > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Vel Elit Scelerisque Mauris Pellentesque Pulvinar Pellentesque", - "type": "heading3", + "text": "Consectetur adipiscing elit duis tristique sollicitudin nibh sit amet commodo", + "type": "o-list-item", }, { - "alt": null, + "alt": "Lorem mollis aliquam ut porttitor leo a", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#35eaa8", + "x": -757, + "y": -123, + "zoom": 1.2194779259663722, + }, + "id": "9378bc2e4da", + "linkTo": { + "id": "other.id-existing", + "link_type": "Document", }, - "id": "961adcf1f5d", "type": "image", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1", }, ], }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches rich text image nodes > new > slice 1`] = ` +exports[`patches rich text image nodes (from Prismic) > withLinkTo > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": [ { "spans": [], - "text": "Diam Ut Venenatis Tellus", - "type": "heading6", + "text": "Auctor neque vitae tempus quam. At ultrices mi tempus imperdiet nulla malesuada pellentesque elit eget gravida cum.", + "type": "paragraph", }, { - "alt": null, + "alt": "Sed id semper risus in hendrerit gravida rutrum", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#104dde", + "x": -1621, + "y": -870, + "zoom": 1.7278759511485409, + }, + "id": "2003a644c30", + "linkTo": { + "id": "other.id-existing", + "link_type": "Document", }, - "id": "61cc54f4a69", "type": "image", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", }, ], }, @@ -390,73 +410,81 @@ exports[`patches rich text image nodes > new > slice 1`] = ` "field": [ { "spans": [], - "text": "Tincidunt Vitae Semper Quis Lectus Nulla", - "type": "heading4", + "text": "Pharetra et ultrices neque ornare aenean euismod. Mauris sit amet massa vitae tortor condimentum lacinia quis vel eros donec ac.", + "type": "preformatted", }, { - "alt": null, + "alt": "Vitae et leo duis ut diam quam nulla porttitor", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#cc54f4", + "x": 637, + "y": -1697, + "zoom": 1.1481742186351154, + }, + "id": "2003a644c30", + "linkTo": { + "id": "other.id-existing", + "link_type": "Document", }, - "id": "61cc54f4a69", "type": "image", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", }, ], }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches rich text image nodes > new > static zone 1`] = ` +exports[`patches rich text image nodes (from Prismic) > withLinkTo > static zone 1`] = ` { "field": [ { "spans": [], - "text": "Interdum Velit Euismod", - "type": "heading5", + "text": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis. Tincidunt praesent semper feugiat nibh sed pulvinar proin gravida hendrerit lectus a.", + "type": "paragraph", }, { - "alt": null, + "alt": "Adipiscing bibendum est ultricies integer quis auctor elit", "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "transparent", - "x": 0, - "y": 0, - "zoom": 1, + "background": "#b943c8", + "x": 592, + "y": 260, + "zoom": 1.3971999251277185, + }, + "id": "b5df4522c1a", + "linkTo": { + "id": "other.id-existing", + "link_type": "Document", }, - "id": "ed908b1e225", "type": "image", - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?w=6000&h=4000&fit=crop", + "url": "https://images.unsplash.com/photo-1504198266287-1659872e6590", }, ], } `; -exports[`patches rich text image nodes > newLinkTo > group 1`] = ` +exports[`patches rich text image nodes > existing > group 1`] = ` { "group": [ { "field": [ { "spans": [], - "text": "Donec Enim Diam Vulputate Ut Pharetra Sit Amet Aliquam", - "type": "heading4", + "text": "Pulvinar elementum integer enim neque volutpat ac tincidunt vitae semper quis. Gravida hendrerit lectus a molestie lorem ipsum dolor sit amet. Mauris sit amet massa vitae tortor condimentum lacinia. Blandit volutpat maecenas volutpat blandit aliquam. Massa eget egestas purus viverra accumsan in nisl nisi scelerisque. Imperdiet dui accumsan sit amet nulla facilisi morbi tempus iaculis.", + "type": "paragraph", }, { "alt": null, @@ -471,13 +499,9 @@ exports[`patches rich text image nodes > newLinkTo > group 1`] = ` "y": 0, "zoom": 1, }, - "id": "c1d5d24feae", - "linkTo": { - "id": "id-existing", - "link_type": "Document", - }, + "id": "asset.id-existing", "type": "image", - "url": "https://images.unsplash.com/photo-1504198266287-1659872e6590?w=4272&h=2848&fit=crop", + "url": "https://images.unsplash.com/photo-1470770903676-69b98201ea1c?w=4554&h=3036&fit=crop", }, ], }, @@ -485,18 +509,18 @@ exports[`patches rich text image nodes > newLinkTo > group 1`] = ` } `; -exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` +exports[`patches rich text image nodes > existing > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": [ { "spans": [], - "text": "A molestie lorem ipsum dolor sit amet consectetur adipiscing elit ut", - "type": "list-item", + "text": "Diam", + "type": "heading4", }, { "alt": null, @@ -511,13 +535,9 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "961adcf1f5d", - "linkTo": { - "id": "id-existing", - "link_type": "Document", - }, + "id": "asset.id-existing", "type": "image", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?w=4608&h=3456&fit=crop", }, ], }, @@ -526,8 +546,8 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium.", - "type": "preformatted", + "text": "Eget magna fermentum iaculis eu non diam phasellus vestibulum lorem. Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium. Neque aliquam vestibulum morbi blandit cursus risus at ultrices mi tempus imperdiet nulla malesuada. Fermentum posuere urna nec tincidunt praesent semper feugiat nibh. Eleifend donec pretium vulputate sapien.", + "type": "paragraph", }, { "alt": null, @@ -542,13 +562,9 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "961adcf1f5d", - "linkTo": { - "id": "id-existing", - "link_type": "Document", - }, + "id": "asset.id-existing", "type": "image", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?w=4608&h=3456&fit=crop", }, ], "group": [ @@ -556,8 +572,8 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Vel Elit Scelerisque Mauris Pellentesque Pulvinar Pellentesque", - "type": "heading3", + "text": "Quis Enim Lobortis", + "type": "heading2", }, { "alt": null, @@ -572,39 +588,35 @@ exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "961adcf1f5d", - "linkTo": { - "id": "id-existing", - "link_type": "Document", - }, + "id": "asset.id-existing", "type": "image", - "url": "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?w=2200&h=1467&fit=crop", + "url": "https://images.unsplash.com/photo-1504567961542-e24d9439a724?w=4608&h=3456&fit=crop", }, ], }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches rich text image nodes > newLinkTo > slice 1`] = ` +exports[`patches rich text image nodes > existing > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": [ { "spans": [], - "text": "Diam Ut Venenatis Tellus", - "type": "heading6", + "text": "Ultrices dui sapien eget mi proin sed libero enim sed. Diam ut venenatis tellus in metus vulputate eu scelerisque felis imperdiet. Sed nisi lacus sed viverra tellus in hac habitasse. Eget mi proin sed libero enim sed faucibus turpis. Pellentesque id nibh tortor id aliquet. Aliquam sem et tortor consequat id porta nibh venenatis cras sed felis.", + "type": "paragraph", }, { "alt": null, @@ -619,13 +631,9 @@ exports[`patches rich text image nodes > newLinkTo > slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "61cc54f4a69", - "linkTo": { - "id": "id-existing", - "link_type": "Document", - }, + "id": "asset.id-existing", "type": "image", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", }, ], }, @@ -634,8 +642,8 @@ exports[`patches rich text image nodes > newLinkTo > slice 1`] = ` "field": [ { "spans": [], - "text": "Tincidunt Vitae Semper Quis Lectus Nulla", - "type": "heading4", + "text": "Pharetra et ultrices neque ornare aenean euismod. Mauris sit amet massa vitae tortor condimentum lacinia quis vel eros donec ac.", + "type": "preformatted", }, { "alt": null, @@ -650,30 +658,26 @@ exports[`patches rich text image nodes > newLinkTo > slice 1`] = ` "y": 0, "zoom": 1, }, - "id": "61cc54f4a69", - "linkTo": { - "id": "id-existing", - "link_type": "Document", - }, + "id": "asset.id-existing", "type": "image", - "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", + "url": "https://images.unsplash.com/photo-1587502537745-84b86da1204f?w=6550&h=4367&fit=crop", }, ], }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches rich text image nodes > newLinkTo > static zone 1`] = ` +exports[`patches rich text image nodes > existing > static zone 1`] = ` { "field": [ { "spans": [], - "text": "Interdum Velit Euismod", - "type": "heading5", + "text": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis. Tincidunt praesent semper feugiat nibh sed pulvinar proin gravida hendrerit lectus a.", + "type": "paragraph", }, { "alt": null, @@ -688,44 +692,40 @@ exports[`patches rich text image nodes > newLinkTo > static zone 1`] = ` "y": 0, "zoom": 1, }, - "id": "ed908b1e225", - "linkTo": { - "id": "id-existing", - "link_type": "Document", - }, + "id": "asset.id-existing", "type": "image", - "url": "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f?w=6000&h=4000&fit=crop", + "url": "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d?w=4240&h=2832&fit=crop", }, ], } `; -exports[`patches rich text image nodes > otherRepository > group 1`] = ` +exports[`patches rich text image nodes > new > group 1`] = ` { "group": [ { "field": [ { "spans": [], - "text": "Donec Enim Diam Vulputate Ut Pharetra Sit Amet Aliquam", - "type": "heading4", + "text": "Pulvinar elementum integer enim neque volutpat ac tincidunt vitae semper quis. Gravida hendrerit lectus a molestie lorem ipsum dolor sit amet. Mauris sit amet massa vitae tortor condimentum lacinia. Blandit volutpat maecenas volutpat blandit aliquam. Massa eget egestas purus viverra accumsan in nisl nisi scelerisque. Imperdiet dui accumsan sit amet nulla facilisi morbi tempus iaculis.", + "type": "paragraph", }, { - "alt": "Feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper morbi", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#5c0990", - "x": 2090, - "y": -1492, - "zoom": 1.854310159304717, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "6442e21ad60", + "id": "26fe8d0985c", "type": "image", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, ], }, @@ -733,46 +733,35 @@ exports[`patches rich text image nodes > otherRepository > group 1`] = ` } `; -exports[`patches rich text image nodes > otherRepository > shared slice 1`] = ` +exports[`patches rich text image nodes > new > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": [ { - "oembed": { - "embed_url": "https://twitter.com/prismicio/status/1354835716430319617", - "height": 113, - "html": " - -", - "thumbnail_height": null, - "thumbnail_url": null, - "thumbnail_width": null, - "type": "rich", - "version": "1.0", - "width": 200, - }, - "type": "embed", + "spans": [], + "text": "Diam", + "type": "heading4", }, { - "alt": "Eros donec ac odio tempor orci dapibus", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#1eeca0", - "x": 1722, - "y": 1820, - "zoom": 1.8326837750693512, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "3a8ec9378bc", + "id": "f7b961adcf1", "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, ], }, @@ -781,25 +770,25 @@ exports[`patches rich text image nodes > otherRepository > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium.", - "type": "preformatted", + "text": "Eget magna fermentum iaculis eu non diam phasellus vestibulum lorem. Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium. Neque aliquam vestibulum morbi blandit cursus risus at ultrices mi tempus imperdiet nulla malesuada. Fermentum posuere urna nec tincidunt praesent semper feugiat nibh. Eleifend donec pretium vulputate sapien.", + "type": "paragraph", }, { - "alt": "Aliquet lectus proin nibh nisl condimentum id venenatis a", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#87853a", - "x": -1429, - "y": -2019, - "zoom": 1.75840565859303, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "3a8ec9378bc", + "id": "f7b961adcf1", "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, ], "group": [ @@ -807,68 +796,68 @@ exports[`patches rich text image nodes > otherRepository > shared slice 1`] = ` "field": [ { "spans": [], - "text": "Nunc Non Blandit Massa Enim", - "type": "heading5", + "text": "Quis Enim Lobortis", + "type": "heading2", }, { - "alt": "Id faucibus nisl tincidunt eget nullam non nisi est sit amet", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#252b35", - "x": 855, - "y": 1518, - "zoom": 1.5250952426635416, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "3a8ec9378bc", + "id": "f7b961adcf1", "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, ], }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches rich text image nodes > otherRepository > slice 1`] = ` +exports[`patches rich text image nodes > new > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": [ { "spans": [], - "text": "At Ultrices Mi Tempus Imperdiet", - "type": "heading2", + "text": "Ultrices dui sapien eget mi proin sed libero enim sed. Diam ut venenatis tellus in metus vulputate eu scelerisque felis imperdiet. Sed nisi lacus sed viverra tellus in hac habitasse. Eget mi proin sed libero enim sed faucibus turpis. Pellentesque id nibh tortor id aliquet. Aliquam sem et tortor consequat id porta nibh venenatis cras sed felis.", + "type": "paragraph", }, { - "alt": "Sed id semper risus in hendrerit gravida rutrum", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#104dde", - "x": -1621, - "y": -870, - "zoom": 1.7278759511485409, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "2003a644c30", + "id": "54f4a69ff72", "type": "image", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", }, ], }, @@ -877,94 +866,94 @@ exports[`patches rich text image nodes > otherRepository > slice 1`] = ` "field": [ { "spans": [], - "text": "Tincidunt Vitae Semper Quis Lectus Nulla", - "type": "heading4", + "text": "Pharetra et ultrices neque ornare aenean euismod. Mauris sit amet massa vitae tortor condimentum lacinia quis vel eros donec ac.", + "type": "preformatted", }, { - "alt": "Sed nisi lacus sed viverra tellus in hac habitasse", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#63a6c9", - "x": -1609, - "y": -1609, - "zoom": 1.7054690955452316, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "2003a644c30", + "id": "54f4a69ff72", "type": "image", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", }, ], }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches rich text image nodes > otherRepository > static zone 1`] = ` +exports[`patches rich text image nodes > new > static zone 1`] = ` { "field": [ { "spans": [], - "text": "Interdum Velit Euismod", - "type": "heading5", + "text": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis. Tincidunt praesent semper feugiat nibh sed pulvinar proin gravida hendrerit lectus a.", + "type": "paragraph", }, { - "alt": "Tortor consequat id porta nibh", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#c61c37", - "x": 349, - "y": -429, - "zoom": 1.4911347686990943, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "ff1efb2b271", + "id": "ab1d17b04a9", "type": "image", - "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1", + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", }, ], } `; -exports[`patches rich text image nodes > otherRepositoryLinkTo > group 1`] = ` +exports[`patches rich text image nodes > newLinkTo > group 1`] = ` { "group": [ { "field": [ { "spans": [], - "text": "Donec Enim Diam Vulputate Ut Pharetra Sit Amet Aliquam", - "type": "heading4", + "text": "Pulvinar elementum integer enim neque volutpat ac tincidunt vitae semper quis. Gravida hendrerit lectus a molestie lorem ipsum dolor sit amet. Mauris sit amet massa vitae tortor condimentum lacinia. Blandit volutpat maecenas volutpat blandit aliquam. Massa eget egestas purus viverra accumsan in nisl nisi scelerisque. Imperdiet dui accumsan sit amet nulla facilisi morbi tempus iaculis.", + "type": "paragraph", }, { - "alt": "Feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper morbi", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#5c0990", - "x": 2090, - "y": -1492, - "zoom": 1.854310159304717, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "6442e21ad60", + "id": "26fe8d0985c", "linkTo": { - "id": "id-existing", + "id": "other.id-existing", "link_type": "Document", }, "type": "image", - "url": "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, ], }, @@ -972,50 +961,39 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > group 1`] = ` } `; -exports[`patches rich text image nodes > otherRepositoryLinkTo > shared slice 1`] = ` +exports[`patches rich text image nodes > newLinkTo > shared slice 1`] = ` { "slices": [ { - "id": "b9dd0f2c3f8", + "id": "9b9dd0f2c3f", "items": [ { "field": [ { - "oembed": { - "embed_url": "https://twitter.com/prismicio/status/1354835716430319617", - "height": 113, - "html": " - -", - "thumbnail_height": null, - "thumbnail_url": null, - "thumbnail_width": null, - "type": "rich", - "version": "1.0", - "width": 200, - }, - "type": "embed", + "spans": [], + "text": "Diam", + "type": "heading4", }, { - "alt": "Eros donec ac odio tempor orci dapibus", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#1eeca0", - "x": 1722, - "y": 1820, - "zoom": 1.8326837750693512, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "3a8ec9378bc", + "id": "f7b961adcf1", "linkTo": { - "id": "id-existing", + "id": "other.id-existing", "link_type": "Document", }, "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, ], }, @@ -1024,29 +1002,29 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > shared slice 1` "field": [ { "spans": [], - "text": "Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium.", - "type": "preformatted", + "text": "Eget magna fermentum iaculis eu non diam phasellus vestibulum lorem. Egestas maecenas pharetra convallis posuere morbi leo urna molestie at. Cras fermentum odio eu feugiat pretium. Neque aliquam vestibulum morbi blandit cursus risus at ultrices mi tempus imperdiet nulla malesuada. Fermentum posuere urna nec tincidunt praesent semper feugiat nibh. Eleifend donec pretium vulputate sapien.", + "type": "paragraph", }, { - "alt": "Aliquet lectus proin nibh nisl condimentum id venenatis a", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#87853a", - "x": -1429, - "y": -2019, - "zoom": 1.75840565859303, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "3a8ec9378bc", + "id": "f7b961adcf1", "linkTo": { - "id": "id-existing", + "id": "other.id-existing", "link_type": "Document", }, "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, ], "group": [ @@ -1054,76 +1032,76 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > shared slice 1` "field": [ { "spans": [], - "text": "Nunc Non Blandit Massa Enim", - "type": "heading5", + "text": "Quis Enim Lobortis", + "type": "heading2", }, { - "alt": "Id faucibus nisl tincidunt eget nullam non nisi est sit amet", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#252b35", - "x": 855, - "y": 1518, - "zoom": 1.5250952426635416, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "3a8ec9378bc", + "id": "f7b961adcf1", "linkTo": { - "id": "id-existing", + "id": "other.id-existing", "link_type": "Document", }, "type": "image", - "url": "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c", + "url": "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b?w=4240&h=2832&fit=crop", }, ], }, ], }, "slice_label": null, - "slice_type": "dignissim", - "variation": "vitae", - "version": "bfc9053", + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", }, ], } `; -exports[`patches rich text image nodes > otherRepositoryLinkTo > slice 1`] = ` +exports[`patches rich text image nodes > newLinkTo > slice 1`] = ` { "slices": [ { - "id": "306297c5eda", + "id": "5306297c5ed", "items": [ { "field": [ { "spans": [], - "text": "At Ultrices Mi Tempus Imperdiet", - "type": "heading2", + "text": "Ultrices dui sapien eget mi proin sed libero enim sed. Diam ut venenatis tellus in metus vulputate eu scelerisque felis imperdiet. Sed nisi lacus sed viverra tellus in hac habitasse. Eget mi proin sed libero enim sed faucibus turpis. Pellentesque id nibh tortor id aliquet. Aliquam sem et tortor consequat id porta nibh venenatis cras sed felis.", + "type": "paragraph", }, { - "alt": "Sed id semper risus in hendrerit gravida rutrum", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#104dde", - "x": -1621, - "y": -870, - "zoom": 1.7278759511485409, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "2003a644c30", + "id": "54f4a69ff72", "linkTo": { - "id": "id-existing", + "id": "other.id-existing", "link_type": "Document", }, "type": "image", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", }, ], }, @@ -1132,67 +1110,67 @@ exports[`patches rich text image nodes > otherRepositoryLinkTo > slice 1`] = ` "field": [ { "spans": [], - "text": "Tincidunt Vitae Semper Quis Lectus Nulla", - "type": "heading4", + "text": "Pharetra et ultrices neque ornare aenean euismod. Mauris sit amet massa vitae tortor condimentum lacinia quis vel eros donec ac.", + "type": "preformatted", }, { - "alt": "Sed nisi lacus sed viverra tellus in hac habitasse", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#63a6c9", - "x": -1609, - "y": -1609, - "zoom": 1.7054690955452316, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "2003a644c30", + "id": "54f4a69ff72", "linkTo": { - "id": "id-existing", + "id": "other.id-existing", "link_type": "Document", }, "type": "image", - "url": "https://images.unsplash.com/photo-1426604966848-d7adac402bff", + "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?w=2560&h=1440&fit=crop", }, ], }, - "slice_label": "Aliquet", - "slice_type": "vel", + "slice_label": "Vel", + "slice_type": "hac_habitasse", }, ], } `; -exports[`patches rich text image nodes > otherRepositoryLinkTo > static zone 1`] = ` +exports[`patches rich text image nodes > newLinkTo > static zone 1`] = ` { "field": [ { "spans": [], - "text": "Interdum Velit Euismod", - "type": "heading5", + "text": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis. Tincidunt praesent semper feugiat nibh sed pulvinar proin gravida hendrerit lectus a.", + "type": "paragraph", }, { - "alt": "Tortor consequat id porta nibh", + "alt": null, "copyright": null, "dimensions": { "height": 1, "width": 1, }, "edit": { - "background": "#c61c37", - "x": 349, - "y": -429, - "zoom": 1.4911347686990943, + "background": "transparent", + "x": 0, + "y": 0, + "zoom": 1, }, - "id": "ff1efb2b271", + "id": "ab1d17b04a9", "linkTo": { - "id": "id-existing", + "id": "other.id-existing", "link_type": "Document", }, "type": "image", - "url": "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1", + "url": "https://images.unsplash.com/photo-1553531384-397c80973a0b?w=4335&h=6502&fit=crop", }, ], } diff --git a/test/__testutils__/mockPrismicAssetAPI.ts b/test/__testutils__/mockPrismicAssetAPI.ts index ab9ef6b1..8796093d 100644 --- a/test/__testutils__/mockPrismicAssetAPI.ts +++ b/test/__testutils__/mockPrismicAssetAPI.ts @@ -180,6 +180,14 @@ export const mockPrismicAssetAPI = ( : asset.tags, } + // __pdf__ is used as a magic word to transform created assets into + // documents since we can't read FormData when creating assets... + if (response.tags?.some((tag) => tag.name === "__pdf__")) { + response.kind = "document" + response.width = undefined + response.height = undefined + } + // Update asset in DB for (const cursor in assetsDatabase) { for (const asset in assetsDatabase[cursor]) { diff --git a/test/__testutils__/testMigrationFieldPatching.ts b/test/__testutils__/testMigrationFieldPatching.ts index 74a141b0..b74d8caf 100644 --- a/test/__testutils__/testMigrationFieldPatching.ts +++ b/test/__testutils__/testMigrationFieldPatching.ts @@ -22,10 +22,8 @@ type GetDataArgs = { migration: prismic.Migration existingAssets: Asset[] existingDocuments: prismic.PrismicDocument[] - migrationDocuments: { - other: prismic.PrismicMigrationDocument - otherRepository: prismic.PrismicMigrationDocument - } + otherCreateDocument: prismic.PrismicMigrationDocument + otherFromPrismicDocument: prismic.PrismicMigrationDocument mockedDomain: string } @@ -44,43 +42,23 @@ const internalTestMigrationFieldPatching = ( const client = createTestWriteClient({ ctx }) + // Mock Document API const repository = ctx.mock.api.repository() repository.languages[0].id = "en-us" repository.languages[0].is_master = true - const queryResponse = createPagedQueryResponses({ ctx, pages: 1, pageSize: 1, }) - queryResponse[0].results[0].id = "id-existing" - - const { id: _id, ...otherDocument } = { - ...ctx.mock.value.document(), - uid: ctx.mock.value.keyText(), - } - const otherRepositoryDocument = { - ...ctx.mock.value.document(), - uid: ctx.mock.value.keyText(), - } - const { id: originalID, ...newDocument } = ctx.mock.value.document() - - const newID = "id-new" - + queryResponse[0].results[0].id = "other.id-existing" mockPrismicRestAPIV2({ ctx, repositoryResponse: repository, queryResponse }) + + // Mock Asset API const { assetsDatabase } = mockPrismicAssetAPI({ ctx, client, - existingAssets: [[mockAsset(ctx, { id: "id-existing" })]], - }) - const { documentsDatabase } = mockPrismicMigrationAPI({ - ctx, - client, - newDocuments: [ - { id: "id-other" }, - { id: "id-other-repository" }, - { id: newID }, - ], + existingAssets: [[mockAsset(ctx, { id: "asset.id-existing" })]], }) const mockedDomain = `https://${client.repositoryName}.example.com` @@ -90,28 +68,56 @@ const internalTestMigrationFieldPatching = ( ), ) + // Setup migration const migration = prismic.createMigration() + // Create document + const { id: _createOriginalID, ...createDocument } = { + ...ctx.mock.value.document(), + uid: ctx.mock.value.keyText(), + } + const migrationOtherDocument = migration.createDocument( - otherDocument, - "other", + createDocument, + "other.create", ) + // Create document from Prismic + const fromPrismicDocument = { + ...ctx.mock.value.document(), + uid: ctx.mock.value.keyText(), + } + const migrationOtherRepositoryDocument = migration.createDocumentFromPrismic( - otherRepositoryDocument, - "other-repository", + fromPrismicDocument, + "other.fromPrismic", ) + // Create new document + const { id: originalID, ...newDocument } = ctx.mock.value.document() + const newID = + !args.mode || args.mode === "new" ? "id-new" : "id-fromPrismic" + + // Mock Migration API + const { documentsDatabase } = mockPrismicMigrationAPI({ + ctx, + client, + newDocuments: [ + { id: "other.id-create" }, + { id: "other.id-fromPrismic" }, + { id: newID }, + ], + }) + + // Get new document data newDocument.data = args.getData({ ctx, migration, existingAssets: assetsDatabase.flat(), existingDocuments: queryResponse[0].results, - migrationDocuments: { - other: migrationOtherDocument, - otherRepository: migrationOtherRepositoryDocument, - }, + otherCreateDocument: migrationOtherDocument, + otherFromPrismicDocument: migrationOtherRepositoryDocument, mockedDomain, }) diff --git a/test/writeClient-migrate-documents.test.ts b/test/writeClient-migrate-documents.test.ts index af48bfc9..50062671 100644 --- a/test/writeClient-migrate-documents.test.ts +++ b/test/writeClient-migrate-documents.test.ts @@ -293,6 +293,38 @@ it.concurrent( }, ) +it.concurrent( + "creates new non-master locale document with lazy reference (empty)", + async (ctx) => { + const client = createTestWriteClient({ ctx }) + + const { id: documentID, ...document } = ctx.mock.value.document() + const newDocuments = [ + { + id: documentID, + masterLanguageDocumentID: undefined, + }, + ] + + mockPrismicRestAPIV2({ ctx }) + mockPrismicAssetAPI({ ctx, client }) + mockPrismicMigrationAPI({ ctx, client, newDocuments: [...newDocuments] }) + + const migration = prismic.createMigration() + + const doc = migration.createDocument(document, "bar", { + masterLanguageDocument: () => undefined, + }) + + const reporter = vi.fn() + + await client.migrate(migration, { reporter }) + + ctx.expect(doc.document.id).toBe(newDocuments[0].id) + ctx.expect.assertions(1) + }, +) + it.concurrent( "creates new non-master locale document with alternate language", async (ctx) => { diff --git a/test/writeClient-migrate-patch-contentRelationship.test.ts b/test/writeClient-migrate-patch-contentRelationship.test.ts index bc0c2344..3036480c 100644 --- a/test/writeClient-migrate-patch-contentRelationship.test.ts +++ b/test/writeClient-migrate-patch-contentRelationship.test.ts @@ -10,33 +10,43 @@ import { LinkType, RichTextNodeType } from "../src" testMigrationFieldPatching< MigrationContentRelationship | InjectMigrationSpecificTypes ->("patches link fields", { +>("patches content relationship fields", { existing: ({ existingDocuments }) => existingDocuments[0], - migration: ({ migrationDocuments }) => { - delete migrationDocuments.other.document.id - - return migrationDocuments.other + existingLongForm: ({ existingDocuments }) => { + return { + link_type: LinkType.Document, + id: existingDocuments[0], + } + }, + existingLongFormWithText: ({ existingDocuments }) => { + return { + link_type: LinkType.Document, + id: existingDocuments[0], + text: "foo", + } }, + otherCreate: ({ otherCreateDocument }) => otherCreateDocument, lazyExisting: ({ existingDocuments }) => { return () => existingDocuments[0] }, - lazyMigration: ({ migration, migrationDocuments }) => { - delete migrationDocuments.other.document.id - + lazyOtherCreate: ({ migration, otherCreateDocument }) => { return () => migration.getByUID( - migrationDocuments.other.document.type, - migrationDocuments.other.document.uid!, + otherCreateDocument.document.type, + otherCreateDocument.document.uid!, ) }, - migrationNoTags: ({ migration, migrationDocuments }) => { - migrationDocuments.other.document.tags = undefined - - return () => - migration.getByUID( - migrationDocuments.other.document.type, - migrationDocuments.other.document.uid!, + lazyOtherCreateMissingID: ({ migration, otherCreateDocument }) => { + return () => { + const doc = migration.getByUID( + otherCreateDocument.document.type, + otherCreateDocument.document.uid!, ) + + delete doc?.document.id + + return doc + } }, richTextLinkNode: ({ existingDocuments }) => [ { @@ -56,28 +66,42 @@ testMigrationFieldPatching< }) testMigrationFieldPatching( - "patches link fields", + "patches content relationship fields (from Prismic)", { - brokenLink: () => { - return { - link_type: LinkType.Document, - id: "id", - type: "type", - tags: [], - lang: "lang", - isBroken: true, - } + simple: ({ ctx, otherFromPrismicDocument }) => { + const contentRelationship = ctx.mock.value.link({ + type: LinkType.Document, + }) + // `migrationDocuments` contains documents from "another repository" + contentRelationship.id = + otherFromPrismicDocument.originalPrismicDocument!.id + + return contentRelationship }, - otherRepositoryContentRelationship: ({ ctx, migrationDocuments }) => { + withText: ({ ctx, otherFromPrismicDocument }) => { const contentRelationship = ctx.mock.value.link({ type: LinkType.Document, }) // `migrationDocuments` contains documents from "another repository" contentRelationship.id = - migrationDocuments.otherRepository.originalPrismicDocument!.id + otherFromPrismicDocument.originalPrismicDocument!.id + + // TODO: Remove when link text PR is merged + // @ts-expect-error - Future-proofing for link text + contentRelationship.text = "foo" return contentRelationship }, + broken: () => { + return { + link_type: LinkType.Document, + id: "id", + type: "type", + tags: [], + lang: "lang", + isBroken: true, + } + }, }, { mode: "fromPrismic" }, ) diff --git a/test/writeClient-migrate-patch-image.test.ts b/test/writeClient-migrate-patch-image.test.ts index 52c485e8..9f3ce7ab 100644 --- a/test/writeClient-migrate-patch-image.test.ts +++ b/test/writeClient-migrate-patch-image.test.ts @@ -6,6 +6,17 @@ testMigrationFieldPatching( "patches image fields", { new: ({ migration }) => migration.createAsset("foo", "foo.png"), + newLongForm: ({ migration }) => { + return { + id: migration.createAsset("foo", "foo.png"), + } + }, + newThumbnails: ({ migration }) => { + return { + id: migration.createAsset("foo", "foo.png"), + square: migration.createAsset("foo", "foo.png"), + } + }, existing: ({ existingAssets }) => { const asset = existingAssets[0] @@ -22,16 +33,16 @@ testMigrationFieldPatching( ) testMigrationFieldPatching( - "patches image fields", + "patches image fields (from Prismic)", { - otherRepository: ({ ctx, mockedDomain }) => { + simple: ({ ctx, mockedDomain }) => { return { ...ctx.mock.value.image({ state: "filled" }), id: "foo-id", url: `${mockedDomain}/foo.png`, } }, - otherRepositoryWithThumbnails: ({ ctx, mockedDomain }) => { + withThumbnails: ({ ctx, mockedDomain }) => { const image = ctx.mock.value.image({ state: "filled" }) const id = "foo-id" @@ -46,7 +57,7 @@ testMigrationFieldPatching( }, } }, - otherRepositoryWithThumbnailsNoAlt: ({ ctx, mockedDomain }) => { + withThumbnailsNoAlt: ({ ctx, mockedDomain }) => { const image = ctx.mock.value.image({ state: "filled" }) image.alt = null const id = "foo-id" @@ -62,7 +73,7 @@ testMigrationFieldPatching( }, } }, - otherRepositoryWithTypeThumbnail: ({ ctx, mockedDomain }) => { + withSpecialTypeThumbnail: ({ ctx, mockedDomain }) => { const image = ctx.mock.value.image({ state: "filled" }) const id = "foo-id" @@ -77,7 +88,7 @@ testMigrationFieldPatching( }, } }, - otherRepositoryEmpty: ({ ctx }) => ctx.mock.value.image({ state: "empty" }), + empty: ({ ctx }) => ctx.mock.value.image({ state: "empty" }), }, { mode: "fromPrismic" }, ) diff --git a/test/writeClient-migrate-patch-linkToMedia.test.ts b/test/writeClient-migrate-patch-linkToMedia.test.ts index 90ad2b3e..3e394a1e 100644 --- a/test/writeClient-migrate-patch-linkToMedia.test.ts +++ b/test/writeClient-migrate-patch-linkToMedia.test.ts @@ -7,7 +7,6 @@ import type { } from "../src" import { LinkType, RichTextNodeType } from "../src" import type { Asset } from "../src/types/api/asset/asset" -import { AssetType } from "../src/types/api/asset/asset" import type { MigrationLinkToMedia } from "../src/types/migration/Asset" const assetToLinkToMedia = ( @@ -40,16 +39,24 @@ testMigrationFieldPatching< id: migration.createAsset("foo", "foo.png"), } }, - existing: ({ existingAssets }) => assetToLinkToMedia(existingAssets[0]), - existingNonImage: ({ existingAssets }) => { - existingAssets[0].filename = "foo.pdf" - existingAssets[0].extension = "pdf" - existingAssets[0].kind = AssetType.Document - existingAssets[0].width = undefined - existingAssets[0].height = undefined + newWithText: ({ migration }) => { + return { + link_type: LinkType.Media, + id: migration.createAsset("foo", "foo.png"), + text: "foo", + } + }, + newNonImage: ({ migration }) => { + const migrationAsset = migration.createAsset("foo", "foo.pdf", { + tags: ["__pdf__"], + }) - return assetToLinkToMedia(existingAssets[0]) + return { + link_type: LinkType.Media, + id: migrationAsset, + } }, + existing: ({ existingAssets }) => assetToLinkToMedia(existingAssets[0]), richTextNew: ({ migration }) => [ { type: RichTextNodeType.paragraph, @@ -86,16 +93,16 @@ testMigrationFieldPatching< }) testMigrationFieldPatching( - "patches link to media fields", + "patches link to media fields (from Prismic)", { - otherRepository: ({ ctx, mockedDomain }) => { + simple: ({ ctx, mockedDomain }) => { return { ...ctx.mock.value.linkToMedia({ state: "filled" }), id: "foo-id", url: `${mockedDomain}/foo.png`, } }, - richTextOtherRepository: ({ ctx, mockedDomain }) => [ + inRichText: ({ ctx, mockedDomain }) => [ { type: RichTextNodeType.paragraph, text: "lorem", diff --git a/test/writeClient-migrate-patch-rtImageNode.test.ts b/test/writeClient-migrate-patch-rtImageNode.test.ts index d483e056..a7685cc4 100644 --- a/test/writeClient-migrate-patch-rtImageNode.test.ts +++ b/test/writeClient-migrate-patch-rtImageNode.test.ts @@ -40,9 +40,9 @@ testMigrationFieldPatching>( ) testMigrationFieldPatching>( - "patches rich text image nodes", + "patches rich text image nodes (from Prismic)", { - otherRepository: ({ ctx, mockedDomain }) => [ + simple: ({ ctx, mockedDomain }) => [ ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), { type: RichTextNodeType.image, @@ -51,7 +51,7 @@ testMigrationFieldPatching>( url: `${mockedDomain}/foo.png`, }, ], - otherRepositoryLinkTo: ({ ctx, mockedDomain, existingDocuments }) => [ + withLinkTo: ({ ctx, mockedDomain, existingDocuments }) => [ ...ctx.mock.value.richText({ pattern: "short", state: "filled" }), { type: RichTextNodeType.image, diff --git a/test/writeClient-migrate-patch-simpleField.test.ts b/test/writeClient-migrate-patch-simpleField.test.ts index 848fa844..0900323b 100644 --- a/test/writeClient-migrate-patch-simpleField.test.ts +++ b/test/writeClient-migrate-patch-simpleField.test.ts @@ -29,6 +29,12 @@ testMigrationFieldPatching( linkToWeb: ({ ctx }) => ctx.mock.value.link({ type: "Web", withTargetBlank: true }), richTextMisleadingGroup: () => [{ type: "paragraph" }], + documentMisleadingObject: () => { + return { + id: "foo", + href: "bar", + } + }, }, { expectStrictEqual: true }, )