@executablemd/durable-streams 0.4.0 → 0.4.2
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/esm/each.js +2 -1
- package/esm/effect.js +6 -3
- package/esm/replay-index.js +16 -8
- package/esm/serialize.js +4 -2
- package/package.json +1 -1
package/esm/each.js
CHANGED
|
@@ -60,8 +60,9 @@ let activeState = null;
|
|
|
60
60
|
function durableEachFetch(name, source) {
|
|
61
61
|
return (function* () {
|
|
62
62
|
const result = (yield createDurableOperation({ type: "each", name }, () => source.next()));
|
|
63
|
-
if ("done" in result)
|
|
63
|
+
if ("done" in result) {
|
|
64
64
|
return DONE;
|
|
65
|
+
}
|
|
65
66
|
return result.value;
|
|
66
67
|
})();
|
|
67
68
|
}
|
package/esm/effect.js
CHANGED
|
@@ -135,16 +135,18 @@ export function createDurableEffect(desc, execute) {
|
|
|
135
135
|
enter(resolve, routine) {
|
|
136
136
|
const ctx = routine.scope.expect(DurableCtx);
|
|
137
137
|
const replay = checkReplay(desc, resolve, routine, ctx);
|
|
138
|
-
if (replay.path === "replayed")
|
|
138
|
+
if (replay.path === "replayed") {
|
|
139
139
|
return replay.teardown;
|
|
140
|
+
}
|
|
140
141
|
// ── LIVE PATH ──
|
|
141
142
|
let settled = false;
|
|
142
143
|
let tornDown = false;
|
|
143
144
|
let teardown = () => { };
|
|
144
145
|
/** Persist a Yield event then resume the generator. */
|
|
145
146
|
function persistAndResolve(result) {
|
|
146
|
-
if (settled)
|
|
147
|
+
if (settled) {
|
|
147
148
|
return;
|
|
149
|
+
}
|
|
148
150
|
settled = true;
|
|
149
151
|
const event = {
|
|
150
152
|
type: "yield",
|
|
@@ -227,8 +229,9 @@ export function createDurableOperation(desc, execute) {
|
|
|
227
229
|
enter(resolve, routine) {
|
|
228
230
|
const ctx = routine.scope.expect(DurableCtx);
|
|
229
231
|
const replay = checkReplay(desc, resolve, routine, ctx);
|
|
230
|
-
if (replay.path === "replayed")
|
|
232
|
+
if (replay.path === "replayed") {
|
|
231
233
|
return replay.teardown;
|
|
234
|
+
}
|
|
232
235
|
// ── LIVE PATH ──
|
|
233
236
|
// Run the entire execute → capture → persist → resolve sequence
|
|
234
237
|
// as a structured operation in the routine's scope.
|
package/esm/replay-index.js
CHANGED
|
@@ -47,8 +47,9 @@ export class ReplayIndex {
|
|
|
47
47
|
* or undefined if the cursor is past the end or replay is disabled.
|
|
48
48
|
*/
|
|
49
49
|
peekYield(coroutineId) {
|
|
50
|
-
if (this.disabled.has(coroutineId))
|
|
50
|
+
if (this.disabled.has(coroutineId)) {
|
|
51
51
|
return undefined;
|
|
52
|
+
}
|
|
52
53
|
const list = this.yields.get(coroutineId);
|
|
53
54
|
const cursor = this.cursors.get(coroutineId) ?? 0;
|
|
54
55
|
return list?.[cursor];
|
|
@@ -64,14 +65,16 @@ export class ReplayIndex {
|
|
|
64
65
|
}
|
|
65
66
|
/** Returns true if a Close event exists for this coroutine (and replay is not disabled). */
|
|
66
67
|
hasClose(coroutineId) {
|
|
67
|
-
if (this.disabled.has(coroutineId))
|
|
68
|
+
if (this.disabled.has(coroutineId)) {
|
|
68
69
|
return false;
|
|
70
|
+
}
|
|
69
71
|
return this.closes.has(coroutineId);
|
|
70
72
|
}
|
|
71
73
|
/** Returns the Close event for this coroutine, or undefined. */
|
|
72
74
|
getClose(coroutineId) {
|
|
73
|
-
if (this.disabled.has(coroutineId))
|
|
75
|
+
if (this.disabled.has(coroutineId)) {
|
|
74
76
|
return undefined;
|
|
77
|
+
}
|
|
75
78
|
return this.closes.get(coroutineId);
|
|
76
79
|
}
|
|
77
80
|
/**
|
|
@@ -82,11 +85,13 @@ export class ReplayIndex {
|
|
|
82
85
|
*/
|
|
83
86
|
hasAnyUnconsumedYields() {
|
|
84
87
|
for (const [coroutineId, entries] of this.yields.entries()) {
|
|
85
|
-
if (this.disabled.has(coroutineId))
|
|
88
|
+
if (this.disabled.has(coroutineId)) {
|
|
86
89
|
continue;
|
|
90
|
+
}
|
|
87
91
|
const cursor = this.cursors.get(coroutineId) ?? 0;
|
|
88
|
-
if (cursor < entries.length)
|
|
92
|
+
if (cursor < entries.length) {
|
|
89
93
|
return true;
|
|
94
|
+
}
|
|
90
95
|
}
|
|
91
96
|
return false;
|
|
92
97
|
}
|
|
@@ -102,10 +107,12 @@ export class ReplayIndex {
|
|
|
102
107
|
*/
|
|
103
108
|
firstUnconsumed() {
|
|
104
109
|
for (const [coroutineId, entries] of this.yields.entries()) {
|
|
105
|
-
if (this.disabled.has(coroutineId))
|
|
110
|
+
if (this.disabled.has(coroutineId)) {
|
|
106
111
|
continue;
|
|
107
|
-
|
|
112
|
+
}
|
|
113
|
+
if (this.closes.has(coroutineId)) {
|
|
108
114
|
continue;
|
|
115
|
+
}
|
|
109
116
|
const cursor = this.cursors.get(coroutineId) ?? 0;
|
|
110
117
|
if (cursor < entries.length) {
|
|
111
118
|
return { coroutineId, cursor, totalYields: entries.length };
|
|
@@ -121,8 +128,9 @@ export class ReplayIndex {
|
|
|
121
128
|
* Returns false if replay is disabled (run-live mode).
|
|
122
129
|
*/
|
|
123
130
|
isFullyReplayed(coroutineId) {
|
|
124
|
-
if (this.disabled.has(coroutineId))
|
|
131
|
+
if (this.disabled.has(coroutineId)) {
|
|
125
132
|
return false;
|
|
133
|
+
}
|
|
126
134
|
return this.peekYield(coroutineId) === undefined && this.hasClose(coroutineId);
|
|
127
135
|
}
|
|
128
136
|
/** Returns the total number of yield entries for this coroutine. */
|
package/esm/serialize.js
CHANGED
|
@@ -17,10 +17,12 @@ export function serializeError(error) {
|
|
|
17
17
|
/** Deserialize a SerializedError back to an Error. */
|
|
18
18
|
export function deserializeError(se) {
|
|
19
19
|
const error = new Error(se.message);
|
|
20
|
-
if (se.name)
|
|
20
|
+
if (se.name) {
|
|
21
21
|
error.name = se.name;
|
|
22
|
-
|
|
22
|
+
}
|
|
23
|
+
if (se.stack) {
|
|
23
24
|
error.stack = se.stack;
|
|
25
|
+
}
|
|
24
26
|
return error;
|
|
25
27
|
}
|
|
26
28
|
/**
|