effect-browser 0.3.0-beta.13 → 0.3.0-beta.15
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 +59 -19
- package/dist/{Browser-QiT6Cdn_.mjs → Browser-BBSySyjT.mjs} +2 -2
- package/dist/{Browser-QiT6Cdn_.mjs.map → Browser-BBSySyjT.mjs.map} +1 -1
- package/dist/Browser.d.mts +1 -1
- package/dist/Browser.mjs +1 -1
- package/dist/Cdp.mjs +1 -1
- package/dist/Chromium.mjs +1 -1
- package/dist/Expect.d.mts +1 -1
- package/dist/Expect.mjs +1 -1
- package/dist/{Frame-Di2PxyF7.d.mts → Frame-DkNdjjjr.d.mts} +3 -5
- package/dist/Frame.d.mts +1 -1
- package/dist/Frame.mjs +2 -4
- package/dist/Frame.mjs.map +1 -1
- package/dist/Moment.d.mts +1 -1
- package/dist/Moment.mjs +7 -3
- package/dist/Moment.mjs.map +1 -1
- package/dist/{Page-B7X6DQUn.d.mts → Page-DL9eylp3.d.mts} +2 -2
- package/dist/Page.d.mts +1 -1
- package/dist/{Plan-BS0jpENY.d.mts → Plan-6As6vcwT.d.mts} +3 -3
- package/dist/{Plan-Bl2NM1D5.mjs → Plan-CXA2BW-G.mjs} +4 -6
- package/dist/Plan-CXA2BW-G.mjs.map +1 -0
- package/dist/Plan.d.mts +1 -1
- package/dist/Plan.mjs +1 -1
- package/dist/Policy.d.mts +1 -1
- package/dist/Presentation.d.mts +1 -1
- package/dist/Presentation.mjs +1 -1
- package/dist/Stage.d.mts +5 -4
- package/dist/Stage.mjs +53 -20
- package/dist/Stage.mjs.map +1 -1
- package/dist/{Supervisor-CYWFK3vM.d.mts → Supervisor-5tZ47hR5.d.mts} +40 -10
- package/dist/{Supervisor-TNKNOVzu.mjs → Supervisor-DaGlQVjv.mjs} +120 -68
- package/dist/Supervisor-DaGlQVjv.mjs.map +1 -0
- package/dist/Supervisor.d.mts +2 -2
- package/dist/Supervisor.mjs +2 -2
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/{page-ZxMhw16l.mjs → page-B92QnRfT.mjs} +196 -166
- package/dist/page-B92QnRfT.mjs.map +1 -0
- package/package.json +1 -1
- package/src/Frame.ts +2 -4
- package/src/Moment.ts +14 -3
- package/src/Plan.ts +7 -6
- package/src/Stage.ts +61 -21
- package/src/Supervisor.ts +205 -172
- package/src/internal/pictures/capture.ts +172 -188
- package/src/internal/pictures/pictures.ts +50 -73
- package/src/internal/pictures/quiescence.ts +94 -0
- package/src/internal/reading/ready.ts +9 -3
- package/src/internal/supervisor/lifecycle.ts +40 -15
- package/dist/Plan-Bl2NM1D5.mjs.map +0 -1
- package/dist/Supervisor-TNKNOVzu.mjs.map +0 -1
- package/dist/page-ZxMhw16l.mjs.map +0 -1
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* one call where a device pixel is a CSS pixel and nothing is cropped, and two otherwise, unless
|
|
5
5
|
* Playwright emulates the viewport. The page's first clipped picture also holds the screen it reads.
|
|
6
6
|
*/
|
|
7
|
-
import { Duration, Effect, Option, Schedule, Schema
|
|
7
|
+
import { Duration, Effect, Option, Schedule, Schema } from "effect";
|
|
8
8
|
|
|
9
9
|
import { BrowserError, Failed, InvalidRequest } from "../../BrowserError.ts";
|
|
10
10
|
import { Frame, Image, Screenshot } from "../../Frame.ts";
|
|
@@ -156,7 +156,7 @@ const ScreenSize = Schema.Struct({ width: Schema.Int, height: Schema.Int });
|
|
|
156
156
|
// A new picture in CSS pixels. Where a device pixel is not a CSS pixel, or for a crop, it is
|
|
157
157
|
// Playwright's clip over fresh layout metrics: document coordinates from the visual viewport's
|
|
158
158
|
// place, and its pinch scale divided by the device's. Chromium draws such a capture into a
|
|
159
|
-
// running screencast, so the capture
|
|
159
|
+
// running screencast, so the native capture pauses for the whole camera operation and restoration.
|
|
160
160
|
//
|
|
161
161
|
// Chromium takes a clipped picture through the device emulation of the session that asks for it,
|
|
162
162
|
// then restores the view's size and what that session emulated. The page's own session emulated
|
|
@@ -170,41 +170,33 @@ const camera = (
|
|
|
170
170
|
viewport: Viewport,
|
|
171
171
|
capture: Capture.Controller,
|
|
172
172
|
) => {
|
|
173
|
-
const { playwright,
|
|
173
|
+
const { playwright, native, within } = page;
|
|
174
174
|
const { send } = page.protocol;
|
|
175
|
-
const actionMillis = Duration.toMillis(settings.actionTimeout);
|
|
176
175
|
// Device pixels per CSS pixel, as the page's layout metrics last gave it. A picture taken in one
|
|
177
176
|
// call is checked by its size, so a page whose ratio changes is measured again.
|
|
178
177
|
let ratio = 1;
|
|
179
|
-
const alone = Semaphore.makeUnsafe(1).withPermits(1);
|
|
180
178
|
let screenHeld = false;
|
|
181
179
|
|
|
182
180
|
// The copy has the screen alone: the view keeps its own size, and the device its pixel ratio.
|
|
183
|
-
const holdScreen = (operation: string)
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
).pipe(alone),
|
|
200
|
-
),
|
|
201
|
-
Effect.andThen(
|
|
202
|
-
Effect.sync(() => {
|
|
203
|
-
screenHeld = true;
|
|
204
|
-
}),
|
|
205
|
-
),
|
|
206
|
-
),
|
|
181
|
+
const holdScreen = Effect.fnUntraced(function* (operation: string) {
|
|
182
|
+
if (screenHeld) return;
|
|
183
|
+
|
|
184
|
+
const { width, height } = yield* bridge
|
|
185
|
+
.evaluate(operation, scriptCall("screenSize"))
|
|
186
|
+
.pipe(Effect.flatMap(decodeWith(operation, ScreenSize)));
|
|
187
|
+
|
|
188
|
+
yield* native(operation, () =>
|
|
189
|
+
send("Emulation.setDeviceMetricsOverride", {
|
|
190
|
+
width: 0,
|
|
191
|
+
height: 0,
|
|
192
|
+
deviceScaleFactor: 0,
|
|
193
|
+
mobile: false,
|
|
194
|
+
screenWidth: width,
|
|
195
|
+
screenHeight: height,
|
|
196
|
+
}),
|
|
207
197
|
);
|
|
198
|
+
screenHeld = true;
|
|
199
|
+
});
|
|
208
200
|
|
|
209
201
|
const decoded = (operation: string, data: Uint8Array, format: Format) => {
|
|
210
202
|
const size = format === "png" ? pngSize(data) : jpegSize(data);
|
|
@@ -217,41 +209,36 @@ const camera = (
|
|
|
217
209
|
: Effect.succeed(new Image({ data, mediaType: `image/${format}`, ...size }));
|
|
218
210
|
};
|
|
219
211
|
|
|
212
|
+
const take = (operation: string, format: Format, run: () => Promise<Uint8Array>) =>
|
|
213
|
+
native(operation, run).pipe(
|
|
214
|
+
untilPainted,
|
|
215
|
+
Effect.flatMap((data) => decoded(operation, data, format)),
|
|
216
|
+
);
|
|
217
|
+
|
|
220
218
|
const shot = (
|
|
221
219
|
operation: string,
|
|
222
220
|
format: Format,
|
|
223
221
|
quality: number,
|
|
224
222
|
clip?: Capture.Size & { readonly x: number; readonly y: number; readonly scale: number },
|
|
225
223
|
) =>
|
|
226
|
-
|
|
224
|
+
take(operation, format, () =>
|
|
227
225
|
send("Page.captureScreenshot", {
|
|
228
226
|
format,
|
|
229
227
|
...(format === "jpeg" ? { quality } : {}),
|
|
230
228
|
...(clip === undefined ? {} : { clip }),
|
|
231
|
-
}),
|
|
232
|
-
).pipe(
|
|
233
|
-
alone,
|
|
234
|
-
untilPainted,
|
|
235
|
-
Effect.flatMap(({ data }) => decoded(operation, Buffer.from(data, "base64"), format)),
|
|
229
|
+
}).then(({ data }) => Buffer.from(data, "base64")),
|
|
236
230
|
);
|
|
237
231
|
|
|
238
|
-
// Playwright's
|
|
232
|
+
// Playwright's promise owns native restoration; the outer Effect alone bounds callers.
|
|
239
233
|
const emulatedShot = (operation: string, format: Format, quality: number, crop?: Region) =>
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
...(crop === undefined ? {} : { clip: crop }),
|
|
249
|
-
}),
|
|
250
|
-
actionMillis,
|
|
251
|
-
).pipe(
|
|
252
|
-
alone,
|
|
253
|
-
untilPainted,
|
|
254
|
-
Effect.flatMap((data) => decoded(operation, data, format)),
|
|
234
|
+
take(operation, format, () =>
|
|
235
|
+
playwright.screenshot({
|
|
236
|
+
type: format,
|
|
237
|
+
...(format === "jpeg" ? { quality } : {}),
|
|
238
|
+
scale: "css",
|
|
239
|
+
timeout: 0,
|
|
240
|
+
...(crop === undefined ? {} : { clip: crop }),
|
|
241
|
+
}),
|
|
255
242
|
);
|
|
256
243
|
|
|
257
244
|
return (operation: string, quality: number, crop?: Region, format: Format = "jpeg") =>
|
|
@@ -269,17 +256,12 @@ const camera = (
|
|
|
269
256
|
if (emulated !== null) {
|
|
270
257
|
if (whole !== undefined) ratio = whole.width / emulated.width;
|
|
271
258
|
|
|
272
|
-
return yield*
|
|
259
|
+
return yield* emulatedShot(operation, format, quality, crop);
|
|
273
260
|
}
|
|
274
261
|
|
|
275
|
-
const [metrics] = yield*
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
Effect.flatMap(decodeWith(operation, LayoutMetrics)),
|
|
279
|
-
),
|
|
280
|
-
crop === undefined ? Effect.void : holdScreen(operation),
|
|
281
|
-
],
|
|
282
|
-
{ concurrency: 2 },
|
|
262
|
+
const [metrics] = yield* native(operation, () => send("Page.getLayoutMetrics")).pipe(
|
|
263
|
+
Effect.flatMap(decodeWith(operation, LayoutMetrics)),
|
|
264
|
+
Effect.zip(crop === undefined ? Effect.void : holdScreen(operation), { concurrent: true }),
|
|
283
265
|
);
|
|
284
266
|
|
|
285
267
|
const measured = metrics.contentSize.width / metrics.cssContentSize.width;
|
|
@@ -297,19 +279,14 @@ const camera = (
|
|
|
297
279
|
|
|
298
280
|
yield* holdScreen(operation);
|
|
299
281
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
scale: scale / ratio,
|
|
309
|
-
}),
|
|
310
|
-
crop !== undefined,
|
|
311
|
-
);
|
|
312
|
-
}).pipe(within(operation));
|
|
282
|
+
return yield* shot(operation, format, quality, {
|
|
283
|
+
x: pageX + rect.x,
|
|
284
|
+
y: pageY + rect.y,
|
|
285
|
+
width: Math.floor(rect.width / scale + 1e-3),
|
|
286
|
+
height: Math.floor(rect.height / scale + 1e-3),
|
|
287
|
+
scale: scale / ratio,
|
|
288
|
+
});
|
|
289
|
+
}).pipe(capture.excluding, within(operation));
|
|
313
290
|
};
|
|
314
291
|
|
|
315
292
|
// A duration in milliseconds, or NaN for an input that is no duration.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/** Actual native replies outlive callers; bounded transactions retain them without holding teardown. */
|
|
2
|
+
import { Cause, Clock, Duration, Effect, Exit, Fiber } from "effect";
|
|
3
|
+
|
|
4
|
+
import type { BrowserError } from "../../BrowserError.ts";
|
|
5
|
+
import * as Replies from "../input/replies.ts";
|
|
6
|
+
|
|
7
|
+
const deadline = Duration.seconds(2);
|
|
8
|
+
|
|
9
|
+
type Operation = "screencast start" | "screencast stop" | "picture restoration";
|
|
10
|
+
|
|
11
|
+
interface Options<G> {
|
|
12
|
+
readonly clock: Clock.Clock;
|
|
13
|
+
readonly error: (cause: unknown) => BrowserError;
|
|
14
|
+
readonly closed: () => boolean;
|
|
15
|
+
readonly current: () => G;
|
|
16
|
+
readonly pause: (current: G) => Effect.Effect<void, BrowserError>;
|
|
17
|
+
readonly resume: (current: G) => Effect.Effect<void, BrowserError>;
|
|
18
|
+
readonly fail: (current: G, error: BrowserError) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const make = <G>(options: Options<G>) => {
|
|
22
|
+
const replies = Replies.make();
|
|
23
|
+
const pending = new Map<Operation, Promise<void>>();
|
|
24
|
+
|
|
25
|
+
const late = (kind: Operation) => options.error(new Error(`${kind} exceeded its deadline`));
|
|
26
|
+
|
|
27
|
+
const track = (
|
|
28
|
+
operation: Operation,
|
|
29
|
+
actual: Promise<unknown>,
|
|
30
|
+
failed: (cause: unknown) => void,
|
|
31
|
+
) => {
|
|
32
|
+
const reply = actual.then(() => undefined, failed);
|
|
33
|
+
|
|
34
|
+
pending.set(operation, reply);
|
|
35
|
+
|
|
36
|
+
return reply.finally(() => {
|
|
37
|
+
if (pending.get(operation) === reply) pending.delete(operation);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const wait = (operation?: Operation) =>
|
|
42
|
+
(operation === undefined
|
|
43
|
+
? replies.idle.pipe(Effect.andThen(Effect.promise(() => Promise.all(pending.values()))))
|
|
44
|
+
: Effect.promise(() => pending.get(operation) ?? Promise.resolve())
|
|
45
|
+
).pipe(
|
|
46
|
+
Effect.asVoid,
|
|
47
|
+
Effect.interruptible,
|
|
48
|
+
Effect.timeoutOrElse({
|
|
49
|
+
duration: deadline,
|
|
50
|
+
orElse: () =>
|
|
51
|
+
Effect.fail(late(operation ?? pending.keys().next().value ?? "picture restoration")),
|
|
52
|
+
}),
|
|
53
|
+
Effect.provideService(Clock.Clock, options.clock),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const excluding = <A, E, R>(picture: Effect.Effect<A, E, R>) =>
|
|
57
|
+
Effect.uninterruptibleMask((restore) =>
|
|
58
|
+
Effect.gen(function* () {
|
|
59
|
+
yield* restore(wait());
|
|
60
|
+
if (options.closed()) return yield* options.error(new Error("Target page has been closed"));
|
|
61
|
+
const current = options.current();
|
|
62
|
+
const run = yield* replies.begin;
|
|
63
|
+
|
|
64
|
+
const result = yield* restore(
|
|
65
|
+
options
|
|
66
|
+
.pause(current)
|
|
67
|
+
.pipe(Effect.andThen(picture), Effect.provideService(Replies.Current, run)),
|
|
68
|
+
).pipe(Effect.exit);
|
|
69
|
+
|
|
70
|
+
// Called after the Effect exits: the owner cannot become idle between its commands.
|
|
71
|
+
const cleaned = yield* wait().pipe(
|
|
72
|
+
Effect.andThen(options.resume(current)),
|
|
73
|
+
Effect.timeoutOrElse({
|
|
74
|
+
duration: deadline,
|
|
75
|
+
orElse: () => Effect.fail(late("picture restoration")),
|
|
76
|
+
}),
|
|
77
|
+
Effect.provideService(Clock.Clock, options.clock),
|
|
78
|
+
Effect.exit,
|
|
79
|
+
// A joined child has fresh interruption state. Parent cancellation cannot skip cleanup.
|
|
80
|
+
Effect.forkChild,
|
|
81
|
+
Effect.flatMap(Fiber.join),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (Exit.isFailure(cleaned))
|
|
85
|
+
options.fail(current, options.error(Cause.squash(cleaned.cause)));
|
|
86
|
+
if (Exit.isFailure(result)) return yield* Effect.failCause(result.cause);
|
|
87
|
+
if (Exit.isFailure(cleaned)) return yield* Effect.failCause(cleaned.cause);
|
|
88
|
+
|
|
89
|
+
return result.value;
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return { excluding, idle: wait(), wait, track };
|
|
94
|
+
};
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* stillness starts that record itself and ignores capture silence. Each new document starts a
|
|
14
14
|
* new observation, while retries of destroyed script contexts share the caller's deadline.
|
|
15
15
|
*/
|
|
16
|
-
import { Duration, Effect, Schedule, Stream } from "effect";
|
|
16
|
+
import { Duration, Effect, Option, Schedule, Stream } from "effect";
|
|
17
17
|
|
|
18
18
|
import { Timeout } from "../../BrowserError.ts";
|
|
19
19
|
import type { ReadyOptions } from "../../Page.ts";
|
|
@@ -59,8 +59,14 @@ export const make =
|
|
|
59
59
|
let stirred = running ? page.now() : Number.POSITIVE_INFINITY;
|
|
60
60
|
|
|
61
61
|
// How long the screen has been still: since a frame, or an unanswered acknowledgement.
|
|
62
|
-
const look = Effect.
|
|
63
|
-
|
|
62
|
+
const look = Effect.gen(function* () {
|
|
63
|
+
const stats = yield* capture.stats();
|
|
64
|
+
|
|
65
|
+
if (
|
|
66
|
+
!Option.exists(yield* capture.latest, capture.current) ||
|
|
67
|
+
stats.received !== received ||
|
|
68
|
+
stats.ackBacklog > 0
|
|
69
|
+
) {
|
|
64
70
|
received = stats.received;
|
|
65
71
|
stirred = page.now();
|
|
66
72
|
}
|
|
@@ -34,9 +34,10 @@ export class Draining extends Schema.TaggedClass<Draining>()("Draining", {
|
|
|
34
34
|
revokeAt: Schema.Finite,
|
|
35
35
|
}) {}
|
|
36
36
|
|
|
37
|
-
/** Lost
|
|
37
|
+
/** Lost through disconnection or a consumer's declaration that it is unusable. */
|
|
38
38
|
export class Lost extends Schema.TaggedClass<Lost>()("Lost", {
|
|
39
|
-
cause: DisconnectCause,
|
|
39
|
+
cause: Schema.Union([DisconnectCause, Schema.Literal("declared")]),
|
|
40
|
+
detail: Schema.optional(Schema.String),
|
|
40
41
|
}) {}
|
|
41
42
|
|
|
42
43
|
/**
|
|
@@ -101,10 +102,15 @@ export type State<A, H = unknown> = (
|
|
|
101
102
|
readonly serving: Held<A, H> | undefined;
|
|
102
103
|
}
|
|
103
104
|
| { readonly _tag: "Retired" }
|
|
104
|
-
) & {
|
|
105
|
+
) & {
|
|
106
|
+
readonly draining: ReadonlyMap<number, Drain<A, H>>;
|
|
107
|
+
/** Retain the first unconfirmed end, otherwise the latest settled end, without its resources. */
|
|
108
|
+
readonly released?: Released | undefined;
|
|
109
|
+
};
|
|
105
110
|
|
|
106
111
|
export type Input<A, H = unknown> =
|
|
107
112
|
| { readonly _tag: "Opened"; readonly live: Live<A> }
|
|
113
|
+
| { readonly _tag: "AttemptReleased"; readonly released: Released }
|
|
108
114
|
| {
|
|
109
115
|
readonly _tag: "Failed";
|
|
110
116
|
readonly number: number;
|
|
@@ -112,7 +118,12 @@ export type Input<A, H = unknown> =
|
|
|
112
118
|
readonly cause: unknown;
|
|
113
119
|
}
|
|
114
120
|
| { readonly _tag: "Abandoned"; readonly number: number }
|
|
115
|
-
| {
|
|
121
|
+
| {
|
|
122
|
+
readonly _tag: "Lost";
|
|
123
|
+
readonly number: number;
|
|
124
|
+
readonly cause: Lost["cause"];
|
|
125
|
+
readonly detail?: string | undefined;
|
|
126
|
+
}
|
|
116
127
|
| { readonly _tag: "Rotate"; readonly due?: number | undefined }
|
|
117
128
|
| { readonly _tag: "Retire" }
|
|
118
129
|
| { readonly _tag: "Keep" }
|
|
@@ -130,7 +141,7 @@ export type Input<A, H = unknown> =
|
|
|
130
141
|
};
|
|
131
142
|
|
|
132
143
|
export type Command<A> =
|
|
133
|
-
| { readonly _tag: "Open"; readonly number: number
|
|
144
|
+
| { readonly _tag: "Open"; readonly number: number }
|
|
134
145
|
| { readonly _tag: "Watch"; readonly live: Live<A> }
|
|
135
146
|
/** Signal ending and arrange revocation. Repeated only when loss/retirement accelerates it. */
|
|
136
147
|
| { readonly _tag: "Drain"; readonly live: Live<A>; readonly ending: Draining }
|
|
@@ -149,7 +160,7 @@ export interface Step<A, H = unknown> {
|
|
|
149
160
|
export const start = <A, H = unknown>(): Step<A, H> => ({
|
|
150
161
|
state: { _tag: "Opening", number: 1, serving: undefined, draining: new Map() },
|
|
151
162
|
events: [[1, new Opening()]],
|
|
152
|
-
commands: [{ _tag: "Open", number: 1
|
|
163
|
+
commands: [{ _tag: "Open", number: 1 }],
|
|
153
164
|
});
|
|
154
165
|
|
|
155
166
|
const servingOf = <A, H>(state: State<A, H>) =>
|
|
@@ -260,10 +271,6 @@ const next = <A, H>(change: Change<A, H>, number: number, reopen: boolean) => {
|
|
|
260
271
|
const { exclusive } = change;
|
|
261
272
|
const current = servingOf(change.state);
|
|
262
273
|
|
|
263
|
-
const after = exclusive
|
|
264
|
-
? (current?.number ?? change.state.draining.keys().next().value)
|
|
265
|
-
: undefined;
|
|
266
|
-
|
|
267
274
|
if (current !== undefined && (reopen || exclusive))
|
|
268
275
|
end(change, current, reopen ? "lost" : "rotated");
|
|
269
276
|
change.state = {
|
|
@@ -271,9 +278,10 @@ const next = <A, H>(change: Change<A, H>, number: number, reopen: boolean) => {
|
|
|
271
278
|
number,
|
|
272
279
|
serving: reopen || exclusive ? undefined : current,
|
|
273
280
|
draining: change.state.draining,
|
|
281
|
+
released: change.state.released,
|
|
274
282
|
};
|
|
275
283
|
change.events.push([number, reopen ? new Reopening() : new Opening()]);
|
|
276
|
-
change.commands.push({ _tag: "Open", number
|
|
284
|
+
change.commands.push({ _tag: "Open", number });
|
|
277
285
|
};
|
|
278
286
|
|
|
279
287
|
const lost = <A, H>(
|
|
@@ -284,11 +292,12 @@ const lost = <A, H>(
|
|
|
284
292
|
const drain = state.draining.get(input.number);
|
|
285
293
|
const current = servingOf(state);
|
|
286
294
|
|
|
295
|
+
if (input.cause === "declared" && current?.number !== input.number) return;
|
|
287
296
|
if (drain?._tag === "Draining") {
|
|
288
297
|
change.events.push([input.number, new Lost({ cause: input.cause })]);
|
|
289
298
|
revoke(change, input.number, "lost");
|
|
290
299
|
} else if (state._tag !== "Retired" && current?.number === input.number) {
|
|
291
|
-
change.events.push([input.number, new Lost({ cause: input.cause })]);
|
|
300
|
+
change.events.push([input.number, new Lost({ cause: input.cause, detail: input.detail })]);
|
|
292
301
|
if (state._tag !== "Opening")
|
|
293
302
|
next(change, (state._tag === "Open" ? current.number : state.number) + 1, true);
|
|
294
303
|
else {
|
|
@@ -332,7 +341,12 @@ export const transition = <A, H = unknown>(
|
|
|
332
341
|
change.events.push([live.number, new Open()]);
|
|
333
342
|
change.commands.push({ _tag: "Watch", live });
|
|
334
343
|
if (state.serving !== undefined) end(change, state.serving, "rotated");
|
|
335
|
-
change.state = {
|
|
344
|
+
change.state = {
|
|
345
|
+
_tag: "Open",
|
|
346
|
+
serving: live,
|
|
347
|
+
draining: change.state.draining,
|
|
348
|
+
released: change.state.released,
|
|
349
|
+
};
|
|
336
350
|
}
|
|
337
351
|
break;
|
|
338
352
|
}
|
|
@@ -347,6 +361,9 @@ export const transition = <A, H = unknown>(
|
|
|
347
361
|
case "Abandoned":
|
|
348
362
|
change.events.push([input.number, new Closed({})]);
|
|
349
363
|
break;
|
|
364
|
+
case "AttemptReleased":
|
|
365
|
+
change.state = { ...state, released: combine(state.released, input.released) };
|
|
366
|
+
break;
|
|
350
367
|
case "Released": {
|
|
351
368
|
const drain = state.draining.get(input.number);
|
|
352
369
|
|
|
@@ -354,7 +371,7 @@ export const transition = <A, H = unknown>(
|
|
|
354
371
|
const draining = new Map(state.draining);
|
|
355
372
|
|
|
356
373
|
draining.delete(input.number);
|
|
357
|
-
change.state = { ...state, draining };
|
|
374
|
+
change.state = { ...state, draining, released: combine(state.released, input.released) };
|
|
358
375
|
change.events.push([
|
|
359
376
|
input.number,
|
|
360
377
|
input.released === undefined ? new Kept() : new Closed({ released: input.released }),
|
|
@@ -382,12 +399,20 @@ export const transition = <A, H = unknown>(
|
|
|
382
399
|
if (state._tag === "Retired") break;
|
|
383
400
|
for (const number of state.draining.keys()) revoke(change, number, "retired");
|
|
384
401
|
if (state.serving !== undefined) end(change, state.serving, "retired", input._tag === "Keep");
|
|
385
|
-
change.state = {
|
|
402
|
+
change.state = {
|
|
403
|
+
_tag: "Retired",
|
|
404
|
+
draining: change.state.draining,
|
|
405
|
+
released: change.state.released,
|
|
406
|
+
};
|
|
386
407
|
}
|
|
387
408
|
|
|
388
409
|
return change;
|
|
389
410
|
};
|
|
390
411
|
|
|
412
|
+
/** Later confirmations cannot establish that an earlier unconfirmed session ended. */
|
|
413
|
+
export const combine = (before: Released | undefined, next: Released | undefined) =>
|
|
414
|
+
before?._tag === "Unconfirmed" ? before : (next ?? before);
|
|
415
|
+
|
|
391
416
|
export type Resolution<A> =
|
|
392
417
|
| { readonly _tag: "Serve"; readonly live: Live<A> }
|
|
393
418
|
| {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Plan-Bl2NM1D5.mjs","names":[],"sources":["../src/internal/reading/choose.ts","../src/Plan.ts"],"sourcesContent":["/**\n * Choosing the one element a recorded subject names, among those `find` gives for its role and\n * name. Context tells them apart, and an element that does not repeat every part of the recorded\n * context is another subject, so a sole element left once its own has gone, such as Alice's\n * \"Remove\" after Bob has left, drifts rather than stands in:\n *\n * - a row is read whole: a row named \"Wrapped BTC\" is not the row \"BTC\". Laid out again without\n * rows, as cards, one of the element's fields must start with the row's words;\n * - a column counts where the element is under one;\n * - a label or heading must read the same, or its words appear, whole and in order, in one of the\n * element's fields, as `near` reads them.\n *\n * The rest are ranked by how much of the recorded context they read the same. There is no\n * ordinal, so a tie stays a tie.\n */\nimport { Effect, Schema } from \"effect\";\n\nimport type { Subject, SubjectContext } from \"../../BrowserEvent.ts\";\nimport type { Found } from \"../../Page.ts\";\nimport { match } from \"./match.inpage.ts\";\n\n/** Nothing on the page has the step's role and name. */\nexport class Missing extends Schema.TaggedError<Missing>()(\"Missing\", {}) {\n override get message() {\n return \"nothing on the page has the recorded role and name\";\n }\n}\n\n/** Several elements match the step's subject equally well, and nothing tells them apart. */\nexport class Ambiguous extends Schema.TaggedError<Ambiguous>()(\"Ambiguous\", {\n count: Schema.Int,\n}) {\n override get message() {\n return `${this.count} elements match the recorded subject equally well`;\n }\n}\n\n/** The page is not where the recording was: another site, or no element with its context. */\nexport class Drifted extends Schema.TaggedError<Drifted>()(\"Drifted\", {\n detail: Schema.String,\n}) {\n override get message() {\n return this.detail;\n }\n}\n\nconst { holds, normalize } = match();\nconst fields = [\"row\", \"column\", \"label\", \"heading\"] as const;\n\nconst said = (context: SubjectContext) =>\n Object.values(context).filter((value) => typeof value === \"string\");\n\n/** How an element repeats one recorded field: 2 read the same, 1 found as words, 0 not at all. */\nconst repeats = (field: (typeof fields)[number], value: string, context: SubjectContext) => {\n const own = context[field];\n\n if (own !== undefined && normalize(own) === normalize(value)) return 2;\n if (field === \"column\") return own === undefined ? 1 : 0;\n if (field === \"row\")\n return own === undefined &&\n said(context).some((other) => `${normalize(other)} `.startsWith(`${normalize(value)} `))\n ? 1\n : 0;\n\n return said(context).some((other) => holds(other, value)) ? 1 : 0;\n};\n\nexport const choose = (\n subject: Subject,\n found: ReadonlyArray<Found>,\n): Effect.Effect<Found, Missing | Ambiguous | Drifted> => {\n // `find` matched the role; a subject without one only matches elements without one.\n const named = found.filter((one) => subject.role !== null || one.subject.role === null);\n\n const kept = named.flatMap((one) => {\n let score = 0;\n\n for (const field of fields) {\n const value = subject.context[field];\n const repeated = value === undefined ? 0 : repeats(field, value, one.subject.context);\n\n if (value !== undefined && repeated === 0) return [];\n score += repeated;\n }\n\n return [{ one, score }];\n });\n\n const best = Math.max(...kept.map(({ score }) => score));\n const top = kept.filter(({ score }) => score === best);\n const [only] = top;\n\n if (named.length === 0) return Effect.fail(new Missing());\n if (kept.length === 0)\n return Effect.fail(new Drifted({ detail: \"no element named so repeats the recorded context\" }));\n\n return top.length === 1 && only !== undefined\n ? Effect.succeed(only.one)\n : Effect.fail(new Ambiguous({ count: top.length }));\n};\n","/**\n * A walk recorded once from a page's events and replayed later, on a fresh page, with no model\n * call.\n *\n * `fromEvents` keeps one page's completed actions with their subjects and the options they were\n * given, its navigations with both the address asked for and the one reached, and what was typed\n * as a named input slot, never the text itself. A navigation to an address whose credentials the\n * events withheld is an input slot too, so replay goes where the caller says, or nowhere, and\n * never to the address without them. `replay` takes the steps in turn. Before a step\n * that acts on the page, it waits for `Page.ready`; then it finds the one element the step's\n * subject names, by role and name among those that repeat all its recorded context, and acts on\n * it. Text typed into focus was typed into the focused field, which replay finds the same way, and\n * text typed into a secret field goes into nothing else. An element step never falls back to\n * coordinates, and a step recorded at a point acts there only while the element found for it still\n * covers that point. `take` and `replay` return receipts; failure preserves a stopping point and\n * earlier receipts. Unknown consequential input is never resent. Only a positive durable read-back\n * can reconcile it; restoration follows the same rule. The consumer journals begun steps before\n * calling, treating interruption or a missing receipt as unknown. Plain recordings use version 1;\n * authored expected effects use version 2. Old 0.2 plans and unknown versions do not decode.\n *\n * @since 0.3.0\n */\nimport { Duration, Effect, Exit, Option, Schedule, Schema } from \"effect\";\n\nimport { BrowserError, InvalidRequest } from \"./BrowserError.ts\";\nimport {\n type Action,\n ActionOptions,\n Box,\n type BrowserEvent,\n type Navigated,\n Subject,\n} from \"./BrowserEvent.ts\";\nimport { undispatched } from \"./internal/page/context.ts\";\nimport { Ambiguous, choose, Drifted, Missing } from \"./internal/reading/choose.ts\";\nimport {\n type Found,\n type Page,\n type Point,\n type ReadyOptions,\n redacted,\n type Target,\n} from \"./Page.ts\";\n\nexport { Ambiguous, Drifted, Missing } from \"./internal/reading/choose.ts\";\n\nconst ViewportPoint = Schema.Struct({ x: Schema.Finite, y: Schema.Finite });\n\nexport const StepAction = Schema.Literals([\n \"navigate\",\n \"back\",\n \"reload\",\n \"click\",\n \"hover\",\n \"drag\",\n \"type\",\n \"press\",\n \"scroll\",\n \"select\",\n]);\n\nexport type StepAction = typeof StepAction.Type;\n\nconst Query = Schema.Struct({\n role: Schema.optional(Schema.String),\n name: Schema.optional(Schema.String),\n text: Schema.optional(Schema.String),\n});\n\n/**\n * What a step leaves. `durable` asserts an author-chosen, lasting read-back of this operation,\n * such as its uniquely named saved receipt or exact operation URL. Only Appeared and an exact\n * Navigated URL allow it; a toast, absence or relative navigation cannot establish recovery.\n * Relative navigation measures observed change from dispatch, without asserting causality.\n */\nexport const Expected = Schema.Union([\n Schema.TaggedStruct(\"Checked\", { checked: Schema.Boolean }),\n Schema.TaggedStruct(\"Appeared\", {\n query: Query,\n durable: Schema.optional(Schema.Literal(true)),\n }),\n Schema.TaggedStruct(\"Gone\", {\n query: Query,\n durable: Schema.optional(Schema.Never),\n }),\n Schema.TaggedStruct(\"Navigated\", {\n url: Schema.String,\n durable: Schema.optional(Schema.Literal(true)),\n }),\n Schema.TaggedStruct(\"Navigated\", {\n url: Schema.optional(Schema.Never),\n durable: Schema.optional(Schema.Never),\n }),\n]);\n\nexport type Expected = typeof Expected.Type;\n\n/** One recorded step: the action, what it acted on, and what else it was asked. */\nexport class Step extends Schema.Class<Step>(\"effect-browser/Plan/Step\")({\n action: StepAction,\n /**\n * The ending address, or a later recorded navigation before the next action began. Empty when\n * unknown; a delayed navigation can be stronger arrival evidence than the action's ending URL.\n */\n url: Schema.String,\n /** A navigation's requested address, or the keys a press pressed. */\n target: Schema.optional(Schema.String),\n subject: Schema.optional(Subject),\n /** Where a drag ended. */\n to: Schema.optional(Subject),\n /** The viewport point a step aimed at, when it aimed at a point, and a drag's end point. */\n point: Schema.optional(ViewportPoint),\n toPoint: Schema.optional(ViewportPoint),\n /** The box of what a step aimed at by point found there, so replay aims at the same place in it. */\n box: Schema.optional(Box),\n /**\n * The input slot whose text a `type` step types, or whose address a `navigate` step goes to, as\n * its recorded address had a credential withheld.\n */\n input: Schema.optional(Schema.String),\n /** The slot's text went into a secret field, so replay types it into nothing else. */\n secret: Schema.optional(Schema.Literal(true)),\n options: Schema.optional(ActionOptions),\n expect: Schema.optional(Expected),\n}) {}\n\nconst PlanData = Schema.Struct({\n version: Schema.Literals([1, 2]),\n steps: Schema.Array(Step),\n}).check(\n Schema.makeFilter((plan) =>\n plan.version === (plan.steps.some((step) => step.expect !== undefined) ? 2 : 1)\n ? undefined\n : \"only plans with expected effects use version 2\",\n ),\n);\n\nexport class Plan extends Schema.Class<Plan>(\"effect-browser/Plan\")(PlanData) {\n /** Choose the encoding version from the steps; simple recordings remain version 1. */\n static new(steps: ReadonlyArray<Step>): Plan {\n return new Plan({ version: steps.some((step) => step.expect !== undefined) ? 2 : 1, steps });\n }\n\n /** The input slots its steps type, in order; replay needs text for each. */\n get inputs(): ReadonlyArray<string> {\n return this.steps.flatMap((step) => (step.input === undefined ? [] : [step.input]));\n }\n}\n\n/** One completed step, on the page's host clock. `verified` means its expected effect was seen. */\nexport class Receipt extends Schema.Class<Receipt>(\"effect-browser/Plan/Receipt\")({\n step: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n outcome: Schema.Literals([\"taken\", \"verified\", \"skipped\"]),\n startedAt: Schema.Finite,\n at: Schema.Finite,\n}) {}\n\n/** Durable stopping data. A begun step without a receipt must be restored as `unknown`. */\nexport class Stopped extends Schema.Class<Stopped>(\"effect-browser/Plan/Stopped\")({\n step: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n input: Schema.Literals([\"unsent\", \"unknown\"]),\n}) {}\n\n/** Repeating this step could repeat an unresolved effect; the consumer must reconcile it. */\nexport class Uncertain extends Schema.TaggedError<Uncertain>()(\"Uncertain\", {\n detail: Schema.String,\n}) {\n override get message() {\n return this.detail;\n }\n}\n\n/** Where replay stopped, counting steps from 0, why, and the steps that completed before it. */\nexport class ReplayError extends Schema.TaggedError<ReplayError>()(\"ReplayError\", {\n step: Schema.Int,\n reason: Schema.Union([Missing, Ambiguous, Drifted, BrowserError, Uncertain]),\n input: Schema.Literals([\"unsent\", \"unknown\"]),\n receipts: Schema.Array(Receipt),\n}) {\n get stopped(): Stopped {\n return new Stopped({ step: this.step, input: this.input });\n }\n\n override get message() {\n return `step ${this.step} failed: ${this.reason.message}`;\n }\n}\n\nconst isStep = (event: BrowserEvent): event is Action & { readonly name: StepAction } =>\n event._tag === \"Action\" &&\n event.ok &&\n (StepAction.literals as ReadonlyArray<string>).includes(event.name);\n\n// A point target reads `x,y`, as `{\"x\":…,\"y\":…}` inside a drag's; a ref reads like e12.\nconst pointIn = (target: string | undefined): Point | undefined => {\n const parsed = /^\\{?(?:\"x\":)?(-?[\\d.]+),(?:\"y\":)?(-?[\\d.]+)\\}?$/.exec(target ?? \"\");\n\n return parsed === null ? undefined : { x: Number(parsed[1]), y: Number(parsed[2]) };\n};\n\n/** A slot named for the field it fills, such as `email`, unique within the plan. */\nconst slotFor = (taken: Set<string>, field: string | undefined) => {\n const base =\n field\n ?.toLowerCase()\n .match(/[\\p{L}\\p{N}]+/gu)\n ?.join(\"-\") ?? \"input\";\n\n let slot = base;\n\n for (let count = 2; taken.has(slot); count++) slot = `${base}-${count}`;\n taken.add(slot);\n\n return slot;\n};\n\n/**\n * The walk one page's events record: the completed actions of the page that acted first, in\n * order. `page.recentEvents` gives them, or `browser.events()` read until the walk ends.\n */\nexport const fromEvents = (events: Iterable<BrowserEvent>): Plan => {\n const all = Array.from(events);\n const page = all.find((event) => event._tag === \"Action\")?.page;\n const mine = all.filter((event) => \"page\" in event && event.page === page);\n const steps = mine.filter(isStep);\n const opened = mine.find((event) => event._tag === \"PageOpened\")?.url ?? \"\";\n const moves = mine.filter((event): event is Navigated => event._tag === \"Navigated\");\n const taken = new Set<string>();\n\n // Where the page was just before a time: the last address it reached by then.\n const before = (time: number) => moves.findLast((move) => move.at <= time)?.url ?? opened;\n\n return new Plan({\n version: 1,\n steps: steps.map((action, index) => {\n const drag = action.name === \"drag\" ? (action.target ?? \"\").split(\" -> \") : undefined;\n const point = pointIn(drag === undefined ? action.target : drag[0]);\n const until = steps[index + 1]?.startedAt ?? Number.POSITIVE_INFINITY;\n const arrival = moves.findLast((move) => move.at > action.at && move.at <= until);\n\n // Only a navigation and a press keep their target: an address, or keys.\n return new Step({\n action: action.name,\n url: arrival?.url ?? action.url ?? before(until),\n target: action.name === \"navigate\" || action.name === \"press\" ? action.target : undefined,\n subject: action.subject,\n to: action.to,\n point,\n toPoint: pointIn(drag?.[1]),\n box: point === undefined ? undefined : action.box,\n input:\n action.name === \"type\"\n ? slotFor(taken, action.subject?.name)\n : action.name === \"navigate\" && action.target?.includes(redacted) === true\n ? slotFor(taken, \"address\")\n : undefined,\n secret: action.name === \"type\" && action.text === redacted ? true : undefined,\n options: action.options,\n });\n }),\n });\n};\n\n/**\n * The one element on the page that a subject names, by role, name and context (see `Plan`),\n * looking again for two seconds while the page may still be drawing it.\n */\nexport const locate = (page: Page, subject: Subject) =>\n page\n .find({\n name: subject.name,\n scope: \"document\",\n ...(subject.role === null ? {} : { role: subject.role }),\n })\n .pipe(\n Effect.flatMap((found) => choose(subject, found)),\n Effect.retry({\n schedule: Schedule.spaced(Duration.millis(250)),\n times: 8,\n while: (error) => error._tag !== \"BrowserError\",\n }),\n Effect.withSpan(\"Plan.locate\", { attributes: { role: subject.role ?? \"\" } }),\n );\n\nconst invalid = (detail: string) => undispatched(\"replay\", new InvalidRequest({ detail }));\n\n/**\n * Where the step acts: the element its subject names, or, for a step recorded at a point, the same\n * place within that element, as long as a press there reaches that element and not one over it.\n * An element out of view is first brought into it, by hovering it, as a press by ref would be.\n */\nconst aim = (page: Page, subject: Subject | undefined, point?: Point, recorded?: Box) => {\n if (subject === undefined) return Effect.fail(invalid(\"the step names no element\"));\n if (point === undefined) return Effect.map(locate(page, subject), ({ ref }): Target => ref);\n\n const reach = ({ ref, box }: Found) => {\n const at =\n recorded === undefined || recorded.width <= 0 || recorded.height <= 0\n ? point\n : {\n x: box.x + ((point.x - recorded.x) / recorded.width) * box.width,\n y: box.y + ((point.y - recorded.y) / recorded.height) * box.height,\n };\n\n return Effect.map(page.find({ at }), ([reached]) => (reached?.ref === ref ? at : undefined));\n };\n\n const missed = new Drifted({ detail: \"a press at the subject's point reaches another element\" });\n\n return locate(page, subject).pipe(\n Effect.flatMap((found) =>\n Effect.flatMap(reach(found), (at) =>\n at !== undefined\n ? Effect.succeed<Target>(at)\n : page.hover(found.ref).pipe(\n Effect.andThen(locate(page, subject)),\n Effect.flatMap(reach),\n Effect.flatMap((again) =>\n again === undefined ? Effect.fail(missed) : Effect.succeed<Target>(again),\n ),\n ),\n ),\n ),\n );\n};\n\nconst dispatch = (\n page: Page,\n step: Step,\n text: string,\n): Effect.Effect<void, Missing | Ambiguous | Drifted | BrowserError> => {\n const options = step.options ?? {};\n\n switch (step.action) {\n case \"navigate\":\n return page.goto(step.input === undefined ? (step.target ?? step.url) : text);\n case \"back\":\n return page.back;\n case \"reload\":\n return page.reload;\n case \"press\":\n return step.subject === undefined\n ? page.press(step.target ?? \"\", options)\n : Effect.flatMap(locate(page, step.subject), ({ ref }) =>\n page.press(step.target ?? \"\", { ...options, on: ref }),\n );\n case \"click\":\n return aim(page, step.subject, step.point, step.box).pipe(\n Effect.flatMap((at) => page.click(at, options)),\n Effect.asVoid,\n );\n case \"hover\":\n return Effect.flatMap(aim(page, step.subject, step.point, step.box), page.hover);\n case \"drag\":\n return Effect.all([\n aim(page, step.subject, step.point),\n aim(page, step.to, step.toPoint),\n ]).pipe(Effect.flatMap(([from, to]) => page.drag(from, to)));\n case \"select\":\n return aim(page, step.subject).pipe(\n Effect.flatMap((at) => page.select(typeof at === \"string\" ? at : \"\", options.values ?? [])),\n Effect.asVoid,\n );\n // A scroll or a typing step may name no element: the page, or whatever has focus.\n case \"scroll\":\n return step.subject === undefined\n ? page.scroll(options)\n : Effect.flatMap(aim(page, step.subject, step.point, step.box), (at) =>\n page.scroll({ ...options, at }),\n );\n case \"type\":\n return step.subject === undefined\n ? page.type(text, { ...options, secret: step.secret })\n : Effect.flatMap(aim(page, step.subject), (into) =>\n page.type(text, {\n ...options,\n into: typeof into === \"string\" ? into : undefined,\n secret: step.secret,\n }),\n );\n }\n};\n\nexport interface TakeOptions {\n /** How each step waits for the page first, or false not to wait. */\n readonly settle?: ReadyOptions | false | undefined;\n readonly inputs?: Readonly<Record<string, string>> | undefined;\n /**\n * Bound for recorded arrival and expected effect, each. Defaults to 5 seconds. Zero makes one\n * read without polling; that read retains the page operation's timeout.\n */\n readonly arrival?: Duration.Input | undefined;\n}\n\nexport interface ReplayOptions extends TakeOptions {\n readonly from?: number | Stopped | undefined;\n}\n\n/**\n * Input that can be repeated without repeating a commitment. `take` also validates a Checked\n * target's boolean state before input. Back/reload can resubmit a form.\n */\nexport const repeatable = (step: Step): boolean =>\n [\"navigate\", \"hover\", \"scroll\", \"select\"].includes(step.action) ||\n (step.action === \"type\" &&\n step.subject !== undefined &&\n step.options?.replace !== false &&\n step.options?.submit !== true) ||\n (step.action === \"click\" && step.expect?._tag === \"Checked\");\n\ntype StepError = Missing | Ambiguous | Drifted | BrowserError | Uncertain;\n\n// Zero waits make one read; positive waits bound all reads and never repeat input.\nconst within = (check: Effect.Effect<boolean, StepError>, millis: number) =>\n millis === 0\n ? check\n : check.pipe(\n Effect.repeat({ until: (held) => held, schedule: Schedule.spaced(Duration.millis(25)) }),\n Effect.timeoutOrElse({\n duration: Duration.millis(millis),\n orElse: () => Effect.succeed(false),\n }),\n );\n\nconst sameSite = (url: string, recorded: string) => {\n const origin = URL.parse(recorded)?.origin;\n\n return (\n recorded === \"\" ||\n (origin === undefined || origin === \"null\"\n ? url === recorded\n : URL.parse(url)?.origin === origin)\n );\n};\n\nconst arrived = (page: Page, urls: ReadonlyArray<string>, millis: number) =>\n within(\n Effect.map(page.url, (url) => urls.some((recorded) => sameSite(url, recorded))),\n millis,\n ).pipe(\n Effect.filterOrFail(\n (held) => held,\n () =>\n new Drifted({ detail: \"the page did not reach the recorded site within the arrival wait\" }),\n ),\n Effect.asVoid,\n );\n\nconst checkEffect = (\n page: Page,\n step: Step,\n first?: { readonly url: string; readonly document: number },\n) => {\n const expected = step.expect;\n\n if (expected === undefined) return Effect.succeed(false);\n switch (expected._tag) {\n case \"Checked\":\n return step.subject === undefined\n ? Effect.fail(invalid(\"a checked effect needs a subject\"))\n : Effect.flatMap(locate(page, step.subject), (found) =>\n found.state.checked === undefined\n ? Effect.fail(invalid(\"a checked effect needs a checkable subject\"))\n : Effect.succeed(found.state.checked === expected.checked),\n );\n case \"Navigated\":\n if (expected.url === undefined && first === undefined) return Effect.succeed(false);\n\n return Effect.map(page.state, (now) =>\n expected.url === undefined\n ? now.url !== first?.url || now.document !== first?.document\n : now.url === expected.url,\n );\n case \"Appeared\":\n case \"Gone\":\n return Effect.map(page.find({ ...expected.query, scope: \"document\" }), (found) =>\n expected._tag === \"Appeared\" ? found.length > 0 : found.length === 0,\n );\n }\n};\n\n/**\n * Take one step. Unknown non-repeatable input is never resent: only positive durable read-back\n * can skip it. An interrupted call remains interrupted; persist begun-before-call in the consumer\n * and treat a missing receipt as Stopped{input: \"unknown\"}, including after process restart.\n */\nexport const take = Effect.fn(\"Plan.take\")(function* (\n page: Page,\n plan: Plan,\n at: number | Stopped,\n options: TakeOptions = {},\n): Effect.fn.Return<Receipt, ReplayError> {\n const index = typeof at === \"number\" ? at : at.step;\n let input: Stopped[\"input\"] = typeof at === \"number\" ? \"unsent\" : at.input;\n\n const work = Effect.gen(function* (): Effect.fn.Return<Receipt, StepError> {\n const step = plan.steps[index];\n\n if (!Number.isInteger(index) || index < 0 || step === undefined)\n return yield* invalid(\"the step index is outside the plan\");\n const duration = Duration.fromInput(options.arrival ?? Duration.seconds(5));\n\n if (\n Option.isNone(duration) ||\n Duration.isNegative(duration.value) ||\n !Duration.isFinite(duration.value)\n )\n return yield* invalid(\"arrival must be a finite nonnegative duration\");\n const millis = Duration.toMillis(duration.value);\n const first = yield* page.state;\n\n const uncertain = new Uncertain({\n detail: \"the step may have been sent; reconcile its durable effect before continuing\",\n });\n\n const unresolved = input === \"unknown\" && !repeatable(step);\n const expected = step.expect;\n\n const durable =\n expected !== undefined &&\n (expected._tag === \"Appeared\" ||\n (expected._tag === \"Navigated\" && typeof expected.url === \"string\")) &&\n expected.durable === true;\n\n if (\n !durable &&\n (unresolved || (expected !== undefined && \"durable\" in expected && expected.durable === true))\n )\n return yield* uncertain;\n const settle = options.settle === false ? Effect.void : page.ready(options.settle);\n\n if (![\"navigate\", \"back\", \"reload\"].includes(step.action)) yield* settle;\n const before = plan.steps[index - 1]?.url;\n\n if (before !== undefined)\n yield* arrived(page, unresolved ? [before, step.url] : [before], millis);\n const check = checkEffect(page, step);\n\n const read =\n millis === 0\n ? check\n : check.pipe(\n Effect.timeoutOrElse({\n duration: Duration.millis(millis),\n orElse: () =>\n Effect.fail(new Drifted({ detail: \"the expected-effect read timed out\" })),\n }),\n );\n\n const held = yield* read.pipe(Effect.mapError((error) => (unresolved ? uncertain : error)));\n\n const receipt = (outcome: Receipt[\"outcome\"]) =>\n Effect.gen(function* () {\n if (index === plan.steps.length - 1) yield* settle;\n yield* arrived(page, [step.url], millis);\n const now = yield* page.state;\n\n return new Receipt({ step: index, outcome, startedAt: first.at, at: now.at });\n });\n\n if (held) return yield* receipt(\"skipped\");\n if (unresolved) return yield* uncertain;\n const text = step.input === undefined ? \"\" : options.inputs?.[step.input];\n\n if (text === undefined) return yield* invalid(`no text for the input \"${step.input ?? \"\"}\"`);\n const verify = checkEffect(page, step, yield* page.state);\n const acted = yield* Effect.exit(dispatch(page, step, text));\n\n if (Exit.isFailure(acted)) {\n const error = Exit.findErrorOption(acted);\n\n if (Option.isSome(error) && error.value._tag === \"BrowserError\" && error.value.dispatched) {\n input = \"unknown\";\n if (expected !== undefined && (repeatable(step) || durable)) {\n const observed = yield* Effect.exit(within(verify, millis));\n\n if (Exit.isSuccess(observed) && observed.value) return yield* receipt(\"verified\");\n }\n }\n\n return yield* Effect.failCause(acted.cause);\n }\n input = \"unknown\";\n if (expected !== undefined && !(yield* within(verify, millis)))\n return yield* new Drifted({ detail: \"the step's expected effect did not arrive\" });\n\n return yield* receipt(expected === undefined ? \"taken\" : \"verified\");\n });\n\n return yield* work.pipe(\n Effect.mapError(\n (reason) =>\n new ReplayError({\n step: index,\n reason,\n input,\n receipts: [],\n }),\n ),\n );\n});\n\nconst run = Effect.fnUntraced(function* (\n page: Page,\n plan: Plan,\n options: TakeOptions,\n from: number | Stopped,\n until: number,\n restoring: boolean,\n) {\n const receipts: Array<Receipt> = [];\n const start = typeof from === \"number\" ? from : from.step;\n\n if (\n !Number.isInteger(start) ||\n start < 0 ||\n start > plan.steps.length ||\n !Number.isInteger(until) ||\n until < start ||\n until > plan.steps.length\n )\n return yield* new ReplayError({\n step: start,\n input: \"unsent\",\n receipts,\n reason: invalid(\"the run bounds are outside the plan\"),\n });\n // Fresh runs still ask for all input slots before changing the page. Restoration checks first.\n if (!restoring && typeof from === \"number\") {\n const unfilled = plan.steps.findIndex(\n (step, index) =>\n index >= start && step.input !== undefined && options.inputs?.[step.input] === undefined,\n );\n\n if (unfilled !== -1)\n return yield* new ReplayError({\n step: start,\n input: \"unsent\",\n receipts,\n reason: invalid(`no text for the input \"${plan.steps[unfilled]?.input ?? \"\"}\"`),\n });\n }\n for (let index = start; index < until; index++) {\n const at = restoring\n ? new Stopped({ step: index, input: \"unknown\" })\n : index === start\n ? from\n : index;\n\n const receipt = yield* take(page, plan, at, options).pipe(\n Effect.mapError((error) => new ReplayError({ ...error, receipts: [...receipts] })),\n );\n\n receipts.push(receipt);\n }\n\n return receipts;\n});\n\n/** Take a plan's steps from a fresh index or durable stopping point, returning completed receipts. */\nexport const replay = (page: Page, plan: Plan, options: ReplayOptions = {}) =>\n run(page, plan, options, options.from ?? 0, plan.steps.length, false).pipe(\n Effect.withSpan(\"Plan.replay\"),\n );\n\n/** Restore prior steps on a fresh page; unresolved commitments require positive durable evidence. */\nexport const restore = (\n page: Page,\n plan: Plan,\n options: TakeOptions & { readonly upTo?: number | undefined } = {},\n) =>\n run(page, plan, options, 0, options.upTo ?? plan.steps.length, true).pipe(\n Effect.withSpan(\"Plan.restore\"),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,UAAb,cAA6B,OAAO,YAAqB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CACxE,IAAa,UAAU;EACrB,OAAO;CACT;AACF;;AAGA,IAAa,YAAb,cAA+B,OAAO,YAAuB,CAAC,CAAC,aAAa,EAC1E,OAAO,OAAO,IAChB,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,OAAO,GAAG,KAAK,MAAM;CACvB;AACF;;AAGA,IAAa,UAAb,cAA6B,OAAO,YAAqB,CAAC,CAAC,WAAW,EACpE,QAAQ,OAAO,OACjB,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,OAAO,KAAK;CACd;AACF;AAEA,MAAM,EAAE,OAAO,cAAc,MAAM;AACnC,MAAM,SAAS;CAAC;CAAO;CAAU;CAAS;AAAS;AAEnD,MAAM,QAAQ,YACZ,OAAO,OAAO,OAAO,CAAC,CAAC,QAAQ,UAAU,OAAO,UAAU,QAAQ;;AAGpE,MAAM,WAAW,OAAgC,OAAe,YAA4B;CAC1F,MAAM,MAAM,QAAQ;CAEpB,IAAI,QAAQ,KAAA,KAAa,UAAU,GAAG,MAAM,UAAU,KAAK,GAAG,OAAO;CACrE,IAAI,UAAU,UAAU,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