dsh-workbench-tasks 5.9.0 → 5.11.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/lib/client.js +1 -1
- package/lib/db/db-core.js +52 -20
- package/lib/db/db-legacy.js +4 -12
- package/lib/db/db.js +1 -3
- package/lib/index.js +6 -1
- package/lib/infra/backup.js +6 -7
- package/lib/tagging/tagging.js +1 -22
- package/lib/task/model/task-model.js +2 -16
- package/lib/task/read/task-view.js +1 -36
- package/lib/task/write/task-bulk.js +2 -23
- package/lib/task/write/task-claim.js +1 -3
- package/lib/task/write/task-operations.js +2 -15
- package/lib/tasks.js +1 -31
- package/lib/timeline/timeline-migration.js +2 -2
- package/lib/timeline/timeline-store.js +2 -3
- package/lib/timeline/timeline-sync.js +2 -1
- package/lib/tree/task-node-write.js +2 -2
- package/lib/tree/tree.js +1 -23
- package/lib/workspace/workspace-store.js +1 -4
- package/package.json +4 -4
package/lib/client.js
CHANGED
|
@@ -13163,7 +13163,7 @@ var require_timeline_view = __commonJS({
|
|
|
13163
13163
|
var TimelineView = require_timeline_view()({ React, COPY, injectCss, statusInfo, configClient, CFG_FALLBACK, TaskItem, EditModal, DoneModal, TimelineModal, CreateModal });
|
|
13164
13164
|
host.registerAddon({
|
|
13165
13165
|
id: "wb-addon-tasks",
|
|
13166
|
-
version: "5.
|
|
13166
|
+
version: "5.11.0",
|
|
13167
13167
|
icon: ICONS["list-checks"],
|
|
13168
13168
|
// 贡献声明写在 registerAddon 里:卸载任务插件时宿主按 addonId 一起撤销,
|
|
13169
13169
|
// 不会在邮件里留一个渲染即报错的孤儿按钮。
|
package/lib/db/db-core.js
CHANGED
|
@@ -180,17 +180,66 @@ export function hasColumn(db, table, column) {
|
|
|
180
180
|
return columnsOf(db, table).indexOf(column) >= 0;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
/**
|
|
184
|
+
* 本机 meta 记忆层:插件不再直连 host 的 meta 表,只经宿主在 setup 时注入的句柄读写,
|
|
185
|
+
* domain 由宿主固化成 wb-addon-tasks,跨域在结构上就不可能。
|
|
186
|
+
*
|
|
187
|
+
* 句柄按 db 实例登记(WeakMap):正式运行只有一个库,但单测经常同时开好几个内存库互相灌数据,
|
|
188
|
+
* 全局单例会把标记写到别的库里。
|
|
189
|
+
*
|
|
190
|
+
* 单测/独立脚本里不一定有宿主,此时该库没有句柄:读返回 null、写告警一次后跳过,
|
|
191
|
+
* 让不关心迁移标记的测试照旧能跑;宿主运行时一定会注入。
|
|
192
|
+
*/
|
|
193
|
+
const metaHandles = new WeakMap();
|
|
194
|
+
let metaWarned = false;
|
|
195
|
+
|
|
196
|
+
export function bindMeta(db, handle) {
|
|
197
|
+
if (db && handle) metaHandles.set(db, handle);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function metaApi(db) {
|
|
201
|
+
const handle = db ? metaHandles.get(db) : null;
|
|
202
|
+
if (handle) return handle;
|
|
203
|
+
if (!metaWarned) {
|
|
204
|
+
metaWarned = true;
|
|
205
|
+
console.warn("[tasks] 宿主没有注入 meta 句柄:本机 meta 记忆(schema 版本、迁移标记)本次不落库");
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** 读一个插件态标记(数据来源是宿主 meta 句柄,不是这张库里的表)。 */
|
|
183
211
|
export function metaGet(db, key) {
|
|
212
|
+
const api = metaApi(db);
|
|
213
|
+
if (!api) return null;
|
|
184
214
|
try {
|
|
185
|
-
|
|
186
|
-
return row ? String(row.v) : null;
|
|
215
|
+
return api.get(String(key));
|
|
187
216
|
} catch {
|
|
188
217
|
return null;
|
|
189
218
|
}
|
|
190
219
|
}
|
|
191
220
|
|
|
221
|
+
/** 写一个插件态标记(值统一字符串,JSON 由调用方自己序列化)。 */
|
|
192
222
|
export function metaSet(db, key, value) {
|
|
193
|
-
|
|
223
|
+
const api = metaApi(db);
|
|
224
|
+
if (!api) return;
|
|
225
|
+
api.set(String(key), String(value));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** 列某前缀下的标记(键值对,按 key 升序);该库没有句柄时返回空数组。 */
|
|
229
|
+
export function metaListPrefix(db, prefix) {
|
|
230
|
+
const api = metaApi(db);
|
|
231
|
+
if (!api) return [];
|
|
232
|
+
return api.list(String(prefix)).map((row) => ({ k: row.key, v: row.v }));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** 只在键不存在时写入(跨设备的迁移记录不能被后到的包覆盖);返回是否真的写了。 */
|
|
236
|
+
export function metaSetIfAbsent(db, key, value) {
|
|
237
|
+
const api = metaApi(db);
|
|
238
|
+
if (!api) return false;
|
|
239
|
+
const text = String(key);
|
|
240
|
+
if (api.get(text) !== null) return false;
|
|
241
|
+
api.set(text, String(value));
|
|
242
|
+
return true;
|
|
194
243
|
}
|
|
195
244
|
|
|
196
245
|
export function tx(db, fn) {
|
|
@@ -209,23 +258,6 @@ export function tx(db, fn) {
|
|
|
209
258
|
}
|
|
210
259
|
}
|
|
211
260
|
|
|
212
|
-
export function logChange(db, table, rowId, op, payload, origin, ts) {
|
|
213
|
-
if (String(origin || "ui") === "sync") return;
|
|
214
|
-
let value = payload;
|
|
215
|
-
if (String(op) === "delete" && (value === undefined || value === null)) {
|
|
216
|
-
try {
|
|
217
|
-
const row = db.prepare("SELECT * FROM " + String(table) + " WHERE id=?").get(String(rowId));
|
|
218
|
-
if (row) value = row;
|
|
219
|
-
} catch (err) {
|
|
220
|
-
// 表不存在或列不匹配时仍记录墓碑时间和 id。
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
const p = value === undefined ? null : typeof value === "string" ? value : JSON.stringify(value);
|
|
224
|
-
db.prepare(
|
|
225
|
-
"INSERT INTO sync_change_log(table_name,row_id,op,payload,origin,updated_at) VALUES(?,?,?,?,?,?)",
|
|
226
|
-
).run(String(table), String(rowId), String(op), p, String(origin || "ui"), Number(ts || now()));
|
|
227
|
-
}
|
|
228
|
-
|
|
229
261
|
export function rowTask(row) {
|
|
230
262
|
if (!row) return null;
|
|
231
263
|
return {
|
package/lib/db/db-legacy.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 从 db.js 拆出,纯结构调整,行为不变(2026-11-09)。
|
|
5
5
|
*/
|
|
6
|
-
import { quoteIdent, dropIndexesFor, now, newId, idOf, todayStr, dateText, timeMs, tableExists, columnsOf, hasColumn, metaGet, metaSet, tx,
|
|
6
|
+
import { quoteIdent, dropIndexesFor, now, newId, idOf, todayStr, dateText, timeMs, tableExists, columnsOf, hasColumn, metaGet, metaSet, tx, insertNode, createSchema, seedDefaultTree } from "./db-core.js";
|
|
7
7
|
|
|
8
8
|
function legacyName(base, ts) {
|
|
9
9
|
const d = new Date(ts);
|
|
@@ -419,14 +419,13 @@ export function ensureTaskColumns(db, report) {
|
|
|
419
419
|
* 已完成任务不再需要优先级:一次性把历史库里 status=2 的 priority 清零。
|
|
420
420
|
*
|
|
421
421
|
* 新写入由 tasks.js 保证(create/update/bulkUpdate 都会把 DONE 的 priority 归一为 0),
|
|
422
|
-
*
|
|
423
|
-
* meta 标记保证只跑一次,之后用户手动改库也不会被反复覆盖。
|
|
422
|
+
* 这里只修历史数据。meta 标记保证只跑一次,之后用户手动改库也不会被反复覆盖。
|
|
424
423
|
*/
|
|
425
424
|
/**
|
|
426
425
|
* 优先级不变量回填(幂等,每次启动都跑):
|
|
427
426
|
* - 非 ACTIVE(已关闭/已完成/已重启)一律 P0;
|
|
428
427
|
* - ACTIVE 不允许 P0,历史遗留的 0 值回落到 P1。
|
|
429
|
-
* 只处理未删除行,避免给墓碑行涨 rev
|
|
428
|
+
* 只处理未删除行,避免给墓碑行涨 rev。
|
|
430
429
|
*/
|
|
431
430
|
export function normalizePriorities(db, report) {
|
|
432
431
|
const ts = now();
|
|
@@ -441,14 +440,7 @@ export function normalizePriorities(db, report) {
|
|
|
441
440
|
const id = String(row.id);
|
|
442
441
|
const rev = Number(row.rev || 0) + 1;
|
|
443
442
|
updateOne.run(value, ts, rev, id);
|
|
444
|
-
|
|
445
|
-
if (full) {
|
|
446
|
-
try {
|
|
447
|
-
logChange(db, "task", id, "update", full, "migrate", ts);
|
|
448
|
-
} catch (e) {
|
|
449
|
-
/* 独立库(单测/导出)没有 sync_change_log:照常回填,跳过变更日志 */
|
|
450
|
-
}
|
|
451
|
-
}
|
|
443
|
+
load.get(id);
|
|
452
444
|
}
|
|
453
445
|
return rows.length;
|
|
454
446
|
}
|
package/lib/db/db.js
CHANGED
|
@@ -17,9 +17,7 @@ export * from "./db-core.js";
|
|
|
17
17
|
export { migrateLegacy, migrateCurrentTasks, ensureTaskColumns, ensureNodeColumns, normalizePriorities } from "./db-legacy.js";
|
|
18
18
|
|
|
19
19
|
export function ensureSchema(db, log) {
|
|
20
|
-
|
|
21
|
-
db.exec("CREATE TABLE IF NOT EXISTS meta (k TEXT PRIMARY KEY, v TEXT NOT NULL);");
|
|
22
|
-
}
|
|
20
|
+
// meta 是宿主的平台表(按 domain 分区),插件不再自建也不再直连:记录 schema 版本走 bindMeta 注入的句柄。
|
|
23
21
|
const report = {
|
|
24
22
|
at: new Date(now()).toISOString(),
|
|
25
23
|
source: "existing",
|
package/lib/index.js
CHANGED
|
@@ -23,12 +23,15 @@
|
|
|
23
23
|
* 回执 `top` 增 `total` 便于界面回显「共 N 条 / 显示前 M 条」;逾期清单与排行上限解耦,
|
|
24
24
|
* 固定取前 20 条并按逾期任务数降序(此前复用 topLimit 且顺序不是从严到宽);
|
|
25
25
|
* 排行表补完成率进度条、零值收敛、逾期徽标与成员分片,窄屏可横向滚动。
|
|
26
|
+
* 5.10.0:本地变更日志整体下线——删除 `logChange()` 与全部调用点(同步已改为按当前状态对比,
|
|
27
|
+
* 不再需要待推送队列),`sync_change_log` 表由宿主迁移删除;只读它的 `tasks.history`、
|
|
28
|
+
* `tasks.changelog` 两个 action 一并移除。
|
|
26
29
|
*/
|
|
27
30
|
|
|
28
31
|
import { registerActivityCalendarAction } from "./stats/activity-calendar.js";
|
|
29
32
|
import { registerTimelineStatsAction } from "./stats/timeline-stats.js";
|
|
30
33
|
import { DIFFICULTY_GUIDANCE } from "./task/model/task-difficulty.js";
|
|
31
|
-
import { bindClock, ensureSchema } from "./db/db.js";
|
|
34
|
+
import { bindClock, bindMeta, ensureSchema } from "./db/db.js";
|
|
32
35
|
import { createRequire } from "node:module";
|
|
33
36
|
|
|
34
37
|
// 版本号只认 package.json:首页插件卡读的就是这里注册的 version,
|
|
@@ -93,6 +96,8 @@ export function setup(api) {
|
|
|
93
96
|
// 配置读写全部委托宿主配置中心(api.config 缓存 + onChange 失效),插件不再持有配置表。
|
|
94
97
|
bindHostConfig(api);
|
|
95
98
|
if (typeof api.now === "function") bindClock(api.now);
|
|
99
|
+
// meta 句柄必须在 ensureSchema 之前绑定:schema 版本与迁移报告要写进宿主 meta。
|
|
100
|
+
bindMeta(api.db, api.meta);
|
|
96
101
|
ensureSchema(api.db, api.log);
|
|
97
102
|
// 标签来源登记:标签域(tags ≥ 1.7.1)要求 item_type 先注册才能写 tag_mapping。
|
|
98
103
|
ensureTaskTagSource(api.db, api.log);
|
package/lib/infra/backup.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* 所有行(含软删)都会导出,保证删除标记也能随备份恢复。
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { metaGet, metaListPrefix, metaSetIfAbsent, tableExists, tx } from "../db/db.js";
|
|
10
10
|
import { LEGACY_TYPE_TAGS, addTaskTagByName, tagsAvailable } from "../tagging/tagging.js";
|
|
11
11
|
|
|
12
12
|
const SCHEMA_VERSION = 6;
|
|
@@ -130,7 +130,8 @@ function linkValues(row) {
|
|
|
130
130
|
|
|
131
131
|
export function exportTasksData(api) {
|
|
132
132
|
return tx(api.db, () => {
|
|
133
|
-
|
|
133
|
+
// 迁移记录存在宿主 meta 的 wb-addon-tasks 域里:走句柄读,插件不再自查 meta 表是否存在。
|
|
134
|
+
const timelineMigrationRecords = metaListPrefix(api.db, "task_timeline_migration:");
|
|
134
135
|
const data = { schemaVersion: SCHEMA_VERSION, timelineMigrationVersion: 1, timelineMigrationRecords };
|
|
135
136
|
for (const [table, key] of DEFINITIONS) {
|
|
136
137
|
data[key] = tableExists(api.db, table) ? api.db.prepare("SELECT * FROM " + table + " ORDER BY id ASC").all() : [];
|
|
@@ -244,20 +245,18 @@ export function importTasksData(api, raw, options) {
|
|
|
244
245
|
db.prepare("UPDATE task SET timeline_key=?,updated_at=?,rev=? WHERE id=?").run(key, updated, rev, id);
|
|
245
246
|
if (!taskChange) {
|
|
246
247
|
const stored = { ...projected, updated_at: updated, rev };
|
|
247
|
-
logChange(db, "task", id, stored.deleted_at == null ? "upsert" : "delete", stored, "import", updated);
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
for (const record of plan.migrationRecords) {
|
|
251
|
-
const existing = db
|
|
252
|
-
if (existing && existing
|
|
253
|
-
if (
|
|
251
|
+
const existing = metaGet(db, record.k);
|
|
252
|
+
if (existing !== null && existing !== record.v) throw new Error("TIMELINE_MIGRATION_RECORD_CONFLICT: " + record.k);
|
|
253
|
+
if (existing === null) metaSetIfAbsent(db, record.k, record.v);
|
|
254
254
|
}
|
|
255
255
|
for (const { table, row, original, local, columns } of changed) {
|
|
256
256
|
const stored = db.prepare("SELECT * FROM " + table + " WHERE id=?").get(row.id);
|
|
257
257
|
if (local && columns.every(c => local[c] === stored[c])) {
|
|
258
258
|
counts[table].imported--; counts[table].skipped++; imported--; skipped++; continue;
|
|
259
259
|
}
|
|
260
|
-
logChange(db, table, row.id, stored.deleted_at == null ? "upsert" : "delete", stored, "import", stored.updated_at);
|
|
261
260
|
if (table === "task") {
|
|
262
261
|
const legacyName = LEGACY_TYPE_TAGS[String(original.type)];
|
|
263
262
|
if (legacyName && tagsAvailable(db, api)) addTaskTagByName(db, row.id, legacyName, row.updated_at, "import");
|
package/lib/tagging/tagging.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* 标签,否则老任务会集体变成未打标签。迁移用 meta 标记,只跑一次。
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { idOf, newId,
|
|
12
|
+
import { idOf, newId, tableExists, metaGet, metaSet, tx } from "../db/db.js";
|
|
13
13
|
import { TAG_SOURCE, TAG_SOURCE_OWNER, TAG_SOURCE_TITLE, ensureTagSource, withTagSource } from "./source.js";
|
|
14
14
|
|
|
15
15
|
export const TAG_ITEM_TYPE = "task";
|
|
@@ -109,9 +109,6 @@ export function ensureTagIdByName(db, name, ts, origin) {
|
|
|
109
109
|
if (again) return String(again.id);
|
|
110
110
|
throw e;
|
|
111
111
|
}
|
|
112
|
-
logChange(db, "tag", id, "create", {
|
|
113
|
-
id: id, name: name, created_at: ts, updated_at: ts, deleted_at: null, rev: 1,
|
|
114
|
-
}, origin, ts);
|
|
115
112
|
return id;
|
|
116
113
|
}
|
|
117
114
|
|
|
@@ -133,7 +130,6 @@ function writeTaskTags(db, taskId, tagIds, ts, origin) {
|
|
|
133
130
|
for (const m of current) {
|
|
134
131
|
if (wanted.has(String(m.tag_id))) continue;
|
|
135
132
|
db.prepare("UPDATE tag_mapping SET deleted_at=?, updated_at=?, rev=rev+1 WHERE id=?").run(ts, ts, String(m.id));
|
|
136
|
-
logChange(db, "tag_mapping", String(m.id), "delete", null, origin, ts);
|
|
137
133
|
}
|
|
138
134
|
for (const tagId of tagIds) {
|
|
139
135
|
if (byTag.has(String(tagId))) continue;
|
|
@@ -142,20 +138,12 @@ function writeTaskTags(db, taskId, tagIds, ts, origin) {
|
|
|
142
138
|
).get(TAG_ITEM_TYPE, String(taskId), String(tagId));
|
|
143
139
|
if (deleted) {
|
|
144
140
|
db.prepare("UPDATE tag_mapping SET deleted_at=NULL, updated_at=?, rev=rev+1 WHERE id=?").run(ts, String(deleted.id));
|
|
145
|
-
logChange(db, "tag_mapping", String(deleted.id), "upsert", {
|
|
146
|
-
id: String(deleted.id), tag_id: String(tagId), item_id: String(taskId), item_type: TAG_ITEM_TYPE,
|
|
147
|
-
updated_at: ts, deleted_at: null, rev: Number(deleted.rev) + 1,
|
|
148
|
-
}, origin, ts);
|
|
149
141
|
continue;
|
|
150
142
|
}
|
|
151
143
|
const id = newId();
|
|
152
144
|
db.prepare(
|
|
153
145
|
"INSERT INTO tag_mapping(id,tag_id,item_id,item_type,created_at,updated_at,deleted_at,rev) VALUES(?,?,?,?,?,?,?,?)",
|
|
154
146
|
).run(id, String(tagId), String(taskId), TAG_ITEM_TYPE, ts, ts, null, 1);
|
|
155
|
-
logChange(db, "tag_mapping", id, "create", {
|
|
156
|
-
id: id, tag_id: String(tagId), item_id: String(taskId), item_type: TAG_ITEM_TYPE,
|
|
157
|
-
created_at: ts, updated_at: ts, deleted_at: null, rev: 1,
|
|
158
|
-
}, origin, ts);
|
|
159
147
|
}
|
|
160
148
|
}
|
|
161
149
|
|
|
@@ -207,14 +195,9 @@ function writeTaskTagByName(db, taskId, name, ts, origin) {
|
|
|
207
195
|
db.prepare(
|
|
208
196
|
"INSERT INTO tag_mapping(id,tag_id,item_id,item_type,created_at,updated_at,deleted_at,rev) VALUES(?,?,?,?,?,?,?,?)",
|
|
209
197
|
).run(id, String(tagId), String(taskId), TAG_ITEM_TYPE, ts, ts, null, 1);
|
|
210
|
-
logChange(db, "tag_mapping", id, "create", {
|
|
211
|
-
id: id, tag_id: String(tagId), item_id: String(taskId), item_type: TAG_ITEM_TYPE,
|
|
212
|
-
created_at: ts, updated_at: ts, deleted_at: null, rev: 1,
|
|
213
|
-
}, origin, ts);
|
|
214
198
|
return true;
|
|
215
199
|
}
|
|
216
200
|
|
|
217
|
-
|
|
218
201
|
/**
|
|
219
202
|
* 启动时幂等登记本域来源(`tag_mapping.item_type='task'`)。
|
|
220
203
|
* 标签域未装或版本过低时静默跳过;重复注册不阻断启动,写入门禁会在写入时给出可读错误。
|
|
@@ -358,10 +341,6 @@ export function migrateLegacyTypes(db, api, origin) {
|
|
|
358
341
|
db.prepare(
|
|
359
342
|
"INSERT INTO tag_mapping(id,tag_id,item_id,item_type,created_at,updated_at,deleted_at,rev) VALUES(?,?,?,?,?,?,?,?)",
|
|
360
343
|
).run(id, String(tag.id), String(taskId), TAG_ITEM_TYPE, ts, ts, null, 1);
|
|
361
|
-
logChange(db, "tag_mapping", id, "create", {
|
|
362
|
-
id: id, tag_id: String(tag.id), item_id: String(taskId), item_type: TAG_ITEM_TYPE,
|
|
363
|
-
created_at: ts, updated_at: ts, deleted_at: null, rev: 1,
|
|
364
|
-
}, origin || "migrate", ts);
|
|
365
344
|
mappings += 1;
|
|
366
345
|
}
|
|
367
346
|
}
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
// 模型助手;与 task-bulk 的循环引用只在调用期取值,顶层不求值。
|
|
2
|
-
import {
|
|
3
|
-
idOf,
|
|
4
|
-
dateText,
|
|
5
|
-
logChange,
|
|
6
|
-
taskOut,
|
|
7
|
-
nodeMap,
|
|
8
|
-
} from "../../db/db.js";
|
|
2
|
+
import { idOf, dateText, taskOut, nodeMap } from "../../db/db.js";
|
|
9
3
|
// task-query 循环依赖仅在调用期读取 tasks 的函数/常量。
|
|
10
4
|
import { configValues } from "../../infra/config.js";
|
|
11
|
-
import {
|
|
12
|
-
normalizeTagIds,
|
|
13
|
-
normalizeTagNames,
|
|
14
|
-
requireTagRows,
|
|
15
|
-
availableTagsText,
|
|
16
|
-
tagIdsByNames,
|
|
17
|
-
ensureTagsByNames,
|
|
18
|
-
} from "../../tagging/tagging.js";
|
|
5
|
+
import { normalizeTagIds, normalizeTagNames, requireTagRows, availableTagsText, tagIdsByNames, ensureTagsByNames } from "../../tagging/tagging.js";
|
|
19
6
|
/**
|
|
20
7
|
* 标签名校验:默认(form.autoCreateTags=true)未知名字会被补建;
|
|
21
8
|
* 关掉开关后未知名字直接报错,并把可用标签列出来,调用方一次就能改成已存在的名字。
|
|
@@ -188,7 +175,6 @@ export function emitChange(api, id, op, kind) {
|
|
|
188
175
|
}
|
|
189
176
|
|
|
190
177
|
export function writeChange(db, row, op, origin, api, ts, kind) {
|
|
191
|
-
logChange(db, "task", row.id, op, op === "delete" ? null : row, origin, ts);
|
|
192
178
|
emitChange(api, row.id, op, kind);
|
|
193
179
|
}
|
|
194
180
|
|
|
@@ -1,42 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 任务 action
|
|
2
|
+
* 任务 action 的文本渲染:不碰写入路径,方便单独阅读与测试。
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { idOf } from "../../db/db.js";
|
|
6
|
-
|
|
7
|
-
export function taskHistory(db, args) {
|
|
8
|
-
const id = idOf(args.id || args.taskId);
|
|
9
|
-
if (!id) throw new Error("缺少 id");
|
|
10
|
-
const limit = Math.max(1, Math.min(500, Number(args.limit) || 50));
|
|
11
|
-
const rows = db.prepare(
|
|
12
|
-
"SELECT op, payload, origin, updated_at FROM sync_change_log WHERE table_name='task' AND row_id=? ORDER BY updated_at DESC LIMIT ?",
|
|
13
|
-
).all(id, limit);
|
|
14
|
-
const entries = rows.map(function (r) {
|
|
15
|
-
let payload = null;
|
|
16
|
-
try { payload = r.payload ? JSON.parse(String(r.payload)) : null; } catch (e) { payload = String(r.payload || ""); }
|
|
17
|
-
return { op: String(r.op), origin: r.origin || null, at: r.updated_at, payload: payload };
|
|
18
|
-
});
|
|
19
|
-
return { id: String(id), count: entries.length, entries: entries };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function changelog(db, args) {
|
|
23
|
-
const limit = Math.max(1, Math.min(1000, Number(args.limit) || 100));
|
|
24
|
-
const since = args.since ? String(args.since) : null;
|
|
25
|
-
const tables = Array.isArray(args.tables) && args.tables.length ? args.tables.map(String) : ["task", "tag_mapping"];
|
|
26
|
-
const where = ["table_name IN (" + tables.map(function () { return "?"; }).join(",") + ")"];
|
|
27
|
-
const params = tables.slice();
|
|
28
|
-
if (since) { where.push("updated_at>=?"); params.push(since); }
|
|
29
|
-
params.push(limit);
|
|
30
|
-
const stmt = db.prepare(
|
|
31
|
-
"SELECT table_name, row_id, op, origin, updated_at FROM sync_change_log WHERE " + where.join(" AND ") + " ORDER BY updated_at DESC LIMIT ?",
|
|
32
|
-
);
|
|
33
|
-
const rows = stmt.all.apply(stmt, params);
|
|
34
|
-
return { since: since, count: rows.length, entries: rows.map(function (r) {
|
|
35
|
-
return { table: r.table_name, rowId: r.row_id, op: r.op, origin: r.origin || null, at: r.updated_at };
|
|
36
|
-
}) };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
5
|
const STATUS_TEXT = { "0": "已开启", "1": "已关闭", "2": "已完成", "3": "已重启", "4": "已接取" };
|
|
41
6
|
|
|
42
7
|
function tagNames(tags) {
|
|
@@ -9,29 +9,9 @@ import { ownershipFields, renderOwnership } from '../model/task-ownership-path.j
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { setMembership, touchTimelines } from "../../timeline/timeline-store.js";
|
|
12
|
-
import { now, idOf, todayStr,
|
|
12
|
+
import { now, idOf, todayStr, taskOut, nodeMap } from "../../db/db.js";
|
|
13
13
|
import { tagsAvailable, replaceTaskTags } from "../../tagging/tagging.js";
|
|
14
|
-
import {
|
|
15
|
-
PATCH_FIELDS,
|
|
16
|
-
DIFF_COLUMNS,
|
|
17
|
-
STATUSES,
|
|
18
|
-
STATUS_NAMES,
|
|
19
|
-
asCode,
|
|
20
|
-
priorityForStatus,
|
|
21
|
-
clampDifficulty,
|
|
22
|
-
dateArg,
|
|
23
|
-
requireTable,
|
|
24
|
-
checkRequiredDates,
|
|
25
|
-
getTask,
|
|
26
|
-
saveTaskRow,
|
|
27
|
-
writeChange,
|
|
28
|
-
currentTaskTagIds,
|
|
29
|
-
resolveTagPatch,
|
|
30
|
-
withNotices,
|
|
31
|
-
tagMissingNotices,
|
|
32
|
-
createTask,
|
|
33
|
-
emitChange,
|
|
34
|
-
} from "../../tasks.js";
|
|
14
|
+
import { PATCH_FIELDS, DIFF_COLUMNS, STATUSES, STATUS_NAMES, asCode, priorityForStatus, clampDifficulty, dateArg, requireTable, checkRequiredDates, getTask, saveTaskRow, writeChange, currentTaskTagIds, resolveTagPatch, withNotices, tagMissingNotices, createTask, emitChange } from "../../tasks.js";
|
|
35
15
|
|
|
36
16
|
export function idList(argsIds) {
|
|
37
17
|
const ids = Array.isArray(argsIds) ? argsIds.map(function (x) { return idOf(x); }).filter(Boolean) : [];
|
|
@@ -205,7 +185,6 @@ export function bulkDelete(db, args, origin, api) {
|
|
|
205
185
|
setMembership(db,id,null,origin,buffered,{ts,project:false,touched});
|
|
206
186
|
const next = Object.assign({}, cur, { timeline_key:null, deleted_at: ts, updated_at: ts, rev: Number(cur.rev) + 1 });
|
|
207
187
|
saveTaskRow(db, next);
|
|
208
|
-
logChange(db, "task", next.id, "delete", null, origin, ts);
|
|
209
188
|
emitChange(buffered, next.id, "delete");
|
|
210
189
|
}
|
|
211
190
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* 返回回执与失败原因,不参与抢锁决策。
|
|
7
7
|
*/
|
|
8
8
|
import { randomUUID } from "node:crypto";
|
|
9
|
-
import { now, idOf
|
|
9
|
+
import { now, idOf } from "../../db/db.js";
|
|
10
10
|
import { ownershipError } from "../model/task-ownership-path.js";
|
|
11
11
|
import { getTask, outOne, emitChange } from "../model/task-model.js";
|
|
12
12
|
|
|
@@ -83,7 +83,6 @@ export function claimTask(db, args, origin, api) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
function writeClaimChange(db, row, origin, api, ts, kind) {
|
|
86
|
-
logChange(db, "task", row.id, "update", row, origin, ts);
|
|
87
86
|
emitChange(api, row.id, kind || "tasks-changed");
|
|
88
87
|
}
|
|
89
88
|
|
|
@@ -141,7 +140,6 @@ export function claimBatch(db, args, origin, api) {
|
|
|
141
140
|
const row = Object.assign({}, cur, {
|
|
142
141
|
status: STATUS_CLAIMED, owner: owner, claimed_at: ts, claim_token: token, updated_at: ts, rev: Number(cur.rev) + 1,
|
|
143
142
|
});
|
|
144
|
-
logChange(db, "task", row.id, "update", row, origin, ts);
|
|
145
143
|
claimed.push({ id: id, task: outOne(db, row), previousStatus: STATUS_OPEN });
|
|
146
144
|
}
|
|
147
145
|
// 整批只发一次变更事件;事件在事务提交后由 taskTransaction 统一发出。
|
|
@@ -1,24 +1,13 @@
|
|
|
1
1
|
import { setMembership } from "../../timeline/timeline-store.js";
|
|
2
2
|
import { taskTransaction } from "./task-transaction.js";
|
|
3
3
|
// 与 task-bulk 的循环引用只在调用期取值,顶层不求值。
|
|
4
|
-
import {
|
|
5
|
-
now,
|
|
6
|
-
idOf,
|
|
7
|
-
todayStr,
|
|
8
|
-
tx,
|
|
9
|
-
logChange,
|
|
10
|
-
taskOut,
|
|
11
|
-
nodeMap,
|
|
12
|
-
} from "../../db/db.js";
|
|
4
|
+
import { now, idOf, todayStr, tx, taskOut, nodeMap } from "../../db/db.js";
|
|
13
5
|
// task-query 循环依赖仅在调用期读取 tasks 的函数/常量。
|
|
14
6
|
import { listTasks } from "../read/task-query.js";
|
|
15
7
|
import { todayActivity } from "../../stats/stats-today.js";
|
|
16
8
|
import { csvCell } from "../read/task-view.js";
|
|
17
9
|
import { bulkUpdate } from "./task-bulk.js";
|
|
18
|
-
import {
|
|
19
|
-
tagsAvailable,
|
|
20
|
-
attachTags,
|
|
21
|
-
} from "../../tagging/tagging.js";
|
|
10
|
+
import { tagsAvailable, attachTags } from "../../tagging/tagging.js";
|
|
22
11
|
import { TAG_DOMAIN_NOTICE, withNotices, dateArg, getTask, saveTaskRow, emitChange, writeChange } from "../model/task-model.js";
|
|
23
12
|
import { clearTaskWorkspaces, attachWorkspaces } from "../../workspace/workspace-store.js";
|
|
24
13
|
import { updateTask } from "./task-update.js";
|
|
@@ -41,7 +30,6 @@ export function restartTasks(db, args) {
|
|
|
41
30
|
return rows.map(function (r) { return taskOut(r, map); });
|
|
42
31
|
}
|
|
43
32
|
|
|
44
|
-
|
|
45
33
|
export function migrateTasks(db, args, origin, api) {
|
|
46
34
|
const result = bulkUpdate(db,{ids:args.ids,patch:{tableId:args.tableId},dryRun:args.dryRun},origin,api);
|
|
47
35
|
return {...result, ids:result.changes.map(c=>c.id), tableId:String(args.tableId), tasks:result.changes.map(c=>c.task)};
|
|
@@ -152,7 +140,6 @@ export function removeTask(db, args, origin, api, skipTx = false) {
|
|
|
152
140
|
saveTaskRow(db, next);
|
|
153
141
|
// 删除任务连带软删它的工作区关联,避免 link 变成指向已删任务的孤儿行。
|
|
154
142
|
clearTaskWorkspaces(db, next.id, origin, api, ts);
|
|
155
|
-
logChange(db, "task", next.id, "delete", null, origin, ts);
|
|
156
143
|
emitChange(api, next.id, "delete");
|
|
157
144
|
return { ok: true, id: String(next.id) };
|
|
158
145
|
}
|
package/lib/tasks.js
CHANGED
|
@@ -19,7 +19,7 @@ import { TASK_FILTER_SCHEMA } from "./task/read/task-search-schema.js";
|
|
|
19
19
|
import { listTasks } from "./task/read/task-query.js";
|
|
20
20
|
import { statsReport, renderStats } from "./stats/stats.js";
|
|
21
21
|
import { registerTagOptionsAction } from "./tagging/tag-options.js";
|
|
22
|
-
import {
|
|
22
|
+
import { renderArray, renderList, renderTaskDetail } from "./task/read/task-view.js";
|
|
23
23
|
import { bulkUpdate, bulkCreate, bulkDelete, renderBulkUpdate, renderBulkCreate, renderBulkDelete } from "./task/write/task-bulk.js";
|
|
24
24
|
import {
|
|
25
25
|
attachTags,
|
|
@@ -256,36 +256,6 @@ export function registerTaskActions(api) {
|
|
|
256
256
|
render: renderBulkDelete,
|
|
257
257
|
});
|
|
258
258
|
|
|
259
|
-
action("tasks.history", {
|
|
260
|
-
description: "读单个任务的变更历史(来自 sync_change_log,倒序)",
|
|
261
|
-
input: {
|
|
262
|
-
type: "object",
|
|
263
|
-
properties: {
|
|
264
|
-
id: { type: "string" },
|
|
265
|
-
taskId: { type: ["string", "number"] },
|
|
266
|
-
limit: { type: "number", description: "默认 50,最大 500" },
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
examples: [{ id: "1001", limit: 20 }],
|
|
270
|
-
execute: function (args) { return taskHistory(db, args || {}); },
|
|
271
|
-
render: function (r) { return "任务 " + r.id + " 变更 " + r.count + " 条"; },
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
action("tasks.changelog", {
|
|
275
|
-
description: "增量读变更日志(task / tag_mapping),可按 since 与表过滤",
|
|
276
|
-
input: {
|
|
277
|
-
type: "object",
|
|
278
|
-
properties: {
|
|
279
|
-
since: { type: "string", description: "只返回该时间点之后的记录(ISO 或 YYYY-MM-DD)" },
|
|
280
|
-
tables: { type: "array", items: { type: "string" }, description: "默认 task / tag_mapping" },
|
|
281
|
-
limit: { type: "number", description: "默认 100,最大 1000" },
|
|
282
|
-
},
|
|
283
|
-
},
|
|
284
|
-
examples: [{ since: "2026-11-07T00:00:00.000Z", limit: 200 }],
|
|
285
|
-
execute: function (args) { return changelog(db, args || {}); },
|
|
286
|
-
render: function (r) { return "变更 " + r.count + " 条" + (r.since ? "(since " + r.since + ")" : ""); },
|
|
287
|
-
});
|
|
288
|
-
|
|
289
259
|
action("tasks.export", {
|
|
290
260
|
description: "导出任务:format=json|csv|markdown;非空 ids 优先,否则复用 tasks.list 的过滤条件与 filter/notices(含 statuses/urgent OR、三日期范围 AND、标题/描述/感受关键词)。保持列表默认限制:未传分页参数时最多 500 条;不接受分页参数;titleKey 只接受字符串,传数组会报错(分组结果无法直接拼成一份导出)",
|
|
291
261
|
input: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { metaSet } from '../db/db.js';
|
|
2
|
+
import { metaListPrefix, metaSet } from '../db/db.js';
|
|
3
3
|
import { taskTransaction } from '../task/write/task-transaction.js';
|
|
4
4
|
import { timelineError, timelineChange } from './timeline-store.js';
|
|
5
5
|
// The same pure classifier drives preview and apply. No startup backfill.
|
|
@@ -13,7 +13,7 @@ export function classifyTimelineHistory(rows) {
|
|
|
13
13
|
return {invalid,groups:[...groups].map(([key,members])=>({key,members,classification:members.length===1&&String(members[0].id)===key?'ambiguousSelfId':'legacyGrouped',restartOnlyCandidate:members.length>1&&new Set(members.map(r=>r.restart_key)).size===1}))};
|
|
14
14
|
}
|
|
15
15
|
function syncReviewCandidates(db) {
|
|
16
|
-
return db
|
|
16
|
+
return metaListPrefix(db,'task_timeline_migration:sync-candidate:').map(row=>{
|
|
17
17
|
try {
|
|
18
18
|
const value=JSON.parse(row.v);
|
|
19
19
|
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('invalid candidate');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { now } from '../db/db-core.js';
|
|
2
2
|
export { TIMELINE_DDL } from "../db/timeline-schema.js";
|
|
3
3
|
export function timelineError(code, message, details = {}) { return Object.assign(new Error(message), {code, ...details}); }
|
|
4
4
|
export function timelineIdArg(args, required = true) {
|
|
@@ -22,7 +22,6 @@ export function timelineOut(row) {
|
|
|
22
22
|
return {id:row.id,timelineId:row.id,timelineKey:row.id,title:row.title,description:row.description,createdAt:row.created_at,updatedAt:row.updated_at,deletedAt:row.deleted_at,rev:row.rev};
|
|
23
23
|
}
|
|
24
24
|
export function timelineChange(db, table, row, origin, api, op = 'update') {
|
|
25
|
-
logChange(db,table,row.id,op,row,origin,row.updated_at);
|
|
26
25
|
api.emit('tasks-changed',{id:row.id,op});
|
|
27
26
|
api.emit('task-timelines-changed',{id:row.id,op});
|
|
28
27
|
}
|
|
@@ -48,7 +47,7 @@ export function setMembership(db, taskId, timelineId, origin, api, {ts=now(), to
|
|
|
48
47
|
if (project) {
|
|
49
48
|
db.prepare('UPDATE task SET timeline_key=?,updated_at=?,rev=rev+1 WHERE id=?').run(timelineId,ts,String(taskId));
|
|
50
49
|
const task = db.prepare('SELECT * FROM task WHERE id=?').get(String(taskId));
|
|
51
|
-
if (task) {
|
|
50
|
+
if (task) { ; api.emit('tasks-changed',{id:task.id,op:'update'}); }
|
|
52
51
|
}
|
|
53
52
|
const ids = [old?.deleted_at === null ? old.timeline_id : null,timelineId];
|
|
54
53
|
if (touched) { for(const id of ids) if(id) touched.add(id); }
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { metaSetIfAbsent } from '../db/db-core.js';
|
|
1
2
|
/** Legacy keys are candidates only. Membership comes exclusively from stable link rows. */
|
|
2
3
|
function fail(code) { throw Object.assign(new Error(code), { code }); }
|
|
3
4
|
function projectTask(db, id) {
|
|
@@ -30,7 +31,7 @@ export function normalizeTimelineTask({db,row,local}) {
|
|
|
30
31
|
// Keep the incoming hint for explicit review; do not silently reinterpret it as membership.
|
|
31
32
|
const key = "task_timeline_migration:sync-candidate:" + JSON.stringify([row.id,row.updated_at,row.timeline_key ?? null]);
|
|
32
33
|
const value = JSON.stringify({taskId:row.id,timelineKey:row.timeline_key ?? null,updatedAt:row.updated_at,reason:"INCOMING_KEY_DIFFERS_FROM_LINK",requiresApproval:true});
|
|
33
|
-
db
|
|
34
|
+
metaSetIfAbsent(db,key,value);
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
return result;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** 节点无事务助手:调用者必须持有最外层 BEGIN IMMEDIATE,事件由调用者提交后发送。 */
|
|
2
2
|
import limits from '../../shared/tree/limits.cjs';
|
|
3
3
|
const { NAME_MAX } = limits;
|
|
4
|
-
import { nodeMap, newId, now, insertNode
|
|
4
|
+
import { nodeMap, newId, now, insertNode } from '../db/db.js';
|
|
5
5
|
import { ownershipError, pathFromMap } from '../task/model/task-ownership-path.js';
|
|
6
6
|
export function validateNodePlacement(db, parentId, name, excludeId = '') {
|
|
7
7
|
const map = nodeMap(db), parent = map.get(String(parentId));
|
|
@@ -21,6 +21,6 @@ export function insertOwnedNode(db, parentId, name, type, description, origin) {
|
|
|
21
21
|
const max = db.prepare('SELECT MAX(sort) AS m FROM task_node WHERE parent_id=? AND deleted_at IS NULL').get(String(parent.id));
|
|
22
22
|
const parentChain = pathFromMap(parent.id, nodeMap(db)).pathSegments;
|
|
23
23
|
const row = { id, name, description, type: String(type), parent_id: String(parent.id), path: '/' + parentChain.map(n => n.id).concat(id).join('/') + '/', sort: max.m == null ? 0 : Number(max.m)+1, depth: parentChain.length, created_at: ts, updated_at: ts, deleted_at: null, rev: 1 };
|
|
24
|
-
insertNode(db, row);
|
|
24
|
+
insertNode(db, row);
|
|
25
25
|
return row;
|
|
26
26
|
}
|
package/lib/tree/tree.js
CHANGED
|
@@ -11,15 +11,7 @@ import { nodeMap } from '../db/db.js';
|
|
|
11
11
|
* 叶子节点 type='1'(TABLE),组节点 type='0'(GROUP)。
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {
|
|
15
|
-
now,
|
|
16
|
-
idOf,
|
|
17
|
-
tx,
|
|
18
|
-
logChange,
|
|
19
|
-
rowNode,
|
|
20
|
-
childrenOf,
|
|
21
|
-
treeRoot,
|
|
22
|
-
} from "../db/db.js";
|
|
14
|
+
import { now, idOf, tx, rowNode, childrenOf, treeRoot } from "../db/db.js";
|
|
23
15
|
|
|
24
16
|
const NODE_TYPES = { GROUP: "0", TABLE: "1", ROOT_GROUP: "2" };
|
|
25
17
|
const TYPE_NAMES = { 组: "0", 任务组: "0", 表: "1", 任务表: "1" };
|
|
@@ -160,7 +152,6 @@ function renameAction(db, args, origin, api, inside = false) {
|
|
|
160
152
|
const ts = now();
|
|
161
153
|
write(db, function () {
|
|
162
154
|
db.prepare("UPDATE task_node SET name=?, updated_at=?, rev=rev+1 WHERE id=?").run(name, ts, id);
|
|
163
|
-
logChange(db, "task_node", id, "upsert", Object.assign({}, node, { name: name, updated_at: ts, rev: Number(node.rev) + 1 }), origin, ts);
|
|
164
155
|
});
|
|
165
156
|
api.emit("task-nodes-changed", { id: id, op: "rename" });
|
|
166
157
|
return { node: rowNode(Object.assign({}, node, { name: name, updated_at: ts, rev: Number(node.rev) + 1 }), []) };
|
|
@@ -175,7 +166,6 @@ function resort(db, parentId, ts, origin) {
|
|
|
175
166
|
if (Number(row.sort) !== i) {
|
|
176
167
|
const next = Object.assign({}, row, { sort: i, updated_at: ts, rev: Number(row.rev) + 1 });
|
|
177
168
|
db.prepare("UPDATE task_node SET sort=?, updated_at=?, rev=rev+1 WHERE id=?").run(i, ts, String(row.id));
|
|
178
|
-
logChange(db, "task_node", String(row.id), "upsert", next, origin, ts);
|
|
179
169
|
}
|
|
180
170
|
i++;
|
|
181
171
|
}
|
|
@@ -238,14 +228,6 @@ function moveAction(db, args, origin, api, inside = false) {
|
|
|
238
228
|
ts,
|
|
239
229
|
String(row.id),
|
|
240
230
|
);
|
|
241
|
-
logChange(db, "task_node", String(row.id), "upsert", Object.assign({}, row, {
|
|
242
|
-
parent_id: String(row.id) === String(source.id) ? String(newParent.id) : String(row.parent_id),
|
|
243
|
-
path: nextPath,
|
|
244
|
-
depth: nextDepth,
|
|
245
|
-
sort: String(row.id) === String(source.id) ? newSort : Number(row.sort),
|
|
246
|
-
updated_at: ts,
|
|
247
|
-
rev: Number(row.rev) + 1,
|
|
248
|
-
}), origin, ts);
|
|
249
231
|
}
|
|
250
232
|
|
|
251
233
|
const ordered = db.prepare(
|
|
@@ -258,7 +240,6 @@ function moveAction(db, args, origin, api, inside = false) {
|
|
|
258
240
|
if (Number(row.sort) !== i) {
|
|
259
241
|
const next = Object.assign({}, row, { sort: i, updated_at: ts, rev: Number(row.rev) + 1 });
|
|
260
242
|
db.prepare("UPDATE task_node SET sort=?, updated_at=?, rev=rev+1 WHERE id=?").run(i, ts, String(row.id));
|
|
261
|
-
logChange(db, "task_node", String(row.id), "upsert", next, origin, ts);
|
|
262
243
|
}
|
|
263
244
|
i++;
|
|
264
245
|
}
|
|
@@ -284,7 +265,6 @@ function deleteAction(db, args, origin, api) {
|
|
|
284
265
|
for (const t of tasks) {
|
|
285
266
|
const tomb = Object.assign({}, t, { deleted_at: ts, updated_at: ts, rev: Number(t.rev) + 1 });
|
|
286
267
|
db.prepare("UPDATE task SET deleted_at=?, updated_at=?, rev=rev+1 WHERE id=?").run(ts, ts, String(t.id));
|
|
287
|
-
logChange(db, "task", String(t.id), "delete", tomb, origin, ts);
|
|
288
268
|
api.emit("tasks-changed", { id: String(t.id), op: "delete" });
|
|
289
269
|
taskCount++;
|
|
290
270
|
}
|
|
@@ -292,7 +272,6 @@ function deleteAction(db, args, origin, api) {
|
|
|
292
272
|
for (const row of rows) {
|
|
293
273
|
const tomb = Object.assign({}, row, { deleted_at: ts, updated_at: ts, rev: Number(row.rev) + 1 });
|
|
294
274
|
db.prepare("UPDATE task_node SET deleted_at=?, updated_at=?, rev=rev+1 WHERE id=?").run(ts, ts, String(row.id));
|
|
295
|
-
logChange(db, "task_node", String(row.id), "delete", tomb, origin, ts);
|
|
296
275
|
}
|
|
297
276
|
});
|
|
298
277
|
api.emit("task-nodes-changed", { id: id, op: "delete" });
|
|
@@ -372,7 +351,6 @@ function updateNodeAction(db, args, origin, api, inside = false) {
|
|
|
372
351
|
ts,
|
|
373
352
|
id,
|
|
374
353
|
);
|
|
375
|
-
logChange(db, "task_node", id, "upsert", next, origin, ts);
|
|
376
354
|
});
|
|
377
355
|
api.emit("task-nodes-changed", { id: id, op: "update" });
|
|
378
356
|
return { ok: true, changed: true, node: rowNode(next, []) };
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 口径:任何一方(link / workspace / task)已软删,关联就不可见;
|
|
5
5
|
* 删除工作区不删任务,删除任务会连带软删它的关联行;不做级联硬删。
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { now } from '../db/db-core.js';
|
|
8
8
|
|
|
9
9
|
export function workspaceError(code, message, details = {}) {
|
|
10
10
|
return Object.assign(new Error(message), { code, ...details });
|
|
@@ -95,7 +95,6 @@ function writeLink(db, workspaceId, taskId, ts, origin, api, op) {
|
|
|
95
95
|
db.prepare(
|
|
96
96
|
'INSERT INTO task_workspace_link(id,workspace_id,task_id,created_at,updated_at,deleted_at,rev) VALUES(?,?,?,?,?,?,?) ON CONFLICT(id) DO UPDATE SET workspace_id=excluded.workspace_id,task_id=excluded.task_id,updated_at=excluded.updated_at,deleted_at=excluded.deleted_at,rev=excluded.rev',
|
|
97
97
|
).run(...Object.values(row));
|
|
98
|
-
logChange(db, 'task_workspace_link', id, op, row, origin, ts);
|
|
99
98
|
api.emit('tasks-changed', { id: String(taskId), op: 'workspace' });
|
|
100
99
|
api.emit('task-workspaces-changed', { id, workspaceId: String(workspaceId), taskId: String(taskId), op });
|
|
101
100
|
return row;
|
|
@@ -104,7 +103,6 @@ function writeLink(db, workspaceId, taskId, ts, origin, api, op) {
|
|
|
104
103
|
function softDeleteLink(db, row, ts, origin, api) {
|
|
105
104
|
const next = Object.assign({}, row, { deleted_at: ts, updated_at: ts, rev: Number(row.rev) + 1 });
|
|
106
105
|
db.prepare('UPDATE task_workspace_link SET deleted_at=?,updated_at=?,rev=? WHERE id=?').run(ts, ts, next.rev, row.id);
|
|
107
|
-
logChange(db, 'task_workspace_link', row.id, 'delete', next, origin, ts);
|
|
108
106
|
api.emit('tasks-changed', { id: String(row.task_id), op: 'workspace' });
|
|
109
107
|
api.emit('task-workspaces-changed', { id: row.id, workspaceId: String(row.workspace_id), taskId: String(row.task_id), op: 'delete' });
|
|
110
108
|
}
|
|
@@ -181,7 +179,6 @@ export function removeWorkspace(db, workspaceId, origin, api, ts = now(), dryRun
|
|
|
181
179
|
for (const link of links) softDeleteLink(db, link, ts, origin, api);
|
|
182
180
|
const next = Object.assign({}, workspace, { deleted_at: ts, updated_at: ts, rev: Number(workspace.rev) + 1 });
|
|
183
181
|
db.prepare('UPDATE task_workspace SET deleted_at=?,updated_at=?,rev=? WHERE id=?').run(ts, ts, next.rev, workspace.id);
|
|
184
|
-
logChange(db, 'task_workspace', workspace.id, 'delete', next, origin, ts);
|
|
185
182
|
api.emit('task-workspaces-changed', { id: String(workspace.id), op: 'delete' });
|
|
186
183
|
api.emit('tasks-changed', { id: String(workspace.id), op: 'workspace' });
|
|
187
184
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-workbench-tasks",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.11.0",
|
|
4
4
|
"description": "个人工作台任务插件:任务树、优先级、截止日、时间线与重启",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"id": "wb-addon-tasks",
|
|
18
18
|
"title": "任务",
|
|
19
19
|
"description": "任务树 + 统计/记录/时间线/工作区四个视图:紧急/已关闭/已开启/已完成/总览,可按标签筛选,附统计报表;配置项由宿主统一配置中心渲染",
|
|
20
|
-
"version": "5.
|
|
21
|
-
"minShell": "0.
|
|
20
|
+
"version": "5.11.0",
|
|
21
|
+
"minShell": "0.21.0",
|
|
22
22
|
"tables": [
|
|
23
23
|
"task",
|
|
24
24
|
"task_node",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"./package.json": "./package.json"
|
|
92
92
|
},
|
|
93
93
|
"dependencies": {
|
|
94
|
-
"dsh-workbench-host": "^0.
|
|
94
|
+
"dsh-workbench-host": "^0.21.1"
|
|
95
95
|
},
|
|
96
96
|
"dsh": {
|
|
97
97
|
"bundle": {
|