@strapi/data-transfer 5.48.0 → 5.49.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 (210) hide show
  1. package/dist/directory/providers/destination/index.d.ts +1 -1
  2. package/dist/directory/providers/destination/index.d.ts.map +1 -1
  3. package/dist/directory/providers/destination/index.js +16 -11
  4. package/dist/directory/providers/destination/index.js.map +1 -1
  5. package/dist/directory/providers/destination/index.mjs.map +1 -1
  6. package/dist/directory/providers/destination/utils.js +6 -2
  7. package/dist/directory/providers/destination/utils.js.map +1 -1
  8. package/dist/directory/providers/source/index.d.ts +1 -1
  9. package/dist/directory/providers/source/index.d.ts.map +1 -1
  10. package/dist/directory/providers/source/index.js +25 -20
  11. package/dist/directory/providers/source/index.js.map +1 -1
  12. package/dist/directory/providers/source/index.mjs.map +1 -1
  13. package/dist/engine/index.d.ts +1 -1
  14. package/dist/engine/index.d.ts.map +1 -1
  15. package/dist/engine/index.js.map +1 -1
  16. package/dist/engine/index.mjs.map +1 -1
  17. package/dist/engine/validation/provider.d.ts +1 -1
  18. package/dist/engine/validation/provider.d.ts.map +1 -1
  19. package/dist/engine/validation/provider.js.map +1 -1
  20. package/dist/engine/validation/provider.mjs.map +1 -1
  21. package/dist/errors/providers.d.ts +1 -1
  22. package/dist/errors/providers.d.ts.map +1 -1
  23. package/dist/errors/providers.js.map +1 -1
  24. package/dist/errors/providers.mjs.map +1 -1
  25. package/dist/file/providers/destination/index.d.ts +1 -1
  26. package/dist/file/providers/destination/index.d.ts.map +1 -1
  27. package/dist/file/providers/destination/index.js +10 -4
  28. package/dist/file/providers/destination/index.js.map +1 -1
  29. package/dist/file/providers/destination/index.mjs.map +1 -1
  30. package/dist/file/providers/source/index.d.ts +1 -1
  31. package/dist/file/providers/source/index.d.ts.map +1 -1
  32. package/dist/file/providers/source/index.js +9 -3
  33. package/dist/file/providers/source/index.js.map +1 -1
  34. package/dist/file/providers/source/index.mjs.map +1 -1
  35. package/dist/file/providers/source/utils.js +10 -6
  36. package/dist/file/providers/source/utils.js.map +1 -1
  37. package/dist/strapi/providers/local-destination/assets-destination-writable.d.ts +9 -4
  38. package/dist/strapi/providers/local-destination/assets-destination-writable.d.ts.map +1 -1
  39. package/dist/strapi/providers/local-destination/assets-destination-writable.js +67 -49
  40. package/dist/strapi/providers/local-destination/assets-destination-writable.js.map +1 -1
  41. package/dist/strapi/providers/local-destination/assets-destination-writable.mjs +67 -49
  42. package/dist/strapi/providers/local-destination/assets-destination-writable.mjs.map +1 -1
  43. package/dist/strapi/providers/local-destination/index.d.ts +1 -1
  44. package/dist/strapi/providers/local-destination/index.d.ts.map +1 -1
  45. package/dist/strapi/providers/local-destination/index.js +11 -7
  46. package/dist/strapi/providers/local-destination/index.js.map +1 -1
  47. package/dist/strapi/providers/local-destination/index.mjs.map +1 -1
  48. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts +1 -1
  49. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts.map +1 -1
  50. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js +9 -3
  51. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +1 -1
  52. package/dist/strapi/providers/local-destination/strategies/restore/configuration.mjs +4 -2
  53. package/dist/strapi/providers/local-destination/strategies/restore/configuration.mjs.map +1 -1
  54. package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts +1 -1
  55. package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts.map +1 -1
  56. package/dist/strapi/providers/local-destination/strategies/restore/entities.js +13 -25
  57. package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +1 -1
  58. package/dist/strapi/providers/local-destination/strategies/restore/entities.mjs +14 -26
  59. package/dist/strapi/providers/local-destination/strategies/restore/entities.mjs.map +1 -1
  60. package/dist/strapi/providers/local-destination/strategies/restore/index.js +0 -4
  61. package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +1 -1
  62. package/dist/strapi/providers/local-destination/strategies/restore/index.mjs +0 -4
  63. package/dist/strapi/providers/local-destination/strategies/restore/index.mjs.map +1 -1
  64. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +1 -1
  65. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts.map +1 -1
  66. package/dist/strapi/providers/local-destination/strategies/restore/links.js +22 -3
  67. package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +1 -1
  68. package/dist/strapi/providers/local-destination/strategies/restore/links.mjs +22 -3
  69. package/dist/strapi/providers/local-destination/strategies/restore/links.mjs.map +1 -1
  70. package/dist/strapi/providers/local-source/assets.d.ts +1 -1
  71. package/dist/strapi/providers/local-source/assets.d.ts.map +1 -1
  72. package/dist/strapi/providers/local-source/assets.js.map +1 -1
  73. package/dist/strapi/providers/local-source/assets.mjs.map +1 -1
  74. package/dist/strapi/providers/local-source/configuration.d.ts.map +1 -1
  75. package/dist/strapi/providers/local-source/configuration.js +8 -0
  76. package/dist/strapi/providers/local-source/configuration.js.map +1 -1
  77. package/dist/strapi/providers/local-source/configuration.mjs +8 -0
  78. package/dist/strapi/providers/local-source/configuration.mjs.map +1 -1
  79. package/dist/strapi/providers/local-source/entities.d.ts +3 -1
  80. package/dist/strapi/providers/local-source/entities.d.ts.map +1 -1
  81. package/dist/strapi/providers/local-source/entities.js +7 -3
  82. package/dist/strapi/providers/local-source/entities.js.map +1 -1
  83. package/dist/strapi/providers/local-source/entities.mjs +7 -3
  84. package/dist/strapi/providers/local-source/entities.mjs.map +1 -1
  85. package/dist/strapi/providers/local-source/estimate-asset-totals.d.ts +1 -1
  86. package/dist/strapi/providers/local-source/estimate-asset-totals.d.ts.map +1 -1
  87. package/dist/strapi/providers/local-source/estimate-asset-totals.js.map +1 -1
  88. package/dist/strapi/providers/local-source/estimate-asset-totals.mjs.map +1 -1
  89. package/dist/strapi/providers/local-source/index.d.ts +2 -2
  90. package/dist/strapi/providers/local-source/index.d.ts.map +1 -1
  91. package/dist/strapi/providers/local-source/index.js +6 -1
  92. package/dist/strapi/providers/local-source/index.js.map +1 -1
  93. package/dist/strapi/providers/local-source/index.mjs +6 -1
  94. package/dist/strapi/providers/local-source/index.mjs.map +1 -1
  95. package/dist/strapi/providers/local-source/links.js.map +1 -1
  96. package/dist/strapi/providers/local-source/links.mjs.map +1 -1
  97. package/dist/strapi/providers/remote-destination/index.d.ts +2 -2
  98. package/dist/strapi/providers/remote-destination/index.d.ts.map +1 -1
  99. package/dist/strapi/providers/remote-destination/index.js +24 -3
  100. package/dist/strapi/providers/remote-destination/index.js.map +1 -1
  101. package/dist/strapi/providers/remote-destination/index.mjs +25 -4
  102. package/dist/strapi/providers/remote-destination/index.mjs.map +1 -1
  103. package/dist/strapi/providers/remote-source/index.d.ts +2 -2
  104. package/dist/strapi/providers/remote-source/index.d.ts.map +1 -1
  105. package/dist/strapi/providers/remote-source/index.js.map +1 -1
  106. package/dist/strapi/providers/remote-source/index.mjs.map +1 -1
  107. package/dist/strapi/providers/utils.d.ts +2 -2
  108. package/dist/strapi/providers/utils.d.ts.map +1 -1
  109. package/dist/strapi/providers/utils.js.map +1 -1
  110. package/dist/strapi/providers/utils.mjs.map +1 -1
  111. package/dist/strapi/queries/link.d.ts +1 -1
  112. package/dist/strapi/queries/link.d.ts.map +1 -1
  113. package/dist/strapi/queries/link.js.map +1 -1
  114. package/dist/strapi/queries/link.mjs.map +1 -1
  115. package/dist/strapi/remote/flows/index.d.ts +1 -1
  116. package/dist/strapi/remote/flows/index.d.ts.map +1 -1
  117. package/dist/strapi/remote/flows/index.js.map +1 -1
  118. package/dist/strapi/remote/flows/index.mjs.map +1 -1
  119. package/dist/strapi/remote/handlers/pull.d.ts +1 -1
  120. package/dist/strapi/remote/handlers/pull.d.ts.map +1 -1
  121. package/dist/strapi/remote/handlers/pull.js +3 -3
  122. package/dist/strapi/remote/handlers/pull.js.map +1 -1
  123. package/dist/strapi/remote/handlers/pull.mjs +3 -3
  124. package/dist/strapi/remote/handlers/pull.mjs.map +1 -1
  125. package/dist/strapi/remote/handlers/push.d.ts +1 -1
  126. package/dist/strapi/remote/handlers/push.d.ts.map +1 -1
  127. package/dist/strapi/remote/handlers/push.js +8 -1
  128. package/dist/strapi/remote/handlers/push.js.map +1 -1
  129. package/dist/strapi/remote/handlers/push.mjs +8 -1
  130. package/dist/strapi/remote/handlers/push.mjs.map +1 -1
  131. package/dist/strapi/remote/handlers/utils.d.ts +1 -1
  132. package/dist/strapi/remote/handlers/utils.d.ts.map +1 -1
  133. package/dist/strapi/remote/handlers/utils.js.map +1 -1
  134. package/dist/strapi/remote/handlers/utils.mjs.map +1 -1
  135. package/dist/strapi/utils/project-settings-logos.d.ts +29 -0
  136. package/dist/strapi/utils/project-settings-logos.d.ts.map +1 -0
  137. package/dist/strapi/utils/project-settings-logos.js +174 -0
  138. package/dist/strapi/utils/project-settings-logos.js.map +1 -0
  139. package/dist/strapi/utils/project-settings-logos.mjs +169 -0
  140. package/dist/strapi/utils/project-settings-logos.mjs.map +1 -0
  141. package/dist/types/common-entities.d.ts +152 -0
  142. package/dist/types/common-entities.d.ts.map +1 -0
  143. package/dist/types/encryption.d.ts +11 -0
  144. package/dist/types/encryption.d.ts.map +1 -0
  145. package/dist/types/index.d.ts +7 -0
  146. package/dist/types/index.d.ts.map +1 -0
  147. package/dist/types/providers.d.ts +50 -0
  148. package/dist/types/providers.d.ts.map +1 -0
  149. package/dist/types/remote/index.d.ts +2 -0
  150. package/dist/types/remote/index.d.ts.map +1 -0
  151. package/dist/types/remote/protocol/auth.d.ts +5 -0
  152. package/dist/types/remote/protocol/auth.d.ts.map +1 -0
  153. package/dist/types/remote/protocol/client/commands.d.ts +37 -0
  154. package/dist/types/remote/protocol/client/commands.d.ts.map +1 -0
  155. package/dist/types/remote/protocol/client/index.d.ts +9 -0
  156. package/dist/types/remote/protocol/client/index.d.ts.map +1 -0
  157. package/dist/types/remote/protocol/client/transfer/action.d.ts +5 -0
  158. package/dist/types/remote/protocol/client/transfer/action.d.ts.map +1 -0
  159. package/dist/types/remote/protocol/client/transfer/index.d.ts +12 -0
  160. package/dist/types/remote/protocol/client/transfer/index.d.ts.map +1 -0
  161. package/dist/types/remote/protocol/client/transfer/pull.d.ts +25 -0
  162. package/dist/types/remote/protocol/client/transfer/pull.d.ts.map +1 -0
  163. package/dist/types/remote/protocol/client/transfer/push.d.ts +29 -0
  164. package/dist/types/remote/protocol/client/transfer/push.d.ts.map +1 -0
  165. package/dist/types/remote/protocol/client/transfer/utils.d.ts +49 -0
  166. package/dist/types/remote/protocol/client/transfer/utils.d.ts.map +1 -0
  167. package/dist/types/remote/protocol/index.d.ts +4 -0
  168. package/dist/types/remote/protocol/index.d.ts.map +1 -0
  169. package/dist/types/remote/protocol/server/error.d.ts +18 -0
  170. package/dist/types/remote/protocol/server/error.d.ts.map +1 -0
  171. package/dist/types/remote/protocol/server/index.d.ts +3 -0
  172. package/dist/types/remote/protocol/server/index.d.ts.map +1 -0
  173. package/dist/types/remote/protocol/server/messaging.d.ts +37 -0
  174. package/dist/types/remote/protocol/server/messaging.d.ts.map +1 -0
  175. package/dist/types/transfer-engine.d.ts +149 -0
  176. package/dist/types/transfer-engine.d.ts.map +1 -0
  177. package/dist/types/utils.d.ts +83 -0
  178. package/dist/types/utils.d.ts.map +1 -0
  179. package/dist/utils/components.d.ts +21 -1
  180. package/dist/utils/components.d.ts.map +1 -1
  181. package/dist/utils/components.js +76 -24
  182. package/dist/utils/components.js.map +1 -1
  183. package/dist/utils/components.mjs +70 -22
  184. package/dist/utils/components.mjs.map +1 -1
  185. package/dist/utils/encryption/decrypt.d.ts +1 -1
  186. package/dist/utils/encryption/decrypt.d.ts.map +1 -1
  187. package/dist/utils/encryption/decrypt.js.map +1 -1
  188. package/dist/utils/encryption/decrypt.mjs.map +1 -1
  189. package/dist/utils/encryption/encrypt.d.ts +1 -1
  190. package/dist/utils/encryption/encrypt.d.ts.map +1 -1
  191. package/dist/utils/encryption/encrypt.js.map +1 -1
  192. package/dist/utils/encryption/encrypt.mjs.map +1 -1
  193. package/dist/utils/index.js +1 -0
  194. package/dist/utils/index.js.map +1 -1
  195. package/dist/utils/index.mjs +1 -1
  196. package/dist/utils/middleware.d.ts +1 -1
  197. package/dist/utils/middleware.d.ts.map +1 -1
  198. package/dist/utils/middleware.js.map +1 -1
  199. package/dist/utils/middleware.mjs.map +1 -1
  200. package/dist/utils/transaction.d.ts +1 -1
  201. package/dist/utils/transaction.d.ts.map +1 -1
  202. package/dist/utils/transaction.js.map +1 -1
  203. package/dist/utils/transaction.mjs.map +1 -1
  204. package/dist/utils/transfer-asset-chunk.d.ts +22 -0
  205. package/dist/utils/transfer-asset-chunk.d.ts.map +1 -1
  206. package/dist/utils/transfer-asset-chunk.js +25 -0
  207. package/dist/utils/transfer-asset-chunk.js.map +1 -1
  208. package/dist/utils/transfer-asset-chunk.mjs +25 -1
  209. package/dist/utils/transfer-asset-chunk.mjs.map +1 -1
  210. package/package.json +11 -9
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/strapi/providers/local-destination/index.ts"],"sourcesContent":["import { Writable, Readable } from 'stream';\nimport path from 'path';\nimport * as fse from 'fs-extra';\nimport type { Knex } from 'knex';\nimport type { Core, Struct } from '@strapi/types';\nimport type { IDestinationProvider, IMetadata, ProviderType, Transaction } from '../../../../types';\nimport type { IDiagnosticReporter } from '../../../utils/diagnostic';\n\nimport { createAssetsDestinationWritable } from './assets-destination-writable';\nimport { restore } from './strategies';\nimport * as utils from '../../../utils';\nimport {\n ProviderInitializationError,\n ProviderTransferError,\n ProviderValidationError,\n} from '../../../errors/providers';\nimport { assertValidStrapi } from '../../../utils/providers';\n\nexport const VALID_CONFLICT_STRATEGIES = ['restore'];\nexport const DEFAULT_CONFLICT_STRATEGY = 'restore';\n\nexport interface ILocalStrapiDestinationProviderOptions {\n getStrapi(): Core.Strapi | Promise<Core.Strapi>; // return an initialized instance of Strapi\n\n autoDestroy?: boolean; // shut down the instance returned by getStrapi() at the end of the transfer\n restore?: restore.IRestoreOptions; // erase data in strapi database before transfer; required if strategy is 'restore'\n strategy: 'restore'; // conflict management strategy; only the restore strategy is available at this time\n /** CLI / UI: human-readable progress during {@link beforeTransfer} (restore prep). */\n onTransferPhase?: (message: string) => void;\n}\n\nclass LocalStrapiDestinationProvider implements IDestinationProvider {\n name = 'destination::local-strapi';\n\n type: ProviderType = 'destination';\n\n options: ILocalStrapiDestinationProviderOptions;\n\n strapi?: Core.Strapi;\n\n transaction?: Transaction;\n\n uploadsBackupDirectoryName: string;\n\n onWarning?: ((message: string) => void) | undefined;\n\n #diagnostics?: IDiagnosticReporter;\n\n /**\n * The entities mapper is used to map old entities to their new IDs\n */\n #entitiesMapper: { [type: string]: { [id: number]: number } };\n\n constructor(options: ILocalStrapiDestinationProviderOptions) {\n this.options = options;\n this.#entitiesMapper = {};\n this.uploadsBackupDirectoryName = `uploads_backup_${Date.now()}`;\n }\n\n async bootstrap(diagnostics?: IDiagnosticReporter): Promise<void> {\n this.#diagnostics = diagnostics;\n this.#validateOptions();\n this.strapi = await this.options.getStrapi();\n if (!this.strapi) {\n throw new ProviderInitializationError('Could not access local strapi');\n }\n this.strapi.db.lifecycles.disable();\n this.transaction = utils.transaction.createTransaction(this.strapi);\n }\n\n // TODO: either move this to restore strategy, or restore strategy should given access to these instead of repeating the logic possibly in a different way\n #areAssetsIncluded = () => {\n return this.options.restore?.assets;\n };\n\n #isContentTypeIncluded = (type: string) => {\n const notIncluded =\n this.options.restore?.entities?.include &&\n !this.options.restore?.entities?.include?.includes(type);\n const excluded =\n this.options.restore?.entities?.exclude &&\n this.options.restore?.entities.exclude.includes(type);\n\n return !excluded && !notIncluded;\n };\n\n #reportInfo(message: string) {\n this.#diagnostics?.report({\n details: {\n createdAt: new Date(),\n message,\n origin: 'local-destination-provider',\n },\n kind: 'info',\n });\n }\n\n async close(): Promise<void> {\n const { autoDestroy } = this.options;\n assertValidStrapi(this.strapi);\n this.transaction?.end();\n this.strapi.db.lifecycles.enable();\n // Basically `!== false` but more deterministic\n if (autoDestroy === undefined || autoDestroy === true) {\n await this.strapi?.destroy();\n }\n }\n\n #validateOptions() {\n this.#reportInfo('validating options');\n if (!VALID_CONFLICT_STRATEGIES.includes(this.options.strategy)) {\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n // require restore options when using restore\n if (this.options.strategy === 'restore' && !this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n }\n\n async #deleteFromRestoreOptions() {\n assertValidStrapi(this.strapi);\n if (!this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n this.#reportInfo('deleting record ');\n return restore.deleteRecords(this.strapi, this.options.restore);\n }\n\n async #deleteAllAssets(trx?: Knex.Transaction) {\n assertValidStrapi(this.strapi);\n this.#reportInfo('deleting all assets');\n // if we're not restoring files, don't touch the files\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n const stream: Readable = this.strapi.db\n // Create a query builder instance (default type is 'select')\n .queryBuilder('plugin::upload.file')\n // Fetch all columns\n .select('*')\n // Attach the transaction\n .transacting(trx)\n // Get a readable stream\n .stream();\n\n // TODO use bulk delete when exists in providers\n for await (const file of stream) {\n await this.strapi.plugin('upload').provider.delete(file);\n if (file.formats) {\n for (const fileFormat of Object.values(file.formats)) {\n await this.strapi.plugin('upload').provider.delete(fileFormat);\n }\n }\n }\n\n this.#reportInfo('deleted all assets');\n }\n\n async rollback() {\n this.#reportInfo('Rolling back transaction');\n await this.transaction?.rollback();\n this.#reportInfo('Rolled back transaction');\n }\n\n async beforeTransfer() {\n if (!this.strapi) {\n throw new Error('Strapi instance not found');\n }\n\n this.options.onTransferPhase?.('Local: preparing destination for restore…');\n\n await this.transaction?.attach(async (trx) => {\n try {\n if (this.options.strategy === 'restore') {\n if (this.#areAssetsIncluded()) {\n this.options.onTransferPhase?.('Local: backing up existing upload folder…');\n }\n await this.#handleAssetsBackup();\n if (this.#areAssetsIncluded()) {\n this.options.onTransferPhase?.('Local: deleting existing media files from disk…');\n }\n await this.#deleteAllAssets(trx);\n this.options.onTransferPhase?.('Local: clearing database content for restore…');\n await this.#deleteFromRestoreOptions();\n }\n } catch (error) {\n throw new Error(`restore failed ${error}`);\n }\n });\n }\n\n getMetadata(): IMetadata {\n this.#reportInfo('getting metadata');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n const strapiVersion = this.strapi.config.get<string>('info.strapi');\n const createdAt = new Date().toISOString();\n\n return {\n createdAt,\n strapi: {\n version: strapiVersion,\n },\n };\n }\n\n getSchemas(): Record<string, Struct.Schema> {\n this.#reportInfo('getting schema');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n\n const schemas = utils.schema.schemasToValidJSON({\n ...this.strapi.contentTypes,\n ...this.strapi.components,\n });\n\n return utils.schema.mapSchemasValues(schemas);\n }\n\n createEntitiesWriteStream(): Writable {\n assertValidStrapi(this.strapi, 'Not able to import entities');\n this.#reportInfo('creating entities stream');\n const { strategy } = this.options;\n\n const updateMappingTable = (type: string, oldID: number, newID: number) => {\n if (!this.#entitiesMapper[type]) {\n this.#entitiesMapper[type] = {};\n }\n\n Object.assign(this.#entitiesMapper[type], { [oldID]: newID });\n };\n\n if (strategy === 'restore') {\n return restore.createEntitiesWriteStream({\n strapi: this.strapi,\n updateMappingTable,\n transaction: this.transaction,\n });\n }\n\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async #handleAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to create the assets backup');\n\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('creating assets backup directory');\n const assetsDirectory = path.join(this.strapi.dirs.static.public, 'uploads');\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n\n try {\n // Check access before attempting to do anything\n await fse.access(\n assetsDirectory,\n // eslint-disable-next-line no-bitwise\n fse.constants.W_OK | fse.constants.R_OK | fse.constants.F_OK\n );\n // eslint-disable-next-line no-bitwise\n await fse.access(path.join(assetsDirectory, '..'), fse.constants.W_OK | fse.constants.R_OK);\n\n await fse.move(assetsDirectory, backupDirectory);\n await fse.mkdir(assetsDirectory);\n // Create a .gitkeep file to ensure the directory is not empty\n await fse.outputFile(path.join(assetsDirectory, '.gitkeep'), '');\n this.#reportInfo(`created assets backup directory ${backupDirectory}`);\n } catch (err) {\n throw new ProviderTransferError(\n 'The backup folder for the assets could not be created inside the public folder. Please ensure Strapi has write permissions on the public directory',\n {\n code: 'ASSETS_DIRECTORY_ERR',\n }\n );\n }\n return backupDirectory;\n }\n }\n\n async #removeAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to remove Assets');\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n // TODO: this should catch all thrown errors and bubble it up to engine so it can be reported as a non-fatal diagnostic message telling the user they may need to manually delete assets\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('removing assets backup');\n assertValidStrapi(this.strapi);\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n await fse.rm(backupDirectory, { recursive: true, force: true });\n this.#reportInfo('successfully removed assets backup');\n }\n }\n\n // TODO: Move this logic to the restore strategy\n async createAssetsWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Assets');\n this.#reportInfo('creating assets write stream');\n if (!this.#areAssetsIncluded()) {\n throw new ProviderTransferError(\n 'Attempting to transfer assets when `assets` is not set in restore options'\n );\n }\n\n const fileEntitiesMapper = this.#entitiesMapper['plugin::upload.file'];\n\n return createAssetsDestinationWritable({\n strapi: this.strapi,\n transaction: this.transaction!,\n resolveUploadFileId: (metadata) => fileEntitiesMapper?.[metadata.id],\n restoreMediaEntitiesContent: this.#isContentTypeIncluded('plugin::upload.file'),\n removeAssetsBackup: this.#removeAssetsBackup.bind(this),\n });\n }\n\n async createConfigurationWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Configurations');\n this.#reportInfo('creating configuration write stream');\n const { strategy } = this.options;\n\n if (strategy === 'restore') {\n return restore.createConfigurationWriteStream(this.strapi, this.transaction);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async createLinksWriteStream(): Promise<Writable> {\n this.#reportInfo('creating links write stream');\n if (!this.strapi) {\n throw new Error('Not able to stream links. Strapi instance not found');\n }\n\n const { strategy } = this.options;\n const mapID = (uid: string, id: number): number | undefined => this.#entitiesMapper[uid]?.[id];\n\n if (strategy === 'restore') {\n return restore.createLinksWriteStream(mapID, this.strapi, this.transaction, this.onWarning);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n}\n\nexport const createLocalStrapiDestinationProvider = (\n options: ILocalStrapiDestinationProviderOptions\n) => {\n return new LocalStrapiDestinationProvider(options);\n};\n"],"names":["VALID_CONFLICT_STRATEGIES","DEFAULT_CONFLICT_STRATEGY","LocalStrapiDestinationProvider","bootstrap","diagnostics","strapi","options","getStrapi","ProviderInitializationError","db","lifecycles","disable","transaction","utils","close","autoDestroy","assertValidStrapi","end","enable","undefined","destroy","rollback","beforeTransfer","Error","onTransferPhase","attach","trx","strategy","error","getMetadata","strapiVersion","config","get","createdAt","Date","toISOString","version","getSchemas","schemas","contentTypes","components","createEntitiesWriteStream","updateMappingTable","type","oldID","newID","Object","assign","restore","ProviderValidationError","check","validStrategies","createAssetsWriteStream","ProviderTransferError","fileEntitiesMapper","createAssetsDestinationWritable","resolveUploadFileId","metadata","id","restoreMediaEntitiesContent","removeAssetsBackup","bind","createConfigurationWriteStream","createLinksWriteStream","mapID","uid","onWarning","name","assets","notIncluded","entities","include","includes","excluded","exclude","uploadsBackupDirectoryName","now","message","report","details","origin","kind","stream","queryBuilder","select","transacting","file","plugin","provider","delete","formats","fileFormat","values","assetsDirectory","path","join","dirs","static","public","backupDirectory","fse","access","constants","W_OK","R_OK","F_OK","move","mkdir","outputFile","err","code","rm","recursive","force","createLocalStrapiDestinationProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAkBaA,yBAAAA,GAA4B;AAAC,IAAA;;AACnC,MAAMC,4BAA4B;IA2BvC,YAAA,iBAAA,8BAAA,CAAA,cAAA,CAAA;;AAIC,MACD;AAoBA,kBAAA,iBAAA,8BAAA,CAAA,oBAAA,CAAA,EAIA,sBAAA,iBAAA,8BAAA,CAAA,wBAAA,CAAA,EAWA,WAAA,iBAAA,8BAAA,CAAA,aAAA,CAAA,EAsBA,gBAAA,iBAAA,8BAAA,CAAA,kBAAA,CAAA,EAgBM,yBAAA,iBAAA,8BAAA,CAAA,2BAAA,CAAA,EASA,qFAsHA,mBAAA,iBAAA,8BAAA,CAAA,qBAAA,CAAA,EA2CA,mBAAA,iBAAA,8BAAA,CAAA,qBAAA,CAAA;AAvQR,MAAMC,8BAAAA,CAAAA;IA4BJ,MAAMC,SAAAA,CAAUC,WAAiC,EAAiB;QAChE,+BAAA,CAAA,IAAI,EAAC,YAAA,CAAA,CAAA,YAAA,CAAA,GAAeA,WAAAA;QACpB,+BAAA,CAAA,IAAI,EAAC,gBAAA,CAAA,CAAA,gBAAA,CAAA,EAAA;QACL,IAAI,CAACC,MAAM,GAAG,MAAM,IAAI,CAACC,OAAO,CAACC,SAAS,EAAA;AAC1C,QAAA,IAAI,CAAC,IAAI,CAACF,MAAM,EAAE;AAChB,YAAA,MAAM,IAAIG,qCAAAA,CAA4B,+BAAA,CAAA;AACxC,QAAA;AACA,QAAA,IAAI,CAACH,MAAM,CA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AAM,CAAC2F,IAAI,CAACC,MAAM,CAACC,MAAM,EAC9B,IAAI,CAACvB,0BAA0B,CAAA;QAEjC,MAAMyB,aAAAA,CAAIW,EAAE,CAACZ,eAAAA,EAAiB;YAAEa,SAAAA,EAAW,IAAA;YAAMC,KAAAA,EAAO;AAAK,SAAA,CAAA;QAC7D,+BAAA,CAAA,IAAI,EAAC,WAAA,CAAA,CAAA,WAAA,CAAA,CAAY,oCAAA,CAAA;AACnB,IAAA;AACF;AA4DK,MAAMC,uCAAuC,CAClD5G,OAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIJ,8BAAAA,CAA+BI,OAAAA,CAAAA;AAC5C;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/strapi/providers/local-destination/index.ts"],"sourcesContent":["import { Writable, Readable } from 'stream';\nimport path from 'path';\nimport * as fse from 'fs-extra';\nimport type { Knex } from 'knex';\nimport type { Core, Struct } from '@strapi/types';\nimport type { IDestinationProvider, IMetadata, ProviderType, Transaction } from '../../../types';\nimport type { IDiagnosticReporter } from '../../../utils/diagnostic';\n\nimport { createAssetsDestinationWritable } from './assets-destination-writable';\nimport { restore } from './strategies';\nimport * as utils from '../../../utils';\nimport {\n ProviderInitializationError,\n ProviderTransferError,\n ProviderValidationError,\n} from '../../../errors/providers';\nimport { assertValidStrapi } from '../../../utils/providers';\n\nexport const VALID_CONFLICT_STRATEGIES = ['restore'];\nexport const DEFAULT_CONFLICT_STRATEGY = 'restore';\n\nexport interface ILocalStrapiDestinationProviderOptions {\n getStrapi(): Core.Strapi | Promise<Core.Strapi>; // return an initialized instance of Strapi\n\n autoDestroy?: boolean; // shut down the instance returned by getStrapi() at the end of the transfer\n restore?: restore.IRestoreOptions; // erase data in strapi database before transfer; required if strategy is 'restore'\n strategy: 'restore'; // conflict management strategy; only the restore strategy is available at this time\n /** CLI / UI: human-readable progress during {@link beforeTransfer} (restore prep). */\n onTransferPhase?: (message: string) => void;\n}\n\nclass LocalStrapiDestinationProvider implements IDestinationProvider {\n name = 'destination::local-strapi';\n\n type: ProviderType = 'destination';\n\n options: ILocalStrapiDestinationProviderOptions;\n\n strapi?: Core.Strapi;\n\n transaction?: Transaction;\n\n uploadsBackupDirectoryName: string;\n\n onWarning?: ((message: string) => void) | undefined;\n\n #diagnostics?: IDiagnosticReporter;\n\n /**\n * The entities mapper is used to map old entities to their new IDs\n */\n #entitiesMapper: { [type: string]: { [id: number]: number } };\n\n constructor(options: ILocalStrapiDestinationProviderOptions) {\n this.options = options;\n this.#entitiesMapper = {};\n this.uploadsBackupDirectoryName = `uploads_backup_${Date.now()}`;\n }\n\n async bootstrap(diagnostics?: IDiagnosticReporter): Promise<void> {\n this.#diagnostics = diagnostics;\n this.#validateOptions();\n this.strapi = await this.options.getStrapi();\n if (!this.strapi) {\n throw new ProviderInitializationError('Could not access local strapi');\n }\n this.strapi.db.lifecycles.disable();\n this.transaction = utils.transaction.createTransaction(this.strapi);\n }\n\n // TODO: either move this to restore strategy, or restore strategy should given access to these instead of repeating the logic possibly in a different way\n #areAssetsIncluded = () => {\n return this.options.restore?.assets;\n };\n\n #isContentTypeIncluded = (type: string) => {\n const notIncluded =\n this.options.restore?.entities?.include &&\n !this.options.restore?.entities?.include?.includes(type);\n const excluded =\n this.options.restore?.entities?.exclude &&\n this.options.restore?.entities.exclude.includes(type);\n\n return !excluded && !notIncluded;\n };\n\n #reportInfo(message: string) {\n this.#diagnostics?.report({\n details: {\n createdAt: new Date(),\n message,\n origin: 'local-destination-provider',\n },\n kind: 'info',\n });\n }\n\n async close(): Promise<void> {\n const { autoDestroy } = this.options;\n assertValidStrapi(this.strapi);\n this.transaction?.end();\n this.strapi.db.lifecycles.enable();\n // Basically `!== false` but more deterministic\n if (autoDestroy === undefined || autoDestroy === true) {\n await this.strapi?.destroy();\n }\n }\n\n #validateOptions() {\n this.#reportInfo('validating options');\n if (!VALID_CONFLICT_STRATEGIES.includes(this.options.strategy)) {\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n // require restore options when using restore\n if (this.options.strategy === 'restore' && !this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n }\n\n async #deleteFromRestoreOptions() {\n assertValidStrapi(this.strapi);\n if (!this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n this.#reportInfo('deleting record ');\n return restore.deleteRecords(this.strapi, this.options.restore);\n }\n\n async #deleteAllAssets(trx?: Knex.Transaction) {\n assertValidStrapi(this.strapi);\n this.#reportInfo('deleting all assets');\n // if we're not restoring files, don't touch the files\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n const stream: Readable = this.strapi.db\n // Create a query builder instance (default type is 'select')\n .queryBuilder('plugin::upload.file')\n // Fetch all columns\n .select('*')\n // Attach the transaction\n .transacting(trx)\n // Get a readable stream\n .stream();\n\n // TODO use bulk delete when exists in providers\n for await (const file of stream) {\n await this.strapi.plugin('upload').provider.delete(file);\n if (file.formats) {\n for (const fileFormat of Object.values(file.formats)) {\n await this.strapi.plugin('upload').provider.delete(fileFormat);\n }\n }\n }\n\n this.#reportInfo('deleted all assets');\n }\n\n async rollback() {\n this.#reportInfo('Rolling back transaction');\n await this.transaction?.rollback();\n this.#reportInfo('Rolled back transaction');\n }\n\n async beforeTransfer() {\n if (!this.strapi) {\n throw new Error('Strapi instance not found');\n }\n\n this.options.onTransferPhase?.('Local: preparing destination for restore…');\n\n await this.transaction?.attach(async (trx) => {\n try {\n if (this.options.strategy === 'restore') {\n if (this.#areAssetsIncluded()) {\n this.options.onTransferPhase?.('Local: backing up existing upload folder…');\n }\n await this.#handleAssetsBackup();\n if (this.#areAssetsIncluded()) {\n this.options.onTransferPhase?.('Local: deleting existing media files from disk…');\n }\n await this.#deleteAllAssets(trx);\n this.options.onTransferPhase?.('Local: clearing database content for restore…');\n await this.#deleteFromRestoreOptions();\n }\n } catch (error) {\n throw new Error(`restore failed ${error}`);\n }\n });\n }\n\n getMetadata(): IMetadata {\n this.#reportInfo('getting metadata');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n const strapiVersion = this.strapi.config.get<string>('info.strapi');\n const createdAt = new Date().toISOString();\n\n return {\n createdAt,\n strapi: {\n version: strapiVersion,\n },\n };\n }\n\n getSchemas(): Record<string, Struct.Schema> {\n this.#reportInfo('getting schema');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n\n const schemas = utils.schema.schemasToValidJSON({\n ...this.strapi.contentTypes,\n ...this.strapi.components,\n });\n\n return utils.schema.mapSchemasValues(schemas);\n }\n\n createEntitiesWriteStream(): Writable {\n assertValidStrapi(this.strapi, 'Not able to import entities');\n this.#reportInfo('creating entities stream');\n const { strategy } = this.options;\n\n const updateMappingTable = (type: string, oldID: number, newID: number) => {\n if (!this.#entitiesMapper[type]) {\n this.#entitiesMapper[type] = {};\n }\n\n Object.assign(this.#entitiesMapper[type], { [oldID]: newID });\n };\n\n if (strategy === 'restore') {\n return restore.createEntitiesWriteStream({\n strapi: this.strapi,\n updateMappingTable,\n transaction: this.transaction,\n });\n }\n\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async #handleAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to create the assets backup');\n\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('creating assets backup directory');\n const assetsDirectory = path.join(this.strapi.dirs.static.public, 'uploads');\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n\n try {\n // Check access before attempting to do anything\n await fse.access(\n assetsDirectory,\n // eslint-disable-next-line no-bitwise\n fse.constants.W_OK | fse.constants.R_OK | fse.constants.F_OK\n );\n // eslint-disable-next-line no-bitwise\n await fse.access(path.join(assetsDirectory, '..'), fse.constants.W_OK | fse.constants.R_OK);\n\n await fse.move(assetsDirectory, backupDirectory);\n await fse.mkdir(assetsDirectory);\n // Create a .gitkeep file to ensure the directory is not empty\n await fse.outputFile(path.join(assetsDirectory, '.gitkeep'), '');\n this.#reportInfo(`created assets backup directory ${backupDirectory}`);\n } catch (err) {\n throw new ProviderTransferError(\n 'The backup folder for the assets could not be created inside the public folder. Please ensure Strapi has write permissions on the public directory',\n {\n code: 'ASSETS_DIRECTORY_ERR',\n }\n );\n }\n return backupDirectory;\n }\n }\n\n async #removeAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to remove Assets');\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n // TODO: this should catch all thrown errors and bubble it up to engine so it can be reported as a non-fatal diagnostic message telling the user they may need to manually delete assets\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('removing assets backup');\n assertValidStrapi(this.strapi);\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n await fse.rm(backupDirectory, { recursive: true, force: true });\n this.#reportInfo('successfully removed assets backup');\n }\n }\n\n // TODO: Move this logic to the restore strategy\n async createAssetsWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Assets');\n this.#reportInfo('creating assets write stream');\n if (!this.#areAssetsIncluded()) {\n throw new ProviderTransferError(\n 'Attempting to transfer assets when `assets` is not set in restore options'\n );\n }\n\n const fileEntitiesMapper = this.#entitiesMapper['plugin::upload.file'];\n\n return createAssetsDestinationWritable({\n strapi: this.strapi,\n transaction: this.transaction!,\n resolveUploadFileId: (metadata) => fileEntitiesMapper?.[metadata.id],\n restoreMediaEntitiesContent: this.#isContentTypeIncluded('plugin::upload.file'),\n removeAssetsBackup: this.#removeAssetsBackup.bind(this),\n });\n }\n\n async createConfigurationWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Configurations');\n this.#reportInfo('creating configuration write stream');\n const { strategy } = this.options;\n\n if (strategy === 'restore') {\n return restore.createConfigurationWriteStream(this.strapi, this.transaction);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async createLinksWriteStream(): Promise<Writable> {\n this.#reportInfo('creating links write stream');\n if (!this.strapi) {\n throw new Error('Not able to stream links. Strapi instance not found');\n }\n\n const { strategy } = this.options;\n const mapID = (uid: string, id: number): number | undefined => this.#entitiesMapper[uid]?.[id];\n\n if (strategy === 'restore') {\n return restore.createLinksWriteStream(mapID, this.strapi, this.transaction, this.onWarning);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n}\n\nexport const createLocalStrapiDestinationProvider = (\n options: ILocalStrapiDestinationProviderOptions\n) => {\n return new LocalStrapiDestinationProvider(options);\n};\n"],"names":["VALID_CONFLICT_STRATEGIES","DEFAULT_CONFLICT_STRATEGY","LocalStrapiDestinationProvider","bootstrap","diagnostics","strapi","options","getStrapi","ProviderInitializationError","db","lifecycles","disable","transaction","utils","close","autoDestroy","assertValidStrapi","end","enable","undefined","destroy","rollback","beforeTransfer","Error","onTransferPhase","attach","trx","strategy","error","getMetadata","strapiVersion","config","get","createdAt","Date","toISOString","version","getSchemas","schemas","contentTypes","components","createEntitiesWriteStream","updateMappingTable","type","oldID","newID","Object","assign","restore","ProviderValidationError","check","validStrategies","createAssetsWriteStream","ProviderTransferError","fileEntitiesMapper","createAssetsDestinationWritable","resolveUploadFileId","metadata","id","restoreMediaEntitiesContent","removeAssetsBackup","bind","createConfigurationWriteStream","createLinksWriteStream","mapID","uid","onWarning","name","assets","notIncluded","entities","include","includes","excluded","exclude","uploadsBackupDirectoryName","now","message","report","details","origin","kind","stream","queryBuilder","select","transacting","file","plugin","provider","delete","formats","fileFormat","values","assetsDirectory","path","join","dirs","static","public","backupDirectory","fse","access","constants","W_OK","R_OK","F_OK","move","mkdir","outputFile","err","code","rm","recursive","force","createLocalStrapiDestinationProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAkBaA,yBAAAA,GAA4B;AAAC,IAAA;;AACnC,MAAMC,4BAA4B;IA2BvC,YAAA,iBAAA,8BAAA,CAAA,cAAA,CAAA;;AAIC,MACD;AAoBA,kBAAA,iBAAA,8BAAA,CAAA,oBAAA,CAAA,EAIA,sBAAA,iBAAA,8BAAA,CAAA,wBAAA,CAAA,EAWA,WAAA,iBAAA,8BAAA,CAAA,aAAA,CAAA,EAsBA,gBAAA,iBAAA,8BAAA,CAAA,kBAAA,CAAA,EAgBM,yBAAA,iBAAA,8BAAA,CAAA,2BAAA,CAAA,EASA,qFAsHA,mBAAA,iBAAA,8BAAA,CAAA,qBAAA,CAAA,EA2CA,mBAAA,iBAAA,8BAAA,CAAA,qBAAA,CAAA;AAvQR,MAAMC,8BAAAA,CAAAA;IA4BJ,MAAMC,SAAAA,CAAUC,WAAiC,EAAiB;QAChE,+BAAA,CAAA,IAAI,EAAC,YAAA,CAAA,CAAA,YAAA,CAAA,GAAeA,WAAAA;QACpB,+BAAA,CAAA,IAAI,EAAC,gBAAA,CAAA,CAAA,gBAAA,CAAA,EAAA;QACL,IAAI,CAACC,MAAM,GAAG,MAAM,IAAI,CAACC,OAAO,CAACC,SAAS,EAAA;AAC1C,QAAA,IAAI,CAAC,IAAI,CAACF,MAAM,EAAE;AAChB,YAAA,MAAM,IAAIG,qCAAAA,CAA4B,+BAAA,CAAA;AACxC,QAAA;AACA,QAAA,IAAI,CAACH,MAAM,CAACI,EAAE,CAACC,UAAU,CAACC,OAAO,EAAA;QACjC,IAAI,CAACC,WAAW,GAAGC,6BAAmC,CAAC,IAAI,CAACR,MAAM,CAAA;AACpE,IAAA;AA6BA,IAAA,MAAMS,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YAAEa,SAAAA,EAAW,IAAA;YAAMC,KAAAA,EAAO;AAAK,SAAA,CAAA;QAC7D,+BAAA,CAAA,IAAI,EAAC,WAAA,CAAA,CAAA,WAAA,CAAA,CAAY,oCAAA,CAAA;AACnB,IAAA;AACF;AA4DK,MAAMC,uCAAuC,CAClD5G,OAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIJ,8BAAAA,CAA+BI,OAAAA,CAAAA;AAC5C;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../src/strapi/providers/local-destination/index.ts"],"sourcesContent":["import { Writable, Readable } from 'stream';\nimport path from 'path';\nimport * as fse from 'fs-extra';\nimport type { Knex } from 'knex';\nimport type { Core, Struct } from '@strapi/types';\nimport type { IDestinationProvider, IMetadata, ProviderType, Transaction } from '../../../../types';\nimport type { IDiagnosticReporter } from '../../../utils/diagnostic';\n\nimport { createAssetsDestinationWritable } from './assets-destination-writable';\nimport { restore } from './strategies';\nimport * as utils from '../../../utils';\nimport {\n ProviderInitializationError,\n ProviderTransferError,\n ProviderValidationError,\n} from '../../../errors/providers';\nimport { assertValidStrapi } from '../../../utils/providers';\n\nexport const VALID_CONFLICT_STRATEGIES = ['restore'];\nexport const DEFAULT_CONFLICT_STRATEGY = 'restore';\n\nexport interface ILocalStrapiDestinationProviderOptions {\n getStrapi(): Core.Strapi | Promise<Core.Strapi>; // return an initialized instance of Strapi\n\n autoDestroy?: boolean; // shut down the instance returned by getStrapi() at the end of the transfer\n restore?: restore.IRestoreOptions; // erase data in strapi database before transfer; required if strategy is 'restore'\n strategy: 'restore'; // conflict management strategy; only the restore strategy is available at this time\n /** CLI / UI: human-readable progress during {@link beforeTransfer} (restore prep). */\n onTransferPhase?: (message: string) => void;\n}\n\nclass LocalStrapiDestinationProvider implements IDestinationProvider {\n name = 'destination::local-strapi';\n\n type: ProviderType = 'destination';\n\n options: ILocalStrapiDestinationProviderOptions;\n\n strapi?: Core.Strapi;\n\n transaction?: Transaction;\n\n uploadsBackupDirectoryName: string;\n\n onWarning?: ((message: string) => void) | undefined;\n\n #diagnostics?: IDiagnosticReporter;\n\n /**\n * The entities mapper is used to map old entities to their new IDs\n */\n #entitiesMapper: { [type: string]: { [id: number]: number } };\n\n constructor(options: ILocalStrapiDestinationProviderOptions) {\n this.options = options;\n this.#entitiesMapper = {};\n this.uploadsBackupDirectoryName = `uploads_backup_${Date.now()}`;\n }\n\n async bootstrap(diagnostics?: IDiagnosticReporter): Promise<void> {\n this.#diagnostics = diagnostics;\n this.#validateOptions();\n this.strapi = await this.options.getStrapi();\n if (!this.strapi) {\n throw new ProviderInitializationError('Could not access local strapi');\n }\n this.strapi.db.lifecycles.disable();\n this.transaction = utils.transaction.createTransaction(this.strapi);\n }\n\n // TODO: either move this to restore strategy, or restore strategy should given access to these instead of repeating the logic possibly in a different way\n #areAssetsIncluded = () => {\n return this.options.restore?.assets;\n };\n\n #isContentTypeIncluded = (type: string) => {\n const notIncluded =\n this.options.restore?.entities?.include &&\n !this.options.restore?.entities?.include?.includes(type);\n const excluded =\n this.options.restore?.entities?.exclude &&\n this.options.restore?.entities.exclude.includes(type);\n\n return !excluded && !notIncluded;\n };\n\n #reportInfo(message: string) {\n this.#diagnostics?.report({\n details: {\n createdAt: new Date(),\n message,\n origin: 'local-destination-provider',\n },\n kind: 'info',\n });\n }\n\n async close(): Promise<void> {\n const { autoDestroy } = this.options;\n assertValidStrapi(this.strapi);\n this.transaction?.end();\n this.strapi.db.lifecycles.enable();\n // Basically `!== false` but more deterministic\n if (autoDestroy === undefined || autoDestroy === true) {\n await this.strapi?.destroy();\n }\n }\n\n #validateOptions() {\n this.#reportInfo('validating options');\n if (!VALID_CONFLICT_STRATEGIES.includes(this.options.strategy)) {\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n // require restore options when using restore\n if (this.options.strategy === 'restore' && !this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n }\n\n async #deleteFromRestoreOptions() {\n assertValidStrapi(this.strapi);\n if (!this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n this.#reportInfo('deleting record ');\n return restore.deleteRecords(this.strapi, this.options.restore);\n }\n\n async #deleteAllAssets(trx?: Knex.Transaction) {\n assertValidStrapi(this.strapi);\n this.#reportInfo('deleting all assets');\n // if we're not restoring files, don't touch the files\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n const stream: Readable = this.strapi.db\n // Create a query builder instance (default type is 'select')\n .queryBuilder('plugin::upload.file')\n // Fetch all columns\n .select('*')\n // Attach the transaction\n .transacting(trx)\n // Get a readable stream\n .stream();\n\n // TODO use bulk delete when exists in providers\n for await (const file of stream) {\n await this.strapi.plugin('upload').provider.delete(file);\n if (file.formats) {\n for (const fileFormat of Object.values(file.formats)) {\n await this.strapi.plugin('upload').provider.delete(fileFormat);\n }\n }\n }\n\n this.#reportInfo('deleted all assets');\n }\n\n async rollback() {\n this.#reportInfo('Rolling back transaction');\n await this.transaction?.rollback();\n this.#reportInfo('Rolled back transaction');\n }\n\n async beforeTransfer() {\n if (!this.strapi) {\n throw new Error('Strapi instance not found');\n }\n\n this.options.onTransferPhase?.('Local: preparing destination for restore…');\n\n await this.transaction?.attach(async (trx) => {\n try {\n if (this.options.strategy === 'restore') {\n if (this.#areAssetsIncluded()) {\n this.options.onTransferPhase?.('Local: backing up existing upload folder…');\n }\n await this.#handleAssetsBackup();\n if (this.#areAssetsIncluded()) {\n this.options.onTransferPhase?.('Local: deleting existing media files from disk…');\n }\n await this.#deleteAllAssets(trx);\n this.options.onTransferPhase?.('Local: clearing database content for restore…');\n await this.#deleteFromRestoreOptions();\n }\n } catch (error) {\n throw new Error(`restore failed ${error}`);\n }\n });\n }\n\n getMetadata(): IMetadata {\n this.#reportInfo('getting metadata');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n const strapiVersion = this.strapi.config.get<string>('info.strapi');\n const createdAt = new Date().toISOString();\n\n return {\n createdAt,\n strapi: {\n version: strapiVersion,\n },\n };\n }\n\n getSchemas(): Record<string, Struct.Schema> {\n this.#reportInfo('getting schema');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n\n const schemas = utils.schema.schemasToValidJSON({\n ...this.strapi.contentTypes,\n ...this.strapi.components,\n });\n\n return utils.schema.mapSchemasValues(schemas);\n }\n\n createEntitiesWriteStream(): Writable {\n assertValidStrapi(this.strapi, 'Not able to import entities');\n this.#reportInfo('creating entities stream');\n const { strategy } = this.options;\n\n const updateMappingTable = (type: string, oldID: number, newID: number) => {\n if (!this.#entitiesMapper[type]) {\n this.#entitiesMapper[type] = {};\n }\n\n Object.assign(this.#entitiesMapper[type], { [oldID]: newID });\n };\n\n if (strategy === 'restore') {\n return restore.createEntitiesWriteStream({\n strapi: this.strapi,\n updateMappingTable,\n transaction: this.transaction,\n });\n }\n\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async #handleAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to create the assets backup');\n\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('creating assets backup directory');\n const assetsDirectory = path.join(this.strapi.dirs.static.public, 'uploads');\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n\n try {\n // Check access before attempting to do anything\n await fse.access(\n assetsDirectory,\n // eslint-disable-next-line no-bitwise\n fse.constants.W_OK | fse.constants.R_OK | fse.constants.F_OK\n );\n // eslint-disable-next-line no-bitwise\n await fse.access(path.join(assetsDirectory, '..'), fse.constants.W_OK | fse.constants.R_OK);\n\n await fse.move(assetsDirectory, backupDirectory);\n await fse.mkdir(assetsDirectory);\n // Create a .gitkeep file to ensure the directory is not empty\n await fse.outputFile(path.join(assetsDirectory, '.gitkeep'), '');\n this.#reportInfo(`created assets backup directory ${backupDirectory}`);\n } catch (err) {\n throw new ProviderTransferError(\n 'The backup folder for the assets could not be created inside the public folder. Please ensure Strapi has write permissions on the public directory',\n {\n code: 'ASSETS_DIRECTORY_ERR',\n }\n );\n }\n return backupDirectory;\n }\n }\n\n async #removeAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to remove Assets');\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n // TODO: this should catch all thrown errors and bubble it up to engine so it can be reported as a non-fatal diagnostic message telling the user they may need to manually delete assets\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('removing assets backup');\n assertValidStrapi(this.strapi);\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n await fse.rm(backupDirectory, { recursive: true, force: true });\n this.#reportInfo('successfully removed assets backup');\n }\n }\n\n // TODO: Move this logic to the restore strategy\n async createAssetsWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Assets');\n this.#reportInfo('creating assets write stream');\n if (!this.#areAssetsIncluded()) {\n throw new ProviderTransferError(\n 'Attempting to transfer assets when `assets` is not set in restore options'\n );\n }\n\n const fileEntitiesMapper = this.#entitiesMapper['plugin::upload.file'];\n\n return createAssetsDestinationWritable({\n strapi: this.strapi,\n transaction: this.transaction!,\n resolveUploadFileId: (metadata) => fileEntitiesMapper?.[metadata.id],\n restoreMediaEntitiesContent: this.#isContentTypeIncluded('plugin::upload.file'),\n removeAssetsBackup: this.#removeAssetsBackup.bind(this),\n });\n }\n\n async createConfigurationWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Configurations');\n this.#reportInfo('creating configuration write stream');\n const { strategy } = this.options;\n\n if (strategy === 'restore') {\n return restore.createConfigurationWriteStream(this.strapi, this.transaction);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async createLinksWriteStream(): Promise<Writable> {\n this.#reportInfo('creating links write stream');\n if (!this.strapi) {\n throw new Error('Not able to stream links. Strapi instance not found');\n }\n\n const { strategy } = this.options;\n const mapID = (uid: string, id: number): number | undefined => this.#entitiesMapper[uid]?.[id];\n\n if (strategy === 'restore') {\n return restore.createLinksWriteStream(mapID, this.strapi, this.transaction, this.onWarning);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n}\n\nexport const createLocalStrapiDestinationProvider = (\n options: ILocalStrapiDestinationProviderOptions\n) => {\n return new LocalStrapiDestinationProvider(options);\n};\n"],"names":["VALID_CONFLICT_STRATEGIES","DEFAULT_CONFLICT_STRATEGY","LocalStrapiDestinationProvider","bootstrap","diagnostics","strapi","options","getStrapi","ProviderInitializationError","db","lifecycles","disable","transaction","utils","close","autoDestroy","assertValidStrapi","end","enable","undefined","destroy","rollback","beforeTransfer","Error","onTransferPhase","attach","trx","strategy","error","getMetadata","strapiVersion","config","get","createdAt","Date","toISOString","version","getSchemas","schemas","contentTypes","components","createEntitiesWriteStream","updateMappingTable","type","oldID","newID","Object","assign","restore","ProviderValidationError","check","validStrategies","createAssetsWriteStream","ProviderTransferError","fileEntitiesMapper","createAssetsDestinationWritable","resolveUploadFileId","metadata","id","restoreMediaEntitiesContent","removeAssetsBackup","bind","createConfigurationWriteStream","createLinksWriteStream","mapID","uid","onWarning","name","assets","notIncluded","entities","include","includes","excluded","exclude","uploadsBackupDirectoryName","now","message","report","details","origin","kind","stream","queryBuilder","select","transacting","file","plugin","provider","delete","formats","fileFormat","values","assetsDirectory","path","join","dirs","static","public","backupDirectory","fse","access","constants","W_OK","R_OK","F_OK","move","mkdir","outputFile","err","code","rm","recursive","force","createLocalStrapiDestin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A;AACF;AA4DK,MAAMC,uCAAuC,CAClD5G,OAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIJ,8BAAAA,CAA+BI,OAAAA,CAAAA;AAC5C;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/strapi/providers/local-destination/index.ts"],"sourcesContent":["import { Writable, Readable } from 'stream';\nimport path from 'path';\nimport * as fse from 'fs-extra';\nimport type { Knex } from 'knex';\nimport type { Core, Struct } from '@strapi/types';\nimport type { IDestinationProvider, IMetadata, ProviderType, Transaction } from '../../../types';\nimport type { IDiagnosticReporter } from '../../../utils/diagnostic';\n\nimport { createAssetsDestinationWritable } from './assets-destination-writable';\nimport { restore } from './strategies';\nimport * as utils from '../../../utils';\nimport {\n ProviderInitializationError,\n ProviderTransferError,\n ProviderValidationError,\n} from '../../../errors/providers';\nimport { assertValidStrapi } from '../../../utils/providers';\n\nexport const VALID_CONFLICT_STRATEGIES = ['restore'];\nexport const DEFAULT_CONFLICT_STRATEGY = 'restore';\n\nexport interface ILocalStrapiDestinationProviderOptions {\n getStrapi(): Core.Strapi | Promise<Core.Strapi>; // return an initialized instance of Strapi\n\n autoDestroy?: boolean; // shut down the instance returned by getStrapi() at the end of the transfer\n restore?: restore.IRestoreOptions; // erase data in strapi database before transfer; required if strategy is 'restore'\n strategy: 'restore'; // conflict management strategy; only the restore strategy is available at this time\n /** CLI / UI: human-readable progress during {@link beforeTransfer} (restore prep). */\n onTransferPhase?: (message: string) => void;\n}\n\nclass LocalStrapiDestinationProvider implements IDestinationProvider {\n name = 'destination::local-strapi';\n\n type: ProviderType = 'destination';\n\n options: ILocalStrapiDestinationProviderOptions;\n\n strapi?: Core.Strapi;\n\n transaction?: Transaction;\n\n uploadsBackupDirectoryName: string;\n\n onWarning?: ((message: string) => void) | undefined;\n\n #diagnostics?: IDiagnosticReporter;\n\n /**\n * The entities mapper is used to map old entities to their new IDs\n */\n #entitiesMapper: { [type: string]: { [id: number]: number } };\n\n constructor(options: ILocalStrapiDestinationProviderOptions) {\n this.options = options;\n this.#entitiesMapper = {};\n this.uploadsBackupDirectoryName = `uploads_backup_${Date.now()}`;\n }\n\n async bootstrap(diagnostics?: IDiagnosticReporter): Promise<void> {\n this.#diagnostics = diagnostics;\n this.#validateOptions();\n this.strapi = await this.options.getStrapi();\n if (!this.strapi) {\n throw new ProviderInitializationError('Could not access local strapi');\n }\n this.strapi.db.lifecycles.disable();\n this.transaction = utils.transaction.createTransaction(this.strapi);\n }\n\n // TODO: either move this to restore strategy, or restore strategy should given access to these instead of repeating the logic possibly in a different way\n #areAssetsIncluded = () => {\n return this.options.restore?.assets;\n };\n\n #isContentTypeIncluded = (type: string) => {\n const notIncluded =\n this.options.restore?.entities?.include &&\n !this.options.restore?.entities?.include?.includes(type);\n const excluded =\n this.options.restore?.entities?.exclude &&\n this.options.restore?.entities.exclude.includes(type);\n\n return !excluded && !notIncluded;\n };\n\n #reportInfo(message: string) {\n this.#diagnostics?.report({\n details: {\n createdAt: new Date(),\n message,\n origin: 'local-destination-provider',\n },\n kind: 'info',\n });\n }\n\n async close(): Promise<void> {\n const { autoDestroy } = this.options;\n assertValidStrapi(this.strapi);\n this.transaction?.end();\n this.strapi.db.lifecycles.enable();\n // Basically `!== false` but more deterministic\n if (autoDestroy === undefined || autoDestroy === true) {\n await this.strapi?.destroy();\n }\n }\n\n #validateOptions() {\n this.#reportInfo('validating options');\n if (!VALID_CONFLICT_STRATEGIES.includes(this.options.strategy)) {\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n // require restore options when using restore\n if (this.options.strategy === 'restore' && !this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n }\n\n async #deleteFromRestoreOptions() {\n assertValidStrapi(this.strapi);\n if (!this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n this.#reportInfo('deleting record ');\n return restore.deleteRecords(this.strapi, this.options.restore);\n }\n\n async #deleteAllAssets(trx?: Knex.Transaction) {\n assertValidStrapi(this.strapi);\n this.#reportInfo('deleting all assets');\n // if we're not restoring files, don't touch the files\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n const stream: Readable = this.strapi.db\n // Create a query builder instance (default type is 'select')\n .queryBuilder('plugin::upload.file')\n // Fetch all columns\n .select('*')\n // Attach the transaction\n .transacting(trx)\n // Get a readable stream\n .stream();\n\n // TODO use bulk delete when exists in providers\n for await (const file of stream) {\n await this.strapi.plugin('upload').provider.delete(file);\n if (file.formats) {\n for (const fileFormat of Object.values(file.formats)) {\n await this.strapi.plugin('upload').provider.delete(fileFormat);\n }\n }\n }\n\n this.#reportInfo('deleted all assets');\n }\n\n async rollback() {\n this.#reportInfo('Rolling back transaction');\n await this.transaction?.rollback();\n this.#reportInfo('Rolled back transaction');\n }\n\n async beforeTransfer() {\n if (!this.strapi) {\n throw new Error('Strapi instance not found');\n }\n\n this.options.onTransferPhase?.('Local: preparing destination for restore…');\n\n await this.transaction?.attach(async (trx) => {\n try {\n if (this.options.strategy === 'restore') {\n if (this.#areAssetsIncluded()) {\n this.options.onTransferPhase?.('Local: backing up existing upload folder…');\n }\n await this.#handleAssetsBackup();\n if (this.#areAssetsIncluded()) {\n this.options.onTransferPhase?.('Local: deleting existing media files from disk…');\n }\n await this.#deleteAllAssets(trx);\n this.options.onTransferPhase?.('Local: clearing database content for restore…');\n await this.#deleteFromRestoreOptions();\n }\n } catch (error) {\n throw new Error(`restore failed ${error}`);\n }\n });\n }\n\n getMetadata(): IMetadata {\n this.#reportInfo('getting metadata');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n const strapiVersion = this.strapi.config.get<string>('info.strapi');\n const createdAt = new Date().toISOString();\n\n return {\n createdAt,\n strapi: {\n version: strapiVersion,\n },\n };\n }\n\n getSchemas(): Record<string, Struct.Schema> {\n this.#reportInfo('getting schema');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n\n const schemas = utils.schema.schemasToValidJSON({\n ...this.strapi.contentTypes,\n ...this.strapi.components,\n });\n\n return utils.schema.mapSchemasValues(schemas);\n }\n\n createEntitiesWriteStream(): Writable {\n assertValidStrapi(this.strapi, 'Not able to import entities');\n this.#reportInfo('creating entities stream');\n const { strategy } = this.options;\n\n const updateMappingTable = (type: string, oldID: number, newID: number) => {\n if (!this.#entitiesMapper[type]) {\n this.#entitiesMapper[type] = {};\n }\n\n Object.assign(this.#entitiesMapper[type], { [oldID]: newID });\n };\n\n if (strategy === 'restore') {\n return restore.createEntitiesWriteStream({\n strapi: this.strapi,\n updateMappingTable,\n transaction: this.transaction,\n });\n }\n\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async #handleAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to create the assets backup');\n\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('creating assets backup directory');\n const assetsDirectory = path.join(this.strapi.dirs.static.public, 'uploads');\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n\n try {\n // Check access before attempting to do anything\n await fse.access(\n assetsDirectory,\n // eslint-disable-next-line no-bitwise\n fse.constants.W_OK | fse.constants.R_OK | fse.constants.F_OK\n );\n // eslint-disable-next-line no-bitwise\n await fse.access(path.join(assetsDirectory, '..'), fse.constants.W_OK | fse.constants.R_OK);\n\n await fse.move(assetsDirectory, backupDirectory);\n await fse.mkdir(assetsDirectory);\n // Create a .gitkeep file to ensure the directory is not empty\n await fse.outputFile(path.join(assetsDirectory, '.gitkeep'), '');\n this.#reportInfo(`created assets backup directory ${backupDirectory}`);\n } catch (err) {\n throw new ProviderTransferError(\n 'The backup folder for the assets could not be created inside the public folder. Please ensure Strapi has write permissions on the public directory',\n {\n code: 'ASSETS_DIRECTORY_ERR',\n }\n );\n }\n return backupDirectory;\n }\n }\n\n async #removeAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to remove Assets');\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n // TODO: this should catch all thrown errors and bubble it up to engine so it can be reported as a non-fatal diagnostic message telling the user they may need to manually delete assets\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('removing assets backup');\n assertValidStrapi(this.strapi);\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n await fse.rm(backupDirectory, { recursive: true, force: true });\n this.#reportInfo('successfully removed assets backup');\n }\n }\n\n // TODO: Move this logic to the restore strategy\n async createAssetsWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Assets');\n this.#reportInfo('creating assets write stream');\n if (!this.#areAssetsIncluded()) {\n throw new ProviderTransferError(\n 'Attempting to transfer assets when `assets` is not set in restore options'\n );\n }\n\n const fileEntitiesMapper = this.#entitiesMapper['plugin::upload.file'];\n\n return createAssetsDestinationWritable({\n strapi: this.strapi,\n transaction: this.transaction!,\n resolveUploadFileId: (metadata) => fileEntitiesMapper?.[metadata.id],\n restoreMediaEntitiesContent: this.#isContentTypeIncluded('plugin::upload.file'),\n removeAssetsBackup: this.#removeAssetsBackup.bind(this),\n });\n }\n\n async createConfigurationWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Configurations');\n this.#reportInfo('creating configuration write stream');\n const { strategy } = this.options;\n\n if (strategy === 'restore') {\n return restore.createConfigurationWriteStream(this.strapi, this.transaction);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async createLinksWriteStream(): Promise<Writable> {\n this.#reportInfo('creating links write stream');\n if (!this.strapi) {\n throw new Error('Not able to stream links. Strapi instance not found');\n }\n\n const { strategy } = this.options;\n const mapID = (uid: string, id: number): number | undefined => this.#entitiesMapper[uid]?.[id];\n\n if (strategy === 'restore') {\n return restore.createLinksWriteStream(mapID, this.strapi, this.transaction, this.onWarning);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n}\n\nexport const createLocalStrapiDestinationProvider = (\n options: ILocalStrapiDestinationProviderOptions\n) => {\n return new LocalStrapiDestinationProvider(options);\n};\n"],"names":["VALID_CONFLICT_STRATEGIES","DEFAULT_CONFLICT_STRATEGY","LocalStrapiDestinationProvider","bootstrap","diagnostics","strapi","options","getStrapi","ProviderInitializationError","db","lifecycles","disable","transaction","utils","close","autoDestroy","assertValidStrapi","end","enable","undefined","destroy","rollback","beforeTransfer","Error","onTransferPhase","attach","trx","strategy","error","getMetadata","strapiVersion","config","get","createdAt","Date","toISOString","version","getSchemas","schemas","contentTypes","components","createEntitiesWriteStream","updateMappingTable","type","oldID","newID","Object","assign","restore","ProviderValidationError","check","validStrategies","createAssetsWriteStream","ProviderTransferError","fileEntitiesMapper","createAssetsDestinationWritable","resolveUploadFileId","metadata","id","restoreMediaEntitiesContent","removeAssetsBackup","bind","createConfigurationWriteStream","createLinksWriteStream","mapID","uid","onWarning","name","assets","notIncluded","entities","include","includes","excluded","exclude","uploadsBackupDirectoryName","now","message","report","details","origin","kind","stream","queryBuilder","select","transacting","file","plugin","provider","delete","formats","fileFormat","values","assetsDirectory","path","join","dirs","static","public","backupDirectory","fse","access","constants","W_OK","R_OK","F_OK","move","mkdir","outputFile","err","code","rm","recursive","force","createLocalStrapiDestinationProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;MAkBaA,yBAAAA,GAA4B;AAAC,IAAA;;AACnC,MAAMC,4BAA4B;IA2BvC,YAAA,iBAAA,8BAAA,CAAA,cAAA,CAAA;;AAIC,MACD;AAoBA,k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writable } from 'stream';
3
3
  import type { Core } from '@strapi/types';
4
- import { IConfiguration, Transaction } from '../../../../../../types';
4
+ import { IConfiguration, Transaction } from '../../../../../types';
5
5
  export declare const restoreConfigs: (strapi: Core.Strapi, config: IConfiguration) => Promise<any>;
6
6
  export declare const createConfigurationWriteStream: (strapi: Core.Strapi, transaction?: Transaction) => Promise<Writable>;
7
7
  //# sourceMappingURL=configuration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/configuration.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAmBtE,eAAO,MAAM,cAAc,WAAkB,KAAK,MAAM,UAAU,cAAc,iBAQ/E,CAAC;AAEF,eAAO,MAAM,8BAA8B,WACjC,KAAK,MAAM,gBACL,WAAW,sBAyB1B,CAAC"}
1
+ {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/configuration.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAyBnE,eAAO,MAAM,cAAc,WAAkB,KAAK,MAAM,UAAU,cAAc,iBAQ/E,CAAC;AAEF,eAAO,MAAM,8BAA8B,WACjC,KAAK,MAAM,gBACL,WAAW,sBAyB1B,CAAC"}
@@ -4,16 +4,22 @@ var stream = require('stream');
4
4
  var fp = require('lodash/fp');
5
5
  var chalk = require('chalk');
6
6
  var providers = require('../../../../../errors/providers.js');
7
+ var projectSettingsLogos = require('../../../../utils/project-settings-logos.js');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
7
12
 
8
13
  const omitInvalidCreationAttributes = fp.omit([
9
14
  'id'
10
15
  ]);
11
16
  const restoreCoreStore = async (strapi, values)=>{
12
17
  const data = omitInvalidCreationAttributes(values);
18
+ const row = await projectSettingsLogos.restoreProjectSettingsRow(strapi, data);
13
19
  return strapi.db.query('strapi::core-store').create({
14
20
  data: {
15
- ...data,
16
- value: JSON.stringify(data.value)
21
+ ...row,
22
+ value: JSON.stringify(row.value)
17
23
  }
18
24
  });
19
25
  };
@@ -39,7 +45,7 @@ const createConfigurationWriteStream = async (strapi, transaction)=>{
39
45
  try {
40
46
  await restoreConfigs(strapi, config);
41
47
  } catch (error) {
42
- return callback(new providers.ProviderTransferError(`Failed to import ${chalk.yellowBright(config.type)} (${chalk.greenBright(config.value.id)}`));
48
+ return callback(new providers.ProviderTransferError(`Failed to import ${chalk__default.default.yellowBright(config.type)} (${chalk__default.default.greenBright(config.value.id)}`));
43
49
  }
44
50
  callback();
45
51
  });
@@ -1 +1 @@
1
- {"version":3,"file":"configuration.js","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/configuration.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport { omit } from 'lodash/fp';\nimport chalk from 'chalk';\nimport type { Core } from '@strapi/types';\nimport { ProviderTransferError } from '../../../../../errors/providers';\nimport { IConfiguration, Transaction } from '../../../../../../types';\n\nconst omitInvalidCreationAttributes = omit(['id']);\n\nconst restoreCoreStore = async <T extends { value: unknown }>(strapi: Core.Strapi, values: T) => {\n const data = omitInvalidCreationAttributes(values);\n return strapi.db.query('strapi::core-store').create({\n data: {\n ...data,\n value: JSON.stringify(data.value),\n },\n });\n};\n\nconst restoreWebhooks = async <T extends { value: unknown }>(strapi: Core.Strapi, values: T) => {\n const data = omitInvalidCreationAttributes(values);\n return strapi.db.query('strapi::webhook').create({ data });\n};\n\nexport const restoreConfigs = async (strapi: Core.Strapi, config: IConfiguration) => {\n if (config.type === 'core-store') {\n return restoreCoreStore(strapi, config.value as { value: unknown });\n }\n\n if (config.type === 'webhook') {\n return restoreWebhooks(strapi, config.value as { value: unknown });\n }\n};\n\nexport const createConfigurationWriteStream = async (\n strapi: Core.Strapi,\n transaction?: Transaction\n) => {\n return new Writable({\n objectMode: true,\n async write<T extends { id: number }>(\n config: IConfiguration<T>,\n _encoding: BufferEncoding,\n callback: (error?: Error | null) => void\n ) {\n await transaction?.attach(async () => {\n try {\n await restoreConfigs(strapi, config);\n } catch (error) {\n return callback(\n new ProviderTransferError(\n `Failed to import ${chalk.yellowBright(config.type)} (${chalk.greenBright(\n config.value.id\n )}`\n )\n );\n }\n callback();\n });\n },\n });\n};\n"],"names":["omitInvalidCreationAttributes","omit","restoreCoreStore","strapi","values","data","db","query","create","value","JSON","stringify","restoreWebhooks","restoreConfigs","config","type","createConfigurationWriteStream","transaction","Writable","objectMode","write","_encoding","callback","attach","error","ProviderTransferError","chalk","yellowBright","greenBright","id"],"mappings":";;;;;;;AAOA,MAAMA,gCAAgCC,OAAAA,CAAK;AAAC,IAAA;AAAK,CAAA,CAAA;AAEjD,MAAMC,gBAAAA,GAAmB,OAAqCC,MAAAA,EAAqBC,MAAAA,GAAAA;AACjF,IAAA,MAAMC,OAAOL,6BAAAA,CAA8BI,MAAAA,CAAAA;AAC3C,IAAA,OAAOD,OAAOG,EAAE,CAACC,KAAK,CAAC,oBAAA,CAAA,CAAsBC,MAAM,CAAC;QAClDH,IAAAA,EAAM;AACJ,YAAA,GAAGA,IAAI;AACPI,YAAAA,KAAAA,EAAOC,IAAAA,CAAKC,SAAS,CAACN,IAAAA,CAAKI,KAAK;AAClC;AACF,KAAA,CAAA;AACF,CAAA;AAEA,MAAMG,eAAAA,GAAkB,OAAqCT,MAAAA,EAAqBC,MAAAA,GAAAA;AAChF,IAAA,MAAMC,OAAOL,6BAAAA,CAA8BI,MAA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api/providers/local-destination/strategies/restore/configuration.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport { omit } from 'lodash/fp';\nimport chalk from 'chalk';\nimport type { Core } from '@strapi/types';\nimport { ProviderTransferError } from '../../../../../errors/providers';\nimport { IConfiguration, Transaction } from '../../../../../types';\nimport { restoreProjectSettingsRow } from '../../../../utils/project-settings-logos';\n\nconst omitInvalidCreationAttributes = omit(['id']);\n\nconst restoreCoreStore = async <T extends { value: unknown }>(strapi: Core.Strapi, values: T) => {\n const data = omitInvalidCreationAttributes(values);\n const row = await restoreProjectSettingsRow(\n strapi,\n data as unknown as { key: string; value: unknown }\n );\n\n return strapi.db.query('strapi::core-store').create({\n data: {\n ...row,\n value: JSON.stringify(row.value),\n },\n });\n};\n\nconst restoreWebhooks = async <T extends { value: unknown }>(strapi: Core.Strapi, values: T) => {\n const data = omitInvalidCreationAttributes(values);\n return strapi.db.query('strapi::webhook').create({ data });\n};\n\nexport const restoreConfigs = async (strapi: Core.Strapi, config: IConfiguration) => {\n if (config.type === 'core-store') {\n return restoreCoreStore(strapi, config.value as { value: unknown });\n }\n\n if (config.type === 'webhook') {\n return restoreWebhooks(strapi, config.value as { value: unknown });\n }\n};\n\nexport const createConfigurationWriteStream = async (\n strapi: Core.Strapi,\n transaction?: Transaction\n) => {\n return new Writable({\n objectMode: true,\n async write<T extends { id: number }>(\n config: IConfiguration<T>,\n _encoding: BufferEncoding,\n callback: (error?: Error | null) => void\n ) {\n await transaction?.attach(async () => {\n try {\n await restoreConfigs(strapi, config);\n } catch (error) {\n return callback(\n new ProviderTransferError(\n `Failed to import ${chalk.yellowBright(config.type)} (${chalk.greenBright(\n config.value.id\n )}`\n )\n );\n }\n callback();\n });\n },\n });\n};\n"],"names":["omitInvalidCreationAttributes","omit","restoreCoreStore","strapi","values","data","row","restoreProjectSettingsRow","db","query","create","value","JSON","stringify","restoreWebhooks","restoreConfigs","config","type","createConfigurationWriteStream","transaction","Writable","objectMode","write","_encoding","callback","attach","error","Provider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A,OAAO,IAAIC,eAAAA,CAAS;QAClBC,UAAAA,EAAY,IAAA;AACZ,QAAA,MAAMC,KAAAA,CAAAA,CACJN,MAAyB,EACzBO,SAAyB,EACzBC,QAAwC,EAAA;AAExC,YAAA,MAAML,aAAaM,MAAAA,CAAO,UAAA;gBACxB,IAAI;AACF,oBAAA,MAAMV,eAAeZ,MAAAA,EAAQa,MAAAA,CAAAA;AAC/B,gBAAA,CAAA,CAAE,OAAOU,KAAAA,EAAO;oBACd,OAAOF,QAAAA,CACL,IAAIG,+BAAAA,CACF,CAAC,iBAAiB,EAAEC,sBAAAA,CAAMC,YAAY,CAACb,MAAAA,CAAOC,IAAI,CAAA,CAAE,EAAE,EAAEW,sBAAAA,CAAME,WAAW,CACvEd,MAAAA,CAAOL,KAAK,CAACoB,EAAE,CAAA,CAAA,CACd,CAAA,CAAA;AAGT,gBAAA;AACAP,gBAAAA,QAAAA,EAAAA;AACF,YAAA,CAAA,CAAA;AACF,QAAA;AACF,KAAA,CAAA;AACF;;;;;"}
@@ -2,16 +2,18 @@ import { Writable } from 'stream';
2
2
  import { omit } from 'lodash/fp';
