presidium 4.0.6 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  # Presidium
2
2
  ![presidium](https://rubico.land/assets/presidium-logo-3-w200.jpg)
3
3
 
4
- A library for creating web services.
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)
package/S3Bucket.js CHANGED
@@ -16,7 +16,6 @@ const AwsError = require('./internal/AwsError')
16
16
  const parseURL = require('./internal/parseURL')
17
17
  const retryHTTPRequest = require('./internal/retryHTTPRequest')
18
18
  const createS3DeleteObjectError = require('./internal/createS3DeleteObjectError')
19
- const createS3DeleteAllObjectsAggregateError = require('./internal/createS3DeleteAllObjectsAggregateError')
20
19
  const XML = require('./XML')
21
20
  const HTMLEntities = require('html-entities')
22
21
  const encodeURIComponentRFC3986 = require('./internal/encodeURIComponentRFC3986')
@@ -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
- switch (getFirstKey(AttributeValue)) {
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 ${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, name) {
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
- // TODO
5
- const throwThrottlingException = () => {
6
- const error = new Error('Rate exceeded')
7
- error.name = 'ThrottlingException'
8
- throw error
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
- const test = new Test('RetryAwsErrors', RetryAwsErrors)
29
+ assert.rejects(
30
+ retryThrowError(),
31
+ new Error('test')
32
+ )
12
33
 
13
- test.case(throwThrottlingException)
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
- if (streamData.Shards.length > 0) {
34
- yield* streamData.Shards.map(assign({ StreamArn: options.StreamArn }))
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
- if (streamData.Shards.length > 0) {
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
@@ -1,6 +1,6 @@
1
1
  // { [key string]: any } => key
2
2
  const getFirstKey = object => {
3
- let key = null
3
+ let key
4
4
  for (const firstKey in object) {
5
5
  key = firstKey
6
6
  break
@@ -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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "presidium",
3
- "version": "4.0.6",
4
- "description": "A library for creating web services",
3
+ "version": "4.0.8",
4
+ "description": "The Presidium library.",
5
5
  "author": "Richard Tong",
6
6
  "license": "CFOSS",
7
7
  "main": "index.js",
@@ -1,16 +0,0 @@
1
- // createS3DeleteAllObjectsAggregateError(Errors Array<{ Key: string, VersionId: string, Code: string, Message: string }>) -> AggregateError
2
- function createS3DeleteAllObjectsAggregateError(Errors) {
3
- const errors = Errors.map(({ Key, VersionId, Code, Message }) => {
4
- if (VersionId) {
5
- const error = new Error(`${Key}/${VersionId}: ${Message}`)
6
- error.name = Code
7
- return error
8
- }
9
- const error = new Error(`${Key}: ${Message}`)
10
- error.name = Code
11
- return error
12
- })
13
- return new AggregateError(errors)
14
- }
15
-
16
- module.exports = createS3DeleteAllObjectsAggregateError
@@ -1,50 +0,0 @@
1
- const Test = require('thunk-test')
2
- const createS3DeleteAllObjectsAggregateError = require('./createS3DeleteAllObjectsAggregateError')
3
-
4
- const test = new Test('createS3DeleteAllObjectsAggregateError', createS3DeleteAllObjectsAggregateError)
5
-
6
- function createError(name, message) {
7
- const error = new Error(message)
8
- error.name = name
9
- return error
10
- }
11
-
12
- test.case([
13
- {
14
- Key: 'testkey1',
15
- Code: 'AccessDenied',
16
- Message: 'Access Denied',
17
- },
18
- {
19
- Key: 'testkey1',
20
- Code: 'AllAccessDisabled',
21
- Message: 'All access to this Amazon S3 resource has been disabled. Contact AWS Support for further assistance.',
22
- },
23
- ], new AggregateError([
24
- createError('AccessDenied', 'testkey1: Access Denied'),
25
- createError('AllAccessDisabled', 'testkey1: All access to this Amazon S3 resource has been disabled. Contact AWS Support for further assistance.'),
26
- ]))
27
-
28
- test.case([
29
- {
30
- Key: 'testkey1',
31
- VersionId: '1',
32
- Code: 'AccessDenied',
33
- Message: 'Access Denied',
34
- },
35
- {
36
- Key: 'testkey1',
37
- VersionId: '1',
38
- Code: 'AllAccessDisabled',
39
- Message: 'All access to this Amazon S3 resource has been disabled. Contact AWS Support for further assistance.',
40
- },
41
- ], new AggregateError([
42
- createError('AccessDenied', 'testkey1/1: Access Denied'),
43
- createError('AllAccessDisabled', 'testkey1/1: All access to this Amazon S3 resource has been disabled. Contact AWS Support for further assistance.'),
44
- ]))
45
-
46
- if (process.argv[1] == __filename) {
47
- test()
48
- }
49
-
50
- module.exports = test