Skip to content

Commit 0cc4720

Browse files
authored
Merge pull request #1 from jeremydaly/master
update from upstream
2 parents 23b3e46 + 4cbb92a commit 0cc4720

File tree

73 files changed

+10536
-2774
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+10536
-2774
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
coverage
22
node_modules
3-
test
3+
__tests__
44
*.test.js

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: node_js
22

33
node_js:
4-
- "8"
4+
- "12"
55

66
script: "npm run-script test-ci"

README.md

Lines changed: 789 additions & 299 deletions
Large diffs are not rendered by default.

__tests__/bootstrap-tests.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Load simple table creation parameters
2+
module.exports.createTableParams = require('./tables/create-table.json')
3+
4+
// Include dynalite and config server (use in memory)
5+
const dynalite = require('dynalite')
6+
module.exports.dynaliteServer = dynalite({
7+
createTableMs: 0,
8+
updateTableMs: 0,
9+
deleteTableMs: 0
10+
})
11+
12+
// Load AWS SDK
13+
const AWS = require('aws-sdk')
14+
15+
// Create DynamoDB connection to dynalite
16+
module.exports.DynamoDB = new AWS.DynamoDB({
17+
endpoint: 'http://localhost:4567',
18+
region: 'us-east-1',
19+
credentials: new AWS.Credentials({ accessKeyId: 'test', secretAccessKey: 'test' })
20+
})
21+
22+
// Create our document client
23+
module.exports.DocumentClient = new AWS.DynamoDB.DocumentClient({
24+
endpoint: 'http://localhost:4567',
25+
region: 'us-east-1',
26+
credentials: new AWS.Credentials({ accessKeyId: 'test', secretAccessKey: 'test' }),
27+
// convertEmptyValues: true
28+
})
29+
30+
// Delay helper
31+
module.exports.delay = ms => new Promise(res => setTimeout(res, ms))
32+
33+
34+
module.exports.DocumentClient2 = new AWS.DynamoDB.DocumentClient({
35+
region: 'us-east-1',
36+
credentials: new AWS.SharedIniFileCredentials({profile: ''}),
37+
// convertEmptyValues: false
38+
})
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const checkAttribute = require('../lib/checkAttribute')
2+
3+
// Require Table and Entity classes
4+
const Table = require('../classes/Table')
5+
const Entity = require('../classes/Entity')
6+
7+
8+
// Create basic table
9+
let DefaultTable = new Table({
10+
name: 'test-table',
11+
partitionKey: 'pk',
12+
sortKey: 'sk'
13+
})
14+
15+
// Create basic entity
16+
DefaultTable.entities = new Entity({
17+
name: 'User',
18+
attributes: {
19+
pk: { type: 'string', partitionKey: true },
20+
sk: { type: 'string', sortKey: true },
21+
set: { type: 'set', setType: 'string', alias: 'set_alias' },
22+
set_alias2: { type: 'set', setType: 'string', map: 'set2' },
23+
number: 'number',
24+
list: { type: 'list', alias: 'list_alias' },
25+
list_alias2: { type: 'list', map: 'list2' },
26+
test: 'map',
27+
}
28+
})
29+
30+
31+
describe('checkAttribute', () => {
32+
33+
it('checks attribute and returns table attribute', () => {
34+
expect(checkAttribute('number',DefaultTable.User.schema.attributes)).toBe('number')
35+
expect(checkAttribute('set',DefaultTable.User.schema.attributes)).toBe('set')
36+
expect(checkAttribute('set_alias',DefaultTable.User.schema.attributes)).toBe('set')
37+
expect(checkAttribute('set2',DefaultTable.User.schema.attributes)).toBe('set2')
38+
expect(checkAttribute('set_alias2',DefaultTable.User.schema.attributes)).toBe('set2')
39+
expect(checkAttribute('set.test',DefaultTable.User.schema.attributes)).toBe('set.test')
40+
expect(checkAttribute('set.test[0]',DefaultTable.User.schema.attributes)).toBe('set.test[0]')
41+
expect(checkAttribute('set.test.test2[0]',DefaultTable.User.schema.attributes)).toBe('set.test.test2[0]')
42+
expect(checkAttribute('set_alias.test',DefaultTable.User.schema.attributes)).toBe('set.test')
43+
expect(checkAttribute('set_alias.test[0]',DefaultTable.User.schema.attributes)).toBe('set.test[0]')
44+
expect(checkAttribute('set_alias.test.test2[0]',DefaultTable.User.schema.attributes)).toBe('set.test.test2[0]')
45+
expect(checkAttribute('set_alias2.test',DefaultTable.User.schema.attributes)).toBe('set2.test')
46+
expect(checkAttribute('set_alias2.test[0]',DefaultTable.User.schema.attributes)).toBe('set2.test[0]')
47+
expect(checkAttribute('set_alias2.test.test2[0]',DefaultTable.User.schema.attributes)).toBe('set2.test.test2[0]')
48+
expect(checkAttribute('test.test',DefaultTable.User.schema.attributes)).toBe('test.test')
49+
expect(checkAttribute('test.test[0]',DefaultTable.User.schema.attributes)).toBe('test.test[0]')
50+
expect(checkAttribute('list[1]',DefaultTable.User.schema.attributes)).toBe('list[1]')
51+
expect(checkAttribute('list[1]',DefaultTable.User.schema.attributes)).toBe('list[1]')
52+
})
53+
54+
it('returns error on invalid attribute', () => {
55+
expect(() => {
56+
checkAttribute('missing-attribute',DefaultTable.User.schema.attributes)
57+
}).toThrow(`'missing-attribute' is not a valid attribute.`)
58+
})
59+
60+
})

