@hocuspocus/provider 1.0.0-alpha.27 → 1.0.0-alpha.28

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.
@@ -0,0 +1,36 @@
1
+ /// <reference types="node" />
2
+ import { Extension, onChangePayload, onLoadDocumentPayload } from '@hocuspocus/server';
3
+ export interface DatabaseConfiguration {
4
+ /**
5
+ * Pass a Promise to retrieve updates from your database. The Promise should resolve to
6
+ * an array of items with Y.js-compatible binary data.
7
+ */
8
+ fetchUpdates: ({ documentName }: {
9
+ documentName: string;
10
+ }) => Promise<Uint8Array[]>;
11
+ /**
12
+ * Pass a function to store updates in your database.
13
+ */
14
+ storeUpdate: ({ update, documentName }: {
15
+ update: Buffer;
16
+ documentName: string;
17
+ }) => void;
18
+ }
19
+ export declare class Database implements Extension {
20
+ /**
21
+ * Default configuration
22
+ */
23
+ configuration: DatabaseConfiguration;
24
+ /**
25
+ * Constructor
26
+ */
27
+ constructor(configuration: Partial<DatabaseConfiguration>);
28
+ /**
29
+ * Get stored data from the database.
30
+ */
31
+ onLoadDocument({ document, documentName }: onLoadDocumentPayload): Promise<any>;
32
+ /**
33
+ * Store new updates in the database.
34
+ */
35
+ onChange({ document, documentName }: onChangePayload): Promise<void>;
36
+ }
@@ -0,0 +1 @@
1
+ export * from './Database';
@@ -0,0 +1,26 @@
1
+ import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database';
2
+ import sqlite3 from 'sqlite3';
3
+ export interface SQLiteConfiguration extends DatabaseConfiguration {
4
+ /**
5
+ * Valid values are filenames, ":memory:" for an anonymous in-memory database and an empty
6
+ * string for an anonymous disk-based database. Anonymous databases are not persisted and
7
+ * when closing the database handle, their contents are lost.
8
+ *
9
+ * https://github.com/mapbox/node-sqlite3/wiki/API#new-sqlite3databasefilename-mode-callback
10
+ */
11
+ database: string;
12
+ /**
13
+ * The database schema to create.
14
+ */
15
+ schema: string;
16
+ }
17
+ export declare class SQLite extends Database {
18
+ db?: sqlite3.Database;
19
+ configuration: SQLiteConfiguration;
20
+ /**
21
+ * Constructor
22
+ */
23
+ constructor(configuration?: Partial<SQLiteConfiguration>);
24
+ onListen(): Promise<void>;
25
+ onConfigure(): Promise<void>;
26
+ }
@@ -0,0 +1 @@
1
+ export * from './SQLite';
@@ -42,7 +42,7 @@ export declare class Webhook implements Extension {
42
42
  /**
43
43
  * Send a request to the given url containing the given data
44
44
  */
45
- sendRequest(event: Events, payload: any): Promise<AxiosResponse<unknown, any>>;
45
+ sendRequest(event: Events, payload: any): Promise<AxiosResponse<any, any>>;
46
46
  /**
47
47
  * onChange hook
48
48
  */
@@ -130,7 +130,7 @@ export declare class HocuspocusProvider extends EventEmitter {
130
130
  get awareness(): Awareness;
131
131
  checkConnection(): void;
132
132
  forceSync(): void;
133
- registerBeforeUnloadEventListener(): void;
133
+ registerEventListeners(): void;
134
134
  documentUpdateHandler(update: Uint8Array, origin: any): void;
135
135
  awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
136
136
  permissionDeniedHandler(reason: string): void;
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hocuspocus/provider",
3
- "version": "1.0.0-alpha.27",
3
+ "version": "1.0.0-alpha.28",
4
4
  "description": "hocuspocus provider",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
@@ -28,10 +28,10 @@
28
28
  "dist"
29
29
  ],
30
30
  "dependencies": {
31
- "@lifeomic/attempt": "^3.0.0",
32
- "lib0": "^0.2.42",
31
+ "@lifeomic/attempt": "^3.0.1",
32
+ "lib0": "^0.2.43",
33
33
  "y-protocols": "^1.0.5",
34
- "yjs": "^13.5.0"
34
+ "yjs": "^13.5.22"
35
35
  },
36
- "gitHead": "1bbb2df1f2be4046ca7e5415cd975e469ec16145"
36
+ "gitHead": "8ffe8d8f4d10ba33f4f203806bd1d4415bef5dc3"
37
37
  }
@@ -223,7 +223,7 @@ export class HocuspocusProvider extends EventEmitter {
223
223
 
224
224
  this.document.on('update', this.documentUpdateHandler.bind(this))
225
225
  this.awareness.on('update', this.awarenessUpdateHandler.bind(this))
226
- this.registerBeforeUnloadEventListener()
226
+ this.registerEventListeners()
227
227
 
228
228
  this.intervals.connectionChecker = setInterval(
229
229
  this.checkConnection.bind(this),
@@ -358,11 +358,12 @@ export class HocuspocusProvider extends EventEmitter {
358
358
  this.send(SyncStepOneMessage, { document: this.document })
359
359
  }
360
360
 
361
- registerBeforeUnloadEventListener() {
361
+ registerEventListeners() {
362
362
  if (typeof window === 'undefined') {
363
363
  return
364
364
  }
365
365
 
366
+ window.addEventListener('online', this.connect.bind(this))
366
367
  window.addEventListener('beforeunload', () => {
367
368
  removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload')
368
369
  })
@@ -580,6 +581,12 @@ export class HocuspocusProvider extends EventEmitter {
580
581
  this.document.off('update', this.documentUpdateHandler)
581
582
 
582
583
  this.removeAllListeners()
584
+
585
+ if (typeof window === 'undefined') {
586
+ return
587
+ }
588
+
589
+ window.removeEventListener('online', this.connect.bind(this))
583
590
  }
584
591
 
585
592
  get broadcastChannel() {