@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
package/LICENSE
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
24
|
+
permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License.
|
|
67
|
+
|
|
68
|
+
Subject to the terms and conditions of this License, each Contributor
|
|
69
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
|
70
|
+
royalty-free, irrevocable copyright license to reproduce, prepare
|
|
71
|
+
Derivative Works of, publicly display, publicly perform, sublicense,
|
|
72
|
+
and distribute the Work and such Derivative Works in Source or Object
|
|
73
|
+
form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License.
|
|
76
|
+
|
|
77
|
+
Subject to the terms and conditions of this License, each Contributor
|
|
78
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
|
79
|
+
royalty-free, irrevocable (except as stated in this section) patent
|
|
80
|
+
license to make, have made, use, offer to sell, sell, import, and
|
|
81
|
+
otherwise transfer the Work, where such license applies only to those
|
|
82
|
+
patent claims licensable by such Contributor that are necessarily
|
|
83
|
+
infringed by their Contribution(s) alone or by combination of their
|
|
84
|
+
Contribution(s) with the Work to which such Contribution(s) was
|
|
85
|
+
submitted. If You institute patent litigation against any entity
|
|
86
|
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
87
|
+
the Work or a Contribution incorporated within the Work constitutes
|
|
88
|
+
direct or contributory patent infringement, then any patent licenses
|
|
89
|
+
granted to You under this License for that Work shall terminate as of
|
|
90
|
+
the date such litigation is filed.
|
|
91
|
+
|
|
92
|
+
4. Redistribution.
|
|
93
|
+
|
|
94
|
+
You may reproduce and distribute copies of the Work or Derivative
|
|
95
|
+
Works thereof in any medium, with or without modifications, and in
|
|
96
|
+
Source or Object form, provided that You meet the following conditions:
|
|
97
|
+
|
|
98
|
+
(a) You must give any other recipients of the Work or Derivative Works
|
|
99
|
+
a copy of this License; and
|
|
100
|
+
|
|
101
|
+
(b) You must cause any modified files to carry prominent notices
|
|
102
|
+
stating that You changed the files; and
|
|
103
|
+
|
|
104
|
+
(c) You must retain, in the Source form of any Derivative Works that
|
|
105
|
+
You distribute, all copyright, patent, trademark, and attribution
|
|
106
|
+
notices from the Source form of the Work, excluding those notices
|
|
107
|
+
that do not pertain to any part of the Derivative Works; and
|
|
108
|
+
|
|
109
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
110
|
+
distribution, then any Derivative Works that You distribute must
|
|
111
|
+
include a readable copy of the attribution notices contained
|
|
112
|
+
within such NOTICE file, excluding those notices that do not
|
|
113
|
+
pertain to any part of the Derivative Works, in at least one of
|
|
114
|
+
the following places: within a NOTICE text file distributed as
|
|
115
|
+
part of the Derivative Works; within the Source form or
|
|
116
|
+
documentation, if provided along with the Derivative Works; or,
|
|
117
|
+
within a display generated by the Derivative Works, if and
|
|
118
|
+
wherever such third-party notices normally appear. The contents
|
|
119
|
+
of the NOTICE file are for informational purposes only and do not
|
|
120
|
+
modify the License. You may add Your own attribution notices
|
|
121
|
+
within Derivative Works that You distribute, alongside or as an
|
|
122
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
123
|
+
additional attribution notices cannot be construed as modifying
|
|
124
|
+
the License.
|
|
125
|
+
|
|
126
|
+
You may add Your own copyright statement to Your modifications and
|
|
127
|
+
may provide additional or different license terms and conditions
|
|
128
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
129
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
130
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
131
|
+
the conditions stated in this License.
|
|
132
|
+
|
|
133
|
+
5. Submission of Contributions.
|
|
134
|
+
|
|
135
|
+
Unless You explicitly state otherwise, any Contribution intentionally
|
|
136
|
+
submitted for inclusion in the Work by You to the Licensor shall be
|
|
137
|
+
under the terms and conditions of this License, without any additional
|
|
138
|
+
terms or conditions. Notwithstanding the above, nothing herein shall
|
|
139
|
+
supersede or modify the terms of any separate license agreement you
|
|
140
|
+
may have executed with Licensor regarding such Contributions.
|
|
141
|
+
|
|
142
|
+
6. Trademarks.
|
|
143
|
+
|
|
144
|
+
This License does not grant permission to use the trade names,
|
|
145
|
+
trademarks, service marks, or product names of the Licensor, except
|
|
146
|
+
as required for reasonable and customary use in describing the
|
|
147
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
148
|
+
|
|
149
|
+
7. Disclaimer of Warranty.
|
|
150
|
+
|
|
151
|
+
Unless required by applicable law or agreed to in writing, Licensor
|
|
152
|
+
provides the Work (and each Contributor provides its Contributions)
|
|
153
|
+
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
154
|
+
either express or implied, including, without limitation, any
|
|
155
|
+
warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY,
|
|
156
|
+
or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for
|
|
157
|
+
determining the appropriateness of using or redistributing the Work
|
|
158
|
+
and assume any risks associated with Your exercise of permissions
|
|
159
|
+
under this License.
|
|
160
|
+
|
|
161
|
+
8. Limitation of Liability.
|
|
162
|
+
|
|
163
|
+
In no event and under no legal theory, whether in tort (including
|
|
164
|
+
negligence), contract, or otherwise, unless required by applicable
|
|
165
|
+
law (such as deliberate and grossly negligent acts) or agreed to in
|
|
166
|
+
writing, shall any Contributor be liable to You for damages,
|
|
167
|
+
including any direct, indirect, special, incidental, or consequential
|
|
168
|
+
damages of any character arising as a result of this License or out
|
|
169
|
+
of the use or inability to use the Work (including but not limited to
|
|
170
|
+
damages for loss of goodwill, work stoppage, computer failure or
|
|
171
|
+
malfunction, or any and all other commercial damages or losses), even
|
|
172
|
+
if such Contributor has been advised of the possibility of such
|
|
173
|
+
damages.
|
|
174
|
+
|
|
175
|
+
9. Accepting Warranty or Additional Liability.
|
|
176
|
+
|
|
177
|
+
While redistributing the Work or Derivative Works thereof, You may
|
|
178
|
+
choose to offer, and charge a fee for, acceptance of support, warranty,
|
|
179
|
+
indemnity, or other liability obligations and/or rights consistent with
|
|
180
|
+
this License. However, in accepting such obligations, You may act only
|
|
181
|
+
on Your own behalf and on Your sole responsibility, not on behalf of
|
|
182
|
+
any other Contributor, and only if You agree to indemnify, defend, and
|
|
183
|
+
hold each Contributor harmless for any liability incurred by, or
|
|
184
|
+
claims asserted against, such Contributor by reason of your accepting
|
|
185
|
+
any such warranty or additional liability.
|
|
186
|
+
|
|
187
|
+
END OF TERMS AND CONDITIONS
|
|
188
|
+
|
|
189
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
190
|
+
|
|
191
|
+
To apply the Apache License to your work, attach the following
|
|
192
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
193
|
+
replaced with your own identifying information. (Don't include
|
|
194
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
195
|
+
comment syntax for the file format. We also recommend that a
|
|
196
|
+
file or class name and description of purpose be included on the
|
|
197
|
+
same "printed page" as the copyright notice for easier
|
|
198
|
+
identification within third-party archives.
|
|
199
|
+
|
|
200
|
+
Copyright 2025 Daniel Coutinho Ribeiro
|
|
201
|
+
|
|
202
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
203
|
+
you may not use this file except in compliance with the License.
|
|
204
|
+
You may obtain a copy of the License at
|
|
205
|
+
|
|
206
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
207
|
+
|
|
208
|
+
Unless required by applicable law or agreed to in writing, software
|
|
209
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
210
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
211
|
+
See the License for the specific language governing permissions and
|
|
212
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
# CReact — React for Infrastructure
|
|
2
|
+
|
|
3
|
+
Think of it as React's rendering model — but instead of a DOM, you render to the cloud.
|
|
4
|
+
|
|
5
|
+
Write your cloud architecture in JSX. CReact figures out the dependencies, orchestrates the deployment, and keeps everything in sync.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
function App() {
|
|
9
|
+
return (
|
|
10
|
+
<VPC name="prod-vpc">
|
|
11
|
+
<Database name="users-db">
|
|
12
|
+
<API name="users-api">
|
|
13
|
+
<Monitoring />
|
|
14
|
+
</API>
|
|
15
|
+
</Database>
|
|
16
|
+
</VPC>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
That's it. No dependency graphs, no explicit ordering, no YAML. Just components that render to actual infrastructure.
|
|
22
|
+
|
|
23
|
+
## The Problem
|
|
24
|
+
|
|
25
|
+
Terraform and Pulumi are great, but they're static. You write a plan, run it, and hope nothing breaks. If you need dynamic orchestration - like deploying a database, waiting for its endpoint, then using that endpoint in your API config - you're writing bash scripts or custom tooling.
|
|
26
|
+
|
|
27
|
+
CReact treats infrastructure like React treats UI. Components re-render when their dependencies change. Outputs flow naturally through context. The Reconciler figures out what actually needs to deploy.
|
|
28
|
+
|
|
29
|
+
## What Makes It Different
|
|
30
|
+
|
|
31
|
+
**It's reactive** - when a database finishes deploying and outputs its endpoint, components that depend on it automatically re-render and deploy. No manual dependency chains.
|
|
32
|
+
|
|
33
|
+
**It's a compiler** - your JSX compiles to CloudDOM (basically an AST for infrastructure). You can diff it, version it, test it without cloud credentials. Only when you're ready does it materialize to real resources.
|
|
34
|
+
|
|
35
|
+
**It's resilient** - every deployment is checkpointed and resumable. Crash halfway through? Resume from where you left off. The Reconciler only deploys what changed, like React's virtual DOM but for cloud resources.
|
|
36
|
+
|
|
37
|
+
**It works with existing tools** - CReact doesn't replace Terraform or CDK. It orchestrates them. Wrap your Terraform modules as CReact components and compose them together.
|
|
38
|
+
|
|
39
|
+
## Watch It Work
|
|
40
|
+
|
|
41
|
+
Here's a real deployment - 22 resources across 3 regions, 6 reactive cycles, fully automatic:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
$ creact dev --entry reactive-app.tsx --auto-approve
|
|
45
|
+
|
|
46
|
+
Starting CReact development mode...
|
|
47
|
+
Building initial state...
|
|
48
|
+
Changes detected: 2 changes
|
|
49
|
+
|
|
50
|
+
Planning changes for stack: optimized-reactive-app-stack
|
|
51
|
+
──────────────────────────────────────────────────
|
|
52
|
+
+ 2 to create
|
|
53
|
+
+ Analytics (Kinesis stream for API analytics)
|
|
54
|
+
+ VPC (Network foundation)
|
|
55
|
+
|
|
56
|
+
Plan: 2 to add, 0 to change, 0 to destroy
|
|
57
|
+
Auto-approving changes...
|
|
58
|
+
|
|
59
|
+
Applying changes...
|
|
60
|
+
[MockCloud] ✅ All resources materialized
|
|
61
|
+
Apply complete! Resources: 2 added, 0 changed, 0 destroyed
|
|
62
|
+
Duration: 0.3s
|
|
63
|
+
|
|
64
|
+
Reactive changes detected
|
|
65
|
+
+ 6 to create
|
|
66
|
+
+ S3Bucket (Asset storage)
|
|
67
|
+
+ SecurityGroup (Network security)
|
|
68
|
+
+ Subnet × 4 (Multi-AZ subnets)
|
|
69
|
+
|
|
70
|
+
Plan: 6 to add, 0 to change, 0 to destroy
|
|
71
|
+
Reactive deployment cycle #2
|
|
72
|
+
Apply complete! Resources: 6 added, 0 changed, 0 destroyed
|
|
73
|
+
Duration: 0.1s
|
|
74
|
+
|
|
75
|
+
Reactive changes detected
|
|
76
|
+
+ 4 to create
|
|
77
|
+
+ ElastiCache (Redis cluster)
|
|
78
|
+
+ CloudFront (CDN distribution)
|
|
79
|
+
+ LoadBalancer (Application load balancer)
|
|
80
|
+
+ RDSInstance (PostgreSQL database)
|
|
81
|
+
|
|
82
|
+
Reactive deployment cycle #3
|
|
83
|
+
Apply complete! Resources: 4 added, 0 changed, 0 destroyed
|
|
84
|
+
Duration: 0.5s
|
|
85
|
+
|
|
86
|
+
Reactive changes detected
|
|
87
|
+
+ 4 to create
|
|
88
|
+
+ Lambda × 3 (Regional API handlers: us-east-1, eu-west-1, ap-southeast-1)
|
|
89
|
+
+ Backup (Database backup vault)
|
|
90
|
+
|
|
91
|
+
Reactive deployment cycle #4
|
|
92
|
+
Apply complete! Resources: 4 added, 0 changed, 0 destroyed
|
|
93
|
+
Duration: 0.5s
|
|
94
|
+
|
|
95
|
+
Reactive changes detected
|
|
96
|
+
+ 3 to create
|
|
97
|
+
+ ApiGateway × 3 (Regional API endpoints)
|
|
98
|
+
|
|
99
|
+
Reactive deployment cycle #5
|
|
100
|
+
Apply complete! Resources: 3 added, 0 changed, 0 destroyed
|
|
101
|
+
Duration: 0.4s
|
|
102
|
+
|
|
103
|
+
Reactive changes detected
|
|
104
|
+
+ 3 to create
|
|
105
|
+
+ CloudWatch × 3 (Regional monitoring dashboards)
|
|
106
|
+
|
|
107
|
+
Reactive deployment cycle #6
|
|
108
|
+
Apply complete! Resources: 3 added, 0 changed, 0 destroyed
|
|
109
|
+
Duration: 0.4s
|
|
110
|
+
|
|
111
|
+
✅ Deployment complete: 22 resources across 6 reactive cycles
|
|
112
|
+
Watching for changes... (Press Ctrl+C to stop)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**What happened:**
|
|
116
|
+
|
|
117
|
+
VPC deployed first. When its outputs became available, subnets and security groups deployed in parallel. When those finished, database and cache deployed. When the database endpoint was ready, Lambdas deployed. When Lambdas got function ARNs, API Gateways deployed. When APIs were live, monitoring deployed.
|
|
118
|
+
|
|
119
|
+
You didn't orchestrate anything manually. You just wrote JSX components that reference each other's outputs. CReact figured out the rest.
|
|
120
|
+
|
|
121
|
+
## How It Works
|
|
122
|
+
|
|
123
|
+
### JSX Compiles to CloudDOM
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
<VPC name="app-vpc" cidr="10.0.0.0/16" />
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
becomes:
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"id": "app-vpc",
|
|
134
|
+
"construct": "VPC",
|
|
135
|
+
"props": { "cidr": "10.0.0.0/16" },
|
|
136
|
+
"outputs": {}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
CloudDOM is just a JSON tree. You can diff it like Git, version it, test it without touching AWS. It's the intermediate representation between your code and actual cloud resources.
|
|
141
|
+
|
|
142
|
+
### The Reconciler Figures Out What Changed
|
|
143
|
+
|
|
144
|
+
Before deploying anything, CReact diffs the previous CloudDOM against the new one. Creates, updates, deletes, replacements - all computed ahead of time. You get a Terraform-style plan but it's just comparing two data structures.
|
|
145
|
+
|
|
146
|
+
### Deployment Is Checkpointed
|
|
147
|
+
|
|
148
|
+
After each resource deploys, CReact saves a checkpoint. Crash halfway through? Run it again and it resumes from where it left off. No manual cleanup, no orphaned resources.
|
|
149
|
+
|
|
150
|
+
### Outputs Trigger Re-renders
|
|
151
|
+
|
|
152
|
+
When a resource finishes deploying, its outputs (endpoint, ARN, ID) become available. Any component that depends on those outputs automatically re-renders and creates new resources. It's like useEffect but for infrastructure.
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
## Hooks
|
|
157
|
+
|
|
158
|
+
### useInstance - Create Resources
|
|
159
|
+
|
|
160
|
+
Creates cloud resources and provides access to their outputs:
|
|
161
|
+
|
|
162
|
+
```tsx
|
|
163
|
+
function DatabaseComponent() {
|
|
164
|
+
// Create database resource
|
|
165
|
+
const database = useInstance(Database, {
|
|
166
|
+
name: 'my-db',
|
|
167
|
+
engine: 'postgres'
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Access outputs after deployment
|
|
171
|
+
console.log(database.outputs?.endpoint); // "db.example.com:5432"
|
|
172
|
+
|
|
173
|
+
return <></>;
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Key Behavior**: If any prop value is `undefined`, creates a placeholder node that doesn't deploy. When dependencies become available, component re-renders and creates the real resource.
|
|
178
|
+
|
|
179
|
+
### useState - Persistent State
|
|
180
|
+
|
|
181
|
+
Manages state that persists across deployments:
|
|
182
|
+
|
|
183
|
+
```tsx
|
|
184
|
+
function App() {
|
|
185
|
+
// State survives deployments (stored in backend)
|
|
186
|
+
const [deployCount, setDeployCount] = useState(0);
|
|
187
|
+
const [appVersion] = useState('1.0.0');
|
|
188
|
+
|
|
189
|
+
// Update state (takes effect next deployment)
|
|
190
|
+
setDeployCount(prev => (prev || 0) + 1);
|
|
191
|
+
|
|
192
|
+
return <></>;
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
**Advanced**: Can bind to provider outputs for reactivity:
|
|
197
|
+
|
|
198
|
+
```tsx
|
|
199
|
+
function DatabaseComponent() {
|
|
200
|
+
const db = useInstance(Database, { name: 'my-db' });
|
|
201
|
+
|
|
202
|
+
// This triggers re-renders when db.outputs.endpoint changes
|
|
203
|
+
const [endpoint, setEndpoint] = useState(db.outputs?.endpoint);
|
|
204
|
+
|
|
205
|
+
return <></>;
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### useContext - Share Dependencies
|
|
210
|
+
|
|
211
|
+
Shares data between components with reactivity when containing outputs:
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
const DatabaseContext = createContext<{ endpoint?: string }>({});
|
|
215
|
+
|
|
216
|
+
function DatabaseProvider({ children }) {
|
|
217
|
+
const db = useInstance(Database, { name: 'my-db' });
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
<DatabaseContext.Provider value={{
|
|
221
|
+
endpoint: db.outputs?.endpoint // Makes context reactive
|
|
222
|
+
}}>
|
|
223
|
+
{children}
|
|
224
|
+
</DatabaseContext.Provider>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function ApiConsumer() {
|
|
229
|
+
const { endpoint } = useContext(DatabaseContext); // Re-renders when endpoint available
|
|
230
|
+
|
|
231
|
+
const api = useInstance(ApiGateway, {
|
|
232
|
+
dbUrl: endpoint // Triggers re-render when endpoint changes
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
return <></>;
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Reactivity Mechanisms
|
|
240
|
+
|
|
241
|
+
CReact implements multiple interconnected reactivity systems:
|
|
242
|
+
|
|
243
|
+
1. **useState Binding**: `useState` can bind to provider outputs, triggering re-renders when outputs change
|
|
244
|
+
2. **Context Dependency Tracking**: Contexts containing outputs trigger re-renders in consuming components
|
|
245
|
+
3. **Output Change Detection**: Post-deployment effect system detects when provider outputs change
|
|
246
|
+
4. **Selective Re-rendering**: Only components affected by changes re-render
|
|
247
|
+
|
|
248
|
+
## Deployment Orchestration
|
|
249
|
+
|
|
250
|
+
### Reactive Deployment Cycles
|
|
251
|
+
|
|
252
|
+
```tsx
|
|
253
|
+
function MultiLayerApp() {
|
|
254
|
+
return (
|
|
255
|
+
<NetworkStack> {/* Layer 1: Deploy VPC first */}
|
|
256
|
+
<DatabaseStack> {/* Layer 2: Deploy DB/cache when VPC ready */}
|
|
257
|
+
<StorageStack> {/* Layer 3: Deploy S3/CDN when network ready */}
|
|
258
|
+
<ApiStack> {/* Layer 4: Deploy APIs when all deps ready */}
|
|
259
|
+
<MonitoringStack /> {/* Layer 5: Deploy monitoring last */}
|
|
260
|
+
</ApiStack>
|
|
261
|
+
</StorageStack>
|
|
262
|
+
</DatabaseStack>
|
|
263
|
+
</NetworkStack>
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
**Deployment Flow**:
|
|
269
|
+
1. **Initial Render**: All components create resource references
|
|
270
|
+
2. **Wave 1**: Network resources deploy (no dependencies)
|
|
271
|
+
3. **Wave 2**: Data resources deploy (depend on network outputs)
|
|
272
|
+
4. **Wave 3**: Storage resources deploy (depend on network outputs)
|
|
273
|
+
5. **Wave 4**: API resources deploy (depend on data + storage outputs)
|
|
274
|
+
6. **Wave 5**: Monitoring resources deploy (depend on API outputs)
|
|
275
|
+
|
|
276
|
+
## Provider Implementation
|
|
277
|
+
|
|
278
|
+
### Cloud Provider Example
|
|
279
|
+
|
|
280
|
+
```tsx
|
|
281
|
+
class AWSProvider implements ICloudProvider {
|
|
282
|
+
async materialize(resources: CloudDOMNode[]): Promise<void> {
|
|
283
|
+
for (const resource of resources) {
|
|
284
|
+
if (resource.construct?.name === 'Database') {
|
|
285
|
+
const db = await this.createRDSInstance(resource.props);
|
|
286
|
+
resource.outputs = {
|
|
287
|
+
endpoint: db.endpoint,
|
|
288
|
+
connectionUrl: db.connectionString
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
// Handle other resource types...
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Backend Provider Example
|
|
298
|
+
|
|
299
|
+
```tsx
|
|
300
|
+
class S3BackendProvider implements IBackendProvider {
|
|
301
|
+
async getState(stackName: string): Promise<any> {
|
|
302
|
+
const state = await this.s3.getObject({
|
|
303
|
+
Bucket: 'my-state-bucket',
|
|
304
|
+
Key: `${stackName}.json`
|
|
305
|
+
}).promise();
|
|
306
|
+
|
|
307
|
+
return JSON.parse(state.Body.toString());
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async saveState(stackName: string, state: any): Promise<void> {
|
|
311
|
+
await this.s3.putObject({
|
|
312
|
+
Bucket: 'my-state-bucket',
|
|
313
|
+
Key: `${stackName}.json`,
|
|
314
|
+
Body: JSON.stringify(state)
|
|
315
|
+
}).promise();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Real-World Example
|
|
321
|
+
|
|
322
|
+
Here's how the 5-layer enterprise application from the examples works:
|
|
323
|
+
|
|
324
|
+
```tsx
|
|
325
|
+
function EnterpriseApp() {
|
|
326
|
+
return (
|
|
327
|
+
<NetworkProvider> {/* VPC, subnets, security groups */}
|
|
328
|
+
<DatabaseProvider> {/* Database + cache */}
|
|
329
|
+
<StorageProvider> {/* S3 + CDN */}
|
|
330
|
+
<ApiProvider> {/* APIs + load balancer */}
|
|
331
|
+
<MonitoringProvider /> {/* Analytics + backups */}
|
|
332
|
+
</ApiProvider>
|
|
333
|
+
</StorageProvider>
|
|
334
|
+
</DatabaseProvider>
|
|
335
|
+
</NetworkProvider>
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Each provider component:
|
|
340
|
+
function NetworkProvider({ children }) {
|
|
341
|
+
const vpc = useInstance(VPC, { cidr: '10.0.0.0/16' });
|
|
342
|
+
|
|
343
|
+
return (
|
|
344
|
+
<NetworkContext.Provider value={{ vpcId: vpc.outputs?.vpcId }}>
|
|
345
|
+
{children}
|
|
346
|
+
</NetworkContext.Provider>
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function DatabaseProvider({ children }) {
|
|
351
|
+
const { vpcId } = useContext(NetworkContext);
|
|
352
|
+
|
|
353
|
+
const db = useInstance(Database, { vpcId });
|
|
354
|
+
const cache = useInstance(Redis, { vpcId });
|
|
355
|
+
|
|
356
|
+
return (
|
|
357
|
+
<DatabaseContext.Provider value={{
|
|
358
|
+
dbUrl: db.outputs?.endpoint,
|
|
359
|
+
cacheUrl: cache.outputs?.endpoint
|
|
360
|
+
}}>
|
|
361
|
+
{children}
|
|
362
|
+
</DatabaseContext.Provider>
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## Installation & Usage
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
# Deploy your infrastructure
|
|
371
|
+
creact deploy --entry my-app.tsx
|
|
372
|
+
|
|
373
|
+
# Development mode with hot reload
|
|
374
|
+
creact dev --entry my-app.tsx --auto-approve
|
|
375
|
+
|
|
376
|
+
# Preview changes
|
|
377
|
+
creact plan --entry my-app.tsx
|
|
378
|
+
```
|
|
379
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
/**
|
|
31
|
+
* Build Command - builds CloudDOM from entry file
|
|
32
|
+
*/
|
|
33
|
+
import { BaseCommand, CommandResult } from '../core/BaseCommand';
|
|
34
|
+
export declare class BuildCommand extends BaseCommand {
|
|
35
|
+
getName(): string;
|
|
36
|
+
getDescription(): string;
|
|
37
|
+
execute(): Promise<CommandResult>;
|
|
38
|
+
private printVerboseOutput;
|
|
39
|
+
private countResources;
|
|
40
|
+
}
|