@hocuspocus/extension-database 2.6.0 → 2.7.0
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 +2 -2
- package/dist/hocuspocus-database.cjs.map +1 -1
- package/dist/hocuspocus-database.esm.js +2 -2
- package/dist/hocuspocus-database.esm.js.map +1 -1
- package/dist/packages/extension-database/src/Database.d.ts +1 -1
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +0 -1
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +4 -0
- package/dist/packages/provider/src/IncomingMessage.d.ts +1 -0
- package/dist/packages/server/src/DirectConnection.d.ts +1 -1
- package/dist/packages/server/src/Document.d.ts +2 -0
- package/dist/packages/server/src/Hocuspocus.d.ts +1 -1
- package/dist/packages/server/src/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/Database.ts +3 -3
|
@@ -34,7 +34,7 @@ class Database {
|
|
|
34
34
|
*/
|
|
35
35
|
this.configuration = {
|
|
36
36
|
fetch: async () => null,
|
|
37
|
-
store: async () =>
|
|
37
|
+
store: async () => { },
|
|
38
38
|
};
|
|
39
39
|
this.configuration = {
|
|
40
40
|
...this.configuration,
|
|
@@ -55,7 +55,7 @@ class Database {
|
|
|
55
55
|
* Store new updates in the database.
|
|
56
56
|
*/
|
|
57
57
|
async onStoreDocument(data) {
|
|
58
|
-
|
|
58
|
+
await this.configuration.store({
|
|
59
59
|
...data,
|
|
60
60
|
state: Buffer.from(Y__namespace.encodeStateAsUpdate(data.document)),
|
|
61
61
|
});
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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) => Promise<void>,\n}\n\nexport class Database implements Extension {\n /**\n * Default configuration\n */\n configuration: DatabaseConfiguration = {\n fetch: async () => null,\n store: async () => {},\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 await 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,eAAc;SACtB,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,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;AAC7B,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;;;;"}
|
|
@@ -10,7 +10,7 @@ class Database {
|
|
|
10
10
|
*/
|
|
11
11
|
this.configuration = {
|
|
12
12
|
fetch: async () => null,
|
|
13
|
-
store: async () =>
|
|
13
|
+
store: async () => { },
|
|
14
14
|
};
|
|
15
15
|
this.configuration = {
|
|
16
16
|
...this.configuration,
|
|
@@ -31,7 +31,7 @@ class Database {
|
|
|
31
31
|
* Store new updates in the database.
|
|
32
32
|
*/
|
|
33
33
|
async onStoreDocument(data) {
|
|
34
|
-
|
|
34
|
+
await this.configuration.store({
|
|
35
35
|
...data,
|
|
36
36
|
state: Buffer.from(Y.encodeStateAsUpdate(data.document)),
|
|
37
37
|
});
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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) => Promise<void>,\n}\n\nexport class Database implements Extension {\n /**\n * Default configuration\n */\n configuration: DatabaseConfiguration = {\n fetch: async () => null,\n store: async () => {},\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 await 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,eAAc;SACtB,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,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;AAC7B,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;;;;"}
|
|
@@ -8,7 +8,7 @@ export interface DatabaseConfiguration {
|
|
|
8
8
|
/**
|
|
9
9
|
* Pass a function to store updates in your database.
|
|
10
10
|
*/
|
|
11
|
-
store: (data: storePayload) => void
|
|
11
|
+
store: (data: storePayload) => Promise<void>;
|
|
12
12
|
}
|
|
13
13
|
export declare class Database implements Extension {
|
|
14
14
|
/**
|
|
@@ -91,7 +91,6 @@ export declare class HocuspocusProvider extends EventEmitter {
|
|
|
91
91
|
boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
|
|
92
92
|
boundPageUnload: () => void;
|
|
93
93
|
boundOnOpen: (event: Event) => Promise<void>;
|
|
94
|
-
boundOnMessage: (event: MessageEvent) => void;
|
|
95
94
|
boundOnClose: (event: CloseEvent) => void;
|
|
96
95
|
boundOnStatus: ({ status }: onStatusParameters) => void;
|
|
97
96
|
forwardConnect: (e: any) => this;
|
|
@@ -77,6 +77,10 @@ export interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
|
77
77
|
* Don’t output any warnings.
|
|
78
78
|
*/
|
|
79
79
|
quiet: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Map of attached providers keyed by documentName.
|
|
82
|
+
*/
|
|
83
|
+
providerMap: Map<string, HocuspocusProvider>;
|
|
80
84
|
}
|
|
81
85
|
export declare class HocuspocusProviderWebsocket extends EventEmitter {
|
|
82
86
|
private messageQueue;
|
|
@@ -10,5 +10,5 @@ export declare class DirectConnection implements DirectConnectionInterface {
|
|
|
10
10
|
*/
|
|
11
11
|
constructor(document: Document, instance: Hocuspocus, context?: any);
|
|
12
12
|
transact(transaction: (document: Document) => void, transactionOrigin?: any): Promise<void>;
|
|
13
|
-
disconnect(): void
|
|
13
|
+
disconnect(): Promise<void>;
|
|
14
14
|
}
|
|
@@ -19,6 +19,7 @@ export declare class Document extends Doc {
|
|
|
19
19
|
mux: mutex;
|
|
20
20
|
logger: Debugger;
|
|
21
21
|
isLoading: boolean;
|
|
22
|
+
isDestroyed: boolean;
|
|
22
23
|
/**
|
|
23
24
|
* Constructor.
|
|
24
25
|
*/
|
|
@@ -87,5 +88,6 @@ export declare class Document extends Doc {
|
|
|
87
88
|
* Broadcast stateless message to all connections
|
|
88
89
|
*/
|
|
89
90
|
broadcastStateless(payload: string): void;
|
|
91
|
+
destroy(): void;
|
|
90
92
|
}
|
|
91
93
|
export default Document;
|
|
@@ -82,7 +82,7 @@ export declare class Hocuspocus {
|
|
|
82
82
|
* Create a new document by the given request
|
|
83
83
|
*/
|
|
84
84
|
createDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document>;
|
|
85
|
-
storeDocumentHooks(document: Document, hookPayload: onStoreDocumentPayload): void
|
|
85
|
+
storeDocumentHooks(document: Document, hookPayload: onStoreDocumentPayload): Promise<void>;
|
|
86
86
|
/**
|
|
87
87
|
* Run the given hook on all configured extensions.
|
|
88
88
|
* Runs the given callback after each hook.
|
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": "2.
|
|
4
|
+
"version": "2.7.0",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"hocuspocus",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@hocuspocus/server": "^2.
|
|
30
|
+
"@hocuspocus/server": "^2.7.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"yjs": "^13.6.4"
|
package/src/Database.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface DatabaseConfiguration {
|
|
|
16
16
|
/**
|
|
17
17
|
* Pass a function to store updates in your database.
|
|
18
18
|
*/
|
|
19
|
-
store: (data: storePayload) => void
|
|
19
|
+
store: (data: storePayload) => Promise<void>,
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export class Database implements Extension {
|
|
@@ -25,7 +25,7 @@ export class Database implements Extension {
|
|
|
25
25
|
*/
|
|
26
26
|
configuration: DatabaseConfiguration = {
|
|
27
27
|
fetch: async () => null,
|
|
28
|
-
store: async () =>
|
|
28
|
+
store: async () => {},
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -55,7 +55,7 @@ export class Database implements Extension {
|
|
|
55
55
|
* Store new updates in the database.
|
|
56
56
|
*/
|
|
57
57
|
async onStoreDocument(data: onChangePayload) {
|
|
58
|
-
|
|
58
|
+
await this.configuration.store({
|
|
59
59
|
...data,
|
|
60
60
|
state: Buffer.from(
|
|
61
61
|
Y.encodeStateAsUpdate(data.document),
|