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

Function createSession

packages/simdeck-test/src/index.ts:233–712  ·  view source on GitHub ↗
(defaultUdid?: string)

Source from the content-addressed store, hash-verified

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,
281 pid: result.pid,
282 projectRoot: result.projectRoot,
283 udid: defaultUdid,
284 device: (udid: string) => createSession(udid),
285 list: () => requestJson(endpoint, "GET", "/api/simulators"),
286 boot: (...args: [] | [string]) => {
287 const { udid } = resolveNoArgDeviceCall(args);
288 return requestJson(
289 endpoint,
290 "POST",

Callers 1

connectFunction · 0.85

Calls 15

requestJsonFunction · 0.85
resolveNoArgDeviceCallFunction · 0.85
simulatorPathFunction · 0.85
requestOkFunction · 0.85
requestActionOkFunction · 0.85
requireUdidFunction · 0.85
selectorPayloadFunction · 0.85
withQueryDefaultsFunction · 0.85
requestActionFunction · 0.85

Tested by

no test coverage detected