@hocuspocus/extension-sqlite 1.0.0-alpha.7 → 1.0.0-beta.2

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.
Files changed (36) hide show
  1. package/README.md +1 -1
  2. package/dist/hocuspocus-sqlite.cjs.map +1 -1
  3. package/dist/hocuspocus-sqlite.esm.js.map +1 -1
  4. package/dist/packages/common/src/index.d.ts +1 -0
  5. package/dist/packages/common/src/types.d.ts +10 -0
  6. package/dist/packages/extension-database/src/Database.d.ts +3 -5
  7. package/dist/packages/extension-monitor/src/Collector.d.ts +2 -3
  8. package/dist/packages/extension-monitor/src/index.d.ts +2 -2
  9. package/dist/packages/extension-redis/src/Redis.d.ts +91 -9
  10. package/dist/packages/extension-redis/src/index.d.ts +0 -1
  11. package/dist/packages/provider/src/HocuspocusProvider.d.ts +21 -24
  12. package/dist/packages/provider/src/types.d.ts +33 -0
  13. package/dist/packages/server/src/Connection.d.ts +11 -0
  14. package/dist/packages/server/src/Document.d.ts +2 -1
  15. package/dist/packages/server/src/Hocuspocus.d.ts +6 -2
  16. package/dist/packages/server/src/MessageReceiver.d.ts +1 -1
  17. package/dist/packages/server/src/OutgoingMessage.d.ts +1 -0
  18. package/dist/packages/server/src/index.d.ts +3 -4
  19. package/dist/packages/server/src/types.d.ts +39 -18
  20. package/dist/tests/{extension-redis-rewrite/closeConnections.d.ts → extension-database/fetch.d.ts} +0 -0
  21. package/dist/tests/{extension-redis-rewrite/getConnectionCount.d.ts → extension-redis/closeConnections.d.ts} +0 -0
  22. package/dist/tests/{extension-redis-rewrite/getDocumentsCount.d.ts → extension-redis/getConnectionCount.d.ts} +0 -0
  23. package/dist/tests/{extension-redis-rewrite/onAwarenessChange.d.ts → extension-redis/getDocumentsCount.d.ts} +0 -0
  24. package/dist/tests/{extension-redis-rewrite/onChange.d.ts → extension-redis/onAwarenessChange.d.ts} +0 -0
  25. package/dist/tests/{extension-redis-rewrite/onStoreDocument.d.ts → extension-redis/onChange.d.ts} +0 -0
  26. package/dist/tests/extension-redis/{onLoadDocument.d.ts → onStoreDocument.d.ts} +0 -0
  27. package/dist/tests/{extension-redis/onSynced.d.ts → provider/observe.d.ts} +0 -0
  28. package/dist/tests/{extension-rocksdb/onLoadDocument.d.ts → server/beforeHandleMessage.d.ts} +0 -0
  29. package/dist/tests/server/websocketError.d.ts +1 -0
  30. package/dist/tests/utils/index.d.ts +1 -0
  31. package/dist/tests/utils/randomInteger.d.ts +1 -0
  32. package/dist/tests/utils/retryableAssertion.d.ts +2 -0
  33. package/package.json +5 -5
  34. package/LICENSE.md +0 -21
  35. package/dist/packages/extension-redis/src/RedisCluster.d.ts +0 -4
  36. package/dist/packages/extension-rocksdb/src/index.d.ts +0 -22
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/ueberdosis)
6
6
 