3
3
  import chalk from 'chalk';
4
4
  import { ProviderTransferError } from '../../../../../errors/providers.mjs';
5
+ import { restoreProjectSettingsRow } from '../../../../utils/project-settings-logos.mjs';
5
6
 
6
7
  const omitInvalidCreationAttributes = omit([
7
8
  'id'
8
9
  ]);
9
10
  const restoreCoreStore = async (strapi, values)=>{
10
11
  const data = omitInvalidCreationAttributes(values);
12
+ const row = await restoreProjectSettingsRow(strapi, data);
11
13
  return strapi.db.query('strapi::core-store').create({
12
14
  data: {
13
- ...data,
14
- value: JSON.stringify(data.value)
15
+ ...row,
16
+ value: JSON.stringify(row.value)
15
17
  }
16
18
  });
17
19
  };
@@ -1 +1 @@
1
- {"version":3,"file":"configuration.mjs","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/configuration.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport { omit } from 'lodash/fp';\nimport chalk from 'chalk';\nimport type { Core } from '@strapi/types';\nimport { ProviderTransferError } from '../../../../../errors/providers';\nimport { IConfiguration, Transaction } from '../../../../../../types';\n\nconst omitInvalidCreationAttributes = omit(['id']);\n\nconst restoreCoreStore = async <T extends { value: unknown }>(strapi: Core.Strapi, values: T) => {\n const data = omitInvalidCreationAttributes(values);\n return strapi.db.query('strapi::core-store').create({\n data: {\n ...data,\n value: JSON.stringify(data.value),\n },\n });\n};\n\nconst restoreWebhooks = async <T extends { value: unknown }>(strapi: Core.Strapi, values: T) => {\n const data = omitInvalidCreationAttributes(values);\n return strapi.db.query('strapi::webhook').create({ data });\n};\n\nexport const restoreConfigs = async (strapi: Core.Strapi, config: IConfiguration) => {\n if (config.type === 'core-store') {\n return restoreCoreStore(strapi, config.value as { value: unknown });\n }\n\n if (config.type === 'webhook') {\n return restoreWebhooks(strapi, config.value as { value: unknown });\n }\n};\n\nexport const createConfigurationWriteStream = async (\n strapi: Core.Strapi,\n transaction?: Transaction\n) => {\n return new Writable({\n objectMode: true,\n async write<T extends { id: number }>(\n config: IConfiguration<T>,\n _encoding: BufferEncoding,\n callback: (error?: Error | null) => void\n ) {\n await transaction?.attach(async () => {\n try {\n await restoreConfigs(strapi, config);\n } catch (error) {\n return callback(\n new ProviderTransferError(\n `Failed to import ${chalk.yellowBright(config.type)} (${chalk.greenBright(\n config.value.id\n )}`\n )\n );\n }\n callback();\n });\n },\n });\n};\n"],"names":["omitInvalidCreationAttributes","omit","restoreCoreStore","strapi","values","data","db","query","create","value","JSON","stringify","restoreWebhooks","restoreConfigs","config","type","createConfigurationWriteStream","transaction","Writable","objectMode","write","_encoding","callback","attach","error","ProviderTransferError","chalk","yellowBright","greenBright","id"],"mappings":";;;;;AAOA,MAAMA,gCAAgCC,IAAAA,CAAK;AAAC,IAAA;AAAK,CAAA,CAAA;AAEjD,MAAMC,gBAAAA,GAAmB,OAAqCC,MAAAA,EAAqBC,MAAAA,GAAAA;AACjF,IAAA,MAAMC,OAAOL,6B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,EAAO;oBACd,OAAOF,QAAAA,CACL,IAAIG,qBAAAA,CACF,CAAC,iBAAiB,EAAEC,KAAAA,CAAMC,YAAY,CAACb,MAAAA,CAAOC,IAAI,CAAA,CAAE,EAAE,EAAEW,KAAAA,CAAME,WAAW,CACvEd,MAAAA,CAAOL,KAAK,CAACoB,EAAE,CAAA,CAAA,CACd,CAAA,CAAA;AAGT,gBAAA;AACAP,gBAAAA,QAAAA,EAAAA;AACF,YAAA,CAAA,CAAA;AACF,QAAA;AACF,KAAA,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"configuration.mjs","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/configuration.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport { omit } from 'lodash/fp';\nimport chalk from 'chalk';\nimport type { Core } from '@strapi/types';\nimport { ProviderTransferError } from '../../../../../errors/providers';\nimport { IConfiguration, Transaction } from '../../../../../types';\nimport { restoreProjectSettingsRow } from '../../../../utils/project-settings-logos';\n\nconst omitInvalidCreationAttributes = omit(['id']);\n\nconst restoreCoreStore = async <T extends { value: unknown }>(strapi: Core.Strapi, values: T) => {\n const data = omitInvalidCreationAttributes(values);\n const row = await restoreProjectSettingsRow(\n strapi,\n data as unknown as { key: string; value: unknown }\n );\n\n return strapi.db.query('strapi::core-store').create({\n data: {\n ...row,\n value: JSON.stringify(row.value),\n },\n });\n};\n\nconst restoreWebhooks = async <T extends { value: unknown }>(strapi: Core.Strapi, values: T) => {\n const data = omitInvalidCreationAttributes(values);\n return strapi.db.query('strapi::webhook').create({ data });\n};\n\nexport const restoreConfigs = async (strapi: Core.Strapi, config: IConfiguration) => {\n if (config.type === 'core-store') {\n return restoreCoreStore(strapi, config.value as { value: unknown });\n }\n\n if (config.type === 'webhook') {\n return restoreWebhooks(strapi, config.value as { value: unknown });\n }\n};\n\nexport const createConfigurationWriteStream = async (\n strapi: Core.Strapi,\n transaction?: Transaction\n) => {\n return new Writable({\n objectMode: true,\n async write<T extends { id: number }>(\n config: IConfiguration<T>,\n _encoding: BufferEncoding,\n callback: (error?: Error | null) => void\n ) {\n await transaction?.attach(async () => {\n try {\n await restoreConfigs(strapi, config);\n } catch (error) {\n return callback(\n new ProviderTransferError(\n `Failed to import ${chalk.yellowBright(config.type)} (${chalk.greenBright(\n config.value.id\n )}`\n )\n );\n }\n callback();\n });\n },\n });\n};\n"],"names":["omitInvalidCreationAttributes","omit","restoreCoreStore","strapi","values","data","row","restoreProjectSettingsRow","db","query","create","value","JSON","stringify","restoreWebhooks","restoreConfigs","config","type","createConfigurationWriteStream","transaction","Writable","objectMode","write","_encoding","callback","attach","error","ProviderTransferError","chalk","yellowBright","greenBright","id"],"mappings":";;;;;;AAQA,MAAMA,gCAAgCC,IAAAA,CAAK;AAAC,IAAA;AAAK,CAAA,CAAA;AAEjD,MAAMC,gBAAAA,GAAmB,OAAqCC,MAAAA,EAAqBC,MAAAA,GAAAA;AACjF,IAAA,MAAMC,OAAOL,6BAAAA,CAA8BI,MAAAA,CAAAA;IAC3C,MAAME,GAAAA,GAAM,MAAMC,yBAAAA,CAChBJ,MAAAA,EACAE,IAAAA,CAAAA;AAGF,IAAA,OAAOF,OAAOK,EAAE,CAACC,KAAK,CAAC,oBAAA,CAAA,CAAsBC,MAAM,CAAC;QAClDL,IAAAA,EAAM;AACJ,YAAA,GAAGC,GAAG;AACNK,YAAAA,KAAAA,EAAOC,IAAAA,CAAKC,SAAS,CAACP,GAAAA,CAAIK,KAAK;AACjC;AACF,KAAA,CAAA;AACF,CAAA;AAEA,MAAMG,eAAAA,GAAkB,OAAqCX,MAAAA,EAAqBC,MAAAA,GAAAA;AAChF,IAAA,MAAMC,OAAOL,6BAAAA,CAA8BI,MAAAA,CAAAA;AAC3C,IAAA,OAAOD,OAAOK,EAAE,CAACC,KAAK,CAAC,iBAAA,CAAA,CAAmBC,MAAM,CAAC;AAAEL,QAAAA;AAAK,KAAA,CAAA;AAC1D,CAAA;AAEO,MAAMU,cAAAA,GAAiB,OAAOZ,MAAAA,EAAqBa,MAAAA,GAAAA;IACxD,IAAIA,MAAAA,CAAOC,IAAI,KAAK,YAAA,EAAc;QAChC,OAAOf,gBAAAA,CAAiBC,MAAAA,EAAQa,MAAAA,CAAOL,KAAK,CAAA;AAC9C,IAAA;IAEA,IAAIK,MAAAA,CAAOC,IAAI,KAAK,SAAA,EAAW;QAC7B,OAAOH,eAAAA,CAAgBX,MAAAA,EAAQa,MAAAA,CAAOL,KAAK,CAAA;AAC7C,IAAA;AACF;AAEO,MAAMO,8BAAAA,GAAiC,OAC5Cf,MAAAA,EACAgB,WAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIC,QAAAA,CAAS;QAClBC,UAAAA,EAAY,IAAA;AACZ,QAAA,MAAMC,KAAAA,CAAAA,CACJN,MAAyB,EACzBO,SAAyB,EACzBC,QAAwC,EAAA;AAExC,YAAA,MAAML,aAAaM,MAAAA,CAAO,UAAA;gBACxB,IAAI;AACF,oBAAA,MAAMV,eAAeZ,MAAAA,EAAQa,MAAAA,CAAAA;AAC/B,gBAAA,CAAA,CAAE,OAAOU,KAAAA,EAAO;oBACd,OAAOF,QAAAA,CACL,IAAIG,qBAAAA,CACF,CAAC,iBAAiB,EAAEC,KAAAA,CAAMC,YAAY,CAACb,MAAAA,CAAOC,IAAI,CAAA,CAAE,EAAE,EAAEW,KAAAA,CAAME,WAAW,CACvEd,MAAAA,CAAOL,KAAK,CAACoB,EAAE,CAAA,CAAA,CACd,CAAA,CAAA;AAGT,gBAAA;AACAP,gBAAAA,QAAAA,EAAAA;AACF,YAAA,CAAA,CAAA;AACF,QAAA;AACF,KAAA,CAAA;AACF;;;;"}
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Writable } from 'stream';
3
3
  import type { Core, UID } from '@strapi/types';
