@hocuspocus/extension-sqlite 3.4.6-rc.2 → 4.0.0-rc.0
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/LICENSE.md +21 -0
- package/dist/hocuspocus-sqlite.cjs +8 -13
- package/dist/hocuspocus-sqlite.cjs.map +1 -1
- package/dist/hocuspocus-sqlite.esm.js +7 -12
- package/dist/hocuspocus-sqlite.esm.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/package.json +8 -5
- package/src/SQLite.ts +12 -22
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023, Tiptap GmbH
|
|
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.
|
|
@@ -27,8 +27,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
|
|
28
28
|
//#endregion
|
|
29
29
|
let _hocuspocus_extension_database = require("@hocuspocus/extension-database");
|
|
30
|
-
let
|
|
31
|
-
|
|
30
|
+
let better_sqlite3 = require("better-sqlite3");
|
|
31
|
+
better_sqlite3 = __toESM(better_sqlite3);
|
|
32
32
|
let kleur = require("kleur");
|
|
33
33
|
kleur = __toESM(kleur);
|
|
34
34
|
|
|
@@ -53,17 +53,12 @@ var SQLite = class extends _hocuspocus_extension_database.Database {
|
|
|
53
53
|
database: SQLITE_INMEMORY,
|
|
54
54
|
schema,
|
|
55
55
|
fetch: async ({ documentName }) => {
|
|
56
|
-
return
|
|
57
|
-
this.db?.get(selectQuery, { $name: documentName }, (error, row) => {
|
|
58
|
-
if (error) reject(error);
|
|
59
|
-
resolve(row?.data);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
56
|
+
return (this.db?.prepare(selectQuery).get({ name: documentName }))?.data ?? null;
|
|
62
57
|
},
|
|
63
58
|
store: async ({ documentName, state }) => {
|
|
64
|
-
this.db?.run(
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
this.db?.prepare(upsertQuery).run({
|
|
60
|
+
name: documentName,
|
|
61
|
+
data: state
|
|
67
62
|
});
|
|
68
63
|
}
|
|
69
64
|
};
|
|
@@ -73,8 +68,8 @@ var SQLite = class extends _hocuspocus_extension_database.Database {
|
|
|
73
68
|
};
|
|
74
69
|
}
|
|
75
70
|
async onConfigure() {
|
|
76
|
-
this.db = new
|
|
77
|
-
this.db.
|
|
71
|
+
this.db = new better_sqlite3.default(this.configuration.database);
|
|
72
|
+
this.db.exec(this.configuration.schema);
|
|
78
73
|
}
|
|
79
74
|
async onListen() {
|
|
80
75
|
if (this.configuration.database === SQLITE_INMEMORY) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hocuspocus-sqlite.cjs","names":["Database"],"sources":["../src/SQLite.ts"],"sourcesContent":["import type { DatabaseConfiguration } from \"@hocuspocus/extension-database\";\nimport { Database } from \"@hocuspocus/extension-database\";\nimport
|
|
1
|
+
{"version":3,"file":"hocuspocus-sqlite.cjs","names":["Database","BetterSqlite3"],"sources":["../src/SQLite.ts"],"sourcesContent":["import type { DatabaseConfiguration } from \"@hocuspocus/extension-database\";\nimport { Database } from \"@hocuspocus/extension-database\";\nimport BetterSqlite3 from \"better-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\t/**\n\t * Valid values are filenames, \":memory:\" for an anonymous in-memory database and an empty\n\t * string for an anonymous disk-based database. Anonymous databases are not persisted and\n\t * when closing the database handle, their contents are lost.\n\t *\n\t * https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#new-daboratabasepath-options\n\t */\n\tdatabase: string;\n\t/**\n\t * The database schema to create.\n\t */\n\tschema: string;\n}\n\nexport class SQLite extends Database {\n\tdb?: BetterSqlite3.Database;\n\n\tconfiguration: SQLiteConfiguration = {\n\t\tdatabase: SQLITE_INMEMORY,\n\t\tschema,\n\t\tfetch: async ({ documentName }) => {\n\t\t\tconst row = this.db\n\t\t\t\t?.prepare(selectQuery)\n\t\t\t\t.get({ name: documentName }) as { data: Buffer } | undefined;\n\n\t\t\treturn row?.data ?? null;\n\t\t},\n\t\tstore: async ({ documentName, state }) => {\n\t\t\tthis.db?.prepare(upsertQuery).run({\n\t\t\t\tname: documentName,\n\t\t\t\tdata: state,\n\t\t\t});\n\t\t},\n\t};\n\n\tconstructor(configuration?: Partial<SQLiteConfiguration>) {\n\t\tsuper({});\n\n\t\tthis.configuration = {\n\t\t\t...this.configuration,\n\t\t\t...configuration,\n\t\t};\n\t}\n\n\tasync onConfigure() {\n\t\tthis.db = new BetterSqlite3(this.configuration.database);\n\t\tthis.db.exec(this.configuration.schema);\n\t}\n\n\tasync onListen() {\n\t\tif (this.configuration.database === SQLITE_INMEMORY) {\n\t\t\tconsole.warn(\n\t\t\t\t` ${kleur.yellow(\"The SQLite extension is configured as an in-memory database. All changes will be lost on restart!\")}`,\n\t\t\t);\n\t\t\tconsole.log();\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAa,SAAS;;;;;AAMtB,MAAa,cAAc;;;AAI3B,MAAa,cAAc;;;;AAK3B,MAAM,kBAAkB;AAiBxB,IAAa,SAAb,cAA4BA,wCAAS;CAqBpC,YAAY,eAA8C;AACzD,QAAM,EAAE,CAAC;uBAnB2B;GACpC,UAAU;GACV;GACA,OAAO,OAAO,EAAE,mBAAmB;AAKlC,YAJY,KAAK,IACd,QAAQ,YAAY,CACrB,IAAI,EAAE,MAAM,cAAc,CAAC,GAEjB,QAAQ;;GAErB,OAAO,OAAO,EAAE,cAAc,YAAY;AACzC,SAAK,IAAI,QAAQ,YAAY,CAAC,IAAI;KACjC,MAAM;KACN,MAAM;KACN,CAAC;;GAEH;AAKA,OAAK,gBAAgB;GACpB,GAAG,KAAK;GACR,GAAG;GACH;;CAGF,MAAM,cAAc;AACnB,OAAK,KAAK,IAAIC,uBAAc,KAAK,cAAc,SAAS;AACxD,OAAK,GAAG,KAAK,KAAK,cAAc,OAAO;;CAGxC,MAAM,WAAW;AAChB,MAAI,KAAK,cAAc,aAAa,iBAAiB;AACpD,WAAQ,KACP,KAAK,cAAM,OAAO,oGAAoG,GACtH;AACD,WAAQ,KAAK"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Database } from "@hocuspocus/extension-database";
|
|
2
|
-
import
|
|
2
|
+
import BetterSqlite3 from "better-sqlite3";
|
|
3
3
|
import kleur from "kleur";
|
|
4
4
|
|
|
5
5
|
//#region packages/extension-sqlite/src/SQLite.ts
|
|
@@ -23,17 +23,12 @@ var SQLite = class extends Database {
|
|
|
23
23
|
database: SQLITE_INMEMORY,
|
|
24
24
|
schema,
|
|
25
25
|
fetch: async ({ documentName }) => {
|
|
26
|
-
return
|
|
27
|
-
this.db?.get(selectQuery, { $name: documentName }, (error, row) => {
|
|
28
|
-
if (error) reject(error);
|
|
29
|
-
resolve(row?.data);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
26
|
+
return (this.db?.prepare(selectQuery).get({ name: documentName }))?.data ?? null;
|
|
32
27
|
},
|
|
33
28
|
store: async ({ documentName, state }) => {
|
|
34
|
-
this.db?.run(
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
this.db?.prepare(upsertQuery).run({
|
|
30
|
+
name: documentName,
|
|
31
|
+
data: state
|
|
37
32
|
});
|
|
38
33
|
}
|
|
39
34
|
};
|
|
@@ -43,8 +38,8 @@ var SQLite = class extends Database {
|
|
|
43
38
|
};
|
|
44
39
|
}
|
|
45
40
|
async onConfigure() {
|
|
46
|
-
this.db = new
|
|
47
|
-
this.db.
|
|
41
|
+
this.db = new BetterSqlite3(this.configuration.database);
|
|
42
|
+
this.db.exec(this.configuration.schema);
|
|
48
43
|
}
|
|
49
44
|
async onListen() {
|
|
50
45
|
if (this.configuration.database === SQLITE_INMEMORY) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hocuspocus-sqlite.esm.js","names":[],"sources":["../src/SQLite.ts"],"sourcesContent":["import type { DatabaseConfiguration } from \"@hocuspocus/extension-database\";\nimport { Database } from \"@hocuspocus/extension-database\";\nimport
|
|
1
|
+
{"version":3,"file":"hocuspocus-sqlite.esm.js","names":[],"sources":["../src/SQLite.ts"],"sourcesContent":["import type { DatabaseConfiguration } from \"@hocuspocus/extension-database\";\nimport { Database } from \"@hocuspocus/extension-database\";\nimport BetterSqlite3 from \"better-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\t/**\n\t * Valid values are filenames, \":memory:\" for an anonymous in-memory database and an empty\n\t * string for an anonymous disk-based database. Anonymous databases are not persisted and\n\t * when closing the database handle, their contents are lost.\n\t *\n\t * https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#new-daboratabasepath-options\n\t */\n\tdatabase: string;\n\t/**\n\t * The database schema to create.\n\t */\n\tschema: string;\n}\n\nexport class SQLite extends Database {\n\tdb?: BetterSqlite3.Database;\n\n\tconfiguration: SQLiteConfiguration = {\n\t\tdatabase: SQLITE_INMEMORY,\n\t\tschema,\n\t\tfetch: async ({ documentName }) => {\n\t\t\tconst row = this.db\n\t\t\t\t?.prepare(selectQuery)\n\t\t\t\t.get({ name: documentName }) as { data: Buffer } | undefined;\n\n\t\t\treturn row?.data ?? null;\n\t\t},\n\t\tstore: async ({ documentName, state }) => {\n\t\t\tthis.db?.prepare(upsertQuery).run({\n\t\t\t\tname: documentName,\n\t\t\t\tdata: state,\n\t\t\t});\n\t\t},\n\t};\n\n\tconstructor(configuration?: Partial<SQLiteConfiguration>) {\n\t\tsuper({});\n\n\t\tthis.configuration = {\n\t\t\t...this.configuration,\n\t\t\t...configuration,\n\t\t};\n\t}\n\n\tasync onConfigure() {\n\t\tthis.db = new BetterSqlite3(this.configuration.database);\n\t\tthis.db.exec(this.configuration.schema);\n\t}\n\n\tasync onListen() {\n\t\tif (this.configuration.database === SQLITE_INMEMORY) {\n\t\t\tconsole.warn(\n\t\t\t\t` ${kleur.yellow(\"The SQLite extension is configured as an in-memory database. All changes will be lost on restart!\")}`,\n\t\t\t);\n\t\t\tconsole.log();\n\t\t}\n\t}\n}\n"],"mappings":";;;;;AAKA,MAAa,SAAS;;;;;AAMtB,MAAa,cAAc;;;AAI3B,MAAa,cAAc;;;;AAK3B,MAAM,kBAAkB;AAiBxB,IAAa,SAAb,cAA4B,SAAS;CAqBpC,YAAY,eAA8C;AACzD,QAAM,EAAE,CAAC;uBAnB2B;GACpC,UAAU;GACV;GACA,OAAO,OAAO,EAAE,mBAAmB;AAKlC,YAJY,KAAK,IACd,QAAQ,YAAY,CACrB,IAAI,EAAE,MAAM,cAAc,CAAC,GAEjB,QAAQ;;GAErB,OAAO,OAAO,EAAE,cAAc,YAAY;AACzC,SAAK,IAAI,QAAQ,YAAY,CAAC,IAAI;KACjC,MAAM;KACN,MAAM;KACN,CAAC;;GAEH;AAKA,OAAK,gBAAgB;GACpB,GAAG,KAAK;GACR,GAAG;GACH;;CAGF,MAAM,cAAc;AACnB,OAAK,KAAK,IAAI,cAAc,KAAK,cAAc,SAAS;AACxD,OAAK,GAAG,KAAK,KAAK,cAAc,OAAO;;CAGxC,MAAM,WAAW;AAChB,MAAI,KAAK,cAAc,aAAa,iBAAiB;AACpD,WAAQ,KACP,KAAK,MAAM,OAAO,oGAAoG,GACtH;AACD,WAAQ,KAAK"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Database, DatabaseConfiguration } from "@hocuspocus/extension-database";
|
|
2
|
-
import
|
|
2
|
+
import BetterSqlite3 from "better-sqlite3";
|
|
3
3
|
|
|
4
4
|
//#region packages/extension-sqlite/src/SQLite.d.ts
|
|
5
5
|
declare const schema = "CREATE TABLE IF NOT EXISTS \"documents\" (\n \"name\" varchar(255) NOT NULL,\n \"data\" blob NOT NULL,\n UNIQUE(name)\n)";
|
|
@@ -11,7 +11,7 @@ interface SQLiteConfiguration extends DatabaseConfiguration {
|
|
|
11
11
|
* string for an anonymous disk-based database. Anonymous databases are not persisted and
|
|
12
12
|
* when closing the database handle, their contents are lost.
|
|
13
13
|
*
|
|
14
|
-
* https://github.com/
|
|
14
|
+
* https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#new-daboratabasepath-options
|
|
15
15
|
*/
|
|
16
16
|
database: string;
|
|
17
17
|
/**
|
|
@@ -20,7 +20,7 @@ interface SQLiteConfiguration extends DatabaseConfiguration {
|
|
|
20
20
|
schema: string;
|
|
21
21
|
}
|
|
22
22
|
declare class SQLite extends Database {
|
|
23
|
-
db?:
|
|
23
|
+
db?: BetterSqlite3.Database;
|
|
24
24
|
configuration: SQLiteConfiguration;
|
|
25
25
|
constructor(configuration?: Partial<SQLiteConfiguration>);
|
|
26
26
|
onConfigure(): 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": "
|
|
4
|
+
"version": "4.0.0-rc.0",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"hocuspocus",
|
|
@@ -27,14 +27,17 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@hocuspocus/extension-database": "^
|
|
31
|
-
"
|
|
32
|
-
"
|
|
30
|
+
"@hocuspocus/extension-database": "^4.0.0-rc.0",
|
|
31
|
+
"better-sqlite3": "^12.6.2",
|
|
32
|
+
"kleur": "^4.1.4"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/better-sqlite3": "^7.6.12"
|
|
33
36
|
},
|
|
34
37
|
"publishConfig": {
|
|
35
38
|
"access": "public"
|
|
36
39
|
},
|
|
37
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "3fe6c023877badd74d3ea3e50019b73660e028a4",
|
|
38
41
|
"repository": {
|
|
39
42
|
"url": "https://github.com/ueberdosis/hocuspocus"
|
|
40
43
|
}
|
package/src/SQLite.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DatabaseConfiguration } from "@hocuspocus/extension-database";
|
|
2
2
|
import { Database } from "@hocuspocus/extension-database";
|
|
3
|
-
import
|
|
3
|
+
import BetterSqlite3 from "better-sqlite3";
|
|
4
4
|
import kleur from "kleur";
|
|
5
5
|
|
|
6
6
|
export const schema = `CREATE TABLE IF NOT EXISTS "documents" (
|
|
@@ -26,7 +26,7 @@ export interface SQLiteConfiguration extends DatabaseConfiguration {
|
|
|
26
26
|
* string for an anonymous disk-based database. Anonymous databases are not persisted and
|
|
27
27
|
* when closing the database handle, their contents are lost.
|
|
28
28
|
*
|
|
29
|
-
* https://github.com/
|
|
29
|
+
* https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#new-daboratabasepath-options
|
|
30
30
|
*/
|
|
31
31
|
database: string;
|
|
32
32
|
/**
|
|
@@ -36,32 +36,22 @@ export interface SQLiteConfiguration extends DatabaseConfiguration {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export class SQLite extends Database {
|
|
39
|
-
db?:
|
|
39
|
+
db?: BetterSqlite3.Database;
|
|
40
40
|
|
|
41
41
|
configuration: SQLiteConfiguration = {
|
|
42
42
|
database: SQLITE_INMEMORY,
|
|
43
43
|
schema,
|
|
44
44
|
fetch: async ({ documentName }) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
{
|
|
49
|
-
$name: documentName,
|
|
50
|
-
},
|
|
51
|
-
(error, row) => {
|
|
52
|
-
if (error) {
|
|
53
|
-
reject(error);
|
|
54
|
-
}
|
|
45
|
+
const row = this.db
|
|
46
|
+
?.prepare(selectQuery)
|
|
47
|
+
.get({ name: documentName }) as { data: Buffer } | undefined;
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
);
|
|
59
|
-
});
|
|
49
|
+
return row?.data ?? null;
|
|
60
50
|
},
|
|
61
51
|
store: async ({ documentName, state }) => {
|
|
62
|
-
this.db?.run(
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
this.db?.prepare(upsertQuery).run({
|
|
53
|
+
name: documentName,
|
|
54
|
+
data: state,
|
|
65
55
|
});
|
|
66
56
|
},
|
|
67
57
|
};
|
|
@@ -76,8 +66,8 @@ export class SQLite extends Database {
|
|
|
76
66
|
}
|
|
77
67
|
|
|
78
68
|
async onConfigure() {
|
|
79
|
-
this.db = new
|
|
80
|
-
this.db.
|
|
69
|
+
this.db = new BetterSqlite3(this.configuration.database);
|
|
70
|
+
this.db.exec(this.configuration.schema);
|
|
81
71
|
}
|
|
82
72
|
|
|
83
73
|
async onListen() {
|