Skip to content

Commit

Permalink
feat: extend differ v3 for new stream service type
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 committed Aug 30, 2024
1 parent 4681ddf commit 98b5b09
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions apps/cli/src/differ/differv3.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ADCSDK from '@api7/adc-sdk';
import { randomUUID } from 'crypto';
import { diff as objectDiff } from 'deep-diff';
import { cloneDeep, isEmpty, isEqual, isNil, unset } from 'lodash';
import { cloneDeep, has, isEmpty, isEqual, isNil, unset } from 'lodash';
import winston from 'winston';

const order = {
Expand Down Expand Up @@ -359,6 +359,20 @@ export class DifferV3 {
);
}

// Services will have two different default value rules depending on
// the type of route they contain, one for HTTP services and another
// for stream services.
// Therefore, before merging the default values, we should decide
// the default value table according to the type of service. This type
// is only used for merging default values, other processes still
// use the ResourceType.SERVICE type.
const resourceTypeForDefault =
resourceType != ADCSDK.ResourceType.SERVICE
? resourceType
: has(localItem, 'stream_routes')
? ADCSDK.ResourceType.INTERNAL_STREAM_SERVICE
: ADCSDK.ResourceType.SERVICE;

// Merges local resources into a table of default values for this type.
// The Admin API merges the default values specified in the schema into
// the data, so default values not contained in the local data will
Expand All @@ -368,7 +382,8 @@ export class DifferV3 {
// As such, each backend implementation needs to provide its table of
// default values, which merges the local resources to the defaults,
// just as the Admin API does.
const defaultValue = this.defaultValue?.core?.[resourceType] ?? {};
const defaultValue =
this.defaultValue?.core?.[resourceTypeForDefault] ?? {};
const mergedLocalItem = this.mergeDefault(
localItem,
cloneDeep(defaultValue),
Expand Down

0 comments on commit 98b5b09

Please sign in to comment.