-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ConstraintExecutorRegistry to JayveeConstraintExtension
- Loading branch information
1 parent
3c7bedb
commit b429e51
Showing
12 changed files
with
115 additions
and
125 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
77 changes: 77 additions & 0 deletions
77
libs/execution/src/lib/constraints/constraint-executor-extension.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,77 @@ | ||
// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
import { strict as assert } from 'assert'; | ||
|
||
import { | ||
ConstraintDefinition, | ||
Registry, | ||
isExpressionConstraintDefinition, | ||
isTypedConstraintDefinition, | ||
} from '@jvalue/jayvee-language-server'; | ||
import { assertUnreachable } from 'langium'; | ||
|
||
import { ConstraintExecutor } from './constraint-executor'; | ||
import { AllowlistConstraintExecutor } from './executors/allowlist-constraint-executor'; | ||
import { DenylistConstraintExecutor } from './executors/denylist-constraint-executor'; | ||
import { ExpressionConstraintExecutor } from './executors/expression-constraint-executor'; | ||
import { LengthConstraintExecutor } from './executors/length-constraint-executor'; | ||
import { RangeConstraintExecutor } from './executors/range-constraint-executor'; | ||
import { RegexConstraintExecutor } from './executors/regex-constraint-executor'; | ||
import { TypedConstraintExecutorClass } from './typed-constraint-executor-class'; | ||
|
||
export interface JayveeConstraintExtension { | ||
registerConstraintExecutor(executorClass: TypedConstraintExecutorClass): void; | ||
|
||
getConstraintExecutors(): TypedConstraintExecutorClass<ConstraintExecutor>[]; | ||
|
||
createConstraintExecutor( | ||
constraint: ConstraintDefinition, | ||
): ConstraintExecutor; | ||
} | ||
|
||
export class DefaultConstraintExtension | ||
extends Registry<TypedConstraintExecutorClass> | ||
implements JayveeConstraintExtension | ||
{ | ||
constructor() { | ||
super(); | ||
|
||
this.registerConstraintExecutor(AllowlistConstraintExecutor); | ||
this.registerConstraintExecutor(DenylistConstraintExecutor); | ||
this.registerConstraintExecutor(RegexConstraintExecutor); | ||
this.registerConstraintExecutor(LengthConstraintExecutor); | ||
this.registerConstraintExecutor(RangeConstraintExecutor); | ||
} | ||
|
||
registerConstraintExecutor(executorClass: TypedConstraintExecutorClass) { | ||
this.register(executorClass.type, executorClass); | ||
} | ||
|
||
getConstraintExecutors() { | ||
return this.getAll(); | ||
} | ||
|
||
createConstraintExecutor( | ||
constraint: ConstraintDefinition, | ||
): ConstraintExecutor { | ||
if (isTypedConstraintDefinition(constraint)) { | ||
const constraintType = constraint.type.ref?.name; | ||
assert( | ||
constraintType !== undefined, | ||
`Could not resolve reference to constraint type of ${constraint.name}`, | ||
); | ||
const constraintExecutor = this.get(constraintType); | ||
assert( | ||
constraintExecutor !== undefined, | ||
`No executor was registered for constraint type ${constraintType}`, | ||
); | ||
|
||
return new constraintExecutor(); | ||
} else if (isExpressionConstraintDefinition(constraint)) { | ||
return new ExpressionConstraintExecutor(constraint); | ||
} | ||
assertUnreachable(constraint); | ||
} | ||
} |
65 changes: 0 additions & 65 deletions
65
libs/execution/src/lib/constraints/constraint-executor-registry.ts
This file was deleted.
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
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
Oops, something went wrong.