@hamak/ui-store-impl 0.11.0 → 0.12.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 (89) hide show
  1. package/package.json +2 -2
  2. package/dist/autosave/autosave-config-resolver.d.ts +0 -45
  3. package/dist/autosave/autosave-config-resolver.d.ts.map +0 -1
  4. package/dist/autosave/autosave-config-resolver.js +0 -107
  5. package/dist/autosave/autosave-middleware.d.ts +0 -37
  6. package/dist/autosave/autosave-middleware.d.ts.map +0 -1
  7. package/dist/autosave/autosave-middleware.js +0 -297
  8. package/dist/autosave/autosave-registry.d.ts +0 -15
  9. package/dist/autosave/autosave-registry.d.ts.map +0 -1
  10. package/dist/autosave/autosave-registry.js +0 -33
  11. package/dist/autosave/autosave-sync-middleware.d.ts +0 -24
  12. package/dist/autosave/autosave-sync-middleware.d.ts.map +0 -1
  13. package/dist/autosave/autosave-sync-middleware.js +0 -98
  14. package/dist/autosave/index.d.ts +0 -8
  15. package/dist/autosave/index.d.ts.map +0 -1
  16. package/dist/autosave/index.js +0 -7
  17. package/dist/core/index.d.ts +0 -4
  18. package/dist/core/index.d.ts.map +0 -1
  19. package/dist/core/index.js +0 -3
  20. package/dist/core/middleware-registry.d.ts +0 -21
  21. package/dist/core/middleware-registry.d.ts.map +0 -1
  22. package/dist/core/middleware-registry.js +0 -50
  23. package/dist/core/reducer-registry.d.ts +0 -18
  24. package/dist/core/reducer-registry.d.ts.map +0 -1
  25. package/dist/core/reducer-registry.js +0 -54
  26. package/dist/core/store-manager.d.ts +0 -29
  27. package/dist/core/store-manager.d.ts.map +0 -1
  28. package/dist/core/store-manager.js +0 -104
  29. package/dist/es2015/autosave/autosave-config-resolver.js +0 -110
  30. package/dist/es2015/autosave/autosave-middleware.js +0 -311
  31. package/dist/es2015/autosave/autosave-registry.js +0 -33
  32. package/dist/es2015/autosave/autosave-sync-middleware.js +0 -98
  33. package/dist/es2015/autosave/index.js +0 -7
  34. package/dist/es2015/core/index.js +0 -3
  35. package/dist/es2015/core/middleware-registry.js +0 -47
  36. package/dist/es2015/core/reducer-registry.js +0 -54
  37. package/dist/es2015/core/store-manager.js +0 -104
  38. package/dist/es2015/extensions/store-extensions.js +0 -61
  39. package/dist/es2015/fs/commands/fs-commands.js +0 -327
  40. package/dist/es2015/fs/commands/structure-commands.js +0 -21
  41. package/dist/es2015/fs/core/fs-adapter.js +0 -134
  42. package/dist/es2015/fs/core/fs-facade.js +0 -78
  43. package/dist/es2015/fs/index.js +0 -11
  44. package/dist/es2015/fs/utils/data-updater.js +0 -251
  45. package/dist/es2015/fs/utils/deep-equal.js +0 -28
  46. package/dist/es2015/middleware/event-bridge-middleware.js +0 -19
  47. package/dist/es2015/middleware/index.js +0 -5
  48. package/dist/es2015/middleware/logger-middleware.js +0 -18
  49. package/dist/es2015/plugin/index.js +0 -4
  50. package/dist/es2015/plugin/store-plugin-factory.js +0 -137
  51. package/dist/extensions/store-extensions.d.ts +0 -23
  52. package/dist/extensions/store-extensions.d.ts.map +0 -1
  53. package/dist/extensions/store-extensions.js +0 -61
  54. package/dist/fs/commands/fs-commands.d.ts +0 -100
  55. package/dist/fs/commands/fs-commands.d.ts.map +0 -1
  56. package/dist/fs/commands/fs-commands.js +0 -330
  57. package/dist/fs/commands/structure-commands.d.ts +0 -76
  58. package/dist/fs/commands/structure-commands.d.ts.map +0 -1
  59. package/dist/fs/commands/structure-commands.js +0 -21
  60. package/dist/fs/core/fs-adapter.d.ts +0 -60
  61. package/dist/fs/core/fs-adapter.d.ts.map +0 -1
  62. package/dist/fs/core/fs-adapter.js +0 -134
  63. package/dist/fs/core/fs-facade.d.ts +0 -37
  64. package/dist/fs/core/fs-facade.d.ts.map +0 -1
  65. package/dist/fs/core/fs-facade.js +0 -78
  66. package/dist/fs/index.d.ts +0 -8
  67. package/dist/fs/index.d.ts.map +0 -1
  68. package/dist/fs/index.js +0 -11
  69. package/dist/fs/utils/data-updater.d.ts +0 -43
  70. package/dist/fs/utils/data-updater.d.ts.map +0 -1
  71. package/dist/fs/utils/data-updater.js +0 -255
  72. package/dist/fs/utils/deep-equal.d.ts +0 -5
  73. package/dist/fs/utils/deep-equal.d.ts.map +0 -1
  74. package/dist/fs/utils/deep-equal.js +0 -28
  75. package/dist/middleware/event-bridge-middleware.d.ts +0 -7
  76. package/dist/middleware/event-bridge-middleware.d.ts.map +0 -1
  77. package/dist/middleware/event-bridge-middleware.js +0 -19
  78. package/dist/middleware/index.d.ts +0 -6
  79. package/dist/middleware/index.d.ts.map +0 -1
  80. package/dist/middleware/index.js +0 -5
  81. package/dist/middleware/logger-middleware.d.ts +0 -7
  82. package/dist/middleware/logger-middleware.d.ts.map +0 -1
  83. package/dist/middleware/logger-middleware.js +0 -18
  84. package/dist/plugin/index.d.ts +0 -5
  85. package/dist/plugin/index.d.ts.map +0 -1
  86. package/dist/plugin/index.js +0 -4
  87. package/dist/plugin/store-plugin-factory.d.ts +0 -15
  88. package/dist/plugin/store-plugin-factory.d.ts.map +0 -1
  89. package/dist/plugin/store-plugin-factory.js +0 -121
