-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(normalization): require users to explicitly state that entity is…
… unique on uuid, disallow entity.unique.length = 0
- Loading branch information
1 parent
9614e24
commit 614a804
Showing
7 changed files
with
67 additions
and
26 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
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
2 changes: 1 addition & 1 deletion
2
...enerateSchema/normalizeDeclarationContents/throwErrorIfAnyReservedPropertyNamesAreUsed.ts
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
3 changes: 2 additions & 1 deletion
3
...ose/generateSchema/normalizeDeclarationContents/throwErrorIfAnyUniqueIsNotInProperties.ts
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
25 changes: 25 additions & 0 deletions
25
...mpose/generateSchema/normalizeDeclarationContents/throwErrorIfNotUniqueOnAnything.test.ts
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Entity } from '../../../../types'; | ||
import { prop } from '../../../define'; | ||
import { throwErrorIfNotUniqueOnAnything } from './throwErrorIfNotUniqueOnAnything'; | ||
|
||
describe('throwErrorIfNotUniqueOnAnything', () => { | ||
it('should throw an error if entity.unique is empty', () => { | ||
const user = new Entity({ | ||
name: 'user', | ||
properties: { | ||
phone_number: prop.VARCHAR(255), | ||
first_name: prop.VARCHAR(255), | ||
last_name: prop.VARCHAR(255), | ||
}, | ||
unique: [], // note the misspelling | ||
}); | ||
try { | ||
throwErrorIfNotUniqueOnAnything({ entity: user }); | ||
throw new Error('should not reach here'); | ||
} catch (error) { | ||
expect(error.message).toEqual( | ||
"Entity 'user' must be unique on atleast one property. If it is not unique on any natural keys, you can make it unique on the autogenerated 'uuid' property instead.", | ||
); | ||
} | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
...ic/compose/generateSchema/normalizeDeclarationContents/throwErrorIfNotUniqueOnAnything.ts
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Entity } from '../../../../types'; | ||
|
||
export const throwErrorIfNotUniqueOnAnything = ({ entity }: { entity: Entity }) => { | ||
if (entity.unique.length === 0) { | ||
throw new Error( | ||
`Entity '${entity.name}' must be unique on atleast one property. If it is not unique on any natural keys, you can make it unique on the autogenerated 'uuid' property instead.`, | ||
); | ||
} | ||
}; |