Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated email agent fork #4

Open
wants to merge 93 commits into
base: email-agent-fork
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
8ca20dd
[Docs] Indicate create*Query options.results is a Doc[]
ericyhwang Mar 1, 2022
5337969
Fix typos in query docs
curran Mar 17, 2022
cb3aaed
📝 Remove `id` from `getOpsBulk()` documentation
alecgibson Mar 22, 2022
c4a42ed
Merge branch 'share:master' into patch-16
curran Mar 30, 2022
b7eae5c
Merge pull request #555 from curran/patch-16
ericyhwang Apr 5, 2022
40c87bf
Merge pull request #558 from share/get-ops-bulk-docs
alecgibson Apr 5, 2022
c49ad21
More detail on create*Query prior results
ericyhwang Apr 5, 2022
92479d2
Merge pull request #546 from share/docs-createQuery-options-types
alecgibson Apr 12, 2022
c7e63b1
💥 Update Node.js test matrix
alecgibson May 3, 2022
6b5b038
Bump nokogiri from 1.13.3 to 1.13.4 in /docs
dependabot[bot] May 3, 2022
4d7f0d8
Merge pull request #563 from share/dependabot/bundler/docs/nokogiri-1…
alecgibson May 3, 2022
d535855
Merge pull request #562 from share/node-18
alecgibson May 3, 2022
7bf6781
3.0.0
alecgibson May 3, 2022
99b5519
👷 Bump GH actions
alecgibson Jul 12, 2022
16d7431
👷 Verbose GH Actions installation
alecgibson Jul 12, 2022
e71c91b
👷 Increase GH Actions timeout
alecgibson Jul 12, 2022
400ec52
👷 Use HTTPS to fetch `json0`
alecgibson Jul 12, 2022
b1c10d6
👷 Fix `json0` URL
alecgibson Jul 12, 2022
df19240
Revert "👷 Increase GH Actions timeout"
alecgibson Jul 12, 2022
8ed35d5
Revert "👷 Verbose GH Actions installation"
alecgibson Jul 12, 2022
bec7e6d
📌 Pin `json0` dev dependency
alecgibson Jul 12, 2022
8ec5279
📝 Update presence documentation
alecgibson Jul 12, 2022
b681366
Bump nokogiri from 1.13.4 to 1.13.7 in /docs
dependabot[bot] Jul 12, 2022
106e959
Merge pull request #567 from share/pin-json0
alecgibson Jul 12, 2022
5302bc7
Merge pull request #568 from share/dependabot/bundler/docs/nokogiri-1…
alecgibson Jul 12, 2022
8950626
Merge pull request #566 from share/docs-null-presence
alecgibson Jul 12, 2022
95297e5
Bump tzinfo from 1.2.9 to 1.2.10 in /docs
dependabot[bot] Jul 22, 2022
2532faa
Merge pull request #569 from share/dependabot/bundler/docs/tzinfo-1.2.10
alecgibson Jul 22, 2022
e91488d
Refactor action code strings into an enum-like object
ericyhwang Aug 9, 2022
461662d
Updates to message-actios from code review feedback
ericyhwang Aug 9, 2022
c4e82d6
Update action refactoring missed in automated renames
ericyhwang Aug 9, 2022
8879b28
Rename queryReply to queryUpdate, use shared action object from query.js
ericyhwang Aug 9, 2022
55fa1f3
Catch missed actions
alecgibson Aug 9, 2022
bbeaeb9
Add top-level export for MESSAGE_ACTIONS
ericyhwang Aug 9, 2022
28460e3
Merge pull request #570 from share/refactor-action-codes
ericyhwang Aug 9, 2022
8b531be
Refactor message action codes into a shared file
ericyhwang Aug 9, 2022
56ac7a8
✨ Add ping/pong
alecgibson Sep 27, 2022
9157342
Merge pull request #576 from share/ping-pong
alecgibson Sep 27, 2022
791937b
3.2.0
alecgibson Sep 27, 2022
aa9bf9c
Bump commonmarker from 0.23.4 to 0.23.6 in /docs
dependabot[bot] Sep 27, 2022
e3704a7
📝 Add `connection.ping()` to the documentation
alecgibson Sep 27, 2022
1231351
Merge pull request #577 from share/dependabot/bundler/docs/commonmark…
alecgibson Sep 27, 2022
5176283
Merge pull request #578 from share/ping-pong-docs
alecgibson Sep 27, 2022
d121a3e
🐛 Allow getting a `Doc` while it's being destroyed
alecgibson Oct 18, 2022
c9e773d
Merge pull request #580 from share/destroying-docs
alecgibson Oct 25, 2022
c3f7030
🐛 Allow getting `Presence` while it's being destroyed
alecgibson Oct 18, 2022
c22c4ff
Merge pull request #579 from share/destroying-presence
alecgibson Oct 25, 2022
2cdf094
3.2.1
alecgibson Oct 25, 2022
7bac0e9
👷‍♀️ Move to `ruby/setup-ruby` action
alecgibson Nov 23, 2022
9743fd1
Merge pull request #582 from share/bump-actions-versions
alecgibson Nov 29, 2022
8a8447b
Bump nokogiri from 1.13.7 to 1.13.9 in /docs
dependabot[bot] Nov 29, 2022
cc0e338
Merge pull request #583 from share/dependabot/bundler/docs/nokogiri-1…
alecgibson Nov 29, 2022
3db7070
✨ Allow middleware to mutate submitted ops
alecgibson Nov 23, 2022
2c04a08
🔇 Fix sensitive memory leak warnings when using presence
alecgibson Feb 1, 2023
a321275
Merge pull request #588 from share/presence-events
alecgibson Feb 7, 2023
b84290f
3.2.2
alecgibson Feb 7, 2023
7681077
✅ Fix flaky tests
alecgibson Feb 15, 2023
bd7ec3f
Merge pull request #590 from share/flaky-query-test-fix
alecgibson Feb 16, 2023
9c0f1c6
3.2.3
alecgibson Feb 16, 2023
36c8e65
Add missing import in hello world example
jameshfisher Feb 21, 2023
1ffa38a
Merge pull request #591 from jameshfisher/patch-1
ericyhwang Feb 21, 2023
daf3a25
✅ Remove order dependence from test
alecgibson Feb 21, 2023
a263d57
Merge pull request #592 from share/fix-test
alecgibson Feb 21, 2023
f4845fd
3.2.4
alecgibson Feb 21, 2023
ad23bf0
Upgrade deps in examples. Closes #594
curran Mar 2, 2023
2690ecb
Fix leaderboard example
curran Mar 2, 2023
9b4c9f4
Fix rich-text-presence example
curran Mar 2, 2023
72e47b1
Start on Vite example
curran Mar 2, 2023
280d681
Fix CI
curran Mar 2, 2023
628de99
✨ Add multi channel query subscription.
Dawidpol Jan 30, 2023
20f1fa7
Merge pull request #587 from share/feature/multi-channel-subscription
dawidreedsy Mar 3, 2023
812994f
Merge pull request #581 from share/server-fixup
alecgibson Mar 6, 2023
c587181
3.3.0
alecgibson Mar 6, 2023
0f4b211
Got Vite example to work
curran Mar 8, 2023
265840d
Upgrade ShareDB in examples. Fix presence API warning.
curran Mar 9, 2023
f783dec
Fix React warnings
curran Mar 9, 2023
404cde5
Merge pull request #595 from curran/upgrade-deps-in-examples
alecgibson Mar 28, 2023
a7c7697
✅ Try to fix flaky Milestone DB tests
alecgibson Mar 28, 2023
0166274
Merge pull request #602 from share/flaky-milestone-test-fix
alecgibson Mar 28, 2023
d21c26a
3.3.1
alecgibson Mar 28, 2023
ff5d515
Use glob override for .eslintrc
curran Mar 29, 2023
c637650
Make it work
curran Mar 29, 2023
c219205
Lint
curran Mar 29, 2023
ab2341e
Merge pull request #598 from curran/counter-json1-vite
ericyhwang Mar 30, 2023
ec12c16
Merge branch 'master' of github.com:lever/sharedb into email-agent-fork
distracteddev Apr 11, 2023
27dcfe3
Fix bad merge in test files
distracteddev Apr 13, 2023
ac490e0
💥 Drop Node.js 14 and add Node.js 20
alecgibson Apr 21, 2023
c1f1474
Merge pull request #606 from share/bump-node
alecgibson Apr 25, 2023
3e1e7f0
📝 Update docs around `reconnecting-websocket`
alecgibson May 2, 2023
6ee645d
🔊 Warn when messages are sent before the v1.1 handshake
alecgibson May 2, 2023
26d5d49
Merge pull request #607 from share/pre-handshake-warning
alecgibson May 2, 2023
21750e3
Merge pull request #608 from share/reconnecting-socket-docs
alecgibson May 2, 2023
59bce08
Merge branch 'master' of github.com:lever/sharedb into updated-email-…
distracteddev May 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,17 @@ module.exports = {
),
ignorePatterns: [
'/docs/'
],
overrides: [
{
files: ['examples/counter-json1-vite/*.js'],
parserOptions: {
ecmaVersion: 6,
sourceType: 'module'
},
rules: {
quotes: ['error', 'single']
}
}
]
};
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: '2.7'
- name: Install
run: cd docs && gem install bundler && bundle install
- name: Build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ jobs:
strategy:
matrix:
node:
- 12
- 14
- 16
- 18
- 20
services:
mongodb:
image: mongo:4.4
ports:
- 27017:27017
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- name: Install
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ jspm_packages

