@nxtedition/lib 15.1.7 → 16.0.1

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/app.js CHANGED
@@ -1,15 +1,30 @@
1
- const os = require('node:os')
2
- const net = require('node:net')
3
- const stream = require('node:stream')
4
- const { Buffer } = require('node:buffer')
5
- const { getDockerSecretsSync } = require('./docker-secrets')
6
- const { getGlobalDispatcher } = require('undici')
7
- const fp = require('lodash/fp.js')
8
-
9
- module.exports = function (appConfig, onTerminate) {
1
+ import os from 'node:os'
2
+ import net from 'node:net'
3
+ import stream from 'node:stream'
4
+ import { Buffer } from 'node:buffer'
5
+ import { getDockerSecretsSync } from './docker-secrets.js'
6
+ import { getGlobalDispatcher } from 'undici'
7
+ import fp from 'lodash/fp.js'
8
+ import { isMainThread, parentPort } from 'node:worker_threads'
9
+ import toobusy from 'toobusy-js'
10
+ import deepstream from '@nxtedition/deepstream.io-client-js'
11
+ import { createLogger } from './logger.js'
12
+ import nconf from 'nconf'
13
+ import { makeCouch } from './couch.js'
14
+ import { makeTemplateCompiler } from './util/template/index.js'
15
+ import { makeDeepstream } from './deepstream.js'
16
+ import v8 from 'v8'
17
+ import rxjs from 'rxjs'
18
+ import rx from 'rxjs/operators'
19
+ import { performance } from 'perf_hooks'
20
+ import hashString from './hash.js'
21
+ import { makeTrace } from './trace.js'
22
+ import compose from 'koa-compose'
23
+ import { createServer } from './http.js'
24
+
25
+ export function makeApp(appConfig, onTerminate) {
10
26
  let ds
11
27
  let nxt
12
- let toobusy
13
28
  let couch
14
29
  let server
15
30
  let compiler
@@ -26,7 +41,7 @@ module.exports = function (appConfig, onTerminate) {
26
41
  Buffer.poolSize = 128 * 1024
27
42
 
28
43
  if (stream.setDefaultHighWaterMark) {
29
- stream.setDefaultHighWaterMark(false, 64 * 1024)
44
+ stream.setDefaultHighWaterMark(false, 128 * 1024)
30
45
  }
31
46
 
32
47
  const isProduction = process.env.NODE_ENV === 'production'
@@ -41,8 +56,6 @@ module.exports = function (appConfig, onTerminate) {
41
56
  logger?.warn({ err }, 'warning')
42
57
  })
43
58
 
44
- const { createLogger } = require('./logger')
45
-
46
59
  const cleanAppConfig = ({
47
60
  status,
48
61
  stats,
@@ -59,8 +72,6 @@ module.exports = function (appConfig, onTerminate) {
59
72
  }) => values
60
73
 
61
74
  if (appConfig.config) {
62
- const nconf = require('nconf')
63
-
64
75
  config = nconf
65
76
  .argv()
66
77
  .env({
@@ -152,56 +163,15 @@ module.exports = function (appConfig, onTerminate) {
152
163
 
153
164
  logger.debug({ data: JSON.stringify(config, null, 2) }, 'config')
154
165
 
155
- {
156
- const { isMainThread, parentPort } = require('node:worker_threads')
157
- if (!isMainThread && parentPort) {
158
- parentPort.on('message', ({ type }) => {
159
- if (type === 'nxt:worker:terminate') {
160
- terminate(null, true)
161
- }
162
- })
163
- }
164
- }
165
-
166
- if (appConfig.niceIncrement) {
167
- try {
168
- if (appConfig.niceIncrement !== 0 && process.platform === 'linux') {
169
- const nice = require('nice-napi')
170
- nice(appConfig.niceIncrement)
166
+ if (!isMainThread && parentPort) {
167
+ parentPort.on('message', ({ type }) => {
168
+ if (type === 'nxt:worker:terminate') {
169
+ terminate(null)
171
170
  }
172
- } catch {}
173
- }
174
-
175
- if (appConfig.perf && process.platform === 'linux') {
176
- const perfName = typeof appConfig.perf === 'string' ? appConfig.perf : serviceInstanceId
177
-
178
- try {
179
- const linuxPerf = require('linux-perf')
180
-
181
- let started = false
182
- ds.rpc.provide(`${perfName}:perf.start`, () => {
183
- if (started) {
184
- return false
185
- }
186
- linuxPerf.start()
187
- started = true
188
- return true
189
- })
190
- ds.rpc.provide(`${perfName}:perf.stop`, () => {
191
- if (!started) {
192
- return false
193
- }
194
- linuxPerf.stop()
195
- started = false
196
- return true
197
- })
198
- } catch (err) {
199
- logger.error('could not initialize linux perf')
200
- }
171
+ })
201
172
  }
202
173
 
203
174
  if (appConfig.toobusy) {
204
- toobusy = require('toobusy-js')
205
175
  toobusy.onLag((currentLag) => {
206
176
  if (currentLag > 1e3) {
207
177
  logger.error({ currentLag }, 'lag')
@@ -231,7 +201,6 @@ module.exports = function (appConfig, onTerminate) {
231
201
  )
232
202
 
233
203
  if (couchConfig.url) {
234
- const makeCouch = require('./couch')
235
204
  couch = makeCouch(couchConfig)
236
205
  destroyers.push(() => couch.close())
237
206
  } else {
@@ -240,8 +209,6 @@ module.exports = function (appConfig, onTerminate) {
240
209
  }
241
210
 
242
211
  if (appConfig.deepstream) {
243
- const deepstream = require('@nxtedition/deepstream.io-client-js')
244
-
245
212
  let dsConfig = fp.mergeAll(
246
213
  [
247
214
  { userAgent, url: isProduction ? null : 'ws://127.0.0.1:6020/deepstream' },
@@ -322,7 +289,7 @@ module.exports = function (appConfig, onTerminate) {
322
289
  }
323
290
  })
324
291
 
325
- nxt = require('./deepstream')(ds)
292
+ nxt = makeDeepstream(ds)
326
293
 
327
294
  globalThis.ds = ds
328
295
 
@@ -330,19 +297,13 @@ module.exports = function (appConfig, onTerminate) {
330
297
  }
331
298
 
332
299
  if (appConfig.compiler) {
333
- const createTemplateCompiler = require('./util/template')
334
- compiler = createTemplateCompiler({ ds, ...appConfig.compiler })
300
+ compiler = makeTemplateCompiler({ ds, ...appConfig.compiler })
335
301
  }
336
302
 
337
303
  const monitorProviders = {}
338
304
 
339
305
  let stats$
340
306
  if (appConfig.stats) {
341
- const v8 = require('v8')
342
- const rxjs = require('rxjs')
343
- const rx = require('rxjs/operators')
344
- const { eventLoopUtilization } = require('perf_hooks').performance
345
-
346
307
  if (typeof appConfig.stats.subscribe === 'function') {
347
308
  stats$ = appConfig.stats
348
309
  } else if (typeof appConfig.stats === 'function') {
@@ -378,17 +339,17 @@ module.exports = function (appConfig, onTerminate) {
378
339
 
379
340
  monitorProviders.stats$ = stats$
380
341
 
381
- let elu1 = eventLoopUtilization?.()
342
+ let elu1 = performance.eventLoopUtilization?.()
382
343
  const subscription = stats$.pipe(rx.auditTime(10e3)).subscribe((stats) => {
383
344
  if (process.env.NODE_ENV === 'production') {
384
- const elu2 = eventLoopUtilization?.()
345
+ const elu2 = performance.eventLoopUtilization?.()
385
346
  logger.debug(
386
347
  {
387
348
  ds: ds?.stats,
388
349
  couch: couch?.stats,
389
350
  lag: toobusy?.lag(),
390
351
  memory: process.memoryUsage(),
391
- utilization: eventLoopUtilization?.(elu2, elu1),
352
+ utilization: performance.eventLoopUtilization?.(elu2, elu1),
392
353
  heap: v8.getHeapStatistics(),
393
354
  ...stats,
394
355
  },
@@ -405,11 +366,6 @@ module.exports = function (appConfig, onTerminate) {
405
366
 
406
367
  let status$
407
368
  if (appConfig.status) {
408
- const rxjs = require('rxjs')
409
- const rx = require('rxjs/operators')
410
- const fp = require('lodash/fp')
411
- const hashString = require('./hash')
412
-
413
369
  if (appConfig.status.subscribe) {
414
370
  status$ = appConfig.status
415
371
  } else if (typeof appConfig.status === 'function') {
@@ -639,8 +595,6 @@ module.exports = function (appConfig, onTerminate) {
639
595
  }
640
596
 
641
597
  if (ds && Object.keys(monitorProviders).length && appConfig.monitor !== false) {
642
- const { isMainThread } = require('node:worker_threads')
643
-
644
598
  if (isMainThread) {
645
599
  const unprovide = ds.record.provide(`^([^:]+):monitor\\.([^?]+)[?]?`, (key) => {
646
600
  const [, id, prop] = key.match(/^([^:]+):monitor\.([^?]+)[?]?/)
@@ -666,54 +620,26 @@ module.exports = function (appConfig, onTerminate) {
666
620
  if (appConfig.trace) {
667
621
  const traceConfig = { ...appConfig.trace, ...config.trace }
668
622
  if (traceConfig.url) {
669
- const makeTrace = require('./trace')
670
623
  trace = makeTrace({ ...traceConfig, destroyers, logger, serviceName })
671
624
  }
672
625
  }
673
626
 
674
627
  if (appConfig.http) {
675
- // const undici = require('undici')
676
- const compose = require('koa-compose')
677
- const { createServer } = require('./http')
678
-
679
628
  const httpConfig = { ...appConfig.http, ...config.http }
680
629
 
681
630
  const port = httpConfig.port
682
631
  ? httpConfig.port
683
632
  : typeof httpConfig === 'number'
684
- ? httpConfig
685
- : process.env.NODE_ENV === 'production'
686
- ? 8000
687
- : null
633
+ ? httpConfig
634
+ : process.env.NODE_ENV === 'production'
635
+ ? 8000
636
+ : null
688
637
 
689
638
  if (port != null) {
690
639
  const middleware = compose(
691
640
  [
692
641
  async ({ req, res }, next) => {
693
642
  if (req.url.startsWith('/healthcheck')) {
694
- // if (ds._url || ds.url) {
695
- // try {
696
- // const { host } = new URL(ds._url || ds.url)
697
- // await undici.request(`http://${host}/healthcheck`)
698
- // } catch (err) {
699
- // logger.warn({ err }, 'deepstream healthcheck failed')
700
- // if (err.code === 'ENOTFOUND' || err.code === 'EHOSTUNREACH') {
701
- // throw err
702
- // }
703
- // }
704
- // }
705
-
706
- // if (couch) {
707
- // try {
708
- // await couch.info()
709
- // } catch (err) {
710
- // logger.warn({ err }, 'couch healthcheck failed')
711
- // if (err.code === 'ENOTFOUND' || err.code === 'EHOSTUNREACH') {
712
- // throw err
713
- // }
714
- // }
715
- // }
716
-
717
643
  res.statusCode = 200
718
644
  res.end()
719
645
  } else {
@@ -723,8 +649,8 @@ module.exports = function (appConfig, onTerminate) {
723
649
  appConfig.http.request
724
650
  ? appConfig.http.request
725
651
  : typeof appConfig.http === 'function'
726
- ? appConfig.http
727
- : null,
652
+ ? appConfig.http
653
+ : null,
728
654
  ({ res }) => {
729
655
  res.statusCode = 404
730
656
  res.end()
package/ass.js CHANGED
@@ -1,8 +1,6 @@
1
- const fp = require('lodash/fp')
1
+ import fp from 'lodash/fp.js'
2
2
 
3
- module.exports = { encodeASS }
4
-
5
- function encodeASS(events, { styles = {}, width = 1920, height = 1080 } = {}) {
3
+ export function encodeASS(events, { styles = {}, width = 1920, height = 1080 } = {}) {
6
4
  return [encASSHeader({ width, height }), encASSStyles(styles), encASSEvents(events)].join('\n')
7
5
  }
8
6
 
@@ -79,7 +77,7 @@ const formatStyles = fp.pipe(
79
77
  style.encoding +
80
78
  '\n'
81
79
  )
82
- }, '')
80
+ }, ''),
83
81
  )
84
82
 
85
83
  function encASSStyles(styles) {
package/couch.js CHANGED
@@ -1,7 +1,10 @@
1
- const createError = require('http-errors')
2
- const makeWeak = require('./weakCache')
3
- const tp = require('timers/promises')
4
- const { delay } = require('./http')
1
+ import createError from 'http-errors'
2
+ import { makeWeakCache } from './weakCache.js'
3
+ import tp from 'timers/promises'
4
+ import { defaultDelay as delay } from './http.js'
5
+ import querystring from 'querystring'
6
+ import urljoin from 'url-join'
7
+ import undici from 'undici'
5
8
 
6
9
  // https://github.com/fastify/fastify/blob/main/lib/reqIdGenFactory.js
7
10
  // 2,147,483,647 (2^31 − 1) stands for max SMI value (an internal optimization of V8).
@@ -33,11 +36,7 @@ function parseHeaders(headers, obj = {}) {
33
36
  return obj
34
37
  }
35
38
 
36
- module.exports = function (opts) {
37
- const querystring = require('querystring')
38
- const urljoin = require('url-join')
39
- const undici = require('undici')
40
-
39
+ export function makeCouch(opts) {
41
40
  let config
42
41
  if (typeof opts === 'string') {
43
42
  config = opts
@@ -77,7 +76,7 @@ module.exports = function (opts) {
77
76
 
78
77
  const getClient =
79
78
  config.getClient ??
80
- makeWeak(
79
+ makeWeakCache(
81
80
  () =>
82
81
  new undici.Pool(dbOrigin, {
83
82
  ...defaultClientOpts,
package/deepstream.js CHANGED
@@ -1,9 +1,9 @@
1
- const qs = require('qs')
2
- const cached = require('./util/cached')
3
- const undici = require('undici')
4
- const stream = require('node:stream')
5
- const split2 = require('split2')
6
- const { delay } = require('./http')
1
+ import qs from 'qs'
2
+ import cached from './util/cached.js'
3
+ import undici from 'undici'
4
+ import stream from 'node:stream'
5
+ import split2 from 'split2'
6
+ import { defaultDelay as delay } from './http.js'
7
7
 
8
8
  function provide(ds, domain, callback, options) {
9
9
  if (domain instanceof RegExp) {
@@ -121,7 +121,7 @@ function get(ds, name, ...args) {
121
121
  )
122
122
  }
123
123
 
124
- function init(ds) {
124
+ export function makeDeepstream(ds) {
125
125
  const nxt = {
126
126
  ds,
127
127
  record: {
@@ -249,7 +249,7 @@ async function* changes(
249
249
  }
250
250
  }
251
251
 
252
- module.exports = Object.assign(init, {
252
+ Object.assign(makeDeepstream, {
253
253
  changes,
254
254
  provide,
255
255
  observe,
package/docker-secrets.js CHANGED
@@ -1,8 +1,8 @@
1
- const fs = require('fs')
2
- const fsp = require('fs/promises')
3
- const path = require('path')
1
+ import fs from 'fs'
2
+ import fsp from 'fs/promises'
3
+ import path from 'path'
4
4
 
5
- function getDockerSecretsSync({ dir = '/run/secrets' } = {}) {
5
+ export function getDockerSecretsSync({ dir = '/run/secrets' } = {}) {
6
6
  let files
7
7
  try {
8
8
  files = fs.readdirSync(dir)
@@ -22,7 +22,7 @@ function getDockerSecretsSync({ dir = '/run/secrets' } = {}) {
22
22
  return secrets
23
23
  }
24
24
 
25
- function getDockerSecretSync(file, { dir = '/run/secrets', signal } = {}) {
25
+ export function getDockerSecretSync(file, { dir = '/run/secrets', signal } = {}) {
26
26
  try {
27
27
  const [, ext] = file.split('.')
28
28
  const content = fs.readFileSync(path.join(dir, file), { encoding: 'utf8', signal })
@@ -35,7 +35,7 @@ function getDockerSecretSync(file, { dir = '/run/secrets', signal } = {}) {
35
35
  }
36
36
  }
37
37
 
38
- async function getDockerSecret(file, { dir = '/run/secrets', signal } = {}) {
38
+ export async function getDockerSecret(file, { dir = '/run/secrets', signal } = {}) {
39
39
  try {
40
40
  const [, ext] = file.split('.')
41
41
  const content = await fsp.readFile(path.join(dir, file), { encoding: 'utf8', signal })
@@ -47,9 +47,3 @@ async function getDockerSecret(file, { dir = '/run/secrets', signal } = {}) {
47
47
  throw err
48
48
  }
49
49
  }
50
-
51
- module.exports = {
52
- getDockerSecretsSync,
53
- getDockerSecretSync,
54
- getDockerSecret,
55
- }
package/elasticsearch.js CHANGED
@@ -1,5 +1,5 @@
1
- const Elasticsearch = require('@elastic/elasticsearch')
2
- const { UndiciConnection } = require('@elastic/transport')
1
+ import Elasticsearch from '@elastic/elasticsearch'
2
+ import { UndiciConnection } from '@elastic/transport'
3
3
 
4
4
  // https://github.com/elastic/elasticsearch-js/issues/1716#issuecomment-1167173492
5
5
  class Connection extends UndiciConnection {
@@ -19,7 +19,7 @@ class Connection extends UndiciConnection {
19
19
  // See, https://github.com/elastic/kibana/pull/134628
20
20
  const ConnectionPool = Elasticsearch.ClusterConnectionPool
21
21
 
22
- module.exports = function makeElasticsearchClient(config) {
22
+ export default function makeElasticsearchClient(config) {
23
23
  config = config?.elasticsearch ?? config
24
24
  if (typeof config === 'string') {
25
25
  config = { url: config }
package/errors.js CHANGED
@@ -1,9 +1,10 @@
1
- const objectHash = require('object-hash')
2
- const fp = require('lodash/fp.js')
1
+ import objectHash from 'object-hash'
2
+ import fp from 'lodash/fp.js'
3
+ import { SIGNALS } from './platform.js'
4
+
3
5
  const { toString } = Object.prototype
4
- const { SIGNALS } = require('./platform.js')
5
6
 
6
- module.exports.AbortError = class AbortError extends Error {
7
+ export class AbortError extends Error {
7
8
  constructor(message) {
8
9
  super(message ?? 'The operation was aborted')
9
10
  this.code = 'ABORT_ERR'
@@ -11,7 +12,7 @@ module.exports.AbortError = class AbortError extends Error {
11
12
  }
12
13
  }
13
14
 
14
- module.exports.parseError = function parseError(error) {
15
+ export function parseError(error) {
15
16
  if (!error) {
16
17
  return null
17
18
  }
@@ -41,7 +42,7 @@ module.exports.parseError = function parseError(error) {
41
42
 
42
43
  const kSeen = Symbol('kSeen')
43
44
 
44
- module.exports.serializeError = function serializeError(error) {
45
+ export function serializeError(error) {
45
46
  if (!error) {
46
47
  return null
47
48
  }
@@ -117,7 +118,7 @@ module.exports.serializeError = function serializeError(error) {
117
118
  }
118
119
 
119
120
  // TODO (fix): Recursion guard?
120
- module.exports.makeMessages = function makeMessages(error, options) {
121
+ export function makeMessages(error, options) {
121
122
  if (!error) {
122
123
  return []
123
124
  }
@@ -163,12 +164,12 @@ module.exports.makeMessages = function makeMessages(error, options) {
163
164
  error.index === null || error.index === false
164
165
  ? null
165
166
  : typeof error.index === 'object'
166
- ? error.index
167
- : error.index === undefined || error.index === true
168
- ? options?.index === true
169
- ? { message: msg }
170
- : null
171
- : null,
167
+ ? error.index
168
+ : error.index === undefined || error.index === true
169
+ ? options?.index === true
170
+ ? { message: msg }
171
+ : null
172
+ : null,
172
173
  }
173
174
  } else {
174
175
  err = {
@@ -196,7 +197,7 @@ module.exports.makeMessages = function makeMessages(error, options) {
196
197
  }
197
198
  }
198
199
 
199
- module.exports.makeErrorString = function makeErrorString(err) {
200
+ export function makeErrorString(err) {
200
201
  err = module.exports.parseError(err)
201
202
 
202
203
  let msg = err?.message || 'error'
package/hash.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
2
- module.exports = function hash(str, seed = 0) {
2
+ export default function hash(str, seed = 0) {
3
3
  if (typeof str !== 'string') {
4
4
  throw new Error(`invalid argument "str" (${str}). Expected string but received ${typeof str}`)
5
5
  }
package/http.js CHANGED
@@ -1,11 +1,11 @@
1
- const createError = require('http-errors')
2
- const { performance } = require('perf_hooks')
3
- const requestTarget = require('request-target')
4
- const querystring = require('fast-querystring')
5
- const compose = require('koa-compose')
6
- const http = require('http')
7
- const fp = require('lodash/fp')
8
- const tp = require('timers/promises')
1
+ import createError from 'http-errors'
2
+ import { performance } from 'perf_hooks'
3
+ import requestTarget from 'request-target'
4
+ import querystring from 'fast-querystring'
5
+ import compose from 'koa-compose'
6
+ import http from 'http'
7
+ import fp from 'lodash/fp.js'
8
+ import tp from 'timers/promises'
9
9
 
10
10
  const ERR_HEADER_EXPR =
11
11
  /^(content-length|content-type|te|host|upgrade|trailers|connection|keep-alive|http2-settings|transfer-encoding|proxy-connection|proxy-authenticate|proxy-authorization)$/i
@@ -23,7 +23,7 @@ function genReqId() {
23
23
  return `req-${nextReqId.toString(36)}`
24
24
  }
25
25
 
26
- module.exports.request = async function request(ctx, next) {
26
+ export async function request(ctx, next) {
27
27
  const { req, res, logger } = ctx
28
28
  const startTime = performance.now()
29
29
 
@@ -36,7 +36,7 @@ module.exports.request = async function request(ctx, next) {
36
36
  throw new createError.BadRequest('invalid url')
37
37
  }
38
38
 
39
- ctx.id = req.id = req.headers['request-id'] || genReqId()
39
+ ctx.id = req.id = res.id = req.headers['request-id'] || genReqId()
40
40
  ctx.logger = req.log = res.log = logger.child({ req: { id: req.id, url: req.url } })
41
41
  ctx.signal = ac.signal
42
42
  ctx.method = req.method
@@ -172,7 +172,7 @@ module.exports.request = async function request(ctx, next) {
172
172
  }
173
173
  }
174
174
 
175
- class ServerResponse extends http.ServerResponse {
175
+ export class ServerResponse extends http.ServerResponse {
176
176
  constructor(req) {
177
177
  super(req)
178
178
  this.startTime = performance.now()
@@ -210,9 +210,7 @@ class ServerResponse extends http.ServerResponse {
210
210
  }
211
211
  }
212
212
 
213
- module.exports.ServerResponse = ServerResponse
214
-
215
- module.exports.createServer = function (options, ctx, middleware) {
213
+ export function createServer(options, ctx, middleware) {
216
214
  middleware = Array.isArray(middleware) ? middleware : [middleware]
217
215
  middleware = fp.values(middleware)
218
216
  middleware = middleware.flat().filter(Boolean)
@@ -242,7 +240,7 @@ module.exports.createServer = function (options, ctx, middleware) {
242
240
  return server
243
241
  }
244
242
 
245
- module.exports.upgrade = async function upgrade(ctx, next) {
243
+ export async function upgrade(ctx, next) {
246
244
  const { req, res, socket = res, logger } = ctx
247
245
 
248
246
  const ac = new AbortController()
@@ -316,7 +314,7 @@ module.exports.upgrade = async function upgrade(ctx, next) {
316
314
  }
317
315
  }
318
316
 
319
- function isConnectionError(err) {
317
+ export function isConnectionError(err) {
320
318
  // AWS compat.
321
319
  const statusCode = err?.statusCode ?? err?.$metadata?.httpStatusCode
322
320
  return err
@@ -337,7 +335,7 @@ function isConnectionError(err) {
337
335
  : false
338
336
  }
339
337
 
340
- function defaultDelay(err, retryCount, options) {
338
+ export function defaultDelay(err, retryCount, options) {
341
339
  const { signal, logger = null } = options ?? {}
342
340
  if (isConnectionError(err)) {
343
341
  const delay =
@@ -349,10 +347,7 @@ function defaultDelay(err, retryCount, options) {
349
347
  }
350
348
  }
351
349
 
352
- module.exports.delay = defaultDelay
353
- module.exports.isConnectionError = isConnectionError
354
-
355
- module.exports.retry = async function _retry(fn, options) {
350
+ export async function retry(fn, options) {
356
351
  const { maxRetries = 8, count = maxRetries, delay = defaultDelay, signal } = options ?? {}
357
352
 
358
353
  for (let retryCount = 0; true; ++retryCount) {
@@ -372,7 +367,7 @@ module.exports.retry = async function _retry(fn, options) {
372
367
  }
373
368
  }
374
369
 
375
- module.exports.parseHeaders = function parseHeaders(rawHeaders, obj = {}) {
370
+ export function parseHeaders(rawHeaders, obj = {}) {
376
371
  for (let i = 0; i < rawHeaders.length; i += 2) {
377
372
  const key = rawHeaders[i].toString().toLowerCase()
378
373
  let val = obj[key]
package/logger.js CHANGED
@@ -1,10 +1,10 @@
1
- const { isMainThread } = require('node:worker_threads')
2
- const serializers = require('./serializers')
3
- const pino = require('pino')
1
+ import { isMainThread } from 'node:worker_threads'
2
+ import serializers from './serializers.js'
3
+ import pino from 'pino'
4
4
 
5
5
  const isProduction = process.env.NODE_ENV === 'production'
6
6
 
7
- module.exports.createLogger = function (
7
+ export function createLogger(
8
8
  { level = isProduction ? 'debug' : 'trace', flushInterval = 1e3, stream = null, ...options } = {},
9
9
  onTerminate,
10
10
  ) {
package/merge-ranges.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const EMPTY_ARR = Object.freeze([])
2
2
 
3
- module.exports = function mergeRanges(ranges) {
3
+ export function mergeRanges(ranges) {
4
4
  if (!Array.isArray(ranges) || ranges.length === 0) {
5
5
  return EMPTY_ARR
6
6
  }
package/mime.js CHANGED
@@ -1,6 +1,6 @@
1
- const mime = require('mime')
1
+ import mime from 'mime'
2
2
 
3
- function lookup(name) {
3
+ export function lookup(name) {
4
4
  if (typeof name !== 'string' || name.length === 0) {
5
5
  return null
6
6
  }
@@ -29,7 +29,7 @@ function lookup(name) {
29
29
  return mime.getType(name)
30
30
  }
31
31
 
32
- function extension(type, name) {
32
+ export function extension(type, name) {
33
33
  if (typeof type !== 'string' || type.length === 0) {
34
34
  return null
35
35
  }
@@ -57,10 +57,3 @@ function extension(type, name) {
57
57
 
58
58
  return extension
59
59
  }
60
-
61
- module.exports = {
62
- extension,
63
- getExtension: extension,
64
- lookup,
65
- getType: lookup,
66
- }