@kontent-ai/migration-toolkit 2.9.1 → 3.0.0-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 (235) hide show
  1. package/README.md +19 -17
  2. package/dist/core/config.js +3 -3
  3. package/dist/core/config.js.map +1 -1
  4. package/dist/core/helpers/workflow-helper.d.ts +1 -1
  5. package/dist/core/helpers/workflow-helper.js +28 -26
  6. package/dist/core/helpers/workflow-helper.js.map +1 -1
  7. package/dist/core/logs/loggers.d.ts +1 -1
  8. package/dist/core/logs/loggers.js +15 -15
  9. package/dist/core/logs/loggers.js.map +1 -1
  10. package/dist/core/models/core.models.d.ts +27 -22
  11. package/dist/core/models/error.models.d.ts +14 -0
  12. package/dist/core/models/error.models.js +25 -0
  13. package/dist/core/models/error.models.js.map +1 -0
  14. package/dist/core/models/log.models.d.ts +2 -2
  15. package/dist/core/models/migration.models.d.ts +14 -14
  16. package/dist/core/models/migration.schema.d.ts +9 -9
  17. package/dist/core/models/migration.schema.js +28 -28
  18. package/dist/core/models/migration.schema.js.map +1 -1
  19. package/dist/core/utils/array.utils.d.ts +1 -1
  20. package/dist/core/utils/array.utils.js +4 -3
  21. package/dist/core/utils/array.utils.js.map +1 -1
  22. package/dist/core/utils/binary-data.utils.d.ts +1 -1
  23. package/dist/core/utils/binary-data.utils.js +6 -6
  24. package/dist/core/utils/binary-data.utils.js.map +1 -1
  25. package/dist/core/utils/confirm.utils.d.ts +1 -1
  26. package/dist/core/utils/confirm.utils.js +21 -20
  27. package/dist/core/utils/confirm.utils.js.map +1 -1
  28. package/dist/core/utils/error.utils.d.ts +1 -1
  29. package/dist/core/utils/error.utils.js +16 -14
  30. package/dist/core/utils/error.utils.js.map +1 -1
  31. package/dist/core/utils/external-id.utils.js +1 -1
  32. package/dist/core/utils/external-id.utils.js.map +1 -1
  33. package/dist/core/utils/global.utils.d.ts +3 -3
  34. package/dist/core/utils/global.utils.js +20 -18
  35. package/dist/core/utils/global.utils.js.map +1 -1
  36. package/dist/core/utils/http.utils.d.ts +2 -2
  37. package/dist/core/utils/http.utils.js +4 -4
  38. package/dist/core/utils/http.utils.js.map +1 -1
  39. package/dist/core/utils/management-client-utils.d.ts +4 -4
  40. package/dist/core/utils/management-client-utils.js +34 -34
  41. package/dist/core/utils/management-client-utils.js.map +1 -1
  42. package/dist/core/utils/processing-utils.d.ts +4 -4
  43. package/dist/core/utils/processing-utils.js +13 -13
  44. package/dist/core/utils/processing-utils.js.map +1 -1
  45. package/dist/core/utils/run.utils.d.ts +2 -2
  46. package/dist/core/utils/run.utils.js +7 -7
  47. package/dist/core/utils/run.utils.js.map +1 -1
  48. package/dist/export/context/export-context-fetcher.d.ts +1 -1
  49. package/dist/export/context/export-context-fetcher.js +92 -62
  50. package/dist/export/context/export-context-fetcher.js.map +1 -1
  51. package/dist/export/export-manager.d.ts +2 -2
  52. package/dist/export/export-manager.js +46 -37
  53. package/dist/export/export-manager.js.map +1 -1
  54. package/dist/export/export.models.d.ts +21 -2
  55. package/dist/export/utils/export.utils.d.ts +1 -1
  56. package/dist/export/utils/export.utils.js +3 -2
  57. package/dist/export/utils/export.utils.js.map +1 -1
  58. package/dist/file/file-manager.d.ts +2 -2
  59. package/dist/file/file-manager.js +7 -7
  60. package/dist/file/file-manager.js.map +1 -1
  61. package/dist/import/comparers/asset-comparer.d.ts +2 -2
  62. package/dist/import/comparers/asset-comparer.js +12 -11
  63. package/dist/import/comparers/asset-comparer.js.map +1 -1
  64. package/dist/import/context/import-context-fetcher.d.ts +1 -1
  65. package/dist/import/context/import-context-fetcher.js +77 -73
  66. package/dist/import/context/import-context-fetcher.js.map +1 -1
  67. package/dist/import/import-manager.d.ts +1 -1
  68. package/dist/import/import-manager.js +59 -56
  69. package/dist/import/import-manager.js.map +1 -1
  70. package/dist/import/import.models.d.ts +6 -2
  71. package/dist/import/importers/assets-importer.d.ts +3 -3
  72. package/dist/import/importers/assets-importer.js +46 -43
  73. package/dist/import/importers/assets-importer.js.map +1 -1
  74. package/dist/import/importers/content-items-importer.d.ts +3 -3
  75. package/dist/import/importers/content-items-importer.js +28 -25
  76. package/dist/import/importers/content-items-importer.js.map +1 -1
  77. package/dist/import/importers/language-variant-importer.d.ts +3 -3
  78. package/dist/import/importers/language-variant-importer.js +45 -45
  79. package/dist/import/importers/language-variant-importer.js.map +1 -1
  80. package/dist/import/importers/workflow-importer.d.ts +3 -2
  81. package/dist/import/importers/workflow-importer.js +58 -54
  82. package/dist/import/importers/workflow-importer.js.map +1 -1
  83. package/dist/import/utils/import.utils.d.ts +1 -1
  84. package/dist/import/utils/import.utils.js +3 -2
  85. package/dist/import/utils/import.utils.js.map +1 -1
  86. package/dist/index.d.ts +11 -7
  87. package/dist/index.js +10 -8
  88. package/dist/index.js.map +1 -1
  89. package/dist/metadata.js +3 -3
  90. package/dist/metadata.js.map +1 -1
  91. package/dist/node/cli/actions/export-action.d.ts +1 -1
  92. package/dist/node/cli/actions/export-action.js +28 -23
  93. package/dist/node/cli/actions/export-action.js.map +1 -1
  94. package/dist/node/cli/actions/import-action.d.ts +1 -1
  95. package/dist/node/cli/actions/import-action.js +15 -12
  96. package/dist/node/cli/actions/import-action.js.map +1 -1
  97. package/dist/node/cli/actions/migrate-action.d.ts +1 -1
  98. package/dist/node/cli/actions/migrate-action.js +25 -22
  99. package/dist/node/cli/actions/migrate-action.js.map +1 -1
  100. package/dist/node/cli/app.js +13 -12
  101. package/dist/node/cli/app.js.map +1 -1
  102. package/dist/node/cli/args/args-fetcher.d.ts +1 -1
  103. package/dist/node/cli/args/args-fetcher.js +14 -13
  104. package/dist/node/cli/args/args-fetcher.js.map +1 -1
  105. package/dist/node/cli/args/args-setter.d.ts +1 -1
  106. package/dist/node/cli/args/args-setter.js +8 -6
  107. package/dist/node/cli/args/args-setter.js.map +1 -1
  108. package/dist/node/cli/cli.models.d.ts +2 -2
  109. package/dist/node/cli/commands.js +68 -56
  110. package/dist/node/cli/commands.js.map +1 -1
  111. package/dist/toolkit/elements-builder.d.ts +1 -1
  112. package/dist/toolkit/elements-builder.js +12 -12
  113. package/dist/toolkit/elements-builder.js.map +1 -1
  114. package/dist/toolkit/export.d.ts +2 -2
  115. package/dist/toolkit/export.js +8 -8
  116. package/dist/toolkit/export.js.map +1 -1
  117. package/dist/toolkit/file.d.ts +2 -1
  118. package/dist/toolkit/file.js +18 -16
  119. package/dist/toolkit/file.js.map +1 -1
  120. package/dist/toolkit/import.d.ts +1 -1
  121. package/dist/toolkit/import.js +12 -12
  122. package/dist/toolkit/import.js.map +1 -1
  123. package/dist/toolkit/migrate.d.ts +13 -4
  124. package/dist/toolkit/migrate.js +15 -13
  125. package/dist/toolkit/migrate.js.map +1 -1
  126. package/dist/translation/extraction/items-extraction.processor.d.ts +5 -4
  127. package/dist/translation/extraction/items-extraction.processor.js +73 -35
  128. package/dist/translation/extraction/items-extraction.processor.js.map +1 -1
  129. package/dist/translation/helpers/export-placeholder.utils.d.ts +11 -0
  130. package/dist/translation/helpers/export-placeholder.utils.js +11 -0
  131. package/dist/translation/helpers/export-placeholder.utils.js.map +1 -0
  132. package/dist/translation/helpers/rich-text.processor.d.ts +6 -6
  133. package/dist/translation/helpers/rich-text.processor.js +38 -38
  134. package/dist/translation/helpers/rich-text.processor.js.map +1 -1
  135. package/dist/translation/transforms/export-transforms.d.ts +2 -2
  136. package/dist/translation/transforms/export-transforms.js +93 -67
  137. package/dist/translation/transforms/export-transforms.js.map +1 -1
  138. package/dist/translation/transforms/import-transforms.d.ts +2 -2
  139. package/dist/translation/transforms/import-transforms.js +38 -40
  140. package/dist/translation/transforms/import-transforms.js.map +1 -1
  141. package/dist/zip/zip-manager.d.ts +4 -3
  142. package/dist/zip/zip-manager.js +9 -9
  143. package/dist/zip/zip-manager.js.map +1 -1
  144. package/dist/zip/zip-packager.d.ts +2 -2
  145. package/dist/zip/zip-packager.js +19 -17
  146. package/dist/zip/zip-packager.js.map +1 -1
  147. package/dist/zip/zip-transformer.d.ts +3 -2
  148. package/dist/zip/zip-transformer.js +16 -15
  149. package/dist/zip/zip-transformer.js.map +1 -1
  150. package/dist/zip/zip.models.d.ts +2 -2
  151. package/lib/core/config.ts +6 -6
  152. package/lib/core/helpers/workflow-helper.ts +190 -185
  153. package/lib/core/logs/loggers.ts +52 -52
  154. package/lib/core/models/core.models.ts +128 -119
  155. package/lib/core/models/error.models.ts +41 -0
  156. package/lib/core/models/log.models.ts +20 -20
  157. package/lib/core/models/migration.models.ts +54 -54
  158. package/lib/core/models/migration.schema.ts +108 -108
  159. package/lib/core/utils/array.utils.ts +43 -42
  160. package/lib/core/utils/binary-data.utils.ts +16 -16
  161. package/lib/core/utils/confirm.utils.ts +106 -105
  162. package/lib/core/utils/error.utils.ts +69 -72
  163. package/lib/core/utils/external-id.utils.ts +4 -4
  164. package/lib/core/utils/global.utils.ts +81 -75
  165. package/lib/core/utils/http.utils.ts +23 -23
  166. package/lib/core/utils/management-client-utils.ts +186 -186
  167. package/lib/core/utils/processing-utils.ts +82 -82
  168. package/lib/core/utils/run.utils.ts +50 -50
  169. package/lib/export/context/export-context-fetcher.ts +472 -447
  170. package/lib/export/export-manager.ts +233 -232
  171. package/lib/export/export.models.ts +71 -56
  172. package/lib/export/utils/export.utils.ts +9 -7
  173. package/lib/file/file-manager.ts +28 -28
  174. package/lib/import/comparers/asset-comparer.ts +107 -106
  175. package/lib/import/context/import-context-fetcher.ts +462 -462
  176. package/lib/import/import-manager.ts +243 -240
  177. package/lib/import/import.models.ts +69 -67
  178. package/lib/import/importers/assets-importer.ts +240 -236
  179. package/lib/import/importers/content-items-importer.ts +126 -122
  180. package/lib/import/importers/language-variant-importer.ts +324 -328
  181. package/lib/import/importers/workflow-importer.ts +372 -367
  182. package/lib/import/utils/import.utils.ts +9 -7
  183. package/lib/index.ts +12 -8
  184. package/lib/metadata.ts +3 -4
  185. package/lib/node/cli/actions/export-action.ts +43 -38
  186. package/lib/node/cli/actions/import-action.ts +32 -29
  187. package/lib/node/cli/actions/migrate-action.ts +49 -46
  188. package/lib/node/cli/app.ts +21 -21
  189. package/lib/node/cli/args/args-fetcher.ts +55 -54
  190. package/lib/node/cli/args/args-setter.ts +34 -32
  191. package/lib/node/cli/cli.models.ts +17 -17
  192. package/lib/node/cli/commands.ts +165 -153
  193. package/lib/toolkit/elements-builder.ts +69 -69
  194. package/lib/toolkit/export.ts +21 -21
  195. package/lib/toolkit/file.ts +59 -53
  196. package/lib/toolkit/import.ts +32 -32
  197. package/lib/toolkit/migrate.ts +60 -49
  198. package/lib/translation/extraction/items-extraction.processor.ts +203 -173
  199. package/lib/translation/helpers/export-placeholder.utils.ts +10 -0
  200. package/lib/translation/helpers/rich-text.processor.ts +311 -311
  201. package/lib/translation/transforms/export-transforms.ts +313 -279
  202. package/lib/translation/transforms/import-transforms.ts +188 -191
  203. package/lib/zip/zip-manager.ts +28 -27
  204. package/lib/zip/zip-packager.ts +75 -73
  205. package/lib/zip/zip-transformer.ts +112 -107
  206. package/lib/zip/zip.models.ts +7 -7
  207. package/package.json +91 -84
  208. package/dist/core/index.d.ts +0 -16
  209. package/dist/core/index.js +0 -17
  210. package/dist/core/index.js.map +0 -1
  211. package/dist/export/index.d.ts +0 -2
  212. package/dist/export/index.js +0 -3
  213. package/dist/export/index.js.map +0 -1
  214. package/dist/file/index.d.ts +0 -1
  215. package/dist/file/index.js +0 -2
  216. package/dist/file/index.js.map +0 -1
  217. package/dist/import/index.d.ts +0 -2
  218. package/dist/import/index.js +0 -3
  219. package/dist/import/index.js.map +0 -1
  220. package/dist/toolkit/index.d.ts +0 -5
  221. package/dist/toolkit/index.js +0 -6
  222. package/dist/toolkit/index.js.map +0 -1
  223. package/dist/translation/index.d.ts +0 -4
  224. package/dist/translation/index.js +0 -5
  225. package/dist/translation/index.js.map +0 -1
  226. package/dist/zip/index.d.ts +0 -4
  227. package/dist/zip/index.js +0 -5
  228. package/dist/zip/index.js.map +0 -1
  229. package/lib/core/index.ts +0 -18
  230. package/lib/export/index.ts +0 -2
  231. package/lib/file/index.ts +0 -1
  232. package/lib/import/index.ts +0 -2
  233. package/lib/toolkit/index.ts +0 -5
  234. package/lib/translation/index.ts +0 -4
  235. package/lib/zip/index.ts +0 -4