@@ -1,311 +0,0 @@
1
- /**
2
- * Autosave Middleware
3
- *
4
- * Core middleware that orchestrates autosave operations:
5
- * 1. Detects file content changes
6
- * 2. Manages debounce timers per file
7
- * 3. Delegates save operations to registered providers
8
- * 4. Handles retries on failure
9
- */
10
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
11
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
12
- return new (P || (P = Promise))(function (resolve, reject) {
13
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
14
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
15
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16
- step((generator = generator.apply(thisArg, _arguments || [])).next());
17
- });
18
- };
19
- import { AutosaveActionTypes, autosaveActions, DEFAULT_AUTOSAVE_CONFIG, } from '@hamak/ui-store-api';
20
- import { resolveAutosaveConfig, getNodeAtPath, pathToKey, } from './autosave-config-resolver.js';
21
- /**
22
- * Content change action types to monitor
23
- */
24
- const CONTENT_CHANGE_ACTION_TYPES = [
25
- 'set-file-content',
26
- 'update-file-content',
27
- ];
28
- /**
29
- * Check if an action is a content change action
30
- */
31
- function isContentChangeAction(action) {
32
- // Check for filesystem command actions
33
- if (action.type === '@@fs/COMMAND' && action.command) {
34
- return CONTENT_CHANGE_ACTION_TYPES.includes(action.command.name);
35
- }
36
- // Check for direct content change actions from fs-adapter
37
- if (typeof action.type === 'string') {
38
- const type = action.type.toLowerCase();
39
- return (type.includes('setfilecontent') ||
40
- type.includes('updatefilecontent') ||
41
- type.includes('set_file_content') ||
42
- type.includes('update_file_content'));
43
- }
44
- return false;
45
- }
46
- /**
47
- * Check if content change is from remote (should not trigger autosave)
48
- */
49
- function isFromRemote(action) {
50
- var _a, _b;
51
- if (((_a = action.command) === null || _a === void 0 ? void 0 : _a.fromRemote) === true) {
52
- return true;
53
- }
54
- if (((_b = action.payload) === null || _b === void 0 ? void 0 : _b.fromRemote) === true) {
55
- return true;
56
- }
57
- if (action.fromRemote === true) {
58
- return true;
59
- }
60
- return false;
61
- }
62
- /**
63
- * Get path from action
64
- */
65
- function getPathFromAction(action) {
66
- var _a, _b;
67
- // Try command path
68
- if ((_a = action.command) === null || _a === void 0 ? void 0 : _a.path) {
69
- return Array.isArray(action.command.path)
70
- ? action.command.path
71
- : [action.command.path];
72
- }
73
- // Try payload path
74
- if ((_b = action.payload) === null || _b === void 0 ? void 0 : _b.path) {
75
- return Array.isArray(action.payload.path)
76
- ? action.payload.path
77
- : [action.payload.path];
78
- }
79
- // Try direct path
80
- if (action.path) {
81
- return Array.isArray(action.path) ? action.path : [action.path];
82
- }
83
- return undefined;
84
- }
85
- /**
86
- * Create autosave middleware
87
- */
88
- export function createAutosaveMiddleware(config) {
89
- const { registry, fsSliceName = 'fileSystem', defaultConfig = {}, onSaveStart, onSaveSuccess, onSaveError, } = config;
90
- const mergedDefaultConfig = Object.assign(Object.assign({}, DEFAULT_AUTOSAVE_CONFIG), defaultConfig);
91
- // Track pending saves by path key
92
- const pendingSaves = new Map();
93
- /**
94
- * Get filesystem root from state
95
- */
96
- function getRoot(state) {
97
- var _a;
98
- return (_a = state[fsSliceName]) === null || _a === void 0 ? void 0 : _a.root;
99
- }
100
- /**
101
- * Clear timers for a path
102
- */
103
- function clearTimers(pathKey) {
104
- const pending = pendingSaves.get(pathKey);
105
- if (pending) {
106
- clearTimeout(pending.debounceTimer);
107
- if (pending.maxWaitTimer) {
108
- clearTimeout(pending.maxWaitTimer);
109
- }
110
- }
111
- }
112
- /**
113
- * Cancel pending save
114
- */
115
- function cancelPending(pathKey) {
116
- clearTimers(pathKey);
117
- pendingSaves.delete(pathKey);
118
- }
119
- /**
120
- * Schedule autosave for a path
121
- */
122
- function scheduleAutosave(store, path, providerId, config) {
123
- var _a, _b, _c;
124
- const pathKey = pathToKey(path);
125
- const now = Date.now();
126
- const debounceMs = (_a = config.debounceMs) !== null && _a !== void 0 ? _a : DEFAULT_AUTOSAVE_CONFIG.debounceMs;
127
- const maxWaitMs = (_b = config.maxWaitMs) !== null && _b !== void 0 ? _b : DEFAULT_AUTOSAVE_CONFIG.maxWaitMs;
128
- // Clear existing debounce timer (but keep max wait if exists)
129
- const existing = pendingSaves.get(pathKey);
130
- if (existing) {
131
- clearTimeout(existing.debounceTimer);
132
- }
133
- // Create debounce timer
134
- const debounceTimer = setTimeout(() => {
135
- store.dispatch(autosaveActions.debounceExpired(path));
136
- }, debounceMs);
137
- // Create max wait timer if not exists
138
- let maxWaitTimer = existing === null || existing === void 0 ? void 0 : existing.maxWaitTimer;
139
- if (!maxWaitTimer) {
140
- maxWaitTimer = setTimeout(() => {
141
- store.dispatch(autosaveActions.debounceExpired(path));
142
- }, maxWaitMs);
143
- }
144
- // Store pending save
145
- pendingSaves.set(pathKey, {
146
- path,
147
- providerId,
148
- debounceTimer,
149
- maxWaitTimer,
150
- retryCount: (_c = existing === null || existing === void 0 ? void 0 : existing.retryCount) !== null && _c !== void 0 ? _c : 0,
151
- config,
152
- });
153
- // Dispatch change detected
154
- store.dispatch(autosaveActions.changeDetected(path, now, now + debounceMs, providerId));
155
- }
156
- /**
157
- * Execute save operation
158
- */
159
- function executeSave(store, path) {
160
- return __awaiter(this, void 0, void 0, function* () {
161
- var _a, _b, _c;
162
- const pathKey = pathToKey(path);
163
- const pending = pendingSaves.get(pathKey);
164
- if (!pending) {
165
- return;
166
- }
167
- // Clear timers
168
- clearTimers(pathKey);
169
- // Get current state
170
- const state = store.getState();
171
- const root = getRoot(state);
172
- if (!root) {
173
- pendingSaves.delete(pathKey);
174
- return;
175
- }
176
- // Get node
177
- const node = getNodeAtPath(root, path);
178
- if (!node || node.type !== 'file') {
179
- pendingSaves.delete(pathKey);
180
- return;
181
- }
182
- // Get provider
183
- const provider = registry.get(pending.providerId);
184
- if (!provider) {
185
- pendingSaves.delete(pathKey);
186
- return;
187
- }
188
- // Dispatch save started
189
- store.dispatch(autosaveActions.saveStarted(path, pending.providerId));
190
- onSaveStart === null || onSaveStart === void 0 ? void 0 : onSaveStart(path);
191
- try {
192
- // Execute save via provider
193
- const result = yield provider.save(path, node.content, node, store.dispatch);
194
- if (result.success) {
195
- // Success
196
- pendingSaves.delete(pathKey);
197
- store.dispatch(autosaveActions.saveSucceeded(path, result.timestamp));
198
- onSaveSuccess === null || onSaveSuccess === void 0 ? void 0 : onSaveSuccess(path, result);
199
- }
200
- else {
201
- // Provider reported failure
202
- handleSaveFailure(store, path, (_a = result.error) !== null && _a !== void 0 ? _a : { code: 'UNKNOWN', message: 'Save failed' });
203
- }
204
- }
205
- catch (error) {
206
- // Exception during save
207
- handleSaveFailure(store, path, {
208
- code: (_b = error.code) !== null && _b !== void 0 ? _b : 'ERROR',
209
- message: (_c = error.message) !== null && _c !== void 0 ? _c : 'Unknown error',
210
- });
211
- }
212
- });
213
- }
214
- /**
215
- * Handle save failure with retry logic
216
- */
217
- function handleSaveFailure(store, path, error) {
218
- var _a;
219
- const pathKey = pathToKey(path);
220
- const pending = pendingSaves.get(pathKey);
221
- if (!pending) {
222
- return;
223
- }
224
- const retryCount = pending.retryCount + 1;
225
- const maxRetries = (_a = pending.config.maxRetries) !== null && _a !== void 0 ? _a : DEFAULT_AUTOSAVE_CONFIG.maxRetries;
226
- const shouldRetry = pending.config.retryOnFailure !== false && retryCount < maxRetries;
227
- // Dispatch failure
228
- store.dispatch(autosaveActions.saveFailed(path, error, retryCount));
229
- onSaveError === null || onSaveError === void 0 ? void 0 : onSaveError(path, error);
230
- if (shouldRetry) {
231
- // Schedule retry with exponential backoff
232
- const retryDelay = Math.min(1000 * Math.pow(2, retryCount - 1), 10000);
233
- const retryAt = Date.now() + retryDelay;
234
- store.dispatch(autosaveActions.retryScheduled(path, retryAt, retryCount));
235
- // Update pending save with retry timer
236
- pending.retryCount = retryCount;
237
- pending.debounceTimer = setTimeout(() => {
238
- executeSave(store, path);
239
- }, retryDelay);
240
- pendingSaves.set(pathKey, pending);
241
- }
242
- else {
243
- // No more retries
244
- pendingSaves.delete(pathKey);
245
- }
246
- }
247
- /**
248
- * The middleware
249
- */
250
- const autosaveMiddleware = (store) => (next) => (action) => {
251
- const result = next(action);
252
- const typedAction = action;
253
- // ─────────────────────────────────────────────────────────────────
254
- // Handle content changes
255
- // ─────────────────────────────────────────────────────────────────
256
- if (isContentChangeAction(typedAction) && !isFromRemote(typedAction)) {
257
- const path = getPathFromAction(typedAction);
258
- if (path) {
259
- const state = store.getState();
260
- const root = getRoot(state);
261
- if (root) {
262
- // Resolve config
263
- const autosaveConfig = resolveAutosaveConfig(root, path, mergedDefaultConfig);
264
- if (autosaveConfig.enabled) {
265
- // Get node
266
- const node = getNodeAtPath(root, path);
267
- if (node) {
268
- // Find provider
269
- const provider = registry.findProvider(path, node);
270
- if (provider) {
271
- scheduleAutosave(store, path, provider.id, autosaveConfig);
272
- }
273
- }
274
- }
275
- }
276
- }
277
- }
278
- // ─────────────────────────────────────────────────────────────────
279
- // Handle autosave actions
280
- // ─────────────────────────────────────────────────────────────────
281
- switch (typedAction.type) {
282
- case AutosaveActionTypes.DEBOUNCE_EXPIRED: {
283
- const path = typedAction.payload.path;
284
- void executeSave(store, path);
285
- break;
286
- }
287
- case AutosaveActionTypes.FLUSH_PENDING: {
288
- const path = typedAction.payload.path;
289
- const pathKey = pathToKey(path);
290
- if (pendingSaves.has(pathKey)) {
291
- void executeSave(store, path);
292
- }
293
- break;
294
- }
295
- case AutosaveActionTypes.FLUSH_ALL_PENDING: {
296
- const paths = Array.from(pendingSaves.values()).map((p) => p.path);
297
- for (const path of paths) {
298
- void executeSave(store, path);
299
- }
300
- break;
301
- }
302
- case AutosaveActionTypes.CANCEL_PENDING: {
303
- const path = typedAction.payload.path;
304
- cancelPending(pathToKey(path));
305
- break;
306
- }
307
- }
308
- return result;
309
- };
310
- return autosaveMiddleware;
311
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * Autosave Provider Registry Implementation
3
- */
4
- export class AutosaveProviderRegistry {
5
- constructor() {
6
- this.providers = new Map();
7
- }
8
- register(provider) {
9
- if (this.providers.has(provider.id)) {
10
- console.warn(`[AutosaveRegistry] Provider "${provider.id}" already registered, overwriting.`);
11
- }
12
- this.providers.set(provider.id, provider);
13
- }
14
- unregister(providerId) {
15
- this.providers.delete(providerId);
16
- }
17
- get(providerId) {
18
- return this.providers.get(providerId);
19
- }
20
- findProvider(path, node) {
21
- // Get all providers that support this path, sorted by priority (descending)
22
- const supportingProviders = Array.from(this.providers.values())
23
- .filter((provider) => provider.supports(path, node))
24
- .sort((a, b) => { var _a, _b; return ((_a = b.priority) !== null && _a !== void 0 ? _a : 0) - ((_b = a.priority) !== null && _b !== void 0 ? _b : 0); });
25
- return supportingProviders[0];
26
- }
27
- getAll() {
28
- return Array.from(this.providers.values());
29
- }
30
- has(providerId) {
31
- return this.providers.has(providerId);
32
- }
33
- }
@@ -1,98 +0,0 @@
1
- /**
2
- * Autosave Sync Middleware
3
- *
4
- * Updates FileSystemNode extension states based on autosave lifecycle actions.
5
- * This middleware runs after the main autosave middleware and updates the
6
- * state so components can display autosave status.
7
- */
8
- import { AutosaveActionTypes, autosaveActions, } from '@hamak/ui-store-api';
9
- /**
10
- * Create autosave sync middleware
11
- */
12
- export function createAutosaveSyncMiddleware(config) {
13
- const { updateExtensionState } = config;
14
- const autosaveSyncMiddleware = (store) => (next) => (action) => {
15
- const result = next(action);
16
- const typedAction = action;
17
- // Only process autosave actions
18
- if (!autosaveActions.isAutosaveAction(typedAction)) {
19
- return result;
20
- }
21
- const dispatch = store.dispatch;
22
- switch (typedAction.type) {
23
- case AutosaveActionTypes.SET_CONFIG: {
24
- const { path, config: autosaveConfig } = typedAction.payload;
25
- dispatch(updateExtensionState(path, {
26
- config: autosaveConfig,
27
- effectivelyEnabled: autosaveConfig.enabled,
28
- status: autosaveConfig.enabled ? 'idle' : 'disabled',
29
- }));
30
- break;
31
- }
32
- case AutosaveActionTypes.CLEAR_CONFIG: {
33
- const { path } = typedAction.payload;
34
- dispatch(updateExtensionState(path, {
35
- config: undefined,
36
- // Status will be recomputed based on parent config
37
- }));
38
- break;
39
- }
40
- case AutosaveActionTypes.CHANGE_DETECTED: {
41
- const { path, detectedAt, providerId } = typedAction.payload;
42
- dispatch(updateExtensionState(path, {
43
- status: 'pending',
44
- pendingSince: detectedAt,
45
- providerId,
46
- }));
47
- break;
48
- }
49
- case AutosaveActionTypes.SAVE_STARTED: {
50
- const { path, providerId } = typedAction.payload;
51
- dispatch(updateExtensionState(path, {
52
- status: 'saving',
53
- lastSaveAttempt: Date.now(),
54
- providerId,
55
- }));
56
- break;
57
- }
58
- case AutosaveActionTypes.SAVE_SUCCEEDED: {
59
- const { path, timestamp } = typedAction.payload;
60
- dispatch(updateExtensionState(path, {
61
- status: 'idle',
62
- lastSaveSuccess: timestamp,
63
- lastSaveError: undefined,
64
- retryCount: 0,
65
- pendingSince: undefined,
66
- }));
67
- break;
68
- }
69
- case AutosaveActionTypes.SAVE_FAILED: {
70
- const { path, error } = typedAction.payload;
71
- dispatch(updateExtensionState(path, {
72
- status: 'error',
73
- lastSaveError: error,
74
- retryCount: error.attempt,
75
- }));
76
- break;
77
- }
78
- case AutosaveActionTypes.RETRY_SCHEDULED: {
79
- const { path, attempt } = typedAction.payload;
80
- dispatch(updateExtensionState(path, {
81
- status: 'pending',
82
- retryCount: attempt,
83
- }));
84
- break;
85
- }
86
- case AutosaveActionTypes.CANCEL_PENDING: {
87
- const { path } = typedAction.payload;
88
- dispatch(updateExtensionState(path, {
89
- status: 'idle',
90
- pendingSince: undefined,
91
- }));
92
- break;
93
- }
94
- }
95
- return result;
96
- };
97
- return autosaveSyncMiddleware;
98
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Autosave Implementation
3
- */
4
- export * from './autosave-registry.js';
5
- export * from './autosave-config-resolver.js';
6
- export * from './autosave-middleware.js';
7
- export * from './autosave-sync-middleware.js';
@@ -1,3 +0,0 @@
1
- export * from './store-manager.js';
2
- export * from './middleware-registry.js';
3
- export * from './reducer-registry.js';
@@ -1,47 +0,0 @@
1
- /**
2
- * Middleware Registry Implementation
3
- */
4
- export class MiddlewareRegistry {
5
- constructor() {
6
- this.registrations = new Map();
7
- this.locked = false;
8
- }
9
- register(registration) {
10
- if (this.locked) {
11
- throw new Error(`Cannot register middleware "${registration.id}" - store already created. ` +
12
- `Register middleware during plugin initialization phase.`);
13
- }
14
- if (this.registrations.has(registration.id)) {
15
- console.warn(`[MiddlewareRegistry] Middleware "${registration.id}" already registered, overwriting.`);
16
- }
17
- this.registrations.set(registration.id, Object.assign({ priority: 0 }, registration));
18
- }
19
- unregister(id) {
20
- if (this.locked) {
21
- throw new Error(`Cannot unregister middleware after store creation`);
22
- }
23
- this.registrations.delete(id);
24
- }
25
- getAll() {
26
- const sorted = Array.from(this.registrations.values())
27
- .sort((a, b) => (b.priority || 0) - (a.priority || 0));
28
- return sorted.map(reg => reg.middleware);
29
- }
30
- has(id) {
31
- return this.registrations.has(id);
32
- }
33
- getInfo(id) {
34
- return this.registrations.get(id);
35
- }
36
- getAllRegistrations() {
37
- return Array.from(this.registrations.values())
38
- .sort((a, b) => (b.priority || 0) - (a.priority || 0));
39
- }
40
- /**
41
- * Lock the registry (called when store is created)
42
- * @internal
43
- */
44
- lock() {
45
- this.locked = true;
46
- }
47
- }
@@ -1,54 +0,0 @@
1
- /**
2
- * Reducer Registry Implementation
3
- */
4
- import { combineReducers } from 'redux';
5
- export class ReducerRegistry {
6
- constructor(onReducerChange) {
7
- this.reducers = new Map();
8
- this.onReducerChange = onReducerChange;
9
- }
10
- register(key, reducer, replace = false) {
11
- if (!replace && this.reducers.has(key)) {
12
- console.warn(`[ReducerRegistry] Reducer "${key}" already registered. Use replace=true to override.`);
13
- return;
14
- }
15
- this.reducers.set(key, {
16
- key,
17
- reducer,
18
- registeredAt: new Date(),
19
- });
20
- // Notify about reducer change for hot replacement
21
- if (this.onReducerChange) {
22
- this.onReducerChange(this.getCombinedReducer());
23
- }
24
- }
25
- unregister(key) {
26
- this.reducers.delete(key);
27
- if (this.onReducerChange) {
28
- this.onReducerChange(this.getCombinedReducer());
29
- }
30
- }
31
- getAll() {
32
- const map = {};
33
- this.reducers.forEach((registration, key) => {
34
- map[key] = registration.reducer;
35
- });
36
- return map;
37
- }
38
- getCombinedReducer() {
39
- const reducerMap = this.getAll();
40
- if (Object.keys(reducerMap).length === 0) {
41
- return (state = {}) => state;
42
- }
43
- return combineReducers(reducerMap);
44
- }
45
- has(key) {
46
- return this.reducers.has(key);
47
- }
48
- getInfo(key) {
49
- return this.reducers.get(key);
50
- }
51
- getAllRegistrations() {
52
- return Array.from(this.reducers.values());
53
- }
54
- }
@@ -1,104 +0,0 @@
1
- /**
2
- * Store Manager Implementation
3
- */
4
- import { configureStore } from '@reduxjs/toolkit';
5
- import { MiddlewareRegistry } from './middleware-registry.js';
6
- import { ReducerRegistry } from './reducer-registry.js';
7
- export class StoreManager {
8
- constructor() {
9
- this.store = null;
10
- this.initialized = false;
11
- this.config = null;
12
- this.fileSystemAdapter = null;
13
- this.middlewareRegistry = new MiddlewareRegistry();
14
- this.reducerRegistry = new ReducerRegistry((rootReducer) => {
15
- // Hot replacement callback
16
- if (this.store) {
17
- this.store.replaceReducer(rootReducer);
18
- }
19
- });
20
- }
21
- getMiddlewareRegistry() {
22
- return this.middlewareRegistry;
23
- }
24
- getReducerRegistry() {
25
- return this.reducerRegistry;
26
- }
27
- setFileSystemAdapter(adapter) {
28
- this.fileSystemAdapter = adapter;
29
- }
30
- getFileSystemAdapter() {
31
- return this.fileSystemAdapter;
32
- }
33
- isInitialized() {
34
- return this.initialized;
35
- }
36
- initialize(config = {}) {
37
- if (this.initialized) {
38
- throw new Error('[StoreManager] Store already initialized');
39
- }
40
- this.config = config;
41
- // Get all middleware in priority order
42
- const middleware = this.middlewareRegistry.getAll();
43
- // Lock the middleware registry
44
- this.middlewareRegistry.lock();
45
- // Get combined reducer
46
- const rootReducer = this.reducerRegistry.getCombinedReducer();
47
- // Create enhancers
48
- const enhancers = config.enhancers || [];
49
- // Create store using configureStore (modern Redux Toolkit API)
50
- this.store = configureStore({
51
- reducer: rootReducer,
52
- preloadedState: config.preloadedState,
53
- // Use only our custom middleware (disabling Redux Toolkit defaults to maintain exact behavior)
54
- middleware: (getDefaultMiddleware) => getDefaultMiddleware({
55
- // Disable all default middleware to maintain exact parity with old createStore behavior
56
- thunk: false,
57
- serializableCheck: false,
58
- immutableCheck: false,
59
- actionCreatorCheck: false,
60
- }).concat(...middleware),
61
- // Add custom enhancers if provided
62
- enhancers: (getDefaultEnhancers) => getDefaultEnhancers().concat(enhancers),
63
- // Configure DevTools with trace support
64
- devTools: config.devTools !== false ? {
65
- trace: true,
66
- traceLimit: 25,
67
- } : false,
68
- });
69
- this.initialized = true;
70
- console.log('[StoreManager] Store initialized with:', {
71
- reducers: this.reducerRegistry.getAllRegistrations().map(r => r.key),
72
- middleware: this.middlewareRegistry.getAllRegistrations().map(m => ({
73
- id: m.id,
74
- priority: m.priority,
75
- plugin: m.plugin,
76
- })),
77
- devTools: config.devTools !== false,
78
- });
79
- return this.store;
80
- }
81
- getStore() {
82
- if (!this.store) {
83
- throw new Error('[StoreManager] Store not initialized. Call initialize() first.');
84
- }
85
- return this.store;
86
- }
87
- dispatch(action) {
88
- return this.getStore().dispatch(action);
89
- }
90
- getState() {
91
- return this.getStore().getState();
92
- }
93
- subscribe(listener) {
94
- return this.getStore().subscribe(listener);
95
- }
96
- replaceReducer(nextReducer) {
97
- this.getStore().replaceReducer(nextReducer);
98
- }
99
- destroy() {
100
- this.store = null;
101
- this.initialized = false;
102
- console.log('[StoreManager] Store destroyed');
103
- }
104
- }