@nxtedition/lib 26.8.2 → 26.8.4

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
@@ -1,4 +1,4 @@
1
- import type { DeepstreamClient } from '@nxtedition/deepstream.io-client-js'
1
+ import type { DeepstreamClient, RpcMethodDef } from '@nxtedition/deepstream.io-client-js'
2
2
  import type { NxtDeepstreamClient } from './deepstream.js'
3
3
  import type { Logger } from './logger.js'
4
4
  import type { CouchClient } from './couch.js'
@@ -6,7 +6,11 @@ import type { Server } from 'http'
6
6
  import type { BehaviorSubject } from 'rxjs'
7
7
  import type { Subscription } from 'rxjs'
8
8
 
9
- export function makeApp<Records, RpcMethods, Config = Record<string, unknown>>(
9
+ export function makeApp<
10
+ Records,
11
+ RpcMethods extends Record<string, RpcMethodDef> = Record<string, RpcMethodDef>,
12
+ Config = Record<string, unknown>,
13
+ >(
10
14
  appConfig: AppConfig<Config>,
11
15
  onTerminate?: (logger: Logger) => Promise<void>,
12
16
  ): App<Records, RpcMethods, Config>
@@ -26,7 +30,11 @@ export interface AppConfig<Config = Record<string, unknown>> {
26
30
  [key: string]: unknown
27
31
  }
28
32
 
29
- export interface App<Records, RpcMethods, Config = Record<string, unknown>> {
33
+ export interface App<
34
+ Records,
35
+ RpcMethods extends Record<string, RpcMethodDef>,
36
+ Config = Record<string, unknown>,
37
+ > {
30
38
  ds: DeepstreamClientWithNxt<Records, RpcMethods>
31
39
  nxt: NxtDeepstreamClient<Records, RpcMethods>
32
40
  couch: CouchClient
@@ -53,7 +61,7 @@ export interface App<Records, RpcMethods, Config = Record<string, unknown>> {
53
61
  signal: AbortSignal
54
62
  }
55
63
 
56
- export interface DeepstreamClientWithNxt<Records, RpcMethods>
64
+ export interface DeepstreamClientWithNxt<Records, RpcMethods extends Record<string, RpcMethodDef>>
57
65
  extends DeepstreamClient<Records, RpcMethods> {
58
66
  nxt: NxtDeepstreamClient<Records, RpcMethods>
59
67
  }
package/app.js CHANGED
@@ -35,7 +35,6 @@ import { monitorEventLoopDelay } from 'node:perf_hooks'
35
35
  import xuid from 'xuid'
36
36
  import { isTimeBetween } from './time.js'
37
37
  import makeUnderPressure from './under-pressure.js'
38
- import undici from '@nxtedition/undici'
39
38
  import { isPrimary } from 'node:cluster'
40
39
  import { nice } from '@nxtedition/sched'
41
40
  import { setAffinity } from './numa.js'
@@ -550,65 +549,6 @@ export function makeApp(appConfig, onTerminate) {
550
549
  compiler = makeTemplateCompiler({ ds, logger, ...appConfig.compiler })
551
550
  }
552
551
 
553
- const undiciDefaults = Object.freeze({
554
- connected: 0,
555
- disconnected: 0,
556
- connections: 0,
557
- })
558
-
559
- const undici$ = new rxjs.BehaviorSubject({ ...undiciDefaults })
560
- {
561
- function onConnect(origin, targets) {
562
- const stats = { ...undici$.value }
563
- stats.connected++
564
- stats.connections = stats.connected - stats.disconnected
565
- undici$.next(stats)
566
- logger.debug({ url: origin, count: stats.connected }, 'upstream connect')
567
- }
568
-
569
- function onDisconnect(origin, targets, err) {
570
- const stats = { ...undici$.value }
571
- stats.connected--
572
- stats.connections = stats.connected - stats.disconnected
573
- undici$.next(stats)
574
- logger.debug({ url: origin, count: stats.connected }, 'upstream disconnect')
575
- }
576
-
577
- let currentDispatcher
578
- function maybeRegisterUndiciStats() {
579
- const nextDispatcher = undici.getGlobalDispatcher()
580
-
581
- if (nextDispatcher === currentDispatcher) {
582
- return
583
- }
584
-
585
- if (currentDispatcher) {
586
- currentDispatcher.off('connect', onConnect).off('disconnect', onDisconnect)
587
- currentDispatcher = null
588
- }
589
-
590
- undici$.next({ ...undiciDefaults })
591
-
592
- nextDispatcher.on('connect', onConnect).on('disconnect', onDisconnect)
593
-
594
- currentDispatcher = nextDispatcher
595
- }
596
-
597
- let undiciInterval = setInterval(() => maybeRegisterUndiciStats(), 10e3).unref()
598
-
599
- destroyers.push(() => {
600
- if (undiciInterval) {
601
- clearInterval(undiciInterval)
602
- undiciInterval = null
603
- }
604
-
605
- if (currentDispatcher) {
606
- currentDispatcher.off('connect', onConnect).off('disconnect', onDisconnect)
607
- currentDispatcher = null
608
- }
609
- })
610
- }
611
-
612
552
  const monitorProviders = {}
613
553
 
614
554
  let stats$
@@ -695,17 +635,15 @@ export function makeApp(appConfig, onTerminate) {
695
635
  userAgent,
696
636
  pending: globalThis._nxt_lib_http_pending?.size,
697
637
  },
638
+ undici: {
639
+ sockets: globalThis.__undici_sockets?.size ?? 0,
640
+ },
698
641
  }
699
642
  }),