@@ -1,37 +1,37 @@
1
- import chalk from 'chalk';
2
- import { writeFile } from 'fs/promises';
3
- import { executeWithTrackingAsync } from '../core/index.js';
4
- import type { ImportConfig, ImportResult } from '../import/index.js';
5
- import { importManager as _importManager } from '../import/index.js';
6
- import { libMetadata } from '../metadata.js';
1
+ import { writeFile } from "node:fs/promises";
2
+ import chalk from "chalk";
3
+ import { executeWithTrackingAsync } from "../core/utils/global.utils.js";
4
+ import type { ImportConfig, ImportResult } from "../import/import.models.js";
5
+ import { importManager as _importManager } from "../import/import-manager.js";
6
+ import { libMetadata } from "../metadata.js";
7
7
 
8
8
  export async function importAsync(config: ImportConfig): Promise<ImportResult> {
9
- return await executeWithTrackingAsync({
10
- event: {
11
- tool: 'migrationToolkit',
12
- package: {
13
- name: libMetadata.name,
14
- version: libMetadata.version
15
- },
16
- action: 'import',
17
- relatedEnvironmentId: undefined,
18
- details: {}
19
- },
20
- func: async () => {
21
- const importManager = _importManager(config);
22
- const importResult = await importManager.importAsync();
9
+ return await executeWithTrackingAsync({
10
+ event: {
11
+ tool: "migrationToolkit",
12
+ package: {
13
+ name: libMetadata.name,
14
+ version: libMetadata.version,
15
+ },
16
+ action: "import",
17
+ relatedEnvironmentId: undefined,
18
+ details: {},
19
+ },
20
+ func: async () => {
21
+ const importManager = _importManager(config);
22
+ const importResult = await importManager.importAsync();
23
23
 
24
- if (config.createReportFile) {
25
- const reportFile = importManager.getReportFile(importResult);
26
- await writeFile(reportFile.filename, reportFile.content);
27
- config.logger?.log({
28
- type: 'writeFs',
29
- message: `Report '${chalk.yellow(reportFile.filename)}' was created`
30
- });
31
- }
24
+ if (config.createReportFile) {
25
+ const reportFile = importManager.getReportFile(importResult);
26
+ await writeFile(reportFile.filename, reportFile.content);
27
+ config.logger?.log({
28
+ type: "writeFs",
29
+ message: `Report '${chalk.yellow(reportFile.filename)}' was created`,
30
+ });
31
+ }
32
32
 
33
- return importResult;
34
- },
35
- logger: config.logger
36
- });
33
+ return importResult;
34
+ },
35
+ logger: config.logger,
36
+ });
37
37
  }
