@creact-labs/creact 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +212 -0
- package/README.md +379 -0
- package/dist/cli/commands/BuildCommand.d.ts +40 -0
- package/dist/cli/commands/BuildCommand.js +151 -0
- package/dist/cli/commands/DeployCommand.d.ts +38 -0
- package/dist/cli/commands/DeployCommand.js +194 -0
- package/dist/cli/commands/DevCommand.d.ts +52 -0
- package/dist/cli/commands/DevCommand.js +385 -0
- package/dist/cli/commands/PlanCommand.d.ts +39 -0
- package/dist/cli/commands/PlanCommand.js +164 -0
- package/dist/cli/commands/index.d.ts +36 -0
- package/dist/cli/commands/index.js +43 -0
- package/dist/cli/core/ArgumentParser.d.ts +46 -0
- package/dist/cli/core/ArgumentParser.js +127 -0
- package/dist/cli/core/BaseCommand.d.ts +75 -0
- package/dist/cli/core/BaseCommand.js +95 -0
- package/dist/cli/core/CLIContext.d.ts +68 -0
- package/dist/cli/core/CLIContext.js +183 -0
- package/dist/cli/core/CommandRegistry.d.ts +64 -0
- package/dist/cli/core/CommandRegistry.js +89 -0
- package/dist/cli/core/index.d.ts +36 -0
- package/dist/cli/core/index.js +43 -0
- package/dist/cli/index.d.ts +35 -0
- package/dist/cli/index.js +100 -0
- package/dist/cli/output.d.ts +204 -0
- package/dist/cli/output.js +437 -0
- package/dist/cli/utils.d.ts +59 -0
- package/dist/cli/utils.js +76 -0
- package/dist/context/createContext.d.ts +90 -0
- package/dist/context/createContext.js +113 -0
- package/dist/context/index.d.ts +30 -0
- package/dist/context/index.js +35 -0
- package/dist/core/CReact.d.ts +409 -0
- package/dist/core/CReact.js +1127 -0
- package/dist/core/CloudDOMBuilder.d.ts +429 -0
- package/dist/core/CloudDOMBuilder.js +1198 -0
- package/dist/core/ContextDependencyTracker.d.ts +165 -0
- package/dist/core/ContextDependencyTracker.js +448 -0
- package/dist/core/ErrorRecoveryManager.d.ts +145 -0
- package/dist/core/ErrorRecoveryManager.js +443 -0
- package/dist/core/EventBus.d.ts +91 -0
- package/dist/core/EventBus.js +185 -0
- package/dist/core/ProviderOutputTracker.d.ts +211 -0
- package/dist/core/ProviderOutputTracker.js +476 -0
- package/dist/core/ReactiveUpdateQueue.d.ts +76 -0
- package/dist/core/ReactiveUpdateQueue.js +121 -0
- package/dist/core/Reconciler.d.ts +415 -0
- package/dist/core/Reconciler.js +1037 -0
- package/dist/core/RenderScheduler.d.ts +153 -0
- package/dist/core/RenderScheduler.js +519 -0
- package/dist/core/Renderer.d.ts +276 -0
- package/dist/core/Renderer.js +791 -0
- package/dist/core/Runtime.d.ts +246 -0
- package/dist/core/Runtime.js +640 -0
- package/dist/core/StateBindingManager.d.ts +121 -0
- package/dist/core/StateBindingManager.js +309 -0
- package/dist/core/StateMachine.d.ts +424 -0
- package/dist/core/StateMachine.js +787 -0
- package/dist/core/StructuralChangeDetector.d.ts +140 -0
- package/dist/core/StructuralChangeDetector.js +363 -0
- package/dist/core/Validator.d.ts +127 -0
- package/dist/core/Validator.js +279 -0
- package/dist/core/errors.d.ts +153 -0
- package/dist/core/errors.js +202 -0
- package/dist/core/index.d.ts +38 -0
- package/dist/core/index.js +64 -0
- package/dist/core/types.d.ts +263 -0
- package/dist/core/types.js +48 -0
- package/dist/hooks/context.d.ts +147 -0
- package/dist/hooks/context.js +334 -0
- package/dist/hooks/useContext.d.ts +113 -0
- package/dist/hooks/useContext.js +169 -0
- package/dist/hooks/useEffect.d.ts +105 -0
- package/dist/hooks/useEffect.js +540 -0
- package/dist/hooks/useInstance.d.ts +139 -0
- package/dist/hooks/useInstance.js +441 -0
- package/dist/hooks/useState.d.ts +120 -0
- package/dist/hooks/useState.js +298 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +70 -0
- package/dist/jsx.d.ts +64 -0
- package/dist/jsx.js +76 -0
- package/dist/providers/DummyBackendProvider.d.ts +193 -0
- package/dist/providers/DummyBackendProvider.js +189 -0
- package/dist/providers/DummyCloudProvider.d.ts +128 -0
- package/dist/providers/DummyCloudProvider.js +157 -0
- package/dist/providers/IBackendProvider.d.ts +177 -0
- package/dist/providers/IBackendProvider.js +31 -0
- package/dist/providers/ICloudProvider.d.ts +146 -0
- package/dist/providers/ICloudProvider.js +31 -0
- package/dist/providers/index.d.ts +31 -0
- package/dist/providers/index.js +31 -0
- package/dist/test-event-callbacks.d.ts +0 -0
- package/dist/test-event-callbacks.js +1 -0
- package/dist/utils/Logger.d.ts +144 -0
- package/dist/utils/Logger.js +220 -0
- package/dist/utils/Output.d.ts +161 -0
- package/dist/utils/Output.js +401 -0
- package/dist/utils/deepEqual.d.ts +71 -0
- package/dist/utils/deepEqual.js +276 -0
- package/dist/utils/naming.d.ts +241 -0
- package/dist/utils/naming.js +376 -0
- package/package.json +87 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
/**
|
|
2
|
+
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
*
|
|
10
|
+
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
*
|
|
14
|
+
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
|
|
25
|
+
*
|
|
26
|
+
|
|
27
|
+
* Copyright 2025 Daniel Coutinho Ribeiro
|
|
28
|
+
|
|
29
|
+
*/
|
|
30
|
+
import { CloudDOMNode, ChangeSet } from './types';
|
|
31
|
+
import { IBackendProvider } from '../providers/IBackendProvider';
|
|
32
|
+
import { DeploymentError, DeploymentErrorData } from './errors';
|
|
33
|
+
/**
|
|
34
|
+
* DeploymentStatus represents the lifecycle state of a deployment
|
|
35
|
+
*
|
|
36
|
+
* State transitions:
|
|
37
|
+
* - PENDING → APPLYING (deployment starts)
|
|
38
|
+
* - APPLYING → DEPLOYED (deployment succeeds)
|
|
39
|
+
* - APPLYING → FAILED (deployment fails)
|
|
40
|
+
* - APPLYING → ROLLED_BACK (rollback completes)
|
|
41
|
+
*
|
|
42
|
+
* REQ-O01: State machine with crash recovery
|
|
43
|
+
*/
|
|
44
|
+
export type DeploymentStatus = 'PENDING' | 'APPLYING' | 'DEPLOYED' | 'FAILED' | 'ROLLED_BACK';
|
|
45
|
+
/**
|
|
46
|
+
* StateMachineEvent represents events emitted by the state machine
|
|
47
|
+
*
|
|
48
|
+
* Used for observability and telemetry integration.
|
|
49
|
+
*/
|
|
50
|
+
export type StateMachineEvent = 'started' | 'checkpoint' | 'completed' | 'failed' | 'rolled_back';
|
|
51
|
+
/**
|
|
52
|
+
* AuditLogEntry represents an audit trail entry for state changes
|
|
53
|
+
*
|
|
54
|
+
* REQ-O05: Audit log for compliance and debugging
|
|
55
|
+
*/
|
|
56
|
+
export interface AuditLogEntry {
|
|
57
|
+
/** Timestamp when action occurred (milliseconds since epoch) */
|
|
58
|
+
timestamp: number;
|
|
59
|
+
/** User who initiated the action */
|
|
60
|
+
user: string;
|
|
61
|
+
/** Action performed */
|
|
62
|
+
action: 'start' | 'checkpoint' | 'complete' | 'fail' | 'rollback';
|
|
63
|
+
/** Stack name */
|
|
64
|
+
stackName: string;
|
|
65
|
+
/** Status of the action */
|
|
66
|
+
status: 'completed' | 'failed';
|
|
67
|
+
/** Error message if action failed */
|
|
68
|
+
error?: string;
|
|
69
|
+
/** Change set being applied (optional) */
|
|
70
|
+
changeSet?: ChangeSet;
|
|
71
|
+
/** Checkpoint index (optional) */
|
|
72
|
+
checkpoint?: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* DeploymentState represents the complete state of a deployment transaction
|
|
76
|
+
*
|
|
77
|
+
* Stored in BackendProvider for crash recovery and audit trail.
|
|
78
|
+
*
|
|
79
|
+
* REQ-O01: Transactional deployment with checkpoints
|
|
80
|
+
*/
|
|
81
|
+
export interface DeploymentState {
|
|
82
|
+
/** Current deployment status */
|
|
83
|
+
status: DeploymentStatus;
|
|
84
|
+
/** CloudDOM tree being deployed */
|
|
85
|
+
cloudDOM: CloudDOMNode[];
|
|
86
|
+
/** Change set computed by Reconciler (optional, only during deployment) */
|
|
87
|
+
changeSet?: ChangeSet;
|
|
88
|
+
/** Index of last successfully deployed resource (for crash recovery) */
|
|
89
|
+
checkpoint?: number;
|
|
90
|
+
/** Structured error data (if status is FAILED) */
|
|
91
|
+
error?: DeploymentErrorData;
|
|
92
|
+
/** Timestamp when state was last updated (milliseconds since epoch) */
|
|
93
|
+
timestamp: number;
|
|
94
|
+
/** User who initiated the deployment */
|
|
95
|
+
user: string;
|
|
96
|
+
/** Stack name for this deployment */
|
|
97
|
+
stackName: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* StateMachineEventPayload wraps state with event metadata
|
|
101
|
+
*
|
|
102
|
+
* Used for telemetry, metrics, and structured logging.
|
|
103
|
+
*/
|
|
104
|
+
export interface StateMachineEventPayload {
|
|
105
|
+
/** Event type */
|
|
106
|
+
event: StateMachineEvent;
|
|
107
|
+
/** Current deployment state */
|
|
108
|
+
state: DeploymentState;
|
|
109
|
+
/** Additional metadata (optional) */
|
|
110
|
+
metadata?: Record<string, any>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* StateMachine manages deployment lifecycle with crash recovery
|
|
114
|
+
*
|
|
115
|
+
* Responsibilities:
|
|
116
|
+
* - Track deployment state transitions
|
|
117
|
+
* - Save checkpoints after each resource deploys
|
|
118
|
+
* - Enable crash recovery (resume or rollback)
|
|
119
|
+
* - Provide atomic state persistence via BackendProvider
|
|
120
|
+
* - Prevent concurrent deployments via locking (REQ-O02)
|
|
121
|
+
* - Emit audit trail for compliance (REQ-O05)
|
|
122
|
+
* - Retry transient backend failures (REQ-O03)
|
|
123
|
+
*
|
|
124
|
+
* Design principles:
|
|
125
|
+
* - All state changes are atomic (saved to BackendProvider immediately)
|
|
126
|
+
* - Checkpoints enable resume from any point
|
|
127
|
+
* - Rollback applies reverse change set
|
|
128
|
+
* - State machine is universal (works with all providers)
|
|
129
|
+
* - Locking prevents race conditions
|
|
130
|
+
* - Audit trail provides compliance and debugging
|
|
131
|
+
*
|
|
132
|
+
* REQ-O01: CloudDOM State Machine
|
|
133
|
+
* REQ-O02: State Locking
|
|
134
|
+
* REQ-O03: Retry Logic
|
|
135
|
+
* REQ-O05: Audit Log
|
|
136
|
+
* REQ-ARCH-01: Provider-Orchestration Separation
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* const stateMachine = new StateMachine(backendProvider);
|
|
141
|
+
*
|
|
142
|
+
* // Listen to events
|
|
143
|
+
* stateMachine.on('checkpoint', (state) => {
|
|
144
|
+
* logger.info(`Checkpoint: ${state.checkpoint}`);
|
|
145
|
+
* });
|
|
146
|
+
*
|
|
147
|
+
* // Start deployment (acquires lock)
|
|
148
|
+
* await stateMachine.startDeployment('my-stack', changeSet, cloudDOM, 'user@example.com');
|
|
149
|
+
*
|
|
150
|
+
* // Update checkpoint after each resource
|
|
151
|
+
* await stateMachine.updateCheckpoint('my-stack', 0);
|
|
152
|
+
* await stateMachine.updateCheckpoint('my-stack', 1);
|
|
153
|
+
*
|
|
154
|
+
* // Complete deployment (releases lock)
|
|
155
|
+
* await stateMachine.completeDeployment('my-stack');
|
|
156
|
+
*
|
|
157
|
+
* // Or handle failure (releases lock)
|
|
158
|
+
* await stateMachine.failDeployment('my-stack', new DeploymentError('Provider timeout'));
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export declare class StateMachine {
|
|
162
|
+
private backendProvider;
|
|
163
|
+
private options;
|
|
164
|
+
private listeners;
|
|
165
|
+
/**
|
|
166
|
+
* Map of active lock renewal timers by stack name
|
|
167
|
+
* Used to clean up timers when deployment completes
|
|
168
|
+
*/
|
|
169
|
+
private lockRenewalTimers;
|
|
170
|
+
/**
|
|
171
|
+
* Valid state transitions
|
|
172
|
+
*
|
|
173
|
+
* Defines allowed transitions for state machine validation.
|
|
174
|
+
*/
|
|
175
|
+
private static readonly VALID_TRANSITIONS;
|
|
176
|
+
constructor(backendProvider: IBackendProvider<DeploymentState>, options?: {
|
|
177
|
+
/** Number of retries for transient backend failures (default: 3) */
|
|
178
|
+
maxRetries?: number;
|
|
179
|
+
/** Enable audit logging (default: true) */
|
|
180
|
+
enableAuditLog?: boolean;
|
|
181
|
+
/** Enable state snapshots (default: false) */
|
|
182
|
+
enableSnapshots?: boolean;
|
|
183
|
+
/** Lock TTL in seconds (default: 600 = 10 minutes) */
|
|
184
|
+
lockTTL?: number;
|
|
185
|
+
});
|
|
186
|
+
/**
|
|
187
|
+
* Subscribe to state machine events
|
|
188
|
+
*
|
|
189
|
+
* Enables observability and telemetry integration.
|
|
190
|
+
*
|
|
191
|
+
* @param event - Event type to listen for
|
|
192
|
+
* @param handler - Callback function receiving structured payload
|
|
193
|
+
*/
|
|
194
|
+
on(event: StateMachineEvent, handler: (payload: StateMachineEventPayload) => void): void;
|
|
195
|
+
/**
|
|
196
|
+
* Unsubscribe from state machine events
|
|
197
|
+
*
|
|
198
|
+
* @param event - Event type to stop listening for
|
|
199
|
+
* @param handler - Callback function to remove
|
|
200
|
+
*/
|
|
201
|
+
off(event: StateMachineEvent, handler: (payload: StateMachineEventPayload) => void): void;
|
|
202
|
+
/**
|
|
203
|
+
* Emit event to all listeners with structured payload
|
|
204
|
+
*
|
|
205
|
+
* @param event - Event type
|
|
206
|
+
* @param state - Current deployment state
|
|
207
|
+
* @param metadata - Additional metadata (optional)
|
|
208
|
+
*/
|
|
209
|
+
private emit;
|
|
210
|
+
/**
|
|
211
|
+
* Start lock auto-renewal for a stack
|
|
212
|
+
*
|
|
213
|
+
* Renews the lock at 50% of the TTL interval to prevent expiration
|
|
214
|
+
* during long deployments. Only starts renewal if backend supports locking.
|
|
215
|
+
*
|
|
216
|
+
* @param stackName - Name of the stack
|
|
217
|
+
* @param holder - Lock holder identifier
|
|
218
|
+
* @param ttl - Lock TTL in seconds
|
|
219
|
+
*/
|
|
220
|
+
private startLockRenewal;
|
|
221
|
+
/**
|
|
222
|
+
* Stop lock auto-renewal for a stack
|
|
223
|
+
*
|
|
224
|
+
* Cleans up the renewal timer to prevent memory leaks.
|
|
225
|
+
*
|
|
226
|
+
* @param stackName - Name of the stack
|
|
227
|
+
*/
|
|
228
|
+
private stopLockRenewal;
|
|
229
|
+
/**
|
|
230
|
+
* Validate state transition
|
|
231
|
+
*
|
|
232
|
+
* Ensures state machine only transitions through valid states.
|
|
233
|
+
* Prevents accidental invalid state mutations.
|
|
234
|
+
*
|
|
235
|
+
* @param from - Current state
|
|
236
|
+
* @param to - Target state
|
|
237
|
+
* @throws DeploymentError if transition is invalid
|
|
238
|
+
*/
|
|
239
|
+
private validateTransition;
|
|
240
|
+
/**
|
|
241
|
+
* Retry operation with exponential backoff
|
|
242
|
+
*
|
|
243
|
+
* Handles transient backend failures (network issues, timeouts, etc.)
|
|
244
|
+
*
|
|
245
|
+
* REQ-O03: Error handling and retry logic
|
|
246
|
+
*
|
|
247
|
+
* @param operation - Async operation to retry
|
|
248
|
+
* @param retries - Number of retries (default: from options)
|
|
249
|
+
* @returns Promise resolving to operation result
|
|
250
|
+
* @throws Error if all retries fail
|
|
251
|
+
*/
|
|
252
|
+
private withRetry;
|
|
253
|
+
/**
|
|
254
|
+
* Log action to audit trail
|
|
255
|
+
*
|
|
256
|
+
* REQ-O05: Audit log for compliance
|
|
257
|
+
*
|
|
258
|
+
* @param stackName - Stack name
|
|
259
|
+
* @param action - Action performed
|
|
260
|
+
* @param state - Current deployment state
|
|
261
|
+
* @param error - Error if action failed
|
|
262
|
+
*/
|
|
263
|
+
private logAction;
|
|
264
|
+
/**
|
|
265
|
+
* Save state snapshot for time-travel debugging
|
|
266
|
+
*
|
|
267
|
+
* Creates a deep copy to ensure immutability.
|
|
268
|
+
*
|
|
269
|
+
* REQ-O01: Immutable state snapshots
|
|
270
|
+
*
|
|
271
|
+
* @param stackName - Stack name
|
|
272
|
+
* @param state - Current deployment state
|
|
273
|
+
*/
|
|
274
|
+
private saveSnapshot;
|
|
275
|
+
/**
|
|
276
|
+
* Start a deployment transaction
|
|
277
|
+
*
|
|
278
|
+
* Transitions state from PENDING to APPLYING and saves to backend.
|
|
279
|
+
* Acquires lock to prevent concurrent deployments.
|
|
280
|
+
*
|
|
281
|
+
* REQ-O01.1: WHEN deployment starts THEN CloudDOM state SHALL transition to APPLYING
|
|
282
|
+
* REQ-O02: State locking to prevent concurrent deployments
|
|
283
|
+
*
|
|
284
|
+
* @param stackName - Name of the stack being deployed
|
|
285
|
+
* @param changeSet - Change set computed by Reconciler
|
|
286
|
+
* @param cloudDOM - CloudDOM tree being deployed
|
|
287
|
+
* @param user - User initiating the deployment
|
|
288
|
+
* @returns Promise that resolves when state is saved
|
|
289
|
+
* @throws DeploymentError if lock cannot be acquired or state save fails
|
|
290
|
+
*/
|
|
291
|
+
startDeployment(stackName: string, changeSet: ChangeSet, cloudDOM: CloudDOMNode[], user: string): Promise<void>;
|
|
292
|
+
/**
|
|
293
|
+
* Update checkpoint after each resource deploys
|
|
294
|
+
*
|
|
295
|
+
* Saves progress to enable crash recovery. If deployment crashes,
|
|
296
|
+
* it can resume from the last checkpoint.
|
|
297
|
+
*
|
|
298
|
+
* REQ-O01.5: WHEN any provider executes THEN StateMachine SHALL checkpoint after each resource
|
|
299
|
+
*
|
|
300
|
+
* @param stackName - Name of the stack being deployed
|
|
301
|
+
* @param checkpoint - Index of last successfully deployed resource
|
|
302
|
+
* @returns Promise that resolves when checkpoint is saved
|
|
303
|
+
* @throws DeploymentError if state is invalid or save fails
|
|
304
|
+
*/
|
|
305
|
+
updateCheckpoint(stackName: string, checkpoint: number): Promise<void>;
|
|
306
|
+
/**
|
|
307
|
+
* Mark deployment as complete
|
|
308
|
+
*
|
|
309
|
+
* Transitions state from APPLYING to DEPLOYED and releases lock.
|
|
310
|
+
*
|
|
311
|
+
* REQ-O01.2: WHEN deployment succeeds THEN state SHALL transition to DEPLOYED
|
|
312
|
+
* REQ-O02: Release lock after deployment completes
|
|
313
|
+
*
|
|
314
|
+
* @param stackName - Name of the stack that was deployed
|
|
315
|
+
* @returns Promise that resolves when state is saved
|
|
316
|
+
* @throws DeploymentError if state is invalid or save fails
|
|
317
|
+
*/
|
|
318
|
+
completeDeployment(stackName: string): Promise<void>;
|
|
319
|
+
/**
|
|
320
|
+
* Mark deployment as failed
|
|
321
|
+
*
|
|
322
|
+
* Transitions state from APPLYING to FAILED, stores error details, and releases lock.
|
|
323
|
+
*
|
|
324
|
+
* @param stackName - Name of the stack that failed
|
|
325
|
+
* @param error - Error that caused the failure (should be DeploymentError or subclass)
|
|
326
|
+
* @returns Promise that resolves when state is saved
|
|
327
|
+
* @throws DeploymentError if state is invalid or save fails
|
|
328
|
+
*/
|
|
329
|
+
failDeployment(stackName: string, error: Error | DeploymentError): Promise<void>;
|
|
330
|
+
/**
|
|
331
|
+
* Resume interrupted deployment from checkpoint
|
|
332
|
+
*
|
|
333
|
+
* Returns the change set and checkpoint so deployment can continue
|
|
334
|
+
* from where it left off.
|
|
335
|
+
*
|
|
336
|
+
* REQ-O01.4: WHEN CReact restarts THEN it SHALL detect incomplete transactions
|
|
337
|
+
* and offer resume/rollback
|
|
338
|
+
*
|
|
339
|
+
* @param stackName - Name of the stack to resume
|
|
340
|
+
* @returns Promise resolving to change set, checkpoint index, and cloudDOM
|
|
341
|
+
* @throws DeploymentError if no incomplete deployment found
|
|
342
|
+
*/
|
|
343
|
+
resumeDeployment(stackName: string): Promise<{
|
|
344
|
+
changeSet: ChangeSet;
|
|
345
|
+
checkpoint: number;
|
|
346
|
+
cloudDOM: CloudDOMNode[];
|
|
347
|
+
}>;
|
|
348
|
+
/**
|
|
349
|
+
* Rollback to previous state
|
|
350
|
+
*
|
|
351
|
+
* Applies reverse change set (deletes → creates, creates → deletes)
|
|
352
|
+
* and transitions state to ROLLED_BACK. Releases lock.
|
|
353
|
+
*
|
|
354
|
+
* Note: This method only updates the state machine status. The actual
|
|
355
|
+
* rollback logic (applying reverse change set) is handled by the caller
|
|
356
|
+
* (typically CReact or CLI).
|
|
357
|
+
*
|
|
358
|
+
* REQ-O01: Crash recovery with rollback
|
|
359
|
+
* REQ-O02: Release lock after rollback
|
|
360
|
+
*
|
|
361
|
+
* @param stackName - Name of the stack to rollback
|
|
362
|
+
* @returns Promise that resolves when state is saved
|
|
363
|
+
* @throws DeploymentError if state is invalid or save fails
|
|
364
|
+
*/
|
|
365
|
+
rollback(stackName: string): Promise<void>;
|
|
366
|
+
/**
|
|
367
|
+
* Get current deployment state for a stack
|
|
368
|
+
*
|
|
369
|
+
* @param stackName - Name of the stack
|
|
370
|
+
* @returns Promise resolving to deployment state, or undefined if not found
|
|
371
|
+
*/
|
|
372
|
+
getState(stackName: string): Promise<DeploymentState | undefined>;
|
|
373
|
+
/**
|
|
374
|
+
* Update the CloudDOM in the deployment state (for post-deployment effects)
|
|
375
|
+
*
|
|
376
|
+
* @param stackName - Stack name
|
|
377
|
+
* @param cloudDOM - Updated CloudDOM with new outputs
|
|
378
|
+
* @throws DeploymentError if state update fails
|
|
379
|
+
*/
|
|
380
|
+
updateCloudDOM(stackName: string, cloudDOM: CloudDOMNode[]): Promise<void>;
|
|
381
|
+
/**
|
|
382
|
+
* Check if a stack has an incomplete deployment
|
|
383
|
+
*
|
|
384
|
+
* Used on startup to detect crashed deployments that need recovery.
|
|
385
|
+
*
|
|
386
|
+
* REQ-O01.3: WHEN CReact process crashes mid-deploy THEN state SHALL remain in APPLYING
|
|
387
|
+
* REQ-O01.4: WHEN CReact restarts THEN it SHALL detect incomplete transactions
|
|
388
|
+
*
|
|
389
|
+
* @param stackName - Name of the stack to check
|
|
390
|
+
* @returns Promise resolving to true if deployment is incomplete
|
|
391
|
+
*/
|
|
392
|
+
hasIncompleteDeployment(stackName: string): Promise<boolean>;
|
|
393
|
+
/**
|
|
394
|
+
* Get checkpoint info for display
|
|
395
|
+
*
|
|
396
|
+
* Returns human-readable checkpoint information for CLI/UI.
|
|
397
|
+
* Includes resource ID for better UX.
|
|
398
|
+
*
|
|
399
|
+
* @param stackName - Name of the stack
|
|
400
|
+
* @returns Promise resolving to checkpoint info, or undefined if not found
|
|
401
|
+
*/
|
|
402
|
+
getCheckpointInfo(stackName: string): Promise<{
|
|
403
|
+
checkpoint: number;
|
|
404
|
+
resourceId?: string;
|
|
405
|
+
totalResources: number;
|
|
406
|
+
percentComplete: number;
|
|
407
|
+
} | undefined>;
|
|
408
|
+
/**
|
|
409
|
+
* Auto-recover from incomplete deployment
|
|
410
|
+
*
|
|
411
|
+
* Convenience method for CLI/orchestrator to automatically resume or rollback
|
|
412
|
+
* based on configuration.
|
|
413
|
+
*
|
|
414
|
+
* @param stackName - Name of the stack to recover
|
|
415
|
+
* @param strategy - Recovery strategy ('resume' or 'rollback')
|
|
416
|
+
* @returns Promise resolving to recovery info, or undefined if no recovery needed
|
|
417
|
+
*/
|
|
418
|
+
autoRecover(stackName: string, strategy: 'resume' | 'rollback'): Promise<{
|
|
419
|
+
action: 'resumed' | 'rolled_back' | 'none';
|
|
420
|
+
checkpoint?: number;
|
|
421
|
+
changeSet?: ChangeSet;
|
|
422
|
+
cloudDOM?: CloudDOMNode[];
|
|
423
|
+
}>;
|
|
424
|
+
}
|