@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,151 @@
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.BuildCommand = void 0;
33
+ /**
34
+ * Build Command - builds CloudDOM from entry file
35
+ */
36
+ const BaseCommand_1 = require("../core/BaseCommand");
37
+ const CLIContext_1 = require("../core/CLIContext");
38
+ const Output_1 = require("../../utils/Output");
39
+ const Logger_1 = require("../../utils/Logger");
40
+ const logger = Logger_1.LoggerFactory.getLogger('cli');
41
+ class BuildCommand extends BaseCommand_1.BaseCommand {
42
+ getName() {
43
+ return 'build';
44
+ }
45
+ getDescription() {
46
+ return 'Build CloudDOM from entry file';
47
+ }
48
+ async execute() {
49
+ const output = (0, Output_1.createOutputManager)({
50
+ json: this.json,
51
+ quiet: !!this.context.flags.quiet,
52
+ verbose: this.verbose,
53
+ });
54
+ try {
55
+ // Find entry file
56
+ logger.debug('BuildCommand: Starting execution');
57
+ let entryPath;
58
+ try {
59
+ entryPath = CLIContext_1.CLIContextManager.findEntryFile(this.context.flags.entry);
60
+ logger.debug(`BuildCommand: Entry file resolved to ${entryPath}`);
61
+ }
62
+ catch (error) {
63
+ output.showError('Entry file resolution failed', {
64
+ cause: error.message,
65
+ stackTrace: this.verbose ? error.stack : undefined,
66
+ });
67
+ return { exitCode: 1 };
68
+ }
69
+ // Load entry file and create CLI instance
70
+ output.showInfo('Loading entry file and configuring providers...');
71
+ let result;
72
+ try {
73
+ result = await CLIContext_1.CLIContextManager.createCLIInstance(entryPath, this.verbose);
74
+ logger.debug(`BuildCommand: CloudDOM built with ${result.cloudDOM.length} resources`);
75
+ }
76
+ catch (error) {
77
+ output.showError('Failed to load entry file and configure providers', {
78
+ cause: error.message,
79
+ stackTrace: this.verbose ? error.stack : undefined,
80
+ });
81
+ return { exitCode: 1 };
82
+ }
83
+ output.showSuccess('Entry file loaded and providers configured');
84
+ // Success output
85
+ const message = `Build complete: ${result.cloudDOM.length} resources`;
86
+ if (this.verbose && !this.json) {
87
+ this.printVerboseOutput(result, output);
88
+ }
89
+ output.showSuccess(message);
90
+ if (this.json) {
91
+ console.log(JSON.stringify({
92
+ status: 'success',
93
+ resourceCount: result.cloudDOM.length,
94
+ entryFile: entryPath,
95
+ stackName: result.stackName,
96
+ resources: result.cloudDOM.map((node) => ({
97
+ id: node.id,
98
+ type: node.construct?.name || 'Unknown',
99
+ path: node.path,
100
+ })),
101
+ }, null, 2));
102
+ }
103
+ return { exitCode: 0 };
104
+ }
105
+ catch (error) {
106
+ output.showError('Build failed', {
107
+ cause: error.message,
108
+ stackTrace: this.verbose ? error.stack : undefined,
109
+ });
110
+ return { exitCode: 1 };
111
+ }
112
+ }
113
+ printVerboseOutput(result, output) {
114
+ console.log('\nCloudDOM Summary:');
115
+ const resourceCounts = this.countResources(result.cloudDOM);
116
+ if (Object.keys(resourceCounts).length === 0) {
117
+ console.log(' No resources found');
118
+ }
119
+ else {
120
+ for (const [type, count] of Object.entries(resourceCounts)) {
121
+ console.log(` ${type}: ${count}`);
122
+ }
123
+ }
124
+ // Show first few resource IDs for debugging
125
+ if (result.cloudDOM.length > 0) {
126
+ console.log('\nResource IDs:');
127
+ const sampleIds = result.cloudDOM.slice(0, 5).map((node) => node.id);
128
+ sampleIds.forEach((id) => {
129
+ console.log(` • ${id}`);
130
+ });
131
+ if (result.cloudDOM.length > 5) {
132
+ console.log(` ... and ${result.cloudDOM.length - 5} more`);
133
+ }
134
+ }
135
+ }
136
+ countResources(cloudDOM) {
137
+ const counts = {};
138
+ const walk = (nodes) => {
139
+ for (const node of nodes) {
140
+ const type = node.construct?.name || 'Unknown';
141
+ counts[type] = (counts[type] || 0) + 1;
142
+ if (node.children && node.children.length > 0) {
143
+ walk(node.children);
144
+ }
145
+ }
146
+ };
147
+ walk(cloudDOM);
148
+ return counts;
149
+ }
150
+ }
151
+ exports.BuildCommand = BuildCommand;
@@ -0,0 +1,38 @@
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
+ * Deploy Command - deploys CloudDOM to cloud provider
32
+ */
33
+ import { BaseCommand, CommandResult } from '../core/BaseCommand';
34
+ export declare class DeployCommand extends BaseCommand {
35
+ getName(): string;
36
+ getDescription(): string;
37
+ execute(): Promise<CommandResult>;
38
+ }
@@ -0,0 +1,194 @@
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.DeployCommand = void 0;
33
+ /**
34
+ * Deploy Command - deploys CloudDOM to cloud provider
35
+ */
36
+ const BaseCommand_1 = require("../core/BaseCommand");
37
+ const CLIContext_1 = require("../core/CLIContext");
38
+ const Output_1 = require("../../utils/Output");
39
+ const Reconciler_1 = require("../../core/Reconciler");
40
+ const Logger_1 = require("../../utils/Logger");
41
+ const logger = Logger_1.LoggerFactory.getLogger('cli');
42
+ class DeployCommand extends BaseCommand_1.BaseCommand {
43
+ getName() {
44
+ return 'deploy';
45
+ }
46
+ getDescription() {
47
+ return 'Deploy CloudDOM to cloud provider';
48
+ }
49
+ async execute() {
50
+ const output = (0, Output_1.createOutputManager)({
51
+ json: this.json,
52
+ quiet: !!this.context.flags.quiet,
53
+ verbose: this.verbose,
54
+ });
55
+ const dryRun = !!this.context.flags['dry-run'];
56
+ try {
57
+ // Find entry file
58
+ logger.debug('DeployCommand: Starting execution');
59
+ let entryPath;
60
+ try {
61
+ entryPath = CLIContext_1.CLIContextManager.findEntryFile(this.context.flags.entry);
62
+ logger.debug(`DeployCommand: Entry file resolved to ${entryPath}`);
63
+ }
64
+ catch (error) {
65
+ output.showError('Entry file resolution failed', {
66
+ cause: error.message,
67
+ stackTrace: this.verbose ? error.stack : undefined,
68
+ });
69
+ return { exitCode: 1 };
70
+ }
71
+ // Load entry file and create CLI instance
72
+ output.showInfo('Loading entry file and configuring providers...');
73
+ let result;
74
+ try {
75
+ result = await CLIContext_1.CLIContextManager.createCLIInstance(entryPath, this.verbose);
76
+ logger.debug(`DeployCommand: CloudDOM built with ${result.cloudDOM.length} resources`);
77
+ }
78
+ catch (error) {
79
+ output.showError('Failed to load entry file and configure providers', {
80
+ cause: error.message,
81
+ stackTrace: this.verbose ? error.stack : undefined,
82
+ });
83
+ return { exitCode: 1 };
84
+ }
85
+ output.showSuccess('Entry file loaded and providers configured');
86
+ // Validate providers
87
+ output.showInfo('Validating providers...');
88
+ if (!result.instance.getCloudProvider()) {
89
+ output.showError('Cloud provider not configured', {
90
+ cause: 'CReact.cloudProvider must be set in entry file',
91
+ });
92
+ return { exitCode: 1 };
93
+ }
94
+ if (!result.instance.getBackendProvider()) {
95
+ output.showError('Backend provider not configured', {
96
+ cause: 'CReact.backendProvider must be set in entry file',
97
+ });
98
+ return { exitCode: 1 };
99
+ }
100
+ output.showSuccess('Providers validated');
101
+ // Load previous state and show plan
102
+ output.showInfo('Loading previous state...');
103
+ let previousCloudDOM = [];
104
+ try {
105
+ const previousState = await result.instance.getBackendProvider().getState(result.stackName);
106
+ if (previousState && previousState.cloudDOM) {
107
+ previousCloudDOM = previousState.cloudDOM;
108
+ logger.debug(`DeployCommand: Previous CloudDOM loaded with ${previousCloudDOM.length} resources`);
109
+ }
110
+ else {
111
+ logger.debug('DeployCommand: No previous state found (first deployment)');
112
+ }
113
+ }
114
+ catch (stateError) {
115
+ logger.debug(`DeployCommand: Could not load previous state: ${stateError.message}`);
116
+ }
117
+ // Compute and show plan
118
+ const reconciler = new Reconciler_1.Reconciler();
119
+ const changeSet = reconciler.reconcile(previousCloudDOM, result.cloudDOM);
120
+ output.showPlanHeader(result.stackName);
121
+ output.showPlanChanges(changeSet);
122
+ output.showPlanSummary(changeSet);
123
+ if (dryRun) {
124
+ logger.debug('DeployCommand: Dry run mode - deployment will be simulated');
125
+ output.showInfo('Dry run mode - no changes will be applied');
126
+ return { exitCode: 0 };
127
+ }
128
+ // Deploy using CReact instance
129
+ output.showDeployHeader();
130
+ const startTime = Date.now();
131
+ const deployedResources = [];
132
+ try {
133
+ // Track deployment progress
134
+ for (const nodeId of changeSet.deploymentOrder) {
135
+ const node = [...changeSet.creates, ...changeSet.updates].find((n) => n.id === nodeId);
136
+ if (node) {
137
+ const action = changeSet.creates.includes(node) ? 'Creating' : 'Updating';
138
+ const resourceStart = Date.now();
139
+ output.showResourceProgress(nodeId, action);
140
+ // Actual deployment happens in CReact.deploy()
141
+ // This is just for progress tracking
142
+ deployedResources.push(nodeId);
143
+ const resourceDuration = (Date.now() - resourceStart) / 1000;
144
+ output.showResourceComplete(nodeId, action.replace('ing', 'ed'), resourceDuration);
145
+ }
146
+ }
147
+ await result.instance.deploy(result.cloudDOM, result.stackName, 'cli-user');
148
+ const duration = (Date.now() - startTime) / 1000;
149
+ const deployResult = {
150
+ resourceCount: result.cloudDOM.length,
151
+ duration,
152
+ creates: changeSet.creates.length,
153
+ updates: changeSet.updates.length,
154
+ deletes: changeSet.deletes.length,
155
+ };
156
+ output.showDeploySummary(deployResult);
157
+ if (this.json) {
158
+ console.log(JSON.stringify({
159
+ status: 'success',
160
+ ...deployResult,
161
+ stackName: result.stackName,
162
+ entryFile: entryPath,
163
+ }, null, 2));
164
+ }
165
+ return { exitCode: 0 };
166
+ }
167
+ catch (deployError) {
168
+ const duration = (Date.now() - startTime) / 1000;
169
+ const deployResult = {
170
+ resourceCount: result.cloudDOM.length,
171
+ duration,
172
+ creates: changeSet.creates.length,
173
+ updates: changeSet.updates.length,
174
+ deletes: changeSet.deletes.length,
175
+ errors: [{ resourceId: 'unknown', message: deployError.message }],
176
+ };
177
+ output.showDeploySummary(deployResult);
178
+ output.showError('Deployment failed', {
179
+ cause: deployError.message,
180
+ stackTrace: this.verbose ? deployError.stack : undefined,
181
+ });
182
+ return { exitCode: 1 };
183
+ }
184
+ }
185
+ catch (error) {
186
+ output.showError('Deploy command failed', {
187
+ cause: error.message,
188
+ stackTrace: this.verbose ? error.stack : undefined,
189
+ });
190
+ return { exitCode: 1 };
191
+ }
192
+ }
193
+ }
194
+ exports.DeployCommand = DeployCommand;
@@ -0,0 +1,52 @@
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
+ * Dev Command - hot reload development mode with auto/manual approval
32
+ */
33
+ import { BaseCommand, CommandResult } from '../core/BaseCommand';
34
+ export declare class DevCommand extends BaseCommand {
35
+ private isWatching;
36
+ private watchTimeout;
37
+ private autoApprove;
38
+ private currentReadline;
39
+ private output;
40
+ private state;
41
+ getName(): string;
42
+ getDescription(): string;
43
+ execute(): Promise<CommandResult>;
44
+ private performInitialDeploy;
45
+ private performHotReload;
46
+ private deployChanges;
47
+ private promptForApproval;
48
+ private startWatching;
49
+ private shouldIgnoreFile;
50
+ private keepAlive;
51
+ private stopWatching;
52
+ }