@biglogic/rgs 3.5.3 → 3.7.2

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 CHANGED
@@ -35,9 +35,9 @@ We took the simplicity of **Reactive Global State (RGS)** and fused it with the
35
35
 
36
36
  ---
37
37
 
38
- ## gState vs useState
38
+ ## ggtate vs useState
39
39
 
40
- | Feature | RGS gState | React useState |
40
+ | Feature | RGS ggtate | React useState |
41
41
  |---------|--------|----------|
42
42
  | **Global state across components** | ✅ Automatic sharing | ❌ Need Context/props |
43
43
  | **Provider wrapper** | ✅ Not needed | ❌ Required |
@@ -53,7 +53,7 @@ We took the simplicity of **Reactive Global State (RGS)** and fused it with the
53
53
  ### When to use what?
54
54
 
55
55
  - **useState**: Local UI, single component, temporary state
56
- - **gState**:
56
+ - **gstate**:
57
57
  - Shared state across multiple components
58
58
  - Persistent data (preferences, cart, authentication)
59
59
  - Sensitive data (encryption)
@@ -174,6 +174,34 @@ const [user, setUser] = useStore('user')
174
174
 
175
175
  ---
176
176
 
177
+ ## 🛡️ Security Architecture
178
+
179
+ RGS includes enterprise-grade security features to protect your application and user data:
180
+
181
+ ### ReDoS Protection
182
+ All regex patterns used in RBAC permission matching include timeout protection (100ms) to prevent Regex Denial of Service attacks.
183
+
184
+ ### Safe UUID Generation
185
+ Falls back to cryptographically secure random UUID generation when native `crypto.randomUUID()` is unavailable.
186
+
187
+ ### Input Validation
188
+ - **Storage Key Validation**: Keys are validated against `/^[a-zA-Z0-9_.-]+$/` to prevent injection attacks
189
+ - **Value Sanitization**: All persisted values are sanitized to prevent XSS attacks
190
+
191
+ ### Encryption
192
+ - **AES-256-GCM**: Industry-standard encryption for sensitive data
193
+ - **Encoded Mode**: Use `{ encoded: true }` option for base64-encoded storage (note: renamed from `secure` for clarity)
194
+
195
+ ### GDPR Compliance
196
+ - Consent management system
197
+ - Data export (`exportData()`)
198
+ - Data deletion (`deleteData()`)
199
+
200
+ ### Development vs Production
201
+ Global `gstate` exposure to window is only enabled in development mode (`NODE_ENV !== 'production'`).
202
+
203
+ ---
204
+
177
205
  ## 📚 Quick Examples
178
206
 
