Skip to content

Commit

Permalink
feat(mvc): Add PropertyFn decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed May 24, 2019
1 parent f81dce1 commit 565ab93
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/common/src/jsonschema/decorators/ignoreProperty.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {PropertyFn} from "@tsed/common";
import {PropertyMetadata} from "../class/PropertyMetadata";
import {PropertyRegistry} from "../registries/PropertyRegistry";

/**
* Disable serialization for this property when the Converters service will render the JSON object.
Expand Down Expand Up @@ -63,7 +63,7 @@ import {PropertyRegistry} from "../registries/PropertyRegistry";
* @converters
*/
export function IgnoreProperty() {
return PropertyRegistry.decorate((propertyMetadata: PropertyMetadata) => {
return PropertyFn((propertyMetadata: PropertyMetadata) => {
propertyMetadata.ignoreProperty = true;
});
}
8 changes: 6 additions & 2 deletions packages/common/src/jsonschema/decorators/jsonProperty.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isEmpty, Type} from "@tsed/core";
import {DecoratorParameters, isEmpty, Type} from "@tsed/core";
import {IPropertyOptions} from "../../converters/interfaces/IPropertyOptions";
import {PropertyMetadata} from "../class/PropertyMetadata";
import {PropertyRegistry} from "../registries/PropertyRegistry";
Expand Down Expand Up @@ -91,7 +91,7 @@ import {PropertyRegistry} from "../registries/PropertyRegistry";
* @converters
*/
export function JsonProperty(options?: IPropertyOptions | string): Function {
return PropertyRegistry.decorate((propertyMetadata: PropertyMetadata) => {
return PropertyFn((propertyMetadata: PropertyMetadata) => {
if (typeof options === "string") {
propertyMetadata.name = options as string;
} else if (typeof options === "object") {
Expand Down Expand Up @@ -192,3 +192,7 @@ export function JsonProperty(options?: IPropertyOptions | string): Function {
export function Property(options?: IPropertyOptions | string) {
return JsonProperty(options);
}

export function PropertyFn(fn: (propertyMetadata: PropertyMetadata, parameters: DecoratorParameters) => void): Function {
return PropertyRegistry.decorate(fn);
}
4 changes: 2 additions & 2 deletions packages/common/src/jsonschema/decorators/propertyName.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {PropertyMetadata} from "../class/PropertyMetadata";
import {PropertyRegistry} from "../registries/PropertyRegistry";
import {PropertyFn} from "./jsonProperty";

/**
* Create an alias of the propertyKey that must be used by the converter.
Expand All @@ -23,7 +23,7 @@ import {PropertyRegistry} from "../registries/PropertyRegistry";
* @converters
*/
export function PropertyName(name: string) {
return PropertyRegistry.decorate((propertyMetadata: PropertyMetadata) => {
return PropertyFn((propertyMetadata: PropertyMetadata) => {
propertyMetadata.name = name;
});
}
4 changes: 2 additions & 2 deletions packages/common/src/jsonschema/decorators/propertyType.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Type} from "@tsed/core";
import {PropertyMetadata} from "../class/PropertyMetadata";
import {PropertyRegistry} from "../registries/PropertyRegistry";
import {PropertyFn} from "./jsonProperty";

/**
* Set the type of the array items. The possible value is String, Boolean, Number, Date, Object, Class, etc...
Expand Down Expand Up @@ -44,7 +44,7 @@ import {PropertyRegistry} from "../registries/PropertyRegistry";
* @converters
*/
export function PropertyType(type: Type<any>) {
return PropertyRegistry.decorate((propertyMetadata: PropertyMetadata) => {
return PropertyFn((propertyMetadata: PropertyMetadata) => {
propertyMetadata.type = type;
});
}

0 comments on commit 565ab93

Please sign in to comment.