@moberg_hr/work-tree 1.9.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/wd-bin.js CHANGED
@@ -8982,6 +8982,14 @@ function getCommentFileStore(sessionId) {
8982
8982
  },
8983
8983
  reload() {
8984
8984
  reloadInner();
8985
+ },
8986
+ clearAll() {
8987
+ return lockedMutate(() => {
8988
+ const list = inner.list();
8989
+ const n = list.length;
8990
+ list.length = 0;
8991
+ return { value: n, persisted: n > 0 };
8992
+ });
8985
8993
  }
8986
8994
  };
8987
8995
  cache.set(sessionId, store);
@@ -9880,6 +9888,12 @@ function markScopeEnded(hash) {
9880
9888
  entry.scope.ended = true;
9881
9889
  return true;
9882
9890
  }
9891
+ function reviveScope(hash) {
9892
+ const entry = scopes.get(hash);
9893
+ if (!entry || !entry.scope.ended) return false;
9894
+ entry.scope.ended = false;
9895
+ return true;
9896
+ }
9883
9897
  function getScope(hash) {
9884
9898
  return scopes.get(hash)?.scope ?? null;
9885
9899
  }
@@ -9968,6 +9982,10 @@ function mountScopeRoutes(app, opts) {
9968
9982
  }
9969
9983
  const scopeBus = new EventEmitter();
9970
9984
  scopeBus.setMaxListeners(0);
9985
+ function emitCommentsChanged(payload) {
9986
+ opts.broadcast("comments-changed", payload);
9987
+ scopeBus.emit("comments-changed", payload);
9988
+ }
9971
9989
  function scopeRepos(scopePaths) {
9972
9990
  return scopePaths.map((p) => ({ name: p, root: p }));
9973
9991
  }
@@ -9984,6 +10002,12 @@ function mountScopeRoutes(app, opts) {
9984
10002
  const { paths, label: label2 } = c.req.valid("json");
9985
10003
  try {
9986
10004
  const scope = registerScope(paths, label2);
10005
+ if (reviveScope(scope.hash)) {
10006
+ const cleared = commentStore(scope.hash).clearAll();
10007
+ if (cleared > 0) {
10008
+ emitCommentsChanged({ scopeHash: scope.hash });
10009
+ }
10010
+ }
9987
10011
  opts.broadcast("scopes-changed", { hash: scope.hash });
9988
10012
  const announceCheckpoint = (entry) => {
9989
10013
  const payload = { scopeHash: scope.hash, id: entry.id };
@@ -10222,7 +10246,7 @@ function mountScopeRoutes(app, opts) {
10222
10246
  const store = commentStore(scope.hash);
10223
10247
  try {
10224
10248
  const comment = store.post(c.req.valid("json"));
10225
- opts.broadcast("comments-changed", {
10249
+ emitCommentsChanged({
10226
10250
  scopeHash: scope.hash,
10227
10251
  id: comment.id
10228
10252
  });
@@ -10238,7 +10262,7 @@ function mountScopeRoutes(app, opts) {
10238
10262
  const store = commentStore(scope.hash);
10239
10263
  const removed = store.remove(c.req.param("cid"));
10240
10264
  if (removed) {
10241
- opts.broadcast("comments-changed", {
10265
+ emitCommentsChanged({
10242
10266
  scopeHash: scope.hash,
10243
10267
  deleted: c.req.param("cid")
10244
10268
  });
@@ -10257,7 +10281,7 @@ function mountScopeRoutes(app, opts) {
10257
10281
  c.req.valid("json").resolved
10258
10282
  );
10259
10283
  if (updated) {
10260
- opts.broadcast("comments-changed", {
10284
+ emitCommentsChanged({
10261
10285
  scopeHash: scope.hash,
10262
10286
  id: updated.id
10263
10287
  });
@@ -10273,7 +10297,7 @@ function mountScopeRoutes(app, opts) {
10273
10297
  if (!scope) return c.json({ error: "unknown scope" }, 404);
10274
10298
  const store = commentStore(scope.hash);
10275
10299
  const result = store.submit(c.req.valid("json").summary);
10276
- opts.broadcast("comments-changed", {
10300
+ emitCommentsChanged({
10277
10301
  scopeHash: scope.hash,
10278
10302
  submittedCount: result.drafts.length
10279
10303
  });
@@ -10289,7 +10313,7 @@ function mountScopeRoutes(app, opts) {
10289
10313
  const store = commentStore(scope.hash);
10290
10314
  const discarded = store.discardDrafts();
10291
10315
  if (discarded > 0) {
10292
- opts.broadcast("comments-changed", { scopeHash: scope.hash });
10316
+ emitCommentsChanged({ scopeHash: scope.hash });
10293
10317
  }
10294
10318
  return c.json({ discarded, comments: store.snapshot() });
10295
10319
  });
@@ -10299,7 +10323,9 @@ function mountScopeRoutes(app, opts) {
10299
10323
  const store = commentStore(scope.hash);
10300
10324
  const count = store.list().length;
10301
10325
  markScopeEnded(scope.hash);
10302
- opts.broadcast("review-done", { scopeHash: scope.hash, count });
10326
+ const payload = { scopeHash: scope.hash, count };
10327
+ opts.broadcast("review-done", payload);
10328
+ scopeBus.emit("review-done", payload);
10303
10329
  return c.json({ ok: true, count });
10304
10330
  });
10305
10331
  app.get("/api/scopes/:hash/events", (c) => {
@@ -10322,11 +10348,31 @@ function mountScopeRoutes(app, opts) {
10322
10348
  });
10323
10349
  };
10324
10350
  scopeBus.on("checkpoints-changed", onCheckpoint);
10351
+ const onComments = (payload) => {
10352
+ if (payload.scopeHash !== scope.hash) return;
10353
+ stream.writeSSE({
10354
+ event: "comments-changed",
10355
+ data: JSON.stringify(payload)
10356
+ }).catch(() => {
10357
+ });
10358
+ };
10359
+ scopeBus.on("comments-changed", onComments);
10360
+ const onDone = (payload) => {
10361
+ if (payload.scopeHash !== scope.hash) return;
10362
+ stream.writeSSE({
10363
+ event: "review-done",
10364
+ data: JSON.stringify(payload)
10365
+ }).catch(() => {
10366
+ });
10367
+ };
10368
+ scopeBus.on("review-done", onDone);
10325
10369
  await stream.writeSSE({ event: "connected", data: "" });
10326
10370
  await new Promise((resolve) => {
10327
10371
  stream.onAbort(() => {
10328
10372
  unsubscribe?.();
10329
10373
  scopeBus.off("checkpoints-changed", onCheckpoint);
10374
+ scopeBus.off("comments-changed", onComments);
10375
+ scopeBus.off("review-done", onDone);
10330
10376
  resolve();
10331
10377
  });
10332
10378
  });
@@ -11458,7 +11504,7 @@ function completeGroupBranches(groupName, repoAliases, current, config, done) {
11458
11504
  }
11459
11505
 
11460
11506
  // src/version.ts
11461
- var VERSION = true ? "1.9.0" : "dev";
11507
+ var VERSION = true ? "1.9.1" : "dev";
11462
11508
 
11463
11509
  // src/cli.ts
11464
11510
  function showHelp() {