-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
74 changed files
with
3,909 additions
and
540 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
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
3 changes: 2 additions & 1 deletion
3
packages/jsx/lib/util/getEntityForType.js → packages/js/lib/util/getEntityForType.js
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,2 @@ | ||
export const compositeKeySeparator = "--@me/sep!-"; | ||
export {default as getEntityForType} from "./getEntityForType"; |
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 |
---|---|---|
|
@@ -47,6 +47,7 @@ jspm_packages | |
dist | ||
data/flickr | ||
.webpack | ||
.dynamoDb | ||
|
||
# Environment variables | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import dynamoose from "dynamoose"; | ||
import logger from "../../lib/logger"; | ||
import PostSchema from "../schema/post"; | ||
|
||
const Post = dynamoose.model(process.env.POSTS_DYNAMODB_TABLE, PostSchema); | ||
|
||
const postModelInstanceToEntity = postModelInstance => postModelInstance && postModelInstance.toEntity(); | ||
|
||
/** | ||
* Persist a [Post]{@link Post} | ||
* @param post {Post} | ||
* @returns {Promise<Post>} | ||
*/ | ||
export const createPost = async post => { | ||
logger.debug(`[Post.createPost] persisting post (${post.uid})`); | ||
const postModelInstance = await Post.create(post, {overwrite: true}); | ||
logger.debug(`[Post.createPost] persisted post (${JSON.stringify(postModelInstance && postModelInstance.uid)})`); | ||
return postModelInstanceToEntity(postModelInstance); | ||
}; | ||
|
||
/** | ||
* Retrieve a single [Post]{@link Post} matching a [Post.uid]{@link Post.uid} or some combination of other attributes | ||
* @param postUidOrParams {String|Object[]} | ||
* @returns {Promise<Post>} | ||
*/ | ||
export const getPost = async postUidOrParams => { | ||
logger.debug(`[Post.getPost] retrieving post (${JSON.stringify(postUidOrParams)})`); | ||
const queryParams = typeof postUidOrParams === "string" | ||
? {uid: {eq: postUidOrParams}} | ||
: postUidOrParams; | ||
const postModelInstance = await Post.queryOne(queryParams).exec(); | ||
logger.debug(`[Post.getPost] retrieved post (${postModelInstance && postModelInstance.uid})`); | ||
return postModelInstanceToEntity(postModelInstance); | ||
}; | ||
|
||
/** | ||
* Persist an array of [Posts]{@link Post} | ||
* @param posts {Post[]} | ||
* @returns {Promise<Post[]>} | ||
*/ | ||
export const createPosts = async posts => { | ||
logger.debug(`[Post.createPosts] persisting posts (${JSON.stringify(posts.map(post => post.uid))})`); | ||
await Post.batchPut(posts, {overwrite: true}); | ||
const postModelInstances = await Post.batchGet(posts.map(post => post.uid)); // NOTE-RT: Ugh. This is gross af. According to the docs, `batchPut`should return some Dynamoose model instances, but if you look at their tests and source they just return a statement of success and what wasn't processed | ||
logger.debug(`[Post.createPosts] persisted posts (${JSON.stringify(postModelInstances.map(postModelInstance => postModelInstance.uid))})`); | ||
return postModelInstances.map(postModelInstanceToEntity); | ||
}; | ||
|
||
/** | ||
* Retrieve an array of [Posts]{@link Post} matching a [Post.uid]{@link Post.uid} or some combination of other attributes | ||
* @param postUidsOrParams {Object} | ||
* @returns {Promise<Post[]>} | ||
*/ | ||
export const getPosts = async postUidsOrParams => { | ||
logger.debug(`[Post.getPosts] retrieving posts (${JSON.stringify(postUidsOrParams)})`); | ||
let postModelInstances; | ||
|
||
if (postUidsOrParams instanceof Array) { | ||
postModelInstances = await Post.batchGet(postUidsOrParams.map(postUid => { | ||
return {uid: postUid}; | ||
})); | ||
} else { | ||
postModelInstances = await Post.query(postUidsOrParams).all().exec(); | ||
} | ||
|
||
logger.debug(`[Post.getPosts] retrieved posts (${JSON.stringify(postModelInstances.map(postModelInstance => postModelInstance.uid))})`); | ||
return postModelInstances.map(postModelInstanceToEntity); | ||
}; | ||
|
||
export default Post; |
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,75 @@ | ||
import {Photo, Post, util} from "@randy.tarampi/js"; | ||
import {Schema} from "dynamoose"; | ||
|
||
const post = new Schema({ | ||
uid: { | ||
type: String, | ||
hashKey: true, | ||
default: model => `${model.source}${util.compositeKeySeparator}${model.id}` | ||
}, | ||
id: { | ||
type: String, | ||
required: true, | ||
index: { | ||
global: true | ||
} | ||
}, | ||
type: { | ||
type: String, | ||
required: true, | ||
enum: [ | ||
Photo.name, | ||
Post.name | ||
], | ||
index: { | ||
global: true | ||
} | ||
}, | ||
source: { | ||
type: String, | ||
required: true, | ||
index: { | ||
global: true | ||
} | ||
}, | ||
datePublished: { | ||
type: Date, | ||
index: { | ||
global: true | ||
} | ||
}, | ||
dateCreated: { | ||
type: Date, | ||
index: { | ||
global: true | ||
} | ||
}, | ||
title: { | ||
type: String | ||
}, | ||
body: { | ||
type: String | ||
}, | ||
sourceUrl: { | ||
type: String | ||
}, | ||
creator: { | ||
type: Object | ||
}, | ||
sizedPhotos: { | ||
type: [Object] | ||
} | ||
}, { | ||
throughput: 1, | ||
useNativeBooleans: false, | ||
useDocumentTypes: false, | ||
timestamps: true, | ||
expires: 7 * 24 * 60 * 60 | ||
}); | ||
|
||
post.methods.toEntity = function () { | ||
const Constructor = util.getEntityForType(this.type); | ||
return Constructor.fromJSON(this); | ||
}; | ||
|
||
export default post; |
Oops, something went wrong.