@ricsam/r5d-worker 0.0.123 → 0.0.125

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.
Files changed (64) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/command-launcher.cjs +6 -2
  3. package/dist/cjs/main.cjs +496 -238
  4. package/dist/cjs/package.json +1 -1
  5. package/dist/cjs/project-checkout-garbage.cjs +32 -3
  6. package/dist/cjs/project-workspace-state.cjs +51 -35
  7. package/dist/cjs/project-worktrees.cjs +79 -34
  8. package/dist/cjs/recovery-journal-protocol.cjs +56 -0
  9. package/dist/cjs/recovery-journal-runtime.cjs +133 -0
  10. package/dist/cjs/recovery-journal-thread.cjs +9 -0
  11. package/dist/cjs/recovery-journal.cjs +735 -0
  12. package/dist/cjs/recovery-store.cjs +8 -0
  13. package/dist/cjs/session-file-mutations.cjs +61 -0
  14. package/dist/cjs/working-tree-mirror.cjs +1 -0
  15. package/dist/cjs/workspace-command-sync-policy.cjs +37 -8
  16. package/dist/cjs/workspace-filesystem-executor-thread.cjs +36 -0
  17. package/dist/cjs/workspace-filesystem-executor.cjs +327 -0
  18. package/dist/cjs/workspace-filesystem-job-types.cjs +134 -0
  19. package/dist/cjs/workspace-filesystem-jobs.cjs +57 -0
  20. package/dist/cjs/workspace-git-sync.cjs +275 -201
  21. package/dist/cjs/workspace-mount-hold-fence.cjs +120 -0
  22. package/dist/mjs/command-launcher.mjs +6 -2
  23. package/dist/mjs/main.mjs +499 -244
  24. package/dist/mjs/package.json +1 -1
  25. package/dist/mjs/project-checkout-garbage.mjs +30 -2
  26. package/dist/mjs/project-workspace-state.mjs +51 -35
  27. package/dist/mjs/project-worktrees.mjs +74 -34
  28. package/dist/mjs/recovery-journal-protocol.mjs +30 -0
  29. package/dist/mjs/recovery-journal-runtime.mjs +112 -0
  30. package/dist/mjs/recovery-journal-thread.mjs +8 -0
  31. package/dist/mjs/recovery-journal.mjs +687 -0
  32. package/dist/mjs/recovery-store.mjs +8 -0
  33. package/dist/mjs/session-file-mutations.mjs +37 -0
  34. package/dist/mjs/working-tree-mirror.mjs +1 -0
  35. package/dist/mjs/workspace-command-sync-policy.mjs +37 -8
  36. package/dist/mjs/workspace-filesystem-executor-thread.mjs +38 -0
  37. package/dist/mjs/workspace-filesystem-executor.mjs +287 -0
  38. package/dist/mjs/workspace-filesystem-job-types.mjs +106 -0
  39. package/dist/mjs/workspace-filesystem-jobs.mjs +51 -0
  40. package/dist/mjs/workspace-git-sync.mjs +264 -202
  41. package/dist/mjs/workspace-mount-hold-fence.mjs +95 -0
  42. package/dist/types/command-launcher.d.ts +2 -1
  43. package/dist/types/main.d.ts +30 -19
  44. package/dist/types/project-checkout-garbage.d.ts +19 -2
  45. package/dist/types/project-workspace-state.d.ts +9 -9
  46. package/dist/types/project-worktrees.d.ts +49 -5
  47. package/dist/types/recovery-journal-protocol.d.ts +35 -0
  48. package/dist/types/recovery-journal-runtime.d.ts +12 -0
  49. package/dist/types/recovery-journal-stall-fixture.d.ts +1 -0
  50. package/dist/types/recovery-journal-thread.d.ts +1 -0
  51. package/dist/types/recovery-journal.d.ts +246 -0
  52. package/dist/types/recovery-store.d.ts +6 -0
  53. package/dist/types/session-file-mutations.d.ts +22 -0
  54. package/dist/types/workspace-command-sync-policy.d.ts +22 -7
  55. package/dist/types/workspace-filesystem-executor-thread.d.ts +1 -0
  56. package/dist/types/workspace-filesystem-executor.d.ts +123 -0
  57. package/dist/types/workspace-filesystem-job-types.d.ts +246 -0
  58. package/dist/types/workspace-filesystem-jobs.d.ts +7 -0
  59. package/dist/types/workspace-git-sync.d.ts +113 -7
  60. package/dist/types/workspace-mount-hold-fence.d.ts +42 -0
  61. package/package.json +1 -1
  62. package/dist/cjs/project-snapshot-recovery-runner.cjs +0 -171
  63. package/dist/mjs/project-snapshot-recovery-runner.mjs +0 -135
  64. package/dist/types/project-snapshot-recovery-runner.d.ts +0 -10
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var recovery_journal_runtime_exports = {};
20
+ __export(recovery_journal_runtime_exports, {
21
+ serveRecoveryJournal: () => serveRecoveryJournal
22
+ });
23
+ module.exports = __toCommonJS(recovery_journal_runtime_exports);
24
+ var import_recovery_journal_protocol = require("./recovery-journal-protocol.cjs");
25
+ var import_recovery_store = require("./recovery-store.cjs");
26
+ function serveRecoveryJournal(port, filename, hooks = {}) {
27
+ const store = new import_recovery_store.WorkerRecoveryStore(filename);
28
+ const outputReplays = /* @__PURE__ */ new Map();
29
+ let nextReplayId = 1;
30
+ function runOp(op, args) {
31
+ switch (op) {
32
+ case "admit": {
33
+ const message = args[0];
34
+ const admission = store.admit(message);
35
+ return {
36
+ admission,
37
+ response: admission === "new" ? void 0 : store.response(message.requestId),
38
+ cancelled: store.isRequestCancelled(message.requestId)
39
+ };
40
+ }
41
+ case "readmitUnknownBranchDeletion":
42
+ return store.readmitUnknownBranchDeletion(args[0]);
43
+ case "record": {
44
+ const message = args[0];
45
+ if (typeof message.requestId === "string" && store.isUnknown(message.requestId)) return { suppressed: true, recorded: message };
46
+ return { suppressed: false, recorded: store.record(message) };
47
+ }
48
+ case "unknown":
49
+ store.unknown(args[0]);
50
+ return null;
51
+ case "unknownRun":
52
+ store.unknownRun(args[0]);
53
+ return null;
54
+ case "acknowledgeResult":
55
+ store.acknowledgeResult(args[0]);
56
+ return null;
57
+ case "acknowledgeOutput":
58
+ store.acknowledgeOutput(args[0], args[1], args[2]);
59
+ return null;
60
+ case "acknowledgeTerminal":
61
+ store.acknowledgeTerminal(args[0]);
62
+ return null;
63
+ case "cancelSession":
64
+ store.cancelSession(args[0]);
65
+ return null;
66
+ case "isRequestCancelled":
67
+ return store.isRequestCancelled(args[0]);
68
+ case "operations":
69
+ return store.operations();
70
+ case "recoveryState": {
71
+ const requests = args[0];
72
+ return {
73
+ operations: store.operations(),
74
+ cursors: store.outputCursors(),
75
+ responses: store.responses(requests),
76
+ terminals: store.terminals()
77
+ };
78
+ }
79
+ case "terminals":
80
+ return store.terminals();
81
+ case "outputReplayBegin": {
82
+ const replayId = nextReplayId++;
83
+ outputReplays.set(replayId, store.output(args[0]));
84
+ return replayId;
85
+ }
86
+ case "outputReplayNext": {
87
+ const replay = outputReplays.get(args[0]);
88
+ if (!replay) return { frames: [], done: true };
89
+ const maxFrames = args[1];
90
+ const frames = [];
91
+ while (frames.length < maxFrames) {
92
+ const next = replay.next();
93
+ if (next.done) {
94
+ outputReplays.delete(args[0]);
95
+ return { frames, done: true };
96
+ }
97
+ frames.push(next.value);
98
+ }
99
+ return { frames, done: false };
100
+ }
101
+ case "outputReplayEnd":
102
+ outputReplays.delete(args[0]);
103
+ return null;
104
+ }
105
+ }
106
+ port.on("message", (message) => {
107
+ if (!message || typeof message !== "object") return;
108
+ const request = message;
109
+ if (request.type !== "batch" || typeof request.id !== "number" || !Array.isArray(request.entries)) return;
110
+ const entries = request.entries;
111
+ try {
112
+ hooks.beforeBatch?.();
113
+ const results = store.batch(
114
+ () => entries.map((entry) => {
115
+ if (!(0, import_recovery_journal_protocol.isWorkerRecoveryJournalOp)(entry.op)) throw new Error(`Unknown recovery journal operation: ${String(entry.op)}`);
116
+ return { seq: entry.seq, value: runOp(entry.op, entry.args) };
117
+ })
118
+ );
119
+ port.postMessage({ type: "batch_result", id: request.id, results });
120
+ } catch (error) {
121
+ port.postMessage({
122
+ type: "batch_failure",
123
+ id: request.id,
124
+ error: (0, import_recovery_journal_protocol.serializeWorkerRecoveryJournalError)(error)
125
+ });
126
+ }
127
+ });
128
+ port.postMessage({ type: "ready", ledgerId: store.ledgerId });
129
+ }
130
+ // Annotate the CommonJS export names for ESM import in node:
131
+ 0 && (module.exports = {
132
+ serveRecoveryJournal
133
+ });
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ var import_node_worker_threads = require("node:worker_threads");
3
+ var import_recovery_journal_runtime = require("./recovery-journal-runtime.cjs");
4
+ if (import_node_worker_threads.isMainThread || !import_node_worker_threads.parentPort) {
5
+ throw new Error("The recovery journal thread must be started by the worker runtime");
6
+ }
7
+ const data = import_node_worker_threads.workerData;
8
+ if (!data || typeof data.filename !== "string" || !data.filename) throw new Error("The recovery journal thread needs a store filename");
9
+ (0, import_recovery_journal_runtime.serveRecoveryJournal)(import_node_worker_threads.parentPort, data.filename);