presidium 4.0.7 → 4.0.9

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.
@@ -23,12 +23,6 @@ const getChromeUrl = require('./internal/getChromeUrl')
23
23
  const getAbsoluteFilePath = require('./internal/getAbsoluteFilePath')
24
24
  const getChromeBinaryOrExecutableFilePath = require('./internal/getChromeBinaryOrExecutableFilePath')
25
25
 
26
- function updateConsoleLog(message, platform) {
27
- readline.cursorTo(process.stdout, 0, undefined);
28
- readline.clearLine(process.stdout, 0);
29
- process.stdout.write(message);
30
- }
31
-
32
26
  async function installChrome() {
33
27
  const platform = getPlatform()
34
28
  const url = await getChromeUrl.call(this, platform)
@@ -53,9 +47,9 @@ async function installChrome() {
53
47
  response.on('data', chunk => {
54
48
  downloadedLength += chunk.length
55
49
  if (downloadedLength == contentLength) {
56
- updateConsoleLog(`Downloading ${url} (${downloadedLength} / ${contentLength} bytes)\n`, platform)
50
+ console.log(`Downloading ${url} (${downloadedLength} / ${contentLength} bytes)\n`, platform)
57
51
  } else {
58
- updateConsoleLog(`Downloading ${url} (${downloadedLength} / ${contentLength} bytes)`, platform)
52
+ console.log(`Downloading ${url} (${downloadedLength} / ${contentLength} bytes)`, platform)
59
53
  }
60
54
 
61
55
  fileStream.write(chunk)
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)
@@ -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.7",
4
- "description": "A library for creating web services",
3
+ "version": "4.0.9",
4
+ "description": "The Presidium library.",
5
5
  "author": "Richard Tong",
6
6
  "license": "CFOSS",
7
7
  "main": "index.js",