Skip to content

Commit

Permalink
fix(models): remove external dependency for name generation
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 55 deletions.
26 changes: 12 additions & 14 deletions lib/common/benchmarkModelGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}` : ''
}`;
}

/**
Expand All @@ -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,
};
Expand Down Expand Up @@ -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,
Expand All @@ -199,7 +197,7 @@ class BenchmarkModelGenerator {
}) {
let declaration = {
$class: '[email protected]',
name: this.generateName(`${modelI}.${declarationI}`),
name: this.generateName({ modelI, declarationI }),
isAbstract: false,
properties: [],
};
Expand Down
11 changes: 1 addition & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@
"debug": "4.3.1",
"get-value": "3.0.1",
"json-schema-migrate": "2.0.0",
"pluralize": "8.0.0",
"unique-names-generator": "4.7.1"
"pluralize": "8.0.0"
},
"license-check-and-add-config": {
"folder": "./lib",
Expand Down
58 changes: 29 additions & 29 deletions test/common/benchmarkModelGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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
});
Expand All @@ -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;
Expand All @@ -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
});
});

Expand Down

0 comments on commit 2dabc92

Please sign in to comment.