@hocuspocus/extension-sqlite 2.0.0-beta.0 → 2.0.1
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/README.md +2 -2
- package/dist/hocuspocus-sqlite.cjs +6 -3
- package/dist/hocuspocus-sqlite.cjs.map +1 -1
- package/dist/hocuspocus-sqlite.esm.js +6 -3
- package/dist/hocuspocus-sqlite.esm.js.map +1 -1
- package/dist/packages/extension-monitor/src/Dashboard.d.ts +1 -0
- package/dist/packages/extension-redis/src/Redis.d.ts +1 -1
- package/dist/packages/provider/src/HocuspocusCloudProvider.d.ts +1 -1
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +1 -1
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +1 -1
- package/dist/packages/provider/src/TiptapCollabProvider.d.ts +11 -0
- package/dist/packages/provider/src/index.d.ts +1 -1
- package/dist/packages/provider/src/types.d.ts +13 -13
- package/dist/packages/server/src/Connection.d.ts +2 -1
- package/dist/packages/server/src/Hocuspocus.d.ts +1 -0
- package/dist/packages/server/src/types.d.ts +5 -3
- package/dist/tests/utils/newHocuspocus.d.ts +1 -1
- package/package.json +2 -2
- package/src/SQLite.ts +8 -4
package/README.md
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
[](https://github.com/sponsors/ueberdosis)
|
|
6
6
|
|
|
7
7
|
## Introduction
|
|
8
|
-
|
|
8
|
+
Hocuspocus is an opinionated collaborative editing backend for [Tiptap](https://github.com/ueberdosis/tiptap) – based on [Y.js](https://github.com/yjs/yjs), a CRDT framework with a powerful abstraction of shared data.
|
|
9
9
|
|
|
10
10
|
## Offical Documentation
|
|
11
11
|
Documentation can be found in the [GitHub repository](https://github.com/ueberdosis/hocuspocus).
|
|
12
12
|
|
|
13
13
|
## License
|
|
14
|
-
|
|
14
|
+
Hocuspocus is open-sourced software licensed under the [MIT license](https://github.com/ueberdosis/hocuspocus/blob/main/LICENSE.md).
|
|
@@ -23,11 +23,12 @@ const upsertQuery = `
|
|
|
23
23
|
INSERT INTO "documents" ("name", "data") VALUES ($name, $data)
|
|
24
24
|
ON CONFLICT(name) DO UPDATE SET data = $data
|
|
25
25
|
`;
|
|
26
|
+
const SQLITE_INMEMORY = ':memory:';
|
|
26
27
|
class SQLite extends extensionDatabase.Database {
|
|
27
28
|
constructor(configuration) {
|
|
28
29
|
super({});
|
|
29
30
|
this.configuration = {
|
|
30
|
-
database:
|
|
31
|
+
database: SQLITE_INMEMORY,
|
|
31
32
|
schema,
|
|
32
33
|
fetch: async ({ documentName }) => {
|
|
33
34
|
return new Promise((resolve, reject) => {
|
|
@@ -60,8 +61,10 @@ class SQLite extends extensionDatabase.Database {
|
|
|
60
61
|
this.db.run(this.configuration.schema);
|
|
61
62
|
}
|
|
62
63
|
async onListen() {
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
if (this.configuration.database === SQLITE_INMEMORY) {
|
|
65
|
+
console.warn(` ${kleur__default["default"].yellow('The SQLite extension is configured as an in-memory database. All changes will be lost on restart!')}`);
|
|
66
|
+
console.log();
|
|
67
|
+
}
|
|
65
68
|
}
|
|
66
69
|
}
|
|
67
70
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hocuspocus-sqlite.cjs","sources":["../src/SQLite.ts"],"sourcesContent":["import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database'\nimport sqlite3 from 'sqlite3'\nimport kleur from 'kleur'\n\nexport const schema = `CREATE TABLE IF NOT EXISTS \"documents\" (\n \"name\" varchar(255) NOT NULL,\n \"data\" blob NOT NULL,\n UNIQUE(name)\n)`\n\nexport const selectQuery = `\n SELECT data FROM \"documents\" WHERE name = $name ORDER BY rowid DESC\n`\n\nexport const upsertQuery = `\n INSERT INTO \"documents\" (\"name\", \"data\") VALUES ($name, $data)\n ON CONFLICT(name) DO UPDATE SET data = $data\n`\n\nexport interface SQLiteConfiguration extends DatabaseConfiguration {\n /**\n * Valid values are filenames, \":memory:\" for an anonymous in-memory database and an empty\n * string for an anonymous disk-based database. Anonymous databases are not persisted and\n * when closing the database handle, their contents are lost.\n *\n * https://github.com/mapbox/node-sqlite3/wiki/API#new-sqlite3databasefilename-mode-callback\n */\n database: string,\n /**\n * The database schema to create.\n */\n schema: string,\n}\n\nexport class SQLite extends Database {\n db?: sqlite3.Database\n\n configuration: SQLiteConfiguration = {\n database:
|
|
1
|
+
{"version":3,"file":"hocuspocus-sqlite.cjs","sources":["../src/SQLite.ts"],"sourcesContent":["import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database'\nimport sqlite3 from 'sqlite3'\nimport kleur from 'kleur'\n\nexport const schema = `CREATE TABLE IF NOT EXISTS \"documents\" (\n \"name\" varchar(255) NOT NULL,\n \"data\" blob NOT NULL,\n UNIQUE(name)\n)`\n\nexport const selectQuery = `\n SELECT data FROM \"documents\" WHERE name = $name ORDER BY rowid DESC\n`\n\nexport const upsertQuery = `\n INSERT INTO \"documents\" (\"name\", \"data\") VALUES ($name, $data)\n ON CONFLICT(name) DO UPDATE SET data = $data\n`\n\nconst SQLITE_INMEMORY = ':memory:'\n\nexport interface SQLiteConfiguration extends DatabaseConfiguration {\n /**\n * Valid values are filenames, \":memory:\" for an anonymous in-memory database and an empty\n * string for an anonymous disk-based database. Anonymous databases are not persisted and\n * when closing the database handle, their contents are lost.\n *\n * https://github.com/mapbox/node-sqlite3/wiki/API#new-sqlite3databasefilename-mode-callback\n */\n database: string,\n /**\n * The database schema to create.\n */\n schema: string,\n}\n\nexport class SQLite extends Database {\n db?: sqlite3.Database\n\n configuration: SQLiteConfiguration = {\n database: SQLITE_INMEMORY,\n schema,\n fetch: async ({ documentName }) => {\n return new Promise((resolve, reject) => {\n this.db?.get(selectQuery, {\n $name: documentName,\n }, (error, row) => {\n if (error) {\n reject(error)\n }\n\n resolve((row as any)?.data)\n })\n })\n },\n store: async ({ documentName, state }) => {\n this.db?.run(upsertQuery, {\n $name: documentName,\n $data: state,\n })\n },\n }\n\n constructor(configuration?: Partial<SQLiteConfiguration>) {\n super({})\n\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n }\n\n async onConfigure() {\n this.db = new sqlite3.Database(this.configuration.database)\n this.db.run(this.configuration.schema)\n }\n\n async onListen() {\n if (this.configuration.database === SQLITE_INMEMORY) {\n console.warn(` ${kleur.yellow('The SQLite extension is configured as an in-memory database. All changes will be lost on restart!')}`)\n console.log()\n }\n }\n}\n"],"names":["Database","sqlite3","kleur"],"mappings":";;;;;;;;;;;;;AAIa,MAAA,MAAM,GAAG,CAAA;;;;GAIpB;AAEW,MAAA,WAAW,GAAG,CAAA;;EAE1B;AAEY,MAAA,WAAW,GAAG,CAAA;;;EAG1B;AAED,MAAM,eAAe,GAAG,UAAU,CAAA;AAiB5B,MAAO,MAAO,SAAQA,0BAAQ,CAAA;AA2BlC,IAAA,WAAA,CAAY,aAA4C,EAAA;QACtD,KAAK,CAAC,EAAE,CAAC,CAAA;AAzBX,QAAA,IAAA,CAAA,aAAa,GAAwB;AACnC,YAAA,QAAQ,EAAE,eAAe;YACzB,MAAM;AACN,YAAA,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,KAAI;gBAChC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;;AACrC,oBAAA,CAAA,EAAA,GAAA,IAAI,CAAC,EAAE,0CAAE,GAAG,CAAC,WAAW,EAAE;AACxB,wBAAA,KAAK,EAAE,YAAY;AACpB,qBAAA,EAAE,CAAC,KAAK,EAAE,GAAG,KAAI;AAChB,wBAAA,IAAI,KAAK,EAAE;4BACT,MAAM,CAAC,KAAK,CAAC,CAAA;AACd,yBAAA;wBAED,OAAO,CAAE,GAAW,KAAX,IAAA,IAAA,GAAG,uBAAH,GAAG,CAAU,IAAI,CAAC,CAAA;AAC7B,qBAAC,CAAC,CAAA;AACJ,iBAAC,CAAC,CAAA;aACH;YACD,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,KAAI;;AACvC,gBAAA,CAAA,EAAA,GAAA,IAAI,CAAC,EAAE,0CAAE,GAAG,CAAC,WAAW,EAAE;AACxB,oBAAA,KAAK,EAAE,YAAY;AACnB,oBAAA,KAAK,EAAE,KAAK;AACb,iBAAA,CAAC,CAAA;aACH;SACF,CAAA;QAKC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SACjB,CAAA;KACF;AAED,IAAA,MAAM,WAAW,GAAA;AACf,QAAA,IAAI,CAAC,EAAE,GAAG,IAAIC,2BAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;QAC3D,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;KACvC;AAED,IAAA,MAAM,QAAQ,GAAA;AACZ,QAAA,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,KAAK,eAAe,EAAE;AACnD,YAAA,OAAO,CAAC,IAAI,CAAC,CAAA,EAAA,EAAKC,yBAAK,CAAC,MAAM,CAAC,mGAAmG,CAAC,CAAE,CAAA,CAAC,CAAA;YACtI,OAAO,CAAC,GAAG,EAAE,CAAA;AACd,SAAA;KACF;AACF;;;;;;;"}
|
|
@@ -14,11 +14,12 @@ const upsertQuery = `
|
|
|
14
14
|
INSERT INTO "documents" ("name", "data") VALUES ($name, $data)
|
|
15
15
|
ON CONFLICT(name) DO UPDATE SET data = $data
|
|
16
16
|
`;
|
|
17
|
+
const SQLITE_INMEMORY = ':memory:';
|
|
17
18
|
class SQLite extends Database {
|
|
18
19
|
constructor(configuration) {
|
|
19
20
|
super({});
|
|
20
21
|
this.configuration = {
|
|
21
|
-
database:
|
|
22
|
+
database: SQLITE_INMEMORY,
|
|
22
23
|
schema,
|
|
23
24
|
fetch: async ({ documentName }) => {
|
|
24
25
|
return new Promise((resolve, reject) => {
|
|
@@ -51,8 +52,10 @@ class SQLite extends Database {
|
|
|
51
52
|
this.db.run(this.configuration.schema);
|
|
52
53
|
}
|
|
53
54
|
async onListen() {
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
if (this.configuration.database === SQLITE_INMEMORY) {
|
|
56
|
+
console.warn(` ${kleur.yellow('The SQLite extension is configured as an in-memory database. All changes will be lost on restart!')}`);
|
|
57
|
+
console.log();
|
|
58
|
+
}
|
|
56
59
|
}
|
|
57
60
|
}
|
|
58
61
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hocuspocus-sqlite.esm.js","sources":["../src/SQLite.ts"],"sourcesContent":["import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database'\nimport sqlite3 from 'sqlite3'\nimport kleur from 'kleur'\n\nexport const schema = `CREATE TABLE IF NOT EXISTS \"documents\" (\n \"name\" varchar(255) NOT NULL,\n \"data\" blob NOT NULL,\n UNIQUE(name)\n)`\n\nexport const selectQuery = `\n SELECT data FROM \"documents\" WHERE name = $name ORDER BY rowid DESC\n`\n\nexport const upsertQuery = `\n INSERT INTO \"documents\" (\"name\", \"data\") VALUES ($name, $data)\n ON CONFLICT(name) DO UPDATE SET data = $data\n`\n\nexport interface SQLiteConfiguration extends DatabaseConfiguration {\n /**\n * Valid values are filenames, \":memory:\" for an anonymous in-memory database and an empty\n * string for an anonymous disk-based database. Anonymous databases are not persisted and\n * when closing the database handle, their contents are lost.\n *\n * https://github.com/mapbox/node-sqlite3/wiki/API#new-sqlite3databasefilename-mode-callback\n */\n database: string,\n /**\n * The database schema to create.\n */\n schema: string,\n}\n\nexport class SQLite extends Database {\n db?: sqlite3.Database\n\n configuration: SQLiteConfiguration = {\n database:
|
|
1
|
+
{"version":3,"file":"hocuspocus-sqlite.esm.js","sources":["../src/SQLite.ts"],"sourcesContent":["import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database'\nimport sqlite3 from 'sqlite3'\nimport kleur from 'kleur'\n\nexport const schema = `CREATE TABLE IF NOT EXISTS \"documents\" (\n \"name\" varchar(255) NOT NULL,\n \"data\" blob NOT NULL,\n UNIQUE(name)\n)`\n\nexport const selectQuery = `\n SELECT data FROM \"documents\" WHERE name = $name ORDER BY rowid DESC\n`\n\nexport const upsertQuery = `\n INSERT INTO \"documents\" (\"name\", \"data\") VALUES ($name, $data)\n ON CONFLICT(name) DO UPDATE SET data = $data\n`\n\nconst SQLITE_INMEMORY = ':memory:'\n\nexport interface SQLiteConfiguration extends DatabaseConfiguration {\n /**\n * Valid values are filenames, \":memory:\" for an anonymous in-memory database and an empty\n * string for an anonymous disk-based database. Anonymous databases are not persisted and\n * when closing the database handle, their contents are lost.\n *\n * https://github.com/mapbox/node-sqlite3/wiki/API#new-sqlite3databasefilename-mode-callback\n */\n database: string,\n /**\n * The database schema to create.\n */\n schema: string,\n}\n\nexport class SQLite extends Database {\n db?: sqlite3.Database\n\n configuration: SQLiteConfiguration = {\n database: SQLITE_INMEMORY,\n schema,\n fetch: async ({ documentName }) => {\n return new Promise((resolve, reject) => {\n this.db?.get(selectQuery, {\n $name: documentName,\n }, (error, row) => {\n if (error) {\n reject(error)\n }\n\n resolve((row as any)?.data)\n })\n })\n },\n store: async ({ documentName, state }) => {\n this.db?.run(upsertQuery, {\n $name: documentName,\n $data: state,\n })\n },\n }\n\n constructor(configuration?: Partial<SQLiteConfiguration>) {\n super({})\n\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n }\n\n async onConfigure() {\n this.db = new sqlite3.Database(this.configuration.database)\n this.db.run(this.configuration.schema)\n }\n\n async onListen() {\n if (this.configuration.database === SQLITE_INMEMORY) {\n console.warn(` ${kleur.yellow('The SQLite extension is configured as an in-memory database. All changes will be lost on restart!')}`)\n console.log()\n }\n }\n}\n"],"names":[],"mappings":";;;;AAIa,MAAA,MAAM,GAAG,CAAA;;;;GAIpB;AAEW,MAAA,WAAW,GAAG,CAAA;;EAE1B;AAEY,MAAA,WAAW,GAAG,CAAA;;;EAG1B;AAED,MAAM,eAAe,GAAG,UAAU,CAAA;AAiB5B,MAAO,MAAO,SAAQ,QAAQ,CAAA;AA2BlC,IAAA,WAAA,CAAY,aAA4C,EAAA;QACtD,KAAK,CAAC,EAAE,CAAC,CAAA;AAzBX,QAAA,IAAA,CAAA,aAAa,GAAwB;AACnC,YAAA,QAAQ,EAAE,eAAe;YACzB,MAAM;AACN,YAAA,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,KAAI;gBAChC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;;AACrC,oBAAA,CAAA,EAAA,GAAA,IAAI,CAAC,EAAE,0CAAE,GAAG,CAAC,WAAW,EAAE;AACxB,wBAAA,KAAK,EAAE,YAAY;AACpB,qBAAA,EAAE,CAAC,KAAK,EAAE,GAAG,KAAI;AAChB,wBAAA,IAAI,KAAK,EAAE;4BACT,MAAM,CAAC,KAAK,CAAC,CAAA;AACd,yBAAA;wBAED,OAAO,CAAE,GAAW,KAAX,IAAA,IAAA,GAAG,uBAAH,GAAG,CAAU,IAAI,CAAC,CAAA;AAC7B,qBAAC,CAAC,CAAA;AACJ,iBAAC,CAAC,CAAA;aACH;YACD,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,KAAI;;AACvC,gBAAA,CAAA,EAAA,GAAA,IAAI,CAAC,EAAE,0CAAE,GAAG,CAAC,WAAW,EAAE;AACxB,oBAAA,KAAK,EAAE,YAAY;AACnB,oBAAA,KAAK,EAAE,KAAK;AACb,iBAAA,CAAC,CAAA;aACH;SACF,CAAA;QAKC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SACjB,CAAA;KACF;AAED,IAAA,MAAM,WAAW,GAAA;AACf,QAAA,IAAI,CAAC,EAAE,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;QAC3D,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;KACvC;AAED,IAAA,MAAM,QAAQ,GAAA;AACZ,QAAA,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,KAAK,eAAe,EAAE;AACnD,YAAA,OAAO,CAAC,IAAI,CAAC,CAAA,EAAA,EAAK,KAAK,CAAC,MAAM,CAAC,mGAAmG,CAAC,CAAE,CAAA,CAAC,CAAA;YACtI,OAAO,CAAC,GAAG,EAAE,CAAA;AACd,SAAA;KACF;AACF;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import RedisClient, { ClusterNode, ClusterOptions, RedisOptions } from 'ioredis';
|
|
2
2
|
import Redlock from 'redlock';
|
|
3
3
|
import { Document, Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, onChangePayload, Debugger, onConfigurePayload, onListenPayload, beforeBroadcastStatelessPayload } from '@hocuspocus/server';
|
|
4
|
-
export
|
|
4
|
+
export type RedisInstance = RedisClient.Cluster | RedisClient.Redis;
|
|
5
5
|
export interface Configuration {
|
|
6
6
|
/**
|
|
7
7
|
* Redis port
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HocuspocusProvider, HocuspocusProviderConfiguration } from './HocuspocusProvider';
|
|
2
2
|
import { HocuspocusProviderWebsocketConfiguration } from './HocuspocusProviderWebsocket';
|
|
3
|
-
export
|
|
3
|
+
export type HocuspocusCloudProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & Partial<Pick<HocuspocusProviderWebsocketConfiguration, 'url'>> & AdditionalHocuspocusCloudProviderConfiguration;
|
|
4
4
|
export interface AdditionalHocuspocusCloudProviderConfiguration {
|
|
5
5
|
/**
|
|
6
6
|
* A Hocuspocus Cloud key, get one here: https://hocuspocus.cloud/
|
|
@@ -6,7 +6,7 @@ import EventEmitter from './EventEmitter';
|
|
|
6
6
|
import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
|
|
7
7
|
import { CompleteHocuspocusProviderWebsocketConfiguration, HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket';
|
|
8
8
|
import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
|
|
9
|
-
export
|
|
9
|
+
export type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'name'>> & Partial<CompleteHocuspocusProviderConfiguration> & (Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> | Required<Pick<CompleteHocuspocusProviderConfiguration, 'websocketProvider'>>);
|
|
10
10
|
export interface CompleteHocuspocusProviderConfiguration {
|
|
11
11
|
/**
|
|
12
12
|
* The identifier/name of your document
|
|
@@ -4,7 +4,7 @@ import { Event } from 'ws';
|
|
|
4
4
|
import EventEmitter from './EventEmitter';
|
|
5
5
|
import { onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, WebSocketStatus } from './types';
|
|
6
6
|
import { HocuspocusProvider, onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
|
|
7
|
-
export
|
|
7
|
+
export type HocuspocusProviderWebsocketConfiguration = Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> & Partial<CompleteHocuspocusProviderWebsocketConfiguration>;
|
|
8
8
|
export interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
9
9
|
/**
|
|
10
10
|
* URL of your @hocuspocus/server instance
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HocuspocusProvider, HocuspocusProviderConfiguration } from './HocuspocusProvider';
|
|
2
|
+
export type TiptapCollabProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & AdditionalTiptapCollabProviderConfiguration;
|
|
3
|
+
export interface AdditionalTiptapCollabProviderConfiguration {
|
|
4
|
+
/**
|
|
5
|
+
* A Hocuspocus Cloud App ID, get one here: https://collab.tiptap.dev
|
|
6
|
+
*/
|
|
7
|
+
appId: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class TiptapCollabProvider extends HocuspocusProvider {
|
|
10
|
+
constructor(configuration: TiptapCollabProviderConfiguration);
|
|
11
|
+
}
|
|
@@ -43,42 +43,42 @@ export interface OutgoingMessageArguments {
|
|
|
43
43
|
export interface Constructable<T> {
|
|
44
44
|
new (...args: any): T;
|
|
45
45
|
}
|
|
46
|
-
export
|
|
47
|
-
export
|
|
46
|
+
export type ConstructableOutgoingMessage = Constructable<AuthenticationMessage> | Constructable<AwarenessMessage> | Constructable<QueryAwarenessMessage> | Constructable<SyncStepOneMessage> | Constructable<SyncStepTwoMessage> | Constructable<UpdateMessage>;
|
|
47
|
+
export type onAuthenticationFailedParameters = {
|
|
48
48
|
reason: string;
|
|
49
49
|
};
|
|
50
|
-
export
|
|
50
|
+
export type onOpenParameters = {
|
|
51
51
|
event: Event;
|
|
52
52
|
};
|
|
53
|
-
export
|
|
53
|
+
export type onMessageParameters = {
|
|
54
54
|
event: MessageEvent;
|
|
55
55
|
message: IncomingMessage;
|
|
56
56
|
};
|
|
57
|
-
export
|
|
57
|
+
export type onOutgoingMessageParameters = {
|
|
58
58
|
message: OutgoingMessage;
|
|
59
59
|
};
|
|
60
|
-
export
|
|
60
|
+
export type onStatusParameters = {
|
|
61
61
|
status: WebSocketStatus;
|
|
62
62
|
};
|
|
63
|
-
export
|
|
63
|
+
export type onSyncedParameters = {
|
|
64
64
|
state: boolean;
|
|
65
65
|
};
|
|
66
|
-
export
|
|
66
|
+
export type onDisconnectParameters = {
|
|
67
67
|
event: CloseEvent;
|
|
68
68
|
};
|
|
69
|
-
export
|
|
69
|
+
export type onCloseParameters = {
|
|
70
70
|
event: CloseEvent;
|
|
71
71
|
};
|
|
72
|
-
export
|
|
72
|
+
export type onAwarenessUpdateParameters = {
|
|
73
73
|
states: StatesArray;
|
|
74
74
|
};
|
|
75
|
-
export
|
|
75
|
+
export type onAwarenessChangeParameters = {
|
|
76
76
|
states: StatesArray;
|
|
77
77
|
};
|
|
78
|
-
export
|
|
78
|
+
export type onStatelessParameters = {
|
|
79
79
|
payload: string;
|
|
80
80
|
};
|
|
81
|
-
export
|
|
81
|
+
export type StatesArray = {
|
|
82
82
|
clientId: number;
|
|
83
83
|
[key: string | number]: any;
|
|
84
84
|
}[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { IncomingMessage as HTTPIncomingMessage } from 'http';
|
|
3
4
|
import AsyncLock from 'async-lock';
|
|
4
5
|
import WebSocket from 'ws';
|
|
@@ -23,7 +24,7 @@ export declare class Connection {
|
|
|
23
24
|
* Constructor.
|
|
24
25
|
*/
|
|
25
26
|
constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, timeout: number, socketId: string, context: any, readOnly: boolean | undefined, logger: Debugger);
|
|
26
|
-
boundClose: (event?: CloseEvent
|
|
27
|
+
boundClose: (event?: CloseEvent) => void;
|
|
27
28
|
boundHandleMessage: (data: Uint8Array) => void;
|
|
28
29
|
boundHandlePong: () => void;
|
|
29
30
|
handlePong(): void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { IncomingMessage, Server as HTTPServer } from 'http';
|
|
3
4
|
import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
|
|
4
5
|
import { Configuration, HookName, HookPayload, onListenPayload } from './types';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
2
4
|
import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http';
|
|
3
5
|
import { URLSearchParams } from 'url';
|
|
4
6
|
import { Awareness } from 'y-protocols/awareness';
|
|
@@ -47,8 +49,8 @@ export interface Extension {
|
|
|
47
49
|
onDisconnect?(data: onDisconnectPayload): Promise<any>;
|
|
48
50
|
onDestroy?(data: onDestroyPayload): Promise<any>;
|
|
49
51
|
}
|
|
50
|
-
export
|
|
51
|
-
export
|
|
52
|
+
export type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'beforeBroadcastStateless' | 'onStateless' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'onDestroy';
|
|
53
|
+
export type HookPayload = onConfigurePayload | onListenPayload | onUpgradePayload | onConnectPayload | connectedPayload | onAuthenticatePayload | onLoadDocumentPayload | onStatelessPayload | beforeHandleMessagePayload | beforeBroadcastStatelessPayload | onChangePayload | onStoreDocumentPayload | afterStoreDocumentPayload | onAwarenessUpdatePayload | onRequestPayload | onDisconnectPayload | onDestroyPayload;
|
|
52
54
|
export interface Configuration extends Extension {
|
|
53
55
|
/**
|
|
54
56
|
* A name for the instance, used for logging.
|
|
@@ -208,7 +210,7 @@ export interface onAwarenessUpdatePayload {
|
|
|
208
210
|
awareness: Awareness;
|
|
209
211
|
states: StatesArray;
|
|
210
212
|
}
|
|
211
|
-
export
|
|
213
|
+
export type StatesArray = {
|
|
212
214
|
clientId: number;
|
|
213
215
|
[key: string | number]: any;
|
|
214
216
|
}[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Hocuspocus, Configuration } from '@hocuspocus/server';
|
|
2
|
-
export declare const newHocuspocus: (options?: Partial<Configuration>
|
|
2
|
+
export declare const newHocuspocus: (options?: Partial<Configuration>) => Promise<Hocuspocus>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/extension-sqlite",
|
|
3
3
|
"description": "a generic Hocuspocus persistence driver for the sqlite",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"hocuspocus",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@hocuspocus/extension-database": "^2.0.
|
|
29
|
+
"@hocuspocus/extension-database": "^2.0.1",
|
|
30
30
|
"kleur": "^4.1.4",
|
|
31
31
|
"sqlite3": "^5.0.11"
|
|
32
32
|
},
|
package/src/SQLite.ts
CHANGED
|
@@ -17,6 +17,8 @@ export const upsertQuery = `
|
|
|
17
17
|
ON CONFLICT(name) DO UPDATE SET data = $data
|
|
18
18
|
`
|
|
19
19
|
|
|
20
|
+
const SQLITE_INMEMORY = ':memory:'
|
|
21
|
+
|
|
20
22
|
export interface SQLiteConfiguration extends DatabaseConfiguration {
|
|
21
23
|
/**
|
|
22
24
|
* Valid values are filenames, ":memory:" for an anonymous in-memory database and an empty
|
|
@@ -36,7 +38,7 @@ export class SQLite extends Database {
|
|
|
36
38
|
db?: sqlite3.Database
|
|
37
39
|
|
|
38
40
|
configuration: SQLiteConfiguration = {
|
|
39
|
-
database:
|
|
41
|
+
database: SQLITE_INMEMORY,
|
|
40
42
|
schema,
|
|
41
43
|
fetch: async ({ documentName }) => {
|
|
42
44
|
return new Promise((resolve, reject) => {
|
|
@@ -47,7 +49,7 @@ export class SQLite extends Database {
|
|
|
47
49
|
reject(error)
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
resolve(row?.data)
|
|
52
|
+
resolve((row as any)?.data)
|
|
51
53
|
})
|
|
52
54
|
})
|
|
53
55
|
},
|
|
@@ -74,7 +76,9 @@ export class SQLite extends Database {
|
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
async onListen() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
if (this.configuration.database === SQLITE_INMEMORY) {
|
|
80
|
+
console.warn(` ${kleur.yellow('The SQLite extension is configured as an in-memory database. All changes will be lost on restart!')}`)
|
|
81
|
+
console.log()
|
|
82
|
+
}
|
|
79
83
|
}
|
|
80
84
|
}
|