@univerjs-pro/collaboration-comment-database-sqlite 1.0.0-insiders.20260808-70eefdd → 1.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 +37 -0
- package/README.zh-CN.md +42 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +4 -7
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @univerjs-pro/collaboration-comment-database-sqlite
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
A persistent SQLite `ICommentDatabaseAdapter` for `@univerjs-pro/collaboration-comment-service`. It uses the stable synchronous `libsql` API, supports Node.js 22 and later, and can share a database file with the core, History, and Worktree SQLite Adapters.
|
|
6
|
+
|
|
7
|
+
## Installation and usage
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add \
|
|
11
|
+
@univerjs-pro/collaboration-comment-service \
|
|
12
|
+
@univerjs-pro/collaboration-comment-database-sqlite
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
const commentDatabase = new SQLiteCommentDatabaseAdapter({
|
|
17
|
+
filename: './data/collaboration.sqlite',
|
|
18
|
+
busyTimeoutMs: 5_000,
|
|
19
|
+
});
|
|
20
|
+
const commentService = new UniverCommentService({
|
|
21
|
+
database: commentDatabase,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await commentService.dispose();
|
|
25
|
+
await commentDatabase.dispose();
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The caller must create the database parent directory in advance and dispose the Adapter after stopping the Service.
|
|
29
|
+
|
|
30
|
+
## Storage contract
|
|
31
|
+
|
|
32
|
+
- Comment data is stored in `collaboration_comments`.
|
|
33
|
+
- Schema version `('comment', 1)` is stored in shared `collaboration_schema_versions`; `PRAGMA user_version` is not used.
|
|
34
|
+
- Compound checks and writes use SQLite transactions. Deletes use a non-reusable concurrency version to avoid overwriting newer data.
|
|
35
|
+
- An empty Comment schema is initialized automatically. Incomplete or unsupported schemas are rejected without migration or legacy fallback.
|
|
36
|
+
|
|
37
|
+
Comment tables are independent of core snapshots and changesets. A core hard delete does not automatically clean up Comments; the application must coordinate cross-module cleanup when required.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# @univerjs-pro/collaboration-comment-database-sqlite
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | [简体中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
面向 `@univerjs-pro/collaboration-comment-service` 的持久化 SQLite
|
|
6
|
+
`ICommentDatabaseAdapter`。它使用稳定的 `libsql` 同步接口,支持 Node.js 22 及以上,
|
|
7
|
+
并可与 core、History 和 Worktree SQLite Adapter 共用数据库文件。
|
|
8
|
+
|
|
9
|
+
## 安装与使用
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add \
|
|
13
|
+
@univerjs-pro/collaboration-comment-service \
|
|
14
|
+
@univerjs-pro/collaboration-comment-database-sqlite
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
const commentDatabase = new SQLiteCommentDatabaseAdapter({
|
|
19
|
+
filename: './data/collaboration.sqlite',
|
|
20
|
+
busyTimeoutMs: 5_000,
|
|
21
|
+
});
|
|
22
|
+
const commentService = new UniverCommentService({
|
|
23
|
+
database: commentDatabase,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
await commentService.dispose();
|
|
27
|
+
await commentDatabase.dispose();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
调用方必须预先创建数据库父目录,并在 Service 停止后释放 Adapter。
|
|
31
|
+
|
|
32
|
+
## 存储契约
|
|
33
|
+
|
|
34
|
+
- Comment 数据保存在 `collaboration_comments`。
|
|
35
|
+
- schema 版本 `('comment', 1)` 记录在共享的
|
|
36
|
+
`collaboration_schema_versions`,不占用 `PRAGMA user_version`。
|
|
37
|
+
- 复合检查与写入使用 SQLite transaction;删除时使用不可复用的并发版本防止覆盖新数据。
|
|
38
|
+
- 空 Comment schema 自动初始化;不完整或不支持的 schema 会被拒绝,不执行 migration
|
|
39
|
+
或 legacy fallback。
|
|
40
|
+
|
|
41
|
+
Comment 表独立于 core snapshot/changeset。core hard delete 不会自动清理 Comment;需要
|
|
42
|
+
跨模块清理时由应用统一协调。
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object['defineProperty'](exports,Symbol['toStringTag'],{'value':'Module'});var e=Object['create'],t=Object['defineProperty'],n=Object['getOwnPropertyDescriptor'],r=Object['getOwnPropertyNames'],i=Object['getPrototypeOf'],a=Object['prototype']['hasOwnProperty'],o=(_0x4968f3,_0x53abd6,_0xb9670e,_0x3a74d8)=>{if(_0x53abd6&&typeof _0x53abd6=='object'||typeof _0x53abd6=='function'){for(var _0x127db0=r(_0x53abd6),_0x3e2a91=0x0,_0x2c12a7=_0x127db0['length'],_0x3ca36d;_0x3e2a91<_0x2c12a7;_0x3e2a91++)_0x3ca36d=_0x127db0[_0x3e2a91],!a['call'](_0x4968f3,_0x3ca36d)&&_0x3ca36d!==_0xb9670e&&t(_0x4968f3,_0x3ca36d,{'get':(_0x32d171=>_0x53abd6[_0x32d171])['bind'](null,_0x3ca36d),'enumerable':!(_0x3a74d8=n(_0x53abd6,_0x3ca36d))||_0x3a74d8['enumerable']});}return _0x4968f3;},s=(_0x539928,_0x4b9a95,_0x2c5d63)=>(_0x2c5d63=_0x539928==null?{}:e(i(_0x539928)),o(_0x4b9a95||!_0x539928||!_0x539928['__esModule']?t(_0x2c5d63,'default',{'value':_0x539928,'enumerable':!0x0}):_0x2c5d63,_0x539928));let c=require('node:crypto'),l=require('libsql');l=s(l,0x1);let u=require('@univerjs/protocol');var d=0x1388,f='comment',p=0x1,m=['collaboration_comments'],h=class{['_database'];['_disposed']=!0x1;constructor(_0x50a128){b(_0x50a128),this['_database']=new l['default'](_0x50a128['filename'],{'timeout':_0x50a128['busyTimeoutMs']??d});try{this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0x50a128['busyTimeoutMs']??d)+';'),this['_initializeSchema']();}catch(_0x2dddeb){throw this['_database']['close'](),_0x2dddeb;}}async['createRoot'](_0xdaf43d,_0xa9d9e6){return this['_assertOpen'](),this['_transaction'](()=>{if(this['_getByReply'](_0xdaf43d['unitID'],_0xdaf43d['threadID']))return{'status':'duplicate'};let _0x2528cc=Date['now']();return this['_insert']({..._0xdaf43d,'replyID':_0xdaf43d['threadID'],'solved':u['CommentSolvedStatus']['OpenOrReOpen'],'createdAt':_0x2528cc,'updatedAt':_0x2528cc,'generation':(0x0,c['randomUUID'])()}),{'status':'created','record':this['_require'](_0xdaf43d['unitID'],_0xdaf43d['threadID'])};});}async['createReply'](_0xedec0c,_0x4960b4){return this['_assertOpen'](),this['_transaction'](()=>{if(this['_getByReply'](_0xedec0c['unitID'],_0xedec0c['replyID']))return{'status':'duplicate'};let _0x476ed6=this['_getByReply'](_0xedec0c['unitID'],_0xedec0c['threadID']);if(!_0x476ed6||_0x476ed6['threadID']!==_0x476ed6['replyID'])return{'status':'not-found'};if(_0x476ed6['solved']!==u['CommentSolvedStatus']['OpenOrReOpen'])return{'status':'closed'};let _0x490807=Date['now']();return this['_insert']({..._0xedec0c,'solved':_0x476ed6['solved'],'createdAt':_0x490807,'updatedAt':_0x490807,'generation':(0x0,c['randomUUID'])()}),{'status':'created','record':this['_require'](_0xedec0c['unitID'],_0xedec0c['replyID'])};});}async['getComment'](_0x38ae27,_0x3f3d39){this['_assertOpen']();let _0x52bf90=this['_getByReply'](_0x38ae27['unitID'],_0x38ae27['replyID']);return _0x52bf90?.['threadID']===_0x38ae27['threadID']?_0x52bf90:null;}async['listThreads'](_0xba0193,_0xd363c3){this['_assertOpen']();let _0xb1453a=[...new Set(_0xba0193['threadIDs'])];return(_0xb1453a['length']===0x0?this['_database']['prepare'](g+'\x20WHERE\x20unit_id\x20=\x20?')['all'](_0xba0193['unitID']):this['_database']['prepare'](g+'\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20thread_id\x20IN\x20('+_0xb1453a['map'](()=>'?')['join'](',')+')')['all'](_0xba0193['unitID'],..._0xb1453a))['map'](_)['sort'](v);}async['editComment'](_0x128c77,_0x5e4de9){return this['_assertOpen'](),this['_transaction'](()=>{let _0xe94de6=this['_getByReply'](_0x128c77['unitID'],_0x128c77['replyID']),_0x451e40=this['_getByReply'](_0x128c77['unitID'],_0x128c77['threadID']);return!_0xe94de6||_0xe94de6['threadID']!==_0x128c77['threadID']||!_0x451e40?{'status':'not-found'}:_0x451e40['solved']===u['CommentSolvedStatus']['OpenOrReOpen']?_0xe94de6['authorUserID']===_0x128c77['expectedAuthorUserID']?_0xe94de6['content']===_0x128c77['content']&&y(_0xe94de6['mentions'],_0x128c77['mentions'])?{'status':'unchanged','record':_0xe94de6}:(this['_database']['prepare']('UPDATE\x20collaboration_comments\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20content\x20=\x20?,\x20mentions_json\x20=\x20?,\x20updated_at\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20thread_id\x20=\x20?\x20AND\x20reply_id\x20=\x20?')['run'](_0x128c77['content'],JSON['stringify'](_0x128c77['mentions']),Math['max'](Date['now'](),_0xe94de6['updatedAt']+0x1),_0x128c77['unitID'],_0x128c77['threadID'],_0x128c77['replyID']),{'status':'edited','record':this['_require'](_0x128c77['unitID'],_0x128c77['replyID'])}):{'status':'author-mismatch'}:{'status':'closed'};});}async['setThreadSolved'](_0x32f177,_0x33c554){return this['_assertOpen'](),this['_transaction'](()=>{let _0x3f31a8=this['_getByReply'](_0x32f177['unitID'],_0x32f177['threadID']);return!_0x3f31a8||_0x3f31a8['threadID']!==_0x3f31a8['replyID']?{'status':'not-found'}:_0x3f31a8['solved']===_0x32f177['solved']?{'status':'unchanged'}:(this['_database']['prepare']('UPDATE\x20collaboration_comments\x20SET\x20solved\x20=\x20?,\x20updated_at\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20reply_id\x20=\x20?')['run'](_0x32f177['solved'],Math['max'](Date['now'](),_0x3f31a8['updatedAt']+0x1),_0x32f177['unitID'],_0x32f177['threadID']),{'status':'updated'});});}async['deleteComment'](_0x5e4a85,_0x59254b){return this['_assertOpen'](),this['_transaction'](()=>{let _0x43b4cc=_0x5e4a85['replyID']??_0x5e4a85['threadID'],_0x22c55=this['_getByReply'](_0x5e4a85['unitID'],_0x43b4cc);return!_0x22c55||_0x22c55['threadID']!==_0x5e4a85['threadID']?{'status':'not-found'}:_0x22c55['generation']===_0x5e4a85['expectedGeneration']?(_0x5e4a85['replyID']===void 0x0?this['_database']['prepare']('DELETE\x20FROM\x20collaboration_comments\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20thread_id\x20=\x20?')['run'](_0x5e4a85['unitID'],_0x5e4a85['threadID']):this['_database']['prepare']('DELETE\x20FROM\x20collaboration_comments\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20thread_id\x20=\x20?\x20AND\x20reply_id\x20=\x20?\x20AND\x20generation\x20=\x20?')['run'](_0x5e4a85['unitID'],_0x5e4a85['threadID'],_0x5e4a85['replyID'],_0x5e4a85['expectedGeneration']),{'status':'deleted'}):{'status':'generation-mismatch'};});}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_database']['close']());}['_initializeSchema'](){this['_transaction'](()=>{if(!this['_hasTable']('collaboration_schema_versions')){if(this['_hasAnyOwnedTable']())throw x('SQLite\x20Comment\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_schema_versions\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20component\x20TEXT\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20version\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(version\x20>=\x201)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x20\x20\x20\x20\x20\x20\x20\x20');}let _0x425566=this['_database']['prepare']('SELECT\x20version\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_schema_versions\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20component\x20=\x20?')['get'](f);if(_0x425566){if(_0x425566['version']!==p)throw x('SQLite\x20Comment\x20schema\x20version\x20'+_0x425566['version']+'\x20is\x20not\x20supported');let _0x707ef0=m['filter'](_0xcbe197=>!this['_hasTable'](_0xcbe197));if(_0x707ef0['length']>0x0)throw x('SQLite\x20Comment\x20schema\x20v1\x20is\x20incomplete:\x20missing\x20'+_0x707ef0['join'](',\x20'));return;}if(this['_hasAnyOwnedTable']())throw x('SQLite\x20Comment\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_comments\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20unit_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20thread_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20reply_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20author_user_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20content\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20mentions_json\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20solved\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20created_at\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20updated_at\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20generation\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20PRIMARY\x20KEY\x20(unit_id,\x20reply_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20INDEX\x20collaboration_comments_thread_lookup\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_comments(unit_id,\x20thread_id,\x20created_at,\x20reply_id);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20INSERT\x20INTO\x20collaboration_schema_versions\x20(component,\x20version)\x0a\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(\x27comment\x27,\x201);\x0a\x20\x20\x20\x20\x20\x20');});}['_hasTable'](_0x191d76){return!!this['_database']['prepare']('SELECT\x201\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20sqlite_schema\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20?')['get'](_0x191d76);}['_hasAnyOwnedTable'](){return m['some'](_0x1d5638=>this['_hasTable'](_0x1d5638));}['_insert'](_0x433198){this['_database']['prepare']('INSERT\x20INTO\x20collaboration_comments\x0a\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20thread_id,\x20reply_id,\x20author_user_id,\x20content,\x20mentions_json,\x0a\x20\x20\x20\x20\x20\x20\x20\x20solved,\x20created_at,\x20updated_at,\x20generation)\x0a\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?)')['run'](_0x433198['unitID'],_0x433198['threadID'],_0x433198['replyID'],_0x433198['authorUserID'],_0x433198['content'],JSON['stringify'](_0x433198['mentions']),_0x433198['solved'],_0x433198['createdAt'],_0x433198['updatedAt'],_0x433198['generation']);}['_getByReply'](_0x3261f5,_0x2b0d71){let _0x5b4709=this['_database']['prepare'](g+'\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20reply_id\x20=\x20?')['get'](_0x3261f5,_0x2b0d71);return _0x5b4709?_(_0x5b4709):null;}['_require'](_0x34bb51,_0x38b8e7){let _0x3caf1a=this['_getByReply'](_0x34bb51,_0x38b8e7);if(!_0x3caf1a)throw Error('SQLite\x20Comment\x20write\x20did\x20not\x20persist\x20its\x20record');return _0x3caf1a;}['_transaction'](_0x1080f8){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x3fc16a=_0x1080f8();return this['_database']['exec']('COMMIT;'),_0x3fc16a;}catch(_0x2f1641){try{this['_database']['exec']('ROLLBACK;');}catch{}throw _0x2f1641;}}['_assertOpen'](){if(this['_disposed'])throw Error('SQLite\x20Comment\x20Database\x20Adapter\x20is\x20disposed');}},g='SELECT\x20unit_id,\x20thread_id,\x20reply_id,\x20author_user_id,\x0a\x20\x20content,\x20mentions_json,\x20solved,\x20created_at,\x20updated_at,\x20generation\x0a\x20\x20FROM\x20collaboration_comments';function _(_0x16e8f9){let _0x2bf5bf=JSON['parse'](_0x16e8f9['mentions_json']);if(!Array['isArray'](_0x2bf5bf)||_0x2bf5bf['some'](_0x4b5906=>typeof _0x4b5906!='string'))throw Error('SQLite\x20Comment\x20contains\x20invalid\x20mentions');if(_0x16e8f9['solved']!==u['CommentSolvedStatus']['OpenOrReOpen']&&_0x16e8f9['solved']!==u['CommentSolvedStatus']['Solved'])throw Error('SQLite\x20Comment\x20contains\x20invalid\x20solved\x20status');return{'unitID':_0x16e8f9['unit_id'],'threadID':_0x16e8f9['thread_id'],'replyID':_0x16e8f9['reply_id'],'authorUserID':_0x16e8f9['author_user_id'],'content':_0x16e8f9['content'],'mentions':_0x2bf5bf,'solved':_0x16e8f9['solved'],'createdAt':_0x16e8f9['created_at'],'updatedAt':_0x16e8f9['updated_at'],'generation':_0x16e8f9['generation']};}function v(_0x5ebb7d,_0x20f79c){let _0xc5ff92=_0x5ebb7d['threadID']['localeCompare'](_0x20f79c['threadID']);return _0xc5ff92===0x0?_0x5ebb7d['replyID']===_0x5ebb7d['threadID']?-0x1:_0x20f79c['replyID']===_0x20f79c['threadID']?0x1:_0x5ebb7d['createdAt']-_0x20f79c['createdAt']||_0x5ebb7d['replyID']['localeCompare'](_0x20f79c['replyID']):_0xc5ff92;}function y(_0xbf4250,_0x5006f9){return _0xbf4250['length']===_0x5006f9['length']&&_0xbf4250['every']((_0xe24f2f,_0x5f19cb)=>_0xe24f2f===_0x5006f9[_0x5f19cb]);}function b(_0x5b811f){if(!_0x5b811f?.['filename'])throw TypeError('SQLiteCommentDatabaseAdapter\x20requires\x20a\x20filename');if(_0x5b811f['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x5b811f['busyTimeoutMs'])||_0x5b811f['busyTimeoutMs']<0x0))throw TypeError('busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20safe\x20integer');}function x(_0x1a7ae7){return Error(_0x1a7ae7);}exports['SQLiteCommentDatabaseAdapter']=h;
|
|
1
|
+
Object['defineProperty'](exports,Symbol['toStringTag'],{'value':'Module'});var e=Object['create'],t=Object['defineProperty'],n=Object['getOwnPropertyDescriptor'],r=Object['getOwnPropertyNames'],i=Object['getPrototypeOf'],a=Object['prototype']['hasOwnProperty'],o=(_0x1e0f31,_0x17bbb6,_0x651c50,_0xb22ca8)=>{if(_0x17bbb6&&typeof _0x17bbb6=='object'||typeof _0x17bbb6=='function'){for(var _0x4f0880=r(_0x17bbb6),_0x3f3778=0x0,_0x50d9a8=_0x4f0880['length'],_0x5c1570;_0x3f3778<_0x50d9a8;_0x3f3778++)_0x5c1570=_0x4f0880[_0x3f3778],!a['call'](_0x1e0f31,_0x5c1570)&&_0x5c1570!==_0x651c50&&t(_0x1e0f31,_0x5c1570,{'get':(_0x13350e=>_0x17bbb6[_0x13350e])['bind'](null,_0x5c1570),'enumerable':!(_0xb22ca8=n(_0x17bbb6,_0x5c1570))||_0xb22ca8['enumerable']});}return _0x1e0f31;},s=(_0x17dbd5,_0x16e695,_0x63991a)=>(_0x63991a=_0x17dbd5==null?{}:e(i(_0x17dbd5)),o(_0x16e695||!_0x17dbd5||!_0x17dbd5['__esModule']?t(_0x63991a,'default',{'value':_0x17dbd5,'enumerable':!0x0}):_0x63991a,_0x17dbd5));let c=require('node:crypto'),l=require('libsql');l=s(l,0x1);let u=require('@univerjs/protocol');var d=0x1388,f='comment',p=0x1,m=['collaboration_comments'],h=class{['_database'];['_disposed']=!0x1;constructor(_0x13b0ee){b(_0x13b0ee),this['_database']=new l['default'](_0x13b0ee['filename'],{'timeout':_0x13b0ee['busyTimeoutMs']??d});try{this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0x13b0ee['busyTimeoutMs']??d)+';'),this['_initializeSchema']();}catch(_0x359989){throw this['_database']['close'](),_0x359989;}}async['createRoot'](_0x55b752,_0x428a7f){return this['_assertOpen'](),this['_transaction'](()=>{if(this['_getByReply'](_0x55b752['unitID'],_0x55b752['threadID']))return{'status':'duplicate'};let _0x3c5597=Date['now']();return this['_insert']({..._0x55b752,'replyID':_0x55b752['threadID'],'solved':u['CommentSolvedStatus']['OpenOrReOpen'],'createdAt':_0x3c5597,'updatedAt':_0x3c5597,'generation':(0x0,c['randomUUID'])()}),{'status':'created','record':this['_require'](_0x55b752['unitID'],_0x55b752['threadID'])};});}async['createReply'](_0x464303,_0x345716){return this['_assertOpen'](),this['_transaction'](()=>{if(this['_getByReply'](_0x464303['unitID'],_0x464303['replyID']))return{'status':'duplicate'};let _0x246435=this['_getByReply'](_0x464303['unitID'],_0x464303['threadID']);if(!_0x246435||_0x246435['threadID']!==_0x246435['replyID'])return{'status':'not-found'};if(_0x246435['solved']!==u['CommentSolvedStatus']['OpenOrReOpen'])return{'status':'closed'};let _0x202da3=Date['now']();return this['_insert']({..._0x464303,'solved':_0x246435['solved'],'createdAt':_0x202da3,'updatedAt':_0x202da3,'generation':(0x0,c['randomUUID'])()}),{'status':'created','record':this['_require'](_0x464303['unitID'],_0x464303['replyID'])};});}async['getComment'](_0x4a676a,_0x4344cb){this['_assertOpen']();let _0x31dbf0=this['_getByReply'](_0x4a676a['unitID'],_0x4a676a['replyID']);return _0x31dbf0?.['threadID']===_0x4a676a['threadID']?_0x31dbf0:null;}async['listThreads'](_0x33f1d0,_0x2edb97){this['_assertOpen']();let _0x13a822=[...new Set(_0x33f1d0['threadIDs'])];return(_0x13a822['length']===0x0?this['_database']['prepare'](g+'\x20WHERE\x20unit_id\x20=\x20?')['all'](_0x33f1d0['unitID']):this['_database']['prepare'](g+'\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20thread_id\x20IN\x20('+_0x13a822['map'](()=>'?')['join'](',')+')')['all'](_0x33f1d0['unitID'],..._0x13a822))['map'](_)['sort'](v);}async['editComment'](_0x8c7abc,_0x1a983e){return this['_assertOpen'](),this['_transaction'](()=>{let _0x17620a=this['_getByReply'](_0x8c7abc['unitID'],_0x8c7abc['replyID']),_0x321c3c=this['_getByReply'](_0x8c7abc['unitID'],_0x8c7abc['threadID']);return!_0x17620a||_0x17620a['threadID']!==_0x8c7abc['threadID']||!_0x321c3c?{'status':'not-found'}:_0x321c3c['solved']===u['CommentSolvedStatus']['OpenOrReOpen']?_0x17620a['authorUserID']===_0x8c7abc['expectedAuthorUserID']?_0x17620a['content']===_0x8c7abc['content']&&y(_0x17620a['mentions'],_0x8c7abc['mentions'])?{'status':'unchanged','record':_0x17620a}:(this['_database']['prepare']('UPDATE\x20collaboration_comments\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20content\x20=\x20?,\x20mentions_json\x20=\x20?,\x20updated_at\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20thread_id\x20=\x20?\x20AND\x20reply_id\x20=\x20?')['run'](_0x8c7abc['content'],JSON['stringify'](_0x8c7abc['mentions']),Math['max'](Date['now'](),_0x17620a['updatedAt']+0x1),_0x8c7abc['unitID'],_0x8c7abc['threadID'],_0x8c7abc['replyID']),{'status':'edited','record':this['_require'](_0x8c7abc['unitID'],_0x8c7abc['replyID'])}):{'status':'author-mismatch'}:{'status':'closed'};});}async['setThreadSolved'](_0xd2bf38,_0x1a2dd4){return this['_assertOpen'](),this['_transaction'](()=>{let _0x1f14e5=this['_getByReply'](_0xd2bf38['unitID'],_0xd2bf38['threadID']);return!_0x1f14e5||_0x1f14e5['threadID']!==_0x1f14e5['replyID']?{'status':'not-found'}:_0x1f14e5['solved']===_0xd2bf38['solved']?{'status':'unchanged'}:(this['_database']['prepare']('UPDATE\x20collaboration_comments\x20SET\x20solved\x20=\x20?,\x20updated_at\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20reply_id\x20=\x20?')['run'](_0xd2bf38['solved'],Math['max'](Date['now'](),_0x1f14e5['updatedAt']+0x1),_0xd2bf38['unitID'],_0xd2bf38['threadID']),{'status':'updated'});});}async['deleteComment'](_0x59b2ff,_0x27a66c){return this['_assertOpen'](),this['_transaction'](()=>{let _0x42b397=_0x59b2ff['replyID']??_0x59b2ff['threadID'],_0x23681c=this['_getByReply'](_0x59b2ff['unitID'],_0x42b397);return!_0x23681c||_0x23681c['threadID']!==_0x59b2ff['threadID']?{'status':'not-found'}:_0x23681c['generation']===_0x59b2ff['expectedGeneration']?(_0x59b2ff['replyID']===void 0x0?this['_database']['prepare']('DELETE\x20FROM\x20collaboration_comments\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20thread_id\x20=\x20?')['run'](_0x59b2ff['unitID'],_0x59b2ff['threadID']):this['_database']['prepare']('DELETE\x20FROM\x20collaboration_comments\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20thread_id\x20=\x20?\x20AND\x20reply_id\x20=\x20?\x20AND\x20generation\x20=\x20?')['run'](_0x59b2ff['unitID'],_0x59b2ff['threadID'],_0x59b2ff['replyID'],_0x59b2ff['expectedGeneration']),{'status':'deleted'}):{'status':'generation-mismatch'};});}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_database']['close']());}['_initializeSchema'](){this['_transaction'](()=>{if(!this['_hasTable']('collaboration_schema_versions')){if(this['_hasAnyOwnedTable']())throw x('SQLite\x20Comment\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_schema_versions\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20component\x20TEXT\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20version\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(version\x20>=\x201)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x20\x20\x20\x20\x20\x20\x20\x20');}let _0x30e05b=this['_database']['prepare']('SELECT\x20version\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_schema_versions\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20component\x20=\x20?')['get'](f);if(_0x30e05b){if(_0x30e05b['version']!==p)throw x('SQLite\x20Comment\x20schema\x20version\x20'+_0x30e05b['version']+'\x20is\x20not\x20supported');let _0x122844=m['filter'](_0x37f75b=>!this['_hasTable'](_0x37f75b));if(_0x122844['length']>0x0)throw x('SQLite\x20Comment\x20schema\x20v1\x20is\x20incomplete:\x20missing\x20'+_0x122844['join'](',\x20'));return;}if(this['_hasAnyOwnedTable']())throw x('SQLite\x20Comment\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_comments\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20unit_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20thread_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20reply_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20author_user_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20content\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20mentions_json\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20solved\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20created_at\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20updated_at\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20generation\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20PRIMARY\x20KEY\x20(unit_id,\x20reply_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20INDEX\x20collaboration_comments_thread_lookup\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_comments(unit_id,\x20thread_id,\x20created_at,\x20reply_id);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20INSERT\x20INTO\x20collaboration_schema_versions\x20(component,\x20version)\x0a\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(\x27comment\x27,\x201);\x0a\x20\x20\x20\x20\x20\x20');});}['_hasTable'](_0x54070d){return!!this['_database']['prepare']('SELECT\x201\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20sqlite_schema\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20?')['get'](_0x54070d);}['_hasAnyOwnedTable'](){return m['some'](_0x5e4884=>this['_hasTable'](_0x5e4884));}['_insert'](_0x4393f3){this['_database']['prepare']('INSERT\x20INTO\x20collaboration_comments\x0a\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20thread_id,\x20reply_id,\x20author_user_id,\x20content,\x20mentions_json,\x0a\x20\x20\x20\x20\x20\x20\x20\x20solved,\x20created_at,\x20updated_at,\x20generation)\x0a\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?)')['run'](_0x4393f3['unitID'],_0x4393f3['threadID'],_0x4393f3['replyID'],_0x4393f3['authorUserID'],_0x4393f3['content'],JSON['stringify'](_0x4393f3['mentions']),_0x4393f3['solved'],_0x4393f3['createdAt'],_0x4393f3['updatedAt'],_0x4393f3['generation']);}['_getByReply'](_0x1415e1,_0x5f650d){let _0x500d98=this['_database']['prepare'](g+'\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20reply_id\x20=\x20?')['get'](_0x1415e1,_0x5f650d);return _0x500d98?_(_0x500d98):null;}['_require'](_0x57d632,_0x4940c6){let _0x18094d=this['_getByReply'](_0x57d632,_0x4940c6);if(!_0x18094d)throw Error('SQLite\x20Comment\x20write\x20did\x20not\x20persist\x20its\x20record');return _0x18094d;}['_transaction'](_0x29810d){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x43ebdc=_0x29810d();return this['_database']['exec']('COMMIT;'),_0x43ebdc;}catch(_0x43145e){try{this['_database']['exec']('ROLLBACK;');}catch{}throw _0x43145e;}}['_assertOpen'](){if(this['_disposed'])throw Error('SQLite\x20Comment\x20Database\x20Adapter\x20is\x20disposed');}},g='SELECT\x20unit_id,\x20thread_id,\x20reply_id,\x20author_user_id,\x0a\x20\x20content,\x20mentions_json,\x20solved,\x20created_at,\x20updated_at,\x20generation\x0a\x20\x20FROM\x20collaboration_comments';function _(_0x10517c){let _0x13a8b8=JSON['parse'](_0x10517c['mentions_json']);if(!Array['isArray'](_0x13a8b8)||_0x13a8b8['some'](_0x498204=>typeof _0x498204!='string'))throw Error('SQLite\x20Comment\x20contains\x20invalid\x20mentions');if(_0x10517c['solved']!==u['CommentSolvedStatus']['OpenOrReOpen']&&_0x10517c['solved']!==u['CommentSolvedStatus']['Solved'])throw Error('SQLite\x20Comment\x20contains\x20invalid\x20solved\x20status');return{'unitID':_0x10517c['unit_id'],'threadID':_0x10517c['thread_id'],'replyID':_0x10517c['reply_id'],'authorUserID':_0x10517c['author_user_id'],'content':_0x10517c['content'],'mentions':_0x13a8b8,'solved':_0x10517c['solved'],'createdAt':_0x10517c['created_at'],'updatedAt':_0x10517c['updated_at'],'generation':_0x10517c['generation']};}function v(_0x4b3b2e,_0x580193){let _0x42c558=_0x4b3b2e['threadID']['localeCompare'](_0x580193['threadID']);return _0x42c558===0x0?_0x4b3b2e['replyID']===_0x4b3b2e['threadID']?-0x1:_0x580193['replyID']===_0x580193['threadID']?0x1:_0x4b3b2e['createdAt']-_0x580193['createdAt']||_0x4b3b2e['replyID']['localeCompare'](_0x580193['replyID']):_0x42c558;}function y(_0x1044c3,_0x145de7){return _0x1044c3['length']===_0x145de7['length']&&_0x1044c3['every']((_0xb283d4,_0x22d419)=>_0xb283d4===_0x145de7[_0x22d419]);}function b(_0x173726){if(!_0x173726?.['filename'])throw TypeError('SQLiteCommentDatabaseAdapter\x20requires\x20a\x20filename');if(_0x173726['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x173726['busyTimeoutMs'])||_0x173726['busyTimeoutMs']<0x0))throw TypeError('busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20safe\x20integer');}function x(_0x1807d4){return Error(_0x1807d4);}exports['SQLiteCommentDatabaseAdapter']=h;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function _0x5d6e(_0xd8899,_0x2de910){_0xd8899=_0xd8899-0xe1;const _0x2587fd=_0x2587();let _0x5d6ef5=_0x2587fd[_0xd8899];return _0x5d6ef5;}(function(_0x1a58bd,_0x56b060){const _0x2c0c34=_0x5d6e,_0x438447=_0x1a58bd();while(!![]){try{const _0x391e65=-parseInt(_0x2c0c34(0xe2))/0x1*(-parseInt(_0x2c0c34(0xe3))/0x2)+parseInt(_0x2c0c34(0xe7))/0x3+-parseInt(_0x2c0c34(0xec))/0x4*(-parseInt(_0x2c0c34(0xe8))/0x5)+-parseInt(_0x2c0c34(0xe4))/0x6*(parseInt(_0x2c0c34(0xeb))/0x7)+parseInt(_0x2c0c34(0xe9))/0x8+parseInt(_0x2c0c34(0xe6))/0x9*(-parseInt(_0x2c0c34(0xe5))/0xa)+-parseInt(_0x2c0c34(0xe1))/0xb*(parseInt(_0x2c0c34(0xea))/0xc);if(_0x391e65===_0x56b060)break;else _0x438447['push'](_0x438447['shift']());}catch(_0x5b5cac){_0x438447['push'](_0x438447['shift']());}}}(_0x2587,0xc64b1));import _0x157562 from'./index.cjs';const facadeExport0=_0x157562['SQLiteCommentDatabaseAdapter'];function _0x2587(){const _0x326a81=['145etwnWB','6113496plDVMk','239964ERqXcM','124082VcZPHA','111404scSGtw','121NohYXi','455YrQAdu','1398MMYcqr','318JDJOKF','1269640wqPMwt','45kLCYhG','2149689zFKSIa'];_0x2587=function(){return _0x326a81;};return _0x2587();}export{facadeExport0 as SQLiteCommentDatabaseAdapter};
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=22"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.0.0
|
|
7
|
+
"version": "1.0.0",
|
|
8
8
|
"main": "./dist/index.cjs",
|
|
9
9
|
"module": "./dist/index.mjs",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
@@ -19,11 +19,8 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@univerjs-pro/collaboration-comment-service": "1.0.0
|
|
23
|
-
"@univerjs/protocol": "1.0.0
|
|
22
|
+
"@univerjs-pro/collaboration-comment-service": "1.0.0",
|
|
23
|
+
"@univerjs/protocol": "1.0.0",
|
|
24
24
|
"libsql": "^0.5.29"
|
|
25
|
-
},
|
|
26
|
-
"publishConfig": {
|
|
27
|
-
"access": "public"
|
|
28
25
|
}
|
|
29
|
-
}
|
|
26
|
+
}
|