@@ -1,64 +1,75 @@
1
- import type { IRetryStrategyOptions } from '@kontent-ai/core-sdk';
2
- import type { ExternalIdGenerator, Logger, ManagementClientConfig, MigrationData } from '../core/index.js';
3
- import { executeWithTrackingAsync, getDefaultLogger } from '../core/index.js';
4
- import type { SourceExportItem } from '../export/index.js';
5
- import type { ImportResult } from '../import/index.js';
6
- import { libMetadata } from '../metadata.js';
7
- import { exportAsync } from './export.js';
8
- import { importAsync } from './import.js';
1
+ import type { IRetryStrategyOptions } from "@kontent-ai/core-sdk";
2
+ import { getDefaultLogger } from "../core/logs/loggers.js";
3
+ import type { Logger } from "../core/models/log.models.js";
4
+ import type { MigrationData } from "../core/models/migration.models.js";
5
+ import type { ExternalIdGenerator } from "../core/utils/external-id.utils.js";
6
+ import { executeWithTrackingAsync } from "../core/utils/global.utils.js";
7
+ import type { ManagementClientConfig } from "../core/utils/management-client-utils.js";
8
+ import type { SourceExportItem } from "../export/export.models.js";
9
+ import type { ImportResult } from "../import/import.models.js";
10
+ import { libMetadata } from "../metadata.js";
11
+ import { exportAsync } from "./export.js";
12
+ import { importAsync } from "./import.js";
9
13
 