7
7
  ## Introduction
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.
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).
@@ -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":";;;;;;;;;;;;;MAIa,MAAM,GAAG;;;;GAIpB;MAEW,WAAW,GAAG;;EAE1B;MAEY,WAAW,GAAG;;;EAG1B;MAiBY,MAAO,SAAQA,0BAAQ;IA2BlC,YAAY,aAA4C;QACtD,KAAK,CAAC,EAAE,CAAC,CAAA;QAzBX,kBAAa,GAAwB;YACnC,QAAQ,EAAE,UAAU;YACpB,MAAM;YACN,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE;gBAC5B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM;;oBACjC,MAAA,IAAI,CAAC,EAAE,0CAAE,GAAG,CAAC,WAAW,EAAE;wBACxB,KAAK,EAAE,YAAY;qBACpB,EAAE,CAAC,KAAK,EAAE,GAAG;wBACZ,IAAI,KAAK,EAAE;4BACT,MAAM,CAAC,KAAK,CAAC,CAAA;yBACd;wBAED,OAAO,CAAC,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC,CAAA;qBACnB,CAAC,CAAA;iBACH,CAAC,CAAA;aACH;YACD,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE;;gBACnC,MAAA,IAAI,CAAC,EAAE,0CAAE,GAAG,CAAC,WAAW,EAAE;oBACxB,KAAK,EAAE,YAAY;oBACnB,KAAK,EAAE,KAAK;iBACb,CAAC,CAAA;aACH;SACF,CAAA;QAKC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;YACrB,GAAG,aAAa;SACjB,CAAA;KACF;IAED,MAAM,WAAW;QACf,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;IAED,MAAM,QAAQ;QACZ,OAAO,CAAC,IAAI,CAAC,KAAKC,yBAAK,CAAC,MAAM,CAAC,kHAAkH,CAAC,EAAE,CAAC,CAAA;QACrJ,OAAO,CAAC,GAAG,EAAE,CAAA;KACd;;;;;;;;"}
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":";;;;MAIa,MAAM,GAAG;;;;GAIpB;MAEW,WAAW,GAAG;;EAE1B;MAEY,WAAW,GAAG;;;EAG1B;MAiBY,MAAO,SAAQ,QAAQ;IA2BlC,YAAY,aAA4C;QACtD,KAAK,CAAC,EAAE,CAAC,CAAA;QAzBX,kBAAa,GAAwB;YACnC,QAAQ,EAAE,UAAU;YACpB,MAAM;YACN,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE;gBAC5B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM;;oBACjC,MAAA,IAAI,CAAC,EAAE,0CAAE,GAAG,CAAC,WAAW,EAAE;wBACxB,KAAK,EAAE,YAAY;qBACpB,EAAE,CAAC,KAAK,EAAE,GAAG;wBACZ,IAAI,KAAK,EAAE;4BACT,MAAM,CAAC,KAAK,CAAC,CAAA;yBACd;wBAED,OAAO,CAAC,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC,CAAA;qBACnB,CAAC,CAAA;iBACH,CAAC,CAAA;aACH;YACD,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE;;gBACnC,MAAA,IAAI,CAAC,EAAE,0CAAE,GAAG,CAAC,WAAW,EAAE;oBACxB,KAAK,EAAE,YAAY;oBACnB,KAAK,EAAE,KAAK;iBACb,CAAC,CAAA;aACH;SACF,CAAA;QAKC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;YACrB,GAAG,aAAa;SACjB,CAAA;KACF;IAED,MAAM,WAAW;QACf,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;IAED,MAAM,QAAQ;QACZ,OAAO,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,MAAM,CAAC,kHAAkH,CAAC,EAAE,CAAC,CAAA;QACrJ,OAAO,CAAC,GAAG,EAAE,CAAA;KACd;;;;;"}
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;;;;"}
@@ -1,3 +1,4 @@
1
1
  export * from './auth';
2
2
  export * from './CloseEvents';
3
3
  export * from './awarenessStatesToArray';
