From 96ee57ed2e22302e6397bbc897f252e2d50b0c9a Mon Sep 17 00:00:00 2001 From: kgajowy Date: Mon, 11 Oct 2021 10:44:02 +0200 Subject: [PATCH] feat(clone): rename clone-piece to export-component --- .../export/application/request-export.ts | 9 ++-- .../application/resource-pieces.port.ts | 7 ++- ....ts => export-component-finished.event.ts} | 2 +- ...ts => export-component-requested.event.ts} | 6 +-- .../domain/export/clone-part/clone-part.ts | 51 ------------------- .../domain/export/clone-part/piece.id.ts | 3 -- ...apshot.ts => export-component.snapshot.ts} | 2 +- .../component-location.ts} | 2 +- .../export/export-component/component.id.ts | 3 ++ .../export-component/export-component.ts | 51 +++++++++++++++++++ .../export/domain/export/export.snapshot.ts | 4 +- .../clone/export/domain/export/export.ts | 26 +++++----- 12 files changed, 86 insertions(+), 80 deletions(-) rename api/apps/api/src/modules/clone/export/domain/events/{clone-parts-finished.event.ts => export-component-finished.event.ts} (71%) rename api/apps/api/src/modules/clone/export/domain/events/{clone-part-requested.event.ts => export-component-requested.event.ts} (66%) delete mode 100644 api/apps/api/src/modules/clone/export/domain/export/clone-part/clone-part.ts delete mode 100644 api/apps/api/src/modules/clone/export/domain/export/clone-part/piece.id.ts rename api/apps/api/src/modules/clone/export/domain/export/{clone-part.snapshot.ts => export-component.snapshot.ts} (82%) rename api/apps/api/src/modules/clone/export/domain/export/{clone-part/piece-location.ts => export-component/component-location.ts} (63%) create mode 100644 api/apps/api/src/modules/clone/export/domain/export/export-component/component.id.ts create mode 100644 api/apps/api/src/modules/clone/export/domain/export/export-component/export-component.ts diff --git a/api/apps/api/src/modules/clone/export/application/request-export.ts b/api/apps/api/src/modules/clone/export/application/request-export.ts index 27016671b1..75e93731d8 100644 --- a/api/apps/api/src/modules/clone/export/application/request-export.ts +++ b/api/apps/api/src/modules/clone/export/application/request-export.ts @@ -1,8 +1,8 @@ -import { EventBus, EventPublisher } from '@nestjs/cqrs'; +import { EventPublisher } from '@nestjs/cqrs'; import { ResourceId } from '../domain/export/resource.id'; import { ResourceKind } from '../domain/export/resource.kind'; -import { ClonePart } from '../domain/export/clone-part/clone-part'; +import { ExportComponent } from '../domain/export/export-component/export-component'; import { Export } from '../domain/export/export'; import { ExportId } from '../domain/export/export.id'; @@ -17,7 +17,10 @@ export class RequestExport { ) {} async export(id: ResourceId, kind: ResourceKind): Promise { - const parts: ClonePart[] = await this.resourcePieces.resolveFor(id, kind); + const parts: ExportComponent[] = await this.resourcePieces.resolveFor( + id, + kind, + ); const exportInstance = this.eventPublisher.mergeObjectContext( Export.project(id, parts), ); diff --git a/api/apps/api/src/modules/clone/export/application/resource-pieces.port.ts b/api/apps/api/src/modules/clone/export/application/resource-pieces.port.ts index 3c7f719e7d..4c3e82739b 100644 --- a/api/apps/api/src/modules/clone/export/application/resource-pieces.port.ts +++ b/api/apps/api/src/modules/clone/export/application/resource-pieces.port.ts @@ -1,7 +1,10 @@ import { ResourceId } from '../domain/export/resource.id'; import { ResourceKind } from '../domain/export/resource.kind'; -import { ClonePart } from '../domain/export/clone-part/clone-part'; +import { ExportComponent } from '../domain/export/export-component/export-component'; export abstract class ResourcePieces { - abstract resolveFor(id: ResourceId, kind: ResourceKind): Promise; + abstract resolveFor( + id: ResourceId, + kind: ResourceKind, + ): Promise; } diff --git a/api/apps/api/src/modules/clone/export/domain/events/clone-parts-finished.event.ts b/api/apps/api/src/modules/clone/export/domain/events/export-component-finished.event.ts similarity index 71% rename from api/apps/api/src/modules/clone/export/domain/events/clone-parts-finished.event.ts rename to api/apps/api/src/modules/clone/export/domain/events/export-component-finished.event.ts index 5602703026..cbd60a4be1 100644 --- a/api/apps/api/src/modules/clone/export/domain/events/clone-parts-finished.event.ts +++ b/api/apps/api/src/modules/clone/export/domain/events/export-component-finished.event.ts @@ -1,6 +1,6 @@ import { IEvent } from '@nestjs/cqrs'; import { ExportId } from '../export/export.id'; -export class ClonePartsFinished implements IEvent { +export class ExportComponentFinished implements IEvent { constructor(public readonly exportId: ExportId) {} } diff --git a/api/apps/api/src/modules/clone/export/domain/events/clone-part-requested.event.ts b/api/apps/api/src/modules/clone/export/domain/events/export-component-requested.event.ts similarity index 66% rename from api/apps/api/src/modules/clone/export/domain/events/clone-part-requested.event.ts rename to api/apps/api/src/modules/clone/export/domain/events/export-component-requested.event.ts index 30ce8d18d4..80b2100d9b 100644 --- a/api/apps/api/src/modules/clone/export/domain/events/clone-part-requested.event.ts +++ b/api/apps/api/src/modules/clone/export/domain/events/export-component-requested.event.ts @@ -1,14 +1,14 @@ import { IEvent } from '@nestjs/cqrs'; import { ExportId } from '../export/export.id'; -import { PieceId } from '../export/clone-part/piece.id'; +import { ComponentId } from '../export/export-component/component.id'; import { ResourceId } from '../export/resource.id'; import { ClonePiece } from '../../../shared-kernel/clone-piece'; -export class ClonePartRequested implements IEvent { +export class ExportComponentRequested implements IEvent { constructor( public readonly exportId: ExportId, - public readonly pieceId: PieceId, + public readonly componentId: ComponentId, public readonly resourceId: ResourceId, public readonly piece: ClonePiece, ) {} diff --git a/api/apps/api/src/modules/clone/export/domain/export/clone-part/clone-part.ts b/api/apps/api/src/modules/clone/export/domain/export/clone-part/clone-part.ts deleted file mode 100644 index 13311dae73..0000000000 --- a/api/apps/api/src/modules/clone/export/domain/export/clone-part/clone-part.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { v4 } from 'uuid'; -import { ClonePiece } from '../../../../shared-kernel/clone-piece'; - -import { ResourceId } from '../resource.id'; -import { ClonePartSnapshot } from '../clone-part.snapshot'; - -import { PieceId } from './piece.id'; -import { PieceLocation } from './piece-location'; - -export class ClonePart { - private constructor( - readonly id: PieceId, - readonly piece: ClonePiece, - readonly resourceId: ResourceId, - private finished: boolean = false, - private uri?: PieceLocation, - ) {} - - static newOne(resourceId: ResourceId, piece: ClonePiece): ClonePart { - return new ClonePart(new PieceId(v4()), piece, resourceId); - } - - finish(location: PieceLocation) { - this.finished = true; - this.uri = location; - } - - isReady() { - return this.finished; - } - - toSnapshot(): ClonePartSnapshot { - return { - id: this.id.value, - piece: this.piece, - resourceId: this.resourceId.value, - finished: this.finished, - uri: this.uri?.value, - }; - } - - static fromSnapshot(snapshot: ClonePartSnapshot) { - return new ClonePart( - new PieceId(snapshot.id), - snapshot.piece, - new ResourceId(snapshot.resourceId), - snapshot.finished, - snapshot.uri ? new PieceLocation(snapshot.uri) : undefined, - ); - } -} diff --git a/api/apps/api/src/modules/clone/export/domain/export/clone-part/piece.id.ts b/api/apps/api/src/modules/clone/export/domain/export/clone-part/piece.id.ts deleted file mode 100644 index 73bda7880b..0000000000 --- a/api/apps/api/src/modules/clone/export/domain/export/clone-part/piece.id.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { TinyTypeOf } from 'tiny-types'; - -export class PieceId extends TinyTypeOf() {} diff --git a/api/apps/api/src/modules/clone/export/domain/export/clone-part.snapshot.ts b/api/apps/api/src/modules/clone/export/domain/export/export-component.snapshot.ts similarity index 82% rename from api/apps/api/src/modules/clone/export/domain/export/clone-part.snapshot.ts rename to api/apps/api/src/modules/clone/export/domain/export/export-component.snapshot.ts index c5a6f9cfed..4b717c265f 100644 --- a/api/apps/api/src/modules/clone/export/domain/export/clone-part.snapshot.ts +++ b/api/apps/api/src/modules/clone/export/domain/export/export-component.snapshot.ts @@ -1,6 +1,6 @@ import { ClonePiece } from '../../../shared-kernel/clone-piece'; -export interface ClonePartSnapshot { +export interface ExportComponentSnapshot { readonly id: string; readonly piece: ClonePiece; readonly resourceId: string; diff --git a/api/apps/api/src/modules/clone/export/domain/export/clone-part/piece-location.ts b/api/apps/api/src/modules/clone/export/domain/export/export-component/component-location.ts similarity index 63% rename from api/apps/api/src/modules/clone/export/domain/export/clone-part/piece-location.ts rename to api/apps/api/src/modules/clone/export/domain/export/export-component/component-location.ts index daef4ea59c..759adb8da2 100644 --- a/api/apps/api/src/modules/clone/export/domain/export/clone-part/piece-location.ts +++ b/api/apps/api/src/modules/clone/export/domain/export/export-component/component-location.ts @@ -3,4 +3,4 @@ import { TinyTypeOf } from 'tiny-types'; /** * a URI pointing at the given Piece, whatever format it is */ -export class PieceLocation extends TinyTypeOf() {} +export class ComponentLocation extends TinyTypeOf() {} diff --git a/api/apps/api/src/modules/clone/export/domain/export/export-component/component.id.ts b/api/apps/api/src/modules/clone/export/domain/export/export-component/component.id.ts new file mode 100644 index 0000000000..b8fd4d2437 --- /dev/null +++ b/api/apps/api/src/modules/clone/export/domain/export/export-component/component.id.ts @@ -0,0 +1,3 @@ +import { TinyTypeOf } from 'tiny-types'; + +export class ComponentId extends TinyTypeOf() {} diff --git a/api/apps/api/src/modules/clone/export/domain/export/export-component/export-component.ts b/api/apps/api/src/modules/clone/export/domain/export/export-component/export-component.ts new file mode 100644 index 0000000000..a14e143761 --- /dev/null +++ b/api/apps/api/src/modules/clone/export/domain/export/export-component/export-component.ts @@ -0,0 +1,51 @@ +import { v4 } from 'uuid'; +import { ClonePiece } from '../../../../shared-kernel/clone-piece'; + +import { ResourceId } from '../resource.id'; +import { ExportComponentSnapshot } from '../export-component.snapshot'; + +import { ComponentId } from './component.id'; +import { ComponentLocation } from './component-location'; + +export class ExportComponent { + private constructor( + readonly id: ComponentId, + readonly piece: ClonePiece, + readonly resourceId: ResourceId, + private finished: boolean = false, + private uri?: ComponentLocation, + ) {} + + static newOne(resourceId: ResourceId, piece: ClonePiece): ExportComponent { + return new ExportComponent(new ComponentId(v4()), piece, resourceId); + } + + finish(location: ComponentLocation) { + this.finished = true; + this.uri = location; + } + + isReady() { + return this.finished; + } + + toSnapshot(): ExportComponentSnapshot { + return { + id: this.id.value, + piece: this.piece, + resourceId: this.resourceId.value, + finished: this.finished, + uri: this.uri?.value, + }; + } + + static fromSnapshot(snapshot: ExportComponentSnapshot) { + return new ExportComponent( + new ComponentId(snapshot.id), + snapshot.piece, + new ResourceId(snapshot.resourceId), + snapshot.finished, + snapshot.uri ? new ComponentLocation(snapshot.uri) : undefined, + ); + } +} diff --git a/api/apps/api/src/modules/clone/export/domain/export/export.snapshot.ts b/api/apps/api/src/modules/clone/export/domain/export/export.snapshot.ts index 3f41d86f50..aa3739a794 100644 --- a/api/apps/api/src/modules/clone/export/domain/export/export.snapshot.ts +++ b/api/apps/api/src/modules/clone/export/domain/export/export.snapshot.ts @@ -1,10 +1,10 @@ import { ResourceKind } from './resource.kind'; -import { ClonePartSnapshot } from './clone-part.snapshot'; +import { ExportComponentSnapshot } from './export-component.snapshot'; export interface ExportSnapshot { id: string; resourceId: string; resourceKind: ResourceKind; archiveLocation?: string; - exportPieces: ClonePartSnapshot[]; + exportPieces: ExportComponentSnapshot[]; } diff --git a/api/apps/api/src/modules/clone/export/domain/export/export.ts b/api/apps/api/src/modules/clone/export/domain/export/export.ts index fb825a7ba7..808d2ade91 100644 --- a/api/apps/api/src/modules/clone/export/domain/export/export.ts +++ b/api/apps/api/src/modules/clone/export/domain/export/export.ts @@ -7,13 +7,13 @@ import { ExportId } from './export.id'; import { ResourceId } from './resource.id'; import { ArchiveLocation } from './archive-location'; -import { ClonePartRequested } from '../events/clone-part-requested.event'; -import { ClonePartsFinished } from '../events/clone-parts-finished.event'; +import { ExportComponentRequested } from '../events/export-component-requested.event'; +import { ExportComponentFinished } from '../events/export-component-finished.event'; import { ArchiveReady } from '../events/archive-ready.event'; -import { PieceLocation } from './clone-part/piece-location'; -import { ClonePart } from './clone-part/clone-part'; -import { PieceId } from './clone-part/piece.id'; +import { ComponentLocation } from './export-component/component-location'; +import { ExportComponent } from './export-component/export-component'; +import { ComponentId } from './export-component/component.id'; import { ExportSnapshot } from './export.snapshot'; export const pieceNotFound = Symbol('export piece not found'); @@ -24,13 +24,13 @@ export class Export extends AggregateRoot { public readonly id: ExportId, public readonly resourceId: ResourceId, public readonly resourceKind: ResourceKind, - public readonly pieces: ClonePart[], + public readonly pieces: ExportComponent[], private archiveLocation?: ArchiveLocation, ) { super(); } - static project(id: ResourceId, parts: ClonePart[]): Export { + static project(id: ResourceId, parts: ExportComponent[]): Export { const exportRequest = new Export( new ExportId(v4()), id, @@ -43,7 +43,7 @@ export class Export extends AggregateRoot { .filter((part) => !part.isReady()) .map( (part) => - new ClonePartRequested( + new ExportComponentRequested( exportRequest.id, part.id, part.resourceId, @@ -55,9 +55,9 @@ export class Export extends AggregateRoot { return exportRequest; } - completePiece( - id: PieceId, - pieceLocation: PieceLocation, + completeComponent( + id: ComponentId, + pieceLocation: ComponentLocation, ): Either { const piece = this.pieces.find((piece) => piece.id.equals(id)); if (!piece) { @@ -66,7 +66,7 @@ export class Export extends AggregateRoot { piece.finish(pieceLocation); if (this.#allPiecesReady()) { - this.apply(new ClonePartsFinished(this.id)); + this.apply(new ExportComponentFinished(this.id)); } return right(true); @@ -96,7 +96,7 @@ export class Export extends AggregateRoot { new ExportId(snapshot.id), new ResourceId(snapshot.resourceId), snapshot.resourceKind, - snapshot.exportPieces.map((piece) => ClonePart.fromSnapshot(piece)), + snapshot.exportPieces.map((piece) => ExportComponent.fromSnapshot(piece)), snapshot.archiveLocation ? new ArchiveLocation(snapshot.archiveLocation) : undefined,