diff --git a/packages/core/data-transfer/src/engine/index.ts b/packages/core/data-transfer/src/engine/index.ts index e0bf6f700c..6bc2898110 100644 --- a/packages/core/data-transfer/src/engine/index.ts +++ b/packages/core/data-transfer/src/engine/index.ts @@ -614,6 +614,21 @@ class TransferEngine< } } + async #getSchemas() { + if (this.#schema.source) { + this.#schema.source = (await this.sourceProvider.getSchemas?.()) as SchemaMap; + } + + if (this.#schema.destination) { + this.#schema.destination = (await this.destinationProvider.getSchemas?.()) as SchemaMap; + } + + return { + sourceSchema: this.#schema.source, + destinationSchema: this.#schema.destination, + }; + } + async integrityCheck() { const sourceMetadata = await this.sourceProvider.getMetadata(); const destinationMetadata = await this.destinationProvider.getMetadata(); @@ -625,12 +640,11 @@ class TransferEngine< ); } - this.#schema.source = (await this.sourceProvider.getSchemas?.()) as SchemaMap; - this.#schema.destination = (await this.destinationProvider.getSchemas?.()) as SchemaMap; + const { sourceSchema, destinationSchema } = await this.#getSchemas(); try { - if (this.#schema.source && this.#schema.destination) { - this.#assertSchemasMatching(this.#schema.source, this.#schema.destination); + if (sourceSchema && destinationSchema) { + this.#assertSchemasMatching(sourceSchema, destinationSchema); } } catch (error) { // if this is a schema matching error, allow handlers to resolve it @@ -762,7 +776,7 @@ class TransferEngine< new Transform({ objectMode: true, transform: async (entity: IEntity, _encoding, callback) => { - const schemas = this.#schema.destination; + const { destinationSchema: schemas } = await this.#getSchemas(); if (!schemas) { return callback(null, entity); @@ -803,7 +817,7 @@ class TransferEngine< new Transform({ objectMode: true, transform: async (link: ILink, _encoding, callback) => { - const schemas = this.#schema.destination; + const { destinationSchema: schemas } = await this.#getSchemas(); if (!schemas) { return callback(null, link);