-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(models): remove external dependency for name generation
Signed-off-by: Stefan Blaginov <[email protected]> Signed-off-by: Stefan Blaginov <[email protected]>
- Loading branch information
Stefan Blaginov
authored and
Stefan Blaginov
committed
Feb 1, 2024
1 parent
ecdbf8b
commit 2dabc92
Showing
4 changed files
with
43 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,6 @@ | |
'use strict'; | ||
|
||
const { Blob } = require('buffer'); | ||
const { | ||
uniqueNamesGenerator, adjectives, colors, animals | ||
} = require('unique-names-generator'); | ||
|
||
const DEFAULT_CONCERTO_METAMODEL_VERSION = '1.0.0'; | ||
const DEFAULT_MODEL_NAMESPACE = 'generated.model'; | ||
|
@@ -74,16 +71,17 @@ class BenchmarkModelGenerator { | |
|
||
/** | ||
* Generates a unique name based on a seed value. | ||
* @param {string} seed A seed value to generate the name. | ||
* @param {Object} params The indexes of the generated components. | ||
* @returns {string} A unique name. | ||
*/ | ||
generateName(seed) { | ||
return uniqueNamesGenerator({ | ||
dictionaries: [adjectives, colors, animals], | ||
style: 'capital', | ||
separator: '', | ||
seed, | ||
}); | ||
generateName({ | ||
modelI, | ||
declarationI, | ||
propertyI, | ||
}) { | ||
return `Model${modelI}Declaration${declarationI}${ | ||
typeof propertyI === 'number' ? `Property${propertyI}` : '' | ||
}`; | ||
} | ||
|
||
/** | ||
|
@@ -98,7 +96,7 @@ class BenchmarkModelGenerator { | |
}) { | ||
return { | ||
$class: '[email protected]', | ||
name: this.generateName(`${modelI}.${declarationI}.${propertyI}`), | ||
name: this.generateName({ modelI, declarationI, propertyI }), | ||
isArray: false, | ||
isOptional: false, | ||
}; | ||
|
@@ -177,7 +175,7 @@ class BenchmarkModelGenerator { | |
}) { | ||
return { | ||
$class: '[email protected]', | ||
name: this.generateName(`${modelI}.${declarationI}`), | ||
name: this.generateName({ modelI, declarationI }), | ||
isAbstract: false, | ||
properties: this.generateNProperties({ | ||
modelI, | ||
|
@@ -199,7 +197,7 @@ class BenchmarkModelGenerator { | |
}) { | ||
let declaration = { | ||
$class: '[email protected]', | ||
name: this.generateName(`${modelI}.${declarationI}`), | ||
name: this.generateName({ modelI, declarationI }), | ||
isAbstract: false, | ||
properties: [], | ||
}; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,36 +33,36 @@ describe('benchmarkModelGenerator', function () { | |
expect(generated.models[0].declarations[0].properties.length).toEqual(5); | ||
expect(generated.models[0].declarations[0]).toEqual({ | ||
'$class': '[email protected]', | ||
name: 'TotalTealDolphin', | ||
name: 'Model0Declaration0', | ||
isAbstract: false, | ||
properties: [ | ||
{ | ||
'$class': '[email protected]', | ||
name: 'PrimaryIndigoOrangutan', | ||
name: 'Model0Declaration0Property0', | ||
isArray: false, | ||
isOptional: false | ||
}, | ||
{ | ||
'$class': '[email protected]', | ||
name: 'TiredTealBear', | ||
name: 'Model0Declaration0Property1', | ||
isArray: false, | ||
isOptional: false | ||
}, | ||
{ | ||
'$class': '[email protected]', | ||
name: 'ChronicCrimsonOtter', | ||
name: 'Model0Declaration0Property2', | ||
isArray: false, | ||
isOptional: false | ||
}, | ||
{ | ||
'$class': '[email protected]', | ||
name: 'InternationalSilverQuelea', | ||
name: 'Model0Declaration0Property3', | ||
isArray: false, | ||
isOptional: false | ||
}, | ||
{ | ||
'$class': '[email protected]', | ||
name: 'ConsistentBlueEarthworm', | ||
name: 'Model0Declaration0Property4', | ||
isArray: false, | ||
isOptional: false | ||
} | ||
|
@@ -76,8 +76,8 @@ describe('benchmarkModelGenerator', function () { | |
imports: [] | ||
}); | ||
expect(generated.metadata).toEqual({ | ||
generatedModelSizeInBytes: 3661, | ||
humanReadableGeneratedModelSize: '3.58 KiB', | ||
generatedModelSizeInBytes: 3845, | ||
humanReadableGeneratedModelSize: '3.75 KiB', | ||
declarationsN: 5, | ||
propertiesNInSmallestDeclaration: 5, | ||
propertiesNInLargestDeclaration: 5 | ||
|
@@ -94,40 +94,40 @@ describe('benchmarkModelGenerator', function () { | |
nProperties: 5, | ||
}); | ||
|
||
expect(generated.models[0].declarations.length).toEqual(14); | ||
expect(generated.models[0].declarations.length).toEqual(13); | ||
expect(generated.models[0].declarations[0].properties.length).toEqual(5); | ||
expect(generated.models[0].declarations[0]).toEqual({ | ||
'$class': '[email protected]', | ||
name: 'TotalTealDolphin', | ||
name: 'Model0Declaration0', | ||
isAbstract: false, | ||
properties: [ | ||
{ | ||
'$class': '[email protected]', | ||
name: 'PrimaryIndigoOrangutan', | ||
name: 'Model0Declaration0Property0', | ||
isArray: false, | ||
isOptional: false | ||
}, | ||
{ | ||
'$class': '[email protected]', | ||
name: 'TiredTealBear', | ||
name: 'Model0Declaration0Property1', | ||
isArray: false, | ||
isOptional: false | ||
}, | ||
{ | ||
'$class': '[email protected]', | ||
name: 'ChronicCrimsonOtter', | ||
name: 'Model0Declaration0Property2', | ||
isArray: false, | ||
isOptional: false | ||
}, | ||
{ | ||
'$class': '[email protected]', | ||
name: 'InternationalSilverQuelea', | ||
name: 'Model0Declaration0Property3', | ||
isArray: false, | ||
isOptional: false | ||
}, | ||
{ | ||
'$class': '[email protected]', | ||
name: 'ConsistentBlueEarthworm', | ||
name: 'Model0Declaration0Property4', | ||
isArray: false, | ||
isOptional: false | ||
} | ||
|
@@ -143,9 +143,9 @@ describe('benchmarkModelGenerator', function () { | |
expect(generated.metadata).toEqual({ | ||
requestedModelSizeInBytes: 10000, | ||
humanReadableRequestedModelSize: '9.77 KiB', | ||
generatedModelSizeInBytes: 9980, | ||
humanReadableGeneratedModelSize: '9.75 KiB', | ||
declarationsN: 14, | ||
generatedModelSizeInBytes: 9815, | ||
humanReadableGeneratedModelSize: '9.58 KiB', | ||
declarationsN: 13, | ||
propertiesNInSmallestDeclaration: 5, | ||
propertiesNInLargestDeclaration: 5 | ||
}); | ||
|
@@ -162,43 +162,43 @@ describe('benchmarkModelGenerator', function () { | |
}); | ||
|
||
expect(generated.models[0].declarations.length).toEqual(5); | ||
expect(generated.models[0].declarations[0].properties.length).toEqual(15); | ||
expect(generated.models[0].declarations[0].properties.length).toEqual(14); | ||
expect(generated.models[0].declarations[0].properties.slice(0, 5)).toEqual([ | ||
{ | ||
'$class': '[email protected]', | ||
name: 'PrimaryIndigoOrangutan', | ||
name: 'Model0Declaration0Property0', | ||
isArray: false, | ||
isOptional: false | ||
}, | ||
{ | ||
'$class': '[email protected]', | ||
name: 'TiredTealBear', | ||
name: 'Model0Declaration0Property1', | ||
isArray: false, | ||
isOptional: false | ||
}, | ||
{ | ||
'$class': '[email protected]', | ||
name: 'ChronicCrimsonOtter', | ||
name: 'Model0Declaration0Property2', | ||
isArray: false, | ||
isOptional: false | ||
}, | ||
{ | ||
'$class': '[email protected]', | ||
name: 'InternationalSilverQuelea', | ||
name: 'Model0Declaration0Property3', | ||
isArray: false, | ||
isOptional: false | ||
}, | ||
{ | ||
'$class': '[email protected]', | ||
name: 'ConsistentBlueEarthworm', | ||
name: 'Model0Declaration0Property4', | ||
isArray: false, | ||
isOptional: false | ||
} | ||
]); | ||
delete generated.models[0].declarations[0].properties; | ||
expect(generated.models[0].declarations[0]).toEqual({ | ||
'$class': '[email protected]', | ||
name: 'TotalTealDolphin', | ||
name: 'Model0Declaration0', | ||
isAbstract: false, | ||
}); | ||
delete generated.models[0].declarations; | ||
|
@@ -211,11 +211,11 @@ describe('benchmarkModelGenerator', function () { | |
expect(generated.metadata).toEqual({ | ||
requestedModelSizeInBytes: 10000, | ||
humanReadableRequestedModelSize: '9.77 KiB', | ||
generatedModelSizeInBytes: 9948, | ||
humanReadableGeneratedModelSize: '9.71 KiB', | ||
generatedModelSizeInBytes: 9994, | ||
humanReadableGeneratedModelSize: '9.76 KiB', | ||
declarationsN: 5, | ||
propertiesNInSmallestDeclaration: 15, | ||
propertiesNInLargestDeclaration: 16 | ||
propertiesNInSmallestDeclaration: 14, | ||
propertiesNInLargestDeclaration: 15 | ||
}); | ||
}); | ||
|
||
|