@hocuspocus/extension-sqlite 1.0.0-alpha.11 → 1.0.0-alpha.14
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-sqlite.cjs.map +1 -1
- package/dist/hocuspocus-sqlite.esm.js.map +1 -1
- package/dist/packages/extension-monitor/src/Collector.d.ts +2 -3
- package/dist/packages/extension-redis/src/Redis.d.ts +87 -9
- package/dist/packages/extension-redis/src/index.d.ts +0 -1
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +11 -21
- package/dist/packages/provider/src/types.d.ts +33 -0
- package/dist/packages/server/src/Hocuspocus.d.ts +2 -2
- package/dist/packages/server/src/index.d.ts +3 -4
- package/dist/packages/server/src/types.d.ts +7 -6
- package/dist/tests/{extension-redis-rewrite → extension-redis}/closeConnections.d.ts +0 -0
- package/dist/tests/{extension-redis-rewrite → extension-redis}/getConnectionCount.d.ts +0 -0
- package/dist/tests/{extension-redis-rewrite → extension-redis}/getDocumentsCount.d.ts +0 -0
- package/dist/tests/{extension-redis-rewrite → extension-redis}/onAwarenessChange.d.ts +0 -0
- package/dist/tests/{extension-redis-rewrite → extension-redis}/onChange.d.ts +0 -0
- package/dist/tests/{extension-redis-rewrite → extension-redis}/onStoreDocument.d.ts +0 -0
- package/dist/tests/utils/index.d.ts +1 -0
- package/dist/tests/utils/randomInteger.d.ts +1 -0
- package/package.json +3 -3
- package/dist/packages/extension-redis/src/RedisCluster.d.ts +0 -4
- package/dist/tests/extension-redis/onLoadDocument.d.ts +0 -1
- package/dist/tests/extension-redis/onSynced.d.ts +0 -1
|
@@ -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: ':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":";;;;;;;;;;;;;
|
|
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 +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: ':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":";;;;
|
|
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;;;;"}
|
|
@@ -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,16 +1,94 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import RedisClient from 'ioredis';
|
|
2
|
+
import Redlock from 'redlock';
|
|
3
|
+
import { Document, Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, 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 }: 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
|
+
* Make sure to *not* listen for further changes, when there’s
|
|
87
|
+
* noone connected anymore.
|
|
88
|
+
*/
|
|
89
|
+
onDisconnect: ({ documentName, clientsCount }: onDisconnectPayload) => Promise<void>;
|
|
9
90
|
/**
|
|
10
|
-
*
|
|
91
|
+
* Kill the Redlock connection immediately.
|
|
11
92
|
*/
|
|
12
|
-
|
|
13
|
-
onLoadDocument(data: onLoadDocumentPayload): Promise<import("yjs").Doc | undefined>;
|
|
14
|
-
onConnect(data: onConnectPayload): Promise<void>;
|
|
15
|
-
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
93
|
+
onDestroy(): Promise<void>;
|
|
16
94
|
}
|
|
@@ -3,14 +3,8 @@ import { Awareness } from 'y-protocols/awareness';
|
|
|
3
3
|
import * as mutex from 'lib0/mutex';
|
|
4
4
|
import type { Event, CloseEvent, MessageEvent } from 'ws';
|
|
5
5
|
import EventEmitter from './EventEmitter';
|
|
6
|
-
import {
|
|
7
|
-
import { ConstructableOutgoingMessage } from './types';
|
|
6
|
+
import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
|
|
8
7
|
import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
|
|
9
|
-
export declare enum WebSocketStatus {
|
|
10
|
-
Connecting = "connecting",
|
|
11
|
-
Connected = "connected",
|
|
12
|
-
Disconnected = "disconnected"
|
|
13
|
-
}
|
|
14
8
|
export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'url' | 'name'>> & Partial<CompleteHocuspocusProviderConfiguration>;
|
|
15
9
|
export interface CompleteHocuspocusProviderConfiguration {
|
|
16
10
|
/**
|
|
@@ -92,22 +86,18 @@ export interface CompleteHocuspocusProviderConfiguration {
|
|
|
92
86
|
*/
|
|
93
87
|
timeout: number;
|
|
94
88
|
onAuthenticated: () => void;
|
|
95
|
-
onAuthenticationFailed: (
|
|
96
|
-
|
|
97
|
-
}) => void;
|
|
98
|
-
onOpen: (event: Event) => void;
|
|
89
|
+
onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
|
|
90
|
+
onOpen: (data: onOpenParameters) => void;
|
|
99
91
|
onConnect: () => void;
|
|
100
|
-
onMessage: (
|
|
101
|
-
onOutgoingMessage: (
|
|
102
|
-
onStatus: (
|
|
103
|
-
onSynced: (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
onDisconnect: (event: CloseEvent) => void;
|
|
107
|
-
onClose: (event: CloseEvent) => void;
|
|
92
|
+
onMessage: (data: onMessageParameters) => void;
|
|
93
|
+
onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
|
|
94
|
+
onStatus: (data: onStatusParameters) => void;
|
|
95
|
+
onSynced: (data: onSyncedParameters) => void;
|
|
96
|
+
onDisconnect: (data: onDisconnectParameters) => void;
|
|
97
|
+
onClose: (data: onCloseParameters) => void;
|
|
108
98
|
onDestroy: () => void;
|
|
109
|
-
onAwarenessUpdate: (
|
|
110
|
-
onAwarenessChange: (
|
|
99
|
+
onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
|
|
100
|
+
onAwarenessChange: (data: onAwarenessChangeParameters) => void;
|
|
111
101
|
/**
|
|
112
102
|
* Don’t output any warnings.
|
|
113
103
|
*/
|
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import { Awareness } from 'y-protocols/awareness';
|
|
2
2
|
import * as Y from 'yjs';
|
|
3
3
|
import { Encoder } from 'lib0/encoding';
|
|
4
|
+
import type { Event, CloseEvent, MessageEvent } from 'ws';
|
|
4
5
|
import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage';
|
|
5
6
|
import { AwarenessMessage } from './OutgoingMessages/AwarenessMessage';
|
|
6
7
|
import { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage';
|
|
7
8
|
import { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage';
|
|
8
9
|
import { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage';
|
|
9
10
|
import { UpdateMessage } from './OutgoingMessages/UpdateMessage';
|
|
11
|
+
import { IncomingMessage } from './IncomingMessage';
|
|
12
|
+
import { OutgoingMessage } from './OutgoingMessage';
|
|
10
13
|
export declare enum MessageType {
|
|
11
14
|
Sync = 0,
|
|
12
15
|
Awareness = 1,
|
|
13
16
|
Auth = 2,
|
|
14
17
|
QueryAwareness = 3
|
|
15
18
|
}
|
|
19
|
+
export declare enum WebSocketStatus {
|
|
20
|
+
Connecting = "connecting",
|
|
21
|
+
Connected = "connected",
|
|
22
|
+
Disconnected = "disconnected"
|
|
23
|
+
}
|
|
16
24
|
export interface OutgoingMessageInterface {
|
|
17
25
|
encoder: Encoder;
|
|
18
26
|
type?: MessageType;
|
|
@@ -32,6 +40,31 @@ export interface Constructable<T> {
|
|
|
32
40
|
new (...args: any): T;
|
|
33
41
|
}
|
|
34
42
|
export declare type ConstructableOutgoingMessage = Constructable<AuthenticationMessage> | Constructable<AwarenessMessage> | Constructable<QueryAwarenessMessage> | Constructable<SyncStepOneMessage> | Constructable<SyncStepTwoMessage> | Constructable<UpdateMessage>;
|
|
43
|
+
export declare type onAuthenticationFailedParameters = {
|
|
44
|
+
reason: string;
|
|
45
|
+
};
|
|
46
|
+
export declare type onOpenParameters = {
|
|
47
|
+
event: Event;
|
|
48
|
+
};
|
|
49
|
+
export declare type onMessageParameters = {
|
|
50
|
+
event: MessageEvent;
|
|
51
|
+
message: IncomingMessage;
|
|
52
|
+
};
|
|
53
|
+
export declare type onOutgoingMessageParameters = {
|
|
54
|
+
message: OutgoingMessage;
|
|
55
|
+
};
|
|
56
|
+
export declare type onStatusParameters = {
|
|
57
|
+
status: WebSocketStatus;
|
|
58
|
+
};
|
|
59
|
+
export declare type onSyncedParameters = {
|
|
60
|
+
state: boolean;
|
|
61
|
+
};
|
|
62
|
+
export declare type onDisconnectParameters = {
|
|
63
|
+
event: CloseEvent;
|
|
64
|
+
};
|
|
65
|
+
export declare type onCloseParameters = {
|
|
66
|
+
event: CloseEvent;
|
|
67
|
+
};
|
|
35
68
|
export declare type onAwarenessUpdateParameters = {
|
|
36
69
|
states: StatesArray;
|
|
37
70
|
};
|
|
@@ -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,9 +1,8 @@
|
|
|
1
|
-
export * from './Hocuspocus';
|
|
2
1
|
export * from './Connection';
|
|
2
|
+
export * from './Debugger';
|
|
3
3
|
export * from './Document';
|
|
4
|
+
export * from './Hocuspocus';
|
|
4
5
|
export * from './IncomingMessage';
|
|
6
|
+
export * from './MessageReceiver';
|
|
5
7
|
export * from './OutgoingMessage';
|
|
6
8
|
export * from './types';
|
|
7
|
-
export * from './MessageReceiver';
|
|
8
|
-
export * from './Document';
|
|
9
|
-
export * from './Connection';
|
|
@@ -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 | onLoadDocumentPayload | 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.
|
|
@@ -198,20 +198,21 @@ export interface onRequestPayload {
|
|
|
198
198
|
instance: Hocuspocus;
|
|
199
199
|
}
|
|
200
200
|
export interface onUpgradePayload {
|
|
201
|
-
head: any;
|
|
202
201
|
request: IncomingMessage;
|
|
203
|
-
socket:
|
|
202
|
+
socket: any;
|
|
203
|
+
head: any;
|
|
204
204
|
instance: Hocuspocus;
|
|
205
205
|
}
|
|
206
206
|
export interface onListenPayload {
|
|
207
|
+
instance: Hocuspocus;
|
|
208
|
+
configuration: Configuration;
|
|
207
209
|
port: number;
|
|
208
210
|
}
|
|
209
211
|
export interface onDestroyPayload {
|
|
210
212
|
instance: Hocuspocus;
|
|
211
213
|
}
|
|
212
214
|
export interface onConfigurePayload {
|
|
215
|
+
instance: Hocuspocus;
|
|
213
216
|
configuration: Configuration;
|
|
214
217
|
version: string;
|
|
215
|
-
yjsVersion: string;
|
|
216
|
-
instance: Hocuspocus;
|
|
217
218
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -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-sqlite",
|
|
3
3
|
"description": "a generic Hocuspocus persistence driver for the sqlite",
|
|
4
|
-
"version": "1.0.0-alpha.
|
|
4
|
+
"version": "1.0.0-alpha.14",
|
|
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": "^1.0.0-alpha.
|
|
29
|
+
"@hocuspocus/extension-database": "^1.0.0-alpha.14",
|
|
30
30
|
"kleur": "^4.1.4",
|
|
31
31
|
"sqlite3": "^5.0.2"
|
|
32
32
|
},
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/sqlite3": "^3.1.8"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "29d403cdc2b972cf3129229abcaceb08e365fbb4"
|
|
40
40
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|