formation

Spec

formation<TSource>(
    source: TSource,
    RootTClass: ClassCapture<TSource>,
    formationType: FormationMask = FormationMask.Full
): AttributeMap

Convert DynamoEntity to AttributeMap.

Input

Name

Type

Information

source

TSource

Entity to convert to AttributeMap.

RootTClass

ClassCapture<TSource>

Reference of @DynamoEntity class

formationType

FormationMask

Conversion bitmask

Formation Mask

With Formation Mask, only certain information can be included in the DynamoItem. It is good for generate key.

FormationMask.ts
export enum FormationMask {
    HashKey = 0b001,
    RangeKey = 0b010,
    Body = 0b100,
    KeyOnly = 0b011, // == HashKey | RangeKey
    Full = 0b111     // == HashKey | RangeKey | Body
}

const dynamoItemKey: Item = Mapper.formation(badCat, Cat, FormationMask.KeyOnly);

Example

@DynamoEntity()
class Cat {
    @DynamoProperty({ keyType: KeyType.hash })
    id!: number;

    @DynamoProperty({ keyType: KeyType.attr })
    name!: string;
}
const badCat :Cat = {
    id: 666,
    name: "garfield"
};
const dynamo : AttributeMap = Mapper.formation(badCat, Cat);

It will be formationed as,

{
    "id": {
        "N": "666"
    },
    "name": {
        "S": "garfield"
    }
}

Internal Logic

Use the formatProperty method to perform a formation on all the properties, then merge all the results.

Last updated

Was this helpful?