Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

easDeviceHostsSettings.logic.ts

42 lines1.6 KB

1import {
2 EasDeviceHostConfig,
3 type EasDeviceHostConfig as EasDeviceHostConfigType,
4} from "@t3tools/contracts";
5import * as Schema from "effect/Schema";
6​
7export const parseEasDeviceHostDraft = Schema.decodeUnknownOption(EasDeviceHostConfig);
8​
9export const newEasDeviceHost = (id: string): EasDeviceHostConfigType => ({
10 kind: "eas",
11 id,
12 label: "EAS Simulator",
13 accessToken: "",
14 maxSessionMinutes: 30,
15 idleMinutes: 10,
16 maxConcurrentSessions: 2,
17});
18​
19/** Adds, replaces, or removes one EAS host. */
20/**
21 * With `keepToken`, the environment keeps the token it holds: a saved token arrives redacted, and
22 * one environment's token says nothing about another's. One new to the host uses its own Expo login.
23 */
24export function updateEasDeviceHosts(
25 hosts: ReadonlyArray<EasDeviceHostConfigType>,
26 host: EasDeviceHostConfigType,
27 remove: boolean,
28 keepToken = false,
29): ReadonlyArray<EasDeviceHostConfigType> {
30 if (remove) return hosts.filter((candidate) => candidate.id !== host.id);
31 const existing = hosts.find((candidate) => candidate.id === host.id);
32 const next = keepToken ? { ...host, accessToken: existing?.accessToken ?? "" } : host;
33 return existing
34 ? hosts.map((candidate) => (candidate.id === host.id ? next : candidate))
35 : [...hosts, next];
37​
38export function easSessionLimits(host: EasDeviceHostConfigType) {
39 const sessions =
40 host.maxConcurrentSessions === 1 ? "1 session" : `${host.maxConcurrentSessions} sessions`;
41 return `Up to ${sessions} at once, each stopped after ${host.maxSessionMinutes} min or ${host.idleMinutes} idle min`;