Skip to content

Commit 11fd22b

Browse files
chore(cleanup): remove unused code
get rid of enum mapper which is not required because we use normal number or string mapper
1 parent 1219093 commit 11fd22b

File tree

13 files changed

+21
-92
lines changed

13 files changed

+21
-92
lines changed

src/decorator/decorators.spec.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ import {
1313
ModelWithABunchOfIndexes,
1414
ModelWithCustomMapperModel,
1515
ModelWithEnum,
16-
ModelWithEnumDeclared,
1716
ModelWithGSI,
1817
NestedObject,
1918
SimpleModel,
2019
} from '../../test/models'
2120
import { Form } from '../../test/models/real-world'
22-
import { EnumType } from '../mapper'
2321
import { GSIPartitionKey, GSISortKey, LSISortKey, PartitionKey, Property, SortedSet, SortKey, Transient } from './impl'
2422
import { Model } from './impl/model/model.decorator'
2523
import { Metadata, metadataForClass, metadataForModel, ModelMetadata } from './index'
@@ -336,20 +334,6 @@ describe('Decorators should add correct metadata', () => {
336334
})
337335
})
338336

339-
describe('enum', () => {
340-
let metadata: Metadata<ModelWithEnumDeclared>
341-
342-
beforeEach(() => {
343-
metadata = metadataForClass(ModelWithEnumDeclared)
344-
})
345-
346-
it('should add enum type to property', () => {
347-
const enumPropertyMetadata = metadata.forProperty('type')!
348-
expect(enumPropertyMetadata.typeInfo).toBeDefined()
349-
expect(enumPropertyMetadata.typeInfo).toEqual({ type: EnumType, isCustom: true })
350-
})
351-
})
352-
353337
describe('with inheritance', () => {
354338
it('should override the table name', () => {
355339
@Model({ tableName: 'super-table-name' })

src/decorator/impl/enum/enum.decorator.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/decorator/impl/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ export * from './collection/typed-set.decorator'
44
export * from './collection/typed-array.decorator'
55
// date
66
export * from './date/date.decorator'
7-
// enum
8-
export * from './enum/enum.decorator'
97
// index
108
export * from './index/secondary-index'
119
export * from './index/gsi-partition-key.decorator'

src/mapper/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export * from './type/attribute.type'
22
export * from './type/attribute-value-type.type'
33
export * from './type/attribute-type.type'
44
export * from './mapper'
5-
export * from './type/enum.type'
65
export * from './type/null.type'
76
export * from './type/undefined.type'
87
export * from './type/binary.type'

src/mapper/mapper.spec.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
OrganizationEvent,
2525
Product,
2626
ProductNested,
27+
StringType,
2728
Type,
2829
} from '../../test/models'
2930
import { IdMapper } from '../../test/models/model-with-custom-mapper.model'
@@ -45,7 +46,6 @@ import {
4546
StringAttribute,
4647
StringSetAttribute,
4748
} from './type/attribute.type'
48-
import { EnumType } from './type/enum.type'
4949

5050
describe('Mapper', () => {
5151
describe('should map single values', () => {
@@ -83,13 +83,20 @@ describe('Mapper', () => {
8383
expect(attrValue.NULL).toBe(true)
8484
})
8585

86-
it('enum (no enum decorator)', () => {
86+
it('enum (number)', () => {
8787
const attrValue = <NumberAttribute>toDbOne(Type.FirstType)!
8888
expect(attrValue).toBeDefined()
8989
expect(keyOf(attrValue)).toBe('N')
9090
expect(attrValue.N).toBe('0')
9191
})
9292

93+
it('enum (string)', () => {
94+
const attrValue = <StringAttribute>toDbOne(StringType.FirstType)!
95+
expect(attrValue).toBeDefined()
96+
expect(keyOf(attrValue)).toBe('S')
97+
expect(attrValue.S).toBe('first')
98+
})
99+
93100
it('enum (propertyMetadata -> no enum decorator)', () => {
94101
const attrValue: Attribute = <MapAttribute>toDbOne(Type.FirstType, <any>{
95102
typeInfo: { type: Object, isCustom: true },
@@ -99,15 +106,6 @@ describe('Mapper', () => {
99106
expect(attrValue.M).toEqual({})
100107
})
101108

102-
it('enum (with decorator)', () => {
103-
const attrValue = <NumberAttribute>toDbOne(Type.FirstType, <any>{
104-
typeInfo: { type: EnumType, isCustom: true },
105-
})!
106-
expect(attrValue).toBeDefined()
107-
expect(keyOf(attrValue)).toBe('N')
108-
expect(attrValue.N).toBe('0')
109-
})
110-
111109
it('array -> SS (homogen, no duplicates)', () => {
112110
const attrValue = <StringSetAttribute>toDbOne(['foo', 'bar'])!
113111
expect(attrValue).toBeDefined()

src/mapper/mapper.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import {v4 as uuidv4} from 'uuid'
1+
import { v4 as uuidv4 } from 'uuid'
22
import { Metadata } from '../decorator/metadata/metadata'
33
import { metadataForClass, metadataForProperty } from '../decorator/metadata/metadata-helper'
44
import { Key, PropertyMetadata } from '../decorator/metadata/property-metadata.model'
55
import { ModelConstructor } from '../model'
66
import { MapperForType } from './for-type/base.mapper'
77
import { BooleanMapper } from './for-type/boolean.mapper'
88
import { CollectionMapper } from './for-type/collection.mapper'
9-
import { EnumMapper } from './for-type/enum.mapper'
109
import { NullMapper } from './for-type/null.mapper'
1110
import { NumberMapper } from './for-type/number.mapper'
1211
import { ObjectMapper } from './for-type/object.mapper'
1312
import { StringMapper } from './for-type/string.mapper'
1413
import { AttributeValueType } from './type/attribute-value-type.type'
1514
import { Attribute, Attributes } from './type/attribute.type'
1615
import { Binary } from './type/binary.type'
17-
import { EnumType } from './type/enum.type'
1816
import { NullType } from './type/null.type'
1917
import { UndefinedType } from './type/undefined.type'
2018
import { typeOf, typeOfFromDb } from './util'
@@ -48,7 +46,6 @@ export function toDb<T>(item: T, modelConstructor?: ModelConstructor<T>): Attrib
4846

4947
let attributeValue: Attribute | undefined | null
5048

51-
// TODO concept maybe make this configurable how to map undefined & null values
5249
if (propertyValue === undefined || propertyValue === null) {
5350
// noop ignore because we can't map it
5451
} else {
@@ -159,8 +156,7 @@ export function createToKeyFn<T>(modelConstructor: ModelConstructor<T>): (item:
159156
throw new Error(`there is no value for property ${propMeta.name.toString()} but is ${propMeta.key.type} key`)
160157
}
161158

162-
// fixme: typings
163-
;(<any>key)[propMeta.name] = <Attribute>toDbOne(propertyValue, propMeta)
159+
key[propMeta.name] = <Attribute>toDbOne(propertyValue, propMeta)
164160
return key
165161
},
166162
<Attributes<T>>{},
@@ -257,9 +253,6 @@ export function forType(type: AttributeValueType): MapperForType<any, Attribute>
257253
case Boolean:
258254
mapper = BooleanMapper
259255
break
260-
case EnumType:
261-
mapper = EnumMapper
262-
break
263256
case Map:
264257
// Maps support complex types as keys, we only support String & Number as Keys, otherwise a .toString() method should be implemented,
265258
// so we now how to save a key
@@ -278,7 +271,6 @@ export function forType(type: AttributeValueType): MapperForType<any, Attribute>
278271
mapper = NullMapper
279272
break
280273
case Binary:
281-
// TODO LOW:BINARY add binary mapper
282274
throw new Error('no mapper for binary type implemented yet')
283275
case UndefinedType:
284276
mapper = ObjectMapper

src/mapper/type/enum.type.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/models/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ export * from './model-with-custom-mapper.model'
66
export * from './model-with-custom-mapper-for-sort-key.model'
77
export * from './model-with-date.model'
88
export * from './model-with-enum.model'
9-
export * from './model-with-enum-declared.model'
109
export * from './model-with-indexes.model'
1110
export * from './model-with-date-as-key.model'
12-
export * from './model-with-typed-enum-declared.model'
1311
export * from './model-without-custom-mapper.model'
1412
export * from './nested-complex.model'
1513
export * from './nested-object.model'

test/models/model-with-enum-declared.model.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/models/model-with-typed-enum-declared.model.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)