conduithub 0.0.3 → 1.0.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 (68) hide show
  1. package/dist/core/conduit-hub/index.cjs +188 -0
  2. package/dist/core/conduit-hub/index.d.cts +44 -0
  3. package/dist/core/conduit-hub/index.d.mts +44 -0
  4. package/dist/core/conduit-hub/index.d.ts +44 -0
  5. package/dist/core/conduit-hub/index.mjs +186 -0
  6. package/dist/core/config-manager/index.cjs +216 -0
  7. package/dist/core/config-manager/index.d.cts +7 -0
  8. package/dist/core/config-manager/index.d.mts +7 -0
  9. package/dist/core/config-manager/index.d.ts +7 -0
  10. package/dist/core/config-manager/index.mjs +214 -0
  11. package/dist/core/event-bus/index.cjs +154 -53
  12. package/dist/core/event-bus/index.d.cts +2 -42
  13. package/dist/core/event-bus/index.d.mts +2 -42
  14. package/dist/core/event-bus/index.d.ts +2 -42
  15. package/dist/core/event-bus/index.mjs +153 -52
  16. package/dist/core/hook/index.cjs +185 -148
  17. package/dist/core/hook/index.d.cts +28 -16
  18. package/dist/core/hook/index.d.mts +28 -16
  19. package/dist/core/hook/index.d.ts +28 -16
  20. package/dist/core/hook/index.mjs +183 -146
  21. package/dist/core/index.cjs +17 -1
  22. package/dist/core/index.d.cts +184 -3
  23. package/dist/core/index.d.mts +184 -3
  24. package/dist/core/index.d.ts +184 -3
  25. package/dist/core/index.mjs +12 -1
  26. package/dist/core/plugin/index.cjs +271 -0
  27. package/dist/core/plugin/index.d.cts +7 -0
  28. package/dist/core/plugin/index.d.mts +7 -0
  29. package/dist/core/plugin/index.d.ts +7 -0
  30. package/dist/core/plugin/index.mjs +268 -0
  31. package/dist/core/service-container/index.cjs +306 -0
  32. package/dist/core/service-container/index.d.cts +51 -0
  33. package/dist/core/service-container/index.d.mts +51 -0
  34. package/dist/core/service-container/index.d.ts +51 -0
  35. package/dist/core/service-container/index.mjs +304 -0
  36. package/dist/core/state-manager/index.cjs +195 -0
  37. package/dist/core/state-manager/index.d.cts +39 -0
  38. package/dist/core/state-manager/index.d.mts +39 -0
  39. package/dist/core/state-manager/index.d.ts +39 -0
  40. package/dist/core/state-manager/index.mjs +193 -0
  41. package/dist/index.cjs +34 -5
  42. package/dist/index.d.cts +54 -2
  43. package/dist/index.d.mts +54 -2
  44. package/dist/index.d.ts +54 -2
  45. package/dist/index.mjs +13 -1
  46. package/dist/shared/conduithub.BDwZXllF.mjs +63 -0
  47. package/dist/shared/{conduithub.CvMLTa-R.cjs → conduithub.BNQsddJO.cjs} +2 -9
  48. package/dist/shared/{conduithub.74V0wiLi.mjs → conduithub.BNefRQsK.mjs} +3 -9
  49. package/dist/shared/conduithub.BZQmkQy7.d.cts +52 -0
  50. package/dist/shared/conduithub.BqUYv04j.cjs +68 -0
  51. package/dist/shared/conduithub.Bq_7Xj0J.cjs +18 -0
  52. package/dist/shared/conduithub.BzLwccre.d.mts +52 -0
  53. package/dist/shared/conduithub.CkOQG3cD.mjs +14 -0
  54. package/dist/shared/conduithub.CmZo_Vuc.cjs +38 -0
  55. package/dist/shared/conduithub.DQO1dRnn.cjs +33 -0
  56. package/dist/shared/conduithub.DQOWQ-Bx.d.ts +52 -0
  57. package/dist/shared/conduithub.DsOOeNwU.cjs +269 -0
  58. package/dist/shared/conduithub.DyQQrHW9.mjs +267 -0
  59. package/dist/shared/conduithub.G7ICpZIy.mjs +36 -0
  60. package/dist/shared/conduithub.alPiaJax.mjs +29 -0
  61. package/dist/shared/conduithub.bsiNMTVD.mjs +59 -0
  62. package/dist/shared/conduithub.gF2DFc43.cjs +76 -0
  63. package/dist/utils/index.cjs +18 -5
  64. package/dist/utils/index.d.cts +33 -2
  65. package/dist/utils/index.d.mts +33 -2
  66. package/dist/utils/index.d.ts +33 -2
  67. package/dist/utils/index.mjs +7 -1
  68. package/package.json +52 -1