700
643
  ),
701
- undici$,
702
644
  ),
703
- rx.map(([serviceStats, appStats, undiciStats]) => ({
645
+ rx.map(([serviceStats, appStats]) => ({
704
646
  ...appStats,
705
- undici: {
706
- sockets: globalThis.__undici_sockets?.size,
707
- ...undiciStats,
708
- },
709
647
  [serviceName]: serviceStats,
710
648
  })),
711
649
  rx.retryWhen((err$) =>
@@ -771,20 +709,17 @@ export function makeApp(appConfig, onTerminate) {
771
709
  rx.distinctUntilChanged(fp.isEqual),
772
710
  rx.repeatWhen((complete$) => complete$.pipe(rx.delay(10e3))),
773
711
  ),
774
- undici$.pipe(
775
- rx.map((stats) => {
776
- return [
777
- {
778
- id: 'app:undici_upstream_sockets',
779
- level: stats.sockets > 8192 ? 50 : stats.sockets > 4096 ? 40 : 30,
780
- msg: `Undici: ${stats.sockets} upstream connected`,
781
- },
782
- {
783
- id: 'app:undici_upstream_connections',
784
- level: stats.connections > 8192 ? 50 : stats.connections > 4096 ? 40 : 30,
785
- msg: `Undici: ${stats.connections} upstream connected`,
786
- },
787
- ]
712
+ stats$.pipe(
713
+ rx.map(({ undici: stats }) => {
714
+ return stats
715
+ ? [
716
+ {
717
+ id: 'app:undici_upstream_sockets',
718
+ level: stats.sockets > 8192 ? 50 : stats.sockets > 4096 ? 40 : 30,
719
+ msg: `Undici: ${stats.sockets} upstream connected`,
720
+ },
721
+ ]
722
+ : []
788
723
  }),
789
724
  ),
790
725
  toobusy?.appLag$.pipe(
package/couch.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Logger } from './logger.js'
2
- import { HttpError } from 'http-errors'
2
+ import type { HttpError } from 'http-errors'
3
3
  import type { Readable } from 'node:stream'
4
+ import type { Dispatcher } from 'undici'
4
5
 
5
6
  export interface CouchOptions {
6
7
  url?: string
@@ -18,7 +19,7 @@ export interface CouchRequestOptions<Stream extends boolean = false> {
18
19
  body?: unknown
19
20
  headersTimeout?: number
20
21
  bodyTimeout?: number
21
- dispatcher?: undici.Dispatcher
22
+ dispatcher?: Dispatcher
22
23
  query?: {
23
24
  startkey?: string
24
25
  endkey?: string
@@ -39,7 +40,7 @@ export interface CouchResponse<T> {
39
40
 
40
41
  export function request<T, Stream extends boolean = false>(
41
42
  url: string | URL | { origin: string; path?: string; pathname?: string },
42
- opts?: CouchRequestOptione<Stream> | null,
43
+ opts?: CouchRequestOptions<Stream> | null,
43
44
  ): Stream extends true ? Readable : Promise<CouchResponse<T>>
44
45
 
45
46
  interface ChangesOptions {
package/deepstream.d.ts CHANGED
@@ -1,19 +1,27 @@
1
- import { DeepstreamClient, RecordHandler } from '@nxtedition/deepstream.io-client-js'
1
+ import type {
2
+ DeepstreamClient,
3
+ RecordHandler,
4
+ RpcMethodDef,
5
+ } from '@nxtedition/deepstream.io-client-js'
2
6
 
3
7
  type Paths<T> = keyof T & string
4
8
  type Get<Data, Path extends string> = Path extends keyof Data ? Data[Path] : unknown
5
9
 
6
- export function makeDeepstream<Records, RpcMethods>(
7
- client: DeepstreamClient<Records, RpcMethods>,
8
- ): NxtDeepstreamClient<Records, RpcMethods>
10
+ export function makeDeepstream<
11
+ Records,
12
+ RpcMethods extends Record<string, RpcMethodDef> = Record<string, RpcMethodDef>,
13
+ >(client: DeepstreamClient<Records, RpcMethods>): NxtDeepstreamClient<Records, RpcMethods>
9
14
 
10
- export interface NxtDeepstreamClient<Records, RpcMethods> {
15
+ export interface NxtDeepstreamClient<
16
+ Records,
17
+ RpcMethods extends Record<string, RpcMethodDef> = Record<string, RpcMethodDef>,
18
+ > {
11
19
  ds: DeepstreamClient<Records, RpcMethods> & { nxt: NxtDeepstreamClient<Records, RpcMethods> }
12
20
  record: {
13
21
  provide: RecordHandler<Records>['provide']
14
22
  observe: RecordHandler<Records>['observe'] // TODO type with query
15
23
  observe2: RecordHandler<Records>['observe2'] // TODO type with query
16
- query: RecordHandler<Records>['query']
24
+ query: (designId: string, params?: Query, state?: number) => Promise<string[]>
17
25
  set: RecordHandler<Records>['set']
18
26
  get: {
19
27
  // without query and path:
package/errors.d.ts CHANGED
@@ -22,7 +22,7 @@ type SerializableError = null | undefined | Error | string | NxtError | Serializ
22
22
 
23
23
  export function serializeError(err: SerializableError): NxtError[] | null
24
24
 
25
- export type Message = {
25
+ export interface Message {
26
26
  msg: string
27
27
  title?: string
28
28
  id: string
@@ -33,7 +33,7 @@ export type Message = {
33
33
  index?: object | null
34
34
  }
35
35
 
36
- export type MessageOptions = {
36
+ export interface MessageOptions {
37
37
  id?: string
38
38
  level?: number
39
39
  code?: string
@@ -46,4 +46,6 @@ export function makeMessages(
46
46
  options?: MessageOptions,
47
47
  ): Message[]
48
48
 
49
+ export type MessageError = unknown
50
+
49
51
  export function makeErrorString(err: unknown): string
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ // dummy file required for tsd to work
package/logger.d.ts CHANGED
@@ -1,18 +1,10 @@
1
- import { pino } from 'pino'
1
+ import type { Logger as PinoLogger, LoggerOptions as PinoLoggerOptions } from 'pino'
2
2
 
3
- export type Logger = pino.Logger
3
+ export type Logger = PinoLogger
4
4
 
5
- interface LoggerOptions extends pino.LoggerOptions {
5
+ interface LoggerOptions extends PinoLoggerOptions {
6
6
  flushInterval?: number
7
- stream?: ReturnType<(typeof pino)['destination']> | (typeof process)['stdout'] | null
7
+ stream?: NodeJS.WriteStream | null
8
8
  }
9
9
 
10
- export function createLogger(
11
- {
12
- level = isProduction ? 'debug' : 'trace',
13
- flushInterval = 1e3,
14
- stream = null,
15
- ...options
16
- }?: LoggerOptions,
17
- onTerminate?: unknown,
18
- ): Logger
10
+ export function createLogger(options?: LoggerOptions, onTerminate?: unknown): Logger
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "26.8.2",
3
+ "version": "26.8.4",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
7
7
  "files": [
8
+ "index.d.ts",
8
9
  "hash.js",
9
10
  "ass.js",
10
11
  "rxjs/*",
@@ -51,6 +52,7 @@
51
52
  ],
52
53
  "scripts": {
53
54
  "test": "node --test-timeout 60000 --test",
55
+ "test:types": "tsd",
54
56
  "prepare": "husky"
55
57
  },
56
58
  "lint-staged": {
@@ -65,12 +67,12 @@
65
67
  "singleQuote": true
66
68
  },
67
69
  "dependencies": {
68
- "@aws-sdk/client-s3": "3.901.0",
70
+ "@aws-sdk/client-s3": "3.918.0",
69
71
  "@elastic/elasticsearch": "^8.17.1",
70
72
  "@elastic/transport": "^8.9.3",
71
- "@nxtedition/nxt-undici": "^6.4.0",
73
+ "@nxtedition/nxt-undici": "^6.4.17",
72
74
  "@nxtedition/sched": "^1.0.2",
73
- "@smithy/node-http-handler": "^4.3.0",
75
+ "@smithy/node-http-handler": "^4.4.3",
74
76
  "acorn": "^8.15.0",
75
77
  "astring": "^1.9.0",
76
78
  "date-fns": "^4.1.0",
@@ -87,7 +89,7 @@
87
89
  "nconf": "^0.13.0",
88
90
  "object-hash": "^3.0.0",
89
91
  "p-queue": "^9.0.0",
90
- "pino": "^10.0.0",
92
+ "pino": "^10.1.0",
91
93
  "qs": "^6.14.0",
92
94
  "request-target": "^1.0.2",
93
95
  "smpte-timecode": "^1.3.6",
@@ -97,11 +99,11 @@
97
99
  "yocto-queue": "^1.2.1"
98
100
  },
99
101
  "devDependencies": {
100
- "@nxtedition/deepstream.io-client-js": ">=31.0.18",
102
+ "@nxtedition/deepstream.io-client-js": ">=31.2.1",
101
103
  "@types/lodash": "^4.17.20",
102
- "@types/node": "^24.7.0",
104
+ "@types/node": "^24.9.1",
103
105
  "canvas": "^3.1.0",
104
- "eslint": "^9.37.0",
106
+ "eslint": "^9.38.0",
105
107
  "eslint-config-prettier": "^10.1.8",
106
108
  "eslint-config-standard": "^17.0.0",
107
109
  "eslint-plugin-import": "^2.32.0",
@@ -109,11 +111,12 @@
109
111
  "eslint-plugin-node": "^11.1.0",
110
112
  "eslint-plugin-promise": "^7.2.1",
111
113
  "husky": "^9.1.7",
112
- "lint-staged": "^16.2.3",
114
+ "lint-staged": "^16.2.6",
113
115
  "prettier": "^3.6.2",
114
116
  "rxjs": "^7.8.2",
117
+ "tsd": "^0.33.0",
115
118
  "typescript": "^5.9.3",
116
- "typescript-eslint": "^8.46.0"
119
+ "typescript-eslint": "^8.46.2"
117
120
  },
118
121
  "peerDependencies": {
119
122
  "@elastic/elasticsearch": "^8.6.0",
@@ -1,31 +1,32 @@
1
1
  import type { FirstValueFromConfig } from 'rxjs/internal/firstValueFrom'
2
2
  import type * as rx from 'rxjs'
3
- import { DeepstreamClient } from '@nxtedition/deepstream.io-client-js'
3
+ import type { DeepstreamClient } from '@nxtedition/deepstream.io-client-js'
4
+ import type { Logger } from '../../logger.js'
4
5
 
5
6
  export interface MakeTemplateCompilerParams {
6
- ds?: DeepstreamClient
7
+ ds?: DeepstreamClient<unknown>
7
8
  proxify?: unknown
8
- logger?: unknown
9
+ logger?: Logger
9
10
  platform?: unknown
10
11
  }
11
12
 
12
- export function makeTemplateCompiler(params: MakeTemplateCompilerParams): TemplateCompiler
13
+ export declare function makeTemplateCompiler(params: MakeTemplateCompilerParams): TemplateCompiler
13
14
 
14
15
  export interface TemplateCompiler {
15
16
  current: null
16
17
 
17
- resolveTemplate: <ReturnValue, Context>(
18
+ resolveTemplate: <ReturnValue, Context extends Record<string, unknown>>(
18
19
  template: Nxtpression<ReturnValue, Context> | string,
19
20
  args$?: Context | rx.Observable<Context>,
20
- options?: FirstValueFromConfig,
21
+ options?: FirstValueFromConfig<ReturnValue>,
21
22
  ) => Promise<unknown>
22
23
 
23
- onResolveTemplate: <ReturnValue, Context>(
24
+ onResolveTemplate: <ReturnValue, Context extends Record<string, unknown>>(
24
25
  template: Nxtpression<ReturnValue, Context> | string,
25
26
  args$?: Context | rx.Observable<Context>,
26
27
  ) => rx.Observable<unknown>
27
28
 
28
- compileTemplate: <ReturnValue, Context>(
29
+ compileTemplate: <ReturnValue, Context extends Record<string, unknown>>(
29
30
  template: Nxtpression<ReturnValue, Context> | string,
30
31
  ) => null | ((args$?: Context | rx.Observable<Context>) => rx.Observable<unknown>)
31
32
 
@@ -1 +1 @@
1
- export * from './index-common.d.ts'
1
+ export * from './index-common.js'
@@ -1 +1 @@
1
- export * from './index-common.d.ts'
1
+ export * from './index-common.js'