@nxtedition/lib 20.1.2 → 20.2.1

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/couch.js CHANGED
@@ -132,7 +132,7 @@ export function makeCouch(opts) {
132
132
  * @param {string} [options.since=null] - The sequence number to start from.
133
133
  * @yields {Array<{ id: string, seq?: string, doc?: Object, deleted?: boolean, changes: Array<{ rev: string }> }>}
134
134
  */
135
- async function* changes({ client = defaultClient, signal = null, ...options } = {}) {
135
+ async function* changes({ client = defaultClient, signal = null, logger, ...options } = {}) {
136
136
  const params = {}
137
137
 
138
138
  let body
@@ -221,7 +221,13 @@ export function makeCouch(opts) {
221
221
  }
222
222
 
223
223
  const live = options.live == null || !!options.live
224
- const retry = options.retry
224
+ const retry =
225
+ options.retry ??
226
+ (async (err, retryCount, params, { signal }, next) => {
227
+ logger?.error({ err, retryCount, params }, 'changes error')
228
+ return next()
229
+ })
230
+
225
231
  const limit = options.limit
226
232
 
227
233
  try {
package/mutex.js ADDED
@@ -0,0 +1,50 @@
1
+ import Queue from 'yocto-queue'
2
+
3
+ export default class Mutex {
4
+ #queue = new Queue()
5
+ #isLocked = false
6
+
7
+ tryLock() {
8
+ if (!this.#isLocked) {
9
+ this.#isLocked = true
10
+ return true
11
+ }
12
+
13
+ return false
14
+ }
15
+
16
+ async lock() {
17
+ if (!this.#isLocked) {
18
+ this.#isLocked = true
19
+ return
20
+ }
21
+
22
+ return new Promise((resolve) => {
23
+ this.#queue.enqueue(resolve)
24
+ })
25
+ }
26
+
27
+ unlock() {
28
+ if (this.#queue.size > 0) {
29
+ const resolve = this.#queue.dequeue()
30
+ resolve()
31
+ } else {
32
+ this.#isLocked = false
33
+ }
34
+ }
35
+
36
+ async withLock(task) {
37
+ try {
38
+ if (!this.tryLock()) {
39
+ await this.lock()
40
+ }
41
+ return await task()
42
+ } finally {
43
+ this.unlock()
44
+ }
45
+ }
46
+
47
+ get isLocked() {
48
+ return this.#isLocked
49
+ }
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "20.1.2",
3
+ "version": "20.2.1",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -18,6 +18,7 @@
18
18
  "http.js",
19
19
  "s3.js",
20
20
  "time.js",
21
+ "mutex.js",
21
22
  "deepstream.js",
22
23
  "sequence.js",
23
24
  "logger.js",
@@ -79,7 +80,8 @@
79
80
  "split-string": "^6.0.0",
80
81
  "undici": "^6.19.7",
81
82
  "url-join": "^5.0.0",
82
- "xuid": "^4.1.3"
83
+ "xuid": "^4.1.3",
84
+ "yocto-queue": "^1.1.1"
83
85
  },
84
86
  "devDependencies": {
85
87
  "@nxtedition/deepstream.io-client-js": ">=25.6.3",
package/platform.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export const SIGNALS =
2
2
  typeof process === 'object'
3
- ? {
3
+ ? ({
4
4
  linux: {
5
5
  129: 'SIGHUP', // 1
6
6
  130: 'SIGINT', // 2
@@ -34,5 +34,5 @@ export const SIGNALS =
34
34
  158: 'SIGPWR', // 30
35
35
  159: 'SIGSYS', // 31
36
36
  },
37
- }[process.platform] ?? {}
37
+ }[process.platform] ?? {})
38
38
  : {}
package/s3.js CHANGED
@@ -321,7 +321,7 @@ function getTransformedHeaders(headers) {
321
321
  const headerValues = headers[name]
322
322
  transformedHeaders[name] = Array.isArray(headerValues)
323
323
  ? headerValues.join(',')
324
- : headerValues ?? ''
324
+ : (headerValues ?? '')
325
325
  }
326
326
 
327
327
  return transformedHeaders