@nxtedition/lib 15.0.13 → 15.0.15

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/errors.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const objectHash = require('object-hash')
2
2
  const fp = require('lodash/fp.js')
3
3
  const { toString } = Object.prototype
4
+ const { SIGNALS } = require('./platform.js')
4
5
 
5
6
  module.exports.AbortError = class AbortError extends Error {
6
7
  constructor(message) {
@@ -77,6 +78,7 @@ module.exports.serializeError = function serializeError(error) {
77
78
  message = msg,
78
79
  errors,
79
80
  code,
81
+ signal,
80
82
  cause,
81
83
  body,
82
84
  statusCode,
@@ -85,6 +87,10 @@ module.exports.serializeError = function serializeError(error) {
85
87
  ...properties
86
88
  } = error
87
89
 
90
+ if (typeof signal === 'number') {
91
+ signal = SIGNALS[signal] ?? signal
92
+ }
93
+
88
94
  errors = Array.isArray(errors) ? errors.map(serializeError) : undefined
89
95
  cause = cause ? serializeError(cause) : undefined
90
96
 
@@ -96,6 +102,7 @@ module.exports.serializeError = function serializeError(error) {
96
102
  message,
97
103
  type,
98
104
  code,
105
+ signal,
99
106
  status,
100
107
  headers,
101
108
  data,
@@ -67,7 +67,6 @@ const dispatchers = {
67
67
  abort: require('./interceptor/abort.js'),
68
68
  catch: require('./interceptor/catch.js'),
69
69
  content: require('./interceptor/content.js'),
70
- responseBodyDump: require('./interceptor/response-body-dump.js'),
71
70
  log: require('./interceptor/log.js'),
72
71
  redirect: require('./interceptor/redirect.js'),
73
72
  responseBodyRetry: require('./interceptor/response-body-retry.js'),
@@ -92,7 +91,6 @@ async function request(urlOrOpts, opts = {}) {
92
91
 
93
92
  const method = opts.method ?? (opts.body ? 'POST' : 'GET')
94
93
  const idempotent = opts.idempotent ?? (method === 'GET' || method === 'HEAD')
95
- const dump = opts.dump ?? method === 'HEAD'
96
94
 
97
95
  let headers
98
96
  if (Array.isArray(opts.headers)) {
@@ -119,7 +117,6 @@ async function request(urlOrOpts, opts = {}) {
119
117
  signal: opts.signal,
120
118
  retry: opts.retry ?? 8,
121
119
  follow: { count: opts.maxRedirections ?? 8, ...opts.redirect, ...opts.follow },
122
- dump,
123
120
  logger: opts.logger,
124
121
  }
125
122
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "15.0.13",
3
+ "version": "15.0.15",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "files": [
@@ -13,6 +13,7 @@
13
13
  "http-client.js",
14
14
  "subtract-ranges.js",
15
15
  "serializers.js",
16
+ "platform.js",
16
17
  "elasticsearch.js",
17
18
  "merge-ranges.js",
18
19
  "http.js",
package/platform.js ADDED
@@ -0,0 +1,36 @@
1
+ module.exports.SIGNALS =
2
+ {
3
+ linux: {
4
+ 129: 'SIGHUP', // 1
5
+ 130: 'SIGINT', // 2
6
+ 131: 'SIGQUIT', // 3
7
+ 132: 'SIGILL', // 4
8
+ 133: 'SIGTRAP', // 5
9
+ 134: 'SIGABRT', // 6
10
+ 135: 'SIGBUS', // 7
11
+ 136: 'SIGFPE', // 8
12
+ 137: 'SIGKILL', // 9
13
+ 138: 'SIGUSR1', // 10
14
+ 139: 'SIGSEGV', // 11
15
+ 140: 'SIGUSR2', // 12
16
+ 141: 'SIGPIPE', // 13
17
+ 142: 'SIGALRM', // 14
18
+ 143: 'SIGTERM', // 15
19
+ 144: 'SIGSTKFLT', // 16
20
+ 145: 'SIGCHLD', // 17
21
+ 146: 'SIGCONT', // 18
22
+ 147: 'SIGSTOP', // 19
23
+ 148: 'SIGTSTP', // 20
24
+ 149: 'SIGTTIN', // 21
25
+ 150: 'SIGTTOU', // 22
26
+ 151: 'SIGURG', // 23
27
+ 152: 'SIGXCPU', // 24
28
+ 153: 'SIGXFSZ', // 25
29
+ 154: 'SIGVTALRM', // 26
30
+ 155: 'SIGPROF', // 27
31
+ 156: 'SIGWINCH', // 28
32
+ 157: 'SIGIO', // 29
33
+ 158: 'SIGPWR', // 30
34
+ 159: 'SIGSYS', // 31
35
+ },
36
+ }[process.platform] ?? {}
package/serializers.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const serializers = require('pino-std-serializers')
2
+ const { SIGNALS } = require('./platform.js')
2
3
 
3
4
  function getHeader(obj, key) {
4
5
  return obj?.headers?.get?.(key) || obj?.getHeader?.(key) || obj?.headers?.[key]
@@ -29,6 +30,8 @@ function getHeaders(obj) {
29
30
 
30
31
  module.exports = {
31
32
  err: (err) => {
33
+ // TODO (fix): Merge with errors/serializeError?
34
+
32
35
  if (Array.isArray(err)) {
33
36
  err = err.length === 1 ? err[0] : new AggregateError(err)
34
37
  }
@@ -38,6 +41,10 @@ module.exports = {
38
41
  ret.data = JSON.stringify(ret.data)
39
42
  }
40
43
 
44
+ if (typeof ret.signal === 'number') {
45
+ ret.signal = SIGNALS[ret.signal] ?? String(ret.signal)
46
+ }
47
+
41
48
  return ret
42
49
  },
43
50
  res: (res) =>
@@ -1,46 +0,0 @@
1
- const { AbortError } = require('../../../errors')
2
-
3
- class Handler {
4
- constructor(opts, { handler }) {
5
- this.handler = handler
6
- this.pos = 0
7
- }
8
-
9
- onConnect(abort) {
10
- this.abort = abort
11
- return this.handler.onConnect?.(abort)
12
- }
13
-
14
- onBodySent(chunk) {
15
- return this.handler.onBodySent?.(chunk)
16
- }
17
-
18
- onHeaders(statusCode, rawHeaders, resume, statusMessage) {
19
- return this.handler.onHeaders?.(statusCode, rawHeaders, resume, statusMessage)
20
- }
21
-
22
- onData(chunk) {
23
- this.pos += chunk.length
24
- if (this.pos < 128 * 1024) {
25
- return true
26
- }
27
-
28
- this.handler.onComplete?.([])
29
- this.handler = null
30
-
31
- this.abort(new AbortError('dump'))
32
-
33
- return false
34
- }
35
-
36
- onComplete(rawTrailers) {
37
- return this.handler.onComplete?.([])
38
- }
39
-
40
- onError(err) {
41
- return this.handler?.onError?.(err)
42
- }
43
- }
44
-
45
- module.exports = (dispatch) => (opts, handler) =>
46
- opts.dump ? dispatch(opts, new Handler(opts, { handler })) : dispatch(opts, handler)