Cloud Directory Mapper for AWS Cloud Directory
Copyright (C) Clouden 2018
Author Kenneth Falck kennu@clouden.net 2018
Overview
This is an experimental JavaScript mapper for managing AWS Cloud Directory
content using dynamic object facets defined with TypeScript.
Installation
To add the library to your project:
npm install --save cloud-directory-mapper
Usage
To define a dynamic object facet:
import { CloudDirectoryMapper, dynamicObjectFacet, attribute } from 'cloud-directory-mapper'
import * as AWS from 'aws-sdk'
@dynamicObjectFacet()
class Post {
@attribute()
postId: string
@attribute()
title: string
@attribute()
content: string
}
To create a mapper instance connected to CLOUD_DIRECTORY_ARN (environment variable):
const cloudDirectory = new AWS.CloudDirectory()
const cloudDirectoryMapper = new CloudDirectoryMapper(cloudDirectory, process.env.CLOUD_DIRECTORY_ARN)
To create a new child object under a known parent object (/posts) using the link name postId:
const post = new Post()
post.postId = '123'
post.title = 'hello world'
post.content = 'longer content'
await mapper.createObject(post, '/posts', postId)
To retrieve child objects of a known parent object:
const posts = [] as Post[]
for await (const post of mapper.getChildObjects(Post, '/posts')) {
posts.push(post)
}
To retrieve a single child object of a known parent object using the link name postId:
const postId = '123'
const post = await mapper.getObject(Post, '/posts', postId)
To update the retrieved child object:
post.title = 'foo bar'
await mapper.updateObject(post)
Note that Cloud Directory Mapper automatically keeps track of the objectId of the
Post object retrieved using getObject(). This allows the updateObject() to work
without specifying any path or object identifier.