@hocuspocus/extension-sqlite 1.0.0-alpha.2 → 1.0.0-alpha.21
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 +1 -1
- package/dist/hocuspocus-sqlite.cjs +29 -20
- package/dist/hocuspocus-sqlite.cjs.map +1 -1
- package/dist/hocuspocus-sqlite.esm.js +26 -20
- package/dist/hocuspocus-sqlite.esm.js.map +1 -1
- package/dist/packages/common/src/CloseEvents.d.ts +23 -0
- package/dist/packages/common/src/awarenessStatesToArray.d.ts +3 -0
- package/dist/packages/common/src/index.d.ts +3 -0
- package/dist/packages/common/src/types.d.ts +10 -0
- package/dist/packages/extension-database/src/Database.d.ts +5 -11
- package/dist/packages/extension-logger/src/Logger.d.ts +5 -0
- package/dist/packages/extension-monitor/src/Collector.d.ts +2 -3
- package/dist/packages/extension-monitor/src/index.d.ts +2 -2
- package/dist/packages/extension-redis/src/Redis.d.ts +91 -9
- package/dist/packages/extension-redis/src/index.d.ts +0 -1
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +4 -4
- package/dist/packages/extension-throttle/src/index.d.ts +6 -2
- package/dist/packages/extension-webhook/src/index.d.ts +1 -2
- package/dist/packages/provider/src/EventEmitter.d.ts +1 -1
- package/dist/packages/provider/src/HocuspocusCloudProvider.d.ts +4 -3
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +30 -26
- package/dist/packages/provider/src/index.d.ts +0 -1
- package/dist/packages/provider/src/types.d.ts +43 -0
- package/dist/packages/server/src/Connection.d.ts +16 -5
- package/dist/packages/server/src/Debugger.d.ts +1 -2
- package/dist/packages/server/src/Document.d.ts +9 -5
- package/dist/packages/server/src/Hocuspocus.d.ts +37 -15
- package/dist/packages/server/src/MessageReceiver.d.ts +8 -5
- package/dist/packages/server/src/OutgoingMessage.d.ts +2 -0
- package/dist/packages/server/src/index.d.ts +6 -0
- package/dist/packages/server/src/types.d.ts +127 -38
- package/dist/tests/extension-database/fetch.d.ts +1 -0
- package/dist/tests/extension-logger/onListen.d.ts +1 -0
- package/dist/tests/extension-redis/closeConnections.d.ts +1 -0
- package/dist/tests/extension-redis/getConnectionCount.d.ts +1 -0
- package/dist/tests/extension-redis/getDocumentsCount.d.ts +1 -0
- package/dist/tests/extension-redis/onAwarenessChange.d.ts +1 -0
- package/dist/tests/extension-redis/onChange.d.ts +1 -0
- package/dist/tests/extension-redis/onStoreDocument.d.ts +1 -0
- package/dist/tests/extension-throttle/configuration.d.ts +1 -0
- package/dist/tests/provider/configuration.d.ts +1 -0
- package/dist/tests/provider/observe.d.ts +1 -0
- package/dist/tests/provider/observeDeep.d.ts +1 -0
- package/dist/tests/provider/onAuthenticated.d.ts +1 -0
- package/dist/tests/provider/onAuthenticationFailed.d.ts +1 -0
- package/dist/tests/provider/onAwarenessChange.d.ts +1 -0
- package/dist/tests/provider/onAwarenessUpdate.d.ts +1 -0
- package/dist/tests/provider/onClose.d.ts +1 -0
- package/dist/tests/provider/onConnect.d.ts +1 -0
- package/dist/tests/provider/onDisconnect.d.ts +1 -0
- package/dist/tests/provider/onMessage.d.ts +1 -0
- package/dist/tests/provider/onOpen.d.ts +1 -0
- package/dist/tests/provider/onSynced.d.ts +1 -0
- package/dist/tests/server/address.d.ts +1 -0
- package/dist/tests/server/afterStoreDocument.d.ts +1 -0
- package/dist/tests/server/beforeHandleMessage.d.ts +1 -0
- package/dist/tests/server/closeConnections.d.ts +1 -0
- package/dist/tests/server/getConnectionsCount.d.ts +1 -0
- package/dist/tests/server/getDocumentName.d.ts +1 -0
- package/dist/tests/server/getDocumentsCount.d.ts +1 -0
- package/dist/tests/server/getMessageLogs.d.ts +1 -0
- package/dist/tests/server/listen.d.ts +1 -0
- package/dist/tests/server/onAuthenticate.d.ts +1 -0
- package/dist/tests/server/onAwarenessUpdate.d.ts +1 -0
- package/dist/tests/server/onChange.d.ts +1 -0
- package/dist/tests/server/onConfigure.d.ts +1 -0
- package/dist/tests/server/onConnect.d.ts +1 -0
- package/dist/tests/server/onDestroy.d.ts +1 -0
- package/dist/tests/server/onDisconnect.d.ts +1 -0
- package/dist/tests/server/onListen.d.ts +1 -0
- package/dist/tests/server/onLoadDocument.d.ts +1 -0
- package/dist/tests/server/onRequest.d.ts +1 -0
- package/dist/tests/server/onStoreDocument.d.ts +1 -0
- package/dist/tests/server/onUpgrade.d.ts +1 -0
- package/dist/tests/server/requiresAuthentication.d.ts +1 -0
- package/dist/tests/server/websocketError.d.ts +1 -0
- package/dist/tests/transformer/TiptapTransformer.d.ts +1 -0
- package/dist/tests/utils/createDirectory.d.ts +1 -0
- package/dist/tests/utils/flushRedis.d.ts +1 -0
- package/dist/tests/utils/index.d.ts +8 -0
- package/dist/tests/utils/newHocuspocus.d.ts +2 -0
- package/dist/tests/utils/newHocuspocusProvider.d.ts +3 -0
- package/dist/tests/utils/randomInteger.d.ts +1 -0
- package/dist/tests/utils/redisConnectionSettings.d.ts +4 -0
- package/dist/tests/utils/removeDirectory.d.ts +1 -0
- package/dist/tests/utils/retryableAssertion.d.ts +2 -0
- package/dist/tests/utils/sleep.d.ts +1 -0
- package/package.json +7 -7
- package/src/SQLite.ts +29 -21
- package/dist/packages/extension-redis/src/RedisCluster.d.ts +0 -4
- package/dist/packages/extension-rocksdb/src/index.d.ts +0 -22
- package/dist/packages/provider/src/utils/awarenessStatesToArray.d.ts +0 -4
- package/dist/packages/provider/src/utils/index.d.ts +0 -1
- package/dist/packages/server/src/CloseEvents.d.ts +0 -4
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/sponsors/ueberdosis)
|
|
6
6
|
|
|
7
7
|
## Introduction
|
|
8
|
-
hocuspocus is an opinionated collaborative editing backend for [
|
|
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).
|
|
@@ -4,43 +4,49 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var extensionDatabase = require('@hocuspocus/extension-database');
|
|
6
6
|
var sqlite3 = require('sqlite3');
|
|
7
|
-
var
|
|
7
|
+
var kleur = require('kleur');
|
|
8
8
|
|
|
9
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
10
|
|
|
11
11
|
var sqlite3__default = /*#__PURE__*/_interopDefaultLegacy(sqlite3);
|
|
12
|
-
var
|
|
12
|
+
var kleur__default = /*#__PURE__*/_interopDefaultLegacy(kleur);
|
|
13
13
|
|
|
14
|
+
const schema = `CREATE TABLE IF NOT EXISTS "documents" (
|
|
15
|
+
"name" varchar(255) NOT NULL,
|
|
16
|
+
"data" blob NOT NULL,
|
|
17
|
+
UNIQUE(name)
|
|
18
|
+
)`;
|
|
19
|
+
const selectQuery = `
|
|
20
|
+
SELECT data FROM "documents" WHERE name = $name ORDER BY rowid DESC
|
|
21
|
+
`;
|
|
22
|
+
const upsertQuery = `
|
|
23
|
+
INSERT INTO "documents" ("name", "data") VALUES ($name, $data)
|
|
24
|
+
ON CONFLICT(name) DO UPDATE SET data = $data
|
|
25
|
+
`;
|
|
14
26
|
class SQLite extends extensionDatabase.Database {
|
|
15
|
-
/**
|
|
16
|
-
* Constructor
|
|
17
|
-
*/
|
|
18
27
|
constructor(configuration) {
|
|
19
28
|
super({});
|
|
20
29
|
this.configuration = {
|
|
21
30
|
database: ':memory:',
|
|
22
|
-
schema
|
|
23
|
-
|
|
24
|
-
"data" blob NOT NULL
|
|
25
|
-
);`,
|
|
26
|
-
fetchUpdates: async ({ documentName }) => {
|
|
31
|
+
schema,
|
|
32
|
+
fetch: async ({ documentName }) => {
|
|
27
33
|
return new Promise((resolve, reject) => {
|
|
28
34
|
var _a;
|
|
29
|
-
(_a = this.db) === null || _a === void 0 ? void 0 : _a.
|
|
35
|
+
(_a = this.db) === null || _a === void 0 ? void 0 : _a.get(selectQuery, {
|
|
30
36
|
$name: documentName,
|
|
31
|
-
}, (error,
|
|
37
|
+
}, (error, row) => {
|
|
32
38
|
if (error) {
|
|
33
39
|
reject(error);
|
|
34
40
|
}
|
|
35
|
-
resolve(
|
|
41
|
+
resolve(row === null || row === void 0 ? void 0 : row.data);
|
|
36
42
|
});
|
|
37
43
|
});
|
|
38
44
|
},
|
|
39
|
-
|
|
45
|
+
store: async ({ documentName, state }) => {
|
|
40
46
|
var _a;
|
|
41
|
-
(_a = this.db) === null || _a === void 0 ? void 0 : _a.run(
|
|
47
|
+
(_a = this.db) === null || _a === void 0 ? void 0 : _a.run(upsertQuery, {
|
|
42
48
|
$name: documentName,
|
|
43
|
-
$data:
|
|
49
|
+
$data: state,
|
|
44
50
|
});
|
|
45
51
|
},
|
|
46
52
|
};
|
|
@@ -49,15 +55,18 @@ class SQLite extends extensionDatabase.Database {
|
|
|
49
55
|
...configuration,
|
|
50
56
|
};
|
|
51
57
|
}
|
|
52
|
-
async onListen() {
|
|
53
|
-
console.warn(` ${chalk__default["default"].yellow('The SQLite extension is intended to be used in a local development environment, not in a production environment.')}`);
|
|
54
|
-
console.log();
|
|
55
|
-
}
|
|
56
58
|
async onConfigure() {
|
|
57
59
|
this.db = new sqlite3__default["default"].Database(this.configuration.database);
|
|
58
60
|
this.db.run(this.configuration.schema);
|
|
59
61
|
}
|
|
62
|
+
async onListen() {
|
|
63
|
+
console.warn(` ${kleur__default["default"].yellow('The SQLite extension is intended to be used in a local development environment, not in a production environment.')}`);
|
|
64
|
+
console.log();
|
|
65
|
+
}
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
exports.SQLite = SQLite;
|
|
69
|
+
exports.schema = schema;
|
|
70
|
+
exports.selectQuery = selectQuery;
|
|
71
|
+
exports.upsertQuery = upsertQuery;
|
|
63
72
|
//# sourceMappingURL=hocuspocus-sqlite.cjs.map
|
|
@@ -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
|
|
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: ':memory:',\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?.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 console.warn(` ${kleur.yellow('The SQLite extension is intended to be used in a local development environment, not in a production environment.')}`)\n console.log()\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;AAiBK,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,UAAU;YACpB,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,CAAC,GAAG,KAAH,IAAA,IAAA,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC,CAAA;AACpB,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,OAAO,CAAC,IAAI,CAAC,CAAA,EAAA,EAAKC,yBAAK,CAAC,MAAM,CAAC,kHAAkH,CAAC,CAAE,CAAA,CAAC,CAAA;QACrJ,OAAO,CAAC,GAAG,EAAE,CAAA;KACd;AACF;;;;;;;"}
|
|
@@ -1,37 +1,43 @@
|
|
|
1
1
|
import { Database } from '@hocuspocus/extension-database';
|
|
2
2
|
import sqlite3 from 'sqlite3';
|
|
3
|
-
import
|
|
3
|
+
import kleur from 'kleur';
|
|
4
4
|
|
|
5
|
+
const schema = `CREATE TABLE IF NOT EXISTS "documents" (
|
|
6
|
+
"name" varchar(255) NOT NULL,
|
|
7
|
+
"data" blob NOT NULL,
|
|
8
|
+
UNIQUE(name)
|
|
9
|
+
)`;
|
|
10
|
+
const selectQuery = `
|
|
11
|
+
SELECT data FROM "documents" WHERE name = $name ORDER BY rowid DESC
|
|
12
|
+
`;
|
|
13
|
+
const upsertQuery = `
|
|
14
|
+
INSERT INTO "documents" ("name", "data") VALUES ($name, $data)
|
|
15
|
+
ON CONFLICT(name) DO UPDATE SET data = $data
|
|
16
|
+
`;
|
|
5
17
|
class SQLite extends Database {
|
|
6
|
-
/**
|
|
7
|
-
* Constructor
|
|
8
|
-
*/
|
|
9
18
|
constructor(configuration) {
|
|
10
19
|
super({});
|
|
11
20
|
this.configuration = {
|
|
12
21
|
database: ':memory:',
|
|
13
|
-
schema
|
|
14
|
-
|
|
15
|
-
"data" blob NOT NULL
|
|
16
|
-
);`,
|
|
17
|
-
fetchUpdates: async ({ documentName }) => {
|
|
22
|
+
schema,
|
|
23
|
+
fetch: async ({ documentName }) => {
|
|
18
24
|
return new Promise((resolve, reject) => {
|
|
19
25
|
var _a;
|
|
20
|
-
(_a = this.db) === null || _a === void 0 ? void 0 : _a.
|
|
26
|
+
(_a = this.db) === null || _a === void 0 ? void 0 : _a.get(selectQuery, {
|
|
21
27
|
$name: documentName,
|
|
22
|
-
}, (error,
|
|
28
|
+
}, (error, row) => {
|
|
23
29
|
if (error) {
|
|
24
30
|
reject(error);
|
|
25
31
|
}
|
|
26
|
-
resolve(
|
|
32
|
+
resolve(row === null || row === void 0 ? void 0 : row.data);
|
|
27
33
|
});
|
|
28
34
|
});
|
|
29
35
|
},
|
|
30
|
-
|
|
36
|
+
store: async ({ documentName, state }) => {
|
|
31
37
|
var _a;
|
|
32
|
-
(_a = this.db) === null || _a === void 0 ? void 0 : _a.run(
|
|
38
|
+
(_a = this.db) === null || _a === void 0 ? void 0 : _a.run(upsertQuery, {
|
|
33
39
|
$name: documentName,
|
|
34
|
-
$data:
|
|
40
|
+
$data: state,
|
|
35
41
|
});
|
|
36
42
|
},
|
|
37
43
|
};
|
|
@@ -40,15 +46,15 @@ class SQLite extends Database {
|
|
|
40
46
|
...configuration,
|
|
41
47
|
};
|
|
42
48
|
}
|
|
43
|
-
async onListen() {
|
|
44
|
-
console.warn(` ${chalk.yellow('The SQLite extension is intended to be used in a local development environment, not in a production environment.')}`);
|
|
45
|
-
console.log();
|
|
46
|
-
}
|
|
47
49
|
async onConfigure() {
|
|
48
50
|
this.db = new sqlite3.Database(this.configuration.database);
|
|
49
51
|
this.db.run(this.configuration.schema);
|
|
50
52
|
}
|
|
53
|
+
async onListen() {
|
|
54
|
+
console.warn(` ${kleur.yellow('The SQLite extension is intended to be used in a local development environment, not in a production environment.')}`);
|
|
55
|
+
console.log();
|
|
56
|
+
}
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
export { SQLite };
|
|
59
|
+
export { SQLite, schema, selectQuery, upsertQuery };
|
|
54
60
|
//# sourceMappingURL=hocuspocus-sqlite.esm.js.map
|
|
@@ -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
|
|
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: ':memory:',\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?.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 console.warn(` ${kleur.yellow('The SQLite extension is intended to be used in a local development environment, not in a production environment.')}`)\n console.log()\n }\n}\n"],"names":[],"mappings":";;;;AAIa,MAAA,MAAM,GAAG,CAAA;;;;GAIpB;AAEW,MAAA,WAAW,GAAG,CAAA;;EAE1B;AAEY,MAAA,WAAW,GAAG,CAAA;;;EAG1B;AAiBK,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,UAAU;YACpB,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,CAAC,GAAG,KAAH,IAAA,IAAA,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC,CAAA;AACpB,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,OAAO,CAAC,IAAI,CAAC,CAAA,EAAA,EAAK,KAAK,CAAC,MAAM,CAAC,kHAAkH,CAAC,CAAE,CAAA,CAAC,CAAA;QACrJ,OAAO,CAAC,GAAG,EAAE,CAAA;KACd;AACF;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface CloseEvent {
|
|
2
|
+
code: number;
|
|
3
|
+
reason: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The server successfully processed the request, asks that the requester reset
|
|
7
|
+
* its document view, and is not returning any content.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ResetConnection: CloseEvent;
|
|
10
|
+
/**
|
|
11
|
+
* Similar to Forbidden, but specifically for use when authentication is required and has
|
|
12
|
+
* failed or has not yet been provided.
|
|
13
|
+
*/
|
|
14
|
+
export declare const Unauthorized: CloseEvent;
|
|
15
|
+
/**
|
|
16
|
+
* The request contained valid data and was understood by the server, but the server
|
|
17
|
+
* is refusing action.
|
|
18
|
+
*/
|
|
19
|
+
export declare const Forbidden: CloseEvent;
|
|
20
|
+
/**
|
|
21
|
+
* The server timed out waiting for the request.
|
|
22
|
+
*/
|
|
23
|
+
export declare const ConnectionTimeout: CloseEvent;
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import { Extension, onChangePayload, onLoadDocumentPayload } from '@hocuspocus/server';
|
|
1
|
+
import { Extension, onChangePayload, onLoadDocumentPayload, storePayload, fetchPayload } from '@hocuspocus/server';
|
|
3
2
|
export interface DatabaseConfiguration {
|
|
4
3
|
/**
|
|
5
4
|
* Pass a Promise to retrieve updates from your database. The Promise should resolve to
|
|
6
5
|
* an array of items with Y.js-compatible binary data.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
documentName: string;
|
|
10
|
-
}) => Promise<Uint8Array[]>;
|
|
7
|
+
fetch: (data: fetchPayload) => Promise<Uint8Array | null>;
|
|
11
8
|
/**
|
|
12
9
|
* Pass a function to store updates in your database.
|
|
13
10
|
*/
|
|
14
|
-
|
|
15
|
-
update: Buffer;
|
|
16
|
-
documentName: string;
|
|
17
|
-
}) => void;
|
|
11
|
+
store: (data: storePayload) => void;
|
|
18
12
|
}
|
|
19
13
|
export declare class Database implements Extension {
|
|
20
14
|
/**
|
|
@@ -28,9 +22,9 @@ export declare class Database implements Extension {
|
|
|
28
22
|
/**
|
|
29
23
|
* Get stored data from the database.
|
|
30
24
|
*/
|
|
31
|
-
onLoadDocument(
|
|
25
|
+
onLoadDocument(data: onLoadDocumentPayload): Promise<any>;
|
|
32
26
|
/**
|
|
33
27
|
* Store new updates in the database.
|
|
34
28
|
*/
|
|
35
|
-
|
|
29
|
+
onStoreDocument(data: onChangePayload): Promise<void>;
|
|
36
30
|
}
|
|
@@ -14,6 +14,10 @@ export interface LoggerConfiguration {
|
|
|
14
14
|
* Whether to log something for the `onChange` hook.
|
|
15
15
|
*/
|
|
16
16
|
onChange: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Whether to log something for the `onStoreDocument` hook.
|
|
19
|
+
*/
|
|
20
|
+
onStoreDocument: boolean;
|
|
17
21
|
/**
|
|
18
22
|
* Whether to log something for the `onConnect` hook.
|
|
19
23
|
*/
|
|
@@ -53,6 +57,7 @@ export declare class Logger implements Extension {
|
|
|
53
57
|
onConfigure(data: onConfigurePayload): Promise<void>;
|
|
54
58
|
onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
|
|
55
59
|
onChange(data: onChangePayload): Promise<void>;
|
|
60
|
+
onStoreDocument(data: onDisconnectPayload): Promise<void>;
|
|
56
61
|
onConnect(data: onConnectPayload): Promise<void>;
|
|
57
62
|
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
58
63
|
onUpgrade(data: onUpgradePayload): Promise<void>;
|
|
@@ -3,7 +3,6 @@ import { Configuration, onConnectPayload, onDisconnectPayload, onLoadDocumentPay
|
|
|
3
3
|
export declare class Collector {
|
|
4
4
|
serverConfiguration: Partial<Configuration>;
|
|
5
5
|
version: string;
|
|
6
|
-
yjsVersion: string;
|
|
7
6
|
connections: {};
|
|
8
7
|
messages: {};
|
|
9
8
|
messageCounter: number;
|
|
@@ -51,12 +50,12 @@ export declare class Collector {
|
|
|
51
50
|
documents(): {};
|
|
52
51
|
info(): Promise<{
|
|
53
52
|
configuration: Partial<Configuration>;
|
|
54
|
-
ipAddress: string;
|
|
53
|
+
ipAddress: string | null;
|
|
55
54
|
nodeVersion: string;
|
|
56
55
|
platform: NodeJS.Platform;
|
|
57
56
|
started: string;
|
|
58
57
|
version: string;
|
|
59
|
-
yjsVersion: string;
|
|
60
58
|
}>;
|
|
59
|
+
private getIpAddress;
|
|
61
60
|
private static readableYDoc;
|
|
62
61
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Extension, onChangePayload, onConfigurePayload,
|
|
2
|
+
import { Extension, onChangePayload, onConfigurePayload, onLoadDocumentPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload, connectedPayload } from '@hocuspocus/server';
|
|
3
3
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
4
4
|
import WebSocket from 'ws';
|
|
5
5
|
import { Storage } from './Storage';
|
|
@@ -30,7 +30,7 @@ export declare class Monitor implements Extension {
|
|
|
30
30
|
handleConnection(websocket: WebSocket, request: IncomingMessage): void | undefined;
|
|
31
31
|
onRequest({ request, response }: onRequestPayload): Promise<void>;
|
|
32
32
|
onUpgrade({ request, socket, head }: onUpgradePayload): Promise<void>;
|
|
33
|
-
|
|
33
|
+
connected(data: connectedPayload): Promise<void>;
|
|
34
34
|
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
35
35
|
onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
|
|
36
36
|
onChange(data: onChangePayload): Promise<void>;
|
|
@@ -1,16 +1,98 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import RedisClient from 'ioredis';
|
|
2
|
+
import Redlock from 'redlock';
|
|
3
|
+
import { Document, Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, onChangePayload, Debugger, onConfigurePayload, onListenPayload } from '@hocuspocus/server';
|
|
3
4
|
export interface Configuration {
|
|
5
|
+
/**
|
|
6
|
+
* Redis port
|
|
7
|
+
*/
|
|
8
|
+
port: number;
|
|
9
|
+
/**
|
|
10
|
+
* Redis host
|
|
11
|
+
*/
|
|
12
|
+
host: string;
|
|
13
|
+
/**
|
|
14
|
+
* Options passed directly to Redis constructor
|
|
15
|
+
*
|
|
16
|
+
* https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
|
|
17
|
+
*/
|
|
18
|
+
options?: RedisClient.RedisOptions;
|
|
19
|
+
/**
|
|
20
|
+
* An unique instance name, required to filter messages in Redis.
|
|
21
|
+
* If none is provided an unique id is generated.
|
|
22
|
+
*/
|
|
23
|
+
identifier: string;
|
|
24
|
+
/**
|
|
25
|
+
* Namespace for Redis keys, if none is provided 'hocuspocus' is used
|
|
26
|
+
*/
|
|
27
|
+
prefix: string;
|
|
28
|
+
/**
|
|
29
|
+
* The maximum time for the Redis lock in ms (in case it can’t be released).
|
|
30
|
+
*/
|
|
31
|
+
lockTimeout: number;
|
|
4
32
|
}
|
|
5
33
|
export declare class Redis implements Extension {
|
|
34
|
+
/**
|
|
35
|
+
* Make sure to give that extension a higher priority, so
|
|
36
|
+
* the `onStoreDocument` hook is able to intercept the chain,
|
|
37
|
+
* before documents are stored to the database.
|
|
38
|
+
*/
|
|
39
|
+
priority: number;
|
|
6
40
|
configuration: Configuration;
|
|
7
|
-
|
|
8
|
-
|
|
41
|
+
pub: RedisClient.Redis;
|
|
42
|
+
sub: RedisClient.Redis;
|
|
43
|
+
documents: Map<string, Document>;
|
|
44
|
+
redlock: Redlock;
|
|
45
|
+
locks: Map<string, Redlock.Lock>;
|
|
46
|
+
logger: Debugger;
|
|
47
|
+
constructor(configuration: Partial<Configuration>);
|
|
48
|
+
onConfigure({ instance }: onConfigurePayload): Promise<void>;
|
|
49
|
+
onListen({ configuration }: onListenPayload): Promise<void>;
|
|
50
|
+
private getKey;
|
|
51
|
+
private pubKey;
|
|
52
|
+
private subKey;
|
|
53
|
+
private lockKey;
|
|
54
|
+
/**
|
|
55
|
+
* Once a document is laoded, subscribe to the channel in Redis.
|
|
56
|
+
*/
|
|
57
|
+
afterLoadDocument({ documentName, document }: afterLoadDocumentPayload): Promise<unknown>;
|
|
58
|
+
/**
|
|
59
|
+
* Publish the first sync step through Redis.
|
|
60
|
+
*/
|
|
61
|
+
private publishFirstSyncStep;
|
|
62
|
+
/**
|
|
63
|
+
* Let’s ask Redis who is connected already.
|
|
64
|
+
*/
|
|
65
|
+
private requestAwarenessFromOtherInstances;
|
|
66
|
+
/**
|
|
67
|
+
* Before the document is stored, make sure to set a lock in Redis.
|
|
68
|
+
* That’s meant to avoid conflicts with other instances trying to store the document.
|
|
69
|
+
*/
|
|
70
|
+
onStoreDocument({ documentName }: onStoreDocumentPayload): Promise<unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* Release the Redis lock, so other instances can store documents.
|
|
73
|
+
*/
|
|
74
|
+
afterStoreDocument({ documentName }: afterStoreDocumentPayload): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Handle awareness update messages received directly by this Hocuspocus instance.
|
|
77
|
+
*/
|
|
78
|
+
onAwarenessUpdate({ documentName, awareness, added, updated, removed, }: onAwarenessUpdatePayload): Promise<number>;
|
|
79
|
+
/**
|
|
80
|
+
* Handle incoming messages published on all subscribed document channels.
|
|
81
|
+
* Note that this will also include messages from ourselves as it is not possible
|
|
82
|
+
* in Redis to filter these.
|
|
83
|
+
*/
|
|
84
|
+
private handleIncomingMessage;
|
|
85
|
+
/**
|
|
86
|
+
* if the ydoc changed, we'll need to inform other Hocuspocus servers about it.
|
|
87
|
+
*/
|
|
88
|
+
onChange(data: onChangePayload): Promise<any>;
|
|
89
|
+
/**
|
|
90
|
+
* Make sure to *not* listen for further changes, when there’s
|
|
91
|
+
* noone connected anymore.
|
|
92
|
+
*/
|
|
93
|
+
onDisconnect: ({ documentName, clientsCount }: onDisconnectPayload) => Promise<void>;
|
|
9
94
|
/**
|
|
10
|
-
*
|
|
95
|
+
* Kill the Redlock connection immediately.
|
|
11
96
|
*/
|
|
12
|
-
|
|
13
|
-
onLoadDocument(data: onLoadDocumentPayload): Promise<import("yjs").Doc | undefined>;
|
|
14
|
-
onConnect(data: onConnectPayload): Promise<void>;
|
|
15
|
-
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
97
|
+
onDestroy(): Promise<void>;
|
|
16
98
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database';
|
|
2
2
|
import sqlite3 from 'sqlite3';
|
|
3
|
+
export declare const schema = "CREATE TABLE IF NOT EXISTS \"documents\" (\n \"name\" varchar(255) NOT NULL,\n \"data\" blob NOT NULL,\n UNIQUE(name)\n)";
|
|
4
|
+
export declare const selectQuery = "\n SELECT data FROM \"documents\" WHERE name = $name ORDER BY rowid DESC\n";
|
|
5
|
+
export declare const upsertQuery = "\n INSERT INTO \"documents\" (\"name\", \"data\") VALUES ($name, $data)\n ON CONFLICT(name) DO UPDATE SET data = $data\n";
|
|
3
6
|
export interface SQLiteConfiguration extends DatabaseConfiguration {
|
|
4
7
|
/**
|
|
5
8
|
* Valid values are filenames, ":memory:" for an anonymous in-memory database and an empty
|
|
@@ -17,10 +20,7 @@ export interface SQLiteConfiguration extends DatabaseConfiguration {
|
|
|
17
20
|
export declare class SQLite extends Database {
|
|
18
21
|
db?: sqlite3.Database;
|
|
19
22
|
configuration: SQLiteConfiguration;
|
|
20
|
-
/**
|
|
21
|
-
* Constructor
|
|
22
|
-
*/
|
|
23
23
|
constructor(configuration?: Partial<SQLiteConfiguration>);
|
|
24
|
-
onListen(): Promise<void>;
|
|
25
24
|
onConfigure(): Promise<void>;
|
|
25
|
+
onListen(): Promise<void>;
|
|
26
26
|
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { Extension, onConnectPayload } from '@hocuspocus/server';
|
|
2
|
-
export interface
|
|
2
|
+
export interface ThrottleConfiguration {
|
|
3
3
|
throttle: number | null | false;
|
|
4
4
|
banTime: number;
|
|
5
5
|
}
|
|
6
6
|
export declare class Throttle implements Extension {
|
|
7
|
-
configuration:
|
|
7
|
+
configuration: ThrottleConfiguration;
|
|
8
8
|
connectionsByIp: Map<string, Array<number>>;
|
|
9
9
|
bannedIps: Map<string, number>;
|
|
10
|
+
/**
|
|
11
|
+
* Constructor
|
|
12
|
+
*/
|
|
13
|
+
constructor(configuration?: Partial<ThrottleConfiguration>);
|
|
10
14
|
/**
|
|
11
15
|
* Throttle requests
|
|
12
16
|
* @private
|
|
@@ -3,7 +3,6 @@ import { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, on
|
|
|
3
3
|
import { Doc } from 'yjs';
|
|
4
4
|
import { Transformer } from '@hocuspocus/transformer';
|
|
5
5
|
import { AxiosResponse } from 'axios';
|
|
6
|
-
import Timeout = NodeJS.Timeout;
|
|
7
6
|
export declare enum Events {
|
|
8
7
|
onChange = "change",
|
|
9
8
|
onConnect = "connect",
|
|
@@ -24,7 +23,7 @@ export interface Configuration {
|
|
|
24
23
|
export declare class Webhook implements Extension {
|
|
25
24
|
configuration: Configuration;
|
|
26
25
|
debounced: Map<string, {
|
|
27
|
-
timeout: Timeout;
|
|
26
|
+
timeout: NodeJS.Timeout;
|
|
28
27
|
start: number;
|
|
29
28
|
}>;
|
|
30
29
|
/**
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { HocuspocusProvider,
|
|
2
|
-
export
|
|
1
|
+
import { HocuspocusProvider, HocuspocusProviderConfiguration } from './HocuspocusProvider';
|
|
2
|
+
export declare type HocuspocusCloudProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & AdditionalHocuspocusCloudProviderConfiguration;
|
|
3
|
+
export interface AdditionalHocuspocusCloudProviderConfiguration {
|
|
3
4
|
/**
|
|
4
5
|
* A Hocuspocus Cloud key, get one here: https://hocuspocus.cloud/
|
|
5
6
|
*/
|
|
6
7
|
key: string;
|
|
7
8
|
}
|
|
8
9
|
export declare class HocuspocusCloudProvider extends HocuspocusProvider {
|
|
9
|
-
constructor(
|
|
10
|
+
constructor(configuration: HocuspocusCloudProviderConfiguration);
|
|
10
11
|
}
|