effect-browser 0.3.0-beta.6 → 0.3.0-beta.8
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 +124 -21
- package/dist/{Browser-B5AV7zPS.mjs → Browser-CNwK0r0q.mjs} +2 -2
- package/dist/{Browser-B5AV7zPS.mjs.map → Browser-CNwK0r0q.mjs.map} +1 -1
- package/dist/Browser.d.mts +2 -2
- package/dist/Browser.mjs +1 -1
- package/dist/{BrowserEvent-DzdNdvoh.d.mts → BrowserEvent-BRu2juEz.d.mts} +3 -1
- package/dist/BrowserEvent.d.mts +1 -1
- package/dist/BrowserEvent.mjs +2 -0
- package/dist/BrowserEvent.mjs.map +1 -1
- package/dist/Cdp.mjs +1 -1
- package/dist/{Change-DVP2IJWm.d.mts → Change-iMlcuzVD.d.mts} +2 -2
- package/dist/Change.d.mts +1 -1
- package/dist/Chromium.mjs +1 -1
- package/dist/Expect.d.mts +1 -1
- package/dist/Expect.mjs +1 -1
- package/dist/Moment.d.mts +1 -1
- package/dist/{Page-DYTdVhYa.d.mts → Page-C30aG2RQ.d.mts} +6 -4
- package/dist/Page-D4281dIi.mjs.map +1 -1
- package/dist/Page.d.mts +1 -1
- package/dist/Plan-BvCS9qAf.d.mts +209 -0
- package/dist/{Plan-5MdsRzE5.mjs → Plan-CyQNv49C.mjs} +232 -38
- package/dist/Plan-CyQNv49C.mjs.map +1 -0
- package/dist/Plan.d.mts +2 -2
- package/dist/Plan.mjs +2 -2
- 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 +1 -1
- package/dist/Stage.mjs +1 -1
- package/dist/{Supervisor-Im6-wbg5.d.mts → Supervisor-CYWFK3vM.d.mts} +106 -56
- package/dist/Supervisor-TNKNOVzu.mjs +599 -0
- package/dist/Supervisor-TNKNOVzu.mjs.map +1 -0
- package/dist/Supervisor.d.mts +2 -2
- package/dist/Supervisor.mjs +2 -2
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +3 -3
- package/dist/{page-BkRcLCWZ.mjs → page-DHeYWEs-.mjs} +27 -14
- package/dist/page-DHeYWEs-.mjs.map +1 -0
- package/package.json +1 -1
- package/src/BrowserEvent.ts +2 -0
- package/src/Page.ts +3 -1
- package/src/Plan.ts +365 -56
- package/src/Supervisor.ts +384 -138
- package/src/internal/input/perform.ts +2 -0
- package/src/internal/page/bridge.ts +3 -3
- package/src/internal/reading/ready.inpage.ts +17 -7
- package/src/internal/reading/ready.ts +9 -3
- package/src/internal/supervisor/lifecycle.ts +291 -140
- package/dist/Plan-5MdsRzE5.mjs.map +0 -1
- package/dist/Plan-CNNOU1Tx.d.mts +0 -112
- package/dist/Supervisor-BtEG93gR.mjs +0 -420
- package/dist/Supervisor-BtEG93gR.mjs.map +0 -1
- package/dist/page-BkRcLCWZ.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Plan-5MdsRzE5.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. Replay stops at the first step it cannot take and says why: `Missing`,\n * `Ambiguous`, `Drifted`, or the step's own `BrowserError`. Nothing is replayed automatically, and\n * a plan of another version, such as one 0.2 stored, does not decode.\n *\n * @since 0.3.0\n */\nimport { Duration, Effect, 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\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 /** Where the page was once the step was done, as recorded; empty when unknown. */\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}) {}\n\nexport class Plan extends Schema.Class<Plan>(\"effect-browser/Plan\")({\n version: Schema.Literal(1),\n steps: Schema.Array(Step),\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/** Where replay stopped, counting steps from 0, and why. */\nexport class ReplayError extends Schema.TaggedError<ReplayError>()(\"ReplayError\", {\n step: Schema.Int,\n reason: Schema.Union([Missing, Ambiguous, Drifted, BrowserError]),\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\n // Only a navigation and a press keep their target: an address, or keys.\n return new Step({\n action: action.name,\n url: before(steps[index + 1]?.startedAt ?? Number.POSITIVE_INFINITY),\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 take = (\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 ReplayOptions {\n /** How each step waits for the page first, as `Page.ready` takes it, or false not to wait. */\n readonly settle?: ReadyOptions | false | undefined;\n /** The text for each of the plan's input slots. */\n readonly inputs?: Readonly<Record<string, string>> | undefined;\n}\n\n/** Take a plan's steps on a page, in order, stopping at the first that cannot be taken. */\nexport const replay = (page: Page, plan: Plan, options: ReplayOptions = {}) =>\n Effect.gen(function* () {\n const inputs = options.inputs ?? {};\n const settle = options.settle === false ? Effect.void : page.ready(options.settle);\n\n const at =\n (step: number) =>\n <A>(effect: Effect.Effect<A, Missing | Ambiguous | Drifted | BrowserError>) =>\n effect.pipe(Effect.mapError((reason) => new ReplayError({ step, reason })));\n\n // A step arrived where the recording did, on the same site; a moved path is not drift.\n const arrived = (index: number) => {\n const recorded = plan.steps[index]?.url ?? \"\";\n\n return page.url.pipe(\n Effect.flatMap((url) =>\n recorded === \"\" || URL.parse(url)?.origin === URL.parse(recorded)?.origin\n ? Effect.void\n : Effect.fail(\n new Drifted({ detail: `the page is at ${url}, not on ${recorded}'s site` }),\n ),\n ),\n at(index),\n );\n };\n\n const unfilled = plan.steps.findIndex(\n (step) => step.input !== undefined && inputs[step.input] === undefined,\n );\n\n if (unfilled !== -1)\n return yield* at(unfilled)(\n Effect.fail(invalid(`no text for the input \"${plan.steps[unfilled]?.input ?? \"\"}\"`)),\n );\n for (const [index, step] of plan.steps.entries()) {\n if (step.action !== \"navigate\" && step.action !== \"back\" && step.action !== \"reload\")\n yield* at(index)(settle);\n if (index > 0) yield* arrived(index - 1);\n yield* at(index)(\n take(page, step, step.input === undefined ? \"\" : (inputs[step.input] ?? \"\")),\n );\n }\n if (plan.steps.length > 0) {\n yield* at(plan.steps.length - 1)(settle);\n yield* arrived(plan.steps.length - 1);\n }\n }).pipe(Effect.withSpan(\"Plan.replay\", { attributes: { steps: plan.steps.length } }));\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,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AAK,UAAU,EAAG,CAC7E;CACF;CACA,IAAI,KAAK,MAAM,SAAS,GAAG;EACzB,OAAO,GAAG,KAAK,MAAM,SAAS,CAAC,CAAC,CAAC,MAAM;EACvC,OAAO,QAAQ,KAAK,MAAM,SAAS,CAAC;CACtC;AACF,CAAC,CAAC,CAAC,KAAK,OAAO,SAAS,eAAe,EAAE,YAAY,EAAE,OAAO,KAAK,MAAM,OAAO,EAAE,CAAC,CAAC"}
|
package/dist/Plan-CNNOU1Tx.d.mts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { t as BrowserError } from "./BrowserError-DXXIA6Rk.mjs";
|
|
2
|
-
import { b as Subject, i as BrowserEvent } from "./BrowserEvent-DzdNdvoh.mjs";
|
|
3
|
-
import { m as ReadyOptions, o as Found, u as Page } from "./Page-DYTdVhYa.mjs";
|
|
4
|
-
import { Effect, Schema } from "effect";
|
|
5
|
-
//#region src/internal/reading/choose.d.ts
|
|
6
|
-
declare const Missing_base: Schema.Class<Missing, Schema.TaggedStruct<"Missing", {}>, import("effect/Cause").YieldableError>;
|
|
7
|
-
/** Nothing on the page has the step's role and name. */
|
|
8
|
-
declare class Missing extends Missing_base {
|
|
9
|
-
get message(): string;
|
|
10
|
-
}
|
|
11
|
-
declare const Ambiguous_base: Schema.Class<Ambiguous, Schema.TaggedStruct<"Ambiguous", {
|
|
12
|
-
readonly count: Schema.Int;
|
|
13
|
-
}>, import("effect/Cause").YieldableError>;
|
|
14
|
-
/** Several elements match the step's subject equally well, and nothing tells them apart. */
|
|
15
|
-
declare class Ambiguous extends Ambiguous_base {
|
|
16
|
-
get message(): string;
|
|
17
|
-
}
|
|
18
|
-
declare const Drifted_base: Schema.Class<Drifted, Schema.TaggedStruct<"Drifted", {
|
|
19
|
-
readonly detail: Schema.String;
|
|
20
|
-
}>, import("effect/Cause").YieldableError>;
|
|
21
|
-
/** The page is not where the recording was: another site, or no element with its context. */
|
|
22
|
-
declare class Drifted extends Drifted_base {
|
|
23
|
-
get message(): string;
|
|
24
|
-
}
|
|
25
|
-
declare namespace Plan_d_exports {
|
|
26
|
-
export { Ambiguous, Drifted, Missing, Plan, ReplayError, ReplayOptions, Step, StepAction, fromEvents, locate, replay };
|
|
27
|
-
}
|
|
28
|
-
declare const StepAction: Schema.Literals<readonly ["navigate", "back", "reload", "click", "hover", "drag", "type", "press", "scroll", "select"]>;
|
|
29
|
-
type StepAction = typeof StepAction.Type;
|
|
30
|
-
declare const Step_base: Schema.Class<Step, Schema.Struct<{
|
|
31
|
-
readonly action: Schema.Literals<readonly ["navigate", "back", "reload", "click", "hover", "drag", "type", "press", "scroll", "select"]>;
|
|
32
|
-
/** Where the page was once the step was done, as recorded; empty when unknown. */
|
|
33
|
-
readonly url: Schema.String;
|
|
34
|
-
/** A navigation's requested address, or the keys a press pressed. */
|
|
35
|
-
readonly target: Schema.optional<Schema.String>;
|
|
36
|
-
readonly subject: Schema.optional<typeof Subject>;
|
|
37
|
-
/** Where a drag ended. */
|
|
38
|
-
readonly to: Schema.optional<typeof Subject>;
|
|
39
|
-
/** The viewport point a step aimed at, when it aimed at a point, and a drag's end point. */
|
|
40
|
-
readonly point: Schema.optional<Schema.Struct<{
|
|
41
|
-
readonly x: Schema.Finite;
|
|
42
|
-
readonly y: Schema.Finite;
|
|
43
|
-
}>>;
|
|
44
|
-
readonly toPoint: Schema.optional<Schema.Struct<{
|
|
45
|
-
readonly x: Schema.Finite;
|
|
46
|
-
readonly y: Schema.Finite;
|
|
47
|
-
}>>;
|
|
48
|
-
/** The box of what a step aimed at by point found there, so replay aims at the same place in it. */
|
|
49
|
-
readonly box: Schema.optional<Schema.Struct<{
|
|
50
|
-
readonly x: Schema.Finite;
|
|
51
|
-
readonly y: Schema.Finite;
|
|
52
|
-
readonly width: Schema.Finite;
|
|
53
|
-
readonly height: Schema.Finite;
|
|
54
|
-
}>>;
|
|
55
|
-
/**
|
|
56
|
-
* The input slot whose text a `type` step types, or whose address a `navigate` step goes to, as
|
|
57
|
-
* its recorded address had a credential withheld.
|
|
58
|
-
*/
|
|
59
|
-
readonly input: Schema.optional<Schema.String>;
|
|
60
|
-
/** The slot's text went into a secret field, so replay types it into nothing else. */
|
|
61
|
-
readonly secret: Schema.optional<Schema.Literal<true>>;
|
|
62
|
-
readonly options: Schema.optional<Schema.Struct<{
|
|
63
|
-
readonly button: Schema.optional<Schema.Literals<readonly ["left", "right", "middle"]>>;
|
|
64
|
-
readonly clickCount: Schema.optional<Schema.Finite>;
|
|
65
|
-
readonly holdMillis: Schema.optional<Schema.Finite>;
|
|
66
|
-
readonly replace: Schema.optional<Schema.Boolean>;
|
|
67
|
-
readonly submit: Schema.optional<Schema.Boolean>;
|
|
68
|
-
readonly times: Schema.optional<Schema.Finite>;
|
|
69
|
-
readonly dx: Schema.optional<Schema.Finite>;
|
|
70
|
-
readonly dy: Schema.optional<Schema.Finite>;
|
|
71
|
-
readonly values: Schema.optional<Schema.$Array<Schema.String>>;
|
|
72
|
-
}>>;
|
|
73
|
-
}>, {}>;
|
|
74
|
-
/** One recorded step: the action, what it acted on, and what else it was asked. */
|
|
75
|
-
declare class Step extends Step_base {}
|
|
76
|
-
declare const Plan_base: Schema.Class<Plan, Schema.Struct<{
|
|
77
|
-
readonly version: Schema.Literal<1>;
|
|
78
|
-
readonly steps: Schema.$Array<typeof Step>;
|
|
79
|
-
}>, {}>;
|
|
80
|
-
declare class Plan extends Plan_base {
|
|
81
|
-
/** The input slots its steps type, in order; replay needs text for each. */
|
|
82
|
-
get inputs(): ReadonlyArray<string>;
|
|
83
|
-
}
|
|
84
|
-
declare const ReplayError_base: Schema.Class<ReplayError, Schema.TaggedStruct<"ReplayError", {
|
|
85
|
-
readonly step: Schema.Int;
|
|
86
|
-
readonly reason: Schema.Union<readonly [typeof Missing, typeof Ambiguous, typeof Drifted, typeof BrowserError]>;
|
|
87
|
-
}>, import("effect/Cause").YieldableError>;
|
|
88
|
-
/** Where replay stopped, counting steps from 0, and why. */
|
|
89
|
-
declare class ReplayError extends ReplayError_base {
|
|
90
|
-
get message(): string;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* The walk one page's events record: the completed actions of the page that acted first, in
|
|
94
|
-
* order. `page.recentEvents` gives them, or `browser.events()` read until the walk ends.
|
|
95
|
-
*/
|
|
96
|
-
declare const fromEvents: (events: Iterable<BrowserEvent>) => Plan;
|
|
97
|
-
/**
|
|
98
|
-
* The one element on the page that a subject names, by role, name and context (see `Plan`),
|
|
99
|
-
* looking again for two seconds while the page may still be drawing it.
|
|
100
|
-
*/
|
|
101
|
-
declare const locate: (page: Page, subject: Subject) => Effect.Effect<Found, Ambiguous | BrowserError | Drifted | Missing, never>;
|
|
102
|
-
interface ReplayOptions {
|
|
103
|
-
/** How each step waits for the page first, as `Page.ready` takes it, or false not to wait. */
|
|
104
|
-
readonly settle?: ReadyOptions | false | undefined;
|
|
105
|
-
/** The text for each of the plan's input slots. */
|
|
106
|
-
readonly inputs?: Readonly<Record<string, string>> | undefined;
|
|
107
|
-
}
|
|
108
|
-
/** Take a plan's steps on a page, in order, stopping at the first that cannot be taken. */
|
|
109
|
-
declare const replay: (page: Page, plan: Plan, options?: ReplayOptions) => Effect.Effect<undefined, ReplayError, never>;
|
|
110
|
-
//#endregion
|
|
111
|
-
export { Step as a, locate as c, Drifted as d, Missing as f, ReplayOptions as i, replay as l, Plan_d_exports as n, StepAction as o, ReplayError as r, fromEvents as s, Plan as t, Ambiguous as u };
|
|
112
|
-
//# sourceMappingURL=Plan-CNNOU1Tx.d.mts.map
|
|
@@ -1,420 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import { DisconnectCause } from "./BrowserEvent.mjs";
|
|
3
|
-
import { Cause, Clock, DateTime, Duration, Effect, Exit, Fiber, FiberHandle, FiberMap, Option, Predicate, PubSub, Schedule, Schema, Scope, Stream, SubscriptionRef } from "effect";
|
|
4
|
-
//#region src/internal/supervisor/lifecycle.ts
|
|
5
|
-
/**
|
|
6
|
-
* A supervisor's life as one state and one transition function, and the generation states it
|
|
7
|
-
* publishes. The transition has no effects: `Supervisor.make` applies each input under one lock,
|
|
8
|
-
* publishes the events in order and runs the commands, so the rules here are tested alone.
|
|
9
|
-
*/
|
|
10
|
-
/** The provider confirmed that the generation's browser ended. */
|
|
11
|
-
var Settled = class extends Schema.TaggedClass()("Settled", {}) {};
|
|
12
|
-
/** The provider could not confirm the end by its deadline, so the browser may still run, and bill. */
|
|
13
|
-
var Unconfirmed = class extends Schema.TaggedClass()("Unconfirmed", { detail: Schema.String }) {};
|
|
14
|
-
const Released = Schema.Union([Settled, Unconfirmed]);
|
|
15
|
-
/** Opening, but not after a loss: the first generation, a rotation, or the one after `Down`. */
|
|
16
|
-
var Opening = class extends Schema.TaggedClass()("Opening", {}) {};
|
|
17
|
-
/** Opening after the generation before it was lost. */
|
|
18
|
-
var Reopening = class extends Schema.TaggedClass()("Reopening", {}) {};
|
|
19
|
-
/** Open: `browser` gives this generation until the next one opens. */
|
|
20
|
-
var Open = class extends Schema.TaggedClass()("Open", {}) {};
|
|
21
|
-
/** Lost: its connection dropped, or its provider ended its session, as `cause` says. */
|
|
22
|
-
var Lost = class extends Schema.TaggedClass()("Lost", { cause: DisconnectCause }) {};
|
|
23
|
-
/**
|
|
24
|
-
* It never opened: its last try failed with `cause`, which the provider deems definite, or after
|
|
25
|
-
* which the reopen schedule gave up.
|
|
26
|
-
*/
|
|
27
|
-
var Down = class extends Schema.TaggedClass()("Down", {
|
|
28
|
-
detail: Schema.String,
|
|
29
|
-
cause: Schema.Defect()
|
|
30
|
-
}) {};
|
|
31
|
-
/** It ended. `released` says how its release went; one retired while opening has none. */
|
|
32
|
-
var Closed = class extends Schema.TaggedClass()("Closed", { released: Schema.optional(Released) }) {};
|
|
33
|
-
/**
|
|
34
|
-
* It was serving as the supervisor's scope closed, and was left running, not released: its scope
|
|
35
|
-
* closed, and its provider runs it on, and bills, until something adopts and releases it.
|
|
36
|
-
*/
|
|
37
|
-
var Kept = class extends Schema.TaggedClass()("Kept", {}) {};
|
|
38
|
-
const GenerationState = Schema.Union([
|
|
39
|
-
Opening,
|
|
40
|
-
Reopening,
|
|
41
|
-
Open,
|
|
42
|
-
Lost,
|
|
43
|
-
Down,
|
|
44
|
-
Closed,
|
|
45
|
-
Kept
|
|
46
|
-
]);
|
|
47
|
-
const start = () => ({
|
|
48
|
-
state: {
|
|
49
|
-
_tag: "Opening",
|
|
50
|
-
number: 1,
|
|
51
|
-
serving: void 0
|
|
52
|
-
},
|
|
53
|
-
events: [[1, new Opening()]],
|
|
54
|
-
commands: [{
|
|
55
|
-
_tag: "Open",
|
|
56
|
-
number: 1,
|
|
57
|
-
after: void 0
|
|
58
|
-
}]
|
|
59
|
-
});
|
|
60
|
-
const servingOf = (state) => state._tag === "Retired" ? void 0 : state.serving;
|
|
61
|
-
/** The state after `input`, with the events to publish and the commands to run. */
|
|
62
|
-
const transition = (state, input, exclusive) => {
|
|
63
|
-
const release = (live) => ({
|
|
64
|
-
_tag: "Release",
|
|
65
|
-
live
|
|
66
|
-
});
|
|
67
|
-
const stay = {
|
|
68
|
-
state,
|
|
69
|
-
events: [],
|
|
70
|
-
commands: []
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Open `number`, ending `current` now if it `ends`; exclusive generations open only once its
|
|
74
|
-
* release has finished. Otherwise `current` serves until the next one opens.
|
|
75
|
-
*/
|
|
76
|
-
const next = (number, reopen, current, ends) => ({
|
|
77
|
-
state: {
|
|
78
|
-
_tag: "Opening",
|
|
79
|
-
number,
|
|
80
|
-
serving: ends ? void 0 : current
|
|
81
|
-
},
|
|
82
|
-
events: [[number, reopen ? new Reopening() : new Opening()]],
|
|
83
|
-
commands: [...ends && current !== void 0 ? [release(current)] : [], {
|
|
84
|
-
_tag: "Open",
|
|
85
|
-
number,
|
|
86
|
-
after: ends && exclusive ? current?.number : void 0
|
|
87
|
-
}]
|
|
88
|
-
});
|
|
89
|
-
switch (input._tag) {
|
|
90
|
-
case "Opened": {
|
|
91
|
-
const { live } = input;
|
|
92
|
-
if (state._tag !== "Opening" || state.number !== live.number) return {
|
|
93
|
-
...stay,
|
|
94
|
-
commands: [release(live)]
|
|
95
|
-
};
|
|
96
|
-
return {
|
|
97
|
-
state: {
|
|
98
|
-
_tag: "Open",
|
|
99
|
-
serving: live
|
|
100
|
-
},
|
|
101
|
-
events: [[live.number, new Open()]],
|
|
102
|
-
commands: [{
|
|
103
|
-
_tag: "Watch",
|
|
104
|
-
live
|
|
105
|
-
}, ...state.serving === void 0 ? [] : [release(state.serving)]]
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
case "Failed": {
|
|
109
|
-
const { number, detail, cause } = input;
|
|
110
|
-
const events = [[number, new Down({
|
|
111
|
-
detail,
|
|
112
|
-
cause
|
|
113
|
-
})]];
|
|
114
|
-
if (state._tag !== "Opening" || state.number !== input.number) return {
|
|
115
|
-
...stay,
|
|
116
|
-
events
|
|
117
|
-
};
|
|
118
|
-
return {
|
|
119
|
-
state: {
|
|
120
|
-
_tag: "Down",
|
|
121
|
-
number,
|
|
122
|
-
detail,
|
|
123
|
-
cause,
|
|
124
|
-
serving: state.serving
|
|
125
|
-
},
|
|
126
|
-
events,
|
|
127
|
-
commands: []
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
case "Abandoned": return {
|
|
131
|
-
...stay,
|
|
132
|
-
events: [[input.number, new Closed({})]]
|
|
133
|
-
};
|
|
134
|
-
case "Released": return {
|
|
135
|
-
...stay,
|
|
136
|
-
events: [[input.number, new Closed({ released: input.released })]]
|
|
137
|
-
};
|
|
138
|
-
case "Lost": {
|
|
139
|
-
const lost = servingOf(state);
|
|
140
|
-
if (state._tag === "Retired" || lost?.number !== input.number) return stay;
|
|
141
|
-
const events = [[lost.number, new Lost({ cause: input.cause })]];
|
|
142
|
-
if (state._tag === "Opening") return {
|
|
143
|
-
state: {
|
|
144
|
-
...state,
|
|
145
|
-
serving: void 0
|
|
146
|
-
},
|
|
147
|
-
events,
|
|
148
|
-
commands: [release(lost)]
|
|
149
|
-
};
|
|
150
|
-
const reopened = next((state._tag === "Open" ? lost.number : state.number) + 1, true, lost, true);
|
|
151
|
-
return {
|
|
152
|
-
...reopened,
|
|
153
|
-
events: [...events, ...reopened.events]
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
case "Rotate": {
|
|
157
|
-
if (state._tag === "Retired") return stay;
|
|
158
|
-
if (input.due !== void 0 && (state._tag !== "Open" || state.serving.number !== input.due)) return stay;
|
|
159
|
-
if (state._tag === "Opening") return {
|
|
160
|
-
...stay,
|
|
161
|
-
reply: state.number
|
|
162
|
-
};
|
|
163
|
-
const number = (state._tag === "Open" ? state.serving.number : state.number) + 1;
|
|
164
|
-
return {
|
|
165
|
-
...next(number, false, state.serving, exclusive),
|
|
166
|
-
reply: number
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
case "Retire":
|
|
170
|
-
case "Keep": {
|
|
171
|
-
const current = servingOf(state);
|
|
172
|
-
if (state._tag === "Retired") return stay;
|
|
173
|
-
if (current === void 0) return {
|
|
174
|
-
state: { _tag: "Retired" },
|
|
175
|
-
events: [],
|
|
176
|
-
commands: []
|
|
177
|
-
};
|
|
178
|
-
return input._tag === "Retire" ? {
|
|
179
|
-
state: { _tag: "Retired" },
|
|
180
|
-
events: [],
|
|
181
|
-
commands: [release(current)]
|
|
182
|
-
} : {
|
|
183
|
-
state: { _tag: "Retired" },
|
|
184
|
-
events: [[current.number, new Kept()]],
|
|
185
|
-
commands: [{
|
|
186
|
-
_tag: "Leave",
|
|
187
|
-
live: current
|
|
188
|
-
}]
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
/**
|
|
194
|
-
* What a caller waiting for generation `target`, or for any when it is undefined, gets in
|
|
195
|
-
* `state`; undefined while it should go on waiting.
|
|
196
|
-
*/
|
|
197
|
-
const resolve = (state, target) => {
|
|
198
|
-
const serve = (live) => ({
|
|
199
|
-
_tag: "Serve",
|
|
200
|
-
live
|
|
201
|
-
});
|
|
202
|
-
switch (state._tag) {
|
|
203
|
-
case "Retired": return {
|
|
204
|
-
_tag: "Unavailable",
|
|
205
|
-
reason: "retired",
|
|
206
|
-
detail: "the supervisor was retired"
|
|
207
|
-
};
|
|
208
|
-
case "Open": return target === void 0 || state.serving.number >= target ? serve(state.serving) : void 0;
|
|
209
|
-
case "Opening": return target === void 0 && state.serving !== void 0 ? serve(state.serving) : void 0;
|
|
210
|
-
case "Down":
|
|
211
|
-
if (target === void 0 && state.serving !== void 0) return serve(state.serving);
|
|
212
|
-
return target === void 0 || state.number >= target ? {
|
|
213
|
-
_tag: "Unavailable",
|
|
214
|
-
reason: "down",
|
|
215
|
-
detail: state.detail,
|
|
216
|
-
cause: state.cause
|
|
217
|
-
} : void 0;
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
//#endregion
|
|
221
|
-
//#region src/Supervisor.ts
|
|
222
|
-
/**
|
|
223
|
-
* A browser kept open across losses and session ends, as a series of generations, each a new
|
|
224
|
-
* browser from the same provider. Pages don't carry over from one generation to the next.
|
|
225
|
-
*
|
|
226
|
-
* `make` opens the first generation at once with the provider's `open`, in a scope of its own, so
|
|
227
|
-
* a caller that stops waiting never interrupts a half-open browser. `browser` gives the current
|
|
228
|
-
* generation; callers wait, bounded, and share one open. A loss is published at once and the next
|
|
229
|
-
* generation opens on the `reopen` schedule, which also retries a failed open, unless the provider
|
|
230
|
-
* deems its failure `definite`: that goes `Down` at once, with its cause. `rotate` opens the
|
|
231
|
-
* next generation now, and so does the time `rotateBefore` ahead of a generation's `expiresAt`. A
|
|
232
|
-
* rotation makes the next generation before it breaks the current one, unless generations are
|
|
233
|
-
* `exclusive`, as sessions saving to one stored context must be: then the current one is released
|
|
234
|
-
* first. `retire` stops reopening at once and releases what is open; the scope's close retires
|
|
235
|
-
* too, unless the supervisor `keep`s: then it leaves the serving generation running, `Kept`. `states`
|
|
236
|
-
* publishes each generation's changes, with the provider's release outcome last.
|
|
237
|
-
*
|
|
238
|
-
* Providers supply the specifics: `Browserbase.supervise` opens hosted sessions this way.
|
|
239
|
-
*
|
|
240
|
-
* @since 0.3.0
|
|
241
|
-
*/
|
|
242
|
-
var Supervisor_exports = /* @__PURE__ */ __exportAll({
|
|
243
|
-
Closed: () => Closed,
|
|
244
|
-
Down: () => Down,
|
|
245
|
-
Generation: () => Generation,
|
|
246
|
-
GenerationState: () => GenerationState,
|
|
247
|
-
Kept: () => Kept,
|
|
248
|
-
Lost: () => Lost,
|
|
249
|
-
Open: () => Open,
|
|
250
|
-
Opening: () => Opening,
|
|
251
|
-
Released: () => Released,
|
|
252
|
-
Reopening: () => Reopening,
|
|
253
|
-
Settled: () => Settled,
|
|
254
|
-
Unavailable: () => Unavailable,
|
|
255
|
-
Unconfirmed: () => Unconfirmed,
|
|
256
|
-
make: () => make
|
|
257
|
-
});
|
|
258
|
-
/** One change in a generation's life. `at` is wall-clock epoch milliseconds from the Effect `Clock`. */
|
|
259
|
-
var Generation = class extends Schema.Class("effect-browser/Generation")({
|
|
260
|
-
number: Schema.Int.check(Schema.isGreaterThan(0)),
|
|
261
|
-
at: Schema.Finite,
|
|
262
|
-
state: GenerationState
|
|
263
|
-
}) {};
|
|
264
|
-
/**
|
|
265
|
-
* No browser to give: none opened within `waitTimeout` (`opening`), the latest generation failed
|
|
266
|
-
* to open (`down`, with what it failed with as `cause`), or the supervisor was retired.
|
|
267
|
-
*/
|
|
268
|
-
var Unavailable = class extends Schema.TaggedError()("Unavailable", {
|
|
269
|
-
reason: Schema.Literals([
|
|
270
|
-
"opening",
|
|
271
|
-
"down",
|
|
272
|
-
"retired"
|
|
273
|
-
]),
|
|
274
|
-
detail: Schema.String,
|
|
275
|
-
cause: Schema.optional(Schema.Defect())
|
|
276
|
-
}) {
|
|
277
|
-
get message() {
|
|
278
|
-
return `no browser: ${this.detail}`;
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
const retired = () => new Unavailable({
|
|
282
|
-
reason: "retired",
|
|
283
|
-
detail: "the supervisor was retired"
|
|
284
|
-
});
|
|
285
|
-
const describe = (cause) => {
|
|
286
|
-
const error = Cause.squash(cause);
|
|
287
|
-
return Predicate.isError(error) ? error.message : String(error);
|
|
288
|
-
};
|
|
289
|
-
/**
|
|
290
|
-
* Wait up to `waitTimeout` for generation `target`, or for any when it is undefined, as `state`
|
|
291
|
-
* changes.
|
|
292
|
-
*/
|
|
293
|
-
const waitFor = (state, waitTimeout, target) => SubscriptionRef.changes(state).pipe(Stream.map((current) => resolve(current, target)), Stream.filter(Predicate.isNotUndefined), Stream.runHead, Effect.flatMap(Option.match({
|
|
294
|
-
onNone: () => Effect.fail(retired()),
|
|
295
|
-
onSome: (resolution) => resolution._tag === "Serve" ? Effect.succeed(resolution.live.value.opened.browser) : Effect.fail(new Unavailable({
|
|
296
|
-
reason: resolution.reason,
|
|
297
|
-
detail: resolution.detail,
|
|
298
|
-
cause: resolution.cause
|
|
299
|
-
}))
|
|
300
|
-
})), Effect.timeoutOrElse({
|
|
301
|
-
duration: waitTimeout,
|
|
302
|
-
orElse: () => Effect.fail(new Unavailable({
|
|
303
|
-
reason: "opening",
|
|
304
|
-
detail: `no generation opened within ${Duration.format(waitTimeout)}`
|
|
305
|
-
}))
|
|
306
|
-
}));
|
|
307
|
-
/** Sleep until `before` ahead of `expiresAt`, but no sooner than halfway there from now. */
|
|
308
|
-
const untilRotation = (expiresAt, before) => Clock.currentTimeMillis.pipe(Effect.flatMap((now) => {
|
|
309
|
-
const left = DateTime.toEpochMillis(expiresAt) - now;
|
|
310
|
-
return Effect.sleep(Duration.millis(Math.max(left - Duration.toMillis(before), left / 2, 0)));
|
|
311
|
-
}));
|
|
312
|
-
/** Supervise generations of a provider's browser for as long as the scope is open. */
|
|
313
|
-
const make = Effect.fn("Supervisor.make")(function* (options) {
|
|
314
|
-
const clock = yield* Clock.Clock;
|
|
315
|
-
const context = yield* Effect.context();
|
|
316
|
-
const own = yield* Scope.fork(yield* Effect.scope);
|
|
317
|
-
const exclusive = options.exclusive ?? false;
|
|
318
|
-
const definite = options.definite ?? (() => false);
|
|
319
|
-
const reopen = options.reopen ?? Schedule.exponential("1 second").pipe(Schedule.upTo({ duration: Duration.minutes(5) }));
|
|
320
|
-
const rotateBefore = options.rotateBefore === void 0 ? void 0 : Duration.fromInputUnsafe(options.rotateBefore);
|
|
321
|
-
const waitTimeout = Duration.fromInputUnsafe(options.waitTimeout ?? Duration.minutes(2));
|
|
322
|
-
const started = start();
|
|
323
|
-
const state = yield* SubscriptionRef.make(started.state);
|
|
324
|
-
const events = yield* PubSub.unbounded({ replay: 64 });
|
|
325
|
-
const opening = yield* FiberHandle.make();
|
|
326
|
-
const releases = yield* FiberMap.make();
|
|
327
|
-
const runOpen = yield* FiberHandle.runtime(opening)();
|
|
328
|
-
const runRelease = yield* FiberMap.runtime(releases)();
|
|
329
|
-
const apply = (input) => SubscriptionRef.modifyEffect(state, (current) => {
|
|
330
|
-
const step = transition(current, input, exclusive);
|
|
331
|
-
return Effect.as(perform(step), [step.reply, step.state]);
|
|
332
|
-
}).pipe(Effect.uninterruptible);
|
|
333
|
-
const perform = (step) => Effect.gen(function* () {
|
|
334
|
-
for (const [number, generation] of step.events) PubSub.publishUnsafe(events, [new Generation({
|
|
335
|
-
number,
|
|
336
|
-
at: clock.currentTimeMillisUnsafe(),
|
|
337
|
-
state: generation
|
|
338
|
-
})]);
|
|
339
|
-
for (const command of step.commands) switch (command._tag) {
|
|
340
|
-
case "Open":
|
|
341
|
-
runOpen(openGeneration(command.number, command.after));
|
|
342
|
-
break;
|
|
343
|
-
case "Watch":
|
|
344
|
-
yield* Effect.forkIn(Effect.provideContext(watch(command.live), context), command.live.value.scope);
|
|
345
|
-
break;
|
|
346
|
-
case "Release":
|
|
347
|
-
runRelease(command.live.number, release(command.live));
|
|
348
|
-
break;
|
|
349
|
-
case "Leave": runRelease(command.live.number, Scope.close(command.live.value.scope, Exit.void));
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
const openOnce = Effect.uninterruptibleMask((restore) => Effect.flatMap(Scope.fork(own), (scope) => restore(options.open.pipe(Scope.provide(scope), Effect.provideContext(context))).pipe(Effect.onError((cause) => Scope.close(scope, Exit.failCause(cause))), Effect.map((opened) => ({
|
|
353
|
-
opened,
|
|
354
|
-
scope
|
|
355
|
-
})))));
|
|
356
|
-
const openGeneration = (number, after) => Effect.uninterruptibleMask((restore) => {
|
|
357
|
-
const previous = after === void 0 ? Effect.void : FiberMap.get(releases, after).pipe(Effect.flatMap(Option.match({
|
|
358
|
-
onNone: () => Effect.void,
|
|
359
|
-
onSome: Fiber.await
|
|
360
|
-
})));
|
|
361
|
-
const tries = Effect.retry(openOnce, {
|
|
362
|
-
schedule: reopen,
|
|
363
|
-
while: (error) => !definite(error)
|
|
364
|
-
});
|
|
365
|
-
return restore(previous.pipe(Effect.andThen(tries))).pipe(Effect.exit, Effect.flatMap((exit) => {
|
|
366
|
-
if (Exit.isSuccess(exit)) return apply({
|
|
367
|
-
_tag: "Opened",
|
|
368
|
-
live: {
|
|
369
|
-
number,
|
|
370
|
-
value: exit.value
|
|
371
|
-
}
|
|
372
|
-
});
|
|
373
|
-
return Cause.hasInterruptsOnly(exit.cause) ? apply({
|
|
374
|
-
_tag: "Abandoned",
|
|
375
|
-
number
|
|
376
|
-
}) : apply({
|
|
377
|
-
_tag: "Failed",
|
|
378
|
-
number,
|
|
379
|
-
detail: describe(exit.cause),
|
|
380
|
-
cause: Cause.squash(exit.cause)
|
|
381
|
-
});
|
|
382
|
-
}));
|
|
383
|
-
});
|
|
384
|
-
const watch = (live) => {
|
|
385
|
-
const { browser } = live.value.opened;
|
|
386
|
-
const loss = browser.disconnected.pipe(Effect.flatMap((cause) => apply({
|
|
387
|
-
_tag: "Lost",
|
|
388
|
-
number: live.number,
|
|
389
|
-
cause
|
|
390
|
-
})));
|
|
391
|
-
const rotation = browser.expiresAt === void 0 || rotateBefore === void 0 ? Effect.void : untilRotation(browser.expiresAt, rotateBefore).pipe(Effect.andThen(apply({
|
|
392
|
-
_tag: "Rotate",
|
|
393
|
-
due: live.number
|
|
394
|
-
})));
|
|
395
|
-
return Effect.all([loss, rotation], {
|
|
396
|
-
concurrency: 2,
|
|
397
|
-
discard: true
|
|
398
|
-
});
|
|
399
|
-
};
|
|
400
|
-
const release = (live) => (live.value.opened.release ?? Effect.succeed(new Settled())).pipe(Effect.catchCause((cause) => Effect.succeed(new Unconfirmed({ detail: `the release failed: ${describe(cause)}` }))), Effect.ensuring(Scope.close(live.value.scope, Exit.void)), Effect.flatMap((released) => apply({
|
|
401
|
-
_tag: "Released",
|
|
402
|
-
number: live.number,
|
|
403
|
-
released
|
|
404
|
-
})));
|
|
405
|
-
const end = yield* Effect.cached(PubSub.publish(events, Exit.void));
|
|
406
|
-
const stop = (input) => apply(input).pipe(Effect.andThen(FiberHandle.clear(opening)), Effect.andThen(FiberMap.awaitEmpty(releases)), Effect.andThen(end), Effect.asVoid);
|
|
407
|
-
const retire = yield* Effect.cached(stop({ _tag: "Retire" }));
|
|
408
|
-
yield* Effect.addFinalizer(() => options.keep === true ? stop({ _tag: "Keep" }) : retire);
|
|
409
|
-
yield* perform(started);
|
|
410
|
-
return {
|
|
411
|
-
browser: waitFor(state, waitTimeout, void 0),
|
|
412
|
-
states: Stream.fromPubSubTake(events),
|
|
413
|
-
rotate: apply({ _tag: "Rotate" }).pipe(Effect.flatMap((target) => target === void 0 ? Effect.fail(retired()) : waitFor(state, waitTimeout, target))),
|
|
414
|
-
retire
|
|
415
|
-
};
|
|
416
|
-
});
|
|
417
|
-
//#endregion
|
|
418
|
-
export { Closed as a, Kept as c, Opening as d, Released as f, Unconfirmed as h, make as i, Lost as l, Settled as m, Supervisor_exports as n, Down as o, Reopening as p, Unavailable as r, GenerationState as s, Generation as t, Open as u };
|
|
419
|
-
|
|
420
|
-
//# sourceMappingURL=Supervisor-BtEG93gR.mjs.map
|