@creact-labs/creact 0.1.8 → 0.2.1

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 (146) hide show
  1. package/README.md +85 -22
  2. package/dist/cli.d.ts +11 -0
  3. package/dist/cli.js +88 -0
  4. package/dist/index.d.ts +19 -44
  5. package/dist/index.js +20 -68
  6. package/dist/jsx/index.d.ts +2 -0
  7. package/dist/jsx/index.js +1 -0
  8. package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
  9. package/dist/jsx/jsx-dev-runtime.js +4 -0
  10. package/dist/jsx/jsx-runtime.d.ts +38 -0
  11. package/dist/jsx/jsx-runtime.js +38 -0
  12. package/dist/jsx/types.d.ts +12 -0
  13. package/dist/jsx/types.js +4 -0
  14. package/dist/primitives/context.d.ts +34 -0
  15. package/dist/primitives/context.js +63 -0
  16. package/dist/primitives/index.d.ts +3 -0
  17. package/dist/primitives/index.js +3 -0
  18. package/dist/primitives/instance.d.ts +72 -0
  19. package/dist/primitives/instance.js +235 -0
  20. package/dist/primitives/store.d.ts +22 -0
  21. package/dist/primitives/store.js +97 -0
  22. package/dist/provider/backend.d.ts +110 -0
  23. package/dist/provider/backend.js +37 -0
  24. package/dist/provider/interface.d.ts +48 -0
  25. package/dist/provider/interface.js +39 -0
  26. package/dist/reactive/effect.d.ts +11 -0
  27. package/dist/reactive/effect.js +42 -0
  28. package/dist/reactive/index.d.ts +3 -0
  29. package/dist/reactive/index.js +3 -0
  30. package/dist/reactive/signal.d.ts +32 -0
  31. package/dist/reactive/signal.js +60 -0
  32. package/dist/reactive/tracking.d.ts +41 -0
  33. package/dist/reactive/tracking.js +161 -0
  34. package/dist/runtime/fiber.d.ts +21 -0
  35. package/dist/runtime/fiber.js +16 -0
  36. package/dist/runtime/index.d.ts +4 -0
  37. package/dist/runtime/index.js +4 -0
  38. package/dist/runtime/reconcile.d.ts +66 -0
  39. package/dist/runtime/reconcile.js +210 -0
  40. package/dist/runtime/render.d.ts +42 -0
  41. package/dist/runtime/render.js +231 -0
  42. package/dist/runtime/run.d.ts +119 -0
  43. package/dist/runtime/run.js +334 -0
  44. package/dist/runtime/state-machine.d.ts +95 -0
  45. package/dist/runtime/state-machine.js +209 -0
  46. package/dist/types.d.ts +13 -0
  47. package/dist/types.js +4 -0
  48. package/package.json +29 -24
  49. package/dist/cli/commands/BuildCommand.d.ts +0 -40
  50. package/dist/cli/commands/BuildCommand.js +0 -151
  51. package/dist/cli/commands/DeployCommand.d.ts +0 -38
  52. package/dist/cli/commands/DeployCommand.js +0 -194
  53. package/dist/cli/commands/DevCommand.d.ts +0 -52
  54. package/dist/cli/commands/DevCommand.js +0 -394
  55. package/dist/cli/commands/PlanCommand.d.ts +0 -39
  56. package/dist/cli/commands/PlanCommand.js +0 -164
  57. package/dist/cli/commands/index.d.ts +0 -36
  58. package/dist/cli/commands/index.js +0 -43
  59. package/dist/cli/core/ArgumentParser.d.ts +0 -46
  60. package/dist/cli/core/ArgumentParser.js +0 -127
  61. package/dist/cli/core/BaseCommand.d.ts +0 -75
  62. package/dist/cli/core/BaseCommand.js +0 -95
  63. package/dist/cli/core/CLIContext.d.ts +0 -68
  64. package/dist/cli/core/CLIContext.js +0 -183
  65. package/dist/cli/core/CommandRegistry.d.ts +0 -64
  66. package/dist/cli/core/CommandRegistry.js +0 -89
  67. package/dist/cli/core/index.d.ts +0 -36
  68. package/dist/cli/core/index.js +0 -43
  69. package/dist/cli/index.d.ts +0 -35
  70. package/dist/cli/index.js +0 -100
  71. package/dist/cli/output.d.ts +0 -204
  72. package/dist/cli/output.js +0 -437
  73. package/dist/cli/utils.d.ts +0 -59
  74. package/dist/cli/utils.js +0 -76
  75. package/dist/context/createContext.d.ts +0 -90
  76. package/dist/context/createContext.js +0 -113
  77. package/dist/context/index.d.ts +0 -30
  78. package/dist/context/index.js +0 -35
  79. package/dist/core/CReact.d.ts +0 -409
  80. package/dist/core/CReact.js +0 -1151
  81. package/dist/core/CloudDOMBuilder.d.ts +0 -447
  82. package/dist/core/CloudDOMBuilder.js +0 -1234
  83. package/dist/core/ContextDependencyTracker.d.ts +0 -165
  84. package/dist/core/ContextDependencyTracker.js +0 -448
  85. package/dist/core/ErrorRecoveryManager.d.ts +0 -145
  86. package/dist/core/ErrorRecoveryManager.js +0 -443
  87. package/dist/core/EventBus.d.ts +0 -91
  88. package/dist/core/EventBus.js +0 -185
  89. package/dist/core/ProviderOutputTracker.d.ts +0 -211
  90. package/dist/core/ProviderOutputTracker.js +0 -476
  91. package/dist/core/ReactiveUpdateQueue.d.ts +0 -76
  92. package/dist/core/ReactiveUpdateQueue.js +0 -121
  93. package/dist/core/Reconciler.d.ts +0 -415
  94. package/dist/core/Reconciler.js +0 -1044
  95. package/dist/core/RenderScheduler.d.ts +0 -153
  96. package/dist/core/RenderScheduler.js +0 -519
  97. package/dist/core/Renderer.d.ts +0 -336
  98. package/dist/core/Renderer.js +0 -944
  99. package/dist/core/Runtime.d.ts +0 -246
  100. package/dist/core/Runtime.js +0 -640
  101. package/dist/core/StateBindingManager.d.ts +0 -121
  102. package/dist/core/StateBindingManager.js +0 -309
  103. package/dist/core/StateMachine.d.ts +0 -441
  104. package/dist/core/StateMachine.js +0 -883
  105. package/dist/core/StructuralChangeDetector.d.ts +0 -140
  106. package/dist/core/StructuralChangeDetector.js +0 -363
  107. package/dist/core/Validator.d.ts +0 -127
  108. package/dist/core/Validator.js +0 -279
  109. package/dist/core/errors.d.ts +0 -153
  110. package/dist/core/errors.js +0 -202
  111. package/dist/core/index.d.ts +0 -38
  112. package/dist/core/index.js +0 -64
  113. package/dist/core/types.d.ts +0 -265
  114. package/dist/core/types.js +0 -48
  115. package/dist/hooks/context.d.ts +0 -147
  116. package/dist/hooks/context.js +0 -334
  117. package/dist/hooks/useContext.d.ts +0 -113
  118. package/dist/hooks/useContext.js +0 -169
  119. package/dist/hooks/useEffect.d.ts +0 -105
  120. package/dist/hooks/useEffect.js +0 -540
  121. package/dist/hooks/useInstance.d.ts +0 -139
  122. package/dist/hooks/useInstance.js +0 -455
  123. package/dist/hooks/useState.d.ts +0 -120
  124. package/dist/hooks/useState.js +0 -298
  125. package/dist/jsx.d.ts +0 -143
  126. package/dist/jsx.js +0 -76
  127. package/dist/providers/DummyBackendProvider.d.ts +0 -193
  128. package/dist/providers/DummyBackendProvider.js +0 -189
  129. package/dist/providers/DummyCloudProvider.d.ts +0 -128
  130. package/dist/providers/DummyCloudProvider.js +0 -157
  131. package/dist/providers/IBackendProvider.d.ts +0 -177
  132. package/dist/providers/IBackendProvider.js +0 -31
  133. package/dist/providers/ICloudProvider.d.ts +0 -230
  134. package/dist/providers/ICloudProvider.js +0 -31
  135. package/dist/providers/index.d.ts +0 -31
  136. package/dist/providers/index.js +0 -31
  137. package/dist/test-event-callbacks.d.ts +0 -0
  138. package/dist/test-event-callbacks.js +0 -1
  139. package/dist/utils/Logger.d.ts +0 -144
  140. package/dist/utils/Logger.js +0 -220
  141. package/dist/utils/Output.d.ts +0 -161
  142. package/dist/utils/Output.js +0 -401
  143. package/dist/utils/deepEqual.d.ts +0 -71
  144. package/dist/utils/deepEqual.js +0 -276
  145. package/dist/utils/naming.d.ts +0 -241
  146. package/dist/utils/naming.js +0 -376
@@ -1,64 +0,0 @@
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
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
32
- if (k2 === undefined) k2 = k;
33
- var desc = Object.getOwnPropertyDescriptor(m, k);
34
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
35
- desc = { enumerable: true, get: function() { return m[k]; } };
36
- }
37
- Object.defineProperty(o, k2, desc);
38
- }) : (function(o, m, k, k2) {
39
- if (k2 === undefined) k2 = k;
40
- o[k2] = m[k];
41
- }));
42
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
43
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
44
- };
45
- Object.defineProperty(exports, "__esModule", { value: true });
46
- exports.StateMachine = exports.ProviderError = exports.ValidationError = exports.DeploymentError = exports.ReconciliationError = exports.Reconciler = exports.CloudDOMEventBus = void 0;
47
- // REQ-01: Core module exports
48
- __exportStar(require("./types"), exports);
49
- __exportStar(require("./Renderer"), exports);
50
- __exportStar(require("./Validator"), exports);
51
- __exportStar(require("./CloudDOMBuilder"), exports);
52
- __exportStar(require("./CReact"), exports);
53
- var EventBus_1 = require("./EventBus");
54
- Object.defineProperty(exports, "CloudDOMEventBus", { enumerable: true, get: function () { return EventBus_1.CloudDOMEventBus; } });
55
- var Reconciler_1 = require("./Reconciler");
56
- Object.defineProperty(exports, "Reconciler", { enumerable: true, get: function () { return Reconciler_1.Reconciler; } });
57
- var errors_1 = require("./errors");
58
- Object.defineProperty(exports, "ReconciliationError", { enumerable: true, get: function () { return errors_1.ReconciliationError; } });
59
- Object.defineProperty(exports, "DeploymentError", { enumerable: true, get: function () { return errors_1.DeploymentError; } });
60
- Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_1.ValidationError; } });
61
- Object.defineProperty(exports, "ProviderError", { enumerable: true, get: function () { return errors_1.ProviderError; } });
62
- var StateMachine_1 = require("./StateMachine");
63
- Object.defineProperty(exports, "StateMachine", { enumerable: true, get: function () { return StateMachine_1.StateMachine; } });
64
- // Runtime removed - not being used, CReact handles all orchestration
@@ -1,265 +0,0 @@
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
- * Fiber Node - Intermediate representation of JSX tree
32
- * Contains all components (containers + resources) before filtering to CloudDOM
33
- */
34
- export interface FiberNode {
35
- /** Component type (function or class) */
36
- type: any;
37
- /** Props passed to the component */
38
- props: Record<string, any>;
39
- /** Child Fiber nodes */
40
- children: FiberNode[];
41
- /** Hierarchical path from root (e.g., ['registry', 'service']) */
42
- path: string[];
43
- /** CloudDOM nodes attached by useInstance calls (if any) */
44
- cloudDOMNodes?: CloudDOMNode[];
45
- /** Hooks attached by useState/useEffect calls (if any) */
46
- hooks?: any[];
47
- /** State attached by useState (if any) */
48
- state?: Record<string, any>;
49
- /** Key for stable identity (optional) */
50
- key?: string | number;
51
- /** Reactive state tracking for re-rendering system */
52
- reactiveState?: {
53
- /** Reason for the last re-render */
54
- lastRenderReason?: ReRenderReason;
55
- /** Timestamp of the last render */
56
- lastRenderTime?: number;
57
- /** Total number of times this component has been rendered */
58
- renderCount: number;
59
- /** Whether this component needs re-rendering */
60
- isDirty: boolean;
61
- /** Whether this component has a pending update (mark-and-sweep model) */
62
- updatePending: boolean;
63
- /** Context IDs that triggered the pending update (for debugging) */
64
- pendingContexts?: Set<symbol>;
65
- };
66
- /** Dependency tracking for selective re-rendering */
67
- dependencies?: Set<FiberNode>;
68
- /** Components that depend on this component */
69
- dependents?: Set<FiberNode>;
70
- /** Effect bindings for reactive system integration */
71
- effectBindings?: Map<number, {
72
- boundOutputs: string[];
73
- registeredAt: number;
74
- }>;
75
- /** Context stack snapshot at the time this component was rendered */
76
- contextSnapshot?: Map<symbol, any[]>;
77
- }
78
- /**
79
- * CloudDOM Event Callbacks - Lifecycle event handlers for resources
80
- * These are extracted from component props and triggered during deployment
81
- */
82
- export interface CloudDOMEventCallbacks {
83
- /** Called when resource deployment starts */
84
- onDeploy?: (context: CloudDOMEventContext) => void | Promise<void>;
85
- /** Called when resource deployment fails */
86
- onError?: (context: CloudDOMEventContext, error: Error) => void | Promise<void>;
87
- /** Called when resource is destroyed/deleted */
88
- onDestroy?: (context: CloudDOMEventContext) => void | Promise<void>;
89
- }
90
- /**
91
- * CloudDOM Event Context - Information passed to event callbacks
92
- */
93
- export interface CloudDOMEventContext {
94
- /** Resource ID */
95
- resourceId: string;
96
- /** Resource path */
97
- path: string[];
98
- /** Construct type */
99
- construct: any;
100
- /** Resource props (without event callbacks) */
101
- props: Record<string, any>;
102
- /** Resource outputs (if available) */
103
- outputs?: Record<string, any>;
104
- /** Deployment phase */
105
- phase: 'deploy' | 'error' | 'destroy';
106
- /** Timestamp when event occurred */
107
- timestamp: number;
108
- }
109
- /**
110
- * Event callback props that are automatically available to components using useInstance
111
- */
112
- export interface CloudDOMEventProps {
113
- /** Called when resource deployment starts */
114
- onDeploy?: (ctx: CloudDOMEventContext) => void | Promise<void>;
115
- /** Called when resource deployment fails */
116
- onError?: (ctx: CloudDOMEventContext, error: Error) => void | Promise<void>;
117
- /** Called when resource is destroyed/deleted */
118
- onDestroy?: (ctx: CloudDOMEventContext) => void | Promise<void>;
119
- }
120
- /**
121
- * Utility type that adds event callback props to any component props
122
- * Use this for components that call useInstance
123
- */
124
- export type WithCloudDOMEvents<T = {}> = T & CloudDOMEventProps;
125
- /**
126
- * CloudDOM Node - Represents actual cloud resources
127
- * Only includes components that called useInstance
128
- */
129
- export interface CloudDOMNode {
130
- /** Unique resource ID (e.g., 'registry.service') */
131
- id: string;
132
- /** Hierarchical path (e.g., ['registry', 'service']) */
133
- path: string[];
134
- /** Construct type (e.g., EcrRepository, AppRunnerService) */
135
- construct: any;
136
- /** Serializable construct type name (e.g., 'EcrRepository', 'AppRunnerService') */
137
- constructType: string;
138
- /** Props for the construct */
139
- props: Record<string, any>;
140
- /** Child CloudDOM nodes */
141
- children: CloudDOMNode[];
142
- /** Infrastructure outputs from cloud provider (e.g., connectionUrl, port, bucketName) */
143
- outputs?: Record<string, any>;
144
- /** Application state from useState hooks (e.g., { state1: "...", state2: 123 }) */
145
- state?: Record<string, any>;
146
- /** Event callbacks extracted from component props (optional) */
147
- eventCallbacks?: CloudDOMEventCallbacks;
148
- /** Internal: Cached shallow hash of props for fast diff (optional) */
149
- _propHash?: string;
150
- }
151
- /**
152
- * JSX Element type
153
- */
154
- export interface JSXElement {
155
- type: any;
156
- props: any;
157
- key?: string | number;
158
- }
159
- /**
160
- * ChangeSet represents the minimal set of operations to reconcile two CloudDOM states
161
- *
162
- * REQ-O01: State Machine needs diff to detect changes
163
- * REQ-O04: Plan Command needs diff to show preview
164
- */
165
- export interface ChangeSet {
166
- /** Nodes that exist in current but not in previous (need to be created) */
167
- creates: CloudDOMNode[];
168
- /** Nodes that exist in both but have different props (need to be updated) */
169
- updates: CloudDOMNode[];
170
- /** Nodes that exist in previous but not in current (need to be deleted) */
171
- deletes: CloudDOMNode[];
172
- /** Nodes that changed type (need to be replaced: delete + create) */
173
- replacements: CloudDOMNode[];
174
- /** Nodes that moved in the hierarchy (includes node ID for traceability) */
175
- moves: Array<{
176
- nodeId: string;
177
- from: string;
178
- to: string;
179
- }>;
180
- /** Deployment order based on dependency graph (topologically sorted) */
181
- deploymentOrder: string[];
182
- /** Parallel deployment batches (nodes at same depth can deploy in parallel) */
183
- parallelBatches: string[][];
184
- }
185
- /**
186
- * Get filtered deployment order containing only resources that need deployment
187
- * (creates, updates, replacements) - excludes unchanged resources
188
- *
189
- * @param changeSet - The change set to filter
190
- * @returns Array of resource IDs that need deployment, in dependency order
191
- */
192
- export declare function getResourcesToDeploy(changeSet: ChangeSet): string[];
193
- /**
194
- * DependencyGraph represents resource dependencies for deployment ordering
195
- *
196
- * Maps node ID → array of dependency IDs
197
- */
198
- export interface DependencyGraph {
199
- /** Adjacency list: node ID → dependency IDs */
200
- dependencies: Map<string, string[]>;
201
- /** Reverse adjacency list: node ID → dependent IDs (nodes that depend on this node) */
202
- dependents: Map<string, string[]>;
203
- }
204
- /**
205
- * ReRenderReason - Reasons why a component re-render was triggered
206
- * Used for debugging, performance monitoring, and selective re-rendering
207
- *
208
- * Note: useState changes alone do NOT trigger re-renders in CReact.
209
- * Re-renders only occur when provider outputs that are bound to state change.
210
- */
211
- export type ReRenderReason = 'output-update' | 'context-change' | 'structural-change' | 'hot-reload' | 'manual';
212
- /**
213
- * CReactEvents - Lifecycle event hooks for reactive system
214
- * Optional interface for tooling, debugging, and performance monitoring
215
- */
216
- export interface CReactEvents {
217
- /** Called when a component render starts */
218
- onRenderStart(fiber: FiberNode): void;
219
- /** Called when a component render completes successfully */
220
- onRenderComplete(fiber: FiberNode): void;
221
- /** Called when deployment starts for a stack */
222
- onDeployStart(stack: string): void;
223
- /** Called when deployment completes successfully for a stack */
224
- onDeployComplete(stack: string): void;
225
- /** Called when an error occurs during rendering or deployment */
226
- onError(error: Error, fiber?: FiberNode): void;
227
- /** Called when a context value is updated (for observability) */
228
- onContextUpdate?(contextId: symbol, previousValue: any, newValue: any): void;
229
- /** Called when a fiber is scheduled for re-render (for telemetry/visualization) */
230
- onFiberReRenderScheduled?(fiber: FiberNode, reason: ReRenderReason, contextId?: symbol): void;
231
- /** Called when structural changes are detected in CloudDOM topology */
232
- onStructuralChange?(change: any): void;
233
- }
234
- /**
235
- * OutputBinding - Tracks binding between component state and provider outputs
236
- * Used by StateBindingManager to detect when outputs change
237
- */
238
- export interface OutputBinding {
239
- /** CloudDOM node ID that provides the output */
240
- nodeId: string;
241
- /** Output key from the provider */
242
- outputKey: string;
243
- /** Last known value of the output */
244
- lastValue: any;
245
- /** Timestamp when binding was created */
246
- bindTime: number;
247
- /** Timestamp when binding was last updated (optional, for observability) */
248
- lastUpdate?: number;
249
- }
250
- /**
251
- * OutputChange - Represents a change in provider output
252
- * Used to track what changed and which components are affected
253
- */
254
- export interface OutputChange {
255
- /** CloudDOM node ID that changed */
256
- nodeId: string;
257
- /** Output key that changed */
258
- outputKey: string;
259
- /** Previous value */
260
- previousValue: any;
261
- /** New value */
262
- newValue: any;
263
- /** Fiber nodes affected by this change */
264
- affectedFibers: FiberNode[];
265
- }
@@ -1,48 +0,0 @@
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.getResourcesToDeploy = getResourcesToDeploy;
33
- /**
34
- * Get filtered deployment order containing only resources that need deployment
35
- * (creates, updates, replacements) - excludes unchanged resources
36
- *
37
- * @param changeSet - The change set to filter
38
- * @returns Array of resource IDs that need deployment, in dependency order
39
- */
40
- function getResourcesToDeploy(changeSet) {
41
- const resourcesToDeploy = new Set([
42
- ...changeSet.creates.map(n => n.id),
43
- ...changeSet.updates.map(n => n.id),
44
- ...changeSet.replacements.map(n => n.id),
45
- ]);
46
- // Filter deployment order to maintain dependency ordering
47
- return changeSet.deploymentOrder.filter(id => resourcesToDeploy.has(id));
48
- }
@@ -1,147 +0,0 @@
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 } from '../core/types';
31
- /**
32
- * Access tracking session for output dependency analysis
33
- */
34
- interface AccessTrackingSession {
35
- fiber: FiberNode;
36
- startTime: number;
37
- trackedOutputs: Set<string>;
38
- isActive: boolean;
39
- }
40
- /**
41
- * Consolidated Hook Context - Single source of truth for all hook state
42
- * Addresses Issue #9: Hook Context Consolidation
43
- */
44
- interface ConsolidatedHookContext {
45
- currentFiber: FiberNode | null;
46
- stateHookIndex: number;
47
- effectHookIndex: number;
48
- contextHookIndex: number;
49
- instanceHookIndex: number;
50
- contextStacks: Map<symbol, any[]>;
51
- currentPath: string[];
52
- previousOutputsMap: Map<string, Record<string, any>> | null;
53
- accessTrackingSessions: Map<FiberNode, AccessTrackingSession>;
54
- }
55
- /**
56
- * Get the consolidated hook context with validation
57
- * This is the primary function all hooks should use
58
- */
59
- export declare function requireHookContext(): ConsolidatedHookContext;
60
- /**
61
- * Run a function with a new consolidated hook context
62
- */
63
- export declare function runWithHookContext<T>(fn: () => T): T;
64
- /**
65
- * Increment hook index for specific hook type
66
- */
67
- export declare function incrementHookIndex(hookType?: 'state' | 'effect' | 'context' | 'instance'): number;
68
- /**
69
- * Set the current rendering context for all hooks
70
- * Called by Renderer before executing a component
71
- *
72
- * Requirements: 8.2, 8.4
73
- */
74
- export declare function setRenderContext(fiber: FiberNode, path?: string[]): void;
75
- /**
76
- * Clear the current rendering context for all hooks
77
- * Called by Renderer after component execution
78
- *
79
- * Requirements: 8.2, 8.4
80
- */
81
- export declare function clearRenderContext(): void;
82
- /**
83
- * Check if there is an active render context
84
- */
85
- export declare function hasRenderContext(): boolean;
86
- /**
87
- * Get the current fiber state
88
- */
89
- export declare function getCurrentState(): Record<string, any> | undefined;
90
- /**
91
- * Push a context value onto the stack
92
- * Called by Renderer when entering a Provider
93
- */
94
- export declare function pushContextValue(contextId: symbol, value: any): void;
95
- /**
96
- * Pop a context value from the stack
97
- * Called by Renderer when exiting a Provider
98
- */
99
- export declare function popContextValue(contextId: symbol): void;
100
- /**
101
- * Get the current context value from the stack
102
- */
103
- export declare function getContextValue(contextId: symbol): {
104
- hasValue: boolean;
105
- value: any;
106
- };
107
- /**
108
- * Clear all context stacks
109
- * Called by Renderer to prevent memory leaks
110
- */
111
- export declare function clearContextStacks(): void;
112
- /**
113
- * Clear the global previous outputs map
114
- * Called for test isolation and cleanup
115
- */
116
- export declare function clearPreviousOutputs(): void;
117
- /**
118
- * Set previous outputs map for restoration during render
119
- * Called by CReact before rendering
120
- */
121
- export declare function setPreviousOutputs(outputsMap: Map<string, Record<string, any>> | null): void;
122
- /**
123
- * Get the current rendering path
124
- */
125
- export declare function getCurrentPath(): string[];
126
- /**
127
- * Check if currently rendering
128
- */
129
- export declare function isRendering(): boolean;
130
- /**
131
- * Start tracking output accesses for a fiber
132
- * Used by useEffect to track which outputs are accessed in dependencies
133
- */
134
- export declare function startAccessTracking(fiber: FiberNode): void;
135
- /**
136
- * End tracking and return the set of accessed outputs
137
- */
138
- export declare function endAccessTracking(fiber: FiberNode): Set<string>;
139
- /**
140
- * Track an output access during an active tracking session
141
- */
142
- export declare function trackOutputAccess(fiber: FiberNode, bindingKey: string): void;
143
- /**
144
- * Get the current access tracking session for a fiber
145
- */
146
- export declare function getAccessTrackingSession(fiber: FiberNode): AccessTrackingSession | undefined;
147
- export {};