@signalk/streams 1.19.0 → 2.0.3

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/mdns-ws.js CHANGED
@@ -18,14 +18,11 @@ const Transform = require('stream').Transform
18
18
 
19
19
  const SignalK = require('@signalk/client')
20
20
 
21
- const debug = require('debug')('signalk:streams:mdns-ws')
22
- const dataDebug = require('debug')('signalk:streams:mdns-ws-data')
23
-
24
21
  const WebSocket = require('ws')
25
22
 
26
- function MdnsWs (options) {
23
+ function MdnsWs(options) {
27
24
  Transform.call(this, {
28
- objectMode: true
25
+ objectMode: true,
29
26
  })
30
27
  this.options = options
31
28
  this.selfHost = options.app.config.getExternalHostname() + '.'
@@ -33,9 +30,13 @@ function MdnsWs (options) {
33
30
  this.remoteServers = {}
34
31
  this.remoteServers[this.selfHost + ':' + this.selfPort] = {}
35
32
  const deltaStreamBehaviour = options.subscription ? 'none' : 'all'
33
+
34
+ const createDebug = options.createDebug || require('debug')
35
+ this.debug = createDebug('signalk:streams:mdns-ws')
36
+ this.dataDebug = createDebug('signalk:streams:mdns-ws-data')
36
37
  debug(`deltaStreamBehaviour:${deltaStreamBehaviour}`)
37
38
 
38
- this.handleContext = () => { }
39
+ this.handleContext = () => {}
39
40
  if (options.selfHandling === 'manualSelf') {
40
41
  if (options.remoteSelf) {
41
42
  debug(`Using manual remote self ${options.remoteSelf}`)
@@ -45,12 +46,14 @@ function MdnsWs (options) {
45
46
  }
46
47
  }
47
48
  } else {
48
- console.error('Manual self handling speficied but no remoteSelf configured')
49
+ console.error(
50
+ 'Manual self handling speficied but no remoteSelf configured'
51
+ )
49
52
  }
50
53
  }
51
54
 
52
55
  if (options.ignoreServers) {
53
- options.ignoreServers.forEach(s => {
56
+ options.ignoreServers.forEach((s) => {
54
57
  this.remoteServers[s] = {}
55
58
  })
56
59
  }
@@ -62,18 +65,21 @@ function MdnsWs (options) {
62
65
  reconnect: true,
63
66
  autoConnect: false,
64
67
  deltaStreamBehaviour,
65
- rejectUnauthorized: !(options.selfsignedcert === true)
68
+ rejectUnauthorized: !(options.selfsignedcert === true),
66
69
  })
67
70
  this.connect(this.signalkClient)
68
71
  } else {
69
- this.options.app.setProviderError(this.options.providerId, 'This connection is deprecated and must be deleted')
72
+ this.options.app.setProviderError(
73
+ this.options.providerId,
74
+ 'This connection is deprecated and must be deleted'
75
+ )
70
76
  return
71
77
  }
72
78
  }
73
79
 
74
80
  require('util').inherits(MdnsWs, Transform)
75
81
 
76
- function setProviderStatus (that, providerId, message, isError) {
82
+ function setProviderStatus(that, providerId, message, isError) {
77
83
  if (!isError) {
78
84
  that.options.app.setProviderStatus(providerId, message)
79
85
  console.log(message)
@@ -89,50 +95,70 @@ MdnsWs.prototype.connect = function (client) {
89
95
  client
90
96
  .connect()
91
97
  .then(() => {
92
- setProviderStatus(that, that.options.providerId, `ws connection connected to ${client.options.hostname}:${client.options.port}`)
98
+ setProviderStatus(
99
+ that,
100
+ that.options.providerId,
101
+ `ws connection connected to ${client.options.hostname}:${client.options.port}`
102
+ )
93
103
  if (this.options.selfHandling === 'useRemoteSelf') {
94
- client.API().then(api => api.get('/self')).then(selfFromServer => {
95
- debug(`Mapping context ${selfFromServer} to self (empty context)`)
96
- this.handleContext = (delta) => {
97
- if (delta.context === selfFromServer) {
98
- delete delta.context
104
+ client
105
+ .API()
106
+ .then((api) => api.get('/self'))
107
+ .then((selfFromServer) => {
108
+ that.debug(
109
+ `Mapping context ${selfFromServer} to self (empty context)`
110
+ )
111
+ this.handleContext = (delta) => {
112
+ if (delta.context === selfFromServer) {
113
+ delete delta.context
114
+ }
99
115
  }
100
- }
101
- }).catch(err => {
102
- console.error('Error retrieving self from remote server')
103
- console.error(err)
104
- })
116
+ })
117
+ .catch((err) => {
118
+ console.error('Error retrieving self from remote server')
119
+ console.error(err)
120
+ })
105
121
  }
106
- that.remoteServers[client.options.hostname + ':' + client.options.port] = client
107
- if ( that.options.subscription ) {
108
- let parsed
122
+ that.remoteServers[client.options.hostname + ':' + client.options.port] =
123
+ client
124
+ if (that.options.subscription) {
125
+ let parsed
109
126
  try {
110
127
  parsed = JSON.parse(that.options.subscription)
111
- } catch ( ex ) {
112
- setProviderStatus(that, that.options.providerId, `unable to parse subscription json: ${that.options.subscription}: ${ex.message}`, true)
128
+ } catch (ex) {
129
+ setProviderStatus(
130
+ that,
131
+ that.options.providerId,
132
+ `unable to parse subscription json: ${that.options.subscription}: ${ex.message}`,
133
+ true
134
+ )
113
135
  }
114
- if ( !Array.isArray(parsed) ) {
115
- parsed = [ parsed ]
136
+ if (!Array.isArray(parsed)) {
137
+ parsed = [parsed]
116
138
  }
117
139
  parsed.forEach((sub, idx) => {
118
- debug('sending subscription %j', sub)
140
+ that.debug('sending subscription %j', sub)
119
141
  client.subscribe(sub, String(idx))
120
142
  })
121
143
  }
122
144
  })
123
- .catch(err => {
145
+ .catch((err) => {
124
146
  setProviderStatus(that, that.options.providerId, err.message, true)
125
147
  })
126
-
148
+
127
149
  client.on('delta', (data) => {
128
150
  if (data && data.updates) {
129
151
  that.handleContext(data)
130
- if (dataDebug.enabled) { dataDebug(JSON.stringify(data)) }
152
+ if (that.dataDebug.enabled) {
153
+ that.dataDebug(JSON.stringify(data))
154
+ }
131
155
  data.updates.forEach(function (update) {
132
- update['$source'] = `${that.options.providerId}.${client.options.hostname}:${client.options.port}`
156
+ update[
157
+ '$source'
158
+ ] = `${that.options.providerId}.${client.options.hostname}:${client.options.port}`
133
159
  })
134
160
  }
135
-
161
+
136
162
  that.push(data)
137
163
  })
138
164
  }
package/n2k-signalk.js CHANGED
@@ -20,22 +20,22 @@ const N2kMapper = require('@signalk/n2k-signalk').N2kMapper
20
20
 
21
21
  require('util').inherits(ToSignalK, Transform)
22
22
 
23
- function ToSignalK (options) {
23
+ function ToSignalK(options) {
24
24
  Transform.call(this, {
25
- objectMode: true
25
+ objectMode: true,
26
26
  })
27
27
  const n2kOutEvent = 'nmea2000JsonOut'
28
28
  this.sourceMeta = {}
29
29
  this.notifications = {}
30
30
  this.options = options
31
31
  this.app = options.app
32
- if ( options.filters && options.filtersEnabled ) {
33
- this.filters = options.filters.filter(f => {
32
+ if (options.filters && options.filtersEnabled) {
33
+ this.filters = options.filters.filter((f) => {
34
34
  return (f.source && f.source.length) || (f.pgn && f.pgn.length)
35
35
  })
36
36
  }
37
37
 
38
- this.n2kMapper = new N2kMapper({...options, sendMetaData: true})
38
+ this.n2kMapper = new N2kMapper({ ...options, sendMetaData: true })
39
39
 
40
40
  this.n2kMapper.on('n2kOut', (pgn) => this.app.emit('nmea2000JsonOut', pgn))
41
41
 
@@ -43,7 +43,7 @@ function ToSignalK (options) {
43
43
  const existing = this.sourceMeta[n2k.src] || {}
44
44
  this.sourceMeta[n2k.src] = {
45
45
  ...existing,
46
- ...meta
46
+ ...meta,
47
47
  }
48
48
  const delta = {
49
49
  context: this.app.selfContext,
@@ -54,21 +54,24 @@ function ToSignalK (options) {
54
54
  label: this.options.providerId,
55
55
  type: 'NMEA2000',
56
56
  pgn: Number(n2k.pgn),
57
- src: n2k.src.toString()
57
+ src: n2k.src.toString(),
58
58
  },
59
59
  timestamp:
60
60
  n2k.timestamp.substring(0, 10) +
61
61
  'T' +
62
62
  n2k.timestamp.substring(11, n2k.timestamp.length),
63
- values: []
64
- }
65
- ]
63
+ values: [],
64
+ },
65
+ ],
66
66
  }
67
- this.app.deltaCache.setSourceDelta(`${this.options.providerId}.${n2k.src}`, delta)
67
+ this.app.deltaCache.setSourceDelta(
68
+ `${this.options.providerId}.${n2k.src}`,
69
+ delta
70
+ )
68
71
  })
69
72
 
70
73
  this.n2kMapper.on('n2kSourceMetadataTimeout', (pgn, src) => {
71
- if ( pgn == 60928 ) {
74
+ if (pgn == 60928) {
72
75
  console.warn(`n2k-signalk: unable to detect can name for src ${src}`)
73
76
  this.sourceMeta[src].unknowCanName = true
74
77
  }
@@ -76,86 +79,110 @@ function ToSignalK (options) {
76
79
 
77
80
  this.n2kMapper.on('n2kSourceChanged', (src, from, to) => {
78
81
  console.warn(`n2k-signalk: address ${src} changed from ${from} ${to}`)
79
- if ( this.sourceMeta[src] ) {
82
+ if (this.sourceMeta[src]) {
80
83
  delete this.sourceMeta[src]
81
84
  }
82
85
  })
83
86
 
84
- if ( this.app.isNmea2000OutAvailable ) {
87
+ if (this.app.isNmea2000OutAvailable) {
85
88
  this.n2kMapper.n2kOutIsAvailable(this.app, n2kOutEvent)
86
89
  } else {
87
90
  this.app.on('nmea2000OutAvailable', () =>
88
- this.n2kMapper.n2kOutIsAvailable(this.app, n2kOutEvent))
91
+ this.n2kMapper.n2kOutIsAvailable(this.app, n2kOutEvent)
92
+ )
89
93
  }
90
94
  }
91
95
 
92
- ToSignalK.prototype.isFiltered = function(source) {
93
- return this.filters && this.filters.find(filter => {
94
- const sFilter = this.options.useCanName ? source.canName : source.src
95
- return (!filter.source || filter.source.length === 0 || filter.source == sFilter) && (!filter.pgn || filter.pgn.length === 0 || filter.pgn == source.pgn)
96
- })
96
+ ToSignalK.prototype.isFiltered = function (source) {
97
+ return (
98
+ this.filters &&
99
+ this.filters.find((filter) => {
100
+ const sFilter = this.options.useCanName ? source.canName : source.src
101
+ return (
102
+ (!filter.source ||
103
+ filter.source.length === 0 ||
104
+ filter.source == sFilter) &&
105
+ (!filter.pgn || filter.pgn.length === 0 || filter.pgn == source.pgn)
106
+ )
107
+ })
108
+ )
97
109
  }
98
110
 
99
111
  ToSignalK.prototype._transform = function (chunk, encoding, done) {
100
112
  try {
101
113
  const delta = this.n2kMapper.toDelta(chunk)
102
-
114
+
103
115
  const src = Number(chunk.src)
104
- if ( !this.sourceMeta[src] ) {
116
+ if (!this.sourceMeta[src]) {
105
117
  this.sourceMeta[src] = {}
106
- }
118
+ }
107
119
 
108
- if (delta && delta.updates[0].values.length > 0 && !this.isFiltered(delta.updates[0].source) ) {
109
- if ( !this.options.useCanName ) {
120
+ if (
121
+ delta &&
122
+ delta.updates[0].values.length > 0 &&
123
+ !this.isFiltered(delta.updates[0].source)
124
+ ) {
125
+ if (!this.options.useCanName) {
110
126
  delete delta.updates[0].source.canName
111
127
  }
112
128
 
113
129
  const canName = delta.updates[0].source.canName
114
-
115
- if ( this.options.useCanName && !canName && !this.sourceMeta[src].unknowCanName ) {
130
+
131
+ if (
132
+ this.options.useCanName &&
133
+ !canName &&
134
+ !this.sourceMeta[src].unknowCanName
135
+ ) {
116
136
  done()
117
137
  return
118
138
  }
119
139
 
120
- delta.updates.forEach(update => {
121
- update.values.forEach(kv => {
122
- if ( kv.path && kv.path.startsWith('notifications.') ) {
123
- if ( kv.value.state === 'normal' && this.notifications[kv.path] && this.notifications[kv.path][src]) {
124
- clearInterval(this.notifications[kv.path][src].interval)
125
- delete this.notifications[kv.path][src]
126
- } else if ( kv.value.state !== 'normal' ) {
127
- if ( !this.notifications[kv.path] ) {
128
- this.notifications[kv.path] = {}
129
- }
130
- if ( !this.notifications[kv.path][src] ) {
131
- const interval = setInterval(() => {
132
- if (Date.now() - this.notifications[kv.path][src].lastTime > 10000) {
133
- const copy = JSON.parse(JSON.stringify(kv))
134
- copy.value.state = 'normal'
135
- const normalDelta = {
136
- context: delta.context,
137
- updates: [
138
- {
139
- source: update.source,
140
- values: [ copy ]
141
- }
142
- ]
143
- }
144
- delete this.notifications[kv.path][src]
145
- clearInterval(interval)
146
- this.app.handleMessage(this.options.providerId, normalDelta)
140
+ delta.updates.forEach((update) => {
141
+ update.values.forEach((kv) => {
142
+ if (kv.path && kv.path.startsWith('notifications.')) {
143
+ if (
144
+ kv.value.state === 'normal' &&
145
+ this.notifications[kv.path] &&
146
+ this.notifications[kv.path][src]
147
+ ) {
148
+ clearInterval(this.notifications[kv.path][src].interval)
149
+ delete this.notifications[kv.path][src]
150
+ } else if (kv.value.state !== 'normal') {
151
+ if (!this.notifications[kv.path]) {
152
+ this.notifications[kv.path] = {}
153
+ }
154
+ if (!this.notifications[kv.path][src]) {
155
+ const interval = setInterval(() => {
156
+ if (
157
+ Date.now() - this.notifications[kv.path][src].lastTime >
158
+ 10000
159
+ ) {
160
+ const copy = JSON.parse(JSON.stringify(kv))
161
+ copy.value.state = 'normal'
162
+ const normalDelta = {
163
+ context: delta.context,
164
+ updates: [
165
+ {
166
+ source: update.source,
167
+ values: [copy],
168
+ },
169
+ ],
147
170
  }
148
- }, 5000)
149
- this.notifications[kv.path][src] = {
150
- lastTime: Date.now(),
151
- interval: interval
171
+ delete this.notifications[kv.path][src]
172
+ clearInterval(interval)
173
+ this.app.handleMessage(this.options.providerId, normalDelta)
152
174
  }
153
- } else {
154
- this.notifications[kv.path][src].lastTime = Date.now()
175
+ }, 5000)
176
+ this.notifications[kv.path][src] = {
177
+ lastTime: Date.now(),
178
+ interval: interval,
155
179
  }
180
+ } else {
181
+ this.notifications[kv.path][src].lastTime = Date.now()
156
182
  }
157
183
  }
158
- })
184
+ }
185
+ })
159
186
  })
160
187
  this.push(delta)
161
188
  }
package/n2kAnalyzer.js CHANGED
@@ -15,21 +15,20 @@
15
15
  */
16
16
 
17
17
  const Transform = require('stream').Transform
18
- const debug = require('debug')('signalk:streams:n2k-analyzer')
19
18
 
20
- function N2KAnalyzer (options) {
19
+ function N2KAnalyzer(options) {
21
20
  Transform.call(this, {
22
- objectMode: true
21
+ objectMode: true,
23
22
  })
24
23
  if (process.platform === 'win32') {
25
24
  this.analyzerProcess = require('child_process').spawn('cmd', [
26
25
  '/c',
27
- 'analyzer -json -si'
26
+ 'analyzer -json -si',
28
27
  ])
29
28
  } else {
30
29
  this.analyzerProcess = require('child_process').spawn('sh', [
31
30
  '-c',
32
- 'analyzer -json -si'
31
+ 'analyzer -json -si',
33
32
  ])
34
33
  }
35
34
  this.analyzerProcess.stderr.on('data', function (data) {
@@ -68,7 +67,7 @@ N2KAnalyzer.prototype.pipe = function (pipeTo) {
68
67
  }
69
68
 
70
69
  N2KAnalyzer.prototype.end = function () {
71
- debug('end, killing child analyzer process')
70
+ console.log('end, killing child analyzer process')
72
71
  this.analyzerProcess.kill()
73
72
  this.pipeTo.end()
74
73
  }
@@ -32,14 +32,15 @@
32
32
  const Transform = require('stream').Transform
33
33
  const Parser = require('@signalk/nmea0183-signalk')
34
34
  const utils = require('@signalk/nmea0183-utilities')
35
- const debug = require('debug')('signalk:streams:nmea0183-signalk')
36
35
  const n2kToDelta = require('@signalk/n2k-signalk').toDelta
37
36
  const FromPgn = require('@canboat/canboatjs').FromPgn
38
37
 
39
- function Nmea0183ToSignalK (options) {
38
+ function Nmea0183ToSignalK(options) {
40
39
  Transform.call(this, {
41
- objectMode: true
40
+ objectMode: true,
42
41
  })
42
+ this.debug = (options.createDebug || require('debug'))('signalk:streams:nmea0183-signalk')
43
+
43
44
 
44
45
  this.parser = new Parser(options)
45
46
  this.n2kParser = new FromPgn(options)
@@ -50,7 +51,7 @@ function Nmea0183ToSignalK (options) {
50
51
 
51
52
  // Prepare a list of events to send for each sentence received
52
53
  this.sentenceEvents = options.suppress0183event ? [] : ['nmea0183']
53
- this.appendChecksum = options.appendChecksum;
54
+ this.appendChecksum = options.appendChecksum
54
55
 
55
56
  if (options.sentenceEvent) {
56
57
  if (Array.isArray(options.sentenceEvent)) {
@@ -79,19 +80,19 @@ Nmea0183ToSignalK.prototype._transform = function (chunk, encoding, done) {
79
80
  try {
80
81
  if (sentence !== undefined) {
81
82
  if (this.appendChecksum) {
82
- sentence = utils.appendChecksum(sentence);
83
+ sentence = utils.appendChecksum(sentence)
83
84
  }
84
85
  // Send 'sentences' event to the app for each sentence
85
- this.sentenceEvents.forEach(eventName => {
86
+ this.sentenceEvents.forEach((eventName) => {
86
87
  this.app.emit(eventName, sentence)
87
88
  this.app.signalk.emit(eventName, sentence)
88
89
  })
89
90
 
90
91
  let delta = null
91
- if ( this.n2kParser.isN2KOver0183(sentence) ) {
92
+ if (this.n2kParser.isN2KOver0183(sentence)) {
92
93
  const pgn = this.n2kParser.parseN2KOver0183(sentence)
93
- if ( pgn ) {
94
- delta = n2kToDelta(pgn, this.state, {sendMetaData: true})
94
+ if (pgn) {
95
+ delta = n2kToDelta(pgn, this.state, { sendMetaData: true })
95
96
  }
96
97
  } else {
97
98
  delta = this.parser.parse(sentence)
@@ -99,7 +100,7 @@ Nmea0183ToSignalK.prototype._transform = function (chunk, encoding, done) {
99
100
 
100
101
  if (delta !== null) {
101
102
  if (timestamp !== null) {
102
- delta.updates.forEach(update => {
103
+ delta.updates.forEach((update) => {
103
104
  update.timestamp = timestamp
104
105
  })
105
106
  }
@@ -108,7 +109,7 @@ Nmea0183ToSignalK.prototype._transform = function (chunk, encoding, done) {
108
109
  }
109
110
  }
110
111
  } catch (e) {
111
- debug(`[error] ${e.message}`)
112
+ this.debug(e)
112
113
  }
113
114
 
114
115
  done()
package/nullprovider.js CHANGED
@@ -20,9 +20,9 @@
20
20
 
21
21
  const Transform = require('stream').Transform
22
22
 
23
- function NullProvider (options) {
23
+ function NullProvider(options) {
24
24
  Transform.call(this, {
25
- objectMode: true
25
+ objectMode: true,
26
26
  })
27
27
  }
28
28
 
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@signalk/streams",
3
- "version": "1.19.0",
3
+ "version": "2.0.3",
4
4
  "description": "Utilities for handling streams of Signal K data",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
7
+ "ci": "prettier --check .",
8
+ "format": "prettier --write ."
8
9
  },
9
10
  "repository": {
10
11
  "type": "git",
@@ -28,7 +29,6 @@
28
29
  "@signalk/nmea0183-utilities": "^0.8.0",
29
30
  "@signalk/signalk-schema": "^1.5.0",
30
31
  "any-shell-escape": "^0.1.1",
31
- "aws-sdk": "^2.413.0",
32
32
  "file-timestamp-stream": "^2.1.2",
33
33
  "lodash": "^4.17.4",
34
34
  "moment": "^2.24.0",
@@ -38,5 +38,8 @@
38
38
  },
39
39
  "optionalDependencies": {
40
40
  "serialport": "^9.0.1"
41
+ },
42
+ "devDependencies": {
43
+ "prettier": "2.5.1"
41
44
  }
42
45
  }
package/pigpio-seatalk.js CHANGED
@@ -15,14 +15,13 @@
15
15
  *
16
16
  * You should have received a copy of the GNU General Public License
17
17
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
- *
18
+ *
19
19
  * 2020-06-24 Original Python code from @Thomas-GeDaD https://github.com/Thomas-GeDaD/Seatalk1-Raspi-reader
20
20
  * and finetuned by @MatsA
21
21
  *
22
22
  */
23
23
 
24
24
  const Execute = require('./execute')
25
- const debug = require('debug')('signalk:streams:pigpio-seatalk')
26
25
 
27
26
  const cmd = `
28
27
  import pigpio, time, signal, sys
@@ -79,13 +78,13 @@ if __name__ == "__main__":
79
78
  print ("exit")
80
79
  `
81
80
 
82
- function PigpioSeatalk (options) {
83
- Execute.call(this, {debug})
81
+ function PigpioSeatalk(options) {
82
+ const createDebug = options.createDebug || require('debug')
83
+ Execute.call(this, { debug: createDebug('signalk:streams:pigpio-seatalk') })
84
84
  this.options = options
85
85
  this.options.command = `python -u -c '${cmd}' ${options.gpio} ${options.gpioInvert} `
86
86
  }
87
87
 
88
88
  require('util').inherits(PigpioSeatalk, Execute)
89
89
 
90
-
91
90
  module.exports = PigpioSeatalk
package/replacer.js CHANGED
@@ -14,21 +14,19 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
-
18
17
  const Transform = require('stream').Transform
19
18
 
20
19
  require('util').inherits(Replacer, Transform)
21
20
 
22
- function Replacer (options) {
21
+ function Replacer(options) {
23
22
  Transform.call(this, {
24
- objectMode: true
23
+ objectMode: true,
25
24
  })
26
25
  this.doPush = this.push.bind(this)
27
26
  this.regexp = new RegExp(options.regexp, 'gu')
28
27
  this.template = options.template
29
28
  }
30
29
 
31
-
32
30
  Replacer.prototype._transform = function (chunk, encoding, done) {
33
31
  this.doPush(chunk.toString().replace(this.regexp, this.template))
34
32
  done()
package/s3.js CHANGED
@@ -15,12 +15,19 @@
15
15
  */
16
16
 
17
17
  var Transform = require('stream').Transform
18
+ /*
19
+ aws-sdk is not included in dependencies because of the
20
+ persistent deprecation warnings caused by its transitive
21
+ dependencies. This feature is not in wide use, especially
22
+ not in signalk-server where people encounter the scary looking
23
+ deprecation warnings.
24
+ Known to work with ^2.413.0
25
+ */
18
26
  const AWS = require('aws-sdk')
19
- const debug = require('debug')('signalk:streams:s3-provider')
20
27
 
21
- function S3Provider ({ bucket, prefix }) {
28
+ function S3Provider({ bucket, prefix }) {
22
29
  Transform.call(this, {
23
- objectMode: false
30
+ objectMode: false,
24
31
  })
25
32
  this.Bucket = bucket
26
33
  this.Prefix = prefix
@@ -34,12 +41,12 @@ S3Provider.prototype.pipe = function (pipeTo) {
34
41
  const s3 = new AWS.S3()
35
42
  const params = {
36
43
  Bucket: this.Bucket,
37
- Prefix: this.Prefix
44
+ Prefix: this.Prefix,
38
45
  }
39
46
  console.log('listobjects')
40
47
  s3.listObjects(params)
41
48
  .promise()
42
- .then(data => {
49
+ .then((data) => {
43
50
  // console.log(data)
44
51
  const jobs = data.Contents.map(
45
52
  (item, i) =>
@@ -48,18 +55,15 @@ S3Provider.prototype.pipe = function (pipeTo) {
48
55
  console.log('Starting key ' + item.Key)
49
56
  const objectParams = {
50
57
  Bucket: params.Bucket,
51
- Key: item.Key
58
+ Key: item.Key,
52
59
  }
53
60
  const request = s3.getObject(objectParams)
54
- request.on('error', err => {
61
+ request.on('error', (err) => {
55
62
  console.log(err)
56
63
  })
57
64
  const stream = request.createReadStream()
58
65
  stream.on('end', resolve)
59
- stream.pipe(
60
- pipeTo,
61
- { end: i === data.Contents.length-1 }
62
- )
66
+ stream.pipe(pipeTo, { end: i === data.Contents.length - 1 })
63
67
  })
64
68
  }
65
69
  )
@@ -67,14 +71,14 @@ S3Provider.prototype.pipe = function (pipeTo) {
67
71
  let i = 0
68
72
  function startNext() {
69
73
  if (i < jobs.length) {
70
- jobs[i++]().then(startNext);
74
+ jobs[i++]().then(startNext)
71
75
  } else {
72
76
  doEnd()
73
77
  }
74
78
  }
75
- startNext();
79
+ startNext()
76
80
  })
77
- .catch(error => {
81
+ .catch((error) => {
78
82
  console.error(error)
79
83
  })
80
84
  return pipeTo