@nxtedition/lib 19.7.0 → 19.7.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.
Files changed (4) hide show
  1. package/app.js +1 -1
  2. package/couch.js +10 -1
  3. package/package.json +2 -1
  4. package/time.js +32 -0
package/app.js CHANGED
@@ -278,7 +278,7 @@ export function makeApp(appConfig, onTerminate) {
278
278
  dsConfig.credentials.username ||
279
279
  dsConfig.credentials.userName ||
280
280
  dsConfig.credentials.user ||
281
- serviceName
281
+ `_${serviceName}`
282
282
 
283
283
  dsConfig = {
284
284
  maxReconnectAttempts: Infinity,
package/couch.js CHANGED
@@ -1028,11 +1028,16 @@ class StreamOutput extends stream.Readable {
1028
1028
  #abort
1029
1029
  #state
1030
1030
  #decoder
1031
+ #headers
1031
1032
 
1032
1033
  constructor({ highWaterMark = 256 }) {
1033
1034
  super({ objectMode: true, highWaterMark })
1034
1035
  }
1035
1036
 
1037
+ get headers() {
1038
+ return this.#headers
1039
+ }
1040
+
1036
1041
  _read() {
1037
1042
  this.#resume?.()
1038
1043
  }
@@ -1060,6 +1065,7 @@ class StreamOutput extends stream.Readable {
1060
1065
  throw new Error('invalid status code: ' + statusCode)
1061
1066
  }
1062
1067
 
1068
+ this.#headers = Array.isArray(rawHeaders) ? undiciUtil.parseHeaders(rawHeaders) : rawHeaders
1063
1069
  this.#resume = resume
1064
1070
  }
1065
1071
 
@@ -1108,6 +1114,7 @@ class PromiseOutput {
1108
1114
  #reject
1109
1115
  #str
1110
1116
  #decoder
1117
+ #headers
1111
1118
 
1112
1119
  constructor({ resolve, reject }) {
1113
1120
  this.#resolve = resolve
@@ -1123,6 +1130,7 @@ class PromiseOutput {
1123
1130
  if (statusCode >= 300 || statusCode < 200) {
1124
1131
  throw new Error('invalid status code: ' + statusCode)
1125
1132
  }
1133
+ this.#headers = Array.isArray(rawHeaders) ? undiciUtil.parseHeaders(rawHeaders) : rawHeaders
1126
1134
  }
1127
1135
 
1128
1136
  onData(data) {
@@ -1131,7 +1139,8 @@ class PromiseOutput {
1131
1139
 
1132
1140
  onComplete() {
1133
1141
  this.#str += this.#decoder.decode(undefined, { stream: false })
1134
- this.#resolve(JSON.parse(this.#str))
1142
+
1143
+ this.#resolve(Object.assign(JSON.parse(this.#str), { headers: this.#headers }))
1135
1144
  }
1136
1145
 
1137
1146
  onError(err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "19.7.0",
3
+ "version": "19.7.2",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -17,6 +17,7 @@
17
17
  "merge-ranges.js",
18
18
  "http.js",
19
19
  "s3.js",
20
+ "time.js",
20
21
  "deepstream.js",
21
22
  "sequence.js",
22
23
  "logger.js",
package/time.js ADDED
@@ -0,0 +1,32 @@
1
+ export function isTimeBetween(date, startTime, endTime) {
2
+ const currentHours = date.getHours()
3
+ const currentMinutes = date.getMinutes()
4
+
5
+ let [startHours, startMinutes] = startTime?.split(':').map(Number) ?? [null, 0]
6
+ let [endHours, endMinutes] = endTime?.split(':').map(Number) ?? [null, 0]
7
+
8
+ if (startHours == null) {
9
+ startHours = -Number.MAX_SAFE_INTEGER
10
+ }
11
+
12
+ if (endHours == null) {
13
+ endHours = Number.MAX_SAFE_INTEGER
14
+ }
15
+
16
+ if (startHours < endHours || (startHours === endHours && startMinutes <= endMinutes)) {
17
+ // The time range is within the same day
18
+ return (currentHours > startHours ||
19
+ (currentHours === startHours && currentMinutes >= startMinutes)) &&
20
+ (currentHours < endHours || (currentHours === endHours && currentMinutes <= endMinutes))
21
+ ? { currentHours, currentMinutes, startHours, startMinutes, endHours, endMinutes }
22
+ : null
23
+ } else {
24
+ // The time range spans across two days
25
+ return currentHours > startHours ||
26
+ (currentHours === startHours && currentMinutes >= startMinutes) ||
27
+ currentHours < endHours ||
28
+ (currentHours === endHours && currentMinutes <= endMinutes)
29
+ ? { currentHours, currentMinutes, startHours, startMinutes, endHours, endMinutes }
30
+ : null
31
+ }
32
+ }