diff --git a/package-lock.json b/package-lock.json index 64be3f9..39b17ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@oclif/plugin-help": "3.1.0", "chalk": "2.4.2", "change-case": "4.1.1", - "domain-objects": "0.7.6", + "domain-objects": "0.11.3", "domain-objects-metadata": "0.4.1", "fast-glob": "3.2.2", "joi": "17.4.0", @@ -6008,6 +6008,22 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/declapract/node_modules/domain-objects": { + "version": "0.7.6", + "resolved": "https://registry.npmjs.org/domain-objects/-/domain-objects-0.7.6.tgz", + "integrity": "sha512-8Flf18TvaW1jUnFVNnnXTAF/4m8D31/44VlPL/+/Z+iUkPebW22L3zrjpobXpcwFfrcmvtJvv5pNKmVSet1G1Q==", + "dev": true, + "dependencies": { + "@types/joi": "^17.2.3", + "@types/lodash.omit": "^4.5.6", + "@types/yup": "^0.29.6", + "lodash.omit": "^4.5.0", + "lodash.pick": "^4.4.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/declapract/node_modules/expect": { "version": "27.1.0", "resolved": "https://registry.npmjs.org/expect/-/expect-27.1.0.tgz", @@ -6472,13 +6488,15 @@ } }, "node_modules/domain-objects": { - "version": "0.7.6", - "resolved": "https://registry.npmjs.org/domain-objects/-/domain-objects-0.7.6.tgz", - "integrity": "sha512-8Flf18TvaW1jUnFVNnnXTAF/4m8D31/44VlPL/+/Z+iUkPebW22L3zrjpobXpcwFfrcmvtJvv5pNKmVSet1G1Q==", + "version": "0.11.3", + "resolved": "https://registry.npmjs.org/domain-objects/-/domain-objects-0.11.3.tgz", + "integrity": "sha512-LjSgAoacN2+2rD/LxCuhOunJ2AUpDWqeKGA6HuJt2h1NS9X/Yq98o/8qHOoYd1fVkuC2icEEyOCIKKSgtpZ3Bw==", + "hasInstallScript": true, "dependencies": { "@types/joi": "^17.2.3", "@types/lodash.omit": "^4.5.6", "@types/yup": "^0.29.6", + "change-case": "^4.1.2", "lodash.omit": "^4.5.0", "lodash.pick": "^4.4.0" }, @@ -6502,6 +6520,21 @@ "node": ">=8.0.0" } }, + "node_modules/domain-objects-metadata/node_modules/domain-objects": { + "version": "0.7.6", + "resolved": "https://registry.npmjs.org/domain-objects/-/domain-objects-0.7.6.tgz", + "integrity": "sha512-8Flf18TvaW1jUnFVNnnXTAF/4m8D31/44VlPL/+/Z+iUkPebW22L3zrjpobXpcwFfrcmvtJvv5pNKmVSet1G1Q==", + "dependencies": { + "@types/joi": "^17.2.3", + "@types/lodash.omit": "^4.5.6", + "@types/yup": "^0.29.6", + "lodash.omit": "^4.5.0", + "lodash.pick": "^4.4.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/domain-objects-metadata/node_modules/typescript": { "version": "3.9.10", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", @@ -6514,6 +6547,25 @@ "node": ">=4.2.0" } }, + "node_modules/domain-objects/node_modules/change-case": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/change-case/-/change-case-4.1.2.tgz", + "integrity": "sha512-bSxY2ws9OtviILG1EiY5K7NNxkqg/JnRnFxLtKQ96JaviiIxi7djMrSd0ECT9AC+lttClmYwKw53BWpOMblo7A==", + "dependencies": { + "camel-case": "^4.1.2", + "capital-case": "^1.0.4", + "constant-case": "^3.0.4", + "dot-case": "^3.0.4", + "header-case": "^2.0.4", + "no-case": "^3.0.4", + "param-case": "^3.0.4", + "pascal-case": "^3.1.2", + "path-case": "^3.0.4", + "sentence-case": "^3.0.4", + "snake-case": "^3.0.4", + "tslib": "^2.0.3" + } + }, "node_modules/dot-case": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/dot-case/-/dot-case-3.0.4.tgz", @@ -14326,6 +14378,22 @@ "yesql": "3.2.2" } }, + "node_modules/sql-code-generator/node_modules/domain-objects": { + "version": "0.7.6", + "resolved": "https://registry.npmjs.org/domain-objects/-/domain-objects-0.7.6.tgz", + "integrity": "sha512-8Flf18TvaW1jUnFVNnnXTAF/4m8D31/44VlPL/+/Z+iUkPebW22L3zrjpobXpcwFfrcmvtJvv5pNKmVSet1G1Q==", + "dev": true, + "dependencies": { + "@types/joi": "^17.2.3", + "@types/lodash.omit": "^4.5.6", + "@types/yup": "^0.29.6", + "lodash.omit": "^4.5.0", + "lodash.pick": "^4.4.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/sql-code-generator/node_modules/uuid": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", @@ -14431,6 +14499,22 @@ "node": ">= 8.3" } }, + "node_modules/sql-schema-control/node_modules/domain-objects": { + "version": "0.7.6", + "resolved": "https://registry.npmjs.org/domain-objects/-/domain-objects-0.7.6.tgz", + "integrity": "sha512-8Flf18TvaW1jUnFVNnnXTAF/4m8D31/44VlPL/+/Z+iUkPebW22L3zrjpobXpcwFfrcmvtJvv5pNKmVSet1G1Q==", + "dev": true, + "dependencies": { + "@types/joi": "^17.2.3", + "@types/lodash.omit": "^4.5.6", + "@types/yup": "^0.29.6", + "lodash.omit": "^4.5.0", + "lodash.pick": "^4.4.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/sql-schema-control/node_modules/jest-diff": { "version": "25.5.0", "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-25.5.0.tgz", @@ -14535,6 +14619,22 @@ "node": ">=8.0.0" } }, + "node_modules/sql-schema-generator/node_modules/domain-objects": { + "version": "0.7.6", + "resolved": "https://registry.npmjs.org/domain-objects/-/domain-objects-0.7.6.tgz", + "integrity": "sha512-8Flf18TvaW1jUnFVNnnXTAF/4m8D31/44VlPL/+/Z+iUkPebW22L3zrjpobXpcwFfrcmvtJvv5pNKmVSet1G1Q==", + "dev": true, + "dependencies": { + "@types/joi": "^17.2.3", + "@types/lodash.omit": "^4.5.6", + "@types/yup": "^0.29.6", + "lodash.omit": "^4.5.0", + "lodash.pick": "^4.4.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/sql-schema-generator/node_modules/joi": { "version": "17.4.2", "resolved": "https://registry.npmjs.org/joi/-/joi-17.4.2.tgz", @@ -20789,6 +20889,19 @@ "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", "dev": true }, + "domain-objects": { + "version": "0.7.6", + "resolved": "https://registry.npmjs.org/domain-objects/-/domain-objects-0.7.6.tgz", + "integrity": "sha512-8Flf18TvaW1jUnFVNnnXTAF/4m8D31/44VlPL/+/Z+iUkPebW22L3zrjpobXpcwFfrcmvtJvv5pNKmVSet1G1Q==", + "dev": true, + "requires": { + "@types/joi": "^17.2.3", + "@types/lodash.omit": "^4.5.6", + "@types/yup": "^0.29.6", + "lodash.omit": "^4.5.0", + "lodash.pick": "^4.4.0" + } + }, "expect": { "version": "27.1.0", "resolved": "https://registry.npmjs.org/expect/-/expect-27.1.0.tgz", @@ -21174,15 +21287,37 @@ } }, "domain-objects": { - "version": "0.7.6", - "resolved": "https://registry.npmjs.org/domain-objects/-/domain-objects-0.7.6.tgz", - "integrity": "sha512-8Flf18TvaW1jUnFVNnnXTAF/4m8D31/44VlPL/+/Z+iUkPebW22L3zrjpobXpcwFfrcmvtJvv5pNKmVSet1G1Q==", + "version": "0.11.3", + "resolved": "https://registry.npmjs.org/domain-objects/-/domain-objects-0.11.3.tgz", + "integrity": "sha512-LjSgAoacN2+2rD/LxCuhOunJ2AUpDWqeKGA6HuJt2h1NS9X/Yq98o/8qHOoYd1fVkuC2icEEyOCIKKSgtpZ3Bw==", "requires": { "@types/joi": "^17.2.3", "@types/lodash.omit": "^4.5.6", "@types/yup": "^0.29.6", + "change-case": "^4.1.2", "lodash.omit": "^4.5.0", "lodash.pick": "^4.4.0" + }, + "dependencies": { + "change-case": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/change-case/-/change-case-4.1.2.tgz", + "integrity": "sha512-bSxY2ws9OtviILG1EiY5K7NNxkqg/JnRnFxLtKQ96JaviiIxi7djMrSd0ECT9AC+lttClmYwKw53BWpOMblo7A==", + "requires": { + "camel-case": "^4.1.2", + "capital-case": "^1.0.4", + "constant-case": "^3.0.4", + "dot-case": "^3.0.4", + "header-case": "^2.0.4", + "no-case": "^3.0.4", + "param-case": "^3.0.4", + "pascal-case": "^3.1.2", + "path-case": "^3.0.4", + "sentence-case": "^3.0.4", + "snake-case": "^3.0.4", + "tslib": "^2.0.3" + } + } } }, "domain-objects-metadata": { @@ -21198,6 +21333,18 @@ "typescript": "^3.8.3" }, "dependencies": { + "domain-objects": { + "version": "0.7.6", + "resolved": "https://registry.npmjs.org/domain-objects/-/domain-objects-0.7.6.tgz", + "integrity": "sha512-8Flf18TvaW1jUnFVNnnXTAF/4m8D31/44VlPL/+/Z+iUkPebW22L3zrjpobXpcwFfrcmvtJvv5pNKmVSet1G1Q==", + "requires": { + "@types/joi": "^17.2.3", + "@types/lodash.omit": "^4.5.6", + "@types/yup": "^0.29.6", + "lodash.omit": "^4.5.0", + "lodash.pick": "^4.4.0" + } + }, "typescript": { "version": "3.9.10", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", @@ -27118,6 +27265,19 @@ "yaml": "1.6.0" }, "dependencies": { + "domain-objects": { + "version": "0.7.6", + "resolved": "https://registry.npmjs.org/domain-objects/-/domain-objects-0.7.6.tgz", + "integrity": "sha512-8Flf18TvaW1jUnFVNnnXTAF/4m8D31/44VlPL/+/Z+iUkPebW22L3zrjpobXpcwFfrcmvtJvv5pNKmVSet1G1Q==", + "dev": true, + "requires": { + "@types/joi": "^17.2.3", + "@types/lodash.omit": "^4.5.6", + "@types/yup": "^0.29.6", + "lodash.omit": "^4.5.0", + "lodash.pick": "^4.4.0" + } + }, "uuid": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", @@ -27209,6 +27369,19 @@ "integrity": "sha512-Hq8o7+6GaZeoFjtpgvRBUknSXNeJiCx7V9Fr94ZMljNiCr9n9L8H8aJqgWOQiDDGdyn29fRNcDdRVJ5fdyihfg==", "dev": true }, + "domain-objects": { + "version": "0.7.6", + "resolved": "https://registry.npmjs.org/domain-objects/-/domain-objects-0.7.6.tgz", + "integrity": "sha512-8Flf18TvaW1jUnFVNnnXTAF/4m8D31/44VlPL/+/Z+iUkPebW22L3zrjpobXpcwFfrcmvtJvv5pNKmVSet1G1Q==", + "dev": true, + "requires": { + "@types/joi": "^17.2.3", + "@types/lodash.omit": "^4.5.6", + "@types/yup": "^0.29.6", + "lodash.omit": "^4.5.0", + "lodash.pick": "^4.4.0" + } + }, "jest-diff": { "version": "25.5.0", "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-25.5.0.tgz", @@ -27293,6 +27466,19 @@ "yaml": "2.2.1" }, "dependencies": { + "domain-objects": { + "version": "0.7.6", + "resolved": "https://registry.npmjs.org/domain-objects/-/domain-objects-0.7.6.tgz", + "integrity": "sha512-8Flf18TvaW1jUnFVNnnXTAF/4m8D31/44VlPL/+/Z+iUkPebW22L3zrjpobXpcwFfrcmvtJvv5pNKmVSet1G1Q==", + "dev": true, + "requires": { + "@types/joi": "^17.2.3", + "@types/lodash.omit": "^4.5.6", + "@types/yup": "^0.29.6", + "lodash.omit": "^4.5.0", + "lodash.pick": "^4.4.0" + } + }, "joi": { "version": "17.4.2", "resolved": "https://registry.npmjs.org/joi/-/joi-17.4.2.tgz", diff --git a/package.json b/package.json index 99c5281..24be8d8 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "@oclif/plugin-help": "3.1.0", "chalk": "2.4.2", "change-case": "4.1.1", - "domain-objects": "0.7.6", + "domain-objects": "0.11.3", "domain-objects-metadata": "0.4.1", "fast-glob": "3.2.2", "joi": "17.4.0", diff --git a/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/getDomainObjectNameAfterDroppingSomeQualifiers.test.ts b/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/getDomainObjectNameAfterDroppingSomeQualifiers.test.ts deleted file mode 100644 index 1e9ab38..0000000 --- a/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/getDomainObjectNameAfterDroppingSomeQualifiers.test.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { getDomainObjectNameAfterDroppingSomeQualifiers } from './getDomainObjectNameAfterDroppingSomeQualifiers'; - -describe('getDomainObjectNameAfterDroppingSomeQualifiers', () => { - const cases: { - domainObjectName: string; - qualifiersToDrop: number; - expectedResult: string | null; - }[] = [ - { - domainObjectName: 'HomeAddress', - qualifiersToDrop: 1, - expectedResult: 'Address', - }, - { - domainObjectName: 'HomeAddress', - qualifiersToDrop: 2, - expectedResult: null, - }, - { - domainObjectName: 'PlaceExternalId', - qualifiersToDrop: 1, - expectedResult: 'ExternalId', - }, - { - domainObjectName: 'PlaceExternalId', - qualifiersToDrop: 2, - expectedResult: null, - }, - { - domainObjectName: 'TrainStationDockingGate', - qualifiersToDrop: 2, - expectedResult: 'DockingGate', - }, - { - domainObjectName: 'TrainStationDockingGate', - qualifiersToDrop: 3, - expectedResult: 'Gate', - }, - { - domainObjectName: 'TrainStationDockingGate', - qualifiersToDrop: 4, - expectedResult: null, - }, - ]; - - cases.forEach((testCase) => { - it(`should return ${testCase.expectedResult} for ${testCase.domainObjectName}, ${testCase.qualifiersToDrop}`, () => { - expect( - getDomainObjectNameAfterDroppingSomeQualifiers({ - domainObjectName: testCase.domainObjectName, - qualifiersToDrop: testCase.qualifiersToDrop, - }), - ).toEqual(testCase.expectedResult); - }); - }); -}); diff --git a/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/getDomainObjectNameAfterDroppingSomeQualifiers.ts b/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/getDomainObjectNameAfterDroppingSomeQualifiers.ts deleted file mode 100644 index 57e3472..0000000 --- a/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/getDomainObjectNameAfterDroppingSomeQualifiers.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { noCase, pascalCase } from 'change-case'; - -/** - * examples: - * - HomeAddress, 1 => Address - * - HomeAddress, 2 => null - * - PlaceExternalId, 1 => ExternalId - * - PlaceExternalId, 2 => null - * - TrainStationDockingGate, 2 => DockingGate - * - TrainStationDockingGate, 3 => Gate - * - TrainStationDockingGate, 4 => null - */ -export const getDomainObjectNameAfterDroppingSomeQualifiers = ({ - domainObjectName, - qualifiersToDrop, -}: { - domainObjectName: string; - qualifiersToDrop: number; -}): string | null => { - // sanity check - if (qualifiersToDrop < 0) - throw new Error('qualifiers to drop must be greater than 0'); - - // handle base case - if (qualifiersToDrop === 0) return domainObjectName; // nothing to do in this case - - // drop the qualifiers - const partsOfName = noCase(domainObjectName) // no case splits up string w/ spaces - .split(' '); - const nameWithoutRequestedQualifiers = pascalCase( - partsOfName.slice(qualifiersToDrop).join(' '), - ); - - // check that its still a valid name - if (nameWithoutRequestedQualifiers.length < 3) return null; // less than 3 char -> not a valid name - - // return the name without qualifiers - return nameWithoutRequestedQualifiers; -}; diff --git a/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter.ts b/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter.ts index fbaebc9..d719c87 100644 --- a/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter.ts +++ b/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter.ts @@ -1,5 +1,4 @@ -import { getDomainObjectNameAfterDroppingSomeQualifiers } from './getDomainObjectNameAfterDroppingSomeQualifiers'; -import { isPropertyNamedAfterDomainObject } from './isPropertyNamedAfterDomainObject'; +import { isPropertyNameAReferenceIntuitively } from 'domain-objects'; export class AmbiguouslyNamedDomainObjectReferencePropertyError extends Error { constructor({ @@ -51,66 +50,20 @@ export const getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter = propertyName: string; allDomainObjectNames: string[]; }): string | null => { - let qualifiersToDrop = 0; - let iterationLimitExceeded = false; - while (!iterationLimitExceeded) { - // for this qualifiersToDrop count, define the names for domain objects after dropping those qualifiers - const allDomainObjectNamesWithoutQualifiers = allDomainObjectNames - .map((domainObjectName) => { - return { - withoutQualifiers: getDomainObjectNameAfterDroppingSomeQualifiers({ - domainObjectName, - qualifiersToDrop, - }), - withQualifiers: domainObjectName, - }; - }) - .filter( - ( - name, - ): name is { withoutQualifiers: string; withQualifiers: string } => - !!name.withoutQualifiers, - ); - if (allDomainObjectNamesWithoutQualifiers.length === 0) return null; // if we reached here, then that means we can't find a domain object name that this property name references in any way - - // check if there are any domain objects which it is named for unambiguously, at this level of dropping qualifiers - const namedForAtThisQualifiersToDropLevel = - allDomainObjectNamesWithoutQualifiers.filter( - (name) => - isPropertyNamedAfterDomainObject({ - propertyName, - domainObjectName: name.withoutQualifiers, - }) || - isPropertyNamedAfterDomainObject({ - propertyName: propertyName.replace(/s$/, ''), // without trailing s - domainObjectName: name.withoutQualifiers, - }), - ); - - // if there is exactly one, job done - unambiguously specified - if (namedForAtThisQualifiersToDropLevel.length === 1) - return namedForAtThisQualifiersToDropLevel[0]!.withQualifiers; - - // if more than one, then its ambiguously specified - if (namedForAtThisQualifiersToDropLevel.length > 1) - throw new AmbiguouslyNamedDomainObjectReferencePropertyError({ - parentDomainObjectName, - propertyName, - ambiguousOptions: namedForAtThisQualifiersToDropLevel.map( - (name) => name.withQualifiers, - ), - }); + // determine all of the domain objects that are intuitively referenced by this property name + const intuitivelyReferencedDomainObjectNames = allDomainObjectNames.filter( + (domainObjectName) => + isPropertyNameAReferenceIntuitively({ propertyName, domainObjectName }), + ); - // otherwise, go another layer deeper and try again - qualifiersToDrop += 1; + // if more than one, then its ambiguously specified + if (intuitivelyReferencedDomainObjectNames.length > 1) + throw new AmbiguouslyNamedDomainObjectReferencePropertyError({ + parentDomainObjectName, + propertyName, + ambiguousOptions: intuitivelyReferencedDomainObjectNames, + }); - // safety check: if we passed more than 20 qualifiers, there's been some sort of error - if (qualifiersToDrop > 20) { - iterationLimitExceeded = true; // this is redundant, but feels better than having a `while(true)` defined - throw new Error( - 'attempted to drop more than 20 qualifiers. does someone really have 20 qualifiers on a name? this is probably a bug', - ); - } - } - throw new Error('something unexpected went wrong'); // we shouldn't reach here + // otherwise, there's either exactly one or none + return intuitivelyReferencedDomainObjectNames[0] ?? null; }; diff --git a/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/isPropertyNamedAfterDomainObject.test.ts b/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/isPropertyNamedAfterDomainObject.test.ts deleted file mode 100644 index 72f07f3..0000000 --- a/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/isPropertyNamedAfterDomainObject.test.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { isPropertyNamedAfterDomainObject } from './isPropertyNamedAfterDomainObject'; - -describe('isPropertyNamedAfterDomainObject', () => { - const cases: { - propertyName: string; - domainObjectName: string; - expectedResult: boolean; - }[] = [ - { - propertyName: 'address', - domainObjectName: 'Address', - expectedResult: true, - }, - { - propertyName: 'homeAddress', - domainObjectName: 'Address', - expectedResult: true, - }, - { - propertyName: 'home', - domainObjectName: 'Address', - expectedResult: false, - }, - { - propertyName: 'engineerUuid', - domainObjectName: 'Engineer', - expectedResult: true, - }, - { - propertyName: 'leadEngineerUuid', - domainObjectName: 'Engineer', - expectedResult: true, - }, - { - propertyName: 'engineerUuids', - domainObjectName: 'Engineer', - expectedResult: true, - }, - { - propertyName: 'assignedEngineerUuids', - domainObjectName: 'Engineer', - expectedResult: true, - }, - { - propertyName: 'lead', - domainObjectName: 'Engineer', - expectedResult: false, - }, - { - propertyName: 'leadUuid', - domainObjectName: 'Engineer', - expectedResult: false, - }, - { - propertyName: 'assignedUuids', - domainObjectName: 'Engineer', - expectedResult: false, - }, - ]; - - cases.forEach((testCase) => { - it(`should return ${testCase.expectedResult} for ${testCase.propertyName}: ${testCase.domainObjectName}`, () => { - expect( - isPropertyNamedAfterDomainObject({ - propertyName: testCase.propertyName, - domainObjectName: testCase.domainObjectName, - }), - ).toEqual(testCase.expectedResult); - }); - }); -}); diff --git a/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/isPropertyNamedAfterDomainObject.ts b/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/isPropertyNamedAfterDomainObject.ts deleted file mode 100644 index 5f99185..0000000 --- a/src/logic/define/sqlSchemaRelationship/getDomainObjectNameThatPropertyIsUnambigiouslyNaturallyNamedAfter/isPropertyNamedAfterDomainObject.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { camelCase, pascalCase } from 'change-case'; - -/** - * detects whether a property is named after a domain object - * - * for example: - * - `address: Address` => true - * - `homeAddress: Address` => true - * - `home: Address` => false - * - `engineerUuid: Engineer` => true - * - `leadEngineerUuid: Engineer` => true - * - `engineerUuids: Engineer` => true - * - `assignedEngineerUuids: Engineer` => true - * - `lead: Engineer` => false - * - `leadUuid: Engineer` => false - * - `assignedUuids: Engineer` => false - */ -export const isPropertyNamedAfterDomainObject = ({ - propertyName: propertyNamePotentiallyWithIrrelevantSuffixes, - domainObjectName, -}: { - propertyName: string; - domainObjectName: string; -}) => { - // remove the potential `uuid` or `uuids` suffix of the property name (used in implicit uuid references) - const propertyName = propertyNamePotentiallyWithIrrelevantSuffixes.replace( - /Uuids?$/, - '', - ); - - // check whether the property is exactly named after it - const namedAfterItExactly = camelCase(domainObjectName) === propertyName; - if (namedAfterItExactly) return true; - - // check whether the property is named after it as a suffix - const namedAfterItAsASuffix = new RegExp( - `${pascalCase(domainObjectName)}$`, - ).test(propertyName); // e.g., /Engineer$/.test('leadEngineer'); - if (namedAfterItAsASuffix) return true; - - // otherwise, false - return false; -};