Gathering detailed insights and metrics for @rgomezp/ganon
Gathering detailed insights and metrics for @rgomezp/ganon
Gathering detailed insights and metrics for @rgomezp/ganon
Gathering detailed insights and metrics for @rgomezp/ganon
npm install @rgomezp/ganon
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
4
React Native Ganon SDK provides seamless storage management and cloud backup capabilities using Firestore and a local storage manager (MMKV).
Ganon is a storage and backup management SDK that simplifies integrating Firestore and a local storage system in React Native projects. It provides a typed instance of a storage managers and a simple API for data locally as well as syncing to Firebase.
1# npm 2npm install @rgomezp/ganon 3 4# yarn 5yarn add @rgomezp/ganon
Ganon requires configuration to map local storage data to Firestore backup.
Define a storage mapping interface. Include the identifier key you will use to track users.
1import { BaseStorageMapping } from '@rgomezp/ganon'; 2 3// Define a mapping interface 4interface MyMapping extends BaseStorageMapping { 5 email: string; // identifier key 6 booksRead: number; 7 books: { [key: string]: { title: string } }; 8}
Define a configuration object for Firestore backups. Maps documents to document and sub-collection keys.
You can exclude the identifier key as this is handled automatically.
1interface CloudBackupConfig { 2 [key: string]: { 3 docKeys?: string[]; 4 subcollectionKeys?: string[]; 5 type?: 'string' | 'number' | 'boolean' | 'object' | 'array'; 6 schema?: JSONSchema7; // JSON Schema for validating object/array data 7 } 8}
Example with Schema Validation:
1import { CloudBackupConfig } from '@rgomezp/ganon'; 2import { JSONSchema7 } from 'json-schema'; 3 4// Define a mapping interface 5interface MyMapping extends BaseStorageMapping { 6 email: string; // identifier key 7 booksRead: number; 8 books: { 9 [key: string]: { 10 title: string; 11 author: string; 12 rating: number; 13 genres: string[]; 14 publishedDate: string; 15 } 16 }; 17 userPreferences: { 18 theme: 'light' | 'dark'; 19 notifications: boolean; 20 fontSize: number; 21 }; 22} 23 24// Define JSON schemas for validation 25const bookSchema: JSONSchema7 = { 26 type: 'object', 27 required: ['title', 'author', 'rating', 'genres', 'publishedDate'], 28 properties: { 29 title: { type: 'string', minLength: 1 }, 30 author: { type: 'string', minLength: 1 }, 31 rating: { type: 'number', minimum: 0, maximum: 5 }, 32 genres: { 33 type: 'array', 34 items: { type: 'string' }, 35 minItems: 1 36 }, 37 publishedDate: { 38 type: 'string', 39 format: 'date' 40 } 41 } 42}; 43 44const userPreferencesSchema: JSONSchema7 = { 45 type: 'object', 46 required: ['theme', 'notifications', 'fontSize'], 47 properties: { 48 theme: { 49 type: 'string', 50 enum: ['light', 'dark'] 51 }, 52 notifications: { type: 'boolean' }, 53 fontSize: { 54 type: 'number', 55 minimum: 12, 56 maximum: 24 57 } 58 } 59}; 60 61const cloudConfig: CloudBackupConfig<MyMapping> = { 62 reading: { 63 docKeys: ['booksRead'], 64 subcollectionKeys: ['books'], 65 type: 'object', 66 schema: bookSchema 67 }, 68 preferences: { 69 docKeys: ['userPreferences'], 70 type: 'object', 71 schema: userPreferencesSchema 72 } 73};
This configuration:
When using this configuration, Ganon will automatically validate data against these schemas before syncing to Firestore. If validation fails, the sync operation will be rejected and an error will be thrown.
Property | Type | Description |
---|---|---|
identifierKey | string | Unique user identifier key for users (e.g. email , uid ) |
cloudConfig | CloudBackupConfig<T> | Configuration object for Firestore backups where T is your custom storage mapping. |
logLevel | LogLevel | LogLevel enum |
onSyncConflict | ConflictHandler<T> | Optional handler for resolving sync conflicts |
Ganon provides a robust conflict resolution system to handle synchronization conflicts that occur when data is modified both locally and remotely between syncs.
1import { ConflictHandler } from '@rgomezp/ganon'; 2 3const conflictHandler: ConflictHandler<MyMapping> = (conflict) => { 4 // Always prefer local changes 5 return { strategy: 'local' }; 6}; 7 8const config = { 9 // ... other config options 10 onSyncConflict: conflictHandler 11};
1{ strategy: 'local' }
1{ strategy: 'remote' }
1{ 2 strategy: 'custom', 3 customValue: mergedData 4}
For detailed conflict resolution documentation, see Conflict Resolution Guide.
Create a new file called ganon.ts
. We must use the instance in order for our types to work as expected.
Export the instance for usage across your codebase.
1import Ganon, { LogLevel } from "@rgomezp/ganon"; 2import cloudBackupConfig from "./cloudBackupConfig"; 3import { StorageMapping } from "src/models/StorageMapping"; 4 5const logLevel = process.env.NODE_ENV === 'development' ? LogLevel.VERBOSE : LogLevel.NONE; 6 7// Initialize once using your specialized type. 8export const ganon: Ganon<StorageMapping> = Ganon.init<StorageMapping>({ 9 identifierKey: 'email', 10 cloudConfig: cloudBackupConfig, 11 logLevel, 12});
1import { ganon } from "<path_to_file>/ganon"; 2 3ganon.set("booksRead", 5);
Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.
Give a ⭐️ if this project helped you!
Copyright © 2025 Honey Wolf LLC This project is Unlicensed.
No vulnerabilities found.
No security vulnerabilities found.