-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: field id should be unique rule
- Loading branch information
Showing
7 changed files
with
40 additions
and
14 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
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
23 changes: 23 additions & 0 deletions
23
packages/table/src/modules/schema/rules/field-id-should-be-unique.rule.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,23 @@ | ||
import { DomainRules, ExceptionBase } from "@undb/domain" | ||
import type { Schema } from "../schema.vo" | ||
|
||
class FieldIdShouldBeUniqueError extends ExceptionBase { | ||
code = "table:FIELD_ID_SHOULD_BE_UNIQUE" | ||
|
||
constructor() { | ||
super("Field id should be unique") | ||
} | ||
} | ||
|
||
export class FieldIdShouldBeUnique extends DomainRules<FieldIdShouldBeUniqueError> { | ||
constructor(private readonly schema: Schema) { | ||
super() | ||
} | ||
|
||
override err = new FieldIdShouldBeUniqueError() | ||
|
||
override isBroken(): boolean { | ||
const ids = this.schema.fields.map((field) => field.id.value) | ||
return new Set(ids).size !== ids.length | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./field-id-should-be-unique.rule" | ||
export * from "./field-name-should-be-unique.rule" |
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