Unleash the future of data management with the ultimate platform for secure, scalable, and dynamic data operations. Power the next generation of applications by combining advanced encryption, revolutionary real-time querying, and seamless synchronization to create an ecosystem where data transforms into action. Effortlessly manage hierarchical structures, deploy groundbreaking queries, and enable unparalleled collaboration with robust integration capabilities. Build enterprise solutions, real-time dashboards, or futuristic IoT systems with a cosmic cornerstone for data innovation.
Package Exports
@trap_stevo/star-vault
Readme
π Star-Vault
Unleash the future of data management with the ultimate platform for secure, scalable, and dynamic data operations. Power the next generation of applications by combining advanced encryption, revolutionary real-time querying, and seamless synchronization to create an ecosystem where data transforms into action.
π Features
π Optional Encryption β Secure sensitive data at rest
βοΈ Sharded Storage Engine β Efficiently scales writes across shards
π§ In-Memory Caching β High-speed read layer with StarCache
π Write-Ahead Logging β Resilient logs with rotation and retention policies
π Advanced Query Engine β Chainable and expressive queries with filtering, search, sorting, and spatial support
π Real-Time Event Emission β Listen to data changes with fine-grained control
π‘οΈ Authentication Layer β Optional handler to authorize every operation
π Collection Wildcards β Seamlessly operate across multiple collections
Updates an existing record by ID. Setting record data properties to undefined removes them respectively. Returns the updated record. Throws error if not found.
Soft-deletes a record by filtering it out and overwriting the collection. Returns { id, deleted: true }.
β Sync
π Query Engine
Chainable query builder for filtering and searching collection data.
vault.query("collection").whereRecord("id","value")// Filters root record data by key-value pairs.where({key:"value"})// Filters record data by key-value pairs.search("field","text")// Text search within a specific field.recent("timestamp","7d")// Gets records from the last 7 days.near("location",{lat:0,lng:0},50)// Geospatial filter within 50 units.sort({name:1})// Sorts by a field (1 = asc, -1 = desc).select(["id","name"])// Selects specific fields.limit(10)// Limits results.offset(0)// Skips first N records.filterBy(record=> record.active)// Filters with custom function.execute(exactCollection =false)// Run the query with optional strict collection matching
Method
Description
Sync/Async
query(collection)
Begins a query on the specified collection. Returns a chainable builder.
β Sync
whereRecord(criteria)
Filters records by matching key-value pairs. Accepts both object and parameter inputs.
β Sync
where(criteria)
Filters records' data by matching key-value pairs. Accepts both object and parameter inputs.
β Sync
search(field, text)
Performs a text search within a specified field.
β Sync
recent(field, duration)
Filters records based on recency (e.g., "7d" = 7 days).
β Sync
near(field, center, radius)
Filters based on proximity to a location object { lat, lng }.
β Sync
sort(criteria)
Sorts the results by one or more fields.
β Sync
select(fields)
Selects only the specified fields for output.
β Sync
limit(number)
Restricts the number of records returned.
β Sync
offset(number)
Skips a number of records (used for pagination).
β Sync
filterBy(fn)
Filters using a custom function on each record.
β Sync
callback(fn)
Adds a side effect or transformation hook before execution.
β Sync
execute(exactCollection = false)
Run the query. If true, match only the exact collection name; otherwise, include related subcollections.
β Sync
getByID(collection, id)
Shortcut to retrieve a single record by ID.
β Sync
range(min, max)
Static helper to return an inclusive array of numbers in a range.
β Sync
π‘οΈ Authentication
All methods below require authOptions configuration and are used for session/user management.
The following utility methods get utilized internally across authentication-related flows. You may call them directly for validation, diagnostics, or extension purposes.
Method
Description
Sync/Async
validEmail(email)
Determines if an input email follows proper email address format.
β Sync
satisfiesPasswordStrength(password)
Validates whether the password meets the defined passwordRequirements.
β Sync
extractSessionMetadata(req)
Extracts metadata (IP, fingerprint, user agent, etc.) from the request object .
β Sync
lookupUserGeo(ip)
Performs geo-IP lookup using built-in and custom geo services .
βοΈ Async
π§ Event Listening
Used for reactive, event-driven architecture patterns.
Method
Description
Sync/Async
listen(event, nodePath, callback)
Registers a callback for a specific event (create, update, delete) at a given path.
β Sync
emit(event, nodePath, data)
Triggers callbacks for listeners whose paths match the emitted path.
β Sync
π Collection & Path Matching
Utilities for dynamic collection operations and wildcard paths.
Method
Description
Sync/Async
getMatchingCollections(basePath)
Resolves wildcard-based paths like logs/*/2025 to real collection names.
β Sync
matchesPath(listenerPath, nodePath)
Checks if an emitted node path matches a listener's wildcard path.
β Sync
π StarVault Events
StarVault emits real-time events that let you react to data and authentication lifecycle changes across your app. These include both record-level events and auth lifecycle events.
You can listen to them at multiple levels of granularity:
π Global listeners (across all collections and records)
π Collection-level listeners (any record in a collection)
π§Ύ Record-specific listeners (a specific record path)
π Emitted Record Events (StarVault Core)
Event
Description
Emitted Path
create
Fires on record creation.
collectionName/recordID
update
An existing record updated
collectionName/recordID
delete
A record got deleted (soft or hard)
collectionName/recordID
π Emitted Auth Lifecycle Events (StarAuth)
Event
Description
guest:upgraded
A guest account successfully upgraded to a full user
These event hooks power real-time dashboards, activity tracking, notifications, and custom automation β all deeply integrated with StarVault's reactive system.
const StarVault =require("@trap_stevo/star-vault");const vault =newStarVault("./data","./logs",4,"869MB","1w",{enableEncryption:true,masterKey:"supersecretkey",authHandler:(auth)=> auth.token ==="star-vault-demo",authOptions:{allowGuestSessions:true,generateGuestID:()=>"guest-"+ Math.floor(Math.random()*1000000)}});// Register a full userconst userResult =await vault.registerUser("nova@example.com","strongpassword123",{source:"site"},{token:"star-vault-demo"});
console.log("Registered user:", userResult);// Register a guest userconst guestResult =await vault.registerGuestUser({ip:"127.0.0.1"},{referrer:"home"},{source:"guest-form"},{token:"star-vault-demo"});
console.log("Registered guest:", guestResult);
π Listing Users and Sessions
const StarVault =require("@trap_stevo/star-vault");const vault =newStarVault("./data","./logs",4,"869MB","1w",{enableEncryption:true,masterKey:"supersecretkey",authHandler:(auth)=> auth.token ==="star-vault-demo"});// List all usersconst users =await vault.listUsers({},{limit:25},{token:"star-vault-demo"});
console.log("All users:", users);// List all sessions (including inactive and deleted)const sessions =await vault.listAllSessions({includeDeleted:"only"},true,{token:"star-vault-demo"});
console.log("All sessions:", sessions);// List sessions for a specific userconst userSessions =await vault.listSessions("user-001",{device:"mobile"},false,{token:"star-vault-demo"});
console.log("Sessions for user-001:", userSessions);// List recent user activity (active and inactive)const activity =await vault.listUserActivity({includeInactive:true,onlyMostRecent:true},{token:"star-vault-demo"});
console.log("User activity:", activity);
Star-Vault transcends traditional data systemsβoffering a full-fledged database engine and cosmic foundation that propels secure, reactive, and intelligent data-driven architectures.