-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#91 default value provider
- Loading branch information
Showing
19 changed files
with
104 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# run semantic-release on master branch | ||
branch: master | ||
branches: | ||
- name: master | ||
- name: "#91-default-value-provider" | ||
channel: pr91 | ||
prerelease: pr91 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
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
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 was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
test/models/model-with-custom-mapper-and-default-value.model.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,40 @@ | ||
// tslint:disable:max-classes-per-file | ||
import { Model } from '../../src/decorator/impl/model/model.decorator' | ||
import { Property } from '../../src/decorator/impl/property/property.decorator' | ||
import { MapperForType } from '../../src/mapper/for-type/base.mapper' | ||
import { StringAttribute } from '../../src/mapper/type/attribute.type' | ||
|
||
export class MyProp { | ||
static default() { | ||
return new MyProp('default', 'none') | ||
} | ||
|
||
static parse(v: string) { | ||
const p = v.split('-') | ||
return new MyProp(p[0], p[1]) | ||
} | ||
|
||
static toString(v: MyProp) { | ||
return `${v.type}-${v.name}` | ||
} | ||
|
||
constructor(public type: string, public name: string) {} | ||
|
||
toString() { | ||
return MyProp.toString(this) | ||
} | ||
} | ||
|
||
const myPropMapper: MapperForType<MyProp, StringAttribute> = { | ||
fromDb: a => MyProp.parse(a.S), | ||
toDb: v => ({ S: MyProp.toString(v) }), | ||
} | ||
|
||
@Model() | ||
export class ModelWithCustomMapperAndDefaultValue { | ||
@Property({ | ||
mapper: myPropMapper, | ||
defaultValueProvider: () => MyProp.default(), | ||
}) | ||
myProp: MyProp | ||
} |
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,8 @@ | ||
import { Model, PartitionKey, Property } from '../../src/dynamo-easy' | ||
|
||
@Model() | ||
export class ModelWithDefaultValue { | ||
@PartitionKey() | ||
@Property({ defaultValueProvider: () => `generated-id-${Math.floor(Math.random() * 1000)}` }) | ||
id: string | ||
} |