-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ResourceTypeSupports decorator
- Loading branch information
thomas.nisolle-ext
committed
Feb 3, 2022
1 parent
446248a
commit e4b470f
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
projects/ngx-repository/src/lib/core/decorator/resource-type-supports.decorator.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'reflect-metadata'; | ||
import { Id, ID_METADATA_KEY } from './id.decorator'; | ||
import { COLUMNS_METADATA_KEY } from './column.decorator'; | ||
import {ColumnContextConfiguration} from '../configuration/context/column-context.configuration'; | ||
import {IdContext} from '../configuration/context/id-context.configuration'; | ||
import { RESOURCE_TYPE_SUPPORTS_METADATA_KEY, ResourceTypeSupports } from './resource-type-supports.decorator'; | ||
|
||
describe('ResourceTypeSupportsDecorator', () => { | ||
function resourceTypeSupportsFunction(data: any): boolean { | ||
return !!data; | ||
} | ||
|
||
@ResourceTypeSupports(resourceTypeSupportsFunction) | ||
class MyClass {} | ||
|
||
it('should place all ResourceTypeSupportsContext parameter in the good place', () => { | ||
expect(Reflect.getMetadata(RESOURCE_TYPE_SUPPORTS_METADATA_KEY, MyClass)).toEqual(resourceTypeSupportsFunction); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
projects/ngx-repository/src/lib/core/decorator/resource-type-supports.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { JsonTypeSupports } from '@witty-services/ts-serializer'; | ||
import { JSON_TYPE_SUPPORTS_METADATA_KEY } from '@witty-services/ts-serializer/dist/decorator/json-type-supports.decorator'; | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
export const RESOURCE_TYPE_SUPPORTS_METADATA_KEY: string = JSON_TYPE_SUPPORTS_METADATA_KEY; | ||
|
||
export function ResourceTypeSupports(resourceTypeSupportsContext?: (data: any) => boolean): any { | ||
return (target: any) => { | ||
JsonTypeSupports(resourceTypeSupportsContext)(target); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters