Skip to content

Commit 4d02fd1

Browse files
author
Iurii Golovinskii
committed
[FE][Part 2] Rename Semi-breaking change
1 parent 8bbacc1 commit 4d02fd1

File tree

19 files changed

+203
-75
lines changed

19 files changed

+203
-75
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/apitypes/rest/rest.changes.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ import {
2525
risky,
2626
} from '@netcracker/qubership-apihub-api-diff'
2727
import { MESSAGE_SEVERITY, NORMALIZE_OPTIONS, ORIGINS_SYMBOL } from '../../consts'
28-
import { BREAKING_CHANGE_TYPE, CompareOperationsPairContext, SEMI_BREAKING_CHANGE_TYPE } from '../../types'
28+
import {
29+
BREAKING_CHANGE_TYPE,
30+
CompareOperationsPairContext,
31+
RISKY_CHANGE_TYPE,
32+
} from '../../types'
2933
import { isObject } from '@netcracker/qubership-apihub-json-crawl'
3034
import { areDeclarationPathsEqual } from '../../utils/path'
3135
import { JSON_SCHEMA_PROPERTY_DEPRECATED, pathItemToFullPath, resolveOrigins } from '@netcracker/qubership-apihub-api-unifier'
@@ -147,7 +151,7 @@ async function reclassifyBreakingChanges(
147151

148152
requiredProperties?.forEach(prop => {
149153
// console.log('requiredProperties----->', prop.propDiff)
150-
if (prop.propDiff.type === SEMI_BREAKING_CHANGE_TYPE && prop.requiredDiff?.type === BREAKING_CHANGE_TYPE) {
154+
if (prop.propDiff.type === RISKY_CHANGE_TYPE && prop.requiredDiff?.type === BREAKING_CHANGE_TYPE) {
151155
prop.requiredDiff.type = risky
152156
}
153157
})

src/builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import type {
1818
BuildConfig,
1919
BuildConfigFile,
20-
BuildConfigRef,
20+
BuildConfigRef, DiffTypeDto,
2121
FileId,
2222
OperationId,
2323
OperationsApiType,
@@ -73,7 +73,7 @@ export class PackageVersionBuilder implements IPackageVersionBuilder {
7373
apiBuilders: ApiBuilder[] = []
7474
documents = new Map<string, VersionDocument>()
7575
operations = new Map<string, ApiOperation>()
76-
comparisons: VersionsComparisonDto[] = []
76+
comparisons: VersionsComparisonDto<DiffTypeDto>[] = []
7777

7878
versionsCache = new Map<string, VersionCache>()
7979
referencesCache = new Map<string, BuildConfigRef[]>()

src/components/compare/compare.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { BuildConfigRef, CompareContext, VersionParams, VersionsComparison, VersionsComparisonDto } from '../../types'
17+
import {
18+
BuildConfigRef,
19+
CompareContext,
20+
DiffTypeDto,
21+
VersionParams,
22+
VersionsComparison,
23+
VersionsComparisonDto,
24+
} from '../../types'
1825
import { compareVersionsOperations } from './compare.operations'
1926
import { getSplittedVersionKey } from '../../utils'
2027
import { toVersionsComparisonDto } from '../../utils/transformToDto'
@@ -26,7 +33,7 @@ export async function compareVersions(
2633
curr: VersionParams,
2734
ctx: CompareContext,
2835
debugCtx?: DebugPerformanceContext,
29-
): Promise<VersionsComparisonDto[]> {
36+
): Promise<VersionsComparisonDto<DiffTypeDto>[]> {
3037
let comparisons: VersionsComparison[] = []
3138
await asyncDebugPerformance('[CompareVersions]', async (versionsDebugContext) => {
3239
comparisons = await compareVersionsReferences(prev, curr, ctx)

src/consts.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
ChangeSummary,
2222
DEPRECATED_CHANGE_TYPE,
2323
NON_BREAKING_CHANGE_TYPE,
24-
SEMI_BREAKING_CHANGE_TYPE,
24+
RISKY_CHANGE_TYPE, SEMI_BREAKING_CHANGE_TYPE,
2525
UNCLASSIFIED_CHANGE_TYPE,
2626
} from './types'
2727

@@ -132,6 +132,15 @@ export const NORMALIZE_OPTIONS: NormalizeOptions = {
132132
}
133133

134134
export const EMPTY_CHANGE_SUMMARY: ChangeSummary = {
135+
[BREAKING_CHANGE_TYPE]: 0,
136+
[NON_BREAKING_CHANGE_TYPE]: 0,
137+
[RISKY_CHANGE_TYPE]: 0,
138+
[DEPRECATED_CHANGE_TYPE]: 0,
139+
[ANNOTATION_CHANGE_TYPE]: 0,
140+
[UNCLASSIFIED_CHANGE_TYPE]: 0,
141+
}
142+
143+
export const EMPTY_CHANGE_SUMMARY_DTO = {
135144
[BREAKING_CHANGE_TYPE]: 0,
136145
[NON_BREAKING_CHANGE_TYPE]: 0,
137146
[SEMI_BREAKING_CHANGE_TYPE]: 0,

src/types/external/comparison.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616

1717
import { ApiAudience } from '../package'
1818
import { OperationsApiType, PackageId, VersionId } from './types'
19-
import { ClassifierType, DiffType, risky } from '@netcracker/qubership-apihub-api-diff'
19+
import {
20+
annotation,
21+
breaking,
22+
ClassifierType, deprecated,
23+
DiffType,
24+
nonBreaking,
25+
risky,
26+
unclassified,
27+
} from '@netcracker/qubership-apihub-api-diff'
2028

2129
export type VersionComparisonResolver = (
2230
version: VersionId,
@@ -37,28 +45,39 @@ export interface ResolvedComparisonSummary {
3745
operationTypes: OperationType[]
3846
}
3947

40-
export interface OperationType {
48+
export interface OperationType<T extends string | number | symbol = DiffType> {
4149
apiType: OperationsApiType
42-
changesSummary: ChangeSummary
43-
numberOfImpactedOperations: ChangeSummary
50+
changesSummary: ChangeSummary<T>
51+
numberOfImpactedOperations: ChangeSummary<T>
4452
apiAudienceTransitions: ApiAudienceTransition[]
4553
tags?: string[]
4654
}
4755

48-
export const BREAKING_CHANGE_TYPE = 'breaking'
49-
export const NON_BREAKING_CHANGE_TYPE = 'non-breaking'
50-
export const UNCLASSIFIED_CHANGE_TYPE = 'unclassified'
51-
export const SEMI_BREAKING_CHANGE_TYPE = risky
52-
export const DEPRECATED_CHANGE_TYPE = 'deprecated'
53-
export const ANNOTATION_CHANGE_TYPE = 'annotation'
56+
export const BREAKING_CHANGE_TYPE = breaking
57+
export const NON_BREAKING_CHANGE_TYPE = nonBreaking
58+
export const UNCLASSIFIED_CHANGE_TYPE = unclassified
59+
export const RISKY_CHANGE_TYPE = risky
60+
export const DEPRECATED_CHANGE_TYPE = deprecated
61+
export const ANNOTATION_CHANGE_TYPE = annotation
62+
export const SEMI_BREAKING_CHANGE_TYPE = 'semi-breaking'
5463

55-
export type ChangeSummary = Record<DiffType, number>
64+
export type ChangeSummary<T extends string | number | symbol = DiffType> = Record<T, number>
5665
export type ImpactedOperationSummary = Record<DiffType, boolean>
57-
5866
export const DIFF_TYPES: DiffType[] = Object.values(ClassifierType)
5967

6068
export interface ApiAudienceTransition {
6169
previousAudience: ApiAudience
6270
currentAudience: ApiAudience
6371
operationsCount: number
6472
}
73+
74+
export type ChangeSummaryDto = Record<DiffTypeDto, number>
75+
export type DiffTypeDto = typeof ClassifierTypeDto[keyof typeof ClassifierTypeDto]
76+
export const ClassifierTypeDto = {
77+
breaking,
78+
nonBreaking,
79+
SEMI_BREAKING_CHANGE_TYPE,
80+
annotation,
81+
unclassified,
82+
deprecated,
83+
} as const

src/types/internal/builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { BuildConfig, BuilderResolvers, FileId, PackageId, ResolvedVersion, VersionId } from '../external'
17+
import { BuildConfig, BuilderResolvers, DiffTypeDto, FileId, PackageId, ResolvedVersion, VersionId } from '../external'
1818
import { VersionsComparisonDto } from './compare'
1919
import { PackageConfig } from '../package/config'
2020
import { NotificationMessage } from '../package/notifications'
@@ -29,7 +29,7 @@ export type VersionCache = ResolvedVersion & {
2929

3030
export interface BuildResult {
3131
config: PackageConfig
32-
comparisons: VersionsComparisonDto[]
32+
comparisons: VersionsComparisonDto<DiffTypeDto>[]
3333
notifications: NotificationMessage[]
3434
documents: Map<string, VersionDocument>
3535
operations: Map<string, ApiOperation>

src/types/internal/compare.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Diff } from '@netcracker/qubership-apihub-api-diff'
17+
import { Diff, DiffType } from '@netcracker/qubership-apihub-api-diff'
1818
import {
1919
ApiKind,
2020
BuildConfig,
21-
ChangeSummary,
21+
ChangeSummary, DiffTypeDto,
2222
ImpactedOperationSummary,
2323
OperationType,
2424
PackageId,
@@ -48,27 +48,27 @@ export type OperationChangesMetadata = {
4848
previousOperationMetadata?: OperationChangesMetadata
4949
} & Partial<RestChangesMetadata> & Partial<GraphQLChangesMetadata>
5050

51-
export interface OperationChanges {
51+
export interface OperationChanges<T extends string | number | symbol = DiffType> {
5252
operationId: string
5353
apiType: BuilderType
5454
apiKind?: ApiKind
5555
previousApiKind?: ApiKind
5656
dataHash?: string
5757
previousDataHash?: string
58-
changeSummary: ChangeSummary
58+
changeSummary: ChangeSummary<T>
5959
impactedSummary: ImpactedOperationSummary
6060
// @deprecated. OOM problem
61-
diffs?: Diff[]
61+
diffs?: Diff[]
6262
metadata?: OperationChangesMetadata & {
6363
[key: string]: unknown
6464
}
6565
}
6666

67-
export interface OperationChangesDto extends Omit<OperationChanges, 'diffs' | 'impactedSummary' | 'mergedJso'> {
68-
changes?: ChangeMessage[]
67+
export interface OperationChangesDto extends Omit<OperationChanges<DiffTypeDto>, 'diffs' | 'impactedSummary' | 'mergedJso'> {
68+
changes?: ChangeMessage<DiffTypeDto>[]
6969
}
7070

71-
export interface VersionsComparison {
71+
export interface VersionsComparison<T extends string | number | symbol = DiffType> {
7272
comparisonFileId?: string
7373
packageId: PackageId
7474
version: VersionId
@@ -77,11 +77,11 @@ export interface VersionsComparison {
7777
previousVersionPackageId: PackageId
7878
previousVersionRevision?: number
7979
fromCache: boolean
80-
operationTypes: OperationType[]
80+
operationTypes: OperationType<T>[]
8181
data?: OperationChanges[]
8282
}
8383

84-
export interface VersionsComparisonDto extends Omit<VersionsComparison, 'data'> {
84+
export interface VersionsComparisonDto<T extends string | number | symbol = DiffTypeDto> extends Omit<VersionsComparison<T>, 'data'> {
8585
data?: OperationChangesDto[]
8686
}
8787

src/types/package/comparisons.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { ChangeSummary, OperationId, OperationType, PackageId, VersionId } from '../external'
17+
import { ChangeSummary, DiffTypeDto, OperationId, OperationType, PackageId, VersionId } from '../external'
1818
import { ActionType, DiffAction, DiffType } from '@netcracker/qubership-apihub-api-diff'
1919
import { JsonPath } from '@netcracker/qubership-apihub-json-crawl'
2020

@@ -31,7 +31,7 @@ export interface PackageComparison {
3131
previousVersionPackageId: PackageId
3232
previousVersionRevision?: number
3333
fromCache: boolean
34-
operationTypes: OperationType[]
34+
operationTypes: OperationType<DiffTypeDto>[]
3535
}
3636

3737
export interface PackageComparisonOperations {
@@ -42,45 +42,45 @@ export interface PackageComparisonOperation {
4242
operationId: OperationId
4343
dataHash?: string
4444
previousDataHash?: string
45-
changeSummary?: ChangeSummary
46-
changes?: ChangeMessage[]
45+
changeSummary?: ChangeSummary<DiffTypeDto>
46+
changes?: ChangeMessage<DiffTypeDto>[]
4747
}
4848

49-
interface ChangeBase {
50-
severity: DiffType
49+
interface ChangeBase<T> {
50+
severity: T
5151
action: ActionType
5252
description?: string
5353
scope: string
5454
}
5555

5656
type Hash = string
5757

58-
export interface ChangeAdd extends ChangeBase {
58+
export interface ChangeAdd<T> extends ChangeBase<T> {
5959
action: typeof DiffAction.add
6060
currentDeclarationJsonPaths: JsonPath[]
6161
currentValueHash: Hash
6262
}
6363

64-
export interface ChangeRemove extends ChangeBase {
64+
export interface ChangeRemove<T> extends ChangeBase<T> {
6565
action: typeof DiffAction.remove
6666
previousDeclarationJsonPaths: JsonPath[]
6767
previousValueHash: Hash
6868
}
6969

70-
export interface ChangeReplace extends ChangeBase {
70+
export interface ChangeReplace<T> extends ChangeBase<T> {
7171
action: typeof DiffAction.replace
7272
previousDeclarationJsonPaths: JsonPath[]
7373
currentDeclarationJsonPaths: JsonPath[]
7474
currentValueHash: Hash
7575
previousValueHash: Hash
7676
}
7777

78-
export interface ChangeRename extends ChangeBase {
78+
export interface ChangeRename<T> extends ChangeBase<T> {
7979
action: typeof DiffAction.rename
8080
previousDeclarationJsonPaths: JsonPath[]
8181
currentDeclarationJsonPaths: JsonPath[]
8282
currentKey: unknown
8383
previousKey: unknown
8484
}
8585

86-
export type ChangeMessage = ChangeAdd | ChangeRemove | ChangeReplace | ChangeRename
86+
export type ChangeMessage<T = DiffType> = ChangeAdd<T> | ChangeRemove<T> | ChangeReplace<T> | ChangeRename<T>

src/utils/builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { ApiAudienceTransition } from './../types/external/comparison'
17+
import { ApiAudienceTransition, RISKY_CHANGE_TYPE } from './../types/external/comparison'
1818
import { ApiKind, ChangeSummary, ResolvedOperation } from '../types'
1919
import {
2020
ANNOTATION_CHANGE_TYPE,
@@ -108,7 +108,7 @@ export const calculateChangeSummary = (changes: Diff[]): ChangeSummary => ({
108108
[BREAKING_CHANGE_TYPE]: countByType(BREAKING_CHANGE_TYPE, changes),
109109
[NON_BREAKING_CHANGE_TYPE]: countByType(NON_BREAKING_CHANGE_TYPE, changes),
110110
[UNCLASSIFIED_CHANGE_TYPE]: countByType(UNCLASSIFIED_CHANGE_TYPE, changes),
111-
[SEMI_BREAKING_CHANGE_TYPE]: countByType(SEMI_BREAKING_CHANGE_TYPE, changes),
111+
[RISKY_CHANGE_TYPE]: countByType(RISKY_CHANGE_TYPE, changes),
112112
[DEPRECATED_CHANGE_TYPE]: countByType(DEPRECATED_CHANGE_TYPE, changes),
113113
[ANNOTATION_CHANGE_TYPE]: countByType(ANNOTATION_CHANGE_TYPE, changes),
114114
})
@@ -121,7 +121,7 @@ export const calculateImpactedSummary = (changeSummaries: ChangeSummary[]): Impa
121121
[BREAKING_CHANGE_TYPE]: checkIfHaveChanges(BREAKING_CHANGE_TYPE, changeSummaries),
122122
[NON_BREAKING_CHANGE_TYPE]: checkIfHaveChanges(NON_BREAKING_CHANGE_TYPE, changeSummaries),
123123
[UNCLASSIFIED_CHANGE_TYPE]: checkIfHaveChanges(UNCLASSIFIED_CHANGE_TYPE, changeSummaries),
124-
[SEMI_BREAKING_CHANGE_TYPE]: checkIfHaveChanges(SEMI_BREAKING_CHANGE_TYPE, changeSummaries),
124+
[RISKY_CHANGE_TYPE]: checkIfHaveChanges(RISKY_CHANGE_TYPE, changeSummaries),
125125
[DEPRECATED_CHANGE_TYPE]: checkIfHaveChanges(DEPRECATED_CHANGE_TYPE, changeSummaries),
126126
[ANNOTATION_CHANGE_TYPE]: checkIfHaveChanges(ANNOTATION_CHANGE_TYPE, changeSummaries),
127127
})

0 commit comments

Comments
 (0)