From cd86776d8a7132fdaf45aa1e0a6b6222e4bf5437 Mon Sep 17 00:00:00 2001 From: bzp2010 Date: Fri, 27 Dec 2024 10:06:17 +0800 Subject: [PATCH] feat: field level version filter --- libs/backend-api7/src/index.ts | 6 +++++- libs/backend-api7/src/operator.ts | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/libs/backend-api7/src/index.ts b/libs/backend-api7/src/index.ts index fcdf8e1..ddf7fe5 100644 --- a/libs/backend-api7/src/index.ts +++ b/libs/backend-api7/src/index.ts @@ -216,7 +216,11 @@ export class BackendAPI7 implements ADCSDK.Backend { } public async sync(): Promise { - const operator = new Operator(this.client, this.gatewayGroup); + const operator = new Operator({ + client: this.client, + gatewayGroupName: this.gatewayGroup, + version: this.version, + }); return new Listr( [ this.getAPI7VersionTask(), diff --git a/libs/backend-api7/src/operator.ts b/libs/backend-api7/src/operator.ts index 021e84d..15bb5b4 100644 --- a/libs/backend-api7/src/operator.ts +++ b/libs/backend-api7/src/operator.ts @@ -17,10 +17,19 @@ export interface OperateContext { type OperateTask = ListrTask; export class Operator { - constructor( - private readonly client: Axios, - private readonly gatewayGroupName: string, - ) {} + private readonly client: Axios; + private readonly gatewayGroupName: string; + private readonly version: SemVer; + + constructor(opts: { + client: Axios; + gatewayGroupName: string; + version: SemVer; + }) { + this.client = opts.client; + this.gatewayGroupName = opts.gatewayGroupName; + this.version = opts.version; + } public updateResource(event: ADCSDK.Event): OperateTask { return { @@ -279,12 +288,15 @@ export class Operator { case ADCSDK.ResourceType.SERVICE: (event.newValue as ADCSDK.Service).id = event.resourceId; return fromADC.transformService(event.newValue as ADCSDK.Service); - case ADCSDK.ResourceType.ROUTE: + case ADCSDK.ResourceType.ROUTE: { (event.newValue as ADCSDK.Route).id = event.resourceId; - return fromADC.transformRoute( + const route = fromADC.transformRoute( event.newValue as ADCSDK.Route, event.parentId, ); + if (!semVerGTE(this.version, '3.2.16')) delete route.vars; + return route; + } case ADCSDK.ResourceType.STREAM_ROUTE: (event.newValue as ADCSDK.StreamRoute).id = event.resourceId; return fromADC.transformStreamRoute(