@hocuspocus/extension-database 1.0.0-alpha.13 → 1.0.0-alpha.16
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/dist/hocuspocus-database.cjs +4 -4
- package/dist/hocuspocus-database.cjs.map +1 -1
- package/dist/hocuspocus-database.esm.js +4 -4
- package/dist/hocuspocus-database.esm.js.map +1 -1
- package/dist/packages/extension-database/src/Database.d.ts +3 -5
- package/dist/packages/extension-monitor/src/Collector.d.ts +2 -1
- package/dist/packages/extension-redis/src/Redis.d.ts +2 -2
- package/dist/packages/server/src/Hocuspocus.d.ts +2 -2
- package/dist/packages/server/src/types.d.ts +17 -5
- package/dist/tests/extension-database/fetch.d.ts +1 -0
- package/dist/tests/utils/index.d.ts +1 -0
- package/dist/tests/utils/randomInteger.d.ts +1 -0
- package/package.json +4 -4
- package/src/Database.ts +10 -6
|
@@ -44,12 +44,12 @@ class Database {
|
|
|
44
44
|
/**
|
|
45
45
|
* Get stored data from the database.
|
|
46
46
|
*/
|
|
47
|
-
async onLoadDocument(
|
|
48
|
-
const update = await this.configuration.fetch(
|
|
47
|
+
async onLoadDocument(data) {
|
|
48
|
+
const update = await this.configuration.fetch(data);
|
|
49
49
|
if (update) {
|
|
50
|
-
Y__namespace.applyUpdate(document, update);
|
|
50
|
+
Y__namespace.applyUpdate(data.document, update);
|
|
51
51
|
}
|
|
52
|
-
return document;
|
|
52
|
+
return data.document;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Store new updates in the database.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hocuspocus-database.cjs","sources":["../src/Database.ts"],"sourcesContent":["import {\n Extension
|
|
1
|
+
{"version":3,"file":"hocuspocus-database.cjs","sources":["../src/Database.ts"],"sourcesContent":["import {\n Extension,\n onChangePayload,\n onLoadDocumentPayload,\n storePayload,\n fetchPayload,\n} from '@hocuspocus/server'\nimport * as Y from 'yjs'\n\nexport interface DatabaseConfiguration {\n /**\n * Pass a Promise to retrieve updates from your database. The Promise should resolve to\n * an array of items with Y.js-compatible binary data.\n */\n fetch: (data: fetchPayload) => Promise<Uint8Array | null>,\n /**\n * Pass a function to store updates in your database.\n */\n store: (data: storePayload) => void,\n}\n\nexport class Database implements Extension {\n /**\n * Default configuration\n */\n configuration: DatabaseConfiguration = {\n fetch: async () => null,\n store: async () => null,\n }\n\n /**\n * Constructor\n */\n constructor(configuration: Partial<DatabaseConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n }\n\n /**\n * Get stored data from the database.\n */\n async onLoadDocument(data: onLoadDocumentPayload): Promise<any> {\n const update = await this.configuration.fetch(data)\n\n if (update) {\n Y.applyUpdate(data.document, update)\n }\n\n return data.document\n }\n\n /**\n * Store new updates in the database.\n */\n async onStoreDocument(data: onChangePayload) {\n return this.configuration.store({\n ...data,\n state: Buffer.from(\n Y.encodeStateAsUpdate(data.document),\n ),\n })\n }\n}\n"],"names":["Y"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;MAqBa,QAAQ,CAAA;AASnB;;AAEG;AACH,IAAA,WAAA,CAAY,aAA6C,EAAA;AAXzD;;AAEG;AACH,QAAA,IAAA,CAAA,aAAa,GAA0B;AACrC,YAAA,KAAK,EAAE,YAAY,IAAI;AACvB,YAAA,KAAK,EAAE,YAAY,IAAI;SACxB,CAAA;QAMC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SACjB,CAAA;KACF;AAED;;AAEG;IACH,MAAM,cAAc,CAAC,IAA2B,EAAA;QAC9C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AAEnD,QAAA,IAAI,MAAM,EAAE;YACVA,YAAC,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;AACrC,SAAA;QAED,OAAO,IAAI,CAAC,QAAQ,CAAA;KACrB;AAED;;AAEG;IACH,MAAM,eAAe,CAAC,IAAqB,EAAA;AACzC,QAAA,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;AAC9B,YAAA,GAAG,IAAI;AACP,YAAA,KAAK,EAAE,MAAM,CAAC,IAAI,CAChBA,YAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,CACrC;AACF,SAAA,CAAC,CAAA;KACH;AACF;;;;"}
|
|
@@ -20,12 +20,12 @@ class Database {
|
|
|
20
20
|
/**
|
|
21
21
|
* Get stored data from the database.
|
|
22
22
|
*/
|
|
23
|
-
async onLoadDocument(
|
|
24
|
-
const update = await this.configuration.fetch(
|
|
23
|
+
async onLoadDocument(data) {
|
|
24
|
+
const update = await this.configuration.fetch(data);
|
|
25
25
|
if (update) {
|
|
26
|
-
Y.applyUpdate(document, update);
|
|
26
|
+
Y.applyUpdate(data.document, update);
|
|
27
27
|
}
|
|
28
|
-
return document;
|
|
28
|
+
return data.document;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Store new updates in the database.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hocuspocus-database.esm.js","sources":["../src/Database.ts"],"sourcesContent":["import {\n Extension
|
|
1
|
+
{"version":3,"file":"hocuspocus-database.esm.js","sources":["../src/Database.ts"],"sourcesContent":["import {\n Extension,\n onChangePayload,\n onLoadDocumentPayload,\n storePayload,\n fetchPayload,\n} from '@hocuspocus/server'\nimport * as Y from 'yjs'\n\nexport interface DatabaseConfiguration {\n /**\n * Pass a Promise to retrieve updates from your database. The Promise should resolve to\n * an array of items with Y.js-compatible binary data.\n */\n fetch: (data: fetchPayload) => Promise<Uint8Array | null>,\n /**\n * Pass a function to store updates in your database.\n */\n store: (data: storePayload) => void,\n}\n\nexport class Database implements Extension {\n /**\n * Default configuration\n */\n configuration: DatabaseConfiguration = {\n fetch: async () => null,\n store: async () => null,\n }\n\n /**\n * Constructor\n */\n constructor(configuration: Partial<DatabaseConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n }\n\n /**\n * Get stored data from the database.\n */\n async onLoadDocument(data: onLoadDocumentPayload): Promise<any> {\n const update = await this.configuration.fetch(data)\n\n if (update) {\n Y.applyUpdate(data.document, update)\n }\n\n return data.document\n }\n\n /**\n * Store new updates in the database.\n */\n async onStoreDocument(data: onChangePayload) {\n return this.configuration.store({\n ...data,\n state: Buffer.from(\n Y.encodeStateAsUpdate(data.document),\n ),\n })\n }\n}\n"],"names":[],"mappings":";;MAqBa,QAAQ,CAAA;AASnB;;AAEG;AACH,IAAA,WAAA,CAAY,aAA6C,EAAA;AAXzD;;AAEG;AACH,QAAA,IAAA,CAAA,aAAa,GAA0B;AACrC,YAAA,KAAK,EAAE,YAAY,IAAI;AACvB,YAAA,KAAK,EAAE,YAAY,IAAI;SACxB,CAAA;QAMC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SACjB,CAAA;KACF;AAED;;AAEG;IACH,MAAM,cAAc,CAAC,IAA2B,EAAA;QAC9C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AAEnD,QAAA,IAAI,MAAM,EAAE;YACV,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;AACrC,SAAA;QAED,OAAO,IAAI,CAAC,QAAQ,CAAA;KACrB;AAED;;AAEG;IACH,MAAM,eAAe,CAAC,IAAqB,EAAA;AACzC,QAAA,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;AAC9B,YAAA,GAAG,IAAI;AACP,YAAA,KAAK,EAAE,MAAM,CAAC,IAAI,CAChB,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,CACrC;AACF,SAAA,CAAC,CAAA;KACH;AACF;;;;"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { Extension, onChangePayload, onLoadDocumentPayload, storePayload } from '@hocuspocus/server';
|
|
1
|
+
import { Extension, onChangePayload, onLoadDocumentPayload, storePayload, fetchPayload } from '@hocuspocus/server';
|
|
2
2
|
export interface DatabaseConfiguration {
|
|
3
3
|
/**
|
|
4
4
|
* Pass a Promise to retrieve updates from your database. The Promise should resolve to
|
|
5
5
|
* an array of items with Y.js-compatible binary data.
|
|
6
6
|
*/
|
|
7
|
-
fetch: (
|
|
8
|
-
documentName: string;
|
|
9
|
-
}) => Promise<Uint8Array | null>;
|
|
7
|
+
fetch: (data: fetchPayload) => Promise<Uint8Array | null>;
|
|
10
8
|
/**
|
|
11
9
|
* Pass a function to store updates in your database.
|
|
12
10
|
*/
|
|
@@ -24,7 +22,7 @@ export declare class Database implements Extension {
|
|
|
24
22
|
/**
|
|
25
23
|
* Get stored data from the database.
|
|
26
24
|
*/
|
|
27
|
-
onLoadDocument(
|
|
25
|
+
onLoadDocument(data: onLoadDocumentPayload): Promise<any>;
|
|
28
26
|
/**
|
|
29
27
|
* Store new updates in the database.
|
|
30
28
|
*/
|
|
@@ -50,11 +50,12 @@ export declare class Collector {
|
|
|
50
50
|
documents(): {};
|
|
51
51
|
info(): Promise<{
|
|
52
52
|
configuration: Partial<Configuration>;
|
|
53
|
-
ipAddress: string;
|
|
53
|
+
ipAddress: string | null;
|
|
54
54
|
nodeVersion: string;
|
|
55
55
|
platform: NodeJS.Platform;
|
|
56
56
|
started: string;
|
|
57
57
|
version: string;
|
|
58
58
|
}>;
|
|
59
|
+
private getIpAddress;
|
|
59
60
|
private static readableYDoc;
|
|
60
61
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import RedisClient from 'ioredis';
|
|
2
2
|
import Redlock from 'redlock';
|
|
3
|
-
import { Document, Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, Debugger, onConfigurePayload } from '@hocuspocus/server';
|
|
3
|
+
import { Document, Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, Debugger, onConfigurePayload, onListenPayload } from '@hocuspocus/server';
|
|
4
4
|
export interface Configuration {
|
|
5
5
|
/**
|
|
6
6
|
* Redis port
|
|
@@ -46,7 +46,7 @@ export declare class Redis implements Extension {
|
|
|
46
46
|
logger: Debugger;
|
|
47
47
|
constructor(configuration: Partial<Configuration>);
|
|
48
48
|
onConfigure({ instance }: onConfigurePayload): Promise<void>;
|
|
49
|
-
onListen(): Promise<void>;
|
|
49
|
+
onListen({ configuration }: onListenPayload): Promise<void>;
|
|
50
50
|
private getKey;
|
|
51
51
|
private pubKey;
|
|
52
52
|
private subKey;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
|
|
3
3
|
import { IncomingMessage, Server as HTTPServer } from 'http';
|
|
4
|
-
import { Configuration,
|
|
4
|
+
import { Configuration, HookName, HookPayload } from './types';
|
|
5
5
|
import Document from './Document';
|
|
6
6
|
import { Debugger } from './Debugger';
|
|
7
7
|
import { onListenPayload } from '.';
|
|
@@ -88,7 +88,7 @@ export declare class Hocuspocus {
|
|
|
88
88
|
* Run the given hook on all configured extensions.
|
|
89
89
|
* Runs the given callback after each hook.
|
|
90
90
|
*/
|
|
91
|
-
hooks(name:
|
|
91
|
+
hooks(name: HookName, payload: HookPayload, callback?: Function | null): Promise<any>;
|
|
92
92
|
/**
|
|
93
93
|
* Get parameters by the given request
|
|
94
94
|
*/
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http';
|
|
3
3
|
import { URLSearchParams } from 'url';
|
|
4
|
-
import { Socket } from 'net';
|
|
5
4
|
import { Awareness } from 'y-protocols/awareness';
|
|
6
5
|
import Document from './Document';
|
|
7
6
|
import { Hocuspocus } from './Hocuspocus';
|
|
@@ -44,11 +43,12 @@ export interface Extension {
|
|
|
44
43
|
onDisconnect?(data: onDisconnectPayload): Promise<any>;
|
|
45
44
|
onDestroy?(data: onDestroyPayload): Promise<any>;
|
|
46
45
|
}
|
|
47
|
-
export declare type
|
|
46
|
+
export declare type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' |
|
|
48
47
|
/**
|
|
49
48
|
* @deprecated onCreateDocument is deprecated, use onLoadDocument instead
|
|
50
49
|
*/
|
|
51
50
|
'onCreateDocument' | 'onLoadDocument' | 'afterLoadDocument' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'onDestroy';
|
|
51
|
+
export declare type HookPayload = onConfigurePayload | onListenPayload | onUpgradePayload | onConnectPayload | connectedPayload | onAuthenticatePayload | onLoadDocumentPayload | onChangePayload | onStoreDocumentPayload | afterStoreDocumentPayload | onAwarenessUpdatePayload | onRequestPayload | onDisconnectPayload | onDestroyPayload;
|
|
52
52
|
export interface Configuration extends Extension {
|
|
53
53
|
/**
|
|
54
54
|
* A name for the instance, used for logging.
|
|
@@ -179,6 +179,16 @@ export declare type StatesArray = {
|
|
|
179
179
|
clientId: number;
|
|
180
180
|
[key: string | number]: any;
|
|
181
181
|
}[];
|
|
182
|
+
export interface fetchPayload {
|
|
183
|
+
context: any;
|
|
184
|
+
document: Document;
|
|
185
|
+
documentName: string;
|
|
186
|
+
instance: Hocuspocus;
|
|
187
|
+
requestHeaders: IncomingHttpHeaders;
|
|
188
|
+
requestParameters: URLSearchParams;
|
|
189
|
+
socketId: string;
|
|
190
|
+
connection: ConnectionConfiguration;
|
|
191
|
+
}
|
|
182
192
|
export interface storePayload extends onStoreDocumentPayload {
|
|
183
193
|
state: Buffer;
|
|
184
194
|
}
|
|
@@ -198,19 +208,21 @@ export interface onRequestPayload {
|
|
|
198
208
|
instance: Hocuspocus;
|
|
199
209
|
}
|
|
200
210
|
export interface onUpgradePayload {
|
|
201
|
-
head: any;
|
|
202
211
|
request: IncomingMessage;
|
|
203
|
-
socket:
|
|
212
|
+
socket: any;
|
|
213
|
+
head: any;
|
|
204
214
|
instance: Hocuspocus;
|
|
205
215
|
}
|
|
206
216
|
export interface onListenPayload {
|
|
217
|
+
instance: Hocuspocus;
|
|
218
|
+
configuration: Configuration;
|
|
207
219
|
port: number;
|
|
208
220
|
}
|
|
209
221
|
export interface onDestroyPayload {
|
|
210
222
|
instance: Hocuspocus;
|
|
211
223
|
}
|
|
212
224
|
export interface onConfigurePayload {
|
|
225
|
+
instance: Hocuspocus;
|
|
213
226
|
configuration: Configuration;
|
|
214
227
|
version: string;
|
|
215
|
-
instance: Hocuspocus;
|
|
216
228
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,6 +2,7 @@ export * from './createDirectory';
|
|
|
2
2
|
export * from './flushRedis';
|
|
3
3
|
export * from './newHocuspocus';
|
|
4
4
|
export * from './newHocuspocusProvider';
|
|
5
|
+
export * from './randomInteger';
|
|
5
6
|
export * from './redisConnectionSettings';
|
|
6
7
|
export * from './removeDirectory';
|
|
7
8
|
export * from './sleep';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const randomInteger: (min: number, max: number) => number;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/extension-database",
|
|
3
3
|
"description": "a generic Hocuspocus persistence driver for the database",
|
|
4
|
-
"version": "1.0.0-alpha.
|
|
4
|
+
"version": "1.0.0-alpha.16",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"hocuspocus",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"type": "module",
|
|
12
|
-
"main": "dist/hocuspocus-database.
|
|
12
|
+
"main": "dist/hocuspocus-database.cjs",
|
|
13
13
|
"module": "dist/hocuspocus-database.esm.js",
|
|
14
14
|
"types": "dist/packages/extension-database/src/index.d.ts",
|
|
15
15
|
"exports": {
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@hocuspocus/server": "^1.0.0-alpha.
|
|
29
|
+
"@hocuspocus/server": "^1.0.0-alpha.102",
|
|
30
30
|
"yjs": "^13.5.29"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "450e12c89b027bc62683f151330a98074cd8e8fb"
|
|
36
36
|
}
|
package/src/Database.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Extension,
|
|
2
|
+
Extension,
|
|
3
|
+
onChangePayload,
|
|
4
|
+
onLoadDocumentPayload,
|
|
5
|
+
storePayload,
|
|
6
|
+
fetchPayload,
|
|
3
7
|
} from '@hocuspocus/server'
|
|
4
8
|
import * as Y from 'yjs'
|
|
5
9
|
|
|
@@ -8,7 +12,7 @@ export interface DatabaseConfiguration {
|
|
|
8
12
|
* Pass a Promise to retrieve updates from your database. The Promise should resolve to
|
|
9
13
|
* an array of items with Y.js-compatible binary data.
|
|
10
14
|
*/
|
|
11
|
-
fetch: (
|
|
15
|
+
fetch: (data: fetchPayload) => Promise<Uint8Array | null>,
|
|
12
16
|
/**
|
|
13
17
|
* Pass a function to store updates in your database.
|
|
14
18
|
*/
|
|
@@ -37,14 +41,14 @@ export class Database implements Extension {
|
|
|
37
41
|
/**
|
|
38
42
|
* Get stored data from the database.
|
|
39
43
|
*/
|
|
40
|
-
async onLoadDocument(
|
|
41
|
-
const update = await this.configuration.fetch(
|
|
44
|
+
async onLoadDocument(data: onLoadDocumentPayload): Promise<any> {
|
|
45
|
+
const update = await this.configuration.fetch(data)
|
|
42
46
|
|
|
43
47
|
if (update) {
|
|
44
|
-
Y.applyUpdate(document, update)
|
|
48
|
+
Y.applyUpdate(data.document, update)
|
|
45
49
|
}
|
|
46
50
|
|
|
47
|
-
return document
|
|
51
|
+
return data.document
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
/**
|