Skip to content

Commit

Permalink
Merge branch 'ueberdosis:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
linspw authored Dec 11, 2023
2 parents 41d365f + 8be3c34 commit 5513da4
Show file tree
Hide file tree
Showing 66 changed files with 2,142 additions and 829 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ jobs:

steps:

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Load cached dependencies
uses: actions/[email protected].1
uses: actions/[email protected].2
id: cache
with:
path: |
Expand Down Expand Up @@ -61,15 +61,15 @@ jobs:

steps:

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Load cached dependencies
uses: actions/[email protected].1
uses: actions/[email protected].2
id: cache
with:
path: |
Expand Down Expand Up @@ -99,15 +99,15 @@ jobs:

steps:

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Load cached dependencies
uses: actions/[email protected].1
uses: actions/[email protected].2
id: cache
with:
path: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
docsearch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.0.2
- uses: actions/checkout@v4

- name: Run DocSearch Scraper
shell: bash
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
registry-url: https://registry.npmjs.org/
Expand Down
59 changes: 59 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,65 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.8.1](https://github.com/ueberdosis/hocuspocus/compare/v2.8.0...v2.8.1) (2023-11-21)

**Note:** Version bump only for package hocuspocus





# [2.8.0](https://github.com/ueberdosis/hocuspocus/compare/v2.7.1...v2.8.0) (2023-11-15)

**Note:** Version bump only for package hocuspocus





## [2.7.1](https://github.com/ueberdosis/hocuspocus/compare/v2.7.0...v2.7.1) (2023-10-19)

**Note:** Version bump only for package hocuspocus





# [2.7.0](https://github.com/ueberdosis/hocuspocus/compare/v2.6.1...v2.7.0) (2023-10-16)

**Note:** Version bump only for package hocuspocus





## [2.6.1](https://github.com/ueberdosis/hocuspocus/compare/v2.6.0...v2.6.1) (2023-10-05)


### Bug Fixes

* add `documentName` into broadcast message ([#713](https://github.com/ueberdosis/hocuspocus/issues/713)) ([8400928](https://github.com/ueberdosis/hocuspocus/commit/840092861fa2801c62d5c12d5574bfe24e266c3f))





# [2.6.0](https://github.com/ueberdosis/hocuspocus/compare/v2.5.0...v2.6.0) (2023-10-04)

**Note:** Version bump only for package hocuspocus





# [2.5.0](https://github.com/ueberdosis/hocuspocus/compare/v2.5.0-rc.0...v2.5.0) (2023-09-06)

**Note:** Version bump only for package hocuspocus





# [2.5.0-rc.0](https://github.com/ueberdosis/hocuspocus/compare/v2.4.0...v2.5.0-rc.0) (2023-08-24)

**Note:** Version bump only for package hocuspocus
Expand Down
6 changes: 3 additions & 3 deletions docs/guides/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ With the `onAuthenticate` hook you can check if a client is authenticated and au

When throwing an error or rejecting the returned Promise, the connection to the client will be terminated (see [server hooks lifecycle](/server/hooks#lifecycle)). If the client is authorized and authenticated you can also return contextual data such as a user id which will be accessible in other hooks. But you don’t need to.

For more information on the hook and it's payload checkout it's [section](/server/hooks#on-authenticate).
For more information on the hook and its payload, check out its [section](/server/hooks#on-authenticate).

```js
import { Server } from "@hocuspocus/server";
Expand Down Expand Up @@ -52,8 +52,8 @@ new HocuspocusProvider({

## Read only mode

If you want to restrict the current user only to read the document and it's updates but not apply
updates him- or herself, you can use the `connection` property in the `onAuthenticate` hooks payload:
If you want to restrict the current user only to read the document and its updates but not apply
updates themselves, you can use the `connection` property in the `onAuthenticate` hooks payload:

```js
import { Server } from "@hocuspocus/server";
Expand Down
4 changes: 1 addition & 3 deletions docs/guides/custom-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You can see the extensions we have already created [here](/server/extensions).

Hocuspocus is written in TypeScript. You don't have to use TypeScript to write extensions, but it's highly recommended. We will only cover the TypeScript part in this documentation.

First step: Create a new class that implements the `Extension` interface and add the method stubs the interface requires.
First step: Create a new class that implements the [`Extension`](https://github.com/ueberdosis/hocuspocus/blob/14e5676ff685a1432d87fed780b6cbead12c8122/packages/server/src/types.ts#L35-L57) interface and add the desired hooks.

As every hook needs to return a Promise, the easiest way is to mark them as `async`.

Expand Down Expand Up @@ -53,8 +53,6 @@ Notice something? These look like the hooks we introduced in the previous chapte

Now you can add a constructor that accepts your extension's configuration and merges the default one. It's good practise at this point to create an interface for your configuration too.

You need to keep all those methods, even if you don't use them. If you want to get rid of those annoying TypeScript warnings about empty functions, you can add the `@typescript-eslint/no-empty-function` annotation.

```js
import {
Extension,
Expand Down
7 changes: 2 additions & 5 deletions docs/server/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ npx @hocuspocus/cli --sqlite

### Express

Hocuspocus can be used with any WebSocket implementation that uses `ws` under the hood. When you don't call `listen()` on Hocuspocus, it will not start a WebSocket server itself but rather relies on you calling it's [`handleConnection()` method](/server/methods) manually.
Hocuspocus can be used with any WebSocket implementation that uses `ws` under the hood. When you don't call `listen()` on Hocuspocus, it will not start a WebSocket server itself but rather relies on you calling its [`handleConnection()` method](/server/methods) manually.

To use Hocuspocus with [Express](https://expressjs.com), you need to use the `express-ws` package that adds WebSocket endpoints to Express applications. Then add a new WebSocket route and use Hocuspocus' `handleConnection()` method to do the rest.

Expand All @@ -44,10 +44,9 @@ app.get("/", (request, response) => {
});

// Add a websocket route for Hocuspocus
// Note: make sure to include a parameter for the document name.
// You can set any contextual data like in the onConnect hook
// and pass it to the handleConnection method.
app.ws("/collaboration/:document", (websocket, request) => {
app.ws("/collaboration", (websocket, request) => {
const context = {
user: {
id: 1234,
Expand Down Expand Up @@ -83,12 +82,10 @@ const app = new Koa();
app.use(websocket());

// Add a websocket route for Hocuspocus
// Note: make sure to include a parameter for the document name.
// You can set any contextual data like in the onConnect hook
// and pass it to the handleConnection method.
app.use(async (ctx, next) => {
const ws = await ctx.ws();
const documentName = ctx.request.path.substring(1);

server.handleConnection(
ws,
Expand Down
7 changes: 5 additions & 2 deletions docs/server/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ We already created some very useful extensions you should check out for sure:
| Extension | Description |
|-----------------------------------------| ------------------------------------------------------------------------------ |
| [Database](/server/extensions#database) | A generic database driver that is easily adjustable to work with any database. |
| [Redis](/server/extensions#redis) | Scale Hocuspocus horizontally with Redis. |
| [Logger](/server/extensions#logger) | Add logging to Hocuspocus. |
| [Webhook](/server/extensions#webhook) | Send document changes via webhook to your API. |
| [Redis](/server/extensions#redis) | Scale Hocuspocus horizontally with Redis. |
| [SQLite](/server/extensions#sq-lite) | Persist documents to SQLite. |
| [Throttle](/server/extensions#throttle) | Throttle connections by ips. |
| [Webhook](/server/extensions#webhook) | Send document changes via webhook to your API. |

## Database

Expand Down Expand Up @@ -178,6 +179,8 @@ Hocuspocus can be scaled horizontally using the Redis extension. You can spawn m
load balancer and sync changes and awareness states through Redis. Hocuspocus will propagate all received updates to all other instances
using Redis and thus forward updates to all clients of all Hocuspocus instances.
The Redis extension does not persist data; it only syncs data between instances. Use the [Database](/server/extensions#database) extension to store your documents.
Please note that all messages will be handled on all instances of Hocuspocus, so if you are trying to reduce cpu load by spawning multiple
servers, you should not connect them via Redis.
Expand Down
8 changes: 4 additions & 4 deletions docs/server/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ tableOfContents: true

## Introduction

Hocuspocus offers hooks to extend it's functionality and integrate it into existing applications. Hooks are configured as simple methods the same way as [other configuration options](/server/configuration) are.
Hocuspocus offers hooks to extend its functionality and integrate it into existing applications. Hooks are configured as simple methods the same way as [other configuration options](/server/configuration) are.

Hooks accept a hook payload as first argument. The payload is an object that contains data you can use and manipulate, allowing you to built complex things on top of this simple mechanic, like [extensions](/guides/custom-extensions).

Hooks are required to return a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), the easiest way to do that is to mark the function as `async` (Node.js version must 14+). In this way, you can do things like executing API requests, running DB queries, trigger webhooks or whatever you need to do to integrate it into your application.
Hooks are required to return a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise); the easiest way to do that is to mark the function as `async` (Node.js version must 14+). In this way, you can do things like executing API requests, running DB queries, trigger webhooks or whatever you need to do to integrate it into your application.

## Lifecycle

Expand All @@ -20,7 +20,7 @@ Some hooks allow you not only to react to those events but also to intercept the

## The hook chain

Extensions use hooks to add additional functionality to Hocuspocus. They will be called after another in the order of their registration with your configuration as the last part of the chain.
Extensions use hooks to add additional functionality to Hocuspocus. They will be called one after another in the order of their registration with your configuration as the last part of the chain.

If the Promise in a hook is rejected it will not be called for the following extensions or your configuration. It's like a stack of middlewares a request has to go through. Keep that in mind when working with hooks.

Expand Down Expand Up @@ -608,7 +608,7 @@ Context contains the data provided in former `onConnect` hooks.
### afterLoadDocument
The `afterLoadDocument` hooks are called after a document is successfully loaded. This is different
The `afterLoadDocument` hooks are called after a document is successfully loaded. This is different
to the `onLoadDocument` hooks which are part of the document creation process and could potentially
fail if for instance the document cannot be found in the database.
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"conventionalCommits": true
}
},
"version": "2.5.0-rc.0"
"version": "2.8.1"
}
Loading

0 comments on commit 5513da4

Please sign in to comment.