@univerjs-pro/collaboration-comment-database-sqlite 1.0.0-insiders.20260808-70eefdd → 1.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/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=(_0x2e4b8f,_0x24b5f4,_0x5acf91,_0x2e9c4b)=>{if(_0x24b5f4&&typeof _0x24b5f4=='object'||typeof _0x24b5f4=='function'){for(var _0x1fb9ce=r(_0x24b5f4),_0x3267b7=0x0,_0x487dca=_0x1fb9ce['length'],_0x5616e7;_0x3267b7<_0x487dca;_0x3267b7++)_0x5616e7=_0x1fb9ce[_0x3267b7],!a['call'](_0x2e4b8f,_0x5616e7)&&_0x5616e7!==_0x5acf91&&t(_0x2e4b8f,_0x5616e7,{'get':(_0x43fd10=>_0x24b5f4[_0x43fd10])['bind'](null,_0x5616e7),'enumerable':!(_0x2e9c4b=n(_0x24b5f4,_0x5616e7))||_0x2e9c4b['enumerable']});}return _0x2e4b8f;},s=(_0x1f4d7d,_0x3d44bf,_0x3ad4eb)=>(_0x3ad4eb=_0x1f4d7d==null?{}:e(i(_0x1f4d7d)),o(_0x3d44bf||!_0x1f4d7d||!_0x1f4d7d['__esModule']?t(_0x3ad4eb,'default',{'value':_0x1f4d7d,'enumerable':!0x0}):_0x3ad4eb,_0x1f4d7d));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(_0x157bad){b(_0x157bad),this['_database']=new l['default'](_0x157bad['filename'],{'timeout':_0x157bad['busyTimeoutMs']??d});try{this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0x157bad['busyTimeoutMs']??d)+';'),this['_initializeSchema']();}catch(_0x30e528){throw this['_database']['close'](),_0x30e528;}}async['createRoot'](_0x22aae8,_0x375bc2){return this['_assertOpen'](),this['_transaction'](()=>{if(this['_getByReply'](_0x22aae8['unitID'],_0x22aae8['threadID']))return{'status':'duplicate'};let _0x17c22b=Date['now']();return this['_insert']({..._0x22aae8,'replyID':_0x22aae8['threadID'],'solved':u['CommentSolvedStatus']['OpenOrReOpen'],'createdAt':_0x17c22b,'updatedAt':_0x17c22b,'generation':(0x0,c['randomUUID'])()}),{'status':'created','record':this['_require'](_0x22aae8['unitID'],_0x22aae8['threadID'])};});}async['createReply'](_0x516e38,_0xeda11c){return this['_assertOpen'](),this['_transaction'](()=>{if(this['_getByReply'](_0x516e38['unitID'],_0x516e38['replyID']))return{'status':'duplicate'};let _0x59a179=this['_getByReply'](_0x516e38['unitID'],_0x516e38['threadID']);if(!_0x59a179||_0x59a179['threadID']!==_0x59a179['replyID'])return{'status':'not-found'};if(_0x59a179['solved']!==u['CommentSolvedStatus']['OpenOrReOpen'])return{'status':'closed'};let _0x36389b=Date['now']();return this['_insert']({..._0x516e38,'solved':_0x59a179['solved'],'createdAt':_0x36389b,'updatedAt':_0x36389b,'generation':(0x0,c['randomUUID'])()}),{'status':'created','record':this['_require'](_0x516e38['unitID'],_0x516e38['replyID'])};});}async['getComment'](_0x308b93,_0x1a15ab){this['_assertOpen']();let _0xc791ff=this['_getByReply'](_0x308b93['unitID'],_0x308b93['replyID']);return _0xc791ff?.['threadID']===_0x308b93['threadID']?_0xc791ff:null;}async['listThreads'](_0x1f633a,_0x492c27){this['_assertOpen']();let _0x136023=[...new Set(_0x1f633a['threadIDs'])];return(_0x136023['length']===0x0?this['_database']['prepare'](g+'\x20WHERE\x20unit_id\x20=\x20?')['all'](_0x1f633a['unitID']):this['_database']['prepare'](g+'\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20thread_id\x20IN\x20('+_0x136023['map'](()=>'?')['join'](',')+')')['all'](_0x1f633a['unitID'],..._0x136023))['map'](_)['sort'](v);}async['editComment'](_0x5af051,_0x10e755){return this['_assertOpen'](),this['_transaction'](()=>{let _0x5bbb7e=this['_getByReply'](_0x5af051['unitID'],_0x5af051['replyID']),_0x2574d0=this['_getByReply'](_0x5af051['unitID'],_0x5af051['threadID']);return!_0x5bbb7e||_0x5bbb7e['threadID']!==_0x5af051['threadID']||!_0x2574d0?{'status':'not-found'}:_0x2574d0['solved']===u['CommentSolvedStatus']['OpenOrReOpen']?_0x5bbb7e['authorUserID']===_0x5af051['expectedAuthorUserID']?_0x5bbb7e['content']===_0x5af051['content']&&y(_0x5bbb7e['mentions'],_0x5af051['mentions'])?{'status':'unchanged','record':_0x5bbb7e}:(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'](_0x5af051['content'],JSON['stringify'](_0x5af051['mentions']),Math['max'](Date['now'](),_0x5bbb7e['updatedAt']+0x1),_0x5af051['unitID'],_0x5af051['threadID'],_0x5af051['replyID']),{'status':'edited','record':this['_require'](_0x5af051['unitID'],_0x5af051['replyID'])}):{'status':'author-mismatch'}:{'status':'closed'};});}async['setThreadSolved'](_0x4b9aa3,_0x11ec3e){return this['_assertOpen'](),this['_transaction'](()=>{let _0x42ba31=this['_getByReply'](_0x4b9aa3['unitID'],_0x4b9aa3['threadID']);return!_0x42ba31||_0x42ba31['threadID']!==_0x42ba31['replyID']?{'status':'not-found'}:_0x42ba31['solved']===_0x4b9aa3['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'](_0x4b9aa3['solved'],Math['max'](Date['now'](),_0x42ba31['updatedAt']+0x1),_0x4b9aa3['unitID'],_0x4b9aa3['threadID']),{'status':'updated'});});}async['deleteComment'](_0x408c9e,_0x4ccba1){return this['_assertOpen'](),this['_transaction'](()=>{let _0x4563c5=_0x408c9e['replyID']??_0x408c9e['threadID'],_0x53364d=this['_getByReply'](_0x408c9e['unitID'],_0x4563c5);return!_0x53364d||_0x53364d['threadID']!==_0x408c9e['threadID']?{'status':'not-found'}:_0x53364d['generation']===_0x408c9e['expectedGeneration']?(_0x408c9e['replyID']===void 0x0?this['_database']['prepare']('DELETE\x20FROM\x20collaboration_comments\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20thread_id\x20=\x20?')['run'](_0x408c9e['unitID'],_0x408c9e['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'](_0x408c9e['unitID'],_0x408c9e['threadID'],_0x408c9e['replyID'],_0x408c9e['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 _0x2d7192=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(_0x2d7192){if(_0x2d7192['version']!==p)throw x('SQLite\x20Comment\x20schema\x20version\x20'+_0x2d7192['version']+'\x20is\x20not\x20supported');let _0x3901ed=m['filter'](_0x47ecea=>!this['_hasTable'](_0x47ecea));if(_0x3901ed['length']>0x0)throw x('SQLite\x20Comment\x20schema\x20v1\x20is\x20incomplete:\x20missing\x20'+_0x3901ed['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'](_0x45faef){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'](_0x45faef);}['_hasAnyOwnedTable'](){return m['some'](_0x5e8283=>this['_hasTable'](_0x5e8283));}['_insert'](_0x15dabd){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'](_0x15dabd['unitID'],_0x15dabd['threadID'],_0x15dabd['replyID'],_0x15dabd['authorUserID'],_0x15dabd['content'],JSON['stringify'](_0x15dabd['mentions']),_0x15dabd['solved'],_0x15dabd['createdAt'],_0x15dabd['updatedAt'],_0x15dabd['generation']);}['_getByReply'](_0x94c274,_0x85e8d6){let _0x4986fc=this['_database']['prepare'](g+'\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20reply_id\x20=\x20?')['get'](_0x94c274,_0x85e8d6);return _0x4986fc?_(_0x4986fc):null;}['_require'](_0x405685,_0x2b0a4a){let _0x21f3c1=this['_getByReply'](_0x405685,_0x2b0a4a);if(!_0x21f3c1)throw Error('SQLite\x20Comment\x20write\x20did\x20not\x20persist\x20its\x20record');return _0x21f3c1;}['_transaction'](_0x4bece4){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0xd8da34=_0x4bece4();return this['_database']['exec']('COMMIT;'),_0xd8da34;}catch(_0x3b5e78){try{this['_database']['exec']('ROLLBACK;');}catch{}throw _0x3b5e78;}}['_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 _(_0x1585bd){let _0x18d012=JSON['parse'](_0x1585bd['mentions_json']);if(!Array['isArray'](_0x18d012)||_0x18d012['some'](_0x152e95=>typeof _0x152e95!='string'))throw Error('SQLite\x20Comment\x20contains\x20invalid\x20mentions');if(_0x1585bd['solved']!==u['CommentSolvedStatus']['OpenOrReOpen']&&_0x1585bd['solved']!==u['CommentSolvedStatus']['Solved'])throw Error('SQLite\x20Comment\x20contains\x20invalid\x20solved\x20status');return{'unitID':_0x1585bd['unit_id'],'threadID':_0x1585bd['thread_id'],'replyID':_0x1585bd['reply_id'],'authorUserID':_0x1585bd['author_user_id'],'content':_0x1585bd['content'],'mentions':_0x18d012,'solved':_0x1585bd['solved'],'createdAt':_0x1585bd['created_at'],'updatedAt':_0x1585bd['updated_at'],'generation':_0x1585bd['generation']};}function v(_0x589dd8,_0x52360d){let _0x498be1=_0x589dd8['threadID']['localeCompare'](_0x52360d['threadID']);return _0x498be1===0x0?_0x589dd8['replyID']===_0x589dd8['threadID']?-0x1:_0x52360d['replyID']===_0x52360d['threadID']?0x1:_0x589dd8['createdAt']-_0x52360d['createdAt']||_0x589dd8['replyID']['localeCompare'](_0x52360d['replyID']):_0x498be1;}function y(_0x281863,_0x275a10){return _0x281863['length']===_0x275a10['length']&&_0x281863['every']((_0x2b0b14,_0x2d4dbc)=>_0x2b0b14===_0x275a10[_0x2d4dbc]);}function b(_0x5042bd){if(!_0x5042bd?.['filename'])throw TypeError('SQLiteCommentDatabaseAdapter\x20requires\x20a\x20filename');if(_0x5042bd['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x5042bd['busyTimeoutMs'])||_0x5042bd['busyTimeoutMs']<0x0))throw TypeError('busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20safe\x20integer');}function x(_0x827089){return Error(_0x827089);}exports['SQLiteCommentDatabaseAdapter']=h;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function _0x5796(_0x39eef6,_0x2ec4ff){_0x39eef6=_0x39eef6-0x94;const _0x25fdfe=_0x25fd();let _0x57962a=_0x25fdfe[_0x39eef6];return _0x57962a;}const _0x4ace70=_0x5796;(function(_0x2b572f,_0x2f26a2){const _0x525795=_0x5796,_0x1ab4b7=_0x2b572f();while(!![]){try{const _0x403a57=parseInt(_0x525795(0x94))/0x1+parseInt(_0x525795(0x9d))/0x2*(-parseInt(_0x525795(0x96))/0x3)+parseInt(_0x525795(0x9b))/0x4*(-parseInt(_0x525795(0x98))/0x5)+-parseInt(_0x525795(0x9a))/0x6*(-parseInt(_0x525795(0x99))/0x7)+-parseInt(_0x525795(0x9e))/0x8+parseInt(_0x525795(0x97))/0x9+-parseInt(_0x525795(0x9c))/0xa*(-parseInt(_0x525795(0x95))/0xb);if(_0x403a57===_0x2f26a2)break;else _0x1ab4b7['push'](_0x1ab4b7['shift']());}catch(_0x64c740){_0x1ab4b7['push'](_0x1ab4b7['shift']());}}}(_0x25fd,0x817a0));import _0xb6eee5 from'./index.cjs';const facadeExport0=_0xb6eee5[_0x4ace70(0x9f)];export{facadeExport0 as SQLiteCommentDatabaseAdapter};function _0x25fd(){const _0x21eaf9=['2tUQZdG','2401392cPBvwD','SQLiteCommentDatabaseAdapter','1025149GkkoiQ','121Rplkkc','1388475bJVxmw','1067148waMTBf','205tSYLlF','3332CWzLjS','774tCCBQz','21356CVDtEh','279190bEppHd'];_0x25fd=function(){return _0x21eaf9;};return _0x25fd();}
|
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-rc.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-rc.0",
|
|
23
|
+
"@univerjs/protocol": "1.0.0-rc.0",
|
|
24
24
|
"libsql": "^0.5.29"
|
|
25
|
-
},
|
|
26
|
-
"publishConfig": {
|
|
27
|
-
"access": "public"
|
|
28
25
|
}
|
|
29
|
-
}
|
|
26
|
+
}
|