@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,220 @@
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.LoggerFactory = exports.Logger = void 0;
33
+ /**
34
+ * Log level priorities for filtering
35
+ */
36
+ const LOG_LEVEL_PRIORITY = {
37
+ debug: 0,
38
+ info: 1,
39
+ warn: 2,
40
+ error: 3,
41
+ };
42
+ /**
43
+ * Scoped logger with level filtering
44
+ */
45
+ class Logger {
46
+ constructor(scope, config, context = {}) {
47
+ this.scope = scope;
48
+ this.config = config;
49
+ this.context = context;
50
+ // Check if this scope is enabled
51
+ this.enabled = config.scopes.includes('*') || config.scopes.includes(scope);
52
+ }
53
+ /**
54
+ * Log a debug message
55
+ */
56
+ debug(message, ...args) {
57
+ this.log('debug', message, ...args);
58
+ }
59
+ /**
60
+ * Log an info message
61
+ */
62
+ info(message, ...args) {
63
+ this.log('info', message, ...args);
64
+ }
65
+ /**
66
+ * Log a warning message
67
+ */
68
+ warn(message, ...args) {
69
+ this.log('warn', message, ...args);
70
+ }
71
+ /**
72
+ * Log an error message
73
+ */
74
+ error(message, ...args) {
75
+ this.log('error', message, ...args);
76
+ }
77
+ /**
78
+ * Create a child logger with additional context
79
+ */
80
+ child(additionalContext) {
81
+ return new Logger(this.scope, this.config, {
82
+ ...this.context,
83
+ ...additionalContext,
84
+ });
85
+ }
86
+ /**
87
+ * Internal log method with filtering
88
+ */
89
+ log(level, message, ...args) {
90
+ // Zero overhead when scope is disabled
91
+ if (!this.enabled) {
92
+ return;
93
+ }
94
+ // Filter by log level
95
+ if (LOG_LEVEL_PRIORITY[level] < LOG_LEVEL_PRIORITY[this.config.level]) {
96
+ return;
97
+ }
98
+ // Format: [timestamp] [scope] [level] message
99
+ const timestamp = new Date().toISOString();
100
+ const contextStr = Object.keys(this.context).length ? ` ${JSON.stringify(this.context)}` : '';
101
+ const formattedMessage = `[${timestamp}] [${this.scope}] [${level.toUpperCase()}]${contextStr} ${message}`;
102
+ // Output to stderr (not stdout) for all log levels
103
+ // This ensures user-facing output (stdout) is separate from debug logs (stderr)
104
+ switch (level) {
105
+ case 'debug':
106
+ case 'info':
107
+ console.error(formattedMessage, ...args);
108
+ break;
109
+ case 'warn':
110
+ console.warn(formattedMessage, ...args);
111
+ break;
112
+ case 'error':
113
+ console.error(formattedMessage, ...args);
114
+ break;
115
+ }
116
+ }
117
+ }
118
+ exports.Logger = Logger;
119
+ /**
120
+ * Logger factory for creating scoped loggers
121
+ */
122
+ class LoggerFactory {
123
+ /**
124
+ * Configure the logger factory
125
+ */
126
+ static configure(config) {
127
+ this.config = {
128
+ scopes: config.scopes ?? this.config.scopes,
129
+ level: config.level ?? this.config.level,
130
+ };
131
+ }
132
+ /**
133
+ * Get a logger for a specific scope
134
+ */
135
+ static getLogger(scope) {
136
+ return new Logger(scope, this.config);
137
+ }
138
+ /**
139
+ * Parse configuration from environment variables
140
+ * Supports CREACT_LOG=scope1,scope2 or CREACT_LOG=*
141
+ * Supports CREACT_LOG_LEVEL=debug|info|warn|error
142
+ */
143
+ static configureFromEnv() {
144
+ const scopesEnv = process.env.CREACT_LOG;
145
+ const levelEnv = process.env.CREACT_LOG_LEVEL;
146
+ const config = {};
147
+ if (scopesEnv) {
148
+ config.scopes = scopesEnv.split(',').map((s) => s.trim());
149
+ }
150
+ if (levelEnv && this.isValidLogLevel(levelEnv)) {
151
+ config.level = levelEnv;
152
+ }
153
+ if (Object.keys(config).length > 0) {
154
+ this.configure(config);
155
+ }
156
+ }
157
+ /**
158
+ * Parse configuration from CLI flags
159
+ * Supports --log=scope1,scope2 or --log=*
160
+ * Supports --log-level=debug|info|warn|error
161
+ */
162
+ static configureFromCLI(args) {
163
+ const config = {};
164
+ if (args.log) {
165
+ config.scopes = args.log.split(',').map((s) => s.trim());
166
+ }
167
+ if (args.logLevel && this.isValidLogLevel(args.logLevel)) {
168
+ config.level = args.logLevel;
169
+ }
170
+ if (Object.keys(config).length > 0) {
171
+ this.configure(config);
172
+ }
173
+ }
174
+ /**
175
+ * Parse configuration from config file
176
+ */
177
+ static configureFromFile(fileConfig) {
178
+ if (!fileConfig.log) {
179
+ return;
180
+ }
181
+ const config = {};
182
+ if (fileConfig.log.scopes) {
183
+ config.scopes = fileConfig.log.scopes;
184
+ }
185
+ if (fileConfig.log.level && this.isValidLogLevel(fileConfig.log.level)) {
186
+ config.level = fileConfig.log.level;
187
+ }
188
+ if (Object.keys(config).length > 0) {
189
+ this.configure(config);
190
+ }
191
+ }
192
+ /**
193
+ * Get current configuration
194
+ */
195
+ static getConfig() {
196
+ return { ...this.config };
197
+ }
198
+ /**
199
+ * Reset configuration to defaults
200
+ */
201
+ static reset() {
202
+ this.config = {
203
+ scopes: [],
204
+ level: 'info',
205
+ };
206
+ }
207
+ /**
208
+ * Check if a string is a valid log level
209
+ */
210
+ static isValidLogLevel(level) {
211
+ return ['debug', 'info', 'warn', 'error'].includes(level);
212
+ }
213
+ }
214
+ exports.LoggerFactory = LoggerFactory;
215
+ LoggerFactory.config = {
216
+ scopes: [],
217
+ level: 'info',
218
+ };
219
+ // Auto-configure from environment variables on module load
220
+ LoggerFactory.configureFromEnv();
@@ -0,0 +1,161 @@
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 type { ChangeSet } from '../core/types';
31
+ /**
32
+ * Output mode configuration
33
+ */
34
+ export type OutputMode = 'normal' | 'json' | 'quiet';
35
+ /**
36
+ * Output Manager configuration options
37
+ */
38
+ export interface OutputOptions {
39
+ /** Output mode (normal, json, quiet) */
40
+ mode: OutputMode;
41
+ /** Enable colors (default: true for normal mode, false for json/quiet) */
42
+ colors?: boolean;
43
+ /** Enable verbose error output with stack traces */
44
+ verbose?: boolean;
45
+ }
46
+ /**
47
+ * Error context for detailed error reporting
48
+ */
49
+ export interface ErrorContext {
50
+ /** Resource ID where error occurred */
51
+ resourceId?: string;
52
+ /** Root cause of the error */
53
+ cause?: string;
54
+ /** Stack trace (shown only in verbose mode) */
55
+ stackTrace?: string;
56
+ }
57
+ /**
58
+ * Deployment result summary
59
+ */
60
+ export interface DeployResult {
61
+ /** Total number of resources processed */
62
+ resourceCount: number;
63
+ /** Total deployment duration in seconds */
64
+ duration: number;
65
+ /** Number of resources created */
66
+ creates: number;
67
+ /** Number of resources updated */
68
+ updates: number;
69
+ /** Number of resources deleted */
70
+ deletes: number;
71
+ /** Errors encountered during deployment */
72
+ errors?: Array<{
73
+ resourceId: string;
74
+ message: string;
75
+ }>;
76
+ }
77
+ /**
78
+ * Output Manager - Handles all user-facing CLI output
79
+ */
80
+ export declare class OutputManager {
81
+ private readonly mode;
82
+ private readonly colors;
83
+ private readonly verbose;
84
+ constructor(options: OutputOptions);
85
+ /**
86
+ * Show success message
87
+ */
88
+ showSuccess(message: string): void;
89
+ /**
90
+ * Show info message
91
+ */
92
+ showInfo(message: string): void;
93
+ /**
94
+ * Show warning message
95
+ */
96
+ showWarning(message: string): void;
97
+ /**
98
+ * Show error message with optional context
99
+ */
100
+ showError(message: string, context?: ErrorContext): void;
101
+ /**
102
+ * Show plan header with stack name
103
+ */
104
+ showPlanHeader(stackName: string): void;
105
+ /**
106
+ * Show planned changes with diff visualization
107
+ */
108
+ showPlanChanges(changeSet: ChangeSet): void;
109
+ /**
110
+ * Show plan summary with change counts
111
+ */
112
+ showPlanSummary(changeSet: ChangeSet): void;
113
+ /**
114
+ * Show deployment header
115
+ */
116
+ showDeployHeader(): void;
117
+ /**
118
+ * Show resource deployment progress
119
+ */
120
+ showResourceProgress(id: string, action: string): void;
121
+ /**
122
+ * Show resource deployment completion
123
+ */
124
+ showResourceComplete(id: string, action: string, duration: number): void;
125
+ /**
126
+ * Show deployment summary
127
+ */
128
+ showDeploySummary(result: DeployResult): void;
129
+ /**
130
+ * Show reactive changes detected notification
131
+ */
132
+ showReactiveChangesDetected(): void;
133
+ /**
134
+ * Show file changed notification
135
+ */
136
+ showFileChanged(filename: string): void;
137
+ /**
138
+ * Show hot reload start notification
139
+ */
140
+ showHotReloadStart(): void;
141
+ /**
142
+ * Output JSON to stdout
143
+ */
144
+ private outputJson;
145
+ /**
146
+ * Format node ID for display
147
+ */
148
+ private formatNodeId;
149
+ /**
150
+ * Convert CloudDOM node to JSON representation
151
+ */
152
+ private nodeToJson;
153
+ }
154
+ /**
155
+ * Create an Output Manager from CLI flags
156
+ */
157
+ export declare function createOutputManager(flags: {
158
+ json?: boolean;
159
+ quiet?: boolean;
160
+ verbose?: boolean;
161
+ }): OutputManager;