@resourcefulhumans/rheactor-aws-lambda
Advanced tools
Comparing version 2.2.0 to 3.0.0
@@ -12,6 +12,2 @@ 'use strict'; | ||
var _rheactorValueObjects = require('rheactor-value-objects'); | ||
var _tcomb = require('tcomb'); | ||
var _rheactorModels = require('rheactor-models'); | ||
@@ -22,21 +18,12 @@ | ||
/** | ||
* @param {URIValue} mountURL | ||
* @param {object} routes | ||
* @param {Index} index | ||
* @return {Function} | ||
*/ | ||
var apiIndexOperation = exports.apiIndexOperation = function apiIndexOperation(mountURL, routes) { | ||
(0, _rheactorValueObjects.URIValueType)(mountURL); | ||
(0, _tcomb.Object)(routes); | ||
var apiIndexOperation = exports.apiIndexOperation = function apiIndexOperation(index) { | ||
(0, _rheactorModels.IndexType)(index, ['apiIndexOperation()', 'index:Index']); | ||
return { | ||
get: function get() { | ||
return _bluebird2.default.try(function () { | ||
var links = []; | ||
var u = mountURL.slashless().toString(); | ||
for (var k in routes) { | ||
links.push(new _rheactorModels.Link(new _rheactorValueObjects.URIValue([u, k].join('/')), routes[k])); | ||
} | ||
return new _rheactorModels.Index(links); | ||
}); | ||
return _bluebird2.default.resolve(index); | ||
} | ||
}; | ||
}; |
{ | ||
"name": "@resourcefulhumans/rheactor-aws-lambda", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "Core components for RESTful AWS lambda endpoints", | ||
@@ -37,3 +37,3 @@ "main": "dist/index.js", | ||
"rheactor-models": "3.x >=3.2.2", | ||
"rheactor-value-objects": "9.x >=9.0.1", | ||
"rheactor-value-objects": "^9.1.0", | ||
"tcomb": "^3.2.16" | ||
@@ -40,0 +40,0 @@ }, |
import Promise from 'bluebird' | ||
import {URIValue, URIValueType} from 'rheactor-value-objects' | ||
import {Object as ObjectType} from 'tcomb' | ||
import {Link, Index} from 'rheactor-models' | ||
import {IndexType} from 'rheactor-models' | ||
/** | ||
* @param {URIValue} mountURL | ||
* @param {object} routes | ||
* @param {Index} index | ||
* @return {Function} | ||
*/ | ||
export const apiIndexOperation = (mountURL, routes) => { | ||
URIValueType(mountURL) | ||
ObjectType(routes) | ||
export const apiIndexOperation = (index) => { | ||
IndexType(index, ['apiIndexOperation()', 'index:Index']) | ||
return { | ||
get: () => Promise.try(() => { | ||
const links = [] | ||
const u = mountURL.slashless().toString() | ||
for (const k in routes) { | ||
links.push(new Link(new URIValue([u, k].join('/')), routes[k])) | ||
} | ||
return new Index(links) | ||
}) | ||
get: () => Promise.resolve(index) | ||
} | ||
} |
@@ -5,3 +5,3 @@ /* global describe, it */ | ||
import {handler, apiIndexOperation, statusOperation} from '../src' | ||
import {HttpProblem, Status} from 'rheactor-models' | ||
import {HttpProblem, Status, Link, Index} from 'rheactor-models' | ||
import {URIValue} from 'rheactor-value-objects' | ||
@@ -15,6 +15,6 @@ | ||
const operations = { | ||
index: apiIndexOperation(mountURL, { | ||
'status': Status.$context, | ||
'empty': Status.$context | ||
}), | ||
index: apiIndexOperation(new Index([ | ||
new Link(mountURL.append('status'), Status.$context), | ||
new Link(mountURL.append('empty'), Status.$context) | ||
])), | ||
status: statusOperation('0.0.0', environment, Date.now()), | ||
@@ -21,0 +21,0 @@ empty: { |
@@ -5,3 +5,3 @@ /* global describe, it */ | ||
import {handler, apiIndexOperation, statusOperation} from '../../src' | ||
import {Status} from 'rheactor-models' | ||
import {Status, Index, Link} from 'rheactor-models' | ||
import {URIValue} from 'rheactor-value-objects' | ||
@@ -15,6 +15,6 @@ import Promise from 'bluebird' | ||
const operations = { | ||
index: apiIndexOperation(mountURL, { | ||
'status': Status.$context, | ||
'foo': Status.$context | ||
}), | ||
index: apiIndexOperation(new Index([ | ||
new Link(mountURL.append('status'), Status.$context), | ||
new Link(mountURL.append('foo'), Status.$context) | ||
])), | ||
status: statusOperation('0.0.0', environment, Date.now()) | ||
@@ -21,0 +21,0 @@ } |
@@ -5,3 +5,3 @@ /* global describe, it */ | ||
import {apiIndexOperation} from '../../src' | ||
import {Status, Index} from 'rheactor-models' | ||
import {Status, Index, Link} from 'rheactor-models' | ||
import {URIValue} from 'rheactor-value-objects' | ||
@@ -11,5 +11,5 @@ | ||
it('should create a list of links', () => { | ||
return apiIndexOperation(new URIValue('https://api.example.com/'), { | ||
'status': Status.$context | ||
}).get() | ||
return apiIndexOperation(new Index([ | ||
new Link(new URIValue('https://api.example.com/status'), Status.$context) | ||
])).get() | ||
.then(response => { | ||
@@ -16,0 +16,0 @@ expect(response.$context.toString()).to.equal(Index.$context.toString()) |
29144
682