Skip to content

Commit

Permalink
correct cycle typestack#358, by extracting TransformationType in a se…
Browse files Browse the repository at this point in the history
…parate file

because:
    * TransformationType enum is used by both TransformOperationExecutor  and MetadataStorage
    * TransformationType was in the same file as TransformOperationExecutor
    * TransformOperationExecutor require MetadataStorage
so: importing TransformationType from TransformOperationExecutor.ts was as a side effect importing MetadataStorage.ts that was importing TransformationType etc. creating a cycle
  • Loading branch information
allan-simon committed Jul 29, 2020
1 parent b8f4c47 commit 8c100bb
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/ClassTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ClassTransformOptions } from './ClassTransformOptions';
import { TransformOperationExecutor, TransformationType } from './TransformOperationExecutor';

import { TransformOperationExecutor } from './TransformOperationExecutor';
import { TransformationType } from './TransformationType';
export type ClassType<T> = {
new (...args: any[]): T;
};
Expand Down
7 changes: 1 addition & 6 deletions src/TransformOperationExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { ClassTransformOptions } from './ClassTransformOptions';
import { defaultMetadataStorage } from './storage';
import { TypeHelpOptions, TypeOptions } from './metadata/ExposeExcludeOptions';
import { TypeMetadata } from './metadata/TypeMetadata';

export enum TransformationType {
PLAIN_TO_CLASS,
CLASS_TO_PLAIN,
CLASS_TO_CLASS,
}
import { TransformationType } from './TransformationType';

export function testForBuffer(): boolean {
try {
Expand Down
5 changes: 5 additions & 0 deletions src/TransformationType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum TransformationType {
PLAIN_TO_CLASS,
CLASS_TO_PLAIN,
CLASS_TO_CLASS
}
2 changes: 1 addition & 1 deletion src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { ExcludeMetadata } from './metadata/ExcludeMetadata';
import { TransformMetadata } from './metadata/TransformMetadata';
import { ClassTransformOptions } from './ClassTransformOptions';
import { TransformationType } from './TransformOperationExecutor';
import { TransformationType } from './TransformationType';

/**
* Defines a custom logic for value transformation.
Expand Down
2 changes: 1 addition & 1 deletion src/metadata/MetadataStorage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TypeMetadata } from './TypeMetadata';
import { ExposeMetadata } from './ExposeMetadata';
import { ExcludeMetadata } from './ExcludeMetadata';
import { TransformationType } from '../TransformOperationExecutor';
import { TransformationType } from '../TransformationType';
import { TransformMetadata } from './TransformMetadata';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/metadata/TransformMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TransformOptions } from './ExposeExcludeOptions';
import { TransformationType } from '../TransformOperationExecutor';
import { TransformationType } from '../TransformationType';

export class TransformMetadata {
constructor(
Expand Down
2 changes: 1 addition & 1 deletion test/functional/custom-transform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'reflect-metadata';
import { classToClass, classToPlain, plainToClass } from '../../src/index';
import { defaultMetadataStorage } from '../../src/storage';
import { Expose, Transform, Type } from '../../src/decorators';
import { TransformationType } from '../../src/TransformOperationExecutor';
import { TransformationType } from '../../src/TransformationType';
import dayjs from 'dayjs';

describe('custom transformation decorator', () => {
Expand Down

0 comments on commit 8c100bb

Please sign in to comment.