@hocuspocus/extension-sqlite 2.0.0-beta.0 → 2.0.1

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