10
14
  export interface MigrationSource extends ManagementClientConfig {
11
- readonly items: readonly SourceExportItem[];
15
+ readonly items: readonly SourceExportItem[];
16
+ /**
17
+ * When enabled, the export process will skip missing items and assets instead of throwing errors.
18
+ * Missing references will be filtered out from the exported data.
19
+ * Default: false
20
+ */
21
+ readonly skipMissingReferences?: boolean;
12
22
  }
13
23
 
14
24
  export interface MigrationConfig {
15
- readonly retryStrategy?: IRetryStrategyOptions;
16
- readonly externalIdGenerator?: ExternalIdGenerator;
17
- readonly logger?: Logger;
18
- readonly sourceEnvironment: MigrationSource;
19
- readonly targetEnvironment: ManagementClientConfig;
25
+ readonly retryStrategy?: IRetryStrategyOptions;
26
+ readonly externalIdGenerator?: ExternalIdGenerator;
27
+ readonly logger?: Logger;
28
+ readonly sourceEnvironment: MigrationSource;
29
+ readonly targetEnvironment: ManagementClientConfig;
20
30
  }
21
31
 
22
32
  export interface MigrationResult {
23
- readonly migrationData: MigrationData;
24
- readonly importResult: ImportResult;
33
+ readonly migrationData: MigrationData;
34
+ readonly importResult: ImportResult;
25
35
  }
