presidium 0.20.0 → 0.20.2

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/Docker.js CHANGED
@@ -1114,20 +1114,25 @@ Docker.prototype.getServiceLogs = async function getServiceLogs(serviceId, optio
1114
1114
  }`)
1115
1115
  }
1116
1116
 
1117
+ const toArray = value => Array.isArray(value) ? value : [value]
1118
+
1117
1119
  /**
1118
1120
  * @name Docker.prototype.listTasks
1119
1121
  *
1120
1122
  * @synopsis
1121
1123
  * ```coffeescript [specscript]
1122
1124
  * new Docker().listTasks(options {
1123
- * service?: string,
1124
- * node?: string,
1125
+ * desiredState: 'running'|'shutdown'|'accepted'
1125
1126
  * }) -> Promise<HttpResponse>
1126
1127
  * ```
1127
1128
  */
1128
- Docker.prototype.listTasks = async function listTasks(options) {
1129
+ Docker.prototype.listTasks = async function listTasks(options = {}) {
1129
1130
  return this.http.get(`/tasks?${
1130
- querystring.stringify(pick(['service', 'node'])(options))
1131
+ querystring.stringify({
1132
+ filters: JSON.stringify(filter({
1133
+ 'desired-state': toArray(options.desiredState),
1134
+ }, value => value != null)),
1135
+ })
1131
1136
  }`)
1132
1137
  }
1133
1138
 
package/Docker.test.js CHANGED
@@ -410,6 +410,12 @@ EXPOSE 8888`,
410
410
  assert.equal(body.length, 3) // 2 for hey1, 1 for hey2 (global)
411
411
  }
412
412
 
413
+ { // listTasks filter
414
+ const response = await docker.listTasks({ desiredState: 'accepted' })
415
+ const body = await response.json()
416
+ assert.equal(body.length, 0)
417
+ }
418
+
413
419
  { // deleteService
414
420
  const response = await docker.deleteService(this.serviceId1)
415
421
  assert.equal(response.status, 200)
package/DockerImage.js CHANGED
@@ -13,7 +13,10 @@ const stream = require('stream')
13
13
  const pathJoin = require('./internal/pathJoin')
14
14
  const parseJSON = require('./internal/parseJSON')
15
15
 
16
- const passthrough = target => transform(Transducer.passthrough, target)
16
+ const passthrough = target => transform(
17
+ Transducer.map(chunk => chunk.toString('utf8')),
18
+ target,
19
+ )
17
20
 
18
21
  const PassThroughStream = stream.PassThrough
19
22
 
@@ -15,6 +15,7 @@ const charCode = string => string.charCodeAt(0)
15
15
  const test = new Test('DockerImage', DockerImage)
16
16
  .case('doesnot:exist', async function (dneImage) {
17
17
  const data = await dneImage.inspect()
18
+ console.log(data)
18
19
  assert(data.message.toLowerCase().startsWith('no such image'), data.message)
19
20
  })
20
21
  .case('node:15-alpine', async function (alpineImage) {
@@ -8,8 +8,8 @@
8
8
  * keyConditionExpression string,
9
9
  * queryValues object,
10
10
  * options? {
11
+ * batchLimit?: number,
11
12
  * limit?: number,
12
- * scanIndexForward?: boolean, // true for ASC, false for DESC
13
13
  * },
14
14
  * ) -> AsyncGenerator<DynamoItem>
15
15
  * ```
@@ -18,28 +18,31 @@ const DynamoIndexQueryIterator = async function* (
18
18
  dynamoIndex, keyConditionExpression, queryValues, options = {}
19
19
  ) {
20
20
  const {
21
- limit = 1000,
22
- scanIndexForward = true,
21
+ batchLimit = 1000,
22
+ limit = Infinity,
23
23
  } = options
24
24
 
25
+ let numYielded = 0
25
26
  let response = await dynamoIndex.query(
26
27
  keyConditionExpression,
27
28
  queryValues,
28
- { limit, scanIndexForward },
29
+ { limit: Math.min(batchLimit, limit - numYielded), ...options },
29
30
  )
30
31
  yield* response.Items
32
+ numYielded += response.Items.length
31
33
 
32
- while (response.LastEvaluatedKey != null) {
34
+ while (response.LastEvaluatedKey != null && numYielded < limit) {
33
35
  response = await dynamoIndex.query(
34
36
  keyConditionExpression,
35
37
  queryValues,
36
38
  {
37
- limit,
38
- scanIndexForward,
39
+ limit: Math.min(batchLimit, limit - numYielded),
39
40
  exclusiveStartKey: response.LastEvaluatedKey,
41
+ ...options,
40
42
  },
41
43
  )
42
44
  yield* response.Items
45
+ numYielded += response.Items.length
43
46
  }
44
47
  }
45
48
 
@@ -40,7 +40,6 @@ const test = new Test('DynamoIndexQueryIterator', async function () {
40
40
  testStatusCreateTimeIndex,
41
41
  'status = :status AND createTime > :createTime',
42
42
  { status: 'pending', createTime: 0 },
43
- { limit: 10, scanIndexForward: true },
44
43
  )
45
44
  for await (const item of iter) {
46
45
  array.push(map(item, Dynamo.attributeValueToJSON))
@@ -55,7 +54,22 @@ const test = new Test('DynamoIndexQueryIterator', async function () {
55
54
  testStatusCreateTimeIndex,
56
55
  'status = :status AND createTime > :createTime',
57
56
  { status: 'pending', createTime: 0 },
58
- { limit: 10, scanIndexForward: false },
57
+ { batchLimit: 10, scanIndexForward: true },
58
+ )
59
+ for await (const item of iter) {
60
+ array.push(map(item, Dynamo.attributeValueToJSON))
61
+ }
62
+ assert.equal(array.length, 50)
63
+ assert.equal(array[0].id, '0')
64
+ }
65
+
66
+ {
67
+ const array = []
68
+ const iter = DynamoIndexQueryIterator(
69
+ testStatusCreateTimeIndex,
70
+ 'status = :status AND createTime > :createTime',
71
+ { status: 'pending', createTime: 0 },
72
+ { batchLimit: 10, scanIndexForward: false },
59
73
  )
60
74
  for await (const item of iter) {
61
75
  array.push(map(item, Dynamo.attributeValueToJSON))
@@ -63,6 +77,22 @@ const test = new Test('DynamoIndexQueryIterator', async function () {
63
77
  assert.equal(array.length, 50)
64
78
  assert.equal(array[0].id, '49')
65
79
  }
80
+
81
+ {
82
+ const array = []
83
+ const iter = DynamoIndexQueryIterator(
84
+ testStatusCreateTimeIndex,
85
+ 'status = :status AND createTime > :createTime',
86
+ { status: 'pending', createTime: 0 },
87
+ { batchLimit: 10, limit: 30, scanIndexForward: true },
88
+ )
89
+ for await (const item of iter) {
90
+ array.push(map(item, Dynamo.attributeValueToJSON))
91
+ }
92
+ assert.equal(array.length, 30)
93
+ assert.equal(array[0].id, '0')
94
+ }
95
+
66
96
  }).case()
67
97
 
68
98
  if (process.argv[1] == __filename) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium",
3
- "version": "0.20.0",
3
+ "version": "0.20.2",
4
4
  "description": "A library for creating web services",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",