@nxtedition/lib 20.2.3 → 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.
- package/couch.js +12 -30
- package/package.json +1 -1
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
|
|
1145
|
+
const ureq = {
|
|
1146
|
+
...opts,
|
|
1163
1147
|
url,
|
|
1164
|
-
method,
|
|
1165
|
-
|
|
1166
|
-
blocking,
|
|
1148
|
+
method: opts.method ?? (opts.body ? 'POST' : 'GET'),
|
|
1149
|
+
blocking: opts.blocking ?? Boolean(stream),
|
|
1167
1150
|
headers: {
|
|
1168
|
-
'content-type':
|
|
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
|
-
|
|
1173
|
-
|
|
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,
|
|
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,
|
|
1167
|
+
dispatch(dispatcher, ureq, handler)
|
|
1186
1168
|
})
|
|
1187
1169
|
}
|
|
1188
1170
|
}
|