@prismicio/client 7.9.0 → 7.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/BaseClient.cjs +108 -0
  2. package/dist/BaseClient.cjs.map +1 -0
  3. package/dist/BaseClient.d.ts +152 -0
  4. package/dist/BaseClient.js +108 -0
  5. package/dist/BaseClient.js.map +1 -0
  6. package/dist/Client.cjs +1217 -0
  7. package/dist/Client.cjs.map +1 -0
  8. package/dist/Client.d.ts +924 -0
  9. package/dist/Client.js +1217 -0
  10. package/dist/Client.js.map +1 -0
  11. package/dist/Migration.cjs +318 -0
  12. package/dist/Migration.cjs.map +1 -0
  13. package/dist/Migration.d.ts +213 -0
  14. package/dist/Migration.js +318 -0
  15. package/dist/Migration.js.map +1 -0
  16. package/dist/WriteClient.cjs +512 -0
  17. package/dist/WriteClient.cjs.map +1 -0
  18. package/dist/WriteClient.d.ts +314 -0
  19. package/dist/WriteClient.js +512 -0
  20. package/dist/WriteClient.js.map +1 -0
  21. package/dist/createClient.cjs +2 -1215
  22. package/dist/createClient.cjs.map +1 -1
  23. package/dist/createClient.d.ts +2 -1003
  24. package/dist/createClient.js +1 -1214
  25. package/dist/createClient.js.map +1 -1
  26. package/dist/createMigration.cjs +6 -0
  27. package/dist/createMigration.cjs.map +1 -0
  28. package/dist/createMigration.d.ts +24 -0
  29. package/dist/createMigration.js +6 -0
  30. package/dist/createMigration.js.map +1 -0
  31. package/dist/createWriteClient.cjs +6 -0
  32. package/dist/createWriteClient.cjs.map +1 -0
  33. package/dist/createWriteClient.d.ts +32 -0
  34. package/dist/createWriteClient.js +6 -0
  35. package/dist/createWriteClient.js.map +1 -0
  36. package/dist/getRepositoryName.cjs +7 -2
  37. package/dist/getRepositoryName.cjs.map +1 -1
  38. package/dist/getRepositoryName.d.ts +3 -6
  39. package/dist/getRepositoryName.js +7 -2
  40. package/dist/getRepositoryName.js.map +1 -1
  41. package/dist/index.cjs +14 -1
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.d.ts +17 -2
  44. package/dist/index.js +14 -1
  45. package/dist/index.js.map +1 -1
  46. package/dist/lib/isMigrationValue.cjs +24 -0
  47. package/dist/lib/isMigrationValue.cjs.map +1 -0
  48. package/dist/lib/isMigrationValue.d.ts +62 -0
  49. package/dist/lib/isMigrationValue.js +24 -0
  50. package/dist/lib/isMigrationValue.js.map +1 -0
  51. package/dist/lib/isValue.cjs +53 -0
  52. package/dist/lib/isValue.cjs.map +1 -0
  53. package/dist/lib/isValue.d.ts +72 -0
  54. package/dist/lib/isValue.js +53 -0
  55. package/dist/lib/isValue.js.map +1 -0
  56. package/dist/lib/pLimit.cjs +49 -0
  57. package/dist/lib/pLimit.cjs.map +1 -0
  58. package/dist/lib/pLimit.d.ts +22 -0
  59. package/dist/lib/pLimit.js +49 -0
  60. package/dist/lib/pLimit.js.map +1 -0
  61. package/dist/lib/resolveMigrationDocumentData.cjs +123 -0
  62. package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -0
  63. package/dist/lib/resolveMigrationDocumentData.d.ts +52 -0
  64. package/dist/lib/resolveMigrationDocumentData.js +123 -0
  65. package/dist/lib/resolveMigrationDocumentData.js.map +1 -0
  66. package/dist/lib/validateAssetMetadata.cjs +28 -0
  67. package/dist/lib/validateAssetMetadata.cjs.map +1 -0
  68. package/dist/lib/validateAssetMetadata.d.ts +10 -0
  69. package/dist/lib/validateAssetMetadata.js +28 -0
  70. package/dist/lib/validateAssetMetadata.js.map +1 -0
  71. package/dist/package.json.cjs +1 -1
  72. package/dist/package.json.js +1 -1
  73. package/dist/types/api/asset/asset.d.ts +177 -0
  74. package/dist/types/api/asset/tag.d.ts +53 -0
  75. package/dist/types/api/migration/document.d.ts +60 -0
  76. package/dist/types/migration/Asset.cjs +33 -0
  77. package/dist/types/migration/Asset.cjs.map +1 -0
  78. package/dist/types/migration/Asset.d.ts +109 -0
  79. package/dist/types/migration/Asset.js +33 -0
  80. package/dist/types/migration/Asset.js.map +1 -0
  81. package/dist/types/migration/ContentRelationship.d.ts +17 -0
  82. package/dist/types/migration/Document.cjs +47 -0
  83. package/dist/types/migration/Document.cjs.map +1 -0
  84. package/dist/types/migration/Document.d.ts +94 -0
  85. package/dist/types/migration/Document.js +47 -0
  86. package/dist/types/migration/Document.js.map +1 -0
  87. package/package.json +2 -2
  88. package/src/BaseClient.ts +330 -0
  89. package/src/Client.ts +1787 -0
  90. package/src/Migration.ts +531 -0
  91. package/src/WriteClient.ts +911 -0
  92. package/src/createClient.ts +3 -1931
  93. package/src/createMigration.ts +31 -0
  94. package/src/createWriteClient.ts +43 -0
  95. package/src/getRepositoryName.ts +19 -14
  96. package/src/index.ts +32 -4
  97. package/src/lib/isMigrationValue.ts +126 -0
  98. package/src/lib/isValue.ts +196 -0
  99. package/src/lib/pLimit.ts +106 -0
  100. package/src/lib/resolveMigrationDocumentData.ts +233 -0
  101. package/src/lib/validateAssetMetadata.ts +82 -0
  102. package/src/types/api/asset/asset.ts +211 -0
  103. package/src/types/api/asset/tag.ts +59 -0
  104. package/src/types/api/migration/document.ts +84 -0
  105. package/src/types/migration/Asset.ts +156 -0
  106. package/src/types/migration/ContentRelationship.ts +36 -0
  107. package/src/types/migration/Document.ts +157 -0
