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

threadEnvMode.ts

36 lines1.4 KB

1import type { ThreadEnvMode } from "@t3tools/contracts";
2​
3/**
4 * Canonical priority order for a project's default thread env mode:
5 * per-project setting > checked-in t3.json > global server setting.
6 *
7 * An explicit composer pick outranks all of these; callers apply it before
8 * consulting the defaults. Web resolves the sources imperatively at draft
9 * creation, mobile reactively — both must route through this function so the
10 * platforms cannot disagree on the order.
11 */
12export function resolveDefaultThreadEnvMode(sources: {
13 readonly projectSetting: ThreadEnvMode | null | undefined;
14 readonly projectFile: ThreadEnvMode | null | undefined;
15 readonly globalDefault: ThreadEnvMode;
16}): ThreadEnvMode {
17 return sources.projectSetting ?? sources.projectFile ?? sources.globalDefault;
19​
20/**
21 * True once the resolved default can no longer change: an explicit pick or a
22 * source that outranks t3.json decided, or the file read settled. While
23 * false, nothing may persist the provisional default (for example into a
24 * draft's workspace selection) — it could differ from the final value.
25 */
26export function isDefaultThreadEnvModeSettled(sources: {
27 readonly explicitMode: ThreadEnvMode | undefined;
28 readonly projectSetting: ThreadEnvMode | null | undefined;
29 readonly projectFilePending: boolean;
30}): boolean {
31 return (
32 sources.explicitMode !== undefined ||
33 sources.projectSetting != null ||
34 !sources.projectFilePending
35 );