scope-state 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.
- package/README.md +372 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.esm.js +2023 -0
- package/dist/index.js +2073 -0
- package/dist/src/config/index.d.ts +84 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/core/listeners.d.ts +24 -0
- package/dist/src/core/listeners.d.ts.map +1 -0
- package/dist/src/core/monitoring.d.ts +167 -0
- package/dist/src/core/monitoring.d.ts.map +1 -0
- package/dist/src/core/proxy.d.ts +50 -0
- package/dist/src/core/proxy.d.ts.map +1 -0
- package/dist/src/core/store.d.ts +39 -0
- package/dist/src/core/store.d.ts.map +1 -0
- package/dist/src/core/tracking.d.ts +36 -0
- package/dist/src/core/tracking.d.ts.map +1 -0
- package/dist/src/hooks/useLocal.d.ts +32 -0
- package/dist/src/hooks/useLocal.d.ts.map +1 -0
- package/dist/src/hooks/useScope.d.ts +29 -0
- package/dist/src/hooks/useScope.d.ts.map +1 -0
- package/dist/src/index.d.ts +33 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/persistence/advanced.d.ts +47 -0
- package/dist/src/persistence/advanced.d.ts.map +1 -0
- package/dist/src/persistence/storage.d.ts +14 -0
- package/dist/src/persistence/storage.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +175 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { ProxyConfig, MonitoringConfig, PersistenceConfig, ScopeConfig } from '../types';
|
|
2
|
+
export declare const defaultProxyConfig: ProxyConfig;
|
|
3
|
+
export declare const defaultMonitoringConfig: MonitoringConfig;
|
|
4
|
+
export declare const defaultPersistenceConfig: PersistenceConfig;
|
|
5
|
+
export declare let proxyConfig: {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
maxDepth: number;
|
|
8
|
+
selectiveProxying: boolean;
|
|
9
|
+
trackPathUsage: boolean;
|
|
10
|
+
lazyProxyDeepObjects: boolean;
|
|
11
|
+
preProxyPaths: string[];
|
|
12
|
+
maxPathLength: number;
|
|
13
|
+
smartArrayTracking: boolean;
|
|
14
|
+
nonBlockingProxyCreation: boolean;
|
|
15
|
+
batchSize: number;
|
|
16
|
+
prioritizeUIObjects: boolean;
|
|
17
|
+
maxQueueSize: number;
|
|
18
|
+
memoryLimit: boolean;
|
|
19
|
+
memoryThreshold: number;
|
|
20
|
+
targetMemoryUsage: number;
|
|
21
|
+
proxyEvictionStrategy: "lru";
|
|
22
|
+
disableProxyingUnderPressure: boolean;
|
|
23
|
+
maxProxyCacheSize: number;
|
|
24
|
+
ultraSelectiveProxying: boolean;
|
|
25
|
+
proxySelectorPaths: boolean; /**
|
|
26
|
+
* Full-featured preset: All features enabled
|
|
27
|
+
*/
|
|
28
|
+
forceMemoryCheck: boolean;
|
|
29
|
+
aggressiveMemoryManagement: boolean;
|
|
30
|
+
priorityPaths: string[];
|
|
31
|
+
};
|
|
32
|
+
export declare let monitoringConfig: {
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
verboseLogging: boolean;
|
|
35
|
+
logSubscriptions: boolean;
|
|
36
|
+
logProxyCreation: boolean;
|
|
37
|
+
logStateChanges: boolean;
|
|
38
|
+
logPersistence: boolean;
|
|
39
|
+
logTimings: boolean;
|
|
40
|
+
autoLeakDetection: boolean;
|
|
41
|
+
leakDetectionInterval: number;
|
|
42
|
+
leakAlertThreshold: number;
|
|
43
|
+
leakScanMinimumRenderCycles: number;
|
|
44
|
+
};
|
|
45
|
+
export declare let persistenceConfig: {
|
|
46
|
+
enabled: boolean;
|
|
47
|
+
paths: string[] | undefined;
|
|
48
|
+
blacklist: string[];
|
|
49
|
+
batchDelay: number;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Get current configuration
|
|
53
|
+
*/
|
|
54
|
+
export declare function getConfig(): {
|
|
55
|
+
proxy: ProxyConfig;
|
|
56
|
+
monitoring: MonitoringConfig;
|
|
57
|
+
persistence: PersistenceConfig;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Reset all configuration to defaults
|
|
61
|
+
*/
|
|
62
|
+
export declare function resetConfig(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Quick presets for common use cases
|
|
65
|
+
*/
|
|
66
|
+
export declare const presets: {
|
|
67
|
+
/**
|
|
68
|
+
* Development preset: Enhanced debugging and monitoring
|
|
69
|
+
*/
|
|
70
|
+
development: <T extends Record<string, any> = Record<string, any>>() => ScopeConfig<T>;
|
|
71
|
+
/**
|
|
72
|
+
* Production preset: Optimized for performance
|
|
73
|
+
*/
|
|
74
|
+
production: <T_1 extends Record<string, any> = Record<string, any>>() => ScopeConfig<T_1>;
|
|
75
|
+
/**
|
|
76
|
+
* Memory-constrained preset: Minimal memory usage
|
|
77
|
+
*/
|
|
78
|
+
minimal: <T_2 extends Record<string, any> = Record<string, any>>() => ScopeConfig<T_2>;
|
|
79
|
+
/**
|
|
80
|
+
* Full-featured preset: All features enabled
|
|
81
|
+
*/
|
|
82
|
+
full: <T_3 extends Record<string, any> = Record<string, any>>() => ScopeConfig<T_3>;
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACZ,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,kBAAkB,EAAE,WAwBhC,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,gBAYrC,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,iBAKtC,CAAC;AAGF,eAAO,IAAI,WAAW;;;;;;;;;;;;;;;;;;;;iCAyFpB;;OAEG;;;;CA3F6C,CAAC;AACnD,eAAO,IAAI,gBAAgB;;;;;;;;;;;;CAAiC,CAAC;AAC7D,eAAO,IAAI,iBAAiB;;;;;CAAkC,CAAC;AAK/D;;GAEG;AACH,wBAAgB,SAAS,IAAI;IAC3B,KAAK,EAAE,WAAW,CAAC;IACnB,UAAU,EAAE,gBAAgB,CAAC;IAC7B,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAMA;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAIlC;AAED;;GAEG;AACH,eAAO,MAAM,OAAO;IAClB;;OAEG;;IAeH;;OAEG;;IAgBH;;OAEG;;IAiBH;;OAEG;;CAeJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PathListeners, Listener, MonitoringStats } from '../types';
|
|
2
|
+
export declare const pathListeners: PathListeners;
|
|
3
|
+
export declare let monitoringStats: MonitoringStats;
|
|
4
|
+
/**
|
|
5
|
+
* Subscribe to changes on a specific path
|
|
6
|
+
*/
|
|
7
|
+
export declare function subscribe(path: string, listener: Listener): () => void;
|
|
8
|
+
/**
|
|
9
|
+
* Notify all listeners for a given path and its parents/children
|
|
10
|
+
*/
|
|
11
|
+
export declare function notifyListeners(path: string[]): void;
|
|
12
|
+
/**
|
|
13
|
+
* Get total number of active listeners
|
|
14
|
+
*/
|
|
15
|
+
export declare function getListenerCount(): number;
|
|
16
|
+
/**
|
|
17
|
+
* Get all active paths
|
|
18
|
+
*/
|
|
19
|
+
export declare function getActivePaths(): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Clear all listeners (for cleanup)
|
|
22
|
+
*/
|
|
23
|
+
export declare function clearAllListeners(): void;
|
|
24
|
+
//# sourceMappingURL=listeners.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listeners.d.ts","sourceRoot":"","sources":["../../../src/core/listeners.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAIzE,eAAO,MAAM,aAAa,EAAE,aAAyB,CAAC;AAGtD,eAAO,IAAI,eAAe,EAAE,eAwB3B,CAAC;AAEF;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI,CAqBtE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAoEpD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAMzC;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,EAAE,CAEzC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAKxC"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { monitoringConfig } from '../config';
|
|
3
|
+
import { getProxyCacheStats, optimizeMemoryUsage } from './proxy';
|
|
4
|
+
/**
|
|
5
|
+
* Monitor API for debugging and memory leak detection
|
|
6
|
+
*/
|
|
7
|
+
export declare const monitorAPI: {
|
|
8
|
+
setEnabled: (enabled: boolean) => void;
|
|
9
|
+
setVerboseLogging: (enabled: boolean) => void;
|
|
10
|
+
configure: (config: Partial<typeof monitoringConfig>) => void;
|
|
11
|
+
getStats: () => {
|
|
12
|
+
proxyCount: number;
|
|
13
|
+
totalSubscriptionsCreated: number;
|
|
14
|
+
totalSubscriptionsRemoved: number;
|
|
15
|
+
activeSubscriptions: number;
|
|
16
|
+
pathSubscriptionCounts: Record<string, number>;
|
|
17
|
+
timings: {
|
|
18
|
+
lastNotifyTime: number;
|
|
19
|
+
lastPersistTime: number;
|
|
20
|
+
averageNotifyTime: number;
|
|
21
|
+
averagePersistTime: number;
|
|
22
|
+
notifyTimeTotal: number;
|
|
23
|
+
persistTimeTotal: number;
|
|
24
|
+
notifyCount: number;
|
|
25
|
+
persistCount: number;
|
|
26
|
+
};
|
|
27
|
+
leakDetection: {
|
|
28
|
+
lastCheckTime: number;
|
|
29
|
+
totalChecks: number;
|
|
30
|
+
leaksDetected: number;
|
|
31
|
+
renderCyclesSinceCheck: number;
|
|
32
|
+
isLeakDetectionRunning: boolean;
|
|
33
|
+
leakDetectionTimer: NodeJS.Timeout | null;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
getListenerInfo: () => Record<string, number>;
|
|
37
|
+
checkForLeaks: (logReport?: boolean) => {
|
|
38
|
+
orphanedListeners: number;
|
|
39
|
+
mismatchedCounts: string[];
|
|
40
|
+
emptyPaths: string[];
|
|
41
|
+
totalListeners: number;
|
|
42
|
+
summary: string;
|
|
43
|
+
} | null;
|
|
44
|
+
startAutoLeakDetection: (interval?: number) => boolean;
|
|
45
|
+
stopAutoLeakDetection: () => boolean;
|
|
46
|
+
configureLeakDetection: (config: {
|
|
47
|
+
enabled?: boolean;
|
|
48
|
+
interval?: number;
|
|
49
|
+
alertThreshold?: number;
|
|
50
|
+
minimumRenderCycles?: number;
|
|
51
|
+
}) => void;
|
|
52
|
+
getLeakDetectionStats: () => {
|
|
53
|
+
isEnabled: boolean;
|
|
54
|
+
interval: number;
|
|
55
|
+
checksPerformed: number;
|
|
56
|
+
leaksDetected: number;
|
|
57
|
+
alertThreshold: number;
|
|
58
|
+
};
|
|
59
|
+
resetStats: () => void;
|
|
60
|
+
cleanupEmptyListeners: () => number;
|
|
61
|
+
getProxyCacheStats: typeof getProxyCacheStats;
|
|
62
|
+
getProxyUsageStats: () => {
|
|
63
|
+
accessedPaths: string[];
|
|
64
|
+
modifiedPaths: string[];
|
|
65
|
+
subscribedPaths: string[];
|
|
66
|
+
totalAccessedPaths: number;
|
|
67
|
+
totalModifiedPaths: number;
|
|
68
|
+
totalSubscribedPaths: number;
|
|
69
|
+
};
|
|
70
|
+
resetProxyUsageStats: () => void;
|
|
71
|
+
generatePathUsageReport: () => {
|
|
72
|
+
mostAccessedPaths: string[];
|
|
73
|
+
mostModifiedPaths: string[];
|
|
74
|
+
subscribedPaths: string[];
|
|
75
|
+
recommendations: string[];
|
|
76
|
+
};
|
|
77
|
+
optimizeMemoryUsage: typeof optimizeMemoryUsage;
|
|
78
|
+
getSelectorPathStats: () => {
|
|
79
|
+
totalSelectorPaths: number;
|
|
80
|
+
paths: string[];
|
|
81
|
+
mostAccessedSelectorPaths: string[];
|
|
82
|
+
};
|
|
83
|
+
clearSelectorPaths: () => number;
|
|
84
|
+
getSystemStatus: () => {
|
|
85
|
+
monitoring: {
|
|
86
|
+
enabled: boolean;
|
|
87
|
+
verboseLogging: boolean;
|
|
88
|
+
autoLeakDetection: boolean;
|
|
89
|
+
};
|
|
90
|
+
listeners: {
|
|
91
|
+
total: number;
|
|
92
|
+
pathCount: number;
|
|
93
|
+
};
|
|
94
|
+
proxies: {
|
|
95
|
+
cacheSize: number;
|
|
96
|
+
hitRatio: number;
|
|
97
|
+
totalCreated: number;
|
|
98
|
+
};
|
|
99
|
+
paths: {
|
|
100
|
+
accessed: number;
|
|
101
|
+
modified: number;
|
|
102
|
+
subscribed: number;
|
|
103
|
+
selectors: number;
|
|
104
|
+
};
|
|
105
|
+
leakDetection: {
|
|
106
|
+
isEnabled: boolean;
|
|
107
|
+
interval: number;
|
|
108
|
+
checksPerformed: number;
|
|
109
|
+
leaksDetected: number;
|
|
110
|
+
alertThreshold: number;
|
|
111
|
+
};
|
|
112
|
+
performance: {
|
|
113
|
+
averageNotifyTime: number;
|
|
114
|
+
averagePersistTime: number;
|
|
115
|
+
totalNotifications: number;
|
|
116
|
+
totalPersistOperations: number;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
performHealthCheck: () => {
|
|
120
|
+
healthScore: number;
|
|
121
|
+
recommendations: string[];
|
|
122
|
+
systemStatus: {
|
|
123
|
+
monitoring: {
|
|
124
|
+
enabled: boolean;
|
|
125
|
+
verboseLogging: boolean;
|
|
126
|
+
autoLeakDetection: boolean;
|
|
127
|
+
};
|
|
128
|
+
listeners: {
|
|
129
|
+
total: number;
|
|
130
|
+
pathCount: number;
|
|
131
|
+
};
|
|
132
|
+
proxies: {
|
|
133
|
+
cacheSize: number;
|
|
134
|
+
hitRatio: number;
|
|
135
|
+
totalCreated: number;
|
|
136
|
+
};
|
|
137
|
+
paths: {
|
|
138
|
+
accessed: number;
|
|
139
|
+
modified: number;
|
|
140
|
+
subscribed: number;
|
|
141
|
+
selectors: number;
|
|
142
|
+
};
|
|
143
|
+
leakDetection: {
|
|
144
|
+
isEnabled: boolean;
|
|
145
|
+
interval: number;
|
|
146
|
+
checksPerformed: number;
|
|
147
|
+
leaksDetected: number;
|
|
148
|
+
alertThreshold: number;
|
|
149
|
+
};
|
|
150
|
+
performance: {
|
|
151
|
+
averageNotifyTime: number;
|
|
152
|
+
averagePersistTime: number;
|
|
153
|
+
totalNotifications: number;
|
|
154
|
+
totalPersistOperations: number;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
leakReport: {
|
|
158
|
+
orphanedListeners: number;
|
|
159
|
+
mismatchedCounts: string[];
|
|
160
|
+
emptyPaths: string[];
|
|
161
|
+
totalListeners: number;
|
|
162
|
+
summary: string;
|
|
163
|
+
} | null;
|
|
164
|
+
cleanedListeners: number;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
//# sourceMappingURL=monitoring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitoring.d.ts","sourceRoot":"","sources":["../../../src/core/monitoring.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAiC,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AA6CjG;;GAEG;AACH,eAAO,MAAM,UAAU;0BAEC,OAAO;iCAMA,OAAO;wBAMhB,QAAQ,uBAAuB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCAgGnB;QAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoNF,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CustomMethods, CustomArrayMethods } from '../types';
|
|
2
|
+
export declare const proxyPathMap: WeakMap<object, string[]>;
|
|
3
|
+
export declare const pathUsageStats: {
|
|
4
|
+
accessedPaths: Set<string>;
|
|
5
|
+
modifiedPaths: Set<string>;
|
|
6
|
+
subscribedPaths: Set<string>;
|
|
7
|
+
};
|
|
8
|
+
export declare const selectorPaths: Set<string>;
|
|
9
|
+
export declare const proxyCacheStats: {
|
|
10
|
+
cacheHits: number;
|
|
11
|
+
cacheMisses: number;
|
|
12
|
+
totalProxiesCreated: number;
|
|
13
|
+
activeCachedProxies: number;
|
|
14
|
+
};
|
|
15
|
+
export declare const memoryPressure: {
|
|
16
|
+
isUnderPressure: boolean;
|
|
17
|
+
lastCheckTime: number;
|
|
18
|
+
checkInterval: number;
|
|
19
|
+
highUsageCount: number;
|
|
20
|
+
check(): boolean;
|
|
21
|
+
estimateMemoryUsage(): number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Set the initial store state for reset functionality
|
|
25
|
+
*/
|
|
26
|
+
export declare function setInitialStoreState(state: any): void;
|
|
27
|
+
/**
|
|
28
|
+
* Create an advanced proxy with all the features from the original code
|
|
29
|
+
*/
|
|
30
|
+
export declare function createAdvancedProxy<T extends object>(target: T, path?: string[], depth?: number): T & (T extends any[] ? CustomArrayMethods<T[0]> : CustomMethods<T>);
|
|
31
|
+
/**
|
|
32
|
+
* Clear proxy cache
|
|
33
|
+
*/
|
|
34
|
+
export declare function clearProxyCache(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get proxy cache statistics
|
|
37
|
+
*/
|
|
38
|
+
export declare function getProxyCacheStats(): {
|
|
39
|
+
hitRatio: number;
|
|
40
|
+
estimatedCacheSize: number;
|
|
41
|
+
cacheHits: number;
|
|
42
|
+
cacheMisses: number;
|
|
43
|
+
totalProxiesCreated: number;
|
|
44
|
+
activeCachedProxies: number;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Optimize memory usage
|
|
48
|
+
*/
|
|
49
|
+
export declare function optimizeMemoryUsage(aggressive?: boolean): any;
|
|
50
|
+
//# sourceMappingURL=proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../src/core/proxy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAGlE,eAAO,MAAM,YAAY,2BAAkC,CAAC;AAM5D,eAAO,MAAM,cAAc;;;;CAI1B,CAAC;AAGF,eAAO,MAAM,aAAa,aAAoB,CAAC;AAM/C,eAAO,MAAM,eAAe;;;;;CAK3B,CAAC;AAiGF,eAAO,MAAM,cAAc;;;;;;2BA4CF,MAAM;CAS9B,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,CAErD;AAYD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,EAClD,MAAM,EAAE,CAAC,EACT,IAAI,GAAE,MAAM,EAAO,EACnB,KAAK,GAAE,MAAU,GAChB,CAAC,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAmKrE;AA8UD;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAUtC;AAED;;GAEG;AACH,wBAAgB,kBAAkB;;;;;;;EAMjC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,UAAQ,GAAG,GAAG,CA4B3D"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ScopeConfig } from '../types';
|
|
2
|
+
declare const defaultStore: {
|
|
3
|
+
user: {
|
|
4
|
+
name: string;
|
|
5
|
+
age: number;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare let store: {
|
|
9
|
+
user: {
|
|
10
|
+
name: string;
|
|
11
|
+
age: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare let initialStoreState: any;
|
|
15
|
+
export type CurrentStoreType = typeof store;
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the store with custom initial state
|
|
18
|
+
* This function updates both the store and its type
|
|
19
|
+
*/
|
|
20
|
+
export declare function initializeStore<T extends Record<string, any>>(config?: ScopeConfig<T>): T extends Record<string, any> ? T : typeof defaultStore;
|
|
21
|
+
/**
|
|
22
|
+
* Get the current store (for debugging)
|
|
23
|
+
*/
|
|
24
|
+
export declare function getStore(): {
|
|
25
|
+
user: {
|
|
26
|
+
name: string;
|
|
27
|
+
age: number;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Get the initial store state (for debugging)
|
|
32
|
+
*/
|
|
33
|
+
export declare function getInitialStore(): any;
|
|
34
|
+
/**
|
|
35
|
+
* Reset the entire store to its initial state
|
|
36
|
+
*/
|
|
37
|
+
export declare function resetStore(): void;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/core/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG5C,QAAA,MAAM,YAAY;;;;;CAKjB,CAAC;AAGF,eAAO,IAAI,KAAK;;;;;CAAe,CAAC;AAGhC,eAAO,IAAI,iBAAiB,KAAoC,CAAC;AAGjE,MAAM,MAAM,gBAAgB,GAAG,OAAO,KAAK,CAAC;AAE5C;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAE,WAAW,CAAC,CAAC,CAAM,GAAG,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,OAAO,YAAY,CAiBnJ;AAED;;GAEG;AACH,wBAAgB,QAAQ;;;;;EAEvB;AAED;;GAEG;AACH,wBAAgB,eAAe,QAE9B;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAYjC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Track dependencies during selector execution - tracks individual path segments
|
|
3
|
+
*/
|
|
4
|
+
export declare function trackDependencies<T>(selector: () => T): {
|
|
5
|
+
value: T;
|
|
6
|
+
paths: string[];
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Check if we're currently tracking dependencies
|
|
10
|
+
*/
|
|
11
|
+
export declare function isCurrentlyTracking(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Temporarily skip tracking (for array method internals)
|
|
14
|
+
*/
|
|
15
|
+
export declare function skipTracking<T>(fn: () => T): T;
|
|
16
|
+
/**
|
|
17
|
+
* Get current tracking state (for debugging)
|
|
18
|
+
*/
|
|
19
|
+
export declare function getTrackingState(): {
|
|
20
|
+
isTracking: boolean;
|
|
21
|
+
currentPath: string[];
|
|
22
|
+
skipDepth: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Add a path segment to tracking during proxy get operations
|
|
26
|
+
*/
|
|
27
|
+
export declare function trackPathAccess(path: string[]): void;
|
|
28
|
+
/**
|
|
29
|
+
* Mark a path as modified during proxy set operations
|
|
30
|
+
*/
|
|
31
|
+
export declare function trackPathModification(path: string[]): void;
|
|
32
|
+
/**
|
|
33
|
+
* Reset tracking state (for testing/debugging)
|
|
34
|
+
*/
|
|
35
|
+
export declare function resetTracking(): void;
|
|
36
|
+
//# sourceMappingURL=tracking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracking.d.ts","sourceRoot":"","sources":["../../../src/core/tracking.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAqBrF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAE7C;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAO9C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB,CAMA;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAepD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAQ1D;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAIpC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CustomMethods, CustomArrayMethods } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to create reactive local state that persists across component re-renders.
|
|
4
|
+
*
|
|
5
|
+
* This creates a reactive proxy object with custom methods ($merge, $set, $update, etc.)
|
|
6
|
+
* that can be used to update local component state. Unlike the global store,
|
|
7
|
+
* this state is isolated to the component instance.
|
|
8
|
+
*
|
|
9
|
+
* The state persists across re-renders but is reset when the component unmounts.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* function MyComponent() {
|
|
13
|
+
* const localState = useLocal({ count: 0, name: 'John' });
|
|
14
|
+
*
|
|
15
|
+
* return (
|
|
16
|
+
* <div>
|
|
17
|
+
* <p>Count: {localState.count}</p>
|
|
18
|
+
* <button onClick={() => localState.$merge({ count: localState.count + 1 })}>
|
|
19
|
+
* Increment
|
|
20
|
+
* </button>
|
|
21
|
+
* <button onClick={() => localState.$update('name', name => name.toUpperCase())}>
|
|
22
|
+
* Uppercase Name
|
|
23
|
+
* </button>
|
|
24
|
+
* </div>
|
|
25
|
+
* );
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* @param initialState - The initial state object
|
|
29
|
+
* @returns A reactive proxy object with custom methods for state updates
|
|
30
|
+
*/
|
|
31
|
+
export declare function useLocal<T extends object>(initialState: T): T extends any[] ? T & CustomArrayMethods<T[0]> : T & CustomMethods<T>;
|
|
32
|
+
//# sourceMappingURL=useLocal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocal.d.ts","sourceRoot":"","sources":["../../../src/hooks/useLocal.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,EACvC,YAAY,EAAE,CAAC,GACd,CAAC,SAAS,GAAG,EAAE,GACd,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC5B,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAQvB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CustomMethods, CustomArrayMethods } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to subscribe to the global store and re-render when specific data changes.
|
|
4
|
+
*
|
|
5
|
+
* The hook tracks which store paths your selector function accesses and only
|
|
6
|
+
* re-renders the component when those specific paths change. This provides
|
|
7
|
+
* fine-grained reactivity without unnecessary renders.
|
|
8
|
+
*
|
|
9
|
+
* For objects, the returned value includes custom methods ($merge, $set, $delete, $update)
|
|
10
|
+
* that allow you to modify the data directly and trigger reactive updates.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Subscribe to user data
|
|
14
|
+
* const user = useScope(() => $.user);
|
|
15
|
+
*
|
|
16
|
+
* // Update user data directly (triggers re-render only for components using $.user)
|
|
17
|
+
* user.$merge({ name: 'New Name' });
|
|
18
|
+
*
|
|
19
|
+
* // Subscribe to a specific property
|
|
20
|
+
* const userName = useScope(() => $.user.name);
|
|
21
|
+
*
|
|
22
|
+
* // Subscribe to a computed value
|
|
23
|
+
* const isAdmin = useScope(() => $.user.role === 'admin');
|
|
24
|
+
*
|
|
25
|
+
* @param selector - Function that returns the data you want to subscribe to
|
|
26
|
+
* @returns The selected data, with custom methods attached if it's an object
|
|
27
|
+
*/
|
|
28
|
+
export declare function useScope<T>(selector: () => T): T extends object ? T & CustomMethods<T> : T extends Array<infer U> ? U[] & CustomArrayMethods<U> : T;
|
|
29
|
+
//# sourceMappingURL=useScope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScope.d.ts","sourceRoot":"","sources":["../../../src/hooks/useScope.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,QAAQ,EAAE,MAAM,CAAC,GAChB,CAAC,SAAS,MAAM,GACf,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,GACpB,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GACxB,CAAC,EAAE,GAAG,kBAAkB,CAAC,CAAC,CAAC,GAC3B,CAAC,CAsDJ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export { useScope } from './hooks/useScope';
|
|
2
|
+
export { useLocal } from './hooks/useLocal';
|
|
3
|
+
export { getConfig, resetConfig, presets } from './config';
|
|
4
|
+
export { initializeStore, getStore, resetStore } from './core/store';
|
|
5
|
+
export { monitorAPI } from './core/monitoring';
|
|
6
|
+
export { persistenceAPI } from './persistence/advanced';
|
|
7
|
+
export { setInitialStoreState, createAdvancedProxy, pathUsageStats, selectorPaths, clearProxyCache, getProxyCacheStats, optimizeMemoryUsage, proxyPathMap } from './core/proxy';
|
|
8
|
+
export type { ScopeConfig, ProxyConfig, MonitoringConfig, PersistenceConfig, CustomMethods, CustomArrayMethods, StoreType, MonitoringStats, ProxyCacheStats, PathUsageStats } from './types';
|
|
9
|
+
import type { StoreType, CustomMethods, CustomArrayMethods, ScopeConfig } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Configure Scope with custom settings and return a properly typed store
|
|
12
|
+
* This is the main way to set up Scope with TypeScript support
|
|
13
|
+
*/
|
|
14
|
+
export declare function configure<T extends Record<string, any>>(config: ScopeConfig<T>): StoreType<T>;
|
|
15
|
+
export declare function trackDependenciesAdvanced<T>(selector: () => T): {
|
|
16
|
+
value: T;
|
|
17
|
+
paths: string[];
|
|
18
|
+
};
|
|
19
|
+
export declare const $: StoreType<any>;
|
|
20
|
+
export declare function createReactive<T extends object>(obj: T): T & (T extends any[] ? CustomArrayMethods<T[0]> : CustomMethods<T>);
|
|
21
|
+
export declare const $local: typeof createReactive;
|
|
22
|
+
export declare function isReactive(obj: any): boolean;
|
|
23
|
+
export declare function activate<T>(obj: T): T;
|
|
24
|
+
export declare function $activate<T>(obj: T): T;
|
|
25
|
+
export declare function getProxy<T = any>(path: string | string[] | any): T;
|
|
26
|
+
export declare function $get<T = any>(path: string | string[] | T): T;
|
|
27
|
+
export declare const debugInfo: {
|
|
28
|
+
getListenerCount: () => any;
|
|
29
|
+
getPathCount: () => any;
|
|
30
|
+
getActivePaths: () => any;
|
|
31
|
+
};
|
|
32
|
+
export declare const rawStore: any;
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAGrE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EACb,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,SAAS,EACT,eAAe,EACf,eAAe,EACf,cAAc,EACf,MAAM,SAAS,CAAC;AAQjB,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAYzF;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrD,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GACrB,SAAS,CAAC,CAAC,CAAC,CAwCd;AAGD,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAqB7F;AASD,eAAO,MAAM,CAAC,EAAE,SAAS,CAAC,GAAG,CAAoB,CAAC;AAGlD,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,SAAS,GAAG,EAAE,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAE5H;AAGD,eAAO,MAAM,MAAM,uBAAiB,CAAC;AAGrC,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAE5C;AAGD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAyBrC;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAEtC;AAED,wBAAgB,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,GAAG,GAAG,CAAC,CAsClE;AAED,wBAAgB,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAK5D;AAcD,eAAO,MAAM,SAAS;;;;CAarB,CAAC;AAGF,eAAO,MAAM,QAAQ,KAAc,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add a path to the persistence batch
|
|
3
|
+
*/
|
|
4
|
+
export declare function addToPersistenceBatch(path: string[]): void;
|
|
5
|
+
/**
|
|
6
|
+
* Hydrate state from storage
|
|
7
|
+
*/
|
|
8
|
+
export declare function hydrateState(store?: any): Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* Load persistence configuration
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadPersistenceConfig(): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Save persistence configuration
|
|
15
|
+
*/
|
|
16
|
+
export declare function savePersistenceConfig(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Persistence API - matches the original implementation
|
|
19
|
+
*/
|
|
20
|
+
export declare const persistenceAPI: {
|
|
21
|
+
setEnabled: (enabled: boolean) => void;
|
|
22
|
+
persistPaths: (paths: string[]) => void;
|
|
23
|
+
unpersistPaths: (paths: string[]) => void;
|
|
24
|
+
blacklistPaths: (paths: string[]) => void;
|
|
25
|
+
unblacklistPaths: (paths: string[]) => void;
|
|
26
|
+
getConfig: () => {
|
|
27
|
+
enabled: boolean;
|
|
28
|
+
paths: string[] | undefined;
|
|
29
|
+
blacklist: string[];
|
|
30
|
+
batchDelay: number;
|
|
31
|
+
};
|
|
32
|
+
setBatchDelay: (delay: number) => void;
|
|
33
|
+
reset: () => Promise<void>;
|
|
34
|
+
persist: () => void;
|
|
35
|
+
flushBatch: () => void;
|
|
36
|
+
rehydrate: (store?: any) => Promise<boolean>;
|
|
37
|
+
getBatchStatus: () => {
|
|
38
|
+
pendingPaths: string[];
|
|
39
|
+
isPersisting: boolean;
|
|
40
|
+
batchSize: number;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Initialize persistence system
|
|
45
|
+
*/
|
|
46
|
+
export declare function initializePersistence(): void;
|
|
47
|
+
//# sourceMappingURL=advanced.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../../src/persistence/advanced.ts"],"names":[],"mappings":"AA8FA;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAQ1D;AAoDD;;GAEG;AACH,wBAAsB,YAAY,CAAC,KAAK,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAoEhE;AAED;;GAEG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAe3D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAW5C;AAED;;GAEG;AACH,eAAO,MAAM,cAAc;0BAEH,OAAO;0BAMP,MAAM,EAAE;4BAWN,MAAM,EAAE;4BAeR,MAAM,EAAE;8BAaN,MAAM,EAAE;;;;;;;2BASX,MAAM;;;;wBA2CT,GAAG;;;;;;CAQxB,CAAC;AAEF;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAK5C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare let storage: LocalForage | null;
|
|
2
|
+
/**
|
|
3
|
+
* Initialize storage for persistence
|
|
4
|
+
*/
|
|
5
|
+
export declare function initializeStorage(): void;
|
|
6
|
+
/**
|
|
7
|
+
* Get the current storage instance
|
|
8
|
+
*/
|
|
9
|
+
export declare function getStorage(): LocalForage | null;
|
|
10
|
+
/**
|
|
11
|
+
* Set a custom storage instance
|
|
12
|
+
*/
|
|
13
|
+
export declare function setStorage(customStorage: LocalForage): void;
|
|
14
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/persistence/storage.ts"],"names":[],"mappings":"AAGA,eAAO,IAAI,OAAO,EAAE,WAAW,GAAG,IAAW,CAAC;AAE9C;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAuBxC;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,WAAW,GAAG,IAAI,CAE/C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,aAAa,EAAE,WAAW,GAAG,IAAI,CAE3D"}
|