26
36
 
27
37
  export async function migrateAsync(config: MigrationConfig): Promise<MigrationResult> {
28
- const logger = config.logger ?? getDefaultLogger();
38
+ const logger = config.logger ?? getDefaultLogger();
29
39
 
30
- return await executeWithTrackingAsync({
31
- event: {
32
- tool: 'migrationToolkit',
33
- package: {
34
- name: libMetadata.name,
35
- version: libMetadata.version
36
- },
37
- action: 'migrate',
38
- relatedEnvironmentId: undefined,
39
- details: {
40
- itemsCount: config.sourceEnvironment.items.length
41
- }
42
- },
43
- func: async () => {
44
- const migrationData = await exportAsync({
45
- ...config.sourceEnvironment,
46
- logger: logger,
47
- exportItems: config.sourceEnvironment.items
48
- });
40
+ return await executeWithTrackingAsync({
41
+ event: {
42
+ tool: "migrationToolkit",
43
+ package: {
44
+ name: libMetadata.name,
45
+ version: libMetadata.version,
46
+ },
47
+ action: "migrate",
48
+ relatedEnvironmentId: undefined,
49
+ details: {
50
+ itemsCount: config.sourceEnvironment.items.length,
51
+ },
52
+ },
53
+ func: async () => {
54
+ const migrationData = await exportAsync({
55
+ ...config.sourceEnvironment,
56
+ logger: logger,
57
+ exportItems: config.sourceEnvironment.items,
58
+ skipMissingReferences: config.sourceEnvironment.skipMissingReferences,
59
+ });
49
60
 
50
- const importResult = await importAsync({
51
- ...config.targetEnvironment,
52
- logger: logger,
53
- data: migrationData,
54
- externalIdGenerator: config.externalIdGenerator
55
- });
61
+ const importResult = await importAsync({
62
+ ...config.targetEnvironment,
63
+ logger: logger,
64
+ data: migrationData,
65
+ externalIdGenerator: config.externalIdGenerator,
66
+ });
56
67
 
57
- return {
58
- importResult,
59
- migrationData
60
- };
61
- },
62
- logger: config.logger
63
- });
68
+ return {
69
+ importResult,
70
+ migrationData,
71
+ };
72
+ },
73
+ logger: config.logger,
74
+ });
64
75
  }
@@ -1,188 +1,218 @@
1
- import type { ElementModels } from '@kontent-ai/management-sdk';
2
- import { match, P } from 'ts-pattern';
3
- import type {
4
- MigrationElementModels,
5
- MigrationElements,
6
- ReferencedDataInLanguageVariants,
7
- ReferencedDataInMigrationItems
8
- } from '../../core/index.js';
9
- import { isArray, isString, parseAsMigrationReferencesArray } from '../../core/index.js';
10
- import type { GetFlattenedElementByIds } from '../../export/export.models.js';
11
- import type { GetFlattenedElementByCodenames } from '../../import/index.js';
12
- import { richTextProcessor } from '../index.js';
1
+ import { isArray } from "node:util";
2
+ import type { ElementModels } from "@kontent-ai/management-sdk";
3
+ import { match, P } from "ts-pattern";
4
+ import type { ReferencedDataInLanguageVariants, ReferencedDataInMigrationItems } from "../../core/models/core.models.js";
5
+ import type { MigrationElementModels, MigrationElements } from "../../core/models/migration.models.js";
6
+ import { parseAsMigrationReferencesArray } from "../../core/utils/array.utils.js";
7
+ import { isString } from "../../core/utils/global.utils.js";
8
+ import type { GetFlattenedElementByIds } from "../../export/export.models.js";
9
+ import type { GetFlattenedElementByCodenames } from "../../import/import.models.js";
10
+ import { richTextProcessor } from "../helpers/rich-text.processor.js";
13
11
 
14
12
  export interface ExtractItemById {
15
- readonly elements: readonly Readonly<ElementModels.ContentItemElement>[];
16
- readonly contentTypeId: string;
13
+ readonly elements: readonly Readonly<ElementModels.ContentItemElement>[];
14
+ readonly contentTypeId: string;
17
15
  }