4
+ export * from './types';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * State of the WebSocket connection.
3
+ * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState
4
+ */
5
+ export declare enum WsReadyStates {
6
+ Connecting = 0,
7
+ Open = 1,
8
+ Closing = 2,
9
+ Closed = 3
10
+ }
@@ -1,12 +1,10 @@
1
- import { Extension, onChangePayload, onLoadDocumentPayload, storePayload } from '@hocuspocus/server';
1
+ import { Extension, onChangePayload, onLoadDocumentPayload, storePayload, fetchPayload } from '@hocuspocus/server';
2
2
  export interface DatabaseConfiguration {
3
3
  /**
4
4
  * Pass a Promise to retrieve updates from your database. The Promise should resolve to
5
5
  * an array of items with Y.js-compatible binary data.
6
6
  */
7
- fetch: ({ documentName }: {
8
- documentName: string;
9
- }) => Promise<Uint8Array | null>;
7
+ fetch: (data: fetchPayload) => Promise<Uint8Array | null>;
10
8
  /**
11
9
  * Pass a function to store updates in your database.
12
10
  */
@@ -24,7 +22,7 @@ export declare class Database implements Extension {
24
22
  /**
25
23
  * Get stored data from the database.
26
24
  */
27
- onLoadDocument({ document, documentName }: onLoadDocumentPayload): Promise<any>;
25
+ onLoadDocument(data: onLoadDocumentPayload): Promise<any>;
28
26
  /**
29
27
  * Store new updates in the database.
30
28
  */
@@ -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, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
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
- onConnect(data: onConnectPayload): Promise<void>;
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 { RedisPersistence } from 'y-redis';
2
- import { Extension, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
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
- cluster: boolean;
8
- persistence: RedisPersistence | undefined;
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
- * Constructor
95
+ * Kill the Redlock connection immediately.
11
96
  */
12
- constructor(configuration?: Partial<Configuration>);
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,2 +1 @@
1
1
  export * from './Redis';
2
- export * from './RedisCluster';
@@ -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 { OutgoingMessage } from './OutgoingMessage';
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: ({ reason }: {
96
- reason: string;
97
- }) => void;
98
- onOpen: (event: Event) => void;
89
+ onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
90
+ onOpen: (data: onOpenParameters) => void;
99
91
  onConnect: () => void;
100
- onMessage: (event: MessageEvent) => void;
101
- onOutgoingMessage: (message: OutgoingMessage) => void;
102
- onStatus: (status: any) => void;
103
- onSynced: ({ state }: {
104
- state: boolean;
105
- }) => void;
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: ({ states }: onAwarenessUpdateParameters) => void;
110
- onAwarenessChange: ({ states }: onAwarenessChangeParameters) => void;
99
+ onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
100
+ onAwarenessChange: (data: onAwarenessChangeParameters) => void;
111
101
  /**
112
102
  * Don’t output any warnings.
113
103
  */
@@ -120,6 +110,7 @@ export declare class HocuspocusProvider extends EventEmitter {
120
110
  shouldConnect: boolean;
121
111
  status: WebSocketStatus;
122
112
  isSynced: boolean;
113
+ unsyncedChanges: number;
123
114
  isAuthenticated: boolean;
124
115
  lastMessageReceived: number;
125
116
  mux: mutex.mutex;
@@ -130,14 +121,20 @@ export declare class HocuspocusProvider extends EventEmitter {
130
121
  } | null;
131
122
  constructor(configuration: HocuspocusProviderConfiguration);
132
123
  setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
133
- connect(): Promise<void>;
124
+ boundConnect: () => Promise<unknown>;
125
+ cancelWebsocketRetry?: () => void;
126
+ connect(): Promise<unknown>;
134
127
  createWebSocketConnection(): Promise<unknown>;
135
128
  resolveConnectionAttempt(): void;
129
+ stopConnectionAttempt(): void;
136
130
  rejectConnectionAttempt(): void;
137
131
  get document(): Y.Doc;
138
132
  get awareness(): Awareness;
133
+ get hasUnsyncedChanges(): boolean;
139
134
  checkConnection(): void;
140
135
  forceSync(): void;
136
+ boundBeforeUnload: () => void;
137
+ beforeUnload(): void;
141
138
  registerEventListeners(): void;
142
139
  documentUpdateHandler(update: Uint8Array, origin: any): void;
143
140
  awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
@@ -149,15 +146,15 @@ export declare class HocuspocusProvider extends EventEmitter {
149
146
  set synced(state: boolean);
150
147
  get isAuthenticationRequired(): boolean;
151
148
  disconnect(): void;
152
- onOpen(event: Event): void;
149
+ onOpen(event: Event): Promise<void>;
153
150
  getToken(): Promise<string | null>;
154
- webSocketConnectionEstablished(): Promise<void>;
155
151
  startSync(): void;
156
152
  send(Message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
157
153
  onMessage(event: MessageEvent): void;
158
154
  onClose(event: CloseEvent): void;
159
155
  destroy(): void;
160
156
  get broadcastChannel(): string;
157
+ boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
161
158
  broadcastChannelSubscriber(data: ArrayBuffer): void;
162
159
  subscribeToBroadcastChannel(): void;
163
160
  disconnectBroadcastChannel(): void;
@@ -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
  };
@@ -26,6 +26,10 @@ export declare class Connection {
26
26
  * Set a callback that will be triggered when the connection is closed
27
27
  */
28
28
  onClose(callback: (document: Document) => void): Connection;
29
+ /**
30
+ * Set a callback that will be triggered before an message is handled
31
+ */
32
+ beforeHandleMessage(callback: (payload: Document, update: Uint8Array) => Promise<any>): Connection;
29
33
  /**
30
34
  * Send the given message
31
35
  */
@@ -49,6 +53,13 @@ export declare class Connection {
49
53
  * @private
50
54
  */
51
55
  private handleMessage;
56
+ /**
57
+ * Handle a ws instance error, which is required to prevent
58
+ * the server from crashing when one happens
59
+ * See https://github.com/websockets/ws/issues/1777#issuecomment-660803472
60
+ * @private
61
+ */
62
+ private handleError;
52
63
  /**
53
64
  * Get the underlying connection instance
54
65
  * @deprecated
@@ -16,10 +16,11 @@ export declare class Document extends Doc {
16
16
  name: string;
17
17
  mux: mutex;
18
18
  logger: Debugger;
19
+ isLoading: boolean;
19
20
  /**
20
21
  * Constructor.
21
22
  */
22
- constructor(name: string, logger: Debugger);
23
+ constructor(name: string, logger: Debugger, yDocOptions: {});
23
24
  /**
24
25
  * Check if the Document is empty
25
26
  */
@@ -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, Hook } from './types';
4
+ import { Configuration, HookName, HookPayload } from './types';
5
5
  import Document from './Document';
6
6
  import { Debugger } from './Debugger';
7
7
  import { onListenPayload } from '.';
@@ -12,6 +12,10 @@ export declare const defaultConfiguration: {
12
12
  debounce: number;
13
13
  maxDebounce: number;
14
14
  quiet: boolean;
15
+ yDocOptions: {
16
+ gc: boolean;
17
+ gcFilter: () => boolean;
18
+ };
15
19
  };
16
20
  /**
17
21
  * Hocuspocus Server
@@ -88,7 +92,7 @@ export declare class Hocuspocus {
88
92
  * Run the given hook on all configured extensions.
89
93
  * Runs the given callback after each hook.
90
94
  */
91
- hooks(name: Hook, payload: any, callback?: Function | null): Promise<any>;
95
+ hooks(name: HookName, payload: HookPayload, callback?: Function | null): Promise<any>;
92
96
  /**
93
97
  * Get parameters by the given request
94
98
  */
@@ -8,6 +8,6 @@ export declare class MessageReceiver {
8
8
  logger: Debugger;
9
9
  constructor(message: IncomingMessage, logger: Debugger);
10
10
  apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void;
11
- readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): 0 | 2 | 1;
11
+ readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 2 | 1;
12
12
  applyQueryAwarenessMessage(awareness: Awareness, reply?: (message: Uint8Array) => void): void;
13
13
  }
@@ -7,6 +7,7 @@ export declare class OutgoingMessage {
7
7
  category?: string;
8
8
  constructor();
9
9
  createSyncMessage(): OutgoingMessage;
10
+ createSyncReplyMessage(): OutgoingMessage;
10
11
  createAwarenessUpdateMessage(awareness: Awareness, changedClients?: Array<any>): OutgoingMessage;
11
12
  writeQueryAwareness(): OutgoingMessage;
12
13
  writeAuthenticated(): OutgoingMessage;
@@ -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';
@@ -10,17 +9,8 @@ export declare enum MessageType {
10
9
  Sync = 0,
11
10
  Awareness = 1,
12
11
  Auth = 2,
13
- QueryAwareness = 3
14
- }
15
- /**
16
- * State of the WebSocket connection.
17
- * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState
18
- */
19
- export declare enum WsReadyStates {
20
- Connecting = 0,
21
- Open = 1,
22
- Closing = 2,
23
- Closed = 3
12
+ QueryAwareness = 3,
13
+ SyncReply = 4
24
14
  }
25
15
  export interface AwarenessUpdate {
26
16
  added: Array<any>;
@@ -46,6 +36,7 @@ export interface Extension {
46
36
  onCreateDocument?(data: onLoadDocumentPayload): Promise<any>;
47
37
  onLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
48
38
  afterLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
39
+ beforeHandleMessage?(data: beforeHandleMessagePayload): Promise<any>;
49
40
  onChange?(data: onChangePayload): Promise<any>;
50
41
  onStoreDocument?(data: onStoreDocumentPayload): Promise<any>;
51
42
  afterStoreDocument?(data: afterStoreDocumentPayload): Promise<any>;
@@ -54,11 +45,12 @@ export interface Extension {
54
45
  onDisconnect?(data: onDisconnectPayload): Promise<any>;
55
46
  onDestroy?(data: onDestroyPayload): Promise<any>;
56
47
  }
57
- export declare type Hook = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' |
48
+ export declare type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' |
58
49
  /**
59
50
  * @deprecated onCreateDocument is deprecated, use onLoadDocument instead
60
51
  */
61
- 'onCreateDocument' | 'onLoadDocument' | 'afterLoadDocument' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'onDestroy';
52
+ 'onCreateDocument' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'onDestroy';
53
+ export declare type HookPayload = onConfigurePayload | onListenPayload | onUpgradePayload | onConnectPayload | connectedPayload | onAuthenticatePayload | onLoadDocumentPayload | onChangePayload | onStoreDocumentPayload | afterStoreDocumentPayload | onAwarenessUpdatePayload | onRequestPayload | onDisconnectPayload | onDestroyPayload;
62
54
  export interface Configuration extends Extension {
63
55
  /**
64
56
  * A name for the instance, used for logging.
@@ -89,6 +81,13 @@ export interface Configuration extends Extension {
89
81
  * By default, the servers show a start screen. If passed false, the server will start quietly.
90
82
  */
91
83
  quiet: boolean;
84
+ /**
85
+ * options to pass to the ydoc document
86
+ */
87
+ yDocOptions: {
88
+ gc: boolean;
89
+ gcFilter: () => boolean;
90
+ };
92
91
  /**
93
92
  * Function which returns the (customized) document name based on the request
94
93
  */
@@ -157,6 +156,17 @@ export interface onChangePayload {
157
156
  update: Uint8Array;
158
157
  socketId: string;
159
158
  }
159
+ export interface beforeHandleMessagePayload {
160
+ clientsCount: number;
161
+ context: any;
162
+ document: Document;
163
+ documentName: string;
164
+ instance: Hocuspocus;
165
+ requestHeaders: IncomingHttpHeaders;
166
+ requestParameters: URLSearchParams;
167
+ update: Uint8Array;
168
+ socketId: string;
169
+ }
160
170
  export interface onStoreDocumentPayload {
161
171
  clientsCount: number;
162
172
  context: any;
@@ -189,6 +199,16 @@ export declare type StatesArray = {
189
199
  clientId: number;
190
200
  [key: string | number]: any;
191
201
  }[];
202
+ export interface fetchPayload {
203
+ context: any;
204
+ document: Document;
205
+ documentName: string;
206
+ instance: Hocuspocus;
207
+ requestHeaders: IncomingHttpHeaders;
208
+ requestParameters: URLSearchParams;
209
+ socketId: string;
210
+ connection: ConnectionConfiguration;
211
+ }
192
212
  export interface storePayload extends onStoreDocumentPayload {
193
213
  state: Buffer;
194
214
  }
@@ -208,20 +228,21 @@ export interface onRequestPayload {
208
228
  instance: Hocuspocus;
209
229
  }
210
230
  export interface onUpgradePayload {
211
- head: any;
212
231
  request: IncomingMessage;
213
- socket: Socket;
232
+ socket: any;
233
+ head: any;
214
234
  instance: Hocuspocus;
215
235
  }
216
236
  export interface onListenPayload {
237
+ instance: Hocuspocus;
238
+ configuration: Configuration;
217
239
  port: number;
218
240
  }
219
241
  export interface onDestroyPayload {
220
242
  instance: Hocuspocus;
221
243
  }
222
244
  export interface onConfigurePayload {
245
+ instance: Hocuspocus;
223
246
  configuration: Configuration;
224
247
  version: string;
225
- yjsVersion: string;
226
- instance: Hocuspocus;
227
248
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -2,6 +2,7 @@ export * from './createDirectory';
2
2
  export * from './flushRedis';
3
3
  export * from './newHocuspocus';
4
4
  export * from './newHocuspocusProvider';
5
+ export * from './randomInteger';
5
6
  export * from './redisConnectionSettings';
6
7
  export * from './removeDirectory';
7
8
  export * from './sleep';
@@ -0,0 +1 @@
1
+ export declare const randomInteger: (min: number, max: number) => number;
@@ -0,0 +1,2 @@
1
+ import { ExecutionContext } from 'ava';
2
+ export declare const retryableAssertion: (t: ExecutionContext, recoverableTry: (tt: ExecutionContext) => void) => Promise<void>;
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.7",
4
+ "version": "1.0.0-beta.2",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
7
7
  "hocuspocus",
@@ -9,7 +9,7 @@
9
9
  ],
10
10
  "license": "MIT",
11
11
  "type": "module",
12
- "main": "dist/hocuspocus-sqlite.esm.js",
12
+ "main": "dist/hocuspocus-sqlite.cjs",
13
13
  "module": "dist/hocuspocus-sqlite.esm.js",
14
14
  "types": "dist/packages/extension-sqlite/src/index.d.ts",
15
15
  "exports": {
@@ -26,9 +26,9 @@
26
26
  "dist"
27
27
  ],
28
28
  "dependencies": {
29
- "@hocuspocus/extension-database": "^1.0.0-alpha.7",
29
+ "@hocuspocus/extension-database": "^1.0.0-beta.2",
30
30
  "kleur": "^4.1.4",
31
- "sqlite3": "^5.0.2"
31
+ "sqlite3": "^5.0.11"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
@@ -36,5 +36,5 @@
36
36
  "devDependencies": {
37
37
  "@types/sqlite3": "^3.1.8"
38
38
  },
39
- "gitHead": "05a7eb3d660175613d2fe7b6d9ec030e8e509683"
39
+ "gitHead": "b3454a4ca289a84ddfb7fa5607a2d4b8d5c37e9d"
40
40
  }
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021, überdosis GbR
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,4 +0,0 @@
1
- import { Redis } from './Redis';
2
- export declare class RedisCluster extends Redis {
3
- cluster: boolean;
4
- }
@@ -1,22 +0,0 @@
1
- import { Extension, onLoadDocumentPayload } from '@hocuspocus/server';
2
- import { LeveldbPersistence } from 'y-leveldb';
3
- export interface Configuration {
4
- options: object | undefined;
5
- path: string;
6
- }
7
- export declare class RocksDB implements Extension {
8
- configuration: Configuration;
9
- provider: LeveldbPersistence;
10
- /**
11
- * Constructor
12
- */
13
- constructor(configuration?: Partial<Configuration>);
14
- /**
15
- * onLoadDocument hook
16
- */
17
- onLoadDocument(data: onLoadDocumentPayload): Promise<any>;
18
- /**
19
- * store updates in y-leveldb persistence
20
- */
21
- store(documentName: string, update: Uint8Array): Promise<any>;
22
- }