presidium 0.16.11 → 0.16.15

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/Dynamo.js CHANGED
@@ -442,4 +442,23 @@ Dynamo.attributeValueToJSON = function attributeValueToJSON(attributeValue) {
442
442
  }
443
443
  }
444
444
 
445
+ /**
446
+ * @name Dynamo.itemResponseToJSON
447
+ *
448
+ * @synopsis
449
+ * ```coffeescript [specscript]
450
+ * Dynamo.itemResponseToJSON(
451
+ * dynamoResponse {
452
+ * Item: Object<DynamoAttributeValue>
453
+ * }
454
+ * ) -> json Object
455
+ * ```
456
+ */
457
+ Dynamo.itemResponseToJSON = function itemResponseToJSON(dynamoResponse) {
458
+ return pipe(dynamoResponse, [
459
+ get('Item'),
460
+ map(Dynamo.attributeValueToJSON),
461
+ ])
462
+ }
463
+
445
464
  module.exports = Dynamo
package/Dynamo.test.js CHANGED
@@ -29,6 +29,12 @@ const combinedTest = Test.all([
29
29
  .case({ M: { a: { N: '1' }, b: { L: [{ S: 'a' }, { BOOL: true }] } } }, { a: 1, b: ['a', true] })
30
30
  .throws(NaN, new TypeError('unknown attributeValue NaN')),
31
31
 
32
+ Test('Dynamo.itemResponseToJSON', Dynamo.itemResponseToJSON)
33
+ .case({ Item: { a: { S: 'hey' } } }, { a: 'hey' })
34
+ .case({ Item: { b: { S: '' } } }, { b: '' })
35
+ .case({ Item: { c: { N: '1' } } }, { c: 1 })
36
+ .case({ Item: { a: { M: { a: { N: '1' }, b: { L: [{ S: 'a' }, { BOOL: true }] } } } } }, { a: { a: 1, b: ['a', true] } }),
37
+
32
38
  Test('Dynamo.AttributeType', Dynamo.AttributeType)
33
39
  .case('string', 'S')
34
40
  .case('S', 'S')
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @name DynamoIndexQueryIterator
3
+ *
4
+ * @synopsis
5
+ * ```coffeescript [specscript]
6
+ * DynamoIndexQueryIterator(
7
+ * dynamoIndex DynamoIndex,
8
+ * keyConditionExpression string,
9
+ * queryValues object,
10
+ * options? {
11
+ * limit?: number,
12
+ * scanIndexForward?: boolean, // true for ASC, false for DESC
13
+ * },
14
+ * ) -> AsyncGenerator<DynamoItem>
15
+ * ```
16
+ */
17
+ const DynamoIndexQueryIterator = async function* (
18
+ dynamoIndex, keyConditionExpression, queryValues, options = {}
19
+ ) {
20
+ const {
21
+ limit = 1000,
22
+ scanIndexForward = true,
23
+ } = options
24
+
25
+ let response = await dynamoIndex.query(
26
+ keyConditionExpression,
27
+ queryValues,
28
+ { limit, scanIndexForward },
29
+ )
30
+ yield* response.Items
31
+
32
+ while (response.LastEvaluatedKey != null) {
33
+ response = await dynamoIndex.query(
34
+ keyConditionExpression,
35
+ queryValues,
36
+ {
37
+ limit,
38
+ scanIndexForward,
39
+ exclusiveStartKey: response.LastEvaluatedKey,
40
+ },
41
+ )
42
+ yield* response.Items
43
+ }
44
+ }
45
+
46
+ module.exports = DynamoIndexQueryIterator
@@ -0,0 +1,72 @@
1
+ require('rubico/global')
2
+ const Test = require('thunk-test')
3
+ const assert = require('assert')
4
+ const Dynamo = require('./Dynamo')
5
+ const DynamoTable = require('./DynamoTable')
6
+ const DynamoIndex = require('./DynamoIndex')
7
+ const DynamoIndexQueryIterator = require('./DynamoIndexQueryIterator')
8
+
9
+ const test = new Test('DynamoIndexQueryIterator', async function () {
10
+ const testTable = new DynamoTable({
11
+ name: 'test_table',
12
+ key: [{ id: 'string' }],
13
+ endpoint: 'http://localhost:8000/',
14
+ region: 'dynamodblocal',
15
+ })
16
+ await testTable.ready
17
+
18
+ const testStatusCreateTimeIndex = new DynamoIndex({
19
+ table: 'test_table',
20
+ key: [{ status: 'string' }, { createTime: 'number' }],
21
+ endpoint: 'http://localhost:8000/',
22
+ region: 'dynamodblocal',
23
+ })
24
+ await testStatusCreateTimeIndex.ready
25
+
26
+ {
27
+ let number = -1
28
+ while (++number < 50) {
29
+ await testTable.putItem({
30
+ id: number.toString(),
31
+ status: 'pending',
32
+ createTime: number + 1,
33
+ })
34
+ }
35
+ }
36
+
37
+ {
38
+ const array = []
39
+ const iter = DynamoIndexQueryIterator(
40
+ testStatusCreateTimeIndex,
41
+ 'status = :status AND createTime > :createTime',
42
+ { status: 'pending', createTime: 0 },
43
+ { limit: 10, scanIndexForward: true },
44
+ )
45
+ for await (const item of iter) {
46
+ array.push(map(item, Dynamo.attributeValueToJSON))
47
+ }
48
+ assert.equal(array.length, 50)
49
+ assert.equal(array[0].id, '0')
50
+ }
51
+
52
+ {
53
+ const array = []
54
+ const iter = DynamoIndexQueryIterator(
55
+ testStatusCreateTimeIndex,
56
+ 'status = :status AND createTime > :createTime',
57
+ { status: 'pending', createTime: 0 },
58
+ { limit: 10, scanIndexForward: false },
59
+ )
60
+ for await (const item of iter) {
61
+ array.push(map(item, Dynamo.attributeValueToJSON))
62
+ }
63
+ assert.equal(array.length, 50)
64
+ assert.equal(array[0].id, '49')
65
+ }
66
+ }).case()
67
+
68
+ if (process.argv[1] == __filename) {
69
+ test()
70
+ }
71
+
72
+ module.exports = test
package/EC2.js CHANGED
@@ -124,15 +124,15 @@ const EC2 = function (options) {
124
124
  * },
125
125
  * AvailabilityZone: string, // 'us-west-1a'
126
126
  * Events: Array,
127
- * InstanceState: {
127
+ * InstanceState: { // the intended state of the instance
128
128
  * Code: number, // 16
129
129
  * Name: string, // 'running'
130
130
  * },
131
- * InstanceStatus: {
131
+ * InstanceStatus: { // reports impaired functionality that stems from issues internal to the instance, such as impaired reachability
132
132
  * Details: Array,
133
133
  * Status: string, // 'ok'
134
134
  * },
135
- * SystemStatus: {
135
+ * SystemStatus: { // reports impaired functionality that stems from issues related to systems that support the instance, such as hardware failures and network connectivity problems
136
136
  * Details: Array,
137
137
  * Status: string, // 'ok'
138
138
  * }
@@ -0,0 +1,58 @@
1
+ /*
2
+ // Use this code snippet in your app.
3
+ // If you need more information about configurations or implementing the sample code, visit the AWS docs:
4
+ // https://aws.amazon.com/developers/getting-started/nodejs/
5
+
6
+ // Load the AWS SDK
7
+ var AWS = require('aws-sdk'),
8
+ region = "us-west-1",
9
+ secretName = "production/PAYPAL_CLIENT_ID",
10
+ secret,
11
+ decodedBinarySecret;
12
+
13
+ // Create a Secrets Manager client
14
+ var client = new AWS.SecretsManager({
15
+ region: region
16
+ });
17
+
18
+ // In this sample we only handle the specific exceptions for the 'GetSecretValue' API.
19
+ // See https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html
20
+ // We rethrow the exception by default.
21
+
22
+ client.getSecretValue({SecretId: secretName}, function(err, data) {
23
+ if (err) {
24
+ if (err.code === 'DecryptionFailureException')
25
+ // Secrets Manager can't decrypt the protected secret text using the provided KMS key.
26
+ // Deal with the exception here, and/or rethrow at your discretion.
27
+ throw err;
28
+ else if (err.code === 'InternalServiceErrorException')
29
+ // An error occurred on the server side.
30
+ // Deal with the exception here, and/or rethrow at your discretion.
31
+ throw err;
32
+ else if (err.code === 'InvalidParameterException')
33
+ // You provided an invalid value for a parameter.
34
+ // Deal with the exception here, and/or rethrow at your discretion.
35
+ throw err;
36
+ else if (err.code === 'InvalidRequestException')
37
+ // You provided a parameter value that is not valid for the current state of the resource.
38
+ // Deal with the exception here, and/or rethrow at your discretion.
39
+ throw err;
40
+ else if (err.code === 'ResourceNotFoundException')
41
+ // We can't find the resource that you asked for.
42
+ // Deal with the exception here, and/or rethrow at your discretion.
43
+ throw err;
44
+ }
45
+ else {
46
+ // Decrypts secret using the associated KMS key.
47
+ // Depending on whether the secret is a string or binary, one of these fields will be populated.
48
+ if ('SecretString' in data) {
49
+ secret = data.SecretString;
50
+ } else {
51
+ let buff = new Buffer(data.SecretBinary, 'base64');
52
+ decodedBinarySecret = buff.toString('ascii');
53
+ }
54
+ }
55
+
56
+ // Your code goes here.
57
+ });
58
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium",
3
- "version": "0.16.11",
3
+ "version": "0.16.15",
4
4
  "description": "A library for creating web services",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",