presidium 0.16.28 → 0.17.0

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/DockerService.js CHANGED
@@ -107,35 +107,39 @@ const DockerService = function (options) {
107
107
  if (this == null || this.constructor != DockerService) {
108
108
  return new DockerService(options)
109
109
  }
110
+ this.serviceOptions = pick(dockerServiceOptions)(options)
110
111
  this.name = options.name
111
112
  this.docker = new Docker()
112
113
  this.version = null
113
114
  this.spec = null
114
115
  this.replicas = options.replicas
115
-
116
- this.ready = this.docker.inspectService(this.name).then(pipe([
117
- switchCase([
118
- eq(404, get('status')),
119
- pipe([
120
- () => this.docker.createService(
121
- this.name,
122
- pick(dockerServiceOptions)(options)),
123
- tap(async response => {
124
- if (!response.ok) {
125
- throw new Error(await response.text())
126
- }
127
- }),
128
- ]),
129
- pipe([
130
- tap(() => this.synchronize()),
131
- () => this.update(pick(dockerServiceOptions)(options)),
132
- ]),
133
- ]),
134
- tap(() => this.synchronize()),
135
- ]))
136
116
  return this
137
117
  }
138
118
 
119
+ /**
120
+ * @name DockerService.prototype.deploy
121
+ *
122
+ * @synopsis
123
+ * ```coffeescript [specscript]
124
+ * DockerService(...).deploy()
125
+ * ```
126
+ */
127
+ DockerService.prototype.deploy = async function deploy() {
128
+ const { status } = await this.docker.inspectService(this.name)
129
+
130
+ if (status == 404) {
131
+ const { name, serviceOptions } = this
132
+ const response = await this.docker.createService(name, serviceOptions)
133
+ if (!response.ok) {
134
+ throw new Error(await response.text())
135
+ }
136
+ } else {
137
+ await this.synchronize()
138
+ await this.update(this.serviceOptions)
139
+ }
140
+ await this.synchronize()
141
+ }
142
+
139
143
  // new DockerService().synchronize() -> Promise<>
140
144
  DockerService.prototype.synchronize = function dockerServiceSynchronize() {
141
145
  return this.docker.inspectService(this.name).then(pipe([
@@ -21,6 +21,8 @@ const test = new Test('DockerService', DockerService)
21
21
  image: 'nginx:1.19',
22
22
  replicas: 1,
23
23
  }, async function (myService) {
24
+ await myService.deploy()
25
+
24
26
  {
25
27
  const info = await myService.inspect()
26
28
  this.serviceId = info.ID
@@ -106,7 +108,7 @@ const test = new Test('DockerService', DockerService)
106
108
  image: 'nginx:1.19',
107
109
  replicas: 2,
108
110
  }, async function (myService) {
109
- await myService.ready
111
+ await myService.deploy()
110
112
  // TODO test for update on construction assert.deepEqual(myService.spec, this.myServiceSpec)
111
113
  })
112
114
 
@@ -116,8 +118,8 @@ const test = new Test('DockerService', DockerService)
116
118
  replicas: 2,
117
119
  restart: 'always', // coulda fooled me
118
120
  }, async function (errorService) {
119
- assert.rejects(
120
- always(errorService.ready),
121
+ await assert.rejects(
122
+ errorService.deploy(),
121
123
  new Error('{"message":"invalid RestartCondition: \\"always\\""}\n'))
122
124
  })
123
125
 
package/Password.test.js CHANGED
@@ -5,6 +5,10 @@ const Password = require('./Password')
5
5
  const test = new Test('Password', async function () {
6
6
  const plaintext = 'MyPassword!123'
7
7
  const hashed = await Password.hash(plaintext)
8
+ await assert.rejects(
9
+ Password.verify('incorrect', hashed),
10
+ new Error('Invalid password'),
11
+ )
8
12
  await Password.verify(plaintext, hashed) // should not throw
9
13
  }).case()
10
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium",
3
- "version": "0.16.28",
3
+ "version": "0.17.0",
4
4
  "description": "A library for creating web services",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",