Skip to content

Instantly share code, notes, and snippets.

@likwid
Last active May 31, 2017 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save likwid/e0e57744feb8b831660e623a76e1f3bd to your computer and use it in GitHub Desktop.
Save likwid/e0e57744feb8b831660e623a76e1f3bd to your computer and use it in GitHub Desktop.
aws request document dsl in javascript
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
};
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", {}));
@theqabalist
Copy link

use [].concat(arg) for coercing between non array value and array instead of type sniffing

@theqabalist
Copy link

also lenses are your friend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment