From b86c6ee8757ef58163ef71495cf00bf84259d76a Mon Sep 17 00:00:00 2001 From: Bassel Date: Tue, 23 May 2023 16:45:27 +0300 Subject: [PATCH] creating getSchemas in the engine to manage caching schemas --- .../core/data-transfer/src/engine/index.ts | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) 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);