@nxtedition/lib 20.2.2 → 20.3.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.
Files changed (3) hide show
  1. package/couch.js +12 -30
  2. package/package.json +1 -1
  3. package/serializers.js +4 -0
package/couch.js CHANGED
@@ -1136,53 +1136,35 @@ const defaultDispatcher = new Agent({
1136
1136
  connections: 8,
1137
1137
  })
1138
1138
 
1139
- export function request(
1140
- url,
1141
- {
1142
- body = null,
1143
- method = body ? 'POST' : 'GET',
1144
- query = null,
1145
- headers = null,
1146
- dispatcher = defaultDispatcher,
1147
- signal = null,
1148
- logger = null,
1149
- stream = false,
1150
- blocking = Boolean(stream),
1151
- headerTimeout,
1152
- bodyTimeout,
1153
- } = {},
1154
- ) {
1155
- signal?.throwIfAborted()
1156
-
1139
+ export function request(url, { dispatcher = defaultDispatcher, signal, ...opts } = {}) {
1157
1140
  url = new URL(url)
1158
1141
  if (url.search) {
1159
1142
  throw new Error('invalid url: ' + url.href)
1160
1143
  }
1161
1144
 
1162
- const opts = {
1145
+ const ureq = {
1146
+ ...opts,
1163
1147
  url,
1164
- method,
1165
- query,
1166
- blocking,
1148
+ method: opts.method ?? (opts.body ? 'POST' : 'GET'),
1149
+ blocking: opts.blocking ?? Boolean(stream),
1167
1150
  headers: {
1168
- 'content-type': body != null && typeof body === 'object' ? 'application/json' : 'plain/text',
1151
+ 'content-type':
1152
+ opts.body != null && typeof opts.body === 'object' ? 'application/json' : 'plain/text',
1169
1153
  accept: 'application/json',
1170
- ...headers,
1154
+ ...opts.headers,
1171
1155
  },
1172
- logger,
1173
- body: body != null && typeof body === 'object' ? JSON.stringify(body) : body,
1174
- headerTimeout,
1175
- bodyTimeout,
1156
+ body:
1157
+ opts.body != null && typeof opts.body === 'object' ? JSON.stringify(opts.body) : opts.body,
1176
1158
  }
1177
1159
 
1178
1160
  if (stream) {
1179
1161
  const handler = new StreamOutput({ signal, ...stream })
1180
- dispatch(dispatcher, opts, handler)
1162
+ dispatch(dispatcher, ureq, handler)
1181
1163
  return handler
1182
1164
  } else {
1183
1165
  return new Promise((resolve, reject) => {
1184
1166
  const handler = new PromiseOutput({ resolve, reject, signal })
1185
- dispatch(dispatcher, opts, handler)
1167
+ dispatch(dispatcher, ureq, handler)
1186
1168
  })
1187
1169
  }
1188
1170
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "20.2.2",
3
+ "version": "20.3.0",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
package/serializers.js CHANGED
@@ -181,6 +181,10 @@ function errSerializer(err) {
181
181
  _err.data = JSON.stringify(_err.data, undefined, 2)
182
182
  }
183
183
 
184
+ if (_err.body != null && typeof _err.body !== 'string') {
185
+ _err.body = JSON.stringify(_err.body, undefined, 2)
186
+ }
187
+
184
188
  if (_err.code != null && typeof _err.code !== 'string') {
185
189
  _err.code = String(_err.code)
186
190
  }