-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to use string IDs for executables #262
This commit unifies the concepts of executables having same ID structure. It paves the way for more complex ID structure and using IDs in collection files as part of new ID solution (#262). Using string IDs also leads to more expressive test code. This commit also refactors the rest of the code to adopt to the changes. This commit: - Separate concerns from entities for data access (in repositories) and executables. Executables use `Identifiable` meanwhile repositories use `RepositoryEntity`. - Refactor unnecessary generic parameters for enttities and ids, enforcing string gtype everwyhere. - Changes numeric IDs to string IDs for categories to unify the retrieval and construction for executables, using pseudo-ids (their names) just like scripts. - Remove `BaseEntity` for simplicity. - Simplify usage and construction of executable objects. Move factories responsible for creation of category/scripts to domain layer. Do not longer export `CollectionCategorY` and `CollectionScript`. - Use named typed for string IDs for better differentation of different ID contexts in code.
- Loading branch information
1 parent
19ea8db
commit 48d6dbd
Showing
96 changed files
with
1,409 additions
and
1,101 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
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
src/application/Context/State/Filter/Strategy/FilterStrategy.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
2 changes: 1 addition & 1 deletion
2
src/application/Context/State/Filter/Strategy/LinearFilterStrategy.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
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
6 changes: 2 additions & 4 deletions
6
src/application/Context/State/Selection/Script/SelectedScript.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 |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import type { IEntity } from '@/infrastructure/Entity/IEntity'; | ||
import type { Script } from '@/domain/Executables/Script/Script'; | ||
import type { RepositoryEntity } from '@/application/Repository/RepositoryEntity'; | ||
|
||
type ScriptId = Script['id']; | ||
|
||
export interface SelectedScript extends IEntity<ScriptId> { | ||
export interface SelectedScript extends RepositoryEntity { | ||
readonly script: Script; | ||
readonly revert: boolean; | ||
} |
11 changes: 5 additions & 6 deletions
11
src/application/Context/State/Selection/Script/UserSelectedScript.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 |
---|---|---|
@@ -1,17 +1,16 @@ | ||
import { BaseEntity } from '@/infrastructure/Entity/BaseEntity'; | ||
import type { Script } from '@/domain/Executables/Script/Script'; | ||
import type { SelectedScript } from './SelectedScript'; | ||
import type { RepositoryEntity } from '@/application/Repository/RepositoryEntity'; | ||
|
||
type SelectedScriptId = SelectedScript['id']; | ||
export class UserSelectedScript implements RepositoryEntity { | ||
public readonly id: string; | ||
|
||
export class UserSelectedScript extends BaseEntity<SelectedScriptId> { | ||
constructor( | ||
public readonly script: Script, | ||
public readonly revert: boolean, | ||
) { | ||
super(script.id); | ||
this.id = script.executableId; | ||
if (revert && !script.canRevert()) { | ||
throw new Error(`The script with ID '${script.id}' is not reversible and cannot be reverted.`); | ||
throw new Error(`The script with ID '${script.executableId}' is not reversible and cannot be reverted.`); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import type { IEntity } from '@/infrastructure/Entity/IEntity'; | ||
import type { RepositoryEntity } from './RepositoryEntity'; | ||
|
||
export interface ReadonlyRepository<TKey, TEntity extends IEntity<TKey>> { | ||
type EntityId = RepositoryEntity['id']; | ||
|
||
export interface ReadonlyRepository<TEntity extends RepositoryEntity> { | ||
readonly length: number; | ||
getItems(predicate?: (entity: TEntity) => boolean): readonly TEntity[]; | ||
getById(id: TKey): TEntity; | ||
exists(id: TKey): boolean; | ||
getById(id: EntityId): TEntity; | ||
exists(id: EntityId): boolean; | ||
} | ||
|
||
export interface MutableRepository<TKey, TEntity extends IEntity<TKey>> { | ||
export interface MutableRepository<TEntity extends RepositoryEntity> { | ||
addItem(item: TEntity): void; | ||
addOrUpdateItem(item: TEntity): void; | ||
removeItem(id: TKey): void; | ||
removeItem(id: EntityId): void; | ||
} | ||
|
||
export interface Repository<TKey, TEntity extends IEntity<TKey>> | ||
extends ReadonlyRepository<TKey, TEntity>, MutableRepository<TKey, TEntity> { } | ||
export interface Repository<TEntity extends RepositoryEntity> | ||
extends ReadonlyRepository<TEntity>, MutableRepository<TEntity> { } |
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,6 @@ | ||
/** Aggregate root */ | ||
export type RepositoryEntityId = string; | ||
|
||
export interface RepositoryEntity { | ||
readonly id: RepositoryEntityId; | ||
} |
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.