Skip to content

Commit 6806bcc

Browse files
committed
Tidy up tables factory a wee bit
1 parent ec545ad commit 6806bcc

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

src/tables/factory.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ let paginate = true
66
/**
77
* returns a data client
88
*/
9-
module.exports = function factory ({ tables, options = {} }, callback) {
9+
module.exports = function factory ({ services, options = {} }, callback) {
10+
let { tables } = services
1011
let { ARC_ENV, AWS_REGION } = process.env
1112
let local = ARC_ENV === 'testing'
1213
let region = AWS_REGION || 'us-west-2'

src/tables/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@ module.exports = function tables (arc) {
3636
waterfall([
3737
function (callback) {
3838
arc.services()
39-
.then(serviceMap => {
40-
callback(null, { tables: serviceMap.tables, options })
41-
})
42-
.catch(err => {
43-
callback(err)
44-
})
39+
.then(services => callback(null, { services, options }))
40+
.catch(callback)
4541
},
4642
factory,
4743
function (created, callback) {

test/unit/src/tables/factory-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let sandbox = require('@architect/sandbox')
55
let cwd = process.cwd()
66
let mock = join(cwd, 'test', 'mock', 'project')
77

8-
let tables = { hi: 'there' }
8+
let services = { tables: { hi: 'there' } }
99

1010
test('Set up env', async t => {
1111
t.plan(2)
@@ -17,7 +17,7 @@ test('Set up env', async t => {
1717

1818
test('tables.factory main client', t => {
1919
t.plan(4)
20-
factory({ tables }, (err, client) => {
20+
factory({ services }, (err, client) => {
2121
if (err) t.fail(err)
2222
t.ok(client._client, '_client property assigned')
2323
t.notOk(client._db, '_db property not assigned')
@@ -28,7 +28,7 @@ test('tables.factory main client', t => {
2828

2929
test('tables.factory AWS SDK properties', t => {
3030
t.plan(4)
31-
factory({ tables, options: { awsSdkClient: true } }, (err, client) => {
31+
factory({ services, options: { awsSdkClient: true } }, (err, client) => {
3232
if (err) t.fail(err)
3333
t.ok(client._client, '_client property assigned')
3434
t.ok(client._db, '_db property assigned')
@@ -39,10 +39,10 @@ test('tables.factory AWS SDK properties', t => {
3939

4040
test('tables.factory client static methods', t => {
4141
t.plan(2)
42-
let tables = { quart: 'tequila' }
43-
factory({ tables }, async (err, client) => {
42+
let services = { tables: { quart: 'tequila' } }
43+
factory({ services }, async (err, client) => {
4444
if (err) t.fail(err)
45-
t.equals(await client.reflect(), tables, 'reflect() returns tables object')
45+
t.equals(await client.reflect(), services.tables, 'reflect() returns tables object')
4646
t.equals(client._name('quart'), 'tequila', '_name() returns tables value')
4747
})
4848
})

0 commit comments

Comments
 (0)