@nxtedition/lib 27.0.8 → 27.0.10

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
@@ -7,7 +7,7 @@ import type { BehaviorSubject } from 'rxjs'
7
7
  import type { Subscription } from 'rxjs'
8
8
 
9
9
  export function makeApp<
10
- Records,
10
+ Records extends Record<string, unknown> = Record<string, unknown>,
11
11
  RpcMethods extends Record<string, RpcMethodDef> = Record<string, RpcMethodDef>,
12
12
  Config = Record<string, unknown>,
13
13
  >(
@@ -31,8 +31,8 @@ export interface AppConfig<Config = Record<string, unknown>> {
31
31
  }
32
32
 
33
33
  export interface App<
34
- Records,
35
- RpcMethods extends Record<string, RpcMethodDef>,
34
+ Records extends Record<string, unknown> = Record<string, unknown>,
35
+ RpcMethods extends Record<string, RpcMethodDef> = Record<string, RpcMethodDef>,
36
36
  Config = Record<string, unknown>,
37
37
  > {
38
38
  ds: DeepstreamClientWithNxt<Records, RpcMethods>
@@ -61,8 +61,10 @@ export interface App<
61
61
  signal: AbortSignal
62
62
  }
63
63
 
64
- export interface DeepstreamClientWithNxt<Records, RpcMethods extends Record<string, RpcMethodDef>>
65
- extends DeepstreamClient<Records, RpcMethods> {
64
+ export interface DeepstreamClientWithNxt<
65
+ Records extends Record<string, unknown> = Record<string, unknown>,
66
+ RpcMethods extends Record<string, RpcMethodDef> = Record<string, RpcMethodDef>,
67
+ > extends DeepstreamClient<Records, RpcMethods> {
66
68
  nxt: NxtDeepstreamClient<Records, RpcMethods>
67
69
  }
68
70
 
package/couch.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { Logger } from './logger.js'
2
- import type { HttpError } from 'http-errors'
3
2
  import type { Readable } from 'node:stream'
4
3
  import type { Dispatcher } from 'undici'
5
4
 
@@ -52,7 +51,7 @@ interface ChangesOptions {
52
51
  live?: boolean
53
52
  heartbeat?: number
54
53
  retry?: (
55
- err: HttpError,
54
+ err: unknown,
56
55
  retryCount: number,
57
56
  params: {
58
57
  since?: string | 0 | null
package/deepstream.d.ts CHANGED
@@ -8,12 +8,12 @@ type Paths<T> = keyof T & string
8
8
  type Get<Data, Path extends string> = Path extends keyof Data ? Data[Path] : unknown
9
9
 
10
10
  export function makeDeepstream<
11
- Records,
11
+ Records extends Record<string, unknown> = Record<string, unknown>,
12
12
  RpcMethods extends Record<string, RpcMethodDef> = Record<string, RpcMethodDef>,
13
13
  >(client: DeepstreamClient<Records, RpcMethods>): NxtDeepstreamClient<Records, RpcMethods>
14
14
 
15
15
  export interface NxtDeepstreamClient<
16
- Records,
16
+ Records extends Record<string, unknown> = Record<string, unknown>,
17
17
  RpcMethods extends Record<string, RpcMethodDef> = Record<string, RpcMethodDef>,
18
18
  > {
19
19
  ds: DeepstreamClient<Records, RpcMethods> & { nxt: NxtDeepstreamClient<Records, RpcMethods> }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "27.0.8",
3
+ "version": "27.0.10",
4
4
  "license": "UNLICENSED",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -44,14 +44,15 @@
44
44
  "under-pressure.js"
45
45
  ],
46
46
  "scripts": {
47
- "test": "node --test-timeout 60000 --test"
47
+ "test": "node --test-timeout 60000 --test",
48
+ "test:types": "tsd"
48
49
  },
49
50
  "dependencies": {
50
51
  "@elastic/elasticsearch": "^8.17.1",
51
52
  "@elastic/transport": "^8.9.3",
52
53
  "@nxtedition/nxt-undici": "^7.1.4",
53
54
  "@nxtedition/sched": "^1.0.2",
54
- "@nxtedition/template": "^1.0.2",
55
+ "@nxtedition/template": "^1.0.3",
55
56
  "@nxtedition/weak-cache": "^1.0.1",
56
57
  "diff": "5.2.0",
57
58
  "eslint": "^9.38.0",
@@ -92,5 +93,5 @@
92
93
  "pino": ">=7.0.0",
93
94
  "rxjs": "^7.0.0"
94
95
  },
95
- "gitHead": "7f7389b0cae3822a99eb801f0c0dd0723fe5e140"
96
+ "gitHead": "ff46833af43b6a73524b89dcc1d4eeee2523ee08"
96
97
  }
package/sequence.js CHANGED
@@ -85,18 +85,13 @@ export class Sequence {
85
85
  if (typeof part === 'string') {
86
86
  const [sequenceStr, id] = part.split(ID_SEP)
87
87
  const sequence = parseInt(sequenceStr)
88
- assert(Number.isFinite(sequence) && sequence >= 0)
89
88
  this.#parts.push(id, sequence)
90
89
  this.#identity = null
91
90
  this.#count += part
92
91
  } else if (typeof part === 'number') {
93
- assert(Number.isFinite(part) && part >= 0)
94
- assert(Number.isFinite(identity))
95
92
  this.#parts.push('', part)
96
93
  this.#count += part
97
94
  } else if (part != null) {
98
- assert(Number.isFinite(part.sequence) && part.sequence >= 0)
99
- assert(typeof part.id === 'string' && part.id.length > 0)
100
95
  this.#parts.push(part.id, part.sequence)
101
96
  this.#identity = null
102
97
  this.#count += part.sequence
@@ -108,23 +103,13 @@ export class Sequence {
108
103
  } else if (typeof value === 'string') {
109
104
  const [countStr, token] = value.split('-')
110
105
  const count = parseInt(countStr)
111
- if (!Number.isFinite(count) || count < 0) {
112
- throw new Error('invalid sequence count')
113
- }
114
-
115
106
  if (token) {
116
107
  for (const str of token.split('_')) {
117
108
  const [sequenceStr, id] = str.split(ID_SEP)
118
109
  const sequence = parseInt(sequenceStr)
119
- if (!Number.isFinite(sequence) || sequence < 0) {
120
- throw new Error('invalid sequence part')
121
- }
122
110
  this.#parts.push(id, sequence)
123
111
  }
124
- } else if (count > 0) {
125
- throw new Error('invalid sequence parts')
126
112
  }
127
-
128
113
  this.#count = count
129
114
  this.#value = value
130
115
  } else if (value instanceof Sequence) {
@@ -133,7 +118,36 @@ export class Sequence {
133
118
  this.#parts = value.#parts.slice()
134
119
  this.#identity = value.#identity
135
120
  } else {
136
- assert(false)
121
+ throw new Error('invalid sequence value')
122
+ }
123
+
124
+ if (!Number.isInteger(this.#count) || this.#count < 0) {
125
+ throw new Error('invalid sequence count')
126
+ }
127
+
128
+ if (!Array.isArray(this.#parts)) {
129
+ throw new Error('invalid sequence parts')
130
+ }
131
+
132
+ {
133
+ let count = 0
134
+ for (let n = 0; n < this.#parts.length; n += 2) {
135
+ const id = this.#parts[n + 0]
136
+ if (typeof id !== 'string' || id.length === 0) {
137
+ throw new Error('invalid identity part')
138
+ }
139
+
140
+ const sequence = this.#parts[n + 1]
141
+ if (!Number.isInteger(sequence) || sequence < 0) {
142
+ throw new Error('invalid sequence part')
143
+ }
144
+
145
+ count += sequence
146
+ }
147
+
148
+ if (count !== this.#count) {
149
+ throw new Error('sequence count mismatch')
150
+ }
137
151
  }
138
152
 
139
153
  if (identity != null) {