@@ -0,0 +1,531 @@
1
+ import * as is from "./lib/isValue"
2
+ import { validateAssetMetadata } from "./lib/validateAssetMetadata"
3
+
4
+ import type { Asset } from "./types/api/asset/asset"
5
+ import type {
6
+ MigrationAssetConfig,
7
+ MigrationImage,
8
+ MigrationLinkToMedia,
9
+ MigrationRTImageNode,
10
+ } from "./types/migration/Asset"
11
+ import { PrismicMigrationAsset } from "./types/migration/Asset"
12
+ import type { MigrationContentRelationship } from "./types/migration/ContentRelationship"
13
+ import { PrismicMigrationDocument } from "./types/migration/Document"
14
+ import type {
15
+ ExistingPrismicDocument,
16
+ PendingPrismicDocument,
17
+ } from "./types/migration/Document"
18
+ import type { PrismicDocument } from "./types/value/document"
19
+ import type { FilledImageFieldImage } from "./types/value/image"
20
+ import { type FilledLinkToWebField, LinkType } from "./types/value/link"
21
+ import type { FilledLinkToMediaField } from "./types/value/linkToMedia"
22
+ import { RichTextNodeType } from "./types/value/richText"
23
+
24
+ /**
25
+ * Extracts one or more Prismic document types that match a given Prismic
26
+ * document type. If no matches are found, no extraction is performed and the
27
+ * union of all provided Prismic document types are returned.
28
+ *
29
+ * @typeParam TDocuments - Prismic document types from which to extract.
30
+ * @typeParam TDocumentType - Type(s) to match `TDocuments` against.
31
+ */
32
+ type ExtractDocumentType<
33
+ TDocuments extends { type: string },
34
+ TDocumentType extends TDocuments["type"],
35
+ > =
36
+ Extract<TDocuments, { type: TDocumentType }> extends never
37
+ ? TDocuments
38
+ : Extract<TDocuments, { type: TDocumentType }>
39
+
40
+ /**
41
+ * A helper that allows preparing your migration to Prismic.
42
+ *
43
+ * @typeParam TDocuments - Document types that are registered for the Prismic
44
+ * repository. Query methods will automatically be typed based on this type.
45
+ */
46
+ export class Migration<TDocuments extends PrismicDocument = PrismicDocument> {
47
+ /**
48
+ * Assets registered in the migration.
49
+ *
50
+ * @internal
51
+ */
52
+ _assets: Map<MigrationAssetConfig["file"], PrismicMigrationAsset> = new Map()
53
+
54
+ /**
55
+ * Documents registered in the migration.
56
+ *
57
+ * @internal
58
+ */
59
+ _documents: PrismicMigrationDocument<TDocuments>[] = []
60
+
61
+ /**
62
+ * Registers an asset to be created in the migration from an asset object.
63
+ *
64
+ * @remarks
65
+ * This method does not create the asset in Prismic media library right away.
66
+ * Instead, it registers it in your migration. The asset will be created when
67
+ * the migration is executed through the `writeClient.migrate()` method.
68
+ *
69
+ * @param asset - An asset object from Prismic Asset API.
70
+ *
71
+ * @returns A migration asset field instance.
72
+ *
73
+ * @internal
74
+ */
75
+ createAsset(asset: Asset): PrismicMigrationAsset
76
+
77
+ /**
78
+ * Registers an asset to be created in the migration from an image or link to
79
+ * media field.
80
+ *
81
+ * @remarks
82
+ * This method does not create the asset in Prismic media library right away.
83
+ * Instead, it registers it in your migration. The asset will be created when
84
+ * the migration is executed through the `writeClient.migrate()` method.
85
+ *
86
+ * @param imageOrLinkToMediaField - An image or link to media field from
87
+ * Prismic Document API.
88
+ *
89
+ * @returns A migration asset field instance.
90
+ *
91
+ * @internal
92
+ */
93
+ createAsset(
94
+ imageOrLinkToMediaField: FilledImageFieldImage | FilledLinkToMediaField,
95
+ ): PrismicMigrationAsset
96
+
97
+ /**
98
+ * Registers an asset to be created in the migration from a file.
99
+ *
100
+ * @remarks
101
+ * This method does not create the asset in Prismic media library right away.
102
+ * Instead, it registers it in your migration. The asset will be created when
103
+ * the migration is executed through the `writeClient.migrate()` method.
104
+ *
105
+ * @param file - The URL or content of the file to be created.
106
+ * @param filename - The filename of the asset.
107
+ * @param params - Additional asset data.
108
+ *
109
+ * @returns A migration asset field instance.
110
+ */
111
+ createAsset(
112
+ file: MigrationAssetConfig["file"],
113
+ filename: MigrationAssetConfig["filename"],
114
+ params?: {
115
+ notes?: string
116
+ credits?: string
117
+ alt?: string
118
+ tags?: string[]
119
+ },
120
+ ): PrismicMigrationAsset
121
+
122
+ /**
123
+ * Registers an asset to be created in the migration from a file, an asset
124
+ * object, or an image or link to media field.
125
+ *
126
+ * @remarks
127
+ * This method does not create the asset in Prismic media library right away.
128
+ * Instead, it registers it in your migration. The asset will be created when
129
+ * the migration is executed through the `writeClient.migrate()` method.
130
+ *
131
+ * @returns A migration asset field instance.
132
+ */
133
+ createAsset(
134
+ fileOrAssetOrField:
135
+ | MigrationAssetConfig["file"]
136
+ | Asset
137
+ | FilledImageFieldImage
138
+ | FilledLinkToMediaField,
139
+ filename?: MigrationAssetConfig["filename"],
140
+ {
141
+ notes,
142
+ credits,
143
+ alt,
144
+ tags,
145
+ }: {
146
+ notes?: string
147
+ credits?: string
148
+ alt?: string
149
+ tags?: string[]
150
+ } = {},
151
+ ): PrismicMigrationAsset {
152
+ let config: MigrationAssetConfig
153
+ let maybeInitialField: FilledImageFieldImage | undefined
154
+ if (typeof fileOrAssetOrField === "object" && "url" in fileOrAssetOrField) {
155
+ if (
156
+ "dimensions" in fileOrAssetOrField ||
157
+ "link_type" in fileOrAssetOrField
158
+ ) {
159
+ const url = fileOrAssetOrField.url.split("?")[0]
160
+ const filename =
161
+ "name" in fileOrAssetOrField
162
+ ? fileOrAssetOrField.name
163
+ : url.split("/").pop()!.split("_").pop()!
164
+ const credits =
165
+ "copyright" in fileOrAssetOrField && fileOrAssetOrField.copyright
166
+ ? fileOrAssetOrField.copyright
167
+ : undefined
168
+ const alt =
169
+ "alt" in fileOrAssetOrField && fileOrAssetOrField.alt
170
+ ? fileOrAssetOrField.alt
171
+ : undefined
172
+
173
+ if ("dimensions" in fileOrAssetOrField) {
174
+ maybeInitialField = fileOrAssetOrField
175
+ }
176
+
177
+ config = {
178
+ id: fileOrAssetOrField.id,
179
+ file: url,
180
+ filename,
181
+ notes: undefined,
182
+ credits,
183
+ alt,
184
+ tags: undefined,
185
+ }
186
+ } else {
187
+ config = {
188
+ id: fileOrAssetOrField.id,
189
+ file: fileOrAssetOrField.url,
190
+ filename: fileOrAssetOrField.filename,
191
+ notes: fileOrAssetOrField.notes,
192
+ credits: fileOrAssetOrField.credits,
193
+ alt: fileOrAssetOrField.alt,
194
+ tags: fileOrAssetOrField.tags?.map(({ name }) => name),
195
+ }
196
+ }
197
+ } else {
198
+ config = {
199
+ id: fileOrAssetOrField,
200
+ file: fileOrAssetOrField,
201
+ filename: filename!,
202
+ notes,
203
+ credits,
204
+ alt,
205
+ tags,
206
+ }
207
+ }
208
+
209
+ validateAssetMetadata(config)
210
+
211
+ // We create a detached instance of the asset each time to serialize it properly
212
+ const migrationAsset = new PrismicMigrationAsset(config, maybeInitialField)
213
+
214
+ const maybeAsset = this._assets.get(config.id)
215
+ if (maybeAsset) {
216
+ // Consolidate existing asset with new asset value if possible
217
+ maybeAsset.config.notes = maybeAsset.config.notes || config.notes
218
+ maybeAsset.config.credits = maybeAsset.config.credits || config.credits
219
+ maybeAsset.config.alt = maybeAsset.config.alt || config.alt
220
+ maybeAsset.config.tags = Array.from(
221
+ new Set([...(maybeAsset.config.tags || []), ...(config.tags || [])]),
222
+ )
223
+ } else {
224
+ this._assets.set(config.id, migrationAsset)
225
+ }
226
+
227
+ return migrationAsset
228
+ }
229
+
230
+ /**
231
+ * Registers a document to be created in the migration.
232
+ *
233
+ * @remarks
234
+ * This method does not create the document in Prismic right away. Instead, it
235
+ * registers it in your migration. The document will be created when the
236
+ * migration is executed through the `writeClient.migrate()` method.
237
+ *
238
+ * @typeParam TType - Type of the Prismic document to create.
239
+ *
240
+ * @param document - The document to create.
241
+ * @param title - The title of the document to create which will be displayed
242
+ * in the editor.
243
+ * @param params - Document master language document ID.
244
+ *
245
+ * @returns A migration document instance.
246
+ */
247
+ createDocument<TType extends TDocuments["type"]>(
248
+ document: ExtractDocumentType<PendingPrismicDocument<TDocuments>, TType>,
249
+ title: string,
250
+ params?: {
251
+ masterLanguageDocument?: MigrationContentRelationship
252
+ },
253
+ ): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> {
254
+ const doc = new PrismicMigrationDocument<
255
+ ExtractDocumentType<TDocuments, TType>
256
+ >(document, title, params)
257
+
258
+ this._documents.push(doc)
259
+
260
+ return doc
261
+ }
262
+
263
+ /**
264
+ * Registers an existing document to be updated in the migration.
265
+ *
266
+ * @remarks
267
+ * This method does not update the document in Prismic right away. Instead, it
268
+ * registers it in your migration. The document will be updated when the
269
+ * migration is executed through the `writeClient.migrate()` method.
270
+ *
271
+ * @typeParam TType - Type of Prismic documents to update.
272
+ *
273
+ * @param document - The document to update.
274
+ * @param title - The title of the document to update which will be displayed
275
+ * in the editor.
276
+ *
277
+ * @returns A migration document instance.
278
+ */
279
+ updateDocument<TType extends TDocuments["type"]>(
280
+ document: ExtractDocumentType<ExistingPrismicDocument<TDocuments>, TType>,
281
+ // Title is optional for existing documents as we might not want to update it.
282
+ title?: string,
283
+ ): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> {
284
+ const doc = new PrismicMigrationDocument<
285
+ ExtractDocumentType<TDocuments, TType>
286
+ >(document, title)
287
+
288
+ this._documents.push(doc)
289
+
290
+ return doc
291
+ }
292
+
293
+ /**
294
+ * Registers a document from another Prismic repository to be created in the
295
+ * migration.
296
+ *
297
+ * @remarks
298
+ * This method does not create the document in Prismic right away. Instead, it
299
+ * registers it in your migration. The document will be created when the
300
+ * migration is executed through the `writeClient.migrate()` method.
301
+ *
302
+ * @param document - The document from Prismic to create.
303
+ * @param title - The title of the document to create which will be displayed
304
+ * in the editor.
305
+ *
306
+ * @returns A migration document instance.
307
+ */
308
+ createDocumentFromPrismic<TType extends TDocuments["type"]>(
309
+ document: ExtractDocumentType<ExistingPrismicDocument<TDocuments>, TType>,
310
+ title: string,
311
+ ): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> {
312
+ const doc = new PrismicMigrationDocument(
313
+ this.#migratePrismicDocumentData({
314
+ type: document.type,
315
+ lang: document.lang,
316
+ uid: document.uid,
317
+ tags: document.tags,
318
+ data: document.data,
319
+ }) as PendingPrismicDocument<ExtractDocumentType<TDocuments, TType>>,
320
+ title,
321
+ { originalPrismicDocument: document },
322
+ )
323
+
324
+ this._documents.push(doc)
325
+
326
+ return doc
327
+ }
328
+
329
+ /**
330
+ * Queries a document from the migration instance with a specific UID and
331
+ * custom type.
332
+ *
333
+ * @example
334
+ *
335
+ * ```ts
336
+ * const contentRelationship = migration.createContentRelationship(() =>
337
+ * migration.getByUID("blog_post", "my-first-post"),
338
+ * )
339
+ * ```
340
+ *
341
+ * @typeParam TType - Type of the Prismic document returned.
342
+ *
343
+ * @param type - The API ID of the document's custom type.
344
+ * @param uid - The UID of the document.
345
+ *
346
+ * @returns The migration document instance with a UID matching the `uid`
347
+ * parameter, if a matching document is found.
348
+ */
349
+ getByUID<TType extends TDocuments["type"]>(
350
+ type: TType,
351
+ uid: string,
352
+ ):
353
+ | PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>>
354
+ | undefined {
355
+ return this._documents.find(
356
+ (
357
+ doc,
358
+ ): doc is PrismicMigrationDocument<
359
+ ExtractDocumentType<TDocuments, TType>
360
+ > => doc.document.type === type && doc.document.uid === uid,
361
+ )
362
+ }
363
+
364
+ /**
365
+ * Queries a singleton document from the migration instance for a specific
366
+ * custom type.
367
+ *
368
+ * @example
369
+ *
370
+ * ```ts
371
+ * const contentRelationship = migration.createContentRelationship(() =>
372
+ * migration.getSingle("settings"),
373
+ * )
374
+ * ```
375
+ *
376
+ * @typeParam TType - Type of the Prismic document returned.
377
+ *
378
+ * @param type - The API ID of the singleton custom type.
379
+ *
380
+ * @returns The migration document instance for the custom type, if a matching
381
+ * document is found.
382
+ */
383
+ getSingle<TType extends TDocuments["type"]>(
384
+ type: TType,
385
+ ):
386
+ | PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>>
387
+ | undefined {
388
+ return this._documents.find(
389
+ (
390
+ doc,
391
+ ): doc is PrismicMigrationDocument<
392
+ ExtractDocumentType<TDocuments, TType>
393
+ > => doc.document.type === type,
394
+ )
395
+ }
396
+
397
+ /**
398
+ * Migrates a Prismic document data from another repository so that it can be
399
+ * created through the current repository's Migration API.
400
+ *
401
+ * @param input - The Prismic document data to migrate.
402
+ *
403
+ * @returns The migrated Prismic document data.
404
+ */
405
+ #migratePrismicDocumentData(input: unknown): unknown {
406
+ if (is.filledContentRelationship(input)) {
407
+ if (input.isBroken) {
408
+ return {
409
+ link_type: LinkType.Document,
410
+ // ID needs to be 16 characters long to be considered valid by the API
411
+ id: "_____broken_____",
412
+ isBroken: true,
413
+ // TODO: Remove when link text PR is merged
414
+ // @ts-expect-error - Future-proofing for link text
415
+ text: input.text,
416
+ }
417
+ }
418
+
419
+ return {
420
+ link_type: LinkType.Document,
421
+ id: () => this._getByOriginalID(input.id),
422
+ // TODO: Remove when link text PR is merged
423
+ // @ts-expect-error - Future-proofing for link text
424
+ text: input.text,
425
+ }
426
+ }
427
+
428
+ if (is.filledLinkToMedia(input)) {
429
+ return {
430
+ link_type: LinkType.Media,
431
+ id: this.createAsset(input),
432
+ // TODO: Remove when link text PR is merged
433
+ // @ts-expect-error - Future-proofing for link text
434
+ text: input.text,
435
+ }
436
+ }
437
+
438
+ if (is.rtImageNode(input)) {
439
+ // Rich text image nodes
440
+ const rtImageNode: MigrationRTImageNode = {
441
+ type: RichTextNodeType.image,
442
+ id: this.createAsset(input),
443
+ }
444
+
445
+ if (input.linkTo) {
446
+ rtImageNode.linkTo = this.#migratePrismicDocumentData(input.linkTo) as
447
+ | MigrationContentRelationship
448
+ | MigrationLinkToMedia
449
+ | FilledLinkToWebField
450
+ }
451
+
452
+ return rtImageNode
453
+ }
454
+
455
+ if (is.filledImage(input)) {
456
+ const image: MigrationImage = {
457
+ id: this.createAsset(input),
458
+ }
459
+
460
+ const {
461
+ id: _id,
462
+ url: _url,
463
+ dimensions: _dimensions,
464
+ edit: _edit,
465
+ alt: _alt,
466
+ copyright: _copyright,
467
+ ...thumbnails
468
+ } = input
469
+
470
+ for (const name in thumbnails) {
471
+ if (is.filledImage(thumbnails[name])) {
472
+ image[name] = this.createAsset(thumbnails[name])
473
+ }
474
+ }
475
+
476
+ return image
477
+ }
478
+
479
+ if (Array.isArray(input)) {
480
+ return input.map((element) => this.#migratePrismicDocumentData(element))
481
+ }
482
+
483
+ if (input && typeof input === "object") {
484
+ const res: Record<PropertyKey, unknown> = {}
485
+
486
+ for (const key in input) {
487
+ res[key] = this.#migratePrismicDocumentData(
488
+ input[key as keyof typeof input],
489
+ )
490
+ }
491
+
492
+ return res
493
+ }
494
+
495
+ return input
496
+ }
497
+
498
+ /**
499
+ * Queries a document from the migration instance for a specific original ID.
500
+ *
501
+ * @example
502
+ *
503
+ * ```ts
504
+ * const contentRelationship = migration.createContentRelationship(() =>
505
+ * migration._getByOriginalID("YhdrDxIAACgAcp_b"),
506
+ * )
507
+ * ```
508
+ *
509
+ * @typeParam TType - Type of the Prismic document returned.
510
+ *
511
+ * @param id - The original ID of the Prismic document.
512
+ *
513
+ * @returns The migration document instance for the original ID, if a matching
514
+ * document is found.
515
+ *
516
+ * @internal
517
+ */
518
+ _getByOriginalID<TType extends TDocuments["type"]>(
519
+ id: string,
520
+ ):
521
+ | PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>>
522
+ | undefined {
523
+ return this._documents.find(
524
+ (
525
+ doc,
526
+ ): doc is PrismicMigrationDocument<
527
+ ExtractDocumentType<TDocuments, TType>
528
+ > => doc.originalPrismicDocument?.id === id,
529
+ )
530
+ }
531
+ }