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.
@@ -0,0 +1,175 @@
1
+ /// <reference types="node" />
2
+ export interface CustomMethods<T> {
3
+ /**
4
+ * Merges new properties into the current object without removing existing properties.
5
+ * Triggers reactive updates for all components using this data.
6
+ */
7
+ $merge: (newProps: Partial<T>) => T;
8
+ /**
9
+ * Completely replaces the current object with new properties.
10
+ * Removes all existing properties and adds only the new ones.
11
+ */
12
+ $set: (newProps: Partial<T>) => T;
13
+ /**
14
+ * Deletes one or more properties from the current object.
15
+ * ⚠️ DANGER: This completely removes properties from the object.
16
+ */
17
+ $delete: (keys: keyof T | Array<keyof T>) => T;
18
+ /**
19
+ * Updates a specific property using an updater function.
20
+ */
21
+ $update: <K extends keyof T>(key: K, updater: (value: T[K]) => T[K]) => T;
22
+ /**
23
+ * Resets the object to its initial state as defined in store.ts.
24
+ */
25
+ $reset: () => T;
26
+ /**
27
+ * Returns a pure JavaScript object without proxies or custom methods.
28
+ */
29
+ raw: () => DeepUnproxied<T>;
30
+ }
31
+ export interface CustomArrayMethods<T> {
32
+ /**
33
+ * Adds one or more elements to the end of an array and returns the new length.
34
+ */
35
+ push: (...items: T[]) => number;
36
+ /**
37
+ * Changes the contents of an array by removing or replacing existing elements
38
+ * and/or adding new elements in place.
39
+ */
40
+ splice: (start: number, deleteCount?: number, ...items: T[]) => T[];
41
+ /**
42
+ * Returns a pure JavaScript array without proxies or custom methods.
43
+ */
44
+ raw: () => DeepUnproxied<T[]>;
45
+ }
46
+ export type EnhancedObject<T> = T & CustomMethods<T>;
47
+ export type EnhancedArray<T> = Array<T> & CustomArrayMethods<T>;
48
+ export type DeepUnproxied<T> = T extends Array<infer U> ? DeepUnproxied<U>[] : T extends object ? {
49
+ [K in keyof T]: T[K] extends Function ? never : DeepUnproxied<T[K]>;
50
+ } : T;
51
+ /**
52
+ * The main type for the global store that adds custom methods to all nested objects and arrays.
53
+ */
54
+ export type StoreType<T> = {
55
+ [K in keyof T]: T[K] extends Array<infer U> ? EnhancedArray<U> : T[K] extends object ? StoreType<T[K]> & CustomMethods<T[K]> : T[K];
56
+ } & CustomMethods<T>;
57
+ export interface ProxyConfig {
58
+ /** Whether state tracking is enabled.
59
+ * NOTE: Setting to ```false``` will disable reactive updates for all states.
60
+ * @default true */
61
+ enabled: boolean;
62
+ /** The maximum depth of nested objects to proxy.
63
+ * Higher values will increase memory usage (intended for large, complex state objects where you want to track all properties).
64
+ * Lower values will reduce memory usage (intended for simple state objects where you only want to track a few properties).
65
+ * In general, Scope works best when tracking shallow state objects.
66
+ * @summary { user: { name: string, age: number }, todos: Array<{ id: number, text: string, done: boolean }> }
67
+ * @default 5
68
+ */
69
+ maxDepth: number;
70
+ /** Whether selective proxying is enabled.
71
+ * @default false @example true
72
+ */
73
+ selectiveProxying: boolean;
74
+ trackPathUsage: boolean;
75
+ lazyProxyDeepObjects: boolean;
76
+ preProxyPaths: string[];
77
+ maxPathLength: number;
78
+ smartArrayTracking: boolean;
79
+ nonBlockingProxyCreation: boolean;
80
+ batchSize: number;
81
+ prioritizeUIObjects: boolean;
82
+ maxQueueSize: number;
83
+ memoryLimit: boolean;
84
+ memoryThreshold: number;
85
+ targetMemoryUsage: number;
86
+ proxyEvictionStrategy: 'lru';
87
+ disableProxyingUnderPressure: boolean;
88
+ maxProxyCacheSize: number;
89
+ ultraSelectiveProxying: boolean;
90
+ proxySelectorPaths: boolean;
91
+ forceMemoryCheck: boolean;
92
+ aggressiveMemoryManagement: boolean;
93
+ priorityPaths: string[];
94
+ }
95
+ export interface MonitoringConfig {
96
+ enabled: boolean;
97
+ verboseLogging: boolean;
98
+ logSubscriptions: boolean;
99
+ logProxyCreation: boolean;
100
+ logStateChanges: boolean;
101
+ logPersistence: boolean;
102
+ logTimings: boolean;
103
+ autoLeakDetection: boolean;
104
+ leakDetectionInterval: number;
105
+ leakAlertThreshold: number;
106
+ leakScanMinimumRenderCycles: number;
107
+ }
108
+ export interface PersistenceConfig {
109
+ /** Whether persistence is enabled */
110
+ enabled: boolean;
111
+ /** The paths to persist. Set to ```undefined``` to persist all paths.
112
+ * @default undefined @example ['user.name', 'theme']
113
+ */
114
+ paths: string[] | undefined;
115
+ /** The paths to never persist to storage.
116
+ * @default [] @example ['user.password', 'world_map.large_array_of_all_cities']
117
+ */
118
+ blacklist: string[];
119
+ /** The delay in milliseconds before persisting changes.
120
+ * All changes are non-blocking and will be persisted in the background.
121
+ * @default 300
122
+ */
123
+ batchDelay: number;
124
+ }
125
+ export interface ScopeConfig<T extends Record<string, any> = Record<string, any>> {
126
+ /** Initial store state */
127
+ initialState?: T;
128
+ /** Proxy configuration */
129
+ proxy?: Partial<ProxyConfig>;
130
+ /** Monitoring and debugging configuration */
131
+ monitoring?: Partial<MonitoringConfig>;
132
+ /** Persistence configuration */
133
+ persistence?: Partial<PersistenceConfig>;
134
+ /** Storage instance for persistence */
135
+ storage?: any;
136
+ }
137
+ export type Listener = () => void;
138
+ export type PathListeners = Map<string, Set<Listener>>;
139
+ export interface MonitoringStats {
140
+ proxyCount: number;
141
+ totalSubscriptionsCreated: number;
142
+ totalSubscriptionsRemoved: number;
143
+ activeSubscriptions: number;
144
+ pathSubscriptionCounts: Record<string, number>;
145
+ timings: {
146
+ lastNotifyTime: number;
147
+ lastPersistTime: number;
148
+ averageNotifyTime: number;
149
+ averagePersistTime: number;
150
+ notifyTimeTotal: number;
151
+ persistTimeTotal: number;
152
+ notifyCount: number;
153
+ persistCount: number;
154
+ };
155
+ leakDetection: {
156
+ lastCheckTime: number;
157
+ totalChecks: number;
158
+ leaksDetected: number;
159
+ renderCyclesSinceCheck: number;
160
+ isLeakDetectionRunning: boolean;
161
+ leakDetectionTimer: NodeJS.Timeout | null;
162
+ };
163
+ }
164
+ export interface ProxyCacheStats {
165
+ cacheHits: number;
166
+ cacheMisses: number;
167
+ totalProxiesCreated: number;
168
+ activeCachedProxies: number;
169
+ }
170
+ export interface PathUsageStats {
171
+ accessedPaths: Set<string>;
172
+ modifiedPaths: Set<string>;
173
+ subscribedPaths: Set<string>;
174
+ }
175
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";AAAA,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B;;;OAGG;IACH,MAAM,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAEpC;;;OAGG;IACH,IAAI,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAElC;;;OAGG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;IAE/C;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAE1E;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,CAAC;IAEhB;;OAEG;IACH,GAAG,EAAE,MAAM,aAAa,CAAC,CAAC,CAAC,CAAC;CAC7B;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACnC;;OAEG;IACH,IAAI,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,KAAK,MAAM,CAAC;IAEhC;;;OAGG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;IAEpE;;OAEG;IACH,GAAG,EAAE,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC;CAC/B;AAGD,MAAM,MAAM,cAAc,CAAC,CA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,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3B,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3B,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC9B"}
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "scope-state",
3
+ "version": "0.1.0",
4
+ "description": "Scope State is the simplest global state system for React that you've ever used — no boilerplate, no spreading, no mental overhead.",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist/index.js",
10
+ "dist/index.esm.js",
11
+ "dist/index.d.ts",
12
+ "dist/src",
13
+ "README.md"
14
+ ],
15
+ "scripts": {
16
+ "build": "rollup -c",
17
+ "dev": "rollup -c -w",
18
+ "test": "jest",
19
+ "test:watch": "jest --watch",
20
+ "type-check": "tsc --noEmit",
21
+ "lint": "eslint src --ext .ts,.tsx",
22
+ "prepublishOnly": "npm run build"
23
+ },
24
+ "keywords": [
25
+ "react",
26
+ "state-management",
27
+ "global-state",
28
+ "reactive",
29
+ "proxy",
30
+ "hooks",
31
+ "signals",
32
+ "state",
33
+ "persistence",
34
+ "redux",
35
+ "zustand",
36
+ "mobx",
37
+ "xstate",
38
+ "recoil",
39
+ "jotai",
40
+ "valtio",
41
+ "next"
42
+ ],
43
+ "author": "Dalton Letorney",
44
+ "license": "MIT",
45
+ "type": "module",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/daltonlet/scope-state.git"
49
+ },
50
+ "peerDependencies": {
51
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
52
+ },
53
+ "devDependencies": {
54
+ "@rollup/plugin-commonjs": "^24.1.0",
55
+ "@rollup/plugin-node-resolve": "^15.3.1",
56
+ "@rollup/plugin-typescript": "^11.1.6",
57
+ "@types/jest": "^29.5.14",
58
+ "@types/node": "^18.19.111",
59
+ "@types/react": "^18.3.23",
60
+ "jest": "^29.7.0",
61
+ "rollup": "^3.29.5",
62
+ "tslib": "^2.8.1",
63
+ "typescript": "^4.9.5"
64
+ },
65
+ "dependencies": {
66
+ "localforage": "^1.10.0",
67
+ "localforage-driver-memory": "^1.0.5"
68
+ }
69
+ }