Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rename flag moveToComponents -> moveDuplicatesToComponents #212

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Converts JSON or YAML string object.
| --- | --- | --- |
| [reuseComponents] | <code>Boolean</code> | whether to reuse components from `components` section or not. Defaults to `true`. |
| [removeComponents] | <code>Boolean</code> | whether to remove un-used components from `components` section or not. Defaults to `true`. |
| [moveToComponents] | <code>Boolean</code> | whether to move duplicated components to the `components` section or not. Defaults to `true`. |
| [moveDuplicatesToComponents] | <code>Boolean</code> | whether to move duplicated components to the `components` section or not. Defaults to `true`. |

<a name="Options"></a>

Expand All @@ -144,4 +144,3 @@ Converts JSON or YAML string object.
| --- | --- | --- |
| [rules] | [<code>Rules</code>](#Rules) | the list of rules that specifies which type of optimizations should be applied. |
| [output] | <code>String</code> | specifies which type of output user wants, `'JSON'` or `'YAML'`. Defaults to `'YAML'`; |

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ the report value will be:
action: 'remove',
}
],
moveToComponents: [
moveDuplicatesToComponents: [
{
//move will ref the current path to the moved component as well.
path: 'channels.smartylighting/event/{streetlightId}/lighting/measured.parameters.streetlightId',
Expand All @@ -159,7 +159,7 @@ const optimizedDocument = optimizer.getOptimizedDocument({
rules: {
reuseComponents: true,
removeComponents: true,
moveToComponents: true
moveDuplicatesToComponents: true
}
});
/*
Expand Down
2 changes: 1 addition & 1 deletion examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ optimizer.getReport().then((report) => {
rules: {
reuseComponents: true,
removeComponents: true,
moveToComponents: true,
moveDuplicatesToComponents: true,
},
})
//store optimizedDocument as to output.yaml
Expand Down
8 changes: 4 additions & 4 deletions src/Optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Reporter,
} from './index.d'
import { Parser } from '@asyncapi/parser'
import { removeComponents, reuseComponents, moveToComponents } from './Reporters'
import { removeComponents, reuseComponents, moveDuplicatesToComponents } from './Reporters'
import YAML from 'js-yaml'
import merge from 'merge-deep'
import * as _ from 'lodash'
Expand Down Expand Up @@ -42,7 +42,7 @@ export class Optimizer {
*/
constructor(private YAMLorJSON: any) {
this.outputObject = toJS(this.YAMLorJSON)
this.reporters = [removeComponents, reuseComponents, moveToComponents]
this.reporters = [removeComponents, reuseComponents, moveDuplicatesToComponents]
}

/**
Expand Down Expand Up @@ -78,7 +78,7 @@ export class Optimizer {
* @typedef {Object} Rules
* @property {Boolean=} reuseComponents - whether to reuse components from `components` section or not. Defaults to `true`.
* @property {Boolean=} removeComponents - whether to remove un-used components from `components` section or not. Defaults to `true`.
* @property {Boolean=} moveToComponents - whether to move duplicated components to the `components` section or not. Defaults to `true`.
* @property {Boolean=} moveDuplicatesToComponents - whether to move duplicated components to the `components` section or not. Defaults to `true`.
*/

/**
Expand All @@ -98,7 +98,7 @@ export class Optimizer {
rules: {
reuseComponents: true,
removeComponents: true,
moveToComponents: true,
moveDuplicatesToComponents: true,
},
output: Output.YAML,
}
Expand Down
2 changes: 1 addition & 1 deletion src/Reporters/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './MoveToComponents'
export * from './moveDuplicatesToComponents'
export * from './RemoveComponents'
export * from './ReuseComponents'
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Action } from '../Optimizer'
import { createReport, isEqual, isInComponents } from '../Utils'
import { OptimizableComponent, OptimizableComponentGroup, ReportElement, Reporter } from 'index.d'
import Debug from 'debug'
const debug = Debug('reporter:moveToComponents')
const debug = Debug('reporter:moveDuplicatesToComponents')
/**
*
* @param optimizableComponentGroup components that you want to analyze for duplicates.
Expand Down Expand Up @@ -58,8 +58,8 @@ const findDuplicateComponents = (
return resultElements
}

export const moveToComponents: Reporter = (optimizableComponentsGroup) => {
return createReport(findDuplicateComponents, optimizableComponentsGroup, 'moveToComponents')
export const moveDuplicatesToComponents: Reporter = (optimizableComponentsGroup) => {
return createReport(findDuplicateComponents, optimizableComponentsGroup, 'moveDuplicatesToComponents')
}

function getOutsideComponents(
Expand Down
4 changes: 2 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type OptimizableComponentGroup = {
export interface Report {
reuseComponents?: ReportElement[]
removeComponents?: ReportElement[]
moveToComponents?: ReportElement[]
moveDuplicatesToComponents?: ReportElement[]
}

//In the next major version we can rename this to `Report` and use this format instead.
Expand All @@ -32,7 +32,7 @@ export type Reporter = (optimizeableComponents: OptimizableComponentGroup[]) =>
interface Rules {
reuseComponents?: boolean
removeComponents?: boolean
moveToComponents?: boolean
moveDuplicatesToComponents?: boolean
}
export interface Options {
rules?: Rules
Expand Down
12 changes: 6 additions & 6 deletions test/Reporters/Reporters.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { moveToComponents, reuseComponents, removeComponents } from '../../src/Reporters'
import { moveDuplicatesToComponents, reuseComponents, removeComponents } from '../../src/Reporters'
import { inputYAML } from '../fixtures'
import { Parser } from '@asyncapi/parser'
import { getOptimizableComponents } from '../../src/ComponentProvider'
import { OptimizableComponentGroup } from '../../src/index.d'

const MoveToComponentsExpectedResult: any[] = [
const moveDuplicatesToComponentsExpectedResult: any[] = [
{
path: 'channels.withDuplicatedMessage1.messages.duped1',
action: 'move',
Expand Down Expand Up @@ -55,11 +55,11 @@ describe('Optimizers', () => {
const asyncapiDocument = await new Parser().parse(inputYAML, { applyTraits: false })
optimizableComponents = getOptimizableComponents(asyncapiDocument.document!)
})
describe('MoveToComponents', () => {
describe('moveDuplicatesToComponents', () => {
test('should contain the correct optimizations.', () => {
const report = moveToComponents(optimizableComponents)
expect(report.elements).toEqual(MoveToComponentsExpectedResult)
expect(report.type).toEqual('moveToComponents')
const report = moveDuplicatesToComponents(optimizableComponents)
expect(report.elements).toEqual(moveDuplicatesToComponentsExpectedResult)
expect(report.type).toEqual('moveDuplicatesToComponents')
})
})

Expand Down
Loading