__tests__/delete.unit.test.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

__tests__/models/simple-model-req.js renamed to __tests__/entities/simple-entity-req.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
// SIMPLE MODEL w/ REQUIRED fields for testing
1+
// SIMPLE ENTITY w/ REQUIRED fields for testing
22

33
module.exports = {
4-
// Include table name
5-
table: 'simple-table',
6-
7-
// Include model field
8-
model: false,
4+
// Specify entity name
5+
name: 'SimpleEntityReq',
96

107
// Include timestamps
118
timestamps: false,
129

1310
// Define partition and sort keys
1411
partitionKey: 'pk',
1512

16-
// Define schema
17-
schema: {
13+
// Define attributes
14+
attributes: {
1815
pk: { type: 'string' },
1916
test: { type: 'string', required: true },
2017
test2: { type: 'string', required: 'always' }

__tests__/models/simple-model-sk.js renamed to __tests__/entities/simple-entity-sk.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
// SIMPLE MODEL w/ SORT KEY for testing
1+
// SIMPLE ENTITY w/ SORT KEY for testing
22

33
module.exports = {
4-
// Include table name
5-
table: 'simple-table',
6-
7-
// Include model field
8-
model: false,
4+
// Specify entity name
5+
name: 'SimpleEntitySK',
96

107
// Include timestamps
118
timestamps: false,
@@ -14,8 +11,8 @@ module.exports = {
1411
partitionKey: 'pk',
1512
sortKey: 'sk',
1613

17-
// Define schema
18-
schema: {
14+
// Define attributes
15+
attributes: {
1916
pk: { type: 'string' },
2017
sk: { type: 'string' },
2118
test: { type: 'string' }
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SIMPLE ENTITY for testing
2+
3+
module.exports = {
4+
// Specify entity name
5+
name: 'SimpleEntity',
6+
7+
// Define attributes
8+
attributes: {
9+
pk: { type: 'string', partitionKey: true },
10+
sk: { type: 'string', hidden: true, sortKey: true },
11+
test: { type: 'string' },
12+
test_composite: ['sk',0, { save: true }],
13+
test_composite2: ['sk',1, { save: false }],
14+
test_undefined: { default: () => undefined }
15+
}
16+
}

__tests__/models/test-model.js renamed to __tests__/entities/test-entity.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
1-
// TEST MODEL for testing
1+
// TEST ENTITY for testing
22

33
module.exports = {
4-
// Include table name
5-
table: 'test-table',
6-
7-
// Include model field
8-
model: true,
9-
10-
// Include timestamps
11-
timestamps: true,
12-
13-
// Define partition and sort keys
14-
partitionKey: 'pk',
15-
sortKey: 'sk',
16-
17-
// Define schema
18-
schema: {
19-
pk: { type: 'string', alias: 'email' },
20-
sk: { type: 'string', alias: 'type' },
4+
// Specify name
5+
name: 'TestEntity',
6+
// Optional description
7+
// description: 'This is a test description for this entity',
8+
// Define attributes
9+
attributes: {
10+
email: { type: 'string', partitionKey: true },
11+
test_type: { type: 'string', sortKey: true },
2112
test_string: { type: 'string', coerce: false, default: 'test string' },
2213
test_string_coerce: { type: 'string' },
2314
test_number: { type: 'number', alias: 'count', coerce: false },

0 commit comments

Comments
 (0)