Repository navigation
Expand file tree
/
Copy pathkeyboard-runtime.ts
More file actions
121 lines (111 loc) · 5.22 KB
/
Copy pathkeyboard-runtime.ts
File metadata and controls
121 lines (111 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import type {
Interactor,
KeyboardDismissResult,
KeyboardEnterResult,
KeyboardStatusResult,
RunnerContext,
} from './interactor-types.ts';
import type { RuntimeOperationFact, RuntimeOperationUnavailability } from './platform-runtime.ts';
import type { SnapshotRuntimeExecution } from './snapshot-runtime.ts';
export type { KeyboardDismissResult, KeyboardEnterResult, KeyboardStatusResult };
/**
* Neutral intent for one keyboard probe/action. Every keyboard operation takes the same shape —
* runner metadata only, no arguments — so one input type covers all three; the action itself is
* which operation the caller invokes, decided by the daemon's action-selected bind (ADR 0019 §9),
* never by an argument threaded through here.
*/
export type KeyboardActionInput = Readonly<{
options?: Readonly<{ appBundleId?: string }>;
/** Same runner metadata a capture needs; reuses that type rather than restating it. */
execution?: SnapshotRuntimeExecution;
}>;
export type KeyboardStatusRuntimeOperations = Readonly<{
keyboardStatus(input: KeyboardActionInput): Promise<KeyboardStatusResult>;
}>;
export type KeyboardDismissRuntimeOperations = Readonly<{
keyboardDismiss(input: KeyboardActionInput): Promise<KeyboardDismissResult>;
}>;
export type KeyboardEnterRuntimeOperations = Readonly<{
keyboardEnter(input: KeyboardActionInput): Promise<KeyboardEnterResult>;
}>;
export type KeyboardRuntimeOperations = KeyboardStatusRuntimeOperations &
KeyboardDismissRuntimeOperations &
KeyboardEnterRuntimeOperations;
export type KeyboardRuntimeOperationFacts = Readonly<{
keyboardStatus: RuntimeOperationFact;
keyboardDismiss: RuntimeOperationFact;
keyboardEnter: RuntimeOperationFact;
}>;
/**
* What an owner declares about the keyboard family. No operation here is one every owner serves,
* and several owners serve no keyboard operation at all, so every operation is optional and
* `unsupported` names the denial an omitted cell reports. An owner with no keyboard surface states
* that denial once instead of writing it out per operation, with the reason and hint it would
* otherwise repeat by hand.
*
* Omission is a classified denial, never an unclassified cell and never an implied success: the
* type refuses a call that does not carry `unsupported`, so no owner can leave the family blank.
* An owner that serves one operation names it — omission means "refuses", never "the same as the
* neighbour" — and its `unsupported` must refuse the family, not one operation of it, because
* whatever the owner leaves unnamed reports that cell verbatim.
*/
export type KeyboardRuntimeOperationFactsInput = Readonly<{
unsupported: RuntimeOperationUnavailability;
status?: RuntimeOperationFact;
dismiss?: RuntimeOperationFact;
enter?: RuntimeOperationFact;
}>;
export function keyboardRuntimeOperationFacts(
input: KeyboardRuntimeOperationFactsInput,
): KeyboardRuntimeOperationFacts {
const declared = (fact: RuntimeOperationFact | undefined): RuntimeOperationFact =>
fact ?? input.unsupported;
return Object.freeze({
keyboardStatus: declared(input.status),
keyboardDismiss: declared(input.dismiss),
keyboardEnter: declared(input.enter),
});
}
/**
* Captures one selected owner's interactor authority for the lifetime of a request binding. The
* owner is already chosen by the time a binder is called, so each entry point supplies its own
* resolution and this holds only what all three actions share: the runner context resolution.
*/
async function resolveKeyboardInteractor(
signal: AbortSignal,
resolveInteractor: (runner: RunnerContext) => Promise<Interactor>,
input: KeyboardActionInput,
): Promise<Interactor> {
signal.throwIfAborted();
return await resolveInteractor({
...input.execution,
appBundleId: input.options?.appBundleId,
signal,
});
}
export const KEYBOARD_ACTION_LABELS = {
keyboardStatus: 'keyboard status',
keyboardDismiss: 'keyboard dismiss',
keyboardEnter: 'keyboard enter',
} as const satisfies Record<keyof KeyboardRuntimeOperations, string>;
/**
* Binds whichever keyboard action `key` names against one resolved interactor. The three actions
* differ only by which `Interactor` method they call and what it returns — both read off `key`
* itself, so one generic body replaces three copies that differed by nothing else.
*/
export function bindKeyboardAction<Key extends keyof KeyboardRuntimeOperations>(
key: Key,
signal: AbortSignal,
resolveInteractor: (runner: RunnerContext) => Promise<Interactor>,
): Pick<KeyboardRuntimeOperations, Key> {
const action = async (input: KeyboardActionInput) => {
const interactor = await resolveKeyboardInteractor(signal, resolveInteractor, input);
// The guard every optional-member binder shares. Loaded on the call rather than at module
// evaluation because this facade's eager closure is held at its merge-base size
// (`eager-closure-budgets`); a static edge would grow it by one module.
const { requireInteractorMethod } = await import('./interactor-operation-binding.ts');
const method = requireInteractorMethod(interactor[key], KEYBOARD_ACTION_LABELS[key]);
return await (method as () => Promise<unknown>).call(interactor);
};
return Object.freeze({ [key]: action }) as Pick<KeyboardRuntimeOperations, Key>;
}