MCPcopy Index your code
hub / github.com/NativeScript/SimDeck / connect

Function connect

packages/simdeck-test/src/index.ts:223–714  ·  view source on GitHub ↗
(
  options: SimDeckLaunchOptions = {},
)

Source from the content-addressed store, hash-verified

221};
222
223export async function connect(
224 options: SimDeckLaunchOptions = {},
225): Promise<SimDeckSession> {
226 const cliPath = options.cliPath ?? "simdeck";
227 const result: ServiceConnection = options.isolated
228 ? await startIsolatedService(cliPath, options)
229 : runJson<ServiceStartResult>(cliPath, ["service", "start"], {
230 cwd: options.projectRoot,
231 });
232 const endpoint = result.url;
233 const createSession = (defaultUdid?: string): SimDeckSession => {
234 const simulatorPath = (udid: string, suffix: string) =>
235 `/api/simulators/${encodeURIComponent(udid)}${suffix}`;
236 const actionPath = (udid: string) => simulatorPath(udid, "/action");
237 const requestAction = <T = unknown>(udid: string, body: unknown) =>
238 requestJson<T>(endpoint, "POST", actionPath(udid), body);
239 const requestActionOk = (udid: string, body: unknown) =>
240 requestAction(udid, body).then(() => undefined);
241 const requireUdid = (udid?: string) => {
242 const resolved = udid ?? defaultUdid;
243 if (!resolved) {
244 throw new Error(
245 "This SimDeck session method requires a UDID. Pass one as the first argument or call connect({ udid }).",
246 );
247 }
248 return resolved;
249 };
250 const resolveNoArgDeviceCall = (args: unknown[]) => ({
251 udid: requireUdid(typeof args[0] === "string" ? args[0] : undefined),
252 });
253 const resolveStringArgDeviceCall = (args: unknown[]) => {
254 if (
255 args.length >= 2 &&
256 typeof args[0] === "string" &&
257 typeof args[1] === "string"
258 ) {
259 return { udid: args[0], value: args[1] as string, rest: args.slice(2) };
260 }
261 return {
262 udid: requireUdid(),
263 value: args[0] as string,
264 rest: args.slice(1),
265 };
266 };
267 const resolveObjectArgDeviceCall = <T>(args: unknown[]) => {
268 if (typeof args[0] === "string") {
269 return { udid: args[0], value: args[1] as T, rest: args.slice(2) };
270 }
271 return { udid: requireUdid(), value: args[0] as T, rest: args.slice(1) };
272 };
273 const resolveOptionalObjectDeviceCall = <T>(args: unknown[]) => {
274 if (typeof args[0] === "string") {
275 return { udid: args[0], options: args[1] as T | undefined };
276 }
277 return { udid: requireUdid(), options: args[0] as T | undefined };
278 };
279 const session: SimDeckSession = {
280 endpoint,

Callers 9

mainFunction · 0.90
mainFunction · 0.90
run_connectionMethod · 0.50
attach_websocket_innerFunction · 0.50
fetch_devtools_jsonFunction · 0.50
http_requestFunction · 0.50

Calls 3

startIsolatedServiceFunction · 0.85
createSessionFunction · 0.85
runJsonFunction · 0.70

Tested by

no test coverage detected