@mescius/js-collaboration-ot-sqlite 19.0.0 → 19.0.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.
- package/dist/index.js +2 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
*
|
|
3
|
-
* SpreadJS Library 19.0.
|
|
3
|
+
* SpreadJS Library 19.0.2
|
|
4
4
|
*
|
|
5
5
|
* Copyright(c) MESCIUS inc. All rights reserved.
|
|
6
6
|
*
|
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
* https://developer.mescius.com/spreadjs
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
|
-
!function(s,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@mescius/js-collaboration-ot"));else if("function"==typeof define&&define.amd)define(["@mescius/js-collaboration-ot"],t);else{var n="object"==typeof exports?t(require("@mescius/js-collaboration-ot")):t(s["@mescius/js-collaboration-ot"]);for(var e in n)("object"==typeof exports?exports:s)[e]=n[e]}}(this,(s=>(()=>{"use strict";var t={252:t=>{t.exports=s}},n={};function e(s){var i=n[s];if(void 0!==i)return i.exports;var r=n[s]={exports:{}};return t[s](r,r.exports,e),r.exports}var i={};return(()=>{var s=i;Object.defineProperty(s,"__esModule",{value:!0}),s.SqliteDb=void 0;const t=e(252);class n extends t.Db{constructor(s){super(),this.db=s}async init(s=!1){return new Promise((t=>{this.db.serialize((()=>{s&&(this.db.run("DROP TABLE IF EXISTS documents"),this.db.run("DROP TABLE IF EXISTS operations"),this.db.run("DROP TABLE IF EXISTS snapshot_fragments")),this.db.run("CREATE TABLE IF NOT EXISTS documents (\n id TEXT PRIMARY KEY,\n type TEXT NOT NULL,\n version INTEGER NOT NULL,\n snapshot_version INTEGER NOT NULL\n )"),this.db.run("CREATE TABLE IF NOT EXISTS operations (\n doc_id TEXT NOT NULL,\n version INTEGER NOT NULL,\n operation TEXT NOT NULL,\n PRIMARY KEY (doc_id, version),\n FOREIGN KEY (doc_id) REFERENCES documents (id) ON DELETE CASCADE\n )"),this.db.run("CREATE TABLE IF NOT EXISTS snapshot_fragments (\n doc_id TEXT NOT NULL,\n fragment_id TEXT NOT NULL,\n data TEXT NOT NULL,\n PRIMARY KEY (doc_id, fragment_id),\n FOREIGN KEY (doc_id) REFERENCES documents (id) ON DELETE CASCADE\n )"),t()}))}))}runAsync(s,t=[]){return new Promise(((n,e)=>{this.db.run(s,t,(s=>s?e(s):n()))}))}getAsync(s,t=[]){return new Promise(((n,e)=>{this.db.get(s,t,((s,t)=>s?e(s):n(t)))}))}allAsync(s,t=[]){return new Promise(((n,e)=>{this.db.all(s,t,((s,t)=>s?e(s):n(t)))}))}async withTransaction(s){return new Promise((t=>{this.db.serialize((async()=>{try{await this.runAsync("BEGIN");try{const n=await s();await this.runAsync("COMMIT"),t(n)}catch(s){await this.runAsync("ROLLBACK"),t(!1)}}catch(s){t(!1)}}))}))}async getDocument(s){const t=await this.getAsync("SELECT id, type, version, snapshot_version FROM documents WHERE id = ?",[s]);return t?{id:t.id,type:t.type,version:t.version,snapshotVersion:t.snapshot_version}:null}async getSnapshot(s){const t=await this.allAsync("SELECT d.id, d.type, d.snapshot_version, sf.fragment_id, sf.data FROM documents d LEFT JOIN snapshot_fragments sf ON d.id = sf.doc_id WHERE d.id = ?",[s]);if(0===t.length)return null;const n=t[0],e=this._parseFragmentRows(t);return{id:n.id,v:n.snapshot_version,type:n.type,fragments:e}}_parseFragmentRows(s){const t={};for(const n of s)n.fragment_id&&(t[n.fragment_id]=JSON.parse(n.data));return t}async getFragment(s,t){const n=await this.getAsync("SELECT d.snapshot_version, sf.data FROM documents d LEFT JOIN snapshot_fragments sf ON d.id = sf.doc_id AND sf.doc_id = ? AND sf.fragment_id = ? WHERE d.id = ?",[s,t,s]);return n?{version:n.snapshot_version,data:"string"==typeof n.data?JSON.parse(n.data):n.data}:null}async getOps(s,t,n){const e=[s,t];let i="SELECT operation FROM operations WHERE doc_id = ? AND version >= ?";void 0!==n&&(i+=" AND version < ?",e.push(n)),i+=" ORDER BY version";return(await this.allAsync(i,e)).map((s=>JSON.parse(s.operation)))}async commitOp(s,t,n){return this.withTransaction((async()=>{const e=await this.getAsync("SELECT version FROM documents WHERE id = ?",[s]);if(t.create){if(e)return!1;await this.runAsync("INSERT INTO documents (id, type, version, snapshot_version) VALUES (?, ?, ?, ?)",[s,n.type,n.version,n.snapshotVersion]),await this.runAsync("INSERT INTO operations (doc_id, version, operation) VALUES (?, ?, ?)",[s,t.v,JSON.stringify(t)])}else if(t.del){if(!e)return!1;await this.runAsync("DELETE FROM documents WHERE id = ?",[s])}else{if(!e||t.v!==e.version)return!1;await this.runAsync("INSERT INTO operations (doc_id, version, operation) VALUES (?, ?, ?)",[s,t.v,JSON.stringify(t)]),await this.runAsync("UPDATE documents SET version = ? WHERE id = ?",[n.version,s])}return!0}))}async commitSnapshot(s,t){return this.withTransaction((async()=>{const n=await this.getAsync("SELECT snapshot_version FROM documents WHERE id = ?",[s]);if(!n||t.fromVersion!==n.snapshot_version||t.v<=n.snapshot_version)return!1;await this.runAsync("UPDATE documents SET snapshot_version = ? WHERE id = ?",[t.v,s]);const{deleteSnapshot:e,setSnapshotFragments:i,createFragments:r,updateFragments:o,deleteFragments:a}=t.fragmentsChanges;if(e)await this.runAsync("DELETE FROM snapshot_fragments WHERE doc_id = ?",[s]);else if(i){await this.runAsync("DELETE FROM snapshot_fragments WHERE doc_id = ?",[s]);for(const[t,n]of Object.entries(i))await this.runAsync("INSERT INTO snapshot_fragments (doc_id, fragment_id, data) VALUES (?, ?, ?)",[s,t,JSON.stringify(n)])}else{if(r)for(const[t,n]of Object.entries(r))await this.runAsync("INSERT INTO snapshot_fragments (doc_id, fragment_id, data) VALUES (?, ?, ?)",[s,t,JSON.stringify(n)]);if(o)for(const[t,n]of Object.entries(o))await this.runAsync("UPDATE snapshot_fragments SET data = ? WHERE doc_id = ? AND fragment_id = ?",[JSON.stringify(n),s,t]);if(a)for(const t of a)await this.runAsync("DELETE FROM snapshot_fragments WHERE doc_id = ? AND fragment_id = ?",[s,t])}return!0}))}async close(){return new Promise(((s,t)=>{this.db.close((n=>n?t(n):s()))}))}}s.SqliteDb=n})(),i})()));
|
|
12
|
+
!function(s,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@mescius/js-collaboration-ot"));else if("function"==typeof define&&define.amd)define(["@mescius/js-collaboration-ot"],t);else{var n="object"==typeof exports?t(require("@mescius/js-collaboration-ot")):t(s["@mescius/js-collaboration-ot"]);for(var e in n)("object"==typeof exports?exports:s)[e]=n[e]}}(this,(s=>(()=>{"use strict";var t={252:t=>{t.exports=s}},n={};function e(s){var i=n[s];if(void 0!==i)return i.exports;var r=n[s]={exports:{}};return t[s](r,r.exports,e),r.exports}var i={};return(()=>{var s=i;Object.defineProperty(s,"__esModule",{value:!0}),s.SqliteDb=void 0;const t=e(252);class n extends t.Db{constructor(s){super(),this.db=s}async init(s=!1){return new Promise((t=>{this.db.serialize((()=>{s&&(this.db.run("DROP TABLE IF EXISTS documents"),this.db.run("DROP TABLE IF EXISTS operations"),this.db.run("DROP TABLE IF EXISTS snapshot_fragments")),this.db.run("CREATE TABLE IF NOT EXISTS documents (\n id TEXT PRIMARY KEY,\n type TEXT NOT NULL,\n version INTEGER NOT NULL,\n snapshot_version INTEGER NOT NULL\n )"),this.db.run("CREATE TABLE IF NOT EXISTS operations (\n doc_id TEXT NOT NULL,\n version INTEGER NOT NULL,\n operation TEXT NOT NULL,\n PRIMARY KEY (doc_id, version),\n FOREIGN KEY (doc_id) REFERENCES documents (id) ON DELETE CASCADE\n )"),this.db.run("CREATE TABLE IF NOT EXISTS snapshot_fragments (\n doc_id TEXT NOT NULL,\n fragment_id TEXT NOT NULL,\n data TEXT NOT NULL,\n PRIMARY KEY (doc_id, fragment_id),\n FOREIGN KEY (doc_id) REFERENCES documents (id) ON DELETE CASCADE\n )"),t()}))}))}runAsync(s,t=[]){return new Promise(((n,e)=>{this.db.run(s,t,(s=>s?e(s):n()))}))}getAsync(s,t=[]){return new Promise(((n,e)=>{this.db.get(s,t,((s,t)=>s?e(s):n(t)))}))}allAsync(s,t=[]){return new Promise(((n,e)=>{this.db.all(s,t,((s,t)=>s?e(s):n(t)))}))}async withTransaction(s){return new Promise((t=>{this.db.serialize((async()=>{try{await this.runAsync("BEGIN");try{const n=await s();await this.runAsync("COMMIT"),t(n)}catch(s){await this.runAsync("ROLLBACK"),t(!1)}}catch(s){t(!1)}}))}))}async getDocument(s){const t=await this.getAsync("SELECT id, type, version, snapshot_version FROM documents WHERE id = ?",[s]);return t?{id:t.id,type:t.type,version:t.version,snapshotVersion:t.snapshot_version}:null}async getSnapshot(s){const t=await this.allAsync("SELECT d.id, d.type, d.snapshot_version, sf.fragment_id, sf.data FROM documents d LEFT JOIN snapshot_fragments sf ON d.id = sf.doc_id WHERE d.id = ?",[s]);if(0===t.length)return null;const n=t[0],e=this._parseFragmentRows(t);return{id:n.id,v:n.snapshot_version,type:n.type,fragments:e}}_parseFragmentRows(s){const t={};for(const n of s)n.fragment_id&&(t[n.fragment_id]=JSON.parse(n.data));return t}async getFragment(s,t){const n=await this.getAsync("SELECT d.snapshot_version, sf.data FROM documents d LEFT JOIN snapshot_fragments sf ON d.id = sf.doc_id AND sf.doc_id = ? AND sf.fragment_id = ? WHERE d.id = ?",[s,t,s]);return n?{version:n.snapshot_version,data:"string"==typeof n.data?JSON.parse(n.data):n.data}:null}async getOps(s,t,n){const e=[s,t];let i="SELECT operation FROM operations WHERE doc_id = ? AND version >= ?";void 0!==n&&(i+=" AND version < ?",e.push(n)),i+=" ORDER BY version";return(await this.allAsync(i,e)).map((s=>JSON.parse(s.operation)))}async commitOp(s,t,n){return this.withTransaction((async()=>{const e=await this.getAsync("SELECT version FROM documents WHERE id = ?",[s]);if(t.create){if(e)return!1;await this.runAsync("INSERT INTO documents (id, type, version, snapshot_version) VALUES (?, ?, ?, ?)",[s,n.type,n.version,n.snapshotVersion]),await this.runAsync("INSERT INTO operations (doc_id, version, operation) VALUES (?, ?, ?)",[s,t.v,JSON.stringify(t)])}else if(t.del){if(!e)return!1;await this.runAsync("DELETE FROM snapshot_fragments WHERE doc_id = ?",[s]),await this.runAsync("DELETE FROM operations WHERE doc_id = ?",[s]),await this.runAsync("DELETE FROM documents WHERE id = ?",[s])}else{if(!e||t.v!==e.version)return!1;await this.runAsync("INSERT INTO operations (doc_id, version, operation) VALUES (?, ?, ?)",[s,t.v,JSON.stringify(t)]),await this.runAsync("UPDATE documents SET version = ? WHERE id = ?",[n.version,s])}return!0}))}async commitSnapshot(s,t){return this.withTransaction((async()=>{const n=await this.getAsync("SELECT snapshot_version FROM documents WHERE id = ?",[s]);if(!n||t.fromVersion!==n.snapshot_version||t.v<=n.snapshot_version)return!1;await this.runAsync("UPDATE documents SET snapshot_version = ? WHERE id = ?",[t.v,s]);const{deleteSnapshot:e,setSnapshotFragments:i,createFragments:r,updateFragments:o,deleteFragments:a}=t.fragmentsChanges;if(e)await this.runAsync("DELETE FROM snapshot_fragments WHERE doc_id = ?",[s]);else if(i){await this.runAsync("DELETE FROM snapshot_fragments WHERE doc_id = ?",[s]);for(const[t,n]of Object.entries(i))await this.runAsync("INSERT INTO snapshot_fragments (doc_id, fragment_id, data) VALUES (?, ?, ?)",[s,t,JSON.stringify(n)])}else{if(r)for(const[t,n]of Object.entries(r))await this.runAsync("INSERT INTO snapshot_fragments (doc_id, fragment_id, data) VALUES (?, ?, ?)",[s,t,JSON.stringify(n)]);if(o)for(const[t,n]of Object.entries(o))await this.runAsync("UPDATE snapshot_fragments SET data = ? WHERE doc_id = ? AND fragment_id = ?",[JSON.stringify(n),s,t]);if(a)for(const t of a)await this.runAsync("DELETE FROM snapshot_fragments WHERE doc_id = ? AND fragment_id = ?",[s,t])}return!0}))}async close(){return new Promise(((s,t)=>{this.db.close((n=>n?t(n):s()))}))}}s.SqliteDb=n})(),i})()));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mescius/js-collaboration-ot-sqlite",
|
|
3
|
-
"version": "19.0.
|
|
3
|
+
"version": "19.0.2",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"license": "Commercial",
|
|
27
27
|
"description": "SpreadJS Collaboration plugin",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@mescius/js-collaboration-ot": "19.0.
|
|
29
|
+
"@mescius/js-collaboration-ot": "19.0.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"sqlite3": "^5.1.7"
|