@biglogic/rgs 3.7.0 → 3.7.3

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 (49) hide show
  1. package/README.md +84 -3
  2. package/package.json +91 -85
  3. package/COPYRIGHT.md +0 -4
  4. package/FUNDING.yml +0 -12
  5. package/SECURITY.md +0 -13
  6. package/advanced.d.ts +0 -9
  7. package/core/advanced.d.ts +0 -5
  8. package/core/async.d.ts +0 -8
  9. package/core/hooks.d.ts +0 -17
  10. package/core/persistence.d.ts +0 -23
  11. package/core/plugins.d.ts +0 -8
  12. package/core/reactivity.d.ts +0 -19
  13. package/core/security.d.ts +0 -56
  14. package/core/store.d.ts +0 -7
  15. package/core/sync.d.ts +0 -76
  16. package/core/types.d.ts +0 -163
  17. package/core/utils.d.ts +0 -2
  18. package/docs/README.md +0 -389
  19. package/docs/SUMMARY.md +0 -64
  20. package/docs/_config.yml +0 -1
  21. package/docs/api.md +0 -381
  22. package/docs/chapters/01-philosophy.md +0 -54
  23. package/docs/chapters/02-getting-started.md +0 -68
  24. package/docs/chapters/03-the-magnetar-way.md +0 -69
  25. package/docs/chapters/04-persistence-and-safety.md +0 -125
  26. package/docs/chapters/05-plugin-sdk.md +0 -290
  27. package/docs/chapters/05-plugins-and-extensibility.md +0 -190
  28. package/docs/chapters/06-case-studies.md +0 -69
  29. package/docs/chapters/07-faq.md +0 -53
  30. package/docs/chapters/08-migration-guide.md +0 -284
  31. package/docs/chapters/09-security-architecture.md +0 -50
  32. package/docs/chapters/10-local-first-sync.md +0 -146
  33. package/docs/qa.md +0 -47
  34. package/index.d.ts +0 -41
  35. package/index.js +0 -2
  36. package/index.js.map +0 -7
  37. package/plugins/index.d.ts +0 -15
  38. package/plugins/official/analytics.plugin.d.ts +0 -9
  39. package/plugins/official/cloud-sync.plugin.d.ts +0 -22
  40. package/plugins/official/debug.plugin.d.ts +0 -2
  41. package/plugins/official/devtools.plugin.d.ts +0 -4
  42. package/plugins/official/guard.plugin.d.ts +0 -2
  43. package/plugins/official/immer.plugin.d.ts +0 -2
  44. package/plugins/official/indexeddb.plugin.d.ts +0 -7
  45. package/plugins/official/schema.plugin.d.ts +0 -2
  46. package/plugins/official/snapshot.plugin.d.ts +0 -2
  47. package/plugins/official/sync.plugin.d.ts +0 -4
  48. package/plugins/official/undo-redo.plugin.d.ts +0 -4
  49. package/rgs-extension.vsix +0 -0
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)
@@ -379,6 +379,87 @@ npm run test:e2e
379
379
 
380
380
  ---
381
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
+
382
463
  ## 📄 License
383
464
 
384
465
  MIT © [Dario Passariello](https://github.com/dpassariello)
package/package.json CHANGED
@@ -1,85 +1,91 @@
1
- {
2
- "name": "@biglogic/rgs",
3
- "version": "3.7.0",
4
- "description": "Argis (RGS) - Reactive Global State: A react state everywhere made easy",
5
- "type": "module",
6
- "keywords": [
7
- "rgs",
8
- "gstate",
9
- "state-management",
10
- "react",
11
- "enterprise",
12
- "hooks",
13
- "global-state",
14
- "immer",
15
- "biglogic",
16
- "persistence",
17
- "react-globo-state",
18
- "argis"
19
- ],
20
- "homepage": "https://github.com/BigLogic-ca/rgs",
21
- "bugs": {
22
- "url": "https://github.com/BigLogic-ca/rgs/issues"
23
- },
24
- "license": "MIT",
25
- "author": "Dario Passariello <dariopassariello@gmail.com>",
26
- "contributors": [
27
- {
28
- "name": "Dario Passariello",
29
- "email": "dariopassariello@gmail.com",
30
- "url": "https://dario.passariello.ca/"
31
- },
32
- {
33
- "name": "Valeria Cala Scaglitta",
34
- "email": "valeriacalascaglitta@gmail.com"
35
- }
36
- ],
37
- "main": "./index.js",
38
- "types": "./index.d.ts",
39
- "exports": {
40
- ".": "./index.js"
41
- },
42
- "scripts": {
43
- "build": "rm -rf dist && node ./esbuild.config.mjs && npx tsc -p tsconfig.json --emitDeclarationOnly",
44
- "build:watch": "node ./esbuild.config.mjs --watch",
45
- "build:extension": "cd vscode-extension && vsce package -o ../dist/rgs-extension.vsix",
46
- "dev": "npm run build:watch",
47
- "lint": "cd tests && npm run lint",
48
- "tsc": "cd tests && tsc --noEmit",
49
- "npm:pack": "npm run build && cd dist && npm pack",
50
- "npm:publish": "npm run build && npm run build:extension && cd dist && npm publish --access=public"
51
- },
52
- "peerDependencies": {
53
- "react": ">=16.8.0",
54
- "react-dom": ">=16.8.0"
55
- },
56
- "peerDependenciesMeta": {
57
- "react": {
58
- "optional": false
59
- },
60
- "react-dom": {
61
- "optional": false
62
- }
63
- },
64
- "dependencies": {
65
- "memorio": "^2.5.0",
66
- "immer": "^11.1.4"
67
- },
68
- "devDependencies": {
69
- "@types/jest": "30.0.0",
70
- "@types/node": "^25.3.2",
71
- "@types/react": "^19.2.14",
72
- "@types/react-dom": "^19.2.3",
73
- "esbuild": "0.27.3",
74
- "esbuild-node-externals": "1.20.1",
75
- "esbuild-plugin-alias": "0.2.1",
76
- "esbuild-plugin-copy": "2.1.1",
77
- "esbuild-sass-plugin": "3.6.0",
78
- "esbuild-scss-modules-plugin": "1.1.1",
79
- "react": "^19.2.4",
80
- "react-dom": "^19.2.4",
81
- "ts-jest": "29.4.6",
82
- "tslib": "^2.8.1",
83
- "typescript": "^5.9.3"
84
- }
85
- }
1
+ {
2
+ "name": "@biglogic/rgs",
3
+ "version": "3.7.3",
4
+ "description": "Argis (RGS) - Reactive Global State: A react state everywhere made easy",
5
+ "type": "module",
6
+ "keywords": [
7
+ "rgs",
8
+ "gstate",
9
+ "state-management",
10
+ "react",
11
+ "enterprise",
12
+ "hooks",
13
+ "global-state",
14
+ "immer",
15
+ "biglogic",
16
+ "persistence",
17
+ "react-globo-state",
18
+ "argis"
19
+ ],
20
+ "homepage": "https://github.com/BigLogic-ca/rgs",
21
+ "bugs": {
22
+ "url": "https://github.com/BigLogic-ca/rgs/issues"
23
+ },
24
+ "license": "MIT",
25
+ "author": "Dario Passariello <dariopassariello@gmail.com>",
26
+ "contributors": [
27
+ {
28
+ "name": "Dario Passariello",
29
+ "email": "dariopassariello@gmail.com",
30
+ "url": "https://dario.passariello.ca/"
31
+ },
32
+ {
33
+ "name": "Valeria Cala Scaglitta",
34
+ "email": "valeriacalascaglitta@gmail.com"
35
+ }
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
+ ],
48
+ "main": "./index.js",
49
+ "types": "./index.d.ts",
50
+ "exports": {
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
61
+ },
62
+ "scripts": {
63
+ "dev": "npm run build:watch",
64
+ "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",
65
+ "build:watch": "node ./esbuild.config.mjs --watch",
66
+ "build:extension": "cd vscode-extension && vsce package -o ../dist/rgs-extension.vsix",
67
+ "lint": "cd tests && npm run lint",
68
+ "tsc": "cd tests && tsc --noEmit",
69
+ "test": "cd tests && npm test",
70
+ "npm:pack": "npm run build && cd dist && npm pack",
71
+ "npm:publish": "npm run build && npm run build:extension && cd dist && npm publish --access=public"
72
+ },
73
+ "devDependencies": {
74
+ "@types/node": "^25.3.2",
75
+ "@types/react": "^19.2.14",
76
+ "@types/react-dom": "^19.2.3",
77
+ "esbuild": "0.27.3",
78
+ "esbuild-node-externals": "1.20.1",
79
+ "esbuild-plugin-alias": "0.2.1",
80
+ "esbuild-plugin-copy": "2.1.1",
81
+ "esbuild-sass-plugin": "3.6.0",
82
+ "esbuild-scss-modules-plugin": "1.1.1",
83
+ "immer": "11.1.4",
84
+ "memorio": "2.5.0",
85
+ "react": "^19.2.4",
86
+ "react-dom": "^19.2.4",
87
+ "ts-jest": "29.2.5",
88
+ "tslib": "^2.8.1",
89
+ "typescript": "^5.9.3"
90
+ }
91
+ }
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,56 +0,0 @@
1
- export declare const isCryptoAvailable: boolean;
2
- export declare const deriveKeyFromPassword: (password: string, salt: Uint8Array, iterations?: number) => Promise<EncryptionKey>;
3
- export declare const generateSalt: (length?: number) => Uint8Array;
4
- export interface EncryptionKey {
5
- key: CryptoKey;
6
- iv: Uint8Array;
7
- }
8
- export declare const generateEncryptionKey: () => Promise<EncryptionKey>;
9
- export declare const exportKey: (encryptionKey: EncryptionKey) => Promise<{
10
- key: string;
11
- iv: string;
12
- }>;
13
- export declare const importKey: (keyData: string, ivData: string) => Promise<EncryptionKey>;
14
- export declare const encrypt: (data: unknown, encryptionKey: EncryptionKey) => Promise<string>;
15
- export declare const decrypt: <T>(encryptedData: string, encryptionKey: EncryptionKey) => Promise<T>;
16
- export interface AuditEntry {
17
- timestamp: number;
18
- action: 'set' | 'get' | 'delete' | 'hydrate';
19
- key: string;
20
- userId?: string;
21
- success: boolean;
22
- error?: string;
23
- }
24
- export declare const setAuditLogger: (logger: (entry: AuditEntry) => void) => void;
25
- export declare const isAuditActive: () => boolean;
26
- export declare const logAudit: (entry: AuditEntry) => void;
27
- export type Permission = 'read' | 'write' | 'delete' | 'admin';
28
- export interface AccessRule {
29
- pattern: string | ((key: string, userId?: string) => boolean);
30
- permissions: Permission[];
31
- }
32
- export type AccessRulesMap = Map<string | ((key: string, userId?: string) => boolean), Permission[]>;
33
- export declare const addAccessRule: (rules: AccessRulesMap, pattern: string | ((key: string, userId?: string) => boolean), perms: Permission[]) => void;
34
- export declare const hasPermission: (rules: AccessRulesMap, key: string, action: Permission, _userId?: string) => boolean;
35
- export declare const sanitizeValue: (value: unknown) => unknown;
36
- export declare const validateKey: (key: string) => boolean;
37
- export interface ConsentRecord {
38
- id: string;
39
- purpose: string;
40
- granted: boolean;
41
- timestamp: number;
42
- }
43
- export type ConsentsMap = Map<string, ConsentRecord[]>;
44
- export declare const recordConsent: (consents: ConsentsMap, userId: string, purpose: string, granted: boolean) => ConsentRecord;
45
- export declare const hasConsent: (consents: ConsentsMap, userId: string, purpose: string) => boolean;
46
- export declare const revokeConsent: (consents: ConsentsMap, userId: string, purpose: string) => ConsentRecord | null;
47
- export declare const getConsents: (consents: ConsentsMap, userId: string) => ConsentRecord[];
48
- export declare const exportUserData: (consents: ConsentsMap, userId: string) => {
49
- userId: string;
50
- exportedAt: number;
51
- consents: ConsentRecord[];
52
- };
53
- export declare const deleteUserData: (consents: ConsentsMap, userId: string) => {
54
- success: boolean;
55
- deletedConsents: number;
56
- };
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,76 +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 | (() => string | null);
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 _getAuthToken;
60
- private _setupOnlineListener;
61
- private _setupStoreListener;
62
- private _startAutoSync;
63
- private _notifyOnlineChange;
64
- private _notifyStateChange;
65
- queueChange(key: string, value: unknown): void;
66
- sync(): Promise<SyncResult>;
67
- private _fetchRemoteVersions;
68
- private _pushChange;
69
- private _resolveConflict;
70
- getState(): SyncState;
71
- onOnlineChange(callback: (online: boolean) => void): () => void;
72
- onStateChange(callback: (state: SyncState) => void): () => void;
73
- flush(): Promise<SyncResult>;
74
- destroy(): void;
75
- }
76
- export declare const createSyncEngine: <S extends Record<string, unknown>>(store: IStore<S>, config: SyncConfig) => SyncEngine<S>;