Skip to content

Commit

Permalink
feat: Add ResourceTypeSupports decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas.nisolle-ext committed Feb 3, 2022
1 parent 446248a commit e4b470f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
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);
});
});
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);
};
}
1 change: 1 addition & 0 deletions projects/ngx-repository/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export {JoinColumn} from './lib/core/decorator/join-column.decorator';
export {PathColumn} from './lib/core/decorator/path-column.decorator';
export {PathParam} from './lib/core/decorator/path-param.decorator';
export {Repository, getRepositoryContextConfiguration} from './lib/core/decorator/repository.decorator';
export {ResourceTypeSupports, RESOURCE_TYPE_SUPPORTS_METADATA_KEY} from './lib/core/decorator/resource-type-supports.decorator';
export {SoftCache} from './lib/core/decorator/soft-cache.decorator';
export {HardCache} from './lib/core/decorator/hard-cache.decorator';
export { SubCollection } from './lib/core/decorator/sub-collection.decorator';
Expand Down

0 comments on commit e4b470f

Please sign in to comment.