presidium 4.0.7 → 4.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/internal/DynamoDBAttributeType.test.js +18 -0
- package/internal/DynamoDBAttributeValue.test.js +19 -0
- package/internal/DynamoDBAttributeValueJSON.js +3 -2
- package/internal/DynamoDBAttributeValueJSON.test.js +19 -0
- package/internal/RetryAwsErrors.js +1 -1
- package/internal/RetryAwsErrors.test.js +29 -8
- package/internal/createFilterExpression.test.js +14 -0
- package/internal/createKeyConditionExpression.test.js +14 -0
- package/internal/dynamoDBStreamGetShardsIterator.js +3 -6
- package/internal/dynamoDBStreamGetShardsIterator.test.js +41 -0
- package/internal/getFirstKey.js +1 -1
- package/internal/parseURL.test.js +21 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Presidium
|
|
2
2
|

|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
The Presidium library.
|
|
5
5
|
|
|
6
6
|
Source code: [GitHub](https://github.com/richytong/presidium) |
|
|
7
7
|
License: [CFOSS](https://cloutsworld.com/en-us/legal/license/cfoss)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const Test = require('thunk-test')
|
|
2
|
+
const DynamoDBAttributeType = require('./DynamoDBAttributeType')
|
|
3
|
+
|
|
4
|
+
const test = new Test('DynamoDBAttributeType', DynamoDBAttributeType)
|
|
5
|
+
|
|
6
|
+
test.case('string', 'S')
|
|
7
|
+
test.case('S', 'S')
|
|
8
|
+
test.case('number', 'N')
|
|
9
|
+
test.case('N', 'N')
|
|
10
|
+
test.case('binary', 'B')
|
|
11
|
+
test.case('B', 'B')
|
|
12
|
+
test.throws('test', new TypeError('Invalid value test'))
|
|
13
|
+
|
|
14
|
+
if (process.argv[1] == __filename) {
|
|
15
|
+
test()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = test
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const Test = require('thunk-test')
|
|
2
|
+
const DynamoDBAttributeValue = require('./DynamoDBAttributeValue')
|
|
3
|
+
|
|
4
|
+
const test = new Test('DynamoDBAttributeValue', DynamoDBAttributeValue)
|
|
5
|
+
|
|
6
|
+
test.case('test', { S: 'test' })
|
|
7
|
+
test.case(3, { N: '3' })
|
|
8
|
+
test.case(true, { BOOL: true })
|
|
9
|
+
test.case(false, { BOOL: false })
|
|
10
|
+
test.case(null, { NULL: true })
|
|
11
|
+
test.case([1, 2, 3], { L: [{ N: '1' }, { N: '2' }, { N: '3' }] })
|
|
12
|
+
test.case({ a: 1, b: 2, c: 3 }, { M: { a: { N: '1' }, b: { N: '2' }, c: { N: '3' } } })
|
|
13
|
+
test.throws(NaN, new TypeError('Invalid value NaN'))
|
|
14
|
+
|
|
15
|
+
if (process.argv[1] == __filename) {
|
|
16
|
+
test()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = test
|
|
@@ -20,7 +20,8 @@ const getFirstKey = require('./getFirstKey')
|
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
function DynamoDBAttributeValueJSON(AttributeValue) {
|
|
23
|
-
|
|
23
|
+
const firstKey = getFirstKey(AttributeValue)
|
|
24
|
+
switch (firstKey) {
|
|
24
25
|
case 'S':
|
|
25
26
|
return String(AttributeValue.S)
|
|
26
27
|
case 'N':
|
|
@@ -34,7 +35,7 @@ function DynamoDBAttributeValueJSON(AttributeValue) {
|
|
|
34
35
|
case 'M':
|
|
35
36
|
return map(AttributeValue.M, DynamoDBAttributeValueJSON)
|
|
36
37
|
default:
|
|
37
|
-
throw new TypeError(`Invalid AttributeValue ${
|
|
38
|
+
throw new TypeError(`Invalid AttributeValue ${firstKey}`)
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const Test = require('thunk-test')
|
|
2
|
+
const DynamoDBAttributeValueJSON = require('./DynamoDBAttributeValueJSON')
|
|
3
|
+
|
|
4
|
+
const test = new Test('DynamoDBAttributeValueJSON', DynamoDBAttributeValueJSON)
|
|
5
|
+
|
|
6
|
+
test.case({ S: 'test' }, 'test')
|
|
7
|
+
test.case({ N: '3' }, 3)
|
|
8
|
+
test.case({ BOOL: true }, true)
|
|
9
|
+
test.case({ BOOL: false }, false)
|
|
10
|
+
test.case({ NULL: true }, null)
|
|
11
|
+
test.case({ L: [{ N: '1' }, { N: '2' }, { N: '3' }] }, [1, 2, 3])
|
|
12
|
+
test.case({ M: { a: { N: '1' }, b: { N: '2' }, c: { N: '3' } } }, { a: 1, b: 2, c: 3 })
|
|
13
|
+
test.throws({}, new TypeError('Invalid AttributeValue undefined'))
|
|
14
|
+
|
|
15
|
+
if (process.argv[1] == __filename) {
|
|
16
|
+
test()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = test
|
|
@@ -9,7 +9,7 @@ const sleep = require('./sleep')
|
|
|
9
9
|
* ```
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
const RetryAwsErrors = function (func, context
|
|
12
|
+
const RetryAwsErrors = function (func, context) {
|
|
13
13
|
return function retriesAwsErrors(...args) {
|
|
14
14
|
return func.apply(context, args).catch(async error => {
|
|
15
15
|
if (
|
|
@@ -1,16 +1,37 @@
|
|
|
1
1
|
const Test = require('thunk-test')
|
|
2
|
+
const assert = require('assert')
|
|
2
3
|
const RetryAwsErrors = require('./RetryAwsErrors')
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const test = new Test('RetryAwsErrors', async function integration() {
|
|
6
|
+
|
|
7
|
+
let didThrow1 = false
|
|
8
|
+
const throw1ThrottlingException = async () => {
|
|
9
|
+
if (didThrow1) {
|
|
10
|
+
return true
|
|
11
|
+
}
|
|
12
|
+
didThrow1 = true
|
|
13
|
+
const error = new Error('Rate exceeded')
|
|
14
|
+
error.name = 'ThrottlingException'
|
|
15
|
+
throw error
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const retryThrow1ThrottlingException = RetryAwsErrors(throw1ThrottlingException, {})
|
|
19
|
+
|
|
20
|
+
assert.strictEqual(await retryThrow1ThrottlingException(), true)
|
|
21
|
+
|
|
22
|
+
const throwError = async () => {
|
|
23
|
+
const error = new Error('test')
|
|
24
|
+
throw error
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const retryThrowError = RetryAwsErrors(throwError, {})
|
|
10
28
|
|
|
11
|
-
|
|
29
|
+
assert.rejects(
|
|
30
|
+
retryThrowError(),
|
|
31
|
+
new Error('test')
|
|
32
|
+
)
|
|
12
33
|
|
|
13
|
-
|
|
34
|
+
}).case()
|
|
14
35
|
|
|
15
36
|
if (process.argv[1] == __filename) {
|
|
16
37
|
test()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const Test = require('thunk-test')
|
|
2
|
+
const createFilterExpression = require('./createFilterExpression')
|
|
3
|
+
const hashJSON = require('./hashJSON')
|
|
4
|
+
|
|
5
|
+
const test = new Test('createFilterExpression', createFilterExpression)
|
|
6
|
+
|
|
7
|
+
test.case({ filterExpressionStatements: ['begins_with(test, :a)'] }, `begins_with(#${hashJSON('test')}, :a)`)
|
|
8
|
+
test.case({ filterExpressionStatements: ['a > :a', 'b = :b', 'c <= :c'] }, `#${hashJSON('a')} > :a AND #${hashJSON('b')} = :b AND #${hashJSON('c')} <= :c`)
|
|
9
|
+
|
|
10
|
+
if (process.argv[1] == __filename) {
|
|
11
|
+
test()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = test
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const Test = require('thunk-test')
|
|
2
|
+
const createKeyConditionExpression = require('./createKeyConditionExpression')
|
|
3
|
+
const hashJSON = require('./hashJSON')
|
|
4
|
+
|
|
5
|
+
const test = new Test('createKeyConditionExpression', createKeyConditionExpression)
|
|
6
|
+
|
|
7
|
+
test.case({ keyConditionStatements: ['begins_with(test, :a)'] }, `begins_with(#${hashJSON('test')}, :a)`)
|
|
8
|
+
test.case({ keyConditionStatements: ['a > :a', 'b = :b', 'c <= :c'] }, `#${hashJSON('a')} > :a AND #${hashJSON('b')} = :b AND #${hashJSON('c')} <= :c`)
|
|
9
|
+
|
|
10
|
+
if (process.argv[1] == __filename) {
|
|
11
|
+
test()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = test
|
|
@@ -30,9 +30,8 @@ async function* dynamoDBStreamGetShardsIterator(options) {
|
|
|
30
30
|
Limit: 100,
|
|
31
31
|
}).then(get('StreamDescription'))
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
33
|
+
yield* streamData.Shards.map(assign({ StreamArn: options.StreamArn }))
|
|
34
|
+
|
|
36
35
|
while (!this.closed && streamData.LastEvaluatedShardId != null) {
|
|
37
36
|
await sleep(this.GetShardsInterval)
|
|
38
37
|
|
|
@@ -42,9 +41,7 @@ async function* dynamoDBStreamGetShardsIterator(options) {
|
|
|
42
41
|
ExclusiveStartShardId: streamData.LastEvaluatedShardId,
|
|
43
42
|
}).then(get('StreamDescription'))
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
yield* streamData.Shards.map(assign({ StreamArn: options.StreamArn }))
|
|
47
|
-
}
|
|
44
|
+
yield* streamData.Shards.map(assign({ StreamArn: options.StreamArn }))
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
47
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const Test = require('thunk-test')
|
|
2
|
+
const assert = require('assert')
|
|
3
|
+
const stream = require('stream')
|
|
4
|
+
const dynamoDBStreamGetShardsIterator = require('./dynamoDBStreamGetShardsIterator')
|
|
5
|
+
|
|
6
|
+
const test = new Test('dynamoDBStreamGetShardsIterator', async function integration() {
|
|
7
|
+
|
|
8
|
+
let numRequests = 0
|
|
9
|
+
const dynamoDBStream = {
|
|
10
|
+
GetShardsInterval: 100,
|
|
11
|
+
|
|
12
|
+
_awsDynamoDBStreamsRequest() {
|
|
13
|
+
if (numRequests < 3) {
|
|
14
|
+
numRequests += 1
|
|
15
|
+
const response = stream.Readable.from([JSON.stringify({ StreamDescription: { Shards: [{}], LastEvaluatedShardId: 'test' } })])
|
|
16
|
+
response.headers = {}
|
|
17
|
+
response.ok = true
|
|
18
|
+
return response
|
|
19
|
+
}
|
|
20
|
+
const response = stream.Readable.from([JSON.stringify({ StreamDescription: { Shards: [{}] } })])
|
|
21
|
+
response.headers = {}
|
|
22
|
+
response.ok = true
|
|
23
|
+
return response
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const iter = dynamoDBStreamGetShardsIterator.call(dynamoDBStream, { StreamArn: 'test' })
|
|
28
|
+
|
|
29
|
+
const shards = []
|
|
30
|
+
for await (const Shard of iter) {
|
|
31
|
+
shards.push(Shard)
|
|
32
|
+
}
|
|
33
|
+
assert.equal(shards.length, 4)
|
|
34
|
+
|
|
35
|
+
}).case()
|
|
36
|
+
|
|
37
|
+
if (process.argv[1] == __filename) {
|
|
38
|
+
test()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = test
|
package/internal/getFirstKey.js
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const Test = require('thunk-test')
|
|
2
|
+
const assert = require('assert')
|
|
3
|
+
const parseURL = require('./parseURL')
|
|
4
|
+
|
|
5
|
+
const test = new Test('parseURL', parseURL)
|
|
6
|
+
|
|
7
|
+
test.case('/', url => {
|
|
8
|
+
assert.equal(url.constructor, URL)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
test.case('http://test.test', url => {
|
|
12
|
+
assert.equal(url.constructor, URL)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test.throws('test.test', new TypeError('Invalid URL'))
|
|
16
|
+
|
|
17
|
+
if (process.argv[1] == __filename) {
|
|
18
|
+
test()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = test
|
package/package.json
CHANGED