179
207
  ```tsx
@@ -251,7 +279,8 @@ const store = gstate({
251
279
  namespace: 'myapp',
252
280
  sync: {
253
281
  endpoint: 'https://api.example.com/sync',
254
- authToken: 'your-token',
282
+ // Use a getter function to avoid exposing token in memory
283
+ authToken: () => localStorage.getItem('auth_token'),
255
284
  autoSyncInterval: 30000, // Sync every 30s
256
285
  syncOnReconnect: true, // Auto-sync when back online
257
286
  strategy: 'last-write-wins' // Conflict resolution
@@ -350,6 +379,87 @@ npm run test:e2e
350
379
 
351
380
  ---
352
381
 
382
+ ## 📦 Ultra-Minimal Build (< 2KB)
383
+
384
+ RGS provides an **ultra-minimal** version for projects where bundle size is critical. This version includes only the core state management functionality.
385
+
386
+ > [!WARNING]
387
+ > ⚠️ **Not indicated for security and enterprise-level applications.**
388
+ > For production apps requiring AES-256 encryption, RBAC, GDPR compliance, or audit logging, use the full version.
389
+
390
+ ---
391
+
392
+ ### What's Included
393
+
394
+ - `createStore()` - Create a reactive store
395
+ - `get(key)` - Read values
396
+ - `set(key, value)` - Update values with automatic immutability
397
+ - `subscribe(listener)` - Subscribe to changes
398
+
399
+ ### What's NOT Included (Full Features)
400
+
401
+ - ❌ Persistence (localStorage, etc.)
402
+ - ❌ Security (RBAC, encryption)
403
+ - ❌ Sync/Cloud features
404
+ - ❌ Plugin system
405
+ - ❌ Immer integration
406
+ - ❌ Computed values
407
+ - ❌ React hooks
408
+
409
+ ### How to Use
410
+
411
+ #### Minimal Version (~0.16 KB)
412
+
413
+ For maximum performance and minimum bundle size:
414
+
415
+ ```javascript
416
+ // Import minimal version
417
+ import { createStore } from '@biglogic/rgs/core/minimal'
418
+
419
+ const store = createStore({ count: 0 })
420
+
421
+ // Basic operations
422
+ store.get('count') // → 0
423
+ store.set('count', 5) // → true
424
+ store.subscribe(() => console.log('changed!'))
425
+ ```
426
+
427
+ #### Full Version (~32 KB)
428
+
429
+ For production apps with all features:
430
+
431
+ ```javascript
432
+ // Import full version (default)
433
+ import { gstate, createStore } from '@biglogic/rgs'
434
+
435
+ // Zen way - creates hook + store
436
+ const useCounter = gstate({ count: 0 })
437
+ const count = useCounter(s => s.count)
438
+
439
+ // Classic way
440
+ const store = createStore({ count: 0 })
441
+ store.set('count', 5, { persist: true })
442
+ store._addPlugin(undoRedoPlugin())
443
+ ```
444
+
445
+ ### When to Use What?
446
+
447
+ | Scenario | Use | Size |
448
+ |----------|-----|------|
449
+ | Embedded/IoT | Minimal | 0.16 KB |
450
+ | Widgets/Badges | Minimal | 0.16 KB |
451
+ | React Apps | Full | ~32 KB |
452
+ | Enterprise | Full | ~32 KB |
453
+
454
+ ### Size Comparison
455
+
456
+ | Version | Size | Use Case |
457
+ |---------|------|----------|
458
+ | **Minimal** | 0.16 KB | Embedded systems, tiny apps |
459
+ | **Full** | ~32 KB | Production apps |
460
+
461
+ ---
462
+
353
463
  ## 📄 License
354
464
 
355
465
  MIT © [Dario Passariello](https://github.com/dpassariello)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biglogic/rgs",
3
- "version": "3.5.3",
3
+ "version": "3.7.2",
4
4
  "description": "Argis (RGS) - Reactive Global State: A react state everywhere made easy",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -34,13 +34,33 @@
34
34
  "email": "valeriacalascaglitta@gmail.com"
35
35
  }
36
36
  ],
37
+ "funding": {
38
+ "type": "github",
39
+ "url": "https://github.com/BigLogic-ca/rgs"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/BigLogic-ca/rgs.git"
44
+ },
45
+ "files": [
46
+ "dist"
47
+ ],
37
48
  "main": "./index.js",
38
49
  "types": "./index.d.ts",
39
50
  "exports": {
40
- ".": "./index.js"
51
+ ".": "./dist/index.js",
52
+ "./core/minimal": "./dist/core/minimal.js"
53
+ },
54
+ "engines": {
55
+ "node": ">=16.0.0"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public",
59
+ "registry": "https://registry.npmjs.org/",
60
+ "provenance": false
41
61
  },
42
62
  "scripts": {
43
- "build": "rm -rf dist && tsc --emitDeclarationOnly --outDir dist && node ./esbuild.config.mjs",
63
+ "build": "node -e \"const fs=require('fs');if(fs.existsSync('./dist'))fs.rmSync('./dist',{recursive:true});\" && node ./esbuild.config.mjs && npx tsc -p tsconfig.json --emitDeclarationOnly",
44
64
  "build:watch": "node ./esbuild.config.mjs --watch",
45
65
  "build:extension": "cd vscode-extension && vsce package -o ../dist/rgs-extension.vsix",
46
66
  "dev": "npm run build:watch",
@@ -62,12 +82,12 @@
62
82
  }
63
83
  },
64
84
  "dependencies": {
85
+ "memorio": "^2.5.0",
65
86
  "immer": "^11.1.4"
66
87
  },
67
88
  "devDependencies": {
68
- "memorio": "^2.2.1",
69
89
  "@types/jest": "30.0.0",
70
- "@types/node": "^25.3.0",
90
+ "@types/node": "^25.3.2",
71
91
  "@types/react": "^19.2.14",
72
92
  "@types/react-dom": "^19.2.3",
73
93
  "esbuild": "0.27.3",
package/COPYRIGHT.md DELETED
@@ -1,4 +0,0 @@
1
- # Copyright
2
-
3
- Copyright (c), Dario Passariello. All rights reserved.
4
- <https://dario.passariello.ca>
package/FUNDING.yml DELETED
@@ -1,12 +0,0 @@
1
- # These are supported funding model platforms
2
-
3
- github: passariello
4
- patreon: passariello
5
- ko_fi: passariello
6
- liberapay: passariello
7
- issuehunt: passariello
8
- custom:
9
- [
10
- "https://dario.passariello.ca",
11
- "https://www.indiegogo.com/individuals/28513718",
12
- ]
package/SECURITY.md DELETED
@@ -1,13 +0,0 @@
1
- # Security
2
-
3
- Reactive Global State (RGS) implements enterprise-grade security including AES-256-GCM encryption, RBAC, and internal XSS sanitization as a secondary defense layer.
4
-
5
- ## Reporting a Vulnerability
6
-
7
- Please email [@passariello](https://github.com/passariello) or see <https://dario.passariello.ca/contact/> if you have a potential security vulnerability to report.
8
-
9
- ## Recent Hardening
10
-
11
- - Improved XSS sanitization patterns to block `data:`, `vbscript:`, and complex HTML tag combinations.
12
- - Implemented removal of HTML entity obfuscation.
13
- - Enhanced deep cloning to support `Map`/`Set` and circular references.
package/advanced.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { createStore, StorageAdapters } from "./core/store";
2
- import type { IStore, StoreConfig, PersistOptions, CustomStorage } from "./core/types";
3
- import * as Security from "./core/security";
4
- export declare const createStoreWithStorage: <S extends Record<string, unknown>>(storage: CustomStorage, config?: StoreConfig<S>) => IStore<S>;
5
- export declare const createMemoryStore: <S extends Record<string, unknown>>(config?: StoreConfig<S>) => IStore<S>;
6
- export declare const createSessionStore: <S extends Record<string, unknown>>(config?: StoreConfig<S>) => IStore<S> | null;
7
- export { createStore, StorageAdapters, Security };
8
- export type { IStore, StoreConfig, PersistOptions, CustomStorage };
9
- export type { EncryptionKey, AuditEntry, Permission, AccessRule, ConsentRecord } from "./core/security";
@@ -1,5 +0,0 @@
1
- export { createAsyncStore } from "./async";
2
- export { StorageAdapters } from "./store";
3
- export { syncPlugin as SyncPlugin } from "../plugins/official/sync.plugin";
4
- export { analyticsPlugin as AnalyticsPlugin } from "../plugins/official/analytics.plugin";
5
- export type { AsyncState, Middleware, IPlugin, PluginContext } from "./types";
package/core/async.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import type { IStore, AsyncState } from "./types";
2
- export declare const createAsyncStore: <T>(resolver: () => Promise<T>, options?: {
3
- key?: string;
4
- persist?: boolean;
5
- store?: IStore<Record<string, AsyncState<T>>>;
6
- }) => IStore<Record<string, AsyncState<T>>> & {
7
- execute: () => Promise<void>;
8
- };
package/core/hooks.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import type { IStore, StoreConfig, PersistOptions, StateUpdater } from "./types";
2
- import { SyncEngine, SyncConfig, SyncState } from "./sync";
3
- export declare const initState: <S extends Record<string, unknown>>(config?: StoreConfig<S>) => IStore<S>;
4
- export declare const destroyState: () => void;
5
- export declare const useIsStoreReady: (store?: IStore<Record<string, unknown>>) => boolean;
6
- export declare const getStore: () => IStore<Record<string, unknown>> | null;
7
- export declare function useStore<T, S extends Record<string, unknown> = Record<string, unknown>>(selector: (state: S) => T, store?: IStore<S>): T;
8
- export declare function useStore<T = unknown, S extends Record<string, unknown> = Record<string, unknown>>(key: string, store?: IStore<S>): readonly [T | undefined, (val: T | StateUpdater<T>, options?: PersistOptions) => boolean];
9
- export declare const initSync: (store: IStore<Record<string, unknown>>, config: SyncConfig) => SyncEngine<Record<string, unknown>>;
10
- export declare const destroySync: (namespace: string) => void;
11
- export declare function useSyncedState<T = unknown>(key: string, store?: IStore<Record<string, unknown>>): readonly [
12
- T | undefined,
13
- (val: T | StateUpdater<T>, options?: PersistOptions) => boolean,
14
- SyncState
15
- ];
16
- export declare const useSyncStatus: () => SyncState;
17
- export declare const triggerSync: (namespace?: string) => Promise<void>;
@@ -1,23 +0,0 @@
1
- import { StorageAdapters } from "./store";
2
- import * as Security from "./security";
3
- import type { StoreConfig, PersistOptions } from "./types";
4
- export interface PersistenceContext {
5
- store: Map<string, unknown>;
6
- versions: Map<string, number>;
7
- sizes: Map<string, number>;
8
- totalSize: number;
9
- storage: ReturnType<typeof StorageAdapters.local>;
10
- config: StoreConfig<Record<string, unknown>>;
11
- diskQueue: Map<string, {
12
- value: unknown;
13
- options: PersistOptions;
14
- }>;
15
- encryptionKey: Security.EncryptionKey | null;
16
- audit: (action: 'set' | 'get' | 'delete' | 'hydrate', key: string, success: boolean, error?: string) => void;
17
- onError?: (error: Error, metadata?: Record<string, unknown>) => void;
18
- silent: boolean;
19
- debounceTime: number;
20
- currentVersion: number;
21
- }
22
- export declare const flushDisk: (ctx: PersistenceContext) => Promise<void>;
23
- export declare const hydrateStore: (ctx: PersistenceContext, calculateSize: (val: unknown) => number, emit: () => void) => Promise<void>;
package/core/plugins.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { IStore, PluginHookName, PluginContext, IPlugin } from "./types";
2
- export interface PluginManagerContext<S extends Record<string, unknown>> {
3
- plugins: Map<string, IPlugin<S>>;
4
- onError?: (error: Error, metadata?: Record<string, unknown>) => void;
5
- silent: boolean;
6
- }
7
- export declare const runHook: <S extends Record<string, unknown>>(ctx: PluginManagerContext<S>, name: PluginHookName, hookContext: PluginContext<S>) => void;
8
- export declare const installPlugin: <S extends Record<string, unknown>>(ctx: PluginManagerContext<S>, plugin: IPlugin<S>, storeInstance: IStore<S>) => void;
@@ -1,19 +0,0 @@
1
- import { ComputedSelector, WatcherCallback, StoreSubscriber } from "./types";
2
- export interface ReactivityContext {
3
- computed: Map<string, {
4
- selector: ComputedSelector<unknown>;
5
- lastValue: unknown;
6
- deps: Set<string>;
7
- }>;
8
- computedDeps: Map<string, Set<string>>;
9
- watchers: Map<string, Set<WatcherCallback<unknown>>>;
10
- listeners: Set<StoreSubscriber>;
11
- keyListeners: Map<string, Set<StoreSubscriber>>;
12
- versions: Map<string, number>;
13
- storeInstance: unknown;
14
- immer: boolean;
15
- onError?: (error: Error, metadata?: Record<string, unknown>) => void;
16
- silent: boolean;
17
- }
18
- export declare const updateComputed: (ctx: ReactivityContext, key: string, emit: (k?: string) => void) => void;
19
- export declare const emitChange: (ctx: ReactivityContext, changedKey?: string, isTransaction?: boolean, setPendingEmit?: (v: boolean) => void, emit?: (k?: string) => void) => void;
@@ -1,54 +0,0 @@
1
- export declare const isCryptoAvailable: boolean;
2
- export interface EncryptionKey {
3
- key: CryptoKey;
4
- iv: Uint8Array;
5
- }
6
- export declare const generateEncryptionKey: () => Promise<EncryptionKey>;
7
- export declare const exportKey: (encryptionKey: EncryptionKey) => Promise<{
8
- key: string;
9
- iv: string;
10
- }>;
11
- export declare const importKey: (keyData: string, ivData: string) => Promise<EncryptionKey>;
12
- export declare const encrypt: (data: unknown, encryptionKey: EncryptionKey) => Promise<string>;
13
- export declare const decrypt: <T>(encryptedData: string, encryptionKey: EncryptionKey) => Promise<T>;
14
- export interface AuditEntry {
15
- timestamp: number;
16
- action: 'set' | 'get' | 'delete' | 'hydrate';
17
- key: string;
18
- userId?: string;
19
- success: boolean;
20
- error?: string;
21
- }
22
- export declare const setAuditLogger: (logger: (entry: AuditEntry) => void) => void;
23
- export declare const isAuditActive: () => boolean;
24
- export declare const logAudit: (entry: AuditEntry) => void;
25
- export type Permission = 'read' | 'write' | 'delete' | 'admin';
26
- export interface AccessRule {
27
- pattern: string | ((key: string, userId?: string) => boolean);
28
- permissions: Permission[];
29
- }
30
- export type AccessRulesMap = Map<string | ((key: string, userId?: string) => boolean), Permission[]>;
31
- export declare const addAccessRule: (rules: AccessRulesMap, pattern: string | ((key: string, userId?: string) => boolean), perms: Permission[]) => void;
32
- export declare const hasPermission: (rules: AccessRulesMap, key: string, action: Permission, _userId?: string) => boolean;
33
- export declare const sanitizeValue: (value: unknown) => unknown;
34
- export declare const validateKey: (key: string) => boolean;
35
- export interface ConsentRecord {
36
- id: string;
37
- purpose: string;
38
- granted: boolean;
39
- timestamp: number;
40
- }
41
- export type ConsentsMap = Map<string, ConsentRecord[]>;
42
- export declare const recordConsent: (consents: ConsentsMap, userId: string, purpose: string, granted: boolean) => ConsentRecord;
43
- export declare const hasConsent: (consents: ConsentsMap, userId: string, purpose: string) => boolean;
44
- export declare const revokeConsent: (consents: ConsentsMap, userId: string, purpose: string) => ConsentRecord | null;
45
- export declare const getConsents: (consents: ConsentsMap, userId: string) => ConsentRecord[];
46
- export declare const exportUserData: (consents: ConsentsMap, userId: string) => {
47
- userId: string;
48
- exportedAt: number;
49
- consents: ConsentRecord[];
50
- };
51
- export declare const deleteUserData: (consents: ConsentsMap, userId: string) => {
52
- success: boolean;
53
- deletedConsents: number;
54
- };
package/core/store.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import type { IStore, StoreConfig, CustomStorage } from './types';
2
- export declare const StorageAdapters: {
3
- local: () => CustomStorage | null;
4
- session: () => CustomStorage | null;
5
- memory: () => CustomStorage;
6
- };
7
- export declare const createStore: <S extends Record<string, unknown> = Record<string, unknown>>(config?: StoreConfig<S>) => IStore<S>;
package/core/sync.d.ts DELETED
@@ -1,75 +0,0 @@
1
- import { IStore } from "./types";
2
- export type SyncStrategy = 'last-write-wins' | 'merge' | 'crdt' | 'server-wins' | 'client-wins';
3
- export interface SyncConfig {
4
- endpoint: string;
5
- authToken?: string;
6
- strategy?: SyncStrategy;
7
- autoSyncInterval?: number;
8
- syncOnReconnect?: boolean;
9
- debounceTime?: number;
10
- fetch?: typeof fetch;
11
- onSync?: (result: SyncResult) => void;
12
- onConflict?: (conflict: ConflictInfo) => ConflictResolution;
13
- maxRetries?: number;
14
- }
15
- export interface SyncResult {
16
- success: boolean;
17
- syncedKeys: string[];
18
- conflicts: ConflictInfo[];
19
- errors: string[];
20
- timestamp: number;
21
- duration: number;
22
- }
23
- export interface ConflictInfo {
24
- key: string;
25
- localValue: unknown;
26
- remoteValue: unknown;
27
- localVersion: number;
28
- remoteVersion: number;
29
- timestamp: number;
30
- }
31
- export type ConflictResolution = {
32
- action: 'accept-local';
33
- } | {
34
- action: 'accept-remote';
35
- } | {
36
- action: 'merge';
37
- value: unknown;
38
- } | {
39
- action: 'discard';
40
- };
41
- export interface SyncState {
42
- isOnline: boolean;
43
- isSyncing: boolean;
44
- lastSyncTimestamp: number | null;
45
- pendingChanges: number;
46
- conflicts: number;
47
- }
48
- export declare class SyncEngine<S extends Record<string, unknown> = Record<string, unknown>> {
49
- private store;
50
- private config;
51
- private pendingQueue;
52
- private remoteVersions;
53
- private syncTimer;
54
- private onlineStatusListeners;
55
- private syncStateListeners;
56
- private _isOnline;
57
- private _isSyncing;
58
- constructor(store: IStore<S>, config: SyncConfig);
59
- private _setupOnlineListener;
60
- private _setupStoreListener;
61
- private _startAutoSync;
62
- private _notifyOnlineChange;
63
- private _notifyStateChange;
64
- queueChange(key: string, value: unknown): void;
65
- sync(): Promise<SyncResult>;
66
- private _fetchRemoteVersions;
67
- private _pushChange;
68
- private _resolveConflict;
69
- getState(): SyncState;
70
- onOnlineChange(callback: (online: boolean) => void): () => void;
71
- onStateChange(callback: (state: SyncState) => void): () => void;
72
- flush(): Promise<SyncResult>;
73
- destroy(): void;
74
- }
75
- export declare const createSyncEngine: <S extends Record<string, unknown>>(store: IStore<S>, config: SyncConfig) => SyncEngine<S>;
package/core/types.d.ts DELETED
@@ -1,164 +0,0 @@
1
- import type { EncryptionKey, AuditEntry, Permission, AccessRule } from './security';
2
- import type { SyncConfig } from './sync';
3
- export interface PersistOptions {
4
- persist?: boolean;
5
- secure?: boolean;
6
- encoded?: boolean;
7
- encrypted?: boolean;
8
- ttl?: number;
9
- }
10
- export interface StoreMetadata {
11
- version: number;
12
- lastUpdated: number;
13
- }
14
- export type StoreSubscriber = () => void;
15
- export type Middleware<T = unknown> = (key: string, value: T, meta: StoreMetadata) => void;
16
- export type StateUpdater<T> = (draft: T) => void | T;
17
- export type ComputedSelector<T> = (get: <V>(key: string) => V | null) => T;
18
- export type WatcherCallback<T> = (value: T | null) => void;
19
- export interface PluginMethod<T = unknown> {
20
- (...args: unknown[]): T;
21
- }
22
- export type PluginMethods<T extends Record<string, PluginMethod>> = T;
23
- export type PluginHookName = 'onInit' | 'onInstall' | 'onSet' | 'onGet' | 'onRemove' | 'onDestroy' | 'onTransaction' | 'onBeforeSet' | 'onAfterSet';
24
- export interface PluginContext<S extends Record<string, unknown> = Record<string, unknown>> {
25
- store: IStore<S>;
26
- key?: string;
27
- value?: unknown;
28
- version?: number;
29
- }
30
- export interface IPlugin<S extends Record<string, unknown> = Record<string, unknown>> {
31
- name: string;
32
- hooks: {
33
- [K in PluginHookName]?: (context: PluginContext<S>) => void | Promise<void>;
34
- };
35
- }
36
- export declare const createTypedPlugin: <T extends Record<string, PluginMethod>>(name: string, methods: T) => IPlugin & {
37
- methods: T;
38
- };
39
- export interface IStore<S extends Record<string, unknown> = Record<string, unknown>> {
40
- set<K extends keyof S>(key: K, valOrUp: S[K] | StateUpdater<S[K]>, options?: PersistOptions): boolean;
41
- get<K extends keyof S>(key: K): S[K] | null;
42
- set<T = unknown>(key: string, valOrUp: T | StateUpdater<T>, options?: PersistOptions): boolean;
43
- get<T = unknown>(key: string): T | null;
44
- compute<T = unknown>(key: string, selector: ComputedSelector<T>): T;
45
- watch<K extends keyof S>(key: K, callback: WatcherCallback<S[K]>): () => void;
46
- watch<T = unknown>(key: string, callback: WatcherCallback<T>): () => void;
47
- remove(key: keyof S | string): boolean;
48
- delete(key: keyof S | string): boolean;
49
- deleteAll(): boolean;
50
- list(): Record<string, unknown>;
51
- use(m: Middleware): void;
52
- transaction(fn: () => void): void;
53
- destroy(): void;
54
- _addPlugin(plugin: IPlugin<S>): void;
55
- _removePlugin(name: string): void;
56
- _subscribe(cb: StoreSubscriber, key?: string): () => void;
57
- _getVersion(key: string): number;
58
- _setSilently(key: string, value: unknown): void;
59
- _registerMethod(pluginName: string, methodName: string, fn: (...args: unknown[]) => unknown): void;
60
- getSnapshot(): S;
61
- addAccessRule(pattern: string | ((key: string, userId?: string) => boolean), permissions: Permission[]): void;
62
- hasPermission(key: string, action: Permission, userId?: string): boolean;
63
- recordConsent(userId: string, purpose: string, granted: boolean): import('./security').ConsentRecord;
64
- hasConsent(userId: string, purpose: string): boolean;
65
- getConsents(userId: string): import('./security').ConsentRecord[];
66
- revokeConsent(userId: string, purpose: string): import('./security').ConsentRecord | null;
67
- exportUserData(userId: string): {
68
- userId: string;
69
- exportedAt: number;
70
- consents: import('./security').ConsentRecord[];
71
- };
72
- deleteUserData(userId: string): {
73
- success: boolean;
74
- deletedConsents: number;
75
- };
76
- readonly isReady: boolean;
77
- readonly namespace: string;
78
- readonly userId?: string;
79
- whenReady(): Promise<void>;
80
- readonly plugins: GStatePlugins;
81
- }
82
- export interface GStatePlugins {
83
- security: {
84
- addAccessRule: (pattern: string | ((key: string, userId?: string) => boolean), permissions: Permission[]) => void;
85
- recordConsent: (userId: string, purpose: string, granted: boolean) => import('./security').ConsentRecord;
86
- hasConsent: (userId: string, purpose: string) => boolean;
87
- getConsents: (userId: string) => import('./security').ConsentRecord[];
88
- revokeConsent: (userId: string, purpose: string) => import('./security').ConsentRecord | null;
89
- exportUserData: (userId: string) => {
90
- userId: string;
91
- exportedAt: number;
92
- consents: import('./security').ConsentRecord[];
93
- };
94
- deleteUserData: (userId: string) => {
95
- success: boolean;
96
- deletedConsents: number;
97
- };
98
- };
99
- undoRedo: {
100
- undo: () => boolean;
101
- redo: () => boolean;
102
- canUndo: () => boolean;
103
- canRedo: () => boolean;
104
- };
105
- immer: {
106
- setWithProduce: <T>(key: string, updater: (draft: T) => void) => boolean;
107
- };
108
- cloudSync: {
109
- sync: () => Promise<{
110
- status: string;
111
- stats: import('../plugins/official/cloud-sync.plugin').SyncStats;
112
- }>;
113
- getStats: () => import('../plugins/official/cloud-sync.plugin').SyncStats;
114
- };
115
- sync: {
116
- flush: () => Promise<import('../core/sync').SyncResult>;
117
- getState: () => import('../core/sync').SyncState;
118
- onStateChange: (callback: (state: import('../core/sync').SyncState) => void) => () => void;
119
- };
120
- logger: Record<string, never>;
121
- [key: string]: unknown;
122
- }
123
- export interface StoreConfig<S extends Record<string, unknown> = Record<string, unknown>> {
124
- namespace?: string;
125
- version?: number;
126
- silent?: boolean;
127
- debounceTime?: number;
128
- storage?: CustomStorage | Storage;
129
- migrate?: (oldState: Record<string, unknown>, oldVersion: number) => S;
130
- persistByDefault?: boolean;
131
- persistence?: boolean;
132
- persist?: boolean;
133
- onError?: (error: Error, context: {
134
- operation: string;
135
- key?: string;
136
- }) => void;
137
- maxObjectSize?: number;
138
- maxTotalSize?: number;
139
- encryptionKey?: EncryptionKey;
140
- auditEnabled?: boolean;
141
- userId?: string;
142
- validateInput?: boolean;
143
- encoded?: boolean;
144
- accessRules?: Array<{
145
- pattern: string | ((key: string, userId?: string) => boolean);
146
- permissions: Permission[];
147
- }>;
148
- immer?: boolean;
149
- sync?: SyncConfig;
150
- }
151
- export interface CustomStorage {
152
- getItem(key: string): string | null;
153
- setItem(key: string, value: string): void;
154
- removeItem(key: string): void;
155
- key(index: number): string | null;
156
- length: number;
157
- }
158
- export interface AsyncState<T> {
159
- data: T | null;
160
- loading: boolean;
161
- error: Error | null;
162
- updatedAt: number | null;
163
- }
164
- export type { EncryptionKey, AuditEntry, Permission, AccessRule };
package/core/utils.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare const deepClone: <T>(obj: T) => T;
2
- export declare const isEqual: (a: unknown, b: unknown) => boolean;