Skip to content

Commit

Permalink
feat(clone): rename clone-piece to export-component
Browse files Browse the repository at this point in the history
  • Loading branch information
kgajowy committed Oct 11, 2021
1 parent 99777f0 commit 96ee57e
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -17,7 +17,10 @@ export class RequestExport {
) {}

async export(id: ResourceId, kind: ResourceKind): Promise<ExportId> {
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),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ClonePart[]>;
abstract resolveFor(
id: ResourceId,
kind: ResourceKind,
): Promise<ExportComponent[]>;
}
Original file line number Diff line number Diff line change
@@ -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) {}
}
Original file line number Diff line number Diff line change
@@ -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,
) {}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>() {}
export class ComponentLocation extends TinyTypeOf<string>() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { TinyTypeOf } from 'tiny-types';

export class ComponentId extends TinyTypeOf<string>() {}
Original file line number Diff line number Diff line change
@@ -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,
);
}
}
Original file line number Diff line number Diff line change
@@ -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[];
}
26 changes: 13 additions & 13 deletions api/apps/api/src/modules/clone/export/domain/export/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -55,9 +55,9 @@ export class Export extends AggregateRoot {
return exportRequest;
}

completePiece(
id: PieceId,
pieceLocation: PieceLocation,
completeComponent(
id: ComponentId,
pieceLocation: ComponentLocation,
): Either<typeof pieceNotFound, true> {
const piece = this.pieces.find((piece) => piece.id.equals(id));
if (!piece) {
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 96ee57e

Please sign in to comment.