18
16
 
19
17
  export interface ExtractItemByCodename {
20
- readonly elements: MigrationElements;
21
- readonly contentTypeCodename: string;
18
+ readonly elements: MigrationElements;
19
+ readonly contentTypeCodename: string;
22
20
  }
23
21
 
24
22
  export interface ReferencedDataInMigrationItemsLocal {
25
- readonly itemCodenames: Set<string>;
26
- readonly assetCodenames: Set<string>;
23
+ readonly itemCodenames: Set<string>;
24
+ readonly assetCodenames: Set<string>;
27
25
  }
28
26
 
29
27
  export interface ReferencedDataInLanguageVariantsLocal {
30
- readonly itemIds: Set<string>;
31
- readonly assetIds: Set<string>;
28
+ readonly itemIds: Set<string>;
29
+ readonly assetIds: Set<string>;
32
30
  }
33
31
 
34
32
  export function itemsExtractionProcessor() {
35
- const extractReferencedDataFromExtractItems = (
36
- items: readonly ExtractItemById[],
37
- getElement: GetFlattenedElementByIds
38
- ): ReferencedDataInLanguageVariants => {
39
- const extractedIds = items.reduce<ReferencedDataInLanguageVariantsLocal>(
40
- (extractedIds, item) => {
41
- return item.elements.reduce<ReferencedDataInLanguageVariantsLocal>((childExtractedIds, itemElement) => {
42
- const typeElement = getElement(item.contentTypeId, itemElement.element.id ?? '');
43
-
44
- match(typeElement.type)
45
- .with('rich_text', () => {
46
- const rteValue = itemElement.value && isString(itemElement.value) ? itemElement.value : '';
47
-
48
- // extract referenced items
49
- richTextProcessor()
50
- .processDataIds(rteValue)
51
- .ids.forEach((id) => extractedIds.itemIds.add(id));
52
-
53
- richTextProcessor()
54
- .processLinkItemIds(rteValue)
55
- .ids.forEach((id) => extractedIds.itemIds.add(id));
56
-
57
- // extract referenced assets
58
- richTextProcessor()
59
- .processAssetIds(rteValue)
60
- .ids.forEach((id) => extractedIds.assetIds.add(id));
61
-
62
- richTextProcessor()
63
- .processLinkAssetIds(rteValue)
64
- .ids.forEach((id) => extractedIds.assetIds.add(id));
65
-
66
- // recursively extract data from components as well because they may reference additional assets & content items
67
- const extractedComponents = extractReferencedDataFromExtractItems(
68
- itemElement.components.map((component) => {
69
- return {
70
- contentTypeId: component.type.id ?? '',
71
- elements: component.elements
72
- };
73
- }),
74
- getElement
75
- );
76
-
77
- extractedComponents.itemIds.forEach((id) => extractedIds.itemIds.add(id));
78
- extractedComponents.assetIds.forEach((id) => extractedIds.assetIds.add(id));
79
- })
80
- .with(P.union('modular_content', 'subpages'), () => {
81
- if (itemElement.value && isArray(itemElement.value)) {
82
- itemElement.value.forEach((value) => (value.id ? extractedIds.itemIds.add(value.id) : {}));
83
- }
84
- })
85
- .with('asset', () => {
86
- if (itemElement.value && isArray(itemElement.value)) {
87
- itemElement.value.forEach((value) => (value.id ? extractedIds.assetIds.add(value.id) : {}));
88
- }
89
- })
90
- .otherwise(() => {});
91
-
92
- return childExtractedIds;
93
- }, extractedIds);
94
- },
95
- { itemIds: new Set(), assetIds: new Set() }
96
- );
97
-
98
- return {
99
- itemIds: extractedIds.itemIds,
100
- assetIds: extractedIds.assetIds
101
- };
102
- };
103
-
104
- const extractReferencedItemsFromMigrationItems = (
105
- items: readonly ExtractItemByCodename[],
106
- getElement: GetFlattenedElementByCodenames
107
- ): ReferencedDataInMigrationItems => {
108
- const extractedCodenames = items.reduce<ReferencedDataInMigrationItemsLocal>(
109
- (extractedCodenames, item) => {
110
- return Object.entries(item.elements).reduce<ReferencedDataInMigrationItemsLocal>(
111
- (childExtractedCodenames, [elementCodename, element]) => {
112
- const flattenedElement = getElement(item.contentTypeCodename, elementCodename, element.type);
113
- match(flattenedElement.type)
114
- .with('rich_text', () => {
115
- const richTextElementValue = element as MigrationElementModels.RichTextElement;
116
- const richTextHtml = richTextElementValue?.value ?? '';
117
-
118
- // items
119
- richTextProcessor()
120
- .processItemCodenames(richTextHtml)
121
- .codenames.forEach((codename) => childExtractedCodenames.itemCodenames.add(codename));
122
-
123
- richTextProcessor()
124
- .processLinkItemCodenames(richTextHtml)
125
- .codenames.forEach((codename) => childExtractedCodenames.itemCodenames.add(codename));
126
-
127
- // assets
128
- richTextProcessor()
129
- .processAssetCodenames(richTextHtml)
130
- .codenames.forEach((codename) => childExtractedCodenames.assetCodenames.add(codename));
131
-
132
- richTextProcessor()
133
- .processLinkAssetCodenames(richTextHtml)
134
- .codenames.forEach((codename) => childExtractedCodenames.assetCodenames.add(codename));
135
-
136
- // recursively extract data from components as well because they may reference additional assets & content items
137
- const extractedComponents = extractReferencedItemsFromMigrationItems(
138
- (element.components ?? []).map((component) => {
139
- const extractionItem: ExtractItemByCodename = {
140
- contentTypeCodename: component.system.type.codename,
141
- elements: component.elements
142
- };
143
-
144
- return extractionItem;
145
- }),
146
- getElement
147
- );
148
-
149
- extractedComponents.itemCodenames.forEach((codename) =>
150
- childExtractedCodenames.itemCodenames.add(codename)
151
- );
152
- extractedComponents.assetCodenames.forEach((codename) =>
153
- childExtractedCodenames.assetCodenames.add(codename)
154
- );
155
- })
156
- .with(P.union('modular_content', 'subpages'), () => {
157
- parseAsMigrationReferencesArray(element.value)
158
- .map((m) => m.codename)
159
- .forEach((codename) => childExtractedCodenames.itemCodenames.add(codename));
160
- })
161
- .with('asset', () => {
162
- parseAsMigrationReferencesArray(element.value)
163
- .map((m) => m.codename)
164
- .forEach((codename) => childExtractedCodenames.assetCodenames.add(codename));
165
- });
166
-
167
- return childExtractedCodenames;
168
- },
169
- extractedCodenames
170
- );
171
- },
172
- {
173
- itemCodenames: new Set(),
174
- assetCodenames: new Set()
175
- }
176
- );
177
-
178
- return {
179
- itemCodenames: extractedCodenames.itemCodenames,
180
- assetCodenames: extractedCodenames.assetCodenames
181
- };
182
- };
183
-
184
- return {
185
- extractReferencedDataFromExtractItems,
186
- extractReferencedItemsFromMigrationItems
187
- };
33
+ const extractReferencedDataFromExtractItems = (
34
+ items: readonly ExtractItemById[],
35
+ getElement: GetFlattenedElementByIds,
36
+ ): ReferencedDataInLanguageVariants => {
37
+ const extractedIds = items.reduce<ReferencedDataInLanguageVariantsLocal>(
38
+ (extractedIds, item) => {
39
+ return item.elements.reduce<ReferencedDataInLanguageVariantsLocal>((childExtractedIds, itemElement) => {
40
+ const typeElement = getElement(item.contentTypeId, itemElement.element.id ?? "");
41
+
42
+ match(typeElement.type)
43
+ .with("rich_text", () => {
44
+ const rteValue = itemElement.value && isString(itemElement.value) ? itemElement.value : "";
45
+
46
+ // extract referenced items
47
+ richTextProcessor()
48
+ .processDataIds(rteValue)
49
+ .ids.forEach((id) => {
50
+ extractedIds.itemIds.add(id);
51
+ });
52
+
53
+ richTextProcessor()
54
+ .processLinkItemIds(rteValue)
55
+ .ids.forEach((id) => {
56
+ extractedIds.itemIds.add(id);
57
+ });
58
+
59
+ // extract referenced assets
60
+ richTextProcessor()
61
+ .processAssetIds(rteValue)
62
+ .ids.forEach((id) => {
63
+ extractedIds.assetIds.add(id);
64
+ });
65
+
66
+ richTextProcessor()
67
+ .processLinkAssetIds(rteValue)
68
+ .ids.forEach((id) => {
69
+ extractedIds.assetIds.add(id);
70
+ });
71
+
72
+ // recursively extract data from components as well because they may reference additional assets & content items
73
+ const extractedComponents = extractReferencedDataFromExtractItems(
74
+ itemElement.components.map((component) => {
75
+ return {
76
+ contentTypeId: component.type.id ?? "",
77
+ elements: component.elements,
78
+ };
79
+ }),
80
+ getElement,
81
+ );
82
+
83
+ extractedComponents.itemIds.forEach((id) => {
84
+ extractedIds.itemIds.add(id);
85
+ });
86
+ extractedComponents.assetIds.forEach((id) => {
87
+ extractedIds.assetIds.add(id);
88
+ });
89
+ })
90
+ .with(P.union("modular_content", "subpages"), () => {
91
+ if (itemElement.value && isArray(itemElement.value)) {
92
+ itemElement.value.forEach((value) => {
93
+ if (value.id) {
94
+ extractedIds.itemIds.add(value.id);
95
+ }
96
+ });
97
+ }
98
+ })
99
+ .with("asset", () => {
100
+ if (itemElement.value && isArray(itemElement.value)) {
101
+ itemElement.value.forEach((value) => {
102
+ if (value.id) {
103
+ extractedIds.assetIds.add(value.id);
104
+ }
105
+ });
106
+ }
107
+ })
108
+ .otherwise(() => {});
109
+
110
+ return childExtractedIds;
111
+ }, extractedIds);
112
+ },
113
+ { itemIds: new Set(), assetIds: new Set() },
114
+ );
115
+
116
+ return {
117
+ itemIds: extractedIds.itemIds,
118
+ assetIds: extractedIds.assetIds,
119
+ };
120
+ };
121
+
122
+ const extractReferencedItemsFromMigrationItems = (
123
+ items: readonly ExtractItemByCodename[],
124
+ getElement: GetFlattenedElementByCodenames,
125
+ ): ReferencedDataInMigrationItems => {
126
+ const extractedCodenames = items.reduce<ReferencedDataInMigrationItemsLocal>(
127
+ (extractedCodenames, item) => {
128
+ return Object.entries(item.elements).reduce<ReferencedDataInMigrationItemsLocal>(
129
+ (childExtractedCodenames, [elementCodename, element]) => {
130
+ const flattenedElement = getElement(item.contentTypeCodename, elementCodename, element.type);
131
+ match(flattenedElement.type)
132
+ .with("rich_text", () => {
133
+ const richTextElementValue = element as MigrationElementModels.RichTextElement;
134
+ const richTextHtml = richTextElementValue.value ?? "";
135
+
136
+ // items
137
+ richTextProcessor()
138
+ .processItemCodenames(richTextHtml)
139
+ .codenames.forEach((codename) => {
140
+ childExtractedCodenames.itemCodenames.add(codename);
141
+ });
142
+
143
+ richTextProcessor()
144
+ .processLinkItemCodenames(richTextHtml)
145
+ .codenames.forEach((codename) => {
146
+ childExtractedCodenames.itemCodenames.add(codename);
147
+ });
148
+
149
+ // assets
150
+ richTextProcessor()
151
+ .processAssetCodenames(richTextHtml)
152
+ .codenames.forEach((codename) => {
153
+ childExtractedCodenames.assetCodenames.add(codename);
154
+ });
155
+
156
+ richTextProcessor()
157
+ .processLinkAssetCodenames(richTextHtml)
158
+ .codenames.forEach((codename) => {
159
+ childExtractedCodenames.assetCodenames.add(codename);
160
+ });
161
+
162
+ // recursively extract data from components as well because they may reference additional assets & content items
163
+ const extractedComponents = extractReferencedItemsFromMigrationItems(
164
+ (element.components ?? []).map((component) => {
165
+ const extractionItem: ExtractItemByCodename = {
166
+ contentTypeCodename: component.system.type.codename,
167
+ elements: component.elements,
168
+ };
169
+
170
+ return extractionItem;
171
+ }),
172
+ getElement,
173
+ );
174
+
175
+ extractedComponents.itemCodenames.forEach((codename) => {
176
+ childExtractedCodenames.itemCodenames.add(codename);
177
+ });
178
+ extractedComponents.assetCodenames.forEach((codename) => {
179
+ childExtractedCodenames.assetCodenames.add(codename);
180
+ });
181
+ })
182
+ .with(P.union("modular_content", "subpages"), () => {
183
+ parseAsMigrationReferencesArray(element.value)
184
+ .map((m) => m.codename)
185
+ .forEach((codename) => {
186
+ childExtractedCodenames.itemCodenames.add(codename);
187
+ });
188
+ })
189
+ .with("asset", () => {
190
+ parseAsMigrationReferencesArray(element.value)
191
+ .map((m) => m.codename)
192
+ .forEach((codename) => {
193
+ childExtractedCodenames.assetCodenames.add(codename);
194
+ });
195
+ });
196
+
197
+ return childExtractedCodenames;
198
+ },
199
+ extractedCodenames,
200
+ );
201
+ },
202
+ {
203
+ itemCodenames: new Set(),
204
+ assetCodenames: new Set(),
205
+ },
206
+ );
207
+
208
+ return {
209
+ itemCodenames: extractedCodenames.itemCodenames,
210
+ assetCodenames: extractedCodenames.assetCodenames,
211
+ };
212
+ };
213
+
214
+ return {
215
+ extractReferencedDataFromExtractItems,
216
+ extractReferencedItemsFromMigrationItems,
217
+ };
188
218
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Returns a placeholder that indicates missing reference, this placeholder is not actually used anywhere
3
+ * as missing items will simply be skipped, but may help when debugging in future
4
+ * @param type - The type of the reference
5
+ * @param id - The id of the reference
6
+ * @returns A placeholder that indicates missing reference
7
+ */
8
+ export function getMissingReferencePlaceholder({ type, id }: { readonly type: "item" | "asset"; readonly id: string }): string {
9
+ return `#missing:${type}:${id}#`;
10
+ }