creating getSchemas in the engine to manage caching schemas

This commit is contained in:
Bassel 2023-05-23 16:45:27 +03:00
parent 8ae00e4b9e
commit b86c6ee875

View File

@ -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);