@grapecity-software/js-collaboration-ot-sqlite 18.0.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/README.md +17 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +1 -0
- package/package.json +35 -0
- package/wrapper.mjs +7 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# SpreadJS Collaboration Plugin
|
|
2
|
+
|
|
3
|
+
js collaboration ot sqlite 是 [SpreadJS](https://www.grapecity.com.cn/developer/spreadjs) 的插件之一
|
|
4
|
+
|
|
5
|
+
它通过增加 协同 支持,扩展了 SpreadJS 的功能。
|
|
6
|
+
|
|
7
|
+
有关 SpreadJS 模块和插件的详细列表,请参见 [SpreadJS 组件库](https://demo.grapecity.com.cn/spreadjs/help/docs/getstarted/modules)
|
|
8
|
+
|
|
9
|
+
## 安装模块/插件
|
|
10
|
+
```sh
|
|
11
|
+
npm install @grapecity-software/js-collaboration-ot-sqlite
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 获取更多帮助
|
|
15
|
+
想需要获取更多产品信息,请浏览 [SpreadJS 主页](https://www.grapecity.com.cn/developer/spreadjs)
|
|
16
|
+
|
|
17
|
+
您可以在论坛中提出任何您使用产品过程中遇到的问题: [技术支持论坛](https://gcdn.grapecity.com.cn/showforum-232-1.html)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Database } from 'sqlite3';
|
|
2
|
+
import { Db, IOp, ICommitSnapshot, ISnapshot, IDocument, ISnapshotFragments } from "@grapecity-software/js-collaboration-ot";
|
|
3
|
+
export declare class SqliteDb<S = unknown, T = unknown> extends Db<S, T> {
|
|
4
|
+
constructor(db: Database);
|
|
5
|
+
getDocument(roomId: string): Promise<IDocument | undefined>;
|
|
6
|
+
getSnapshot(roomId: string): Promise<ISnapshot<S> | undefined>;
|
|
7
|
+
getFragment(roomId: string, fragmentId: string): Promise<S | undefined>;
|
|
8
|
+
getFragments(roomId: string): Promise<ISnapshotFragments<S>>;
|
|
9
|
+
getOps(roomId: string, fromVersion: number, toVersion?: number): Promise<IOp<T>[]>;
|
|
10
|
+
commitOp(id: string, op: IOp<T>, document: IDocument): Promise<boolean>;
|
|
11
|
+
commitSnapshot(roomId: string, snapshot: ICommitSnapshot<S>): Promise<boolean>;
|
|
12
|
+
close(): Promise<void>;
|
|
13
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,n){if("object"==typeof exports&&"object"==typeof module)module.exports=n(require("@grapecity-software/js-collaboration-ot"));else if("function"==typeof define&&define.amd)define(["@grapecity-software/js-collaboration-ot"],n);else{var s="object"==typeof exports?n(require("@grapecity-software/js-collaboration-ot")):n(t["@grapecity-software/js-collaboration-ot"]);for(var e in s)("object"==typeof exports?exports:t)[e]=s[e]}}(this,(t=>(()=>{"use strict";var n={288:n=>{n.exports=t}},s={};function e(t){var i=s[t];if(void 0!==i)return i.exports;var r=s[t]={exports:{}};return n[t](r,r.exports,e),r.exports}var i={};return(()=>{var t=i;Object.defineProperty(t,"__esModule",{value:!0}),t.SqliteDb=void 0;const n=e(288);class s extends n.Db{constructor(t){super(),this.db=t}async init(t=!1){return new Promise((n=>{this.db.serialize((()=>{t&&(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 )"),n()}))}))}runAsync(t,n=[]){return new Promise(((s,e)=>{this.db.run(t,n,(t=>t?e(t):s()))}))}getAsync(t,n=[]){return new Promise(((s,e)=>{this.db.get(t,n,((t,n)=>t?e(t):s(n)))}))}allAsync(t,n=[]){return new Promise(((s,e)=>{this.db.all(t,n,((t,n)=>t?e(t):s(n)))}))}async withTransaction(t){return new Promise((n=>{this.db.serialize((async()=>{try{await this.runAsync("BEGIN");try{const s=await t();await this.runAsync("COMMIT"),n(s)}catch(t){await this.runAsync("ROLLBACK"),n(!1)}}catch(t){n(!1)}}))}))}async getDocument(t){const n=await this.getAsync("SELECT id, type, version, snapshot_version FROM documents WHERE id = ?",[t]);if(n)return{id:n.id,type:n.type,version:n.version,snapshotVersion:n.snapshot_version}}async getSnapshot(t){const n=await this.getDocument(t);if(!n)return;const s=await this.getFragments(t);return{id:n.id,v:n.snapshotVersion,type:n.type,fragments:s}}async getFragment(t,n){const s=await this.getAsync("SELECT data FROM snapshot_fragments WHERE doc_id = ? AND fragment_id = ?",[t,n]);return s?JSON.parse(s.data):void 0}async getFragments(t){return(await this.allAsync("SELECT fragment_id, data FROM snapshot_fragments WHERE doc_id = ?",[t])).reduce(((t,n)=>(t[n.fragment_id]=JSON.parse(n.data),t)),{})}async getOps(t,n,s){const e=[t,n];let i="SELECT operation FROM operations WHERE doc_id = ? AND version >= ?";return void 0!==s&&(i+=" AND version < ?",e.push(s)),i+=" ORDER BY version",(await this.allAsync(i,e)).map((t=>JSON.parse(t.operation)))}async commitOp(t,n,s){return this.withTransaction((async()=>{const e=await this.getAsync("SELECT version FROM documents WHERE id = ?",[t]);if(n.create){if(e)return!1;await this.runAsync("INSERT INTO documents (id, type, version, snapshot_version) VALUES (?, ?, ?, ?)",[t,s.type,s.version,s.snapshotVersion]),await this.runAsync("INSERT INTO operations (doc_id, version, operation) VALUES (?, ?, ?)",[t,n.v,JSON.stringify(n)])}else if(n.del){if(!e)return!1;await this.runAsync("DELETE FROM documents WHERE id = ?",[t])}else{if(!e||n.v!==e.version)return!1;await this.runAsync("INSERT INTO operations (doc_id, version, operation) VALUES (?, ?, ?)",[t,n.v,JSON.stringify(n)]),await this.runAsync("UPDATE documents SET version = ? WHERE id = ?",[s.version,t])}return!0}))}async commitSnapshot(t,n){return this.withTransaction((async()=>{const s=await this.getAsync("SELECT snapshot_version FROM documents WHERE id = ?",[t]);if(!s||n.fromVersion!==s.snapshot_version||n.v<=s.snapshot_version)return!1;await this.runAsync("UPDATE documents SET snapshot_version = ? WHERE id = ?",[n.v,t]);const{deleteSnapshot:e,createFragments:i,updateFragments:r,deleteFragments:o}=n.fragmentsChanges;if(e)await this.runAsync("DELETE FROM snapshot_fragments WHERE doc_id = ?",[t]);else{if(i)for(const[n,s]of Object.entries(i))await this.runAsync("INSERT INTO snapshot_fragments (doc_id, fragment_id, data) VALUES (?, ?, ?)",[t,n,JSON.stringify(s)]);if(r)for(const[n,s]of Object.entries(r))await this.runAsync("UPDATE snapshot_fragments SET data = ? WHERE doc_id = ? AND fragment_id = ?",[JSON.stringify(s),t,n]);if(o)for(const n of o)await this.runAsync("DELETE FROM snapshot_fragments WHERE doc_id = ? AND fragment_id = ?",[t,n])}return!0}))}async close(){return new Promise(((t,n)=>{this.db.close((s=>s?n(s):t()))}))}}t.SqliteDb=s})(),i})()));
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@grapecity-software/js-collaboration-ot-sqlite",
|
|
3
|
+
"version": "18.0.0",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./wrapper.mjs",
|
|
9
|
+
"require": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"js-collaboration-ot-sqlite",
|
|
13
|
+
"js-collaboration-ot",
|
|
14
|
+
"js-collaboration",
|
|
15
|
+
"collaboration",
|
|
16
|
+
"spread",
|
|
17
|
+
"sheet",
|
|
18
|
+
"javascript",
|
|
19
|
+
"excel",
|
|
20
|
+
"spreadjs"
|
|
21
|
+
],
|
|
22
|
+
"author": {
|
|
23
|
+
"email": "info.xa@grapecity.com",
|
|
24
|
+
"name": "GrapeCity Software inc"
|
|
25
|
+
},
|
|
26
|
+
"license": "Commercial",
|
|
27
|
+
"description": "SpreadJS Collaboration plugin",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@grapecity-software/js-collaboration-ot": "18.0.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"sqlite3": "^5.1.7"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "http://www.grapecity.com.cn/"
|
|
35
|
+
}
|