@nxtedition/deepstream.io-client-js 32.0.12 → 32.0.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/deepstream.io-client-js",
3
- "version": "32.0.12",
3
+ "version": "32.0.13",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "type": "module",
package/src/client.d.ts CHANGED
@@ -33,6 +33,8 @@ export type {
33
33
  SyncOptions,
34
34
  Paths,
35
35
  Get,
36
+ ConnectionStateName,
37
+ DeepstreamErrorEventName,
36
38
  }
37
39
 
38
40
  type RecordStateConstants = Readonly<{
@@ -99,6 +101,26 @@ export interface DeepstreamError extends Error {
99
101
  data?: unknown
100
102
  }
101
103
 
104
+ export interface DeepstreamMessage {
105
+ raw: string | null
106
+ topic: string | null
107
+ action: string | null
108
+ data: string[]
109
+ }
110
+
111
+ export interface DeepstreamClientEventMap {
112
+ connectionStateChanged: (state: ConnectionStateName) => void
113
+ connected: (connected: boolean) => void
114
+ MAX_RECONNECTION_ATTEMPTS_REACHED: (attempt: number) => void
115
+ error: (error: DeepstreamError) => void
116
+ recv: (message: DeepstreamMessage) => void
117
+ send: (message: DeepstreamMessage) => void
118
+ }
119
+
120
+ type DeepstreamErrorEventMap = {
121
+ [K in DeepstreamErrorEventName]: (error: DeepstreamError) => void
122
+ }
123
+
102
124
  export interface DeepstreamClient<
103
125
  Records extends Record<string, unknown> = Record<string, unknown>,
104
126
  Methods extends Record<string, RpcMethodDef> = Record<string, RpcMethodDef>,
@@ -108,18 +130,21 @@ export interface DeepstreamClient<
108
130
  rpc: RpcHandler<Methods>
109
131
  record: RecordHandler<Records>
110
132
  user: string | null
111
- on(evt: 'connectionStateChanged', callback: (state: ConnectionStateName) => void): this
112
- on(evt: 'connected', callback: (connected: boolean) => void): this
113
- on(evt: 'MAX_RECONNECTION_ATTEMPTS_REACHED', callback: (attempt: number) => void): this
114
- on(evt: 'error' | DeepstreamErrorEventName, callback: (error: DeepstreamError) => void): this
115
- off(evt: 'connectionStateChanged', callback: (state: ConnectionStateName) => void): this
116
- off(evt: 'connected', callback: (connected: boolean) => void): this
117
- off(evt: 'MAX_RECONNECTION_ATTEMPTS_REACHED', callback: (attempt: number) => void): this
118
- off(evt: 'error' | DeepstreamErrorEventName, callback: (error: DeepstreamError) => void): this
133
+ on<K extends keyof (DeepstreamClientEventMap & DeepstreamErrorEventMap)>(
134
+ evt: K,
135
+ callback: (DeepstreamClientEventMap & DeepstreamErrorEventMap)[K],
136
+ ): this
137
+ off<K extends keyof (DeepstreamClientEventMap & DeepstreamErrorEventMap)>(
138
+ evt: K,
139
+ callback: (DeepstreamClientEventMap & DeepstreamErrorEventMap)[K],
140
+ ): this
119
141
  getConnectionState: () => ConnectionStateName
120
142
  close: () => void
121
143
  login(callback: (success: boolean, authData: unknown) => void): this
122
- login(authParams: object, callback: (success: boolean, authData: unknown) => void): this
144
+ login(
145
+ authParams: Record<string, unknown>,
146
+ callback: (success: boolean, authData: unknown) => void,
147
+ ): this
123
148
  stats: {
124
149
  record: RecordStats
125
150
  rpc: RpcStats
@@ -78,7 +78,7 @@ EventHandler.on = function (name, callback) {
78
78
 
79
79
  EventHandler.once = function (name, callback) {
80
80
  const fn = (...args) => {
81
- this.unsubscribe(fn)
81
+ this.unsubscribe(name, fn)
82
82
  callback(...args)
83
83
  }
84
84
  this.subscribe(name, fn)
@@ -249,7 +249,7 @@ class Record {
249
249
  when(stateOrNil, optionsOrNil) {
250
250
  invariant(this._refs > 0, 'missing refs')
251
251
 
252
- if (stateOrNil != null && stateOrNil === 'object') {
252
+ if (stateOrNil != null && typeof stateOrNil === 'object') {
253
253
  optionsOrNil = stateOrNil
254
254
  stateOrNil = optionsOrNil?.state
255
255
  }
@@ -85,7 +85,7 @@ export function setTimeout(callback, timeoutDuration) {
85
85
 
86
86
  export function setInterval(callback, intervalDuration) {
87
87
  if (intervalDuration !== null) {
88
- return setInterval(callback, intervalDuration)
88
+ return globalThis.setInterval(callback, intervalDuration)
89
89
  } else {
90
90
  return -1
91
91
  }
@@ -1,9 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(npm run test:types:*)"
5
- ],
6
- "deny": [],
7
- "ask": []
8
- }
9
- }