Skip to content

Commit

Permalink
feat: add layer and kind to FeatureHObjectMetas
Browse files Browse the repository at this point in the history
  • Loading branch information
Mararok committed Sep 24, 2024
1 parent 3b6d1ac commit b151389
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 43 deletions.
15 changes: 9 additions & 6 deletions src/Util/Feature/Meta/CommonFeatureMeta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { JsonSerialize } from "@hexancore/common";
import type { JsonSerialize, HFeatureBackendLayer } from "@hexancore/common";

export interface FeatureClassMeta {
name: string;
Expand All @@ -10,7 +10,7 @@ export interface FeatureClassMeta {
filePath: string;
}

export enum HObjectType {
export enum HObjectKind {
Command = 'Command',
Query = 'Query',
Event = 'Event',
Expand All @@ -24,18 +24,21 @@ export interface FeatureHObjectMeta extends FeatureClassMeta, JsonSerialize {
context: string;
className: string;
get hashData(): string;
get objectType(): HObjectType;
get kind(): HObjectKind;
get layer(): HFeatureBackendLayer;
}

export type FeatureHObjectMap = Map<string, FeatureHObjectMeta>;

export class FeatureDtoMeta implements FeatureHObjectMeta {
public layer: HFeatureBackendLayer;

public constructor(
public name: string,
public context: string,
public path: string,
) {

this.layer = path.split('/')[0].toLowerCase() as HFeatureBackendLayer;
}

public static parse(plain: unknown): FeatureDtoMeta {
Expand All @@ -51,8 +54,8 @@ export class FeatureDtoMeta implements FeatureHObjectMeta {
return this.path + '.ts';
}

public get objectType(): HObjectType {
return HObjectType.Dto;
public get kind(): HObjectKind.Dto {
return HObjectKind.Dto;
}

public get hashData(): string {
Expand Down
22 changes: 16 additions & 6 deletions src/Util/Feature/Meta/FeatureApplicationMeta.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type JsonSerialize, LogicError } from "@hexancore/common";
import { FeatureClassMeta, FeatureDtoMeta, FeatureHObjectMap, FeatureHObjectMeta, HObjectType } from "./CommonFeatureMeta";
import { type JsonSerialize, LogicError, HFeatureBackendLayer } from "@hexancore/common";
import { FeatureClassMeta, FeatureDtoMeta, FeatureHObjectMap, FeatureHObjectMeta, HObjectKind } from "./CommonFeatureMeta";

export interface FeatureApplicationMessageMeta extends FeatureHObjectMeta {
handlerClass: string;
Expand Down Expand Up @@ -28,14 +28,20 @@ export class FeatureApplicationCommandMeta implements FeatureApplicationMessageM
return this.path + '/' + this.className + '.ts';
}

public get objectType(): HObjectType.Command {
return HObjectType.Command;
public get kind(): HObjectKind.Command {
return HObjectKind.Command;
}

public get layer(): HFeatureBackendLayer {
return 'application';
}

public get hashData(): string {
return this.path;
}



public toJSON(): any {
return {
name: this.name,
Expand Down Expand Up @@ -67,8 +73,12 @@ export class FeatureApplicationQueryMeta implements FeatureApplicationMessageMet
return this.path + '/' + this.className + '.ts';
}

public get objectType(): HObjectType.Query {
return HObjectType.Query;
public get kind(): HObjectKind.Query {
return HObjectKind.Query;
}

public get layer(): HFeatureBackendLayer {
return 'application';
}

public get hashData(): string {
Expand Down
30 changes: 21 additions & 9 deletions src/Util/Feature/Meta/FeatureDomainMeta.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LogicError } from "@hexancore/common";
import { FeatureHObjectMeta, HObjectType, type FeatureHObjectMap } from "./CommonFeatureMeta";
import { LogicError, HFeatureBackendLayer } from "@hexancore/common";
import { FeatureHObjectMeta, HObjectKind, type FeatureHObjectMap} from "./CommonFeatureMeta";

export class FeatureAggregateRootMeta implements FeatureHObjectMeta {
public repositoryName: string;
Expand Down Expand Up @@ -38,8 +38,12 @@ export class FeatureAggregateRootMeta implements FeatureHObjectMeta {
return this.name;
}

public get objectType(): HObjectType {
return HObjectType.AggregateRoot;
public get kind(): HObjectKind.AggregateRoot {
return HObjectKind.AggregateRoot;
}

public get layer(): HFeatureBackendLayer {
return 'domain';
}

public get hashData(): string {
Expand Down Expand Up @@ -88,8 +92,12 @@ export class FeatureEntityMeta implements FeatureHObjectMeta {
return this.aggregateRootName;
}

public get objectType(): HObjectType {
return HObjectType.Entity;
public get kind(): HObjectKind.Entity {
return HObjectKind.Entity;
}

public get layer(): HFeatureBackendLayer {
return 'domain';
}

public get hashData(): string {
Expand Down Expand Up @@ -133,14 +141,18 @@ export class FeatureValueObjectMeta implements FeatureHObjectMeta {
return this.name;
}

public get objectType(): HObjectType.ValueObject {
return HObjectType.ValueObject;
public get kind(): HObjectKind.ValueObject {
return HObjectKind.ValueObject;
}

public get hashData(): string {
return this.path;
}

public get layer(): HFeatureBackendLayer {
return 'domain';
}

public toJSON(): any {
return {
name: this.name,
Expand All @@ -164,7 +176,7 @@ export class FeatureDomainMeta {
const data = plain as Record<string, any[]>;
const aggregateRoots = data.aggregateRoots.map(FeatureAggregateRootMeta.parse);
const valueObjects = data.valueObjects.map(FeatureValueObjectMeta.parse);
return new FeatureDomainMeta (aggregateRoots, valueObjects);
return new FeatureDomainMeta(aggregateRoots, valueObjects);
}

public collectHObjects(map: FeatureHObjectMap): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ describe(FeatureModuleTsTransformer.constructor.name, () => {

expect(out.outputText).toMatchSnapshot();
});

test.skip("transform HObject: Command", () => {
const sourceFilePath = process.cwd() + "/test/helper/libs/test-lib/src/Book/Application/Book/Command/Create/BookCreateCommand.ts";

const out = helper.transpileModule(transformer.transform.bind(transformer), sourceFilePath);

expect(out.outputText).toMatchSnapshot();
});

});


Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,3 @@ exports.BookModule = BookModule = tslib_1.__decorate([
], BookModule);
//# sourceMappingURL=BookModule.js.map"
`;

exports[`Function transform HObject: Command 1`] = `
""use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BookCreateCommand = void 0;
class BookCreateCommand {
constructor(title) {
this.title = title;
}
}
exports.BookCreateCommand = BookCreateCommand;
//# sourceMappingURL=BookCreateCommand.js.map"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ exports[`Function hObjectMap 1`] = `
name: BookDto
context: Book
path: Application/Book/Dto/BookDto
layer: application
Application/Book/Dto/TestTransformDto.ts:
name: TestTransformDto
context: Book
path: Application/Book/Dto/TestTransformDto
layer: application
Domain/Book/Shared/ValueObject/BookCopyId.ts:
name: BookCopyId
context: Book
Expand Down

0 comments on commit b151389

Please sign in to comment.