4
- import type { Transaction } from '../../../../../../types';
4
+ import type { Transaction } from '../../../../../types';
5
5
  interface IEntitiesRestoreStreamOptions {
6
6
  strapi: Core.Strapi;
7
7
  updateMappingTable<TSchemaUID extends UID.Schema>(type: TSchemaUID, oldID: number, newID: number): void;
@@ -1 +1 @@
1
- {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/entities.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAK/C,OAAO,KAAK,EAAW,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAKpE,UAAU,6BAA6B;IACrC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;IACpB,kBAAkB,CAAC,UAAU,SAAS,GAAG,CAAC,MAAM,EAC9C,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,IAAI,CAAC;IACR,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED,eAAO,MAAM,yBAAyB,YAAa,6BAA6B,aAqD/E,CAAC"}
1
+ {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/entities.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,KAAK,EAAW,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIjE,UAAU,6BAA6B;IACrC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;IACpB,kBAAkB,CAAC,UAAU,SAAS,GAAG,CAAC,MAAM,EAC9C,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,IAAI,CAAC;IACR,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED,eAAO,MAAM,yBAAyB,YAAa,6BAA6B,aAgD/E,CAAC"}
@@ -1,14 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var stream = require('stream');
4
- var fp = require('lodash/fp');
5
4
  var providers = require('../../../../../errors/providers.js');
6
- require('crypto');
7
- require('node:events');
8
- require('node:stream/promises');
9
- var json = require('../../../../../utils/json.js');
10
- require('events');
11
5
  var entity = require('../../../../queries/entity.js');
6
+ require('lodash/fp');
12
7
  var components = require('../../../../../utils/components.js');
13
8
 
14
9
  const createEntitiesWriteStream = (options)=>{
@@ -29,27 +24,20 @@ const createEntitiesWriteStream = (options)=>{
29
24
  }),
30
25
  select: 'id'
31
26
  });
32
- // Compute differences between original & new entities
33
- const diffs = json.diff(data, created);
34
27
  updateMappingTable(type, id, created.id);
35
- // For each difference found on an ID attribute,
36
- // update the mapping the table accordingly
37
- diffs.forEach((diff)=>{
38
- if (diff.kind === 'modified' && fp.last(diff.path) === 'id' && 'kind' in contentType) {
39
- const target = components.resolveComponentUID({
40
- paths: diff.path,
41
- data,
42
- contentType,
43
- strapi
44
- });
45
- // If no type is found for the given path, then ignore the diff
46
- if (!target) {
47
- return;
48
- }
49
- const [oldID, newID] = diff.values;
50
- updateMappingTable(target, oldID, newID);
51
- }
28
+ // Register the ID of every component instance that was re-created
29
+ // with the entity — including the ones whose ID did not change — so
30
+ // that the links stage can resolve component-side references and
31
+ // tell transferred components apart from missing/orphaned ones
32
+ const componentMappings = components.collectComponentIdMappings({
33
+ data,
34
+ created,
35
+ schema: contentType,
36
+ strapi
52
37
  });
38
+ for (const { uid, oldID, newID } of componentMappings){
39
+ updateMappingTable(uid, oldID, newID);
40
+ }
53
41
  } catch (e) {
54
42
  if (e instanceof Error) {
55
43
  return callback(e);
@@ -1 +1 @@
1
- {"version":3,"file":"entities.js","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/entities.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport type { Core, UID } from '@strapi/types';\n\nimport { last } from 'lodash/fp';\n\nimport { ProviderTransferError } from '../../../../../errors/providers';\nimport type { IEntity, Transaction } from '../../../../../../types';\nimport { json } from '../../../../../utils';\nimport * as queries from '../../../../queries';\nimport { resolveComponentUID } from '../../../../../utils/components';\n\ninterface IEntitiesRestoreStreamOptions {\n strapi: Core.Strapi;\n updateMappingTable<TSchemaUID extends UID.Schema>(\n type: TSchemaUID,\n oldID: number,\n newID: number\n ): void;\n transaction?: Transaction;\n}\n\nexport const createEntitiesWriteStream = (options: IEntitiesRestoreStreamOptions) => {\n const { strapi, updateMappingTable, transaction } = options;\n const query = queries.entity.createEntityQuery(strapi);\n\n return new Writable({\n objectMode: true,\n\n async write(entity: IEntity, _encoding, callback) {\n await transaction?.attach(async () => {\n const { type, id, data } = entity;\n const { create, getDeepPopulateComponentLikeQuery } = query(type);\n const contentType = strapi.getModel(type);\n\n try {\n const created = await create({\n data,\n populate: getDeepPopulateComponentLikeQuery(contentType, { select: 'id' }),\n select: 'id',\n });\n\n // Compute differences between original & new entities\n const diffs = json.diff(data, created);\n\n updateMappingTable(type, id, created.id);\n\n // For each difference found on an ID attribute,\n // update the mapping the table accordingly\n diffs.forEach((diff) => {\n if (diff.kind === 'modified' && last(diff.path) === 'id' && 'kind' in contentType) {\n const target = resolveComponentUID({ paths: diff.path, data, contentType, strapi });\n\n // If no type is found for the given path, then ignore the diff\n if (!target) {\n return;\n }\n\n const [oldID, newID] = diff.values as [number, number];\n\n updateMappingTable(target, oldID, newID);\n }\n });\n } catch (e) {\n if (e instanceof Error) {\n return callback(e);\n }\n\n return callback(new ProviderTransferError(`Failed to create \"${type}\" (${id})`));\n }\n\n return callback(null);\n });\n },\n });\n};\n"],"names":["createEntitiesWriteStream","options","strapi","updateMappingTable","transaction","query","queries","Writable","objectMode","write","entity","_encoding","callback","attach","type","id","data","create","getDeepPopulateComponentLikeQuery","contentType","getModel","created","populate","select","diffs","json","forEach","diff","kind","last","path","target","resolveComponentUID","paths","oldID","newID","values","e","Error","ProviderTransferError"],"mappings":";;;;;;;;;;;;;AAqBO,MAAMA,4BAA4B,CAACC,OAAAA,GAAAA;AACxC,IAAA,MAAM,EAAEC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,IAAAA;AAAMG,gCAAAA,WAAAA;AAAajB,gCAAAA;AAAO,6BAAA,CAAA;;AAGjF,4BAAA,IAAI,CAAC6B,MAAAA,EAAQ;AACX,gCAAA;AACF,4BAAA;AAEA,4BAAA,MAAM,CAACG,KAAAA,EAAOC,KAAAA,CAAM,GAAGR,KAAKS,MAAM;AAElCjC,4BAAAA,kBAAAA,CAAmB4B,QAAQG,KAAAA,EAAOC,KAAAA,CAAAA;AACpC,wBAAA;AACF,oBAAA,CAAA,CAAA;AACF,gBAAA,CAAA,CAAE,OAAOE,CAAAA,EAAG;AACV,oBAAA,IAAIA,aAAaC,KAAAA,EAAO;AACtB,wBAAA,OAAO1B,QAAAA,CAASyB,CAAAA,CAAAA;AAClB,oBAAA;oBAEA,OAAOzB,QAAAA,CAAS,IAAI2B,+BAAAA,CAAsB,CAAC,kBAAkB,EAAEzB,IAAAA,CAAK,GAAG,EAAEC,EAAAA,CAAG,CAAC,CAAC,CAAA,CAAA;AAChF,gBAAA;AAEA,gBAAA,OAAOH,QAAAA,CAAS,IAAA,CAAA;AAClB,YAAA,CAAA,CAAA;AACF,QAAA;AACF,KAAA,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"entities.js","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/entities.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport type { Core, UID } from '@strapi/types';\n\nimport { ProviderTransferError } from '../../../../../errors/providers';\nimport type { IEntity, Transaction } from '../../../../../types';\nimport * as queries from '../../../../queries';\nimport { collectComponentIdMappings } from '../../../../../utils/components';\n\ninterface IEntitiesRestoreStreamOptions {\n strapi: Core.Strapi;\n updateMappingTable<TSchemaUID extends UID.Schema>(\n type: TSchemaUID,\n oldID: number,\n newID: number\n ): void;\n transaction?: Transaction;\n}\n\nexport const createEntitiesWriteStream = (options: IEntitiesRestoreStreamOptions) => {\n const { strapi, updateMappingTable, transaction } = options;\n const query = queries.entity.createEntityQuery(strapi);\n\n return new Writable({\n objectMode: true,\n\n async write(entity: IEntity, _encoding, callback) {\n await transaction?.attach(async () => {\n const { type, id, data } = entity;\n const { create, getDeepPopulateComponentLikeQuery } = query(type);\n const contentType = strapi.getModel(type);\n\n try {\n const created = await create({\n data,\n populate: getDeepPopulateComponentLikeQuery(contentType, { select: 'id' }),\n select: 'id',\n });\n\n updateMappingTable(type, id, created.id);\n\n // Register the ID of every component instance that was re-created\n // with the entity including the ones whose ID did not change so\n // that the links stage can resolve component-side references and\n // tell transferred components apart from missing/orphaned ones\n const componentMappings = collectComponentIdMappings({\n data,\n created,\n schema: contentType,\n strapi,\n });\n\n for (const { uid, oldID, newID } of componentMappings) {\n updateMappingTable(uid, oldID, newID);\n }\n } catch (e) {\n if (e instanceof Error) {\n return callback(e);\n }\n\n return callback(new ProviderTransferError(`Failed to create \"${type}\" (${id})`));\n }\n\n return callback(null);\n });\n },\n });\n};\n"],"names":["createEntitiesWriteStream","options","strapi","updateMappingTable","transaction","query","queries","Writable","objectMode","write","entity","_encoding","callback","attach","type","id","data","create","getDeepPopulateComponentLikeQuery","contentType","getModel","created","populate","select","componentMappings","collectComponentIdMappings","schema","uid","oldID","newID","e","Error","ProviderTransferError"],"mappings":";;;;;;;;AAkBO,MAAMA,4BAA4B,CAACC,OAAAA,GAAAA;AACxC,IAAA,MAAM,EAAEC,MAAM,EAAEC,kBAAkB,EAAEC,WAAW,EAAE,GAAGH,OAAAA;AACpD,IAAA,MAAMI,KAAAA,GAAQC,wBAAgC,CAACJ,MAAAA,CAAAA;AAE/C,IAAA,OAAO,IAAIK,eAAAA,CAAS;QAClBC,UAAAA,EAAY,IAAA;AAEZ,QAAA,MAAMC,KAAAA,CAAAA,CAAMC,MAAe,EAAEC,SAAS,EAAEC,QAAQ,EAAA;AAC9C,YAAA,MAAMR,aAAaS,MAAAA,CAAO,UAAA;AACxB,gBAAA,MAAM,EAAEC,IAAI,EAAEC,EAAE,EAAEC,IAAI,EAAE,GAAGN,MAAAA;AAC3B,gBAAA,MAAM,EAAEO,MAA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lodash/fp';
3
2
  import { ProviderTransferError } from '../../../../../errors/providers.mjs';
4
- import 'crypto';
5
- import 'node:events';
6
- import 'node:stream/promises';
7
- import { diff } from '../../../../../utils/json.mjs';
8
- import 'events';
9
3
  import { createEntityQuery } from '../../../../queries/entity.mjs';
10
- import { resolveComponentUID } from '../../../../../utils/components.mjs';
4
+ import 'lodash/fp';
5
+ import { collectComponentIdMappings } from '../../../../../utils/components.mjs';
11
6
 
12
7
  const createEntitiesWriteStream = (options)=>{
13
8
  const { strapi, updateMappingTable, transaction } = options;
@@ -27,27 +22,20 @@ const createEntitiesWriteStream = (options)=>{
27
22
  }),
28
23
  select: 'id'
29
24
  });
30
- // Compute differences between original & new entities
31
- const diffs = diff(data, created);
32
25
  updateMappingTable(type, id, created.id);
33
- // For each difference found on an ID attribute,
34
- // update the mapping the table accordingly
35
- diffs.forEach((diff)=>{
36
- if (diff.kind === 'modified' && last(diff.path) === 'id' && 'kind' in contentType) {
37
- const target = resolveComponentUID({
38
- paths: diff.path,
39
- data,
40
- contentType,
41
- strapi
42
- });
43
- // If no type is found for the given path, then ignore the diff
44
- if (!target) {
45
- return;
46
- }
47
- const [oldID, newID] = diff.values;
48
- updateMappingTable(target, oldID, newID);
49
- }
26
+ // Register the ID of every component instance that was re-created
27
+ // with the entity — including the ones whose ID did not change — so
28
+ // that the links stage can resolve component-side references and
29
+ // tell transferred components apart from missing/orphaned ones
30
+ const componentMappings = collectComponentIdMappings({
31
+ data,
32
+ created,
33
+ schema: contentType,
34
+ strapi
50
35
  });
36
+ for (const { uid, oldID, newID } of componentMappings){
37
+ updateMappingTable(uid, oldID, newID);
38
+ }
51
39
  } catch (e) {
52
40
  if (e instanceof Error) {
53
41
  return callback(e);
@@ -1 +1 @@
1
- {"version":3,"file":"entities.mjs","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/entities.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport type { Core, UID } from '@strapi/types';\n\nimport { last } from 'lodash/fp';\n\nimport { ProviderTransferError } from '../../../../../errors/providers';\nimport type { IEntity, Transaction } from '../../../../../../types';\nimport { json } from '../../../../../utils';\nimport * as queries from '../../../../queries';\nimport { resolveComponentUID } from '../../../../../utils/components';\n\ninterface IEntitiesRestoreStreamOptions {\n strapi: Core.Strapi;\n updateMappingTable<TSchemaUID extends UID.Schema>(\n type: TSchemaUID,\n oldID: number,\n newID: number\n ): void;\n transaction?: Transaction;\n}\n\nexport const createEntitiesWriteStream = (options: IEntitiesRestoreStreamOptions) => {\n const { strapi, updateMappingTable, transaction } = options;\n const query = queries.entity.createEntityQuery(strapi);\n\n return new Writable({\n objectMode: true,\n\n async write(entity: IEntity, _encoding, callback) {\n await transaction?.attach(async () => {\n const { type, id, data } = entity;\n const { create, getDeepPopulateComponentLikeQuery } = query(type);\n const contentType = strapi.getModel(type);\n\n try {\n const created = await create({\n data,\n populate: getDeepPopulateComponentLikeQuery(contentType, { select: 'id' }),\n select: 'id',\n });\n\n // Compute differences between original & new entities\n const diffs = json.diff(data, created);\n\n updateMappingTable(type, id, created.id);\n\n // For each difference found on an ID attribute,\n // update the mapping the table accordingly\n diffs.forEach((diff) => {\n if (diff.kind === 'modified' && last(diff.path) === 'id' && 'kind' in contentType) {\n const target = resolveComponentUID({ paths: diff.path, data, contentType, strapi });\n\n // If no type is found for the given path, then ignore the diff\n if (!target) {\n return;\n }\n\n const [oldID, newID] = diff.values as [number, number];\n\n updateMappingTable(target, oldID, newID);\n }\n });\n } catch (e) {\n if (e instanceof Error) {\n return callback(e);\n }\n\n return callback(new ProviderTransferError(`Failed to create \"${type}\" (${id})`));\n }\n\n return callback(null);\n });\n },\n });\n};\n"],"names":["createEntitiesWriteStream","options","strapi","updateMappingTable","transaction","query","queries","Writable","objectMode","write","entity","_encoding","callback","attach","type","id","data","create","getDeepPopulateComponentLikeQuery","contentType","getModel","created","populate","select","diffs","json","forEach","diff","kind","last","path","target","resolveComponentUID","paths","oldID","newID","values","e","Error","ProviderTransferError"],"mappings":";;;;;;;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mBAAAA,CAAoB;AAAEC,gCAAAA,KAAAA,EAAON,KAAKG,IAAI;AAAEd,gCAAAA,IAAAA;AAAMG,gCAAAA,WAAAA;AAAajB,gCAAAA;AAAO,6BAAA,CAAA;;AAGjF,4BAAA,IAAI,CAAC6B,MAAAA,EAAQ;AACX,gCAAA;AACF,4BAAA;AAEA,4BAAA,MAAM,CAACG,KAAAA,EAAOC,KAAAA,CAAM,GAAGR,KAAKS,MAAM;AAElCjC,4BAAAA,kBAAAA,CAAmB4B,QAAQG,KAAAA,EAAOC,KAAAA,CAAAA;AACpC,wBAAA;AACF,oBAAA,CAAA,CAAA;AACF,gBAAA,CAAA,CAAE,OAAOE,CAAAA,EAAG;AACV,oBAAA,IAAIA,aAAaC,KAAAA,EAAO;AACtB,wBAAA,OAAO1B,QAAAA,CAASyB,CAAAA,CAAAA;AAClB,oBAAA;oBAEA,OAAOzB,QAAAA,CAAS,IAAI2B,qBAAAA,CAAsB,CAAC,kBAAkB,EAAEzB,IAAAA,CAAK,GAAG,EAAEC,EAAAA,CAAG,CAAC,CAAC,CAAA,CAAA;AAChF,gBAAA;AAEA,gBAAA,OAAOH,QAAAA,CAAS,IAAA,CAAA;AAClB,YAAA,CAAA,CAAA;AACF,QAAA;AACF,KAAA,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"entities.mjs","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/entities.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport type { Core, UID } from '@strapi/types';\n\nimport { ProviderTransferError } from '../../../../../errors/providers';\nimport type { IEntity, Transaction } from '../../../../../types';\nimport * as queries from '../../../../queries';\nimport { collectComponentIdMappings } from '../../../../../utils/components';\n\ninterface IEntitiesRestoreStreamOptions {\n strapi: Core.Strapi;\n updateMappingTable<TSchemaUID extends UID.Schema>(\n type: TSchemaUID,\n oldID: number,\n newID: number\n ): void;\n transaction?: Transaction;\n}\n\nexport const createEntitiesWriteStream = (options: IEntitiesRestoreStreamOptions) => {\n const { strapi, updateMappingTable, transaction } = options;\n const query = queries.entity.createEntityQuery(strapi);\n\n return new Writable({\n objectMode: true,\n\n async write(entity: IEntity, _encoding, callback) {\n await transaction?.attach(async () => {\n const { type, id, data } = entity;\n const { create, getDeepPopulateComponentLikeQuery } = query(type);\n const contentType = strapi.getModel(type);\n\n try {\n const created = await create({\n data,\n populate: getDeepPopulateComponentLikeQuery(contentType, { select: 'id' }),\n select: 'id',\n });\n\n updateMappingTable(type, id, created.id);\n\n // Register the ID of every component instance that was re-created\n // with the entity including the ones whose ID did not change so\n // that the links stage can resolve component-side references and\n // tell transferred components apart from missing/orphaned ones\n const componentMappings = collectComponentIdMappings({\n data,\n created,\n schema: contentType,\n strapi,\n });\n\n for (const { uid, oldID, newID } of componentMappings) {\n updateMappingTable(uid, oldID, newID);\n }\n } catch (e) {\n if (e instanceof Error) {\n return callback(e);\n }\n\n return callback(new ProviderTransferError(`Failed to create \"${type}\" (${id})`));\n }\n\n return callback(null);\n });\n },\n });\n};\n"],"names":["createEntitiesWriteStream","options","strapi","updateMappingTable","transaction","query","queries","Writable","objectMode","write","entity","_encoding","callback","attach","type","id","data","create","getDeepPopulateComponentLikeQuery","contentType","getModel","created","populate","select","componentMappings","collectComponentIdMappings","schema","uid","oldID","newID","e","Error","ProviderTransferError"],"mappings":";;;;;;AAkBO,MAAMA,4BAA4B,CAACC,OAAAA,GAAAA;AACxC,IAAA,MAAM,EAAEC,MAAM,EAAEC,kBAAkB,EAAEC,WAAW,EAAE,GAAGH,OAAAA;AACpD,IAAA,MAAMI,KAAAA,GAAQC,iBAAgC,CAACJ,MAAAA,CAAAA;AAE/C,IAAA,OAAO,IAAIK,QAAAA,CAAS;QAClBC,UAAAA,EAAY,IAAA;AAEZ,QAAA,MAAMC,KAAAA,CAAAA,CAAMC,MAAe,EAAEC,SAAS,EAAEC,QAAQ,EAAA;AAC9C,YAAA,MAAMR,aAAaS,MAAAA,CAAO,UAAA;AACxB,gBAAA,MAAM,EAAEC,IAAI,EAAEC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