# Don't commit generated JS bundles
examples/**/static/dist/bundle.js
examples/**/dist
6 changes: 3 additions & 3 deletions docs/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GEM
execjs
coffee-script-source (1.11.1)
colorator (1.1.0)
commonmarker (0.23.4)
commonmarker (0.23.6)
concurrent-ruby (1.1.9)
dnsruby (1.61.9)
simpleidn (~> 0.1)
Expand Down Expand Up @@ -232,7 +232,7 @@ GEM
jekyll-seo-tag (~> 2.1)
minitest (5.15.0)
multipart-post (2.1.1)
nokogiri (1.13.3)
nokogiri (1.13.9)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
octokit (4.22.0)
Expand Down Expand Up @@ -265,7 +265,7 @@ GEM
thread_safe (0.3.6)
typhoeus (1.4.0)
ethon (>= 0.9.0)
tzinfo (1.2.9)
tzinfo (1.2.10)
thread_safe (~> 0.1)
tzinfo-data (1.2021.1)
tzinfo (>= 1.0.0)
Expand Down
4 changes: 0 additions & 4 deletions docs/api/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,6 @@ backend.getOpsBulk(agent, index, fromMap, toMap [, options [, callback]])

> The name of the collection or [projection]({{ site.baseurl }}{% link projections.md %})

