-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: serialize properties decorated with @serialize() (#251)
* feat: serialize properties decorated with @serialize() * feat: serialize object array properties decorated with @serialize() * feat: re-initialize properties decorated with @serialize() with their appropriate class * feat: re-initialize object array properties decorated with @serialize() with their appropriate class * chore: code coverage * chore: removed superfluous comment * fix: added some fixture data because its absense broke the integration tests * fix: eslint * fix: apparently I broke a bunch of tests and did not see it * fix: another attempt, hopefully this fixes the mess I made
- Loading branch information
1 parent
110c1f5
commit 6109c26
Showing
11 changed files
with
299 additions
and
12 deletions.
There are no files selected for viewing
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
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
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,22 @@ | ||
import { Serialize, serializeKey } from './Serialize'; | ||
|
||
describe('IgnoreDecorator', () => { | ||
it('should decorate properties', () => { | ||
class Address { | ||
streetName: string; | ||
zipcode: string; | ||
} | ||
|
||
class Band { | ||
id: string; | ||
name: string; | ||
@Serialize(Address) | ||
address: Address; | ||
} | ||
|
||
const band = new Band(); | ||
|
||
expect(Reflect.getMetadata(serializeKey, band, 'name')).toBe(undefined); | ||
expect(Reflect.getMetadata(serializeKey, band, 'address')).toBe(Address); | ||
}); | ||
}); |
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,7 @@ | ||
import 'reflect-metadata'; | ||
import { Constructor } from '../types'; | ||
export const serializeKey = Symbol('Serialize'); | ||
|
||
export function Serialize(entityConstructor: Constructor<unknown>) { | ||
return Reflect.metadata(serializeKey, entityConstructor); | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './Collection'; | ||
export * from './CustomRepository'; | ||
export * from './SubCollection'; | ||
export * from './Ignore'; | ||
export * from './Serialize'; | ||
export * from './SubCollection'; |
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
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
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
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
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
Oops, something went wrong.