Last active
May 31, 2017 16:01
-
-
Save likwid/e0e57744feb8b831660e623a76e1f3bd to your computer and use it in GitHub Desktop.
aws request document dsl in javascript
This file contains hidden or 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
const {__, curry, is, map, merge, objOf} = require("ramda"); | |
const makeArrayDoc = curry((list, containerName, doc) => | |
is(Array, list) ? | |
merge(objOf(containerName, list), doc) : | |
merge(objOf(containerName, [list]), doc)); | |
const makeListOf = curry((list, fn, name, doc) => { | |
const objs = map(([key, val]) => fn(key, val), list); | |
return merge(objOf(name, objs), doc); | |
}); | |
const filtered = (key, value) => | |
({Name: key, Values: [value]}); | |
const tagged = (key, value) => | |
({Key: key, Value: value}); | |
const owners = makeArrayDoc(__, "Owners"); | |
const mine = (doc) => owners("self", doc); | |
const resources = makeArrayDoc(__, "Resources"); | |
const filters = makeListOf(__, filtered, "Filters"); | |
const tags = makeListOf(__, tagged, "Tags"); | |
module.exports = { | |
filters, | |
mine, | |
owners, | |
resources, | |
tags | |
}; |
This file contains hidden or 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
const {curry, pipe} = require("ramda"); | |
const {filters, mine, owners, resources, tags} = require("./lib/aws/dsl"); | |
const descImgParams = pipe( | |
mine, | |
filters([ | |
["tag:Type", "docker-base"] | |
]) | |
); | |
const tagPairingInstance = curry((instanceId, instanceName, doc) => | |
pipe( | |
resources(instanceId), | |
tags([ | |
["Name", instanceName], | |
["Type", "pairing"] | |
]) | |
)(doc) | |
); | |
console.log(descImgParams({})); | |
console.log(""); | |
console.log(tagPairingInstance("i-1234567", "foo-bar-baz", {})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use [].concat(arg) for coercing between non array value and array instead of type sniffing