@@ -0,0 +1,51 @@
1
+ interface ServiceDescriptor<T = unknown> {
2
+ readonly name: string;
3
+ readonly factory: () => Promise<T> | T;
4
+ readonly singleton: boolean;
5
+ readonly dependencies?: readonly string[];
6
+ readonly metadata?: Record<string, unknown>;
7
+ }
8
+ declare class ServiceContainer {
9
+ private readonly services;
10
+ private readonly instances;
11
+ private readonly resolutionStack;
12
+ private readonly pendingResolutions;
13
+ private isInitialized;
14
+ initialize(): Promise<void>;
15
+ shutdown(): Promise<void>;
16
+ private ensureInitialized;
17
+ register<T>(name: string, factory: () => T | Promise<T>, singleton?: boolean, dependencies?: readonly string[], metadata?: Record<string, unknown>): void;
18
+ resolve<T = unknown>(name: string): Promise<T>;
19
+ private resolveDependencies;
20
+ has(name: string): boolean;
21
+ remove(name: string): void;
22
+ clear(): void;
23
+ list(): readonly ServiceDescriptor[];
24
+ isSingleton(name: string): boolean;
25
+ getDescriptor(name: string): ServiceDescriptor | undefined;
26
+ getAllDescriptors(): readonly ServiceDescriptor[];
27
+ createInstance(name: string): Promise<unknown>;
28
+ getStats(): {
29
+ totalServices: number;
30
+ singletonCount: number;
31
+ transientCount: number;
32
+ instanceCount: number;
33
+ serviceNames: readonly string[];
34
+ };
35
+ validateDependencies(): {
36
+ valid: boolean;
37
+ errors: string[];
38
+ };
39
+ getDependencyGraph(): Record<string, string[]>;
40
+ getServiceNames(): readonly string[];
41
+ detectCircularDependencies(): string[][];
42
+ resolveAll(names: readonly string[]): Promise<unknown[]>;
43
+ findServicesByMetadata(key: string, value?: unknown): ServiceDescriptor[];
44
+ getTopologicalOrder(): string[];
45
+ warmup(serviceNames?: readonly string[]): Promise<void>;
46
+ clone(): ServiceContainer;
47
+ dispose(name: string): void;
48
+ }
49
+
50
+ export { ServiceContainer };
51
+ export type { ServiceDescriptor };
@@ -0,0 +1,304 @@
1
+ import { C as ConduithubError } from '../../shared/conduithub.BDwZXllF.mjs';
2
+ import { a as logger } from '../../shared/conduithub.BNefRQsK.mjs';
3
+ import 'process';
4
+ import 'readline';
5
+ import 'uuid';
6
+ import { E as ERROR_CODE } from '../../shared/conduithub.G7ICpZIy.mjs';
7
+
8
+ class ServiceContainer {
9
+ services = /* @__PURE__ */ new Map();
10
+ instances = /* @__PURE__ */ new Map();
11
+ resolutionStack = /* @__PURE__ */ new Set();
12
+ pendingResolutions = /* @__PURE__ */ new Map();
13
+ isInitialized = false;
14
+ async initialize() {
15
+ if (this.isInitialized) return;
16
+ this.isInitialized = true;
17
+ logger.info("Service Container initialized successfully");
18
+ }
19
+ async shutdown() {
20
+ if (!this.isInitialized) return;
21
+ logger.info("Shutting down Service Container...");
22
+ this.services.clear();
23
+ this.instances.clear();
24
+ this.resolutionStack.clear();
25
+ this.pendingResolutions.clear();
26
+ this.isInitialized = false;
27
+ logger.success("Service Container shutdown completed");
28
+ }
29
+ ensureInitialized() {
30
+ if (!this.isInitialized) {
31
+ throw new ConduithubError(ERROR_CODE.SERVICE_CONTAINER_NOT_INITIALIZED);
32
+ }
33
+ }
34
+ register(name, factory, singleton = true, dependencies, metadata) {
35
+ this.ensureInitialized();
36
+ const descriptor = {
37
+ name,
38
+ factory,
39
+ singleton,
40
+ dependencies,
41
+ metadata
42
+ };
43
+ this.services.set(name, descriptor);
44
+ logger.info(`Service registered: ${name} (singleton: ${singleton})`);
45
+ }
46
+ async resolve(name) {
47
+ this.ensureInitialized();
48
+ const service = this.services.get(name);
49
+ if (!service) {
50
+ throw new ConduithubError(`${ERROR_CODE.SERVICE_NOT_FOUND}: ${name}`);
51
+ }
52
+ if (service.singleton && this.instances.has(name)) {
53
+ return this.instances.get(name);
54
+ }
55
+ if (service.singleton && this.pendingResolutions.has(name)) {
56
+ return this.pendingResolutions.get(name);
57
+ }
58
+ if (this.resolutionStack.has(name)) {
59
+ throw new ConduithubError(
60
+ `${ERROR_CODE.CIRCULAR_DEPENDENCY_DETECTED}: ${name}`
61
+ );
62
+ }
63
+ this.resolutionStack.add(name);
64
+ const resolutionPromise = (async () => {
65
+ try {
66
+ await this.resolveDependencies(service.dependencies);
67
+ const instance = await Promise.resolve(service.factory());
68
+ if (service.singleton) {
69
+ this.instances.set(name, instance);
70
+ }
71
+ return instance;
72
+ } finally {
73
+ this.resolutionStack.delete(name);
74
+ if (service.singleton) {
75
+ this.pendingResolutions.delete(name);
76
+ }
77
+ }
78
+ })();
79
+ if (service.singleton) {
80
+ this.pendingResolutions.set(name, resolutionPromise);
81
+ }
82
+ return resolutionPromise;
83
+ }
84
+ async resolveDependencies(dependencies) {
85
+ if (!dependencies?.length) return;
86
+ await Promise.all(dependencies.map((dep) => this.resolve(dep)));
87
+ }
88
+ has(name) {
89
+ return this.services.has(name);
90
+ }
91
+ remove(name) {
92
+ this.ensureInitialized();
93
+ if (!this.services.has(name)) {
94
+ throw new ConduithubError(`${ERROR_CODE.SERVICE_NOT_FOUND}: ${name}`);
95
+ }
96
+ this.instances.delete(name);
97
+ this.services.delete(name);
98
+ logger.info(`Service removed: ${name}`);
99
+ }
100
+ clear() {
101
+ this.ensureInitialized();
102
+ this.instances.clear();
103
+ this.services.clear();
104
+ logger.info("All services cleared from the Service Container");
105
+ }
106
+ list() {
107
+ this.ensureInitialized();
108
+ return Array.from(this.services.values());
109
+ }
110
+ isSingleton(name) {
111
+ const descriptor = this.services.get(name);
112
+ return descriptor ? descriptor.singleton : false;
113
+ }
114
+ getDescriptor(name) {
115
+ return this.services.get(name);
116
+ }
117
+ getAllDescriptors() {
118
+ return Array.from(this.services.values());
119
+ }
120
+ async createInstance(name) {
121
+ this.ensureInitialized();
122
+ const descriptor = this.services.get(name);
123
+ if (!descriptor) {
124
+ throw new ConduithubError(`${ERROR_CODE.SERVICE_NOT_FOUND}: ${name}`);
125
+ }
126
+ if (descriptor.singleton) {
127
+ throw new ConduithubError(`${ERROR_CODE.SERVICE_IS_SINGLETON}: ${name}`);
128
+ }
129
+ if (this.instances.has(name)) {
130
+ return this.instances.get(name);
131
+ }
132
+ try {
133
+ await this.resolveDependencies(descriptor.dependencies);
134
+ const instance = await Promise.resolve(descriptor.factory());
135
+ this.instances.set(name, instance);
136
+ logger.info(`Instance created for service: ${name}`);
137
+ return instance;
138
+ } catch (error) {
139
+ logger.error(`Failed to create instance for service: ${name}`, error);
140
+ throw new ConduithubError(
141
+ `${ERROR_CODE.SERVICE_CREATION_FAILED}: ${name}`,
142
+ {
143
+ code: "SERVICE_CREATION_FAILED",
144
+ details: {
145
+ serviceName: name,
146
+ error: error instanceof Error ? error.message : String(error)
147
+ }
148
+ }
149
+ );
150
+ }
151
+ }
152
+ getStats() {
153
+ const descriptors = this.list();
154
+ let singletonCount = 0;
155
+ let transientCount = 0;
156
+ descriptors.forEach((descriptor) => {
157
+ if (descriptor.singleton) {
158
+ singletonCount++;
159
+ } else {
160
+ transientCount++;
161
+ }
162
+ });
163
+ return {
164
+ totalServices: descriptors.length,
165
+ singletonCount,
166
+ transientCount,
167
+ instanceCount: this.instances.size,
168
+ serviceNames: descriptors.map((d) => d.name)
169
+ };
170
+ }
171
+ validateDependencies() {
172
+ const errors = [];
173
+ for (const [name, descriptor] of this.services) {
174
+ if (descriptor.dependencies) {
175
+ for (const dependency of descriptor.dependencies) {
176
+ if (!this.services.has(dependency)) {
177
+ errors.push(
178
+ `Service '${name}' depends on '${dependency}', which is not registered.`
179
+ );
180
+ }
181
+ }
182
+ }
183
+ }
184
+ return {
185
+ valid: errors.length === 0,
186
+ errors
187
+ };
188
+ }
189
+ getDependencyGraph() {
190
+ const graph = {};
191
+ for (const [name, descriptor] of this.services) {
192
+ graph[name] = descriptor.dependencies ? [...descriptor.dependencies] : [];
193
+ }
194
+ return graph;
195
+ }
196
+ getServiceNames() {
197
+ return Array.from(this.services.keys());
198
+ }
199
+ detectCircularDependencies() {
200
+ const graph = this.getDependencyGraph();
201
+ const visited = /* @__PURE__ */ new Set();
202
+ const recursionStack = /* @__PURE__ */ new Set();
203
+ const cycles = [];
204
+ const dfs = (node, path) => {
205
+ if (recursionStack.has(node)) {
206
+ const cycleStart = path.indexOf(node);
207
+ const cycle = path.slice(cycleStart).concat([node]);
208
+ cycles.push(cycle);
209
+ return;
210
+ }
211
+ if (visited.has(node)) {
212
+ return;
213
+ }
214
+ visited.add(node);
215
+ recursionStack.add(node);
216
+ path.push(node);
217
+ for (const dependency of graph[node] || []) {
218
+ dfs(dependency, [...path]);
219
+ }
220
+ recursionStack.delete(node);
221
+ path.pop();
222
+ };
223
+ for (const node of Object.keys(graph)) {
224
+ if (!visited.has(node)) {
225
+ dfs(node, []);
226
+ }
227
+ }
228
+ return cycles;
229
+ }
230
+ async resolveAll(names) {
231
+ this.ensureInitialized();
232
+ return Promise.all(names.map((name) => this.resolve(name)));
233
+ }
234
+ findServicesByMetadata(key, value) {
235
+ this.ensureInitialized();
236
+ return this.list().filter((descriptor) => {
237
+ if (!descriptor.metadata || !(key in descriptor.metadata)) {
238
+ return false;
239
+ }
240
+ return value === void 0 || descriptor.metadata[key] === value;
241
+ });
242
+ }
243
+ getTopologicalOrder() {
244
+ const graph = this.getDependencyGraph();
245
+ const visited = /* @__PURE__ */ new Set();
246
+ const result = [];
247
+ const dfs = (node) => {
248
+ if (visited.has(node)) return;
249
+ visited.add(node);
250
+ for (const dependency of graph[node] || []) {
251
+ dfs(dependency);
252
+ }
253
+ result.push(node);
254
+ };
255
+ for (const node of Object.keys(graph)) {
256
+ dfs(node);
257
+ }
258
+ return result;
259
+ }
260
+ async warmup(serviceNames) {
261
+ this.ensureInitialized();
262
+ const namesToWarmup = serviceNames || this.getServiceNames();
263
+ const singletonServices = namesToWarmup.filter(
264
+ (name) => this.isSingleton(name)
265
+ );
266
+ await Promise.all(
267
+ singletonServices.map(async (name) => {
268
+ try {
269
+ await this.resolve(name);
270
+ logger.info(`Warmed up service: ${name}`);
271
+ } catch (error) {
272
+ logger.error(`Failed to warm up service: ${name}`, error);
273
+ }
274
+ })
275
+ );
276
+ }
277
+ clone() {
278
+ const newContainer = new ServiceContainer();
279
+ for (const [name, descriptor] of this.services) {
280
+ newContainer.services.set(name, { ...descriptor });
281
+ }
282
+ return newContainer;
283
+ }
284
+ dispose(name) {
285
+ this.ensureInitialized();
286
+ if (!this.services.has(name)) {
287
+ throw new ConduithubError(`${ERROR_CODE.SERVICE_NOT_FOUND}: ${name}`);
288
+ }
289
+ const instance = this.instances.get(name);
290
+ if (instance && typeof instance === "object" && "dispose" in instance) {
291
+ try {
292
+ if (typeof instance.dispose === "function") {
293
+ instance.dispose();
294
+ }
295
+ } catch (error) {
296
+ logger.warn(`Error disposing service ${name}:`, error);
297
+ }
298
+ }
299
+ this.instances.delete(name);
300
+ logger.info(`Service disposed: ${name}`);
301
+ }
302
+ }
303
+
304
+ export { ServiceContainer };
@@ -0,0 +1,195 @@
1
+ 'use strict';
2
+
3
+ const index = require('../../shared/conduithub.BqUYv04j.cjs');
4
+ const logger = require('../../shared/conduithub.BNQsddJO.cjs');
5
+ require('process');
6
+ require('readline');
7
+ require('uuid');
8
+ const code = require('../../shared/conduithub.CmZo_Vuc.cjs');
9
+
10
+ class StateManager {
11
+ state = /* @__PURE__ */ new Map();
12
+ subscribers = /* @__PURE__ */ new Map();
13
+ isInitialized = false;
14
+ async initialize() {
15
+ if (this.isInitialized) return;
16
+ this.isInitialized = true;
17
+ logger.logger.success("StateManager initialized successfully");
18
+ }
19
+ async shutdown() {
20
+ if (!this.isInitialized) return;
21
+ logger.logger.info("Shutting down StateManager...");
22
+ this.state.clear();
23
+ this.subscribers.clear();
24
+ this.isInitialized = false;
25
+ logger.logger.success("StateManager shutdown successfully");
26
+ }
27
+ ensureInitialized() {
28
+ if (!this.isInitialized) {
29
+ throw new index.ConduithubError(code.ERROR_CODE.STATE_MANAGER_NOT_INITIALIZED);
30
+ }
31
+ }
32
+ get(key) {
33
+ this.ensureInitialized();
34
+ return this.state.get(key);
35
+ }
36
+ set(key, value) {
37
+ this.ensureInitialized();
38
+ const oldValue = this.state.get(key);
39
+ this.state.set(key, value);
40
+ this.notifySubscribers(key, value, oldValue);
41
+ logger.logger.info(`State set for key '${String(key)}'`);
42
+ }
43
+ delete(key) {
44
+ this.ensureInitialized();
45
+ const oldValue = this.state.get(key);
46
+ const wasDeleted = this.state.delete(key);
47
+ if (wasDeleted) {
48
+ this.notifySubscribers(key, void 0, oldValue);
49
+ logger.logger.info(`State deleted for key '${String(key)}'`);
50
+ }
51
+ return wasDeleted;
52
+ }
53
+ has(key) {
54
+ this.ensureInitialized();
55
+ return this.state.has(key);
56
+ }
57
+ clear() {
58
+ this.ensureInitialized();
59
+ const oldState = new Map(this.state);
60
+ this.state.clear();
61
+ for (const [key, subscribers] of this.subscribers) {
62
+ const oldValue = oldState.get(key);
63
+ this.notifySubscribersWithErrorHandling(
64
+ subscribers,
65
+ void 0,
66
+ oldValue,
67
+ key
68
+ );
69
+ }
70
+ logger.logger.info("All state cleared");
71
+ }
72
+ keys() {
73
+ this.ensureInitialized();
74
+ return Array.from(this.state.keys());
75
+ }
76
+ values() {
77
+ this.ensureInitialized();
78
+ return Array.from(this.state.values());
79
+ }
80
+ entries() {
81
+ this.ensureInitialized();
82
+ return Array.from(this.state.entries());
83
+ }
84
+ size() {
85
+ this.ensureInitialized();
86
+ return this.state.size;
87
+ }
88
+ subscribe(key, callback) {
89
+ this.ensureInitialized();
90
+ if (!this.subscribers.has(key)) {
91
+ this.subscribers.set(key, /* @__PURE__ */ new Set());
92
+ }
93
+ const subscribers = this.subscribers.get(key);
94
+ subscribers.add(callback);
95
+ logger.logger.info(`Subscriber added for key '${String(key)}'`);
96
+ return () => this.unsubscribeCallback(key, callback);
97
+ }
98
+ unsubscribe(key, callback) {
99
+ this.ensureInitialized();
100
+ this.unsubscribeCallback(key, callback);
101
+ }
102
+ getSubscribersCount(key) {
103
+ const subscribers = this.subscribers.get(key);
104
+ return subscribers ? subscribers.size : 0;
105
+ }
106
+ getSubscribedKeys() {
107
+ return Array.from(this.subscribers.keys());
108
+ }
109
+ notifySubscribers(key, newValue, oldValue) {
110
+ const subscribers = this.subscribers.get(key);
111
+ if (subscribers) {
112
+ this.notifySubscribersWithErrorHandling(
113
+ subscribers,
114
+ newValue,
115
+ oldValue,
116
+ key
117
+ );
118
+ }
119
+ }
120
+ notifySubscribersWithErrorHandling(subscribers, newValue, oldValue, key) {
121
+ for (const callback of subscribers) {
122
+ try {
123
+ callback(newValue, oldValue);
124
+ } catch (error) {
125
+ logger.logger.error(
126
+ `Error in state subscriber for key '${String(key)}'`,
127
+ error
128
+ );
129
+ }
130
+ }
131
+ }
132
+ unsubscribeCallback(key, callback) {
133
+ const subscribers = this.subscribers.get(key);
134
+ if (!subscribers) {
135
+ logger.logger.warn(
136
+ `No subscribers found for key '${String(key)}' to unsubscribe`
137
+ );
138
+ return;
139
+ }
140
+ subscribers.delete(callback);
141
+ if (subscribers.size === 0) {
142
+ this.subscribers.delete(key);
143
+ logger.logger.info(
144
+ `No more subscribers for key '${String(key)}', removed from subscribers map`
145
+ );
146
+ } else {
147
+ logger.logger.info(`Subscriber removed for key '${String(key)}'`);
148
+ }
149
+ }
150
+ getStats() {
151
+ const subscribedKeys = this.getSubscribedKeys();
152
+ const subscriberCounts = {};
153
+ for (const key of subscribedKeys) {
154
+ subscriberCounts[String(key)] = this.getSubscribersCount(key);
155
+ }
156
+ const totalSubscribers = subscribedKeys.reduce(
157
+ (sum, key) => sum + this.getSubscribersCount(key),
158
+ 0
159
+ );
160
+ return {
161
+ totalKeys: this.size(),
162
+ totalSubscribers,
163
+ subscribedKeys,
164
+ subscribersCount: subscriberCounts
165
+ };
166
+ }
167
+ getStateSnapshot() {
168
+ const snapshot = {};
169
+ for (const [key, value] of this.state.entries()) {
170
+ snapshot[String(key)] = value;
171
+ }
172
+ return snapshot;
173
+ }
174
+ loadStateSnapshot(snapshot) {
175
+ this.state.clear();
176
+ for (const [key, value] of Object.entries(snapshot)) {
177
+ this.state.set(key, value);
178
+ }
179
+ }
180
+ exportState() {
181
+ return JSON.stringify(this.getStateSnapshot(), null, 2);
182
+ }
183
+ importState(stateJson) {
184
+ try {
185
+ const snapshot = JSON.parse(stateJson);
186
+ this.loadStateSnapshot(snapshot);
187
+ logger.logger.success("State imported successfully");
188
+ } catch (error) {
189
+ logger.logger.error("Failed to import state", error);
190
+ throw new index.ConduithubError(code.ERROR_CODE.INVALID_STATE_JSON_FORMAT);
191
+ }
192
+ }
193
+ }
194
+
195
+ exports.StateManager = StateManager;
@@ -0,0 +1,39 @@
1
+ type StateChangeHandler<T> = (newValue: T, oldValue: T | undefined) => void;
2
+ interface StateStats<T> {
3
+ readonly totalKeys: number;
4
+ readonly totalSubscribers: number;
5
+ readonly subscribedKeys: readonly (keyof T)[];
6
+ readonly subscribersCount: Record<string, number>;
7
+ }
8
+ declare class StateManager<T extends Record<string, unknown> = Record<string, unknown>> {
9
+ private readonly state;
10
+ private readonly subscribers;
11
+ private isInitialized;
12
+ initialize(): Promise<void>;
13
+ shutdown(): Promise<void>;
14
+ private ensureInitialized;
15
+ get<K extends keyof T>(key: K): T[K] | undefined;
16
+ set<K extends keyof T>(key: K, value: T[K]): void;
17
+ delete<K extends keyof T>(key: K): boolean;
18
+ has<K extends keyof T>(key: K): boolean;
19
+ clear(): void;
20
+ keys(): (keyof T)[];
21
+ values(): T[keyof T][];
22
+ entries(): [keyof T, T[keyof T]][];
23
+ size(): number;
24
+ subscribe<K extends keyof T>(key: K, callback: StateChangeHandler<T[K]>): () => void;
25
+ unsubscribe<K extends keyof T>(key: K, callback: StateChangeHandler<T[K]>): void;
26
+ getSubscribersCount<K extends keyof T>(key: K): number;
27
+ getSubscribedKeys(): (keyof T)[];
28
+ private notifySubscribers;
29
+ private notifySubscribersWithErrorHandling;
30
+ private unsubscribeCallback;
31
+ getStats(): StateStats<T>;
32
+ private getStateSnapshot;
33
+ private loadStateSnapshot;
34
+ exportState(): string;
35
+ importState(stateJson: string): void;
36
+ }
37
+
38
+ export { StateManager };
39
+ export type { StateChangeHandler };
@@ -0,0 +1,39 @@
1
+ type StateChangeHandler<T> = (newValue: T, oldValue: T | undefined) => void;
2
+ interface StateStats<T> {
3
+ readonly totalKeys: number;
4
+ readonly totalSubscribers: number;
5
+ readonly subscribedKeys: readonly (keyof T)[];
6
+ readonly subscribersCount: Record<string, number>;
7
+ }
8
+ declare class StateManager<T extends Record<string, unknown> = Record<string, unknown>> {
9
+ private readonly state;
10
+ private readonly subscribers;
11
+ private isInitialized;
12
+ initialize(): Promise<void>;
13
+ shutdown(): Promise<void>;
14
+ private ensureInitialized;
15
+ get<K extends keyof T>(key: K): T[K] | undefined;
16
+ set<K extends keyof T>(key: K, value: T[K]): void;
17
+ delete<K extends keyof T>(key: K): boolean;
18
+ has<K extends keyof T>(key: K): boolean;
19
+ clear(): void;
20
+ keys(): (keyof T)[];
21
+ values(): T[keyof T][];
22
+ entries(): [keyof T, T[keyof T]][];
23
+ size(): number;
24
+ subscribe<K extends keyof T>(key: K, callback: StateChangeHandler<T[K]>): () => void;
25
+ unsubscribe<K extends keyof T>(key: K, callback: StateChangeHandler<T[K]>): void;
26
+ getSubscribersCount<K extends keyof T>(key: K): number;
27
+ getSubscribedKeys(): (keyof T)[];
28
+ private notifySubscribers;
29
+ private notifySubscribersWithErrorHandling;
30
+ private unsubscribeCallback;
31
+ getStats(): StateStats<T>;
32
+ private getStateSnapshot;
33
+ private loadStateSnapshot;
34
+ exportState(): string;
35
+ importState(stateJson: string): void;
36
+ }
37
+
38
+ export { StateManager };
39
+ export type { StateChangeHandler };
@@ -0,0 +1,39 @@
1
+ type StateChangeHandler<T> = (newValue: T, oldValue: T | undefined) => void;
2
+ interface StateStats<T> {
3
+ readonly totalKeys: number;
4
+ readonly totalSubscribers: number;
5
+ readonly subscribedKeys: readonly (keyof T)[];
6
+ readonly subscribersCount: Record<string, number>;
7
+ }
8
+ declare class StateManager<T extends Record<string, unknown> = Record<string, unknown>> {
9
+ private readonly state;
10
+ private readonly subscribers;
11
+ private isInitialized;
12
+ initialize(): Promise<void>;
13
+ shutdown(): Promise<void>;
14
+ private ensureInitialized;
15
+ get<K extends keyof T>(key: K): T[K] | undefined;
16
+ set<K extends keyof T>(key: K, value: T[K]): void;
17
+ delete<K extends keyof T>(key: K): boolean;
18
+ has<K extends keyof T>(key: K): boolean;
19
+ clear(): void;
20
+ keys(): (keyof T)[];
21
+ values(): T[keyof T][];
22
+ entries(): [keyof T, T[keyof T]][];
23
+ size(): number;
24
+ subscribe<K extends keyof T>(key: K, callback: StateChangeHandler<T[K]>): () => void;
25
+ unsubscribe<K extends keyof T>(key: K, callback: StateChangeHandler<T[K]>): void;
26
+ getSubscribersCount<K extends keyof T>(key: K): number;
27
+ getSubscribedKeys(): (keyof T)[];
28
+ private notifySubscribers;
29
+ private notifySubscribersWithErrorHandling;
30
+ private unsubscribeCallback;
31
+ getStats(): StateStats<T>;
32
+ private getStateSnapshot;
33
+ private loadStateSnapshot;
34
+ exportState(): string;
35
+ importState(stateJson: string): void;
36
+ }
37
+
38
+ export { StateManager };
39
+ export type { StateChangeHandler };