@nxtedition/lib 23.0.4 → 23.0.6

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.d.ts CHANGED
@@ -3,34 +3,58 @@ import type { NxtDeepstreamClient } from './deepstream.js'
3
3
  import type { Logger } from './logger.js'
4
4
  import type { CouchClient } from './couch.js'
5
5
  import type { Server } from 'http'
6
+ import type { BehaviorSubject } from 'rxjs'
6
7
 
7
- export function makeApp<AC extends AppConfig, Records, RpcMethods>(
8
- appConfig: AC,
8
+ export function makeApp<Records, RpcMethods, Config = Record<string, unknown>>(
9
+ appConfig: AppConfig<Config>,
9
10
  onTerminate?: (logger: Logger) => Promise<void>,
10
11
  ): App<AC, Records, RpcMethods>
11
12
 
12
- export interface AppConfig {
13
+ export interface AppConfig<Config = Record<string, unknown>> {
13
14
  name: string
14
15
  module?: string
15
16
  version?: string
16
- config: {
17
- [key: string]: unknown
18
- }
17
+ config: Config
19
18
  [key: string]: unknown
20
19
  }
21
20
 
22
- export interface App<AC extends AppConfig, Records, RpcMethods> {
21
+ export interface App<Records, RpcMethods, Config = Record<string, unknown>> {
23
22
  ds: DeepstreamClientWithNxt<Records, RpcMethods>
24
23
  nxt: NxtDeepstreamClient<Records, RpcMethods>
25
24
  couch: CouchClient
26
25
  server: Server
27
26
  compiler: unkonwn
28
- config: AC
27
+ config: Config
29
28
  logger: Logger
30
29
  trace: unknown
30
+ trace: unknown
31
+ toobusy: TooBusy
32
+ destroyers: Array<
33
+ | rxjs.Subscription
34
+ | ((logger: Logger) => void)
35
+ | ((logger: Logger) => Promise<void>)
36
+ | Disposable
37
+ | AsyncDisposable
38
+ >
39
+ userAgent: string | null
40
+ serviceName: string
41
+ serviceModule: string
42
+ serviceVersion?: string
43
+ serviceInstanceId: string
44
+ serviceWorkerId: number
45
+ signal: AbortSignal
31
46
  }
32
47
 
33
48
  export interface DeepstreamClientWithNxt<Records, RpcMethods>
34
49
  extends DeepstreamClient<Records, RpcMethods> {
35
50
  nxt: NxtDeepstreamClient<Records, RpcMethods>
36
51
  }
52
+
53
+ export interface TooBusy {
54
+ (): boolean
55
+ lag: () => number
56
+ lag$: BehaviorSubject<number>
57
+ appLag: () => number
58
+ appLag$: BehaviorSubject<number>
59
+ maxLag: number
60
+ }
package/app.js CHANGED
@@ -33,7 +33,6 @@ import { json } from 'node:stream/consumers'
33
33
  import { monitorEventLoopDelay } from 'node:perf_hooks'
34
34
  import { LRUCache } from 'lru-cache'
35
35
  import xuid from 'xuid'
36
- import undici from 'undici'
37
36
  import { isTimeBetween } from './time.js'
38
37
 
39
38
  export function makeApp(appConfig, onTerminate) {
@@ -53,10 +52,6 @@ export function makeApp(appConfig, onTerminate) {
53
52
  net.setDefaultAutoSelectFamily(false)
54
53
  }
55
54
 
56
- if (undici.setGlobalDispatcher) {
57
- undici.setGlobalDispatcher(new undici.Agent({ connectTimeout: 2e3 }))
58
- }
59
-
60
55
  // Optimize some Node global defaults.
61
56
 
62
57
  Buffer.poolSize = 128 * 1024
package/couch.js CHANGED
@@ -6,13 +6,7 @@ import { makeWeakCache } from './weakCache.js'
6
6
  import { defaultDelay as delay } from './http.js'
7
7
  import urljoin from 'url-join'
8
8
  import { AbortError } from './errors.js'
9
- import {
10
- dispatch,
11
- Agent,
12
- Pool,
13
- parseHeaders,
14
- request as undiciRequest,
15
- } from '@nxtedition/nxt-undici'
9
+ import { dispatch, Agent, Pool, request as undiciRequest } from '@nxtedition/nxt-undici'
16
10
 
17
11
  export function makeCouch(opts) {
18
12
  let config
@@ -484,7 +478,7 @@ export function makeCouch(opts) {
484
478
  },
485
479
  onHeaders(statusCode, headers) {
486
480
  this.status = statusCode
487
- this.headers = parseHeaders(headers)
481
+ this.headers = headers
488
482
  },
489
483
  onData(chunk) {
490
484
  this.data += chunk
@@ -934,7 +928,7 @@ class StreamOutput extends stream.Readable {
934
928
  }
935
929
  }
936
930
 
937
- onHeaders(statusCode, rawHeaders, resume, statusText, headers = parseHeaders(rawHeaders)) {
931
+ onHeaders(statusCode, headers, resume) {
938
932
  if (statusCode >= 300 || statusCode < 200) {
939
933
  throw new Error('invalid status code: ' + statusCode)
940
934
  }
@@ -1069,11 +1063,26 @@ export function request(url, opts) {
1069
1063
 
1070
1064
  if (opts == null && typeof url === 'object' && url != null) {
1071
1065
  opts = url
1072
- url = null
1066
+ }
1067
+
1068
+ url = opts.url
1069
+
1070
+ let origin = url.origin
1071
+ if (!origin) {
1072
+ const protocol = url.protocol ?? 'http:'
1073
+ const host = url.host ?? `${url.hostname}:${url.port ?? (protocol === 'https:' ? 443 : 80)}`
1074
+ origin = `${protocol}//${host}`
1075
+ }
1076
+
1077
+ let path = url.path
1078
+ if (!path) {
1079
+ path = url.search ? `${url.pathname}${url.search}` : url.pathname
1073
1080
  }
1074
1081
 
1075
1082
  const ureq = {
1076
1083
  ...opts,
1084
+ origin,
1085
+ path,
1077
1086
  method: opts.method ?? (opts.body ? 'POST' : 'GET'),
1078
1087
  blocking: opts.blocking ?? Boolean(opts.stream),
1079
1088
  headers: {
package/deepstream.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { DeepstreamClient, RecordHandler } from '@nxtedition/deepstream.io-client-js'
2
2
 
3
+ type Paths<T> = keyof T & string
4
+ type Get<Data, Path extends string> = Path extends keyof Data ? Data[Path] : unknown
5
+
3
6
  export function makeDeepstream<Records, RpcMethods>(
4
7
  client: DeepstreamClient<Records, RpcMethods>,
5
8
  ): NxtDeepstreamClient<Records, RpcMethods>
@@ -8,12 +11,42 @@ export interface NxtDeepstreamClient<Records, RpcMethods> {
8
11
  ds: DeepstreamClient<Records, RpcMethods> & { nxt: NxtDeepstreamClient<Records, RpcMethods> }
9
12
  record: {
10
13
  provide: RecordHandler<Records>['provide']
11
- observe: RecordHandler<Records>['observe']
12
- observe2: RecordHandler<Records>['observe2']
14
+ observe: RecordHandler<Records>['observe'] // TODO type with query
15
+ observe2: RecordHandler<Records>['observe2'] // TODO type with query
13
16
  query: RecordHandler<Records>['query']
14
17
  set: RecordHandler<Records>['set']
15
- get: RecordHandler<Records>['get']
16
- getRecord: RecordHandler<Records>['getRecord']
18
+ get: {
19
+ // without query and path:
20
+ <Name extends keyof Records, Data extends Records[Name]>(
21
+ name: Name,
22
+ state?: number,
23
+ ): Promise<Data>
24
+
25
+ // with path:
26
+ <Name extends keyof Records, Data extends Records[Name], Path extends Paths<Data> & string>(
27
+ name: Name,
28
+ path?: Path,
29
+ state?: number,
30
+ ): Promise<Get<Data, Path>>
31
+
32
+ // with query:
33
+ <Name extends keyof Records, Data extends Records[Name]>(
34
+ name: Name,
35
+ query: Query,
36
+ state?: number,
37
+ ): Promise<Data>
38
+
39
+ // with query and path:
40
+ <Name extends keyof Records, Data extends Records[Name], Path extends Paths<Data> & string>(
41
+ name: Name,
42
+ query: Query,
43
+ path?: Path,
44
+ state?: number,
45
+ ): Promise<Get<Data, Path>>
46
+ }
47
+ getRecord: RecordHandler<Records>['getRecord'] // TODO type with query
17
48
  update: RecordHandler<Records>['update']
18
49
  }
19
50
  }
51
+
52
+ type Query = Record<string, unknown>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "23.0.4",
3
+ "version": "23.0.6",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -60,10 +60,10 @@
60
60
  "singleQuote": true
61
61
  },
62
62
  "dependencies": {
63
- "@aws-sdk/client-s3": "^3.723.0",
63
+ "@aws-sdk/client-s3": "^3.731.1",
64
64
  "@elastic/elasticsearch": "^8.16.1",
65
- "@elastic/transport": "^8.9.1",
66
- "@nxtedition/nxt-undici": "^5.1.8",
65
+ "@elastic/transport": "^8.9.3",
66
+ "@nxtedition/nxt-undici": "^6.0.0",
67
67
  "@swc/wasm-web": "^1.10.1",
68
68
  "content-type": "^1.0.5",
69
69
  "date-fns": "^3.6.0",
@@ -75,28 +75,28 @@
75
75
  "lodash": "^4.17.21",
76
76
  "lru-cache": "^11.0.2",
77
77
  "mime": "^4.0.6",
78
- "mitata": "^1.0.26",
78
+ "mitata": "^1.0.31",
79
79
  "moment-timezone": "^0.5.46",
80
80
  "nconf": "^0.12.1",
81
81
  "nested-error-stacks": "^2.1.1",
82
82
  "object-hash": "^3.0.0",
83
83
  "p-queue": "^8.0.1",
84
84
  "pino": "^9.6.0",
85
- "qs": "^6.13.1",
85
+ "qs": "^6.14.0",
86
86
  "request-target": "^1.0.2",
87
87
  "smpte-timecode": "^1.3.6",
88
88
  "split-string": "^6.0.0",
89
- "undici": "^7.2.0",
89
+ "undici": "^7.2.3",
90
90
  "url-join": "^5.0.0",
91
- "xuid": "^4.1.3",
91
+ "xuid": "^4.1.5",
92
92
  "yocto-queue": "^1.1.1"
93
93
  },
94
94
  "devDependencies": {
95
- "@nxtedition/deepstream.io-client-js": ">=25.6.3",
95
+ "@nxtedition/deepstream.io-client-js": ">=28.1.5",
96
96
  "@types/lodash": "^4.17.14",
97
- "@types/node": "^22.10.5",
97
+ "@types/node": "^22.10.7",
98
98
  "eslint": "^9.15.0",
99
- "eslint-config-prettier": "^9.1.0",
99
+ "eslint-config-prettier": "^10.0.1",
100
100
  "eslint-config-standard": "^17.0.0",
101
101
  "eslint-plugin-import": "^2.31.0",
102
102
  "eslint-plugin-n": "^17.15.1",
@@ -107,9 +107,9 @@
107
107
  "pinst": "^3.0.0",
108
108
  "prettier": "^3.4.2",
109
109
  "rxjs": "^7.5.6",
110
- "send": "^0.18.0",
110
+ "send": "^1.1.0",
111
111
  "tap": "^21.0.1",
112
- "typescript-eslint": "^8.19.1"
112
+ "typescript-eslint": "^8.20.0"
113
113
  },
114
114
  "peerDependencies": {
115
115
  "@elastic/elasticsearch": "^8.6.0",
@@ -4,8 +4,7 @@ import * as rxjs from 'rxjs'
4
4
  import objectHash from 'object-hash'
5
5
  import * as datefns from 'date-fns'
6
6
  import JSON5 from 'json5'
7
- import { request } from '@nxtedition/nxt-undici'
8
- import undici from 'undici'
7
+ import { request, Agent } from '@nxtedition/nxt-undici'
9
8
  import fp from 'lodash/fp.js'
10
9
  import moment from 'moment-timezone'
11
10
  import Timecode from 'smpte-timecode'
@@ -31,7 +30,7 @@ class TimerEntry {
31
30
  }
32
31
  }
33
32
 
34
- const fetchClient = new undici.Agent({
33
+ const fetchClient = new Agent({
35
34
  connections: 128,
36
35
  })
37
36