`id` -- string

> The document ID

`fromMap` -- Object

> An object whose keys are the IDs of the target documents. The values are the first versions requested of each document (inclusive)
Expand Down
25 changes: 20 additions & 5 deletions docs/api/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ Optional

> Default: `{}`

> `options.results` -- Object[]
> `options.results` -- [`Doc`]({{ site.baseurl }}{% link api/doc.md %})[]

> > Prior query results, if available, such as from server rendering
> > Prior query results, if available, such as from server rendering. This should be an array of Doc instances, as obtained from `connection.get(collection, id)`. If the docs' data is already available, invoke [`ingestSnapshot`]({{ site.baseurl }}{% link api/doc.md %}#ingestsnapshot) for each Doc instance beforehand to avoid re-transferring the data from the server.

> `options.*` -- any

Expand Down Expand Up @@ -105,9 +105,9 @@ Optional

> Default: `{}`

> `options.results` -- Object[]
> `options.results` -- [`Doc`]({{ site.baseurl }}{% link api/doc.md %})[]

> > Prior query results, if available, such as from server rendering
> > Prior query results, if available, such as from server rendering. This should be an array of Doc instances, as obtained from `connection.get(collection, id)`. If the docs' data is already available, invoke [`ingestSnapshot`]({{ site.baseurl }}{% link api/doc.md %}#ingestsnapshot) for each Doc instance beforehand to avoid re-transferring the data from the server.

> `options.*` -- any

Expand Down Expand Up @@ -228,4 +228,19 @@ The document **must** be of a [type]({{ site.baseurl }}{% link types/index.md %}

Return value

> A [`Presence`]({{ site.baseurl }}{% link api/presence.md %}) instance tied to the given document
> A [`Presence`]({{ site.baseurl }}{% link api/presence.md %}) instance tied to the given document

### ping()

Send a short message to the server, which will respond with another short message, emitted on the connection as a
`'pong'` event.

```js
connection.ping()
connection.on('pong', () => {
// The server is still there
})
```

{: .warn }
Calling `ping()` when not connected will throw an error with code `ERR_CANNOT_PING_OFFLINE`.
3 changes: 3 additions & 0 deletions docs/api/presence.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ presence.on('receive', function(id, value) { ... });

> The presence value. The structure of this object will depend on the [type]({{ site.baseurl }}{% link types/index.md %})

{: .info }
> A `null` value means the remote client is no longer present in the document (e.g. they disconnected)

### `'error'`

An error has occurred.
Expand Down
7 changes: 6 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The ShareDB backend expects an instance of a [`Stream`](https://nodejs.org/api/s
```js
var express = require('express')
var WebSocket = require('ws')
var http = require('http')
var ShareDB = require('sharedb')
var WebSocketJSONStream = require('@teamwork/websocket-json-stream')

Expand Down Expand Up @@ -70,7 +71,11 @@ Try running the [working example](https://github.com/share/sharedb/tree/master/e
var ReconnectingWebSocket = require('reconnecting-websocket')
var Connection = require('sharedb/lib/client').Connection

var socket = new ReconnectingWebSocket('ws://localhost:8080')
var socket = new ReconnectingWebSocket('ws://localhost:8080', [], {
// ShareDB handles dropped messages, and buffering them while the socket
// is closed has undefined behavior
maxEnqueuedMessages: 0
})
var connection = new Connection(socket)

var doc = connection.get('doc-collection', 'doc-id')
Expand Down
8 changes: 6 additions & 2 deletions docs/middleware/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ This action has these additional `context` properties:

> The query's projection [fields]({{ site.baseurl }}{% link api/backend.md %}#addprojection)

`channel` -- string
`channel` -- string (deprecated)

> The [Pub/Sub]({{ site.baseurl }}{% link adapters/pub-sub.md %}) channel the query will subscribe to. Defaults to its collection channel.
> This property is deprecated use `channels` instead. The [Pub/Sub]({{ site.baseurl }}{% link adapters/pub-sub.md %}) channels the query will subscribe to. Defaults to its collection channel.

`channels` -- string[]

> The [Pub/Sub]({{ site.baseurl }}{% link adapters/pub-sub.md %}) channels the query will subscribe to. Defaults to its collection channel.

`query` -- Object

Expand Down
18 changes: 13 additions & 5 deletions docs/middleware/op-submission.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,20 @@ Since `'submitRequestEnd'` is an event -- not a middleware hook -- it provides n

## Mutating ops

{: .warn :}
Mutating ops in middleware is generally a **bad idea**, and should be avoided.
Ops may be amended in the `apply` middleware using the special `request.$fixup()` method:

The main reason for avoiding op mutation is that the client who submitted the op will not be informed of the mutation, so the client's doc will never receive the mutation.
```js
backend.use('apply', (request, next) => {
let error;
try {
request.$fixup([{p: ['meta'], oi: {timestamp: Date.now()}}]);
} catch (e) {
error = e;
}

The general workaround is to trigger a second op submission, rather than mutate the provided op. This obviously has the downside of op submissions being unatomic, but is the safest way to get the original client to receive the update.
next(error);
});
```

{: .warn :}
When submitting ops from the middleware, set careful conditions under which you submit ops in order to avoid infinite op submission loops, where submitting an op recursively triggers infinite op submissions.
The `request.$fixup()` method may throw an error, which should be handled appropriately, usually by passing directly to the `next()` callback.
16 changes: 16 additions & 0 deletions docs/presence.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ In this case, clients just need to subscribe to a common channel using [`connect
```js
const presence = connection.getPresence('my-channel')
presence.subscribe()

presence.on('receive', (presenceId, update) => {
if (update === null) {
// The remote client is no longer present in the document
} else {
// Handle the new value by updating UI, etc.
}
})
```

In order to send presence information to other clients, a [`LocalPresence`]({{ site.baseurl }}{% link api/local-presence.md %}) should be created. The presence object can take any arbitrary value
Expand Down Expand Up @@ -51,6 +59,14 @@ Clients subscribe to a particular [`Doc`]({{ site.baseurl }}{% link api/doc.md %
```js
const presence = connection.getDocPresence(collection, id)
presence.subscribe()

presence.on('receive', (presenceId, update) => {
if (update === null) {
// The remote client is no longer present in the document
} else {
// Handle the new value by updating UI, etc.
}
})
```

The shape of the presence value will be defined by the [type]({{ site.baseurl }}{% link types/index.md %}):
Expand Down
8 changes: 4 additions & 4 deletions docs/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ See the [API documentation]({{ site.baseurl }}{% link api/connection.md %}#creat
[`Query`]({{ site.baseurl }}{% link api/query.md %}) instance, which can be used instead:

```js
const query = connection.createFetchQuery('my-connection', {userId: 1})
const query = connection.createFetchQuery('my-collection', {userId: 1})
query.on('ready', () => {
// results are now available in query.results
})
Expand All @@ -48,7 +48,7 @@ A subscribed query will automatically cause any matched `Doc` instances to recei
Subscribe queries can be created similarly to fetch queries, but you may also be interested in [other events]({{ site.baseurl }}{% link api/query.md %}#events):

```js
const query = connection.createSubscribeQuery('my-connection', {userId: 1})
const query = connection.createSubscribeQuery('my-collection', {userId: 1})
query.on('ready', () => {
// The initial results are available in query.results
})
Expand All @@ -73,7 +73,7 @@ If a query can potentially return a large number of results, you may want to con
For example, a `sharedb-mongo` limit might look like this:

```js
const query = connection.createSubscribeQuery('my-connection', {userId: 1, $skip: 10, $limit: 10})
const query = connection.createSubscribeQuery('my-collection', {userId: 1, $skip: 10, $limit: 10})
```

{: .info }
Expand Down Expand Up @@ -160,7 +160,7 @@ backend.use('commit', (context, next) => {

backend.use('query', (context, next) => {
// Set our query to only listen for changes on our user-specific channel
context.channel = userChannel(context)
context.channels = [userChannel(context)]
next()
})

Expand Down
24 changes: 24 additions & 0 deletions examples/counter-json1-vite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
14 changes: 14 additions & 0 deletions examples/counter-json1-vite/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>ShareDB Counter (ottype json1 with Vite)</title>
</head>
<body>
<div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 36px;">
You clicked <span id="num-clicks"></span> times.
<button style="font-size: 36px;" class="increment">+1</button>
</div>
<script type="module" src="/main.js"></script>
</body>
</html>
37 changes: 37 additions & 0 deletions examples/counter-json1-vite/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import ReconnectingWebSocket from 'reconnecting-websocket';
import {json1} from 'sharedb-client-browser/dist/ot-json1-umd.cjs';
import sharedb from 'sharedb-client-browser/dist/sharedb-client-umd.cjs';

// Open WebSocket connection to ShareDB server
var socket = new ReconnectingWebSocket('ws://' + window.location.host + '/ws', [], {
// ShareDB handles dropped messages, and buffering them while the socket
// is closed has undefined behavior
maxEnqueuedMessages: 0
});
sharedb.types.register(json1.type);
var connection = new sharedb.Connection(socket);

// Create local Doc instance mapped to 'examples' collection document with id 'counter'
var doc = connection.get('examples', 'counter');

// Get initial value of document and subscribe to changes
doc.subscribe(showNumbers);
// When document changes (by this client or any other, or the server),
// update the number on the page
doc.on('op', showNumbers);

function showNumbers() {
document.querySelector('#num-clicks').textContent = doc.data.numClicks;
};

// When clicking on the '+1' button, change the number in the local
// document and sync the change to the server and other connected
// clients
function increment() {
// Increment `doc.data.numClicks`. See
// https://github.com/ottypes/json1/blob/master/spec.md for list of valid operations.
doc.submitOp(['numClicks', {ena: 1}]);
}

var button = document.querySelector('button.increment');
button.addEventListener('click', increment);
24 changes: 24 additions & 0 deletions examples/counter-json1-vite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "counter-json1-vite",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"start": "node server.js"
},
"dependencies": {
"@teamwork/websocket-json-stream": "^2.0.0",
"express": "^4.18.2",
"ot-json1": "^1.0.2",
"reconnecting-websocket": "^4.4.0",
"sharedb": "^3.3.1",
"sharedb-client-browser": "^4.2.1",
"ws": "^8.13.0"
},
"devDependencies": {
"vite": "^4.2.1"
}
}
Loading