mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 20:17:09 +00:00
refactor(spec): bridge data-tree nodes to the legacy goja picker tags
This commit is contained in:
1 parent
c9d8f165b1
commit
ee54c474b6
1 file changed
+46
-11
+46
-11
@@ -22,10 +22,39 @@ import type {
|
|||||||
WaitAction,
|
WaitAction,
|
||||||
WeightedEntry,
|
WeightedEntry,
|
||||||
} from "./types.ts";
|
} from "./types.ts";
|
||||||
import type { ActionDescriptor, GeneratorNode } from "./action-tree.ts";
|
import type { ActionDescriptor, BuiltinVerb, GeneratorNode } from "./action-tree.ts";
|
||||||
|
|
||||||
|
// LEGACY GOJA BRIDGE. The new data-tree nodes carry the old goja picker's tags
|
||||||
|
// (__sanderlingKind / entries / per-verb kind) so worker.go keeps walking them
|
||||||
|
// unchanged until Phase 2 rewires goja onto pick.ts. pick.ts ignores these
|
||||||
|
// fields. Delete this bridge (and the goja picker) in Phase 2.
|
||||||
|
const VERB_LEGACY_KIND: Record<string, string> = {
|
||||||
|
taps: "taps",
|
||||||
|
doubleTaps: "doubleTaps",
|
||||||
|
longPresses: "longPresses",
|
||||||
|
scrolls: "scrolls",
|
||||||
|
typing: "typing",
|
||||||
|
swipes: "swipes",
|
||||||
|
waitOnce: "waitOnce",
|
||||||
|
pressKeys: "pressKey",
|
||||||
|
};
|
||||||
|
|
||||||
|
function builtinNode(verb: BuiltinVerb): GeneratorNode {
|
||||||
|
return {
|
||||||
|
kind: "builtin",
|
||||||
|
verb,
|
||||||
|
__sanderlingActionGenerator: true,
|
||||||
|
__sanderlingKind: VERB_LEGACY_KIND[verb],
|
||||||
|
} as GeneratorNode;
|
||||||
|
}
|
||||||
|
|
||||||
export function actions(generator: () => Action[]): GeneratorNode {
|
export function actions(generator: () => Action[]): GeneratorNode {
|
||||||
return { kind: "actions", generate: generator as () => ActionDescriptor[] };
|
return {
|
||||||
|
kind: "actions",
|
||||||
|
generate: generator as () => ActionDescriptor[],
|
||||||
|
__sanderlingActionGenerator: true,
|
||||||
|
__sanderlingKind: "actions",
|
||||||
|
} as GeneratorNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function whenRoute(
|
export function whenRoute(
|
||||||
@@ -42,7 +71,13 @@ export function whenRoute(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function weighted(...entries: WeightedEntry[]): GeneratorNode {
|
export function weighted(...entries: WeightedEntry[]): GeneratorNode {
|
||||||
return { kind: "weighted", branches: entries };
|
return {
|
||||||
|
kind: "weighted",
|
||||||
|
branches: entries,
|
||||||
|
__sanderlingActionGenerator: true,
|
||||||
|
__sanderlingKind: "weighted",
|
||||||
|
entries,
|
||||||
|
} as GeneratorNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// samplerRng is the picker's Pcg while it evaluates an `actions` node's
|
// samplerRng is the picker's Pcg while it evaluates an `actions` node's
|
||||||
@@ -112,11 +147,11 @@ export function Wait(parameters: { durationMillis: number }): WaitAction {
|
|||||||
return { kind: "Wait", durationMillis: parameters.durationMillis };
|
return { kind: "Wait", durationMillis: parameters.durationMillis };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const taps: GeneratorNode = { kind: "builtin", verb: "taps" };
|
export const taps: GeneratorNode = builtinNode("taps");
|
||||||
export const doubleTaps: GeneratorNode = { kind: "builtin", verb: "doubleTaps" };
|
export const doubleTaps: GeneratorNode = builtinNode("doubleTaps");
|
||||||
export const longPresses: GeneratorNode = { kind: "builtin", verb: "longPresses" };
|
export const longPresses: GeneratorNode = builtinNode("longPresses");
|
||||||
export const scrolls: GeneratorNode = { kind: "builtin", verb: "scrolls" };
|
export const scrolls: GeneratorNode = builtinNode("scrolls");
|
||||||
export const typing: GeneratorNode = { kind: "builtin", verb: "typing" };
|
export const typing: GeneratorNode = builtinNode("typing");
|
||||||
export const swipes: GeneratorNode = { kind: "builtin", verb: "swipes" };
|
export const swipes: GeneratorNode = builtinNode("swipes");
|
||||||
export const waitOnce: GeneratorNode = { kind: "builtin", verb: "waitOnce" };
|
export const waitOnce: GeneratorNode = builtinNode("waitOnce");
|
||||||
export const pressKey: GeneratorNode = { kind: "builtin", verb: "pressKeys" };
|
export const pressKey: GeneratorNode = builtinNode("pressKeys");
|
||||||
Reference in new issue
Block a user