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

device.ts

72 lines2.2 KB

1import { WS_METHODS } from "@t3tools/contracts";
2import { Atom } from "effect/unstable/reactivity";
3​
4import type { EnvironmentRegistry } from "../connection/registry.ts";
5import {
6 createAtomCommandScheduler,
7 createEnvironmentRpcCommand,
8 createEnvironmentRpcSubscriptionAtomFamily,
9} from "./runtime.ts";
10​
11export function createDeviceEnvironmentAtoms<R, E>(
12 runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
13) {
14 const scheduler = createAtomCommandScheduler();
15 const concurrency = {
16 mode: "serial" as const,
17 key: ({ environmentId }: { environmentId: string }) => environmentId,
18 };
19 return {
20 /** Server-pushed device hosts, devices, and open sessions for one environment. */
21 state: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
22 label: "environment-data:device:state",
23 tag: WS_METHODS.subscribeDeviceState,
24 }),
25 configure: createEnvironmentRpcCommand(runtime, {
26 label: "environment-data:device:configure",
27 tag: WS_METHODS.deviceConfigure,
28 scheduler,
29 concurrency,
30 }),
31 testHost: createEnvironmentRpcCommand(runtime, {
32 label: "environment-data:device:test-host",
33 tag: WS_METHODS.deviceTestHost,
34 }),
35 list: createEnvironmentRpcCommand(runtime, {
36 label: "environment-data:device:list",
37 tag: WS_METHODS.deviceList,
38 scheduler,
39 concurrency,
40 }),
41 open: createEnvironmentRpcCommand(runtime, {
42 label: "environment-data:device:open",
43 tag: WS_METHODS.deviceOpen,
44 scheduler,
45 concurrency,
46 }),
47 close: createEnvironmentRpcCommand(runtime, {
48 label: "environment-data:device:close",
49 tag: WS_METHODS.deviceClose,
50 scheduler,
51 concurrency,
52 }),
53 shutdown: createEnvironmentRpcCommand(runtime, {
54 label: "environment-data:device:shutdown",
55 tag: WS_METHODS.deviceShutdown,
56 scheduler,
57 concurrency,
58 }),
59 detail: createEnvironmentRpcCommand(runtime, {
60 label: "environment-data:device:detail",
61 tag: WS_METHODS.deviceDetail,
62 scheduler,
63 concurrency,
64 }),
65 action: createEnvironmentRpcCommand(runtime, {
66 label: "environment-data:device:action",
67 tag: WS_METHODS.deviceAction,
68 scheduler,
69 concurrency,
70 }),
71 };