@nxtedition/lib 19.0.26 → 19.0.28

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/deepstream.js CHANGED
@@ -119,6 +119,25 @@ function get(ds, name, ...args) {
119
119
  )
120
120
  }
121
121
 
122
+ function getRecord(ds, name, ...args) {
123
+ let query = null
124
+
125
+ if (args.length > 0 && (args[0] == null || typeof args[0] === 'object')) {
126
+ query = args.shift()
127
+ }
128
+
129
+ name = `${name}`
130
+
131
+ return ds.record.getRecord(
132
+ `${name}${
133
+ query && Object.keys(query).length > 0
134
+ ? `${name.endsWith('?') ? '' : '?'}${qs.stringify(query, { skipNulls: true })}`
135
+ : ''
136
+ }`,
137
+ ...args,
138
+ )
139
+ }
140
+
122
141
  function query(ds, designId, options) {
123
142
  const next = (startkey, prevRows, limit) =>
124
143
  Number.isFinite(limit) && limit <= 0
@@ -164,6 +183,7 @@ export function makeDeepstream(ds) {
164
183
  query: (...args) => query(ds, ...args),
165
184
  set: (...args) => ds.record.set(...args),
166
185
  get: (...args) => get(ds, ...args),
186
+ getRecord: (...args) => getRecord(ds, ...args),
167
187
  update: (...args) => ds.record.update(...args),
168
188
  },
169
189
  }
@@ -177,11 +197,13 @@ Object.assign(makeDeepstream, {
177
197
  observe2,
178
198
  query,
179
199
  get,
200
+ getRecord,
180
201
  record: {
181
202
  provide,
182
203
  observe,
183
204
  observe2,
184
205
  query,
185
206
  get,
207
+ getRecord,
186
208
  },
187
209
  })
package/errors.js CHANGED
@@ -22,10 +22,9 @@ export function parseError(error) {
22
22
  }
23
23
 
24
24
  if (Array.isArray(error)) {
25
- error = error.map(parseError).filter(Boolean)
26
- if (error.length === 1) {
27
- error = error.length === 1 ? error[0] : { errors: error }
28
- }
25
+ return error.length > 1
26
+ ? new AggregateError(error.map(parseError).filter(Boolean))
27
+ : parseError(error[0])
29
28
  }
30
29
 
31
30
  const { msg, message = msg, errors, cause, data, ...properties } = error
@@ -138,7 +137,7 @@ export function makeMessages(error, options) {
138
137
  return fp.pipe(
139
138
  fp.flattenDeep,
140
139
  fp.flatMap((x) => makeMessages(x, options)),
141
- fp.uniqBy('id'),
140
+ fp.uniqBy(fp.isEqual),
142
141
  )(error)
143
142
  } else if (Array.isArray(error.messages)) {
144
143
  return makeMessages(error.messages, options)
package/http.js CHANGED
@@ -23,6 +23,9 @@ function genReqId() {
23
23
  return `req-${nextReqId.toString(36)}`
24
24
  }
25
25
 
26
+ let reqTimeoutError
27
+ let resTimeoutError
28
+
26
29
  export async function request(ctx, next) {
27
30
  const { req, res, logger } = ctx
28
31
  const startTime = performance.now()
@@ -62,14 +65,14 @@ export async function request(ctx, next) {
62
65
  new Promise((resolve, reject) => {
63
66
  req
64
67
  .on('timeout', function () {
65
- this.destroy(new createError.RequestTimeout())
68
+ this.destroy((reqTimeoutError ??= new createError.RequestTimeout()))
66
69
  })
67
70
  .on('error', function (err) {
68
71
  this.log.error({ err }, 'request error')
69
72
  })
70
73
  res
71
74
  .on('timeout', function () {
72
- this.destroy(new createError.RequestTimeout())
75
+ this.destroy((resTimeoutError ??= new createError.RequestTimeout()))
73
76
  })
74
77
  .on('error', function (err) {
75
78
  reject(err)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "19.0.26",
3
+ "version": "19.0.28",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",