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

easDeviceHostsSettings.logic.ts

35 lines1.2 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. */
20export function updateEasDeviceHosts(
21 hosts: ReadonlyArray<EasDeviceHostConfigType>,
22 host: EasDeviceHostConfigType,
23 remove: boolean,
24): ReadonlyArray<EasDeviceHostConfigType> {
25 if (remove) return hosts.filter((candidate) => candidate.id !== host.id);
26 return hosts.some((candidate) => candidate.id === host.id)
27 ? hosts.map((candidate) => (candidate.id === host.id ? host : candidate))
28 : [...hosts, host];
30​
31export function easSessionLimits(host: EasDeviceHostConfigType) {
32 const sessions =
33 host.maxConcurrentSessions === 1 ? "1 session" : `${host.maxConcurrentSessions} sessions`;
34 return `Up to ${sessions} at once, each stopped after ${host.maxSessionMinutes} min or ${host.idleMinutes} idle min`;