-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathclient-command-metadata.ts
More file actions
238 lines (235 loc) · 8.13 KB
/
client-command-metadata.ts
File metadata and controls
238 lines (235 loc) · 8.13 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import type { MetroPrepareOptions, RecordOptions } from '../client-types.ts';
import type { DaemonInstallSource } from '../contracts.ts';
import { requireCommandDescription } from './command-descriptions.ts';
import {
booleanField,
booleanSchema,
enumField,
integerField,
integerSchema,
jsonSchemaField,
looseObjectField,
looseObjectSchema,
numberField,
requiredField,
stringArrayField,
stringField,
stringSchema,
type CommandFieldMap,
} from './command-input.ts';
import { defineFieldCommandMetadata } from './field-command-contract.ts';
const SURFACE_VALUES = ['app', 'frontmost-app', 'desktop', 'menubar'] as const;
const WAIT_KIND_VALUES = ['duration', 'text', 'ref', 'selector'] as const;
const ALERT_ACTION_VALUES = ['get', 'accept', 'dismiss', 'wait'] as const;
const BACK_MODE_VALUES = ['in-app', 'system'] as const;
const ORIENTATION_VALUES = [
'portrait',
'portrait-upside-down',
'landscape-left',
'landscape-right',
] as const;
const CLIPBOARD_ACTION_VALUES = ['read', 'write'] as const;
const LOG_ACTION_VALUES = ['path', 'start', 'stop', 'doctor', 'mark', 'clear'] as const;
const NETWORK_ACTION_VALUES = ['dump', 'log'] as const;
const NETWORK_INCLUDE_VALUES = ['summary', 'headers', 'body', 'all'] as const;
const START_STOP_VALUES = ['start', 'stop'] as const;
const REACT_NATIVE_ACTION_VALUES = ['dismiss-overlay'] as const;
const METRO_ACTION_VALUES = ['prepare', 'reload'] as const;
export const clientCommandMetadata = [
defineClientCommandMetadata('devices', {}),
defineClientCommandMetadata('boot', {
headless: booleanField('Boot without showing simulator UI when supported.'),
}),
defineClientCommandMetadata('apps', {
appsFilter: enumField(['user-installed', 'all']),
}),
defineClientCommandMetadata('session', {
action: enumField(['list']),
}),
defineClientCommandMetadata('open', {
app: stringField('App name, bundle id, package, or URL.'),
url: stringField('Optional URL passed with an app shell.'),
surface: enumField(SURFACE_VALUES),
activity: stringField('Android activity name.'),
launchConsole: stringField('Launch console mode.'),
launchArgs: stringArrayField(
'Launch arguments forwarded verbatim to the platform launch command.',
),
relaunch: booleanField('Force relaunch.'),
saveScript: jsonSchemaField<boolean | string>({ oneOf: [booleanSchema(), stringSchema()] }),
noRecord: booleanField('Do not record this action.'),
}),
defineClientCommandMetadata('close', {
app: stringField('Optional app to close.'),
shutdown: booleanField('Shutdown the session/device where supported.'),
saveScript: jsonSchemaField<boolean | string>({ oneOf: [booleanSchema(), stringSchema()] }),
}),
defineClientCommandMetadata('install', {
app: requiredField(stringField()),
appPath: requiredField(stringField('Path to app binary.')),
}),
defineClientCommandMetadata('reinstall', {
app: requiredField(stringField()),
appPath: requiredField(stringField('Path to app binary.')),
}),
defineClientCommandMetadata('install-from-source', {
source: requiredField(
jsonSchemaField<DaemonInstallSource>(looseObjectSchema('Install source object.')),
),
retainPaths: booleanField(),
retentionMs: integerField(),
}),
defineClientCommandMetadata('push', {
app: requiredField(stringField()),
payload: requiredField(
jsonSchemaField<string | Record<string, unknown>>({
oneOf: [stringSchema(), looseObjectSchema()],
}),
),
}),
defineClientCommandMetadata('trigger-app-event', {
event: requiredField(stringField()),
payload: looseObjectField(),
}),
defineClientCommandMetadata('snapshot', {
interactiveOnly: booleanField(),
compact: booleanField(),
depth: integerField(),
scope: stringField(),
raw: booleanField(),
forceFull: booleanField(),
}),
defineClientCommandMetadata('screenshot', {
path: stringField('Output path.'),
overlayRefs: booleanField(),
fullscreen: booleanField(),
maxSize: integerField(),
stabilize: booleanField(),
surface: enumField(SURFACE_VALUES),
}),
defineClientCommandMetadata('diff', {
kind: requiredField(jsonSchemaField<'snapshot'>({ type: 'string', const: 'snapshot' })),
out: stringField(),
interactiveOnly: booleanField(),
compact: booleanField(),
depth: integerField(),
scope: stringField(),
raw: booleanField(),
}),
defineClientCommandMetadata('wait', {
kind: enumField(WAIT_KIND_VALUES),
durationMs: integerField(),
text: stringField(),
ref: stringField(),
selector: stringField(),
timeoutMs: integerField(),
depth: integerField(),
scope: stringField(),
raw: booleanField(),
}),
defineClientCommandMetadata('alert', {
action: enumField(ALERT_ACTION_VALUES),
timeoutMs: integerField(),
}),
defineClientCommandMetadata('appstate', {}),
defineClientCommandMetadata('back', {
mode: enumField(BACK_MODE_VALUES),
}),
defineClientCommandMetadata('home', {}),
defineClientCommandMetadata('rotate', {
orientation: requiredField(enumField(ORIENTATION_VALUES)),
}),
defineClientCommandMetadata('app-switcher', {}),
defineClientCommandMetadata('keyboard', {
action: enumField(['status', 'dismiss']),
}),
defineClientCommandMetadata('clipboard', {
action: requiredField(enumField(CLIPBOARD_ACTION_VALUES)),
text: stringField(),
}),
defineClientCommandMetadata('react-native', {
action: requiredField(enumField(REACT_NATIVE_ACTION_VALUES)),
}),
defineClientCommandMetadata('replay', {
path: requiredField(stringField()),
update: booleanField(),
backend: stringField(),
maestro: booleanField(),
env: stringArrayField(),
}),
defineClientCommandMetadata('test', {
paths: requiredField(stringArrayField()),
update: booleanField(),
backend: stringField(),
maestro: booleanField(),
env: stringArrayField(),
failFast: booleanField(),
timeoutMs: integerField(),
retries: integerField(),
artifactsDir: stringField(),
reportJunit: stringField(),
}),
defineClientCommandMetadata('perf', {}),
defineClientCommandMetadata('logs', {
action: enumField(LOG_ACTION_VALUES),
message: stringField(),
restart: booleanField(),
}),
defineClientCommandMetadata('network', {
action: enumField(NETWORK_ACTION_VALUES),
limit: integerField(),
include: enumField(NETWORK_INCLUDE_VALUES),
}),
defineClientCommandMetadata('record', {
action: requiredField(enumField(START_STOP_VALUES)),
path: stringField(),
fps: integerField(),
quality: jsonSchemaField<RecordOptions['quality']>(integerSchema()),
hideTouches: booleanField(),
}),
defineClientCommandMetadata('trace', {
action: requiredField(enumField(START_STOP_VALUES)),
path: stringField(),
}),
defineClientCommandMetadata('settings', {
setting: requiredField(stringField()),
state: requiredField(stringField()),
app: stringField(),
latitude: numberField(),
longitude: numberField(),
permission: stringField(),
mode: enumField(['full', 'limited']),
}),
defineClientCommandMetadata('metro', {
action: requiredField(enumField(METRO_ACTION_VALUES)),
projectRoot: stringField(),
kind: jsonSchemaField<MetroPrepareOptions['kind']>(stringSchema()),
publicBaseUrl: stringField(),
proxyBaseUrl: stringField(),
bearerToken: stringField(),
bridgeScope: jsonSchemaField<MetroPrepareOptions['bridgeScope']>({
type: 'object',
additionalProperties: true,
}),
launchUrl: stringField(),
port: integerField(),
listenHost: stringField(),
statusHost: stringField(),
startupTimeoutMs: integerField(),
probeTimeoutMs: integerField(),
reuseExisting: booleanField(),
installDependenciesIfNeeded: booleanField(),
runtimeFilePath: stringField(),
logPath: stringField(),
metroHost: stringField(),
metroPort: integerField(),
bundleUrl: stringField(),
timeoutMs: integerField(),
}),
] as const;
function defineClientCommandMetadata<
const TName extends string,
const TFields extends CommandFieldMap,
>(name: TName, fields: TFields) {
return defineFieldCommandMetadata(name, requireCommandDescription(name), fields);
}