Skip to content

Commit 20707ca

Browse files
committed
4.0.0
1 parent cfdcce1 commit 20707ca

File tree

3 files changed

+96
-223
lines changed

3 files changed

+96
-223
lines changed

CHANGELOG.md

Lines changed: 86 additions & 213 deletions
Original file line numberDiff line numberDiff line change
@@ -1,244 +1,117 @@
1-
# [4.0.0-rc.43] - 2019-07-23
2-
3-
- Fixing an async issue when loading info from offline storage
4-
5-
# [4.0.0-rc.35] - 2019-07-01
6-
7-
- Don't resubscribe records that are unsubscribing on a reconnect
8-
9-
# [4.0.0-rc.31] - 2019-06-27
10-
11-
- Adding an autoVersion option for indexdb
12-
- Fixing a reconnect issue when starting client when server is down
13-
14-
# [4.0.0-rc.30] - 2019-06-13
15-
16-
- Only transition the state to unsubscribing if its the last reference being removed
17-
18-
# [4.0.0-rc.29] - 2019-06-13
19-
20-
- Adding the concept of context to emitter, used to fixed a bug in record where discard doesn't
21-
delete the local emitter bindings, but can hopefully be extended elsewhere
22-
23-
# [4.0.0-rc.28] - 2019-06-10
24-
25-
- Emitter is no longer a dependency and instead is owned by us, which makes typescript happier
26-
27-
# [4.0.0-rc.27] - 2019-06-06
28-
29-
- Users can now delete the offline store via the record handler. This is useful for situations such
30-
as ensuring nothing is on disk on logout.
31-
32-
# [4.0.0-rc.25] - 2019-06-03
33-
34-
- Merging should transition a record to ready when first initialized
35-
- Changing state machine to log an error instead of throwing one to stop things breaking too badly
36-
37-
# [4.0.0-rc.22] - 2019-05-28
38-
39-
- Delete collections from indexdb if no longer in objectStoreList
40-
- Fixing a race condition where ready is triggered without setting the data first
41-
- Adding ability to ignore saving records in indexdb
42-
- Adding the ability to save each update as it comes from the server.
43-
- Save records to storage before they are discarded
44-
- Changing npm to use deepstream org
45-
46-
# [4.0.0-rc.12] - 2019-05-17
47-
48-
- Firing the change event on records before transitioning results in the state machine not
49-
working as expected when doing something like our initial API usage in 2.0 days
50-
51-
```
52-
const record = ds.record.get(name)
53-
record.subscribe(() => {
54-
// do something
55-
record.discard()
56-
// oh no! we never entered the ready state =(
57-
})
58-
```
59-
60-
- Seems like URL gets injected into node somehow, which means we don't want to reference window.URL
61-
- Removing an async state transition to avoid issues when CPU intensive apps are started
62-
- Removing an invalid error message in merge conflicts
63-
- Removing node-localstorage as a dependency, as its node only and doesn't play well with angular
64-
65-
# [4.0.0-rc.3] - 2019-05-16
66-
67-
This release adds indexDB. However its not in a stable state.
68-
69-
# [4.0.0-rc.3] - 2019-05-05
70-
71-
This release includes bulk subscriptions, which allow thousands of records to be subscribed to with a single message,
72-
providing a huge performance boost for application startup time and data on the wire
73-
74-
# [4.0.0-rc.1] - 2019-04-20
75-
76-
This release of the client includes a full rewrite in TypeScript and a move away from the old text-based protocol to the Universal Realtime Protocol (URP). This means the client is not compatible with [deepstream.io](https://github.com/deepstreamio/deepstream.io) prior to version v4.0.0.
77-
78-
## Features
79-
80-
### Additional events
81-
82-
- **clientDataChanged**: emitted every time the server sends new the client new data after authenticating
83-
84-
```javascript
85-
client.on('clientDataChanged', clientData => { ... })
86-
```
87-
88-
- **reauthenticationFailure**: emitted when a client is unable to authenticate with the server after a reconnection. This will only be called for automatic reconnection attempts during connection loss or similar, if calling the `login` function authentication is as normal
89-
90-
```javascript
91-
client.on('reAuthenticationFailure', reason => { ... })
92-
```
93-
94-
## Improvements
95-
96-
### Promisified API's
97-
98-
- Presence
99-
```javascript
100-
client.presence.getAll()
101-
.then(users => {})
102-
.catch(error => {})
103-
104-
client.presence.getAll(users)
105-
.then(users => {})
106-
.catch(error => {})
107-
```
108-
109-
- RPC
110-
```javascript
111-
client.rpc.make(name, data)
112-
.then(data => {})
113-
.catch(error => {})
114-
```
115-
116-
- Record Factory
117-
118-
```javascript
119-
client.record.snapshot(recordName)
120-
.then(data => {})
121-
.catch(error => {})
122-
123-
client.record.has(recordName)
124-
.then(exists => {})
125-
.catch(error => {})
126-
127-
client.record.head(recordName)
128-
.then(version => {})
129-
.catch(error => {})
130-
```
131-
132-
- Record
133-
134-
```javascript
135-
record.whenReady()
136-
.then(() => {})
137-
record.delete()
138-
.then(() => {})
139-
.catch(error => {})
1+
# [4.0.0] - 2019-07-30
2+
3+
### Features:
4+
5+
- New binary protocol support (under the hood)
6+
- Bulk actions support (under the hood)
7+
- Full typescript declaration files
8+
- Promises everywhere! Long live async/await!
9+
- Offline record support
10+
11+
```JavaScript
12+
{
13+
// Use indexdb to store data client side
14+
offlineEnabled: false,
15+
// Save each update as it comes in from the server
16+
saveUpdatesOffline: false,
17+
indexdb: {
18+
// The db version, incrementing this triggers a db upgrade
19+
dbVersion: 1,
20+
// This auto updates the indexdb version if the objectStore names change
21+
autoVersion: false,
22+
// The key to index records by
23+
primaryKey: 'id',
24+
// The indexdb databae name
25+
storageDatabaseName: 'deepstream',
26+
// The default store name if not using a '/' to indicate the object store (example person/uuid)
27+
defaultObjectStoreName: 'records',
28+
// The object store names, required in advance due to how indexdb works
29+
objectStoreNames: [],
30+
// Things to not save, such search results
31+
ignorePrefixes: [],
32+
// The amount of time to buffer together actions before making a request
33+
flushTimeout: 50
34+
}
35+
}
14036
```
14137

142-
### Improved record error handling
38+
- Customizable offline storage support
14339

144-
Permission errors of any kind are now routed to the record instance that had the error. Consider the following snippet
40+
```typescript
41+
export type offlineStoreWriteResponse = ((error: string | null, recordName: string) => void)
14542

146-
```javascript
147-
client.on('error', (description, event, topic) => { ... })
148-
const record = client.record.getRecord('permission-error')
149-
record.set('firstname', 'Homer')
43+
export interface RecordOfflineStore {
44+
get: (recordName: string, callback: ((recordName: string, version: number, data: RecordData) => void)) => void
45+
set: (recordName: string, version: number, data: RecordData, callback: offlineStoreWriteResponse) => void
46+
delete: (recordName: string, callback: offlineStoreWriteResponse) => void
47+
}
15048
```
15149

152-
In this instance all errors are passed to the global client error handler. When dealing with multiple records, it is difficult to correlate errors to different records. We now support the following
153-
154-
```javascript
155-
const record = client.record.getRecord('permission-error')
156-
record.on('error', (description, event, topic) => { ... })
157-
record.set('firstname', 'Homer')
158-
```
159-
160-
### TypeScript
161-
162-
This release includes a full rewrite of the client in TypeScript, fixing many bugs and improving the client quality.
163-
164-
### Client-server binary protocol
165-
166-
A full implementation of the Universal Realtime Protocol (URP) to match deepstream v4.
167-
168-
## Breaking changes
169-
170-
### Chaining
50+
### Improvements
17151

172-
Many functions are no longer chainable (returning an instance of the client or a record) due to supporting promises. This means calls like `client.login` and will return a promise if no callback is provided.
52+
- Separation of errors and warnings for clarity. Non critical failures (such as an ack timeout) can now be treated separated or fully muted.
53+
- Enhanced services to reduce timeout overhead
17354

174-
### Module exports
55+
### Backwards compatibility
17556

176-
Previously a function was exported that allowed creating an instance of the client as follows
57+
- Only works with V4 server
58+
- All single response APIs now return promises when not providing a callback. This means most APIs that could have been chained would now break.
17759

178-
```javascript
179-
const deepstream = require('deepstream.io-client-js')
180-
const client = deepstream('DEEPSTREAM_URL')
181-
// constants also accessible via deepstream.C
182-
```
60+
```JavaScript
61+
const client = deepstream()
62+
try {
63+
await client.login()
18364

184-
We now support the following
65+
const record = client.record.getRecord(name)
66+
await record.whenReady()
18567

186-
```javascript
187-
const { deepstream, C, EVENT, CONNECTION_STATE } = require('deepstream.io-client-js')
68+
const data = await client.record.snapshot(name)
69+
const version = await client.record.head(name)
70+
const exists = await client.record.has(name)
71+
const result = await client.rpc.make(name, data)
72+
const users = await client.presence.getAll()
73+
} catch (e) {
74+
console.log('Error occurred', e)
75+
}
18876
```
18977

190-
### Login
191-
192-
As mentioned higher up, the callback passed to the login function now is called just once. In order to handle client reconnections the `clientDataChanged` and `reAuthenticationFailure` events should be used instead.
193-
194-
### Listening
78+
- Listening
19579

196-
The `isSubscribed` flag in the listener callback was removed and now the response object
197-
has an `onStop` function which will be called when there are no more subscribers on the topic.
80+
The listening API has been ever so slightly tweaked in order to simplify removing an active subscription.
19881

199-
With this change the same context is kept when a subscription is found or removed
200-
and the listen callback now is called just once.
82+
Before when an active provider was started you would usually need to store it in a higher scope, for example:
20183

202-
For those familiar with listening, this
84+
```typescript
85+
const listeners = new Map()
20386

204-
```javascript
205-
client.record.listen('^news/.*', (match, isSubscribed, response) => {
206-
if (isSubscribed) {
207-
if (/* able to provide for this match */) {
208-
response.accept()
209-
// start providing data
87+
client.record.listen('users/.*', (name, isSubscribed, ({ accept, reject }) => {
88+
if (isSubscribed) {
89+
const updateInterval = setInterval(updateRecord.bind(this, name), 1000)
90+
listeners.set(name, updateInterval)
91+
accept()
21092
} else {
211-
response.reject()
93+
clearTimeout(listeners.get(name))
94+
listeners.delete(name)
21295
}
213-
return
214-
}
215-
// stop providing data
21696
})
21797
```
21898
219-
turns into this:
99+
Where now we instead do:
220100
221-
```javascript
222-
client.record.listen('^news/.*', (match, response) => {
223-
if (/* unable to provide for this match */) {
224-
response.reject()
225-
return
226-
}
227-
response.accept()
228-
response.onStop((match) => {
229-
// stop providing data
230-
})
231-
// start providing data
101+
```typescript
102+
const listeners = new Map()
103+
104+
client.record.listen('users/.*', (name, ({ accept, reject, onStop }) => {
105+
const updateInterval = setInterval(updateRecord.bind(this, name), 1000)
106+
accept()
107+
108+
onStop(() => clearTimeout(updateInterval))
232109
})
233110
```
234-
- Presence
235111
236-
The callback for `client.presence.getAll` is now called with an error parameter in standard JavaScript convention
112+
### TLDR;
237113
238-
```javascript
239-
client.presence.getAll((error, userList) => { ... })
240-
client.presence.getAll(users, (error, userMap) => { ... })
241-
```
114+
You can see the in depth side explanation of the changes [here](https://deepstream.io/releases/client-js/v4-0-0/)
242115
243116
## [2.3.0] - 2017-09-25
244117

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@deepstream/client",
3-
"version": "4.0.0-rc.50",
3+
"version": "4.0.0",
44
"description": "the javascript client for deepstream.io",
55
"keywords": [
66
"deepstream",
@@ -30,7 +30,7 @@
3030
"url": "https://github.com/deepstreamIO/deepstream.io-client-js.git"
3131
},
3232
"dependencies": {
33-
"@deepstream/protobuf": "^1.0.0-rc.7",
33+
"@deepstream/protobuf": "^1.0.0",
3434
"protobufjs": "^6.8.8",
3535
"ws": "^7.1.1"
3636
},
@@ -48,7 +48,7 @@
4848
"bluebird": "^3.5.5",
4949
"chai": "^4.2.0",
5050
"coveralls": "^3.0.5",
51-
"husky": "^3.0.1",
51+
"husky": "^3.0.2",
5252
"mocha": "^6.2.0",
5353
"nyc": "^14.1.1",
5454
"rimraf": "^2.6.3",

0 commit comments

Comments
 (0)