@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.
Files changed (103) hide show
  1. package/LICENSE +212 -0
  2. package/README.md +379 -0
  3. package/dist/cli/commands/BuildCommand.d.ts +40 -0
  4. package/dist/cli/commands/BuildCommand.js +151 -0
  5. package/dist/cli/commands/DeployCommand.d.ts +38 -0
  6. package/dist/cli/commands/DeployCommand.js +194 -0
  7. package/dist/cli/commands/DevCommand.d.ts +52 -0
  8. package/dist/cli/commands/DevCommand.js +385 -0
  9. package/dist/cli/commands/PlanCommand.d.ts +39 -0
  10. package/dist/cli/commands/PlanCommand.js +164 -0
  11. package/dist/cli/commands/index.d.ts +36 -0
  12. package/dist/cli/commands/index.js +43 -0
  13. package/dist/cli/core/ArgumentParser.d.ts +46 -0
  14. package/dist/cli/core/ArgumentParser.js +127 -0
  15. package/dist/cli/core/BaseCommand.d.ts +75 -0
  16. package/dist/cli/core/BaseCommand.js +95 -0
  17. package/dist/cli/core/CLIContext.d.ts +68 -0
  18. package/dist/cli/core/CLIContext.js +183 -0
  19. package/dist/cli/core/CommandRegistry.d.ts +64 -0
  20. package/dist/cli/core/CommandRegistry.js +89 -0
  21. package/dist/cli/core/index.d.ts +36 -0
  22. package/dist/cli/core/index.js +43 -0
  23. package/dist/cli/index.d.ts +35 -0
  24. package/dist/cli/index.js +100 -0
  25. package/dist/cli/output.d.ts +204 -0
  26. package/dist/cli/output.js +437 -0
  27. package/dist/cli/utils.d.ts +59 -0
  28. package/dist/cli/utils.js +76 -0
  29. package/dist/context/createContext.d.ts +90 -0
  30. package/dist/context/createContext.js +113 -0
  31. package/dist/context/index.d.ts +30 -0
  32. package/dist/context/index.js +35 -0
  33. package/dist/core/CReact.d.ts +409 -0
  34. package/dist/core/CReact.js +1127 -0
  35. package/dist/core/CloudDOMBuilder.d.ts +429 -0
  36. package/dist/core/CloudDOMBuilder.js +1198 -0
  37. package/dist/core/ContextDependencyTracker.d.ts +165 -0
  38. package/dist/core/ContextDependencyTracker.js +448 -0
  39. package/dist/core/ErrorRecoveryManager.d.ts +145 -0
  40. package/dist/core/ErrorRecoveryManager.js +443 -0
  41. package/dist/core/EventBus.d.ts +91 -0
  42. package/dist/core/EventBus.js +185 -0
  43. package/dist/core/ProviderOutputTracker.d.ts +211 -0
  44. package/dist/core/ProviderOutputTracker.js +476 -0
  45. package/dist/core/ReactiveUpdateQueue.d.ts +76 -0
  46. package/dist/core/ReactiveUpdateQueue.js +121 -0
  47. package/dist/core/Reconciler.d.ts +415 -0
  48. package/dist/core/Reconciler.js +1037 -0
  49. package/dist/core/RenderScheduler.d.ts +153 -0
  50. package/dist/core/RenderScheduler.js +519 -0
  51. package/dist/core/Renderer.d.ts +276 -0
  52. package/dist/core/Renderer.js +791 -0
  53. package/dist/core/Runtime.d.ts +246 -0
  54. package/dist/core/Runtime.js +640 -0
  55. package/dist/core/StateBindingManager.d.ts +121 -0
  56. package/dist/core/StateBindingManager.js +309 -0
  57. package/dist/core/StateMachine.d.ts +424 -0
  58. package/dist/core/StateMachine.js +787 -0
  59. package/dist/core/StructuralChangeDetector.d.ts +140 -0
  60. package/dist/core/StructuralChangeDetector.js +363 -0
  61. package/dist/core/Validator.d.ts +127 -0
  62. package/dist/core/Validator.js +279 -0
  63. package/dist/core/errors.d.ts +153 -0
  64. package/dist/core/errors.js +202 -0
  65. package/dist/core/index.d.ts +38 -0
  66. package/dist/core/index.js +64 -0
  67. package/dist/core/types.d.ts +263 -0
  68. package/dist/core/types.js +48 -0
  69. package/dist/hooks/context.d.ts +147 -0
  70. package/dist/hooks/context.js +334 -0
  71. package/dist/hooks/useContext.d.ts +113 -0
  72. package/dist/hooks/useContext.js +169 -0
  73. package/dist/hooks/useEffect.d.ts +105 -0
  74. package/dist/hooks/useEffect.js +540 -0
  75. package/dist/hooks/useInstance.d.ts +139 -0
  76. package/dist/hooks/useInstance.js +441 -0
  77. package/dist/hooks/useState.d.ts +120 -0
  78. package/dist/hooks/useState.js +298 -0
  79. package/dist/index.d.ts +46 -0
  80. package/dist/index.js +70 -0
  81. package/dist/jsx.d.ts +64 -0
  82. package/dist/jsx.js +76 -0
  83. package/dist/providers/DummyBackendProvider.d.ts +193 -0
  84. package/dist/providers/DummyBackendProvider.js +189 -0
  85. package/dist/providers/DummyCloudProvider.d.ts +128 -0
  86. package/dist/providers/DummyCloudProvider.js +157 -0
  87. package/dist/providers/IBackendProvider.d.ts +177 -0
  88. package/dist/providers/IBackendProvider.js +31 -0
  89. package/dist/providers/ICloudProvider.d.ts +146 -0
  90. package/dist/providers/ICloudProvider.js +31 -0
  91. package/dist/providers/index.d.ts +31 -0
  92. package/dist/providers/index.js +31 -0
  93. package/dist/test-event-callbacks.d.ts +0 -0
  94. package/dist/test-event-callbacks.js +1 -0
  95. package/dist/utils/Logger.d.ts +144 -0
  96. package/dist/utils/Logger.js +220 -0
  97. package/dist/utils/Output.d.ts +161 -0
  98. package/dist/utils/Output.js +401 -0
  99. package/dist/utils/deepEqual.d.ts +71 -0
  100. package/dist/utils/deepEqual.js +276 -0
  101. package/dist/utils/naming.d.ts +241 -0
  102. package/dist/utils/naming.js +376 -0
  103. package/package.json +87 -0
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ /**
3
+
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+
6
+ * you may not use this file except in compliance with the License.
7
+
8
+ * You may obtain a copy of the License at
9
+
10
+ *
11
+
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ *
15
+
16
+ * Unless required by applicable law or agreed to in writing, software
17
+
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+
22
+ * See the License for the specific language governing permissions and
23
+
24
+ * limitations under the License.
25
+
26
+ *
27
+
28
+ * Copyright 2025 Daniel Coutinho Ribeiro
29
+
30
+ */
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.CloudDOMEventBus = void 0;
33
+ const Logger_1 = require("../utils/Logger");
34
+ const logger = Logger_1.LoggerFactory.getLogger('clouddom');
35
+ /**
36
+ * CloudDOM Event Bus - Centralized event system for deployment lifecycle
37
+ *
38
+ * Provides a clean way to trigger CloudDOM event callbacks without
39
+ * coupling to specific classes like CloudDOMBuilder or StateMachine.
40
+ *
41
+ * REQ-2.3: CloudDOM event callbacks for deployment lifecycle
42
+ * REQ-3.2: Error handling with component context
43
+ */
44
+ class CloudDOMEventBus {
45
+ /**
46
+ * Trigger CloudDOM event callbacks for a resource
47
+ *
48
+ * Called during deployment lifecycle to notify parent components
49
+ * about their child resources' deployment events.
50
+ *
51
+ * @param node - CloudDOM node with event callbacks
52
+ * @param phase - Deployment phase ('deploy', 'error', 'destroy')
53
+ * @param error - Error object (only for 'error' phase)
54
+ */
55
+ static async triggerEventCallbacks(node, phase, error) {
56
+ if (!node.eventCallbacks) {
57
+ return; // No callbacks to trigger
58
+ }
59
+ // Create event context
60
+ const context = {
61
+ resourceId: node.id,
62
+ path: node.path,
63
+ construct: node.construct,
64
+ props: { ...node.props }, // Clone to prevent mutations
65
+ outputs: node.outputs ? { ...node.outputs } : undefined,
66
+ phase,
67
+ timestamp: Date.now(),
68
+ };
69
+ try {
70
+ // Trigger appropriate callback based on phase
71
+ switch (phase) {
72
+ case 'deploy':
73
+ if (node.eventCallbacks.onDeploy) {
74
+ await node.eventCallbacks.onDeploy(context);
75
+ }
76
+ break;
77
+ case 'error':
78
+ if (node.eventCallbacks.onError && error) {
79
+ await node.eventCallbacks.onError(context, error);
80
+ }
81
+ break;
82
+ case 'destroy':
83
+ if (node.eventCallbacks.onDestroy) {
84
+ await node.eventCallbacks.onDestroy(context);
85
+ }
86
+ break;
87
+ }
88
+ }
89
+ catch (callbackError) {
90
+ // Don't let callback errors break deployment
91
+ logger.error(`Event callback failed for ${node.id} (${phase}):`, callbackError);
92
+ }
93
+ }
94
+ /**
95
+ * Trigger event callbacks for all nodes in a CloudDOM tree
96
+ *
97
+ * Recursively walks the tree and triggers callbacks for each node.
98
+ *
99
+ * @param nodes - CloudDOM nodes to trigger events for
100
+ * @param phase - Deployment phase
101
+ * @param error - Error object (only for 'error' phase)
102
+ */
103
+ static async triggerEventCallbacksRecursive(nodes, phase, error) {
104
+ for (const node of nodes) {
105
+ // Trigger callback for this node
106
+ await CloudDOMEventBus.triggerEventCallbacks(node, phase, error);
107
+ // Recursively trigger for children
108
+ if (node.children && node.children.length > 0) {
109
+ await CloudDOMEventBus.triggerEventCallbacksRecursive(node.children, phase, error);
110
+ }
111
+ }
112
+ }
113
+ /**
114
+ * Trigger event callbacks for a specific list of nodes by ID
115
+ *
116
+ * Useful for triggering events for specific resources during deployment.
117
+ *
118
+ * @param allNodes - All CloudDOM nodes to search in
119
+ * @param nodeIds - IDs of nodes to trigger events for
120
+ * @param phase - Deployment phase
121
+ * @param error - Error object (only for 'error' phase)
122
+ */
123
+ static async triggerEventCallbacksForNodes(allNodes, nodeIds, phase, error) {
124
+ // Build a map for fast lookup
125
+ const nodeMap = new Map();
126
+ const buildMap = (nodes) => {
127
+ for (const node of nodes) {
128
+ nodeMap.set(node.id, node);
129
+ if (node.children && node.children.length > 0) {
130
+ buildMap(node.children);
131
+ }
132
+ }
133
+ };
134
+ buildMap(allNodes);
135
+ // Trigger events for specified nodes
136
+ for (const nodeId of nodeIds) {
137
+ const node = nodeMap.get(nodeId);
138
+ if (node) {
139
+ await CloudDOMEventBus.triggerEventCallbacks(node, phase, error);
140
+ }
141
+ }
142
+ }
143
+ /**
144
+ * Check if any nodes in a tree have event callbacks
145
+ *
146
+ * Useful for optimization - skip event processing if no callbacks exist.
147
+ *
148
+ * @param nodes - CloudDOM nodes to check
149
+ * @returns True if any node has event callbacks
150
+ */
151
+ static hasEventCallbacks(nodes) {
152
+ for (const node of nodes) {
153
+ if (node.eventCallbacks && Object.keys(node.eventCallbacks).length > 0) {
154
+ return true;
155
+ }
156
+ if (node.children && node.children.length > 0) {
157
+ if (CloudDOMEventBus.hasEventCallbacks(node.children)) {
158
+ return true;
159
+ }
160
+ }
161
+ }
162
+ return false;
163
+ }
164
+ /**
165
+ * Get all nodes with event callbacks from a tree
166
+ *
167
+ * Useful for debugging and introspection.
168
+ *
169
+ * @param nodes - CloudDOM nodes to search
170
+ * @returns Array of nodes that have event callbacks
171
+ */
172
+ static getNodesWithEventCallbacks(nodes) {
173
+ const result = [];
174
+ for (const node of nodes) {
175
+ if (node.eventCallbacks && Object.keys(node.eventCallbacks).length > 0) {
176
+ result.push(node);
177
+ }
178
+ if (node.children && node.children.length > 0) {
179
+ result.push(...CloudDOMEventBus.getNodesWithEventCallbacks(node.children));
180
+ }
181
+ }
182
+ return result;
183
+ }
184
+ }
185
+ exports.CloudDOMEventBus = CloudDOMEventBus;
@@ -0,0 +1,211 @@
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 { FiberNode, CloudDOMNode, CReactEvents, OutputChange } from './types';
31
+ /**
32
+ * Access tracking session for dependency analysis
33
+ * REQ-6.2, 6.3, 6.4: Track output reads during component execution
34
+ */
35
+ interface AccessTrackingSession {
36
+ fiber: FiberNode;
37
+ startTime: number;
38
+ trackedOutputs: Set<string>;
39
+ isActive: boolean;
40
+ }
41
+ /**
42
+ * ProviderOutputTracker - Tracks useInstance calls and their output dependencies
43
+ *
44
+ * Key Features:
45
+ * - Track which components use which provider instances
46
+ * - Detect when provider outputs change
47
+ * - Notify bound components of output changes
48
+ * - Event hook integration for tooling and debugging
49
+ * - REQ-6.2, 6.3, 6.4: Track output reads for automatic binding creation
50
+ */
51
+ export declare class ProviderOutputTracker {
52
+ private instanceBindings;
53
+ private instanceOutputs;
54
+ private eventHooks?;
55
+ private activeSessions;
56
+ constructor(eventHooks?: CReactEvents);
57
+ /**
58
+ * Track a useInstance call - bind a fiber to a CloudDOM node
59
+ * This is called whenever useInstance is called in a component
60
+ */
61
+ trackInstance(node: CloudDOMNode, fiber: FiberNode): void;
62
+ /**
63
+ * Get all fibers bound to a specific instance
64
+ */
65
+ getBindingsForInstance(nodeId: string): Set<FiberNode>;
66
+ /**
67
+ * Update outputs for an instance and detect changes
68
+ * Returns array of output changes that occurred
69
+ */
70
+ updateInstanceOutputs(nodeId: string, newOutputs: Record<string, any>): OutputChange[];
71
+ /**
72
+ * Notify bound components of output changes
73
+ * This triggers re-renders for affected components
74
+ */
75
+ notifyOutputChanges(changes: OutputChange[]): void;
76
+ /**
77
+ * Process a batch of CloudDOM nodes and detect all output changes
78
+ * This is typically called after deployment completes
79
+ */
80
+ processCloudDOMOutputs(nodes: CloudDOMNode[]): OutputChange[];
81
+ /**
82
+ * Remove bindings for a specific fiber (cleanup)
83
+ */
84
+ removeBindingsForFiber(fiber: FiberNode): void;
85
+ /**
86
+ * Remove bindings for a specific instance (when resource is deleted)
87
+ */
88
+ removeBindingsForInstance(nodeId: string): void;
89
+ /**
90
+ * Validate bindings and remove invalid ones
91
+ * This should be called periodically to clean up stale bindings
92
+ */
93
+ validateBindings(validNodes: Set<string>): void;
94
+ /**
95
+ * Get current outputs for an instance
96
+ */
97
+ getInstanceOutputs(nodeId: string): Record<string, any> | undefined;
98
+ /**
99
+ * Check if an instance has any bound components
100
+ */
101
+ hasBindings(nodeId: string): boolean;
102
+ /**
103
+ * Get all tracked instances
104
+ */
105
+ getTrackedInstances(): string[];
106
+ /**
107
+ * Get statistics about current bindings
108
+ */
109
+ getBindingStats(): {
110
+ totalInstances: number;
111
+ totalBindings: number;
112
+ instancesWithOutputs: number;
113
+ };
114
+ /**
115
+ * Get all bindings for debugging/inspection
116
+ */
117
+ getAllBindings(): Map<string, {
118
+ fibers: FiberNode[];
119
+ outputs: Record<string, any> | undefined;
120
+ }>;
121
+ /**
122
+ * Clear all bindings (for testing/cleanup)
123
+ */
124
+ clearAllBindings(): void;
125
+ /**
126
+ * Create a snapshot of current state for comparison
127
+ * Useful for detecting changes between deployments
128
+ */
129
+ createSnapshot(): {
130
+ bindings: Map<string, string[]>;
131
+ outputs: Map<string, Record<string, any>>;
132
+ };
133
+ /**
134
+ * Compare with a previous snapshot to detect changes
135
+ */
136
+ compareWithSnapshot(snapshot: {
137
+ bindings: Map<string, string[]>;
138
+ outputs: Map<string, Record<string, any>>;
139
+ }): {
140
+ bindingChanges: {
141
+ added: string[];
142
+ removed: string[];
143
+ modified: string[];
144
+ };
145
+ outputChanges: OutputChange[];
146
+ };
147
+ /**
148
+ * Compare two output objects and return changes
149
+ */
150
+ private compareOutputs;
151
+ /**
152
+ * Extract output references for automatic state binding
153
+ * Creates proxy objects that can be used to automatically bind state to outputs
154
+ */
155
+ extractOutputReferences(node: CloudDOMNode): Record<string, any>;
156
+ /**
157
+ * Update outputs for a specific node and return changes
158
+ * This is an alias for updateInstanceOutputs for compatibility
159
+ */
160
+ updateNodeOutputs(nodeId: string, newOutputs: Record<string, any>): OutputChange[];
161
+ /**
162
+ * Process output changes and return affected fibers
163
+ * This is an alias for processCloudDOMOutputs for single node updates
164
+ */
165
+ processOutputChanges(changes: OutputChange[]): Set<FiberNode>;
166
+ /**
167
+ * Get current outputs for a node
168
+ * This is an alias for getInstanceOutputs for compatibility
169
+ */
170
+ getNodeOutputs(nodeId: string): Record<string, any>;
171
+ /**
172
+ * Start an access tracking session for a fiber
173
+ * REQ-6.2, 6.3: Track which outputs are accessed during execution
174
+ *
175
+ * @param fiber - Fiber node to track
176
+ */
177
+ startAccessTracking(fiber: FiberNode): void;
178
+ /**
179
+ * End an access tracking session and return tracked outputs
180
+ * REQ-6.3, 6.4: Collect tracked outputs for binding creation
181
+ *
182
+ * @param fiber - Fiber node to end tracking for
183
+ * @returns Set of binding keys that were accessed
184
+ */
185
+ endAccessTracking(fiber: FiberNode): Set<string>;
186
+ /**
187
+ * Track an output read during an active session
188
+ * REQ-6.2, 6.4: Record when outputs are accessed for binding creation
189
+ *
190
+ * @param nodeId - CloudDOM node ID
191
+ * @param outputKey - Output key that was accessed
192
+ * @param fiber - Fiber node that accessed the output
193
+ */
194
+ trackOutputRead(nodeId: string, outputKey: string, fiber: FiberNode): void;
195
+ /**
196
+ * Check if a fiber has an active tracking session
197
+ *
198
+ * @param fiber - Fiber node to check
199
+ * @returns True if tracking is active for this fiber
200
+ */
201
+ isTrackingActive(fiber: FiberNode): boolean;
202
+ /**
203
+ * Get all active tracking sessions (for debugging)
204
+ */
205
+ getActiveSessions(): AccessTrackingSession[];
206
+ /**
207
+ * Clear all active tracking sessions (for cleanup/testing)
208
+ */
209
+ clearActiveSessions(): void;
210
+ }
211
+ export {};