@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 150 lines 5.63 KB
Raw
1 import type { NamespaceNode } from "../Namespace.ts";
2 import type { ProviderMode } from "../ProviderMode.ts";
3 import type { RemovalPolicy } from "../RemovalPolicy.ts";
4 import type { ResourceBinding } from "../Resource.ts";
5
6 export type ResourceState =
7 | CreatingResourceState
8 | CreatedResourceState
9 | UpdatingReourceState
10 | UpdatedResourceState
11 | DeletingResourceState
12 | ReplacingResourceState
13 | ReplacedResourceState;
14
15 export type Props = Record<string, any>;
16 export type Attr = Record<string, any>;
17
18 export type ResourceStatus = ResourceState["status"];
19 export type ReplacementResourceState = ReplacingResourceState | ReplacedResourceState;
20 export type ReplacementOldResourceState =
21 | CreatingResourceState
22 | CreatedResourceState
23 | UpdatingReourceState
24 | UpdatedResourceState
25 | DeletingResourceState
26 | ReplacementResourceState;
27
28 interface BaseResourceState {
29 /**
30 * Discriminator vs {@link ActionState}. Optional for back-compat: legacy
31 * persisted rows have no `kind` field and are implicitly resources.
32 */
33 readonly kind?: "resource";
34 /** Type of the Resource (e.g. AWS.Lambda.Function) */
35 resourceType: string;
36 /** Namespace of the Resource */
37 namespace: NamespaceNode | undefined;
38 /** Fully Qualified Name (namespace path + logical ID) */
39 fqn: string;
40 /** Logical ID of the Resource (stable across creates, updates, deletes and replaces) */
41 logicalId: string;
42 /** A unique randomly generated token used to seed ID generation (only changes when replaced) */
43 instanceId: string;
44 /** The version of the provider that was used to create/update the resource. */
45 providerVersion: number;
46 /** Current status of the logical Resource */
47 status: ResourceStatus;
48 /** List of FQNs of resources that depend on this resource */
49 downstream: string[];
50 /** List of Bindings attached to this Resource */
51 bindings: ResourceBinding[];
52 /** Desired state (input props) of this Resource */
53 props?: Props;
54 /** The output attributes of this Resource (if it has been created) */
55 attr?: Attr | undefined;
56 /** The removal policy of the resource */
57 removalPolicy?: RemovalPolicy["Service"];
58 /** Attr-less lookup could recover the predecessor migrated away from this FQN. */
59 adoptionBlocked?: "migrated-fqn";
60 /** Unresolved props were stripped from this attr-less checkpoint; they cannot identify it. */
61 propsIncomplete?: true;
62 /**
63 * The {@link ProviderMode} this resource was last reconciled with.
64 *
65 * Stamped by Apply on every commit for resources whose provider
66 * distinguishes modes (`ProviderLayer.dual`). Plan treats a mismatch
67 * between the persisted mode and the resolved desired mode as a
68 * **replacement**, and deletion always uses the provider variant of the
69 * mode that created the row.
70 *
71 * `undefined` means either a mode-agnostic provider (single
72 * implementation serves both dev and deploy) or a legacy row written
73 * before modes were persisted — both acted on the real cloud, so an
74 * unstamped row is assumed **live**, unless its attrs carry a local
75 * identity marker (`dev:`-prefixed ids) proving it was reconciled
76 * locally, in which case it is assumed **local** (see `stampedMode`).
77 * Same-mode runs see no churn; a run in the other mode replaces it like
78 * any stamped row.
79 */
80 providerMode?: ProviderMode;
81 }
82
83 export interface CreatingResourceState extends BaseResourceState {
84 status: "creating";
85 /** The new resource properties that are being (or have been) applied. */
86 props: Props;
87 }
88
89 export interface CreatedResourceState extends BaseResourceState {
90 status: "created";
91 /** The new resource properties that have been applied. */
92 props: Props;
93 /** The output attributes of the created resource */
94 attr: Attr;
95 }
96
97 export interface UpdatingReourceState extends BaseResourceState {
98 status: "updating";
99 /** Persisted until the first post-adoption reconcile succeeds. */
100 adopting?: true;
101 /** The new resource properties that are being (or have been) applied. */
102 props: Props;
103 old: {
104 /** The old resource properties that have been successfully applied. */
105 props: Props;
106 /** List of Bindings attached to this Resource */
107 bindings: any[];
108 /** The old output properties that have been successfully applied. */
109 attr: Attr;
110 // TODO(sam): do I need to track the old downstream edges?
111 // downstream: string[];
112 };
113 }
114
115 export interface UpdatedResourceState extends BaseResourceState {
116 status: "updated";
117 /** The new resource properties that are being (or have been) applied. */
118 props: Props;
119 /** The output attributes of the created resource */
120 attr: Attr;
121 }
122
123 export interface DeletingResourceState extends BaseResourceState {
124 status: "deleting";
125 /** Attributes of the resource being deleted */
126 attr: Attr | undefined;
127 }
128
129 export interface ReplacingResourceState extends BaseResourceState {
130 status: "replacing";
131 /** Desired properties of the new resource (the replacement) */
132 props: Props;
133 /** Reference to the state of the old resource (the one being replaced) */
134 old: ReplacementOldResourceState;
135 /** Whether the resource should be deleted before or after replacements */
136 deleteFirst: boolean;
137 }
138
139 export interface ReplacedResourceState extends BaseResourceState {
140 status: "replaced";
141 /** Desired properties of the new resource (the replacement) */
142 props: Props;
143 /** Output attributes of the new resource (the replacement) */
144 attr: Attr;
145 /** Reference to the state of the old resource (the one being replaced) */
146 old: ReplacementOldResourceState;
147 /** Whether the resource should be deleted before or after replacements */
148 deleteFirst: boolean;
149 // .. will (finally) transition to `CreatedResourceState` after finalizing
150 }