Documentation Index
Fetch the complete documentation index at: https://mintlify.com/estebanrfp/gdb/llms.txt
Use this file to discover all available pages before exploring further.
Migration Guide: from new GDB() to await gdb(...)
This guide helps you migrate from the class-based API (new GDB()) to the new async factory function (await gdb(...)). It covers key changes, before/after examples, Security Manager (SM) integration, and common pitfalls.
Key changes
- Support for
new GDB()has been removed.- Initialize with the async function:
const db = await gdb(name, options). - If you use
new GDB(), an error will be thrown pointing to the correct call.
- Initialize with the async function:
- Public operations API remains stable:
put,get,map,remove,link,clearkeep their signatures and behavior.
- Internals exposed for module compatibility:
db.hybridClock,db.graph,db.syncChannelare available as read-only getters.db.readymay exist for legacy uses, but preferawait gdb(...).
Quick migration (before → after)
Basic initialization
Before:Using map (real-time subscription)
Before:
await gdb(...)):
Using get (point-in-time and reactive)
Before:
Write and delete
Before:Security Manager (SM) and RBAC integration
Recommended initialization
smis injected when passing{ sm: { superAdmins: ['0x1...', '0x2...'] } }at initialization. Access it viadb.sm.- Internals expected by SM (now exposed):
db.hybridClock,db.graph,db.syncChannel. - Standardized actions (recommended):
read,write,link,sync,delete.
Permission check (example)
Browser usage (ESM)
- Using the local bundle:
- Using the NPM package (if applicable):
Common pitfalls and fixes
-
Error:
db.map is not a functionordb.put is not a function- Cause: using
dbbefore initialization completes. - Fix: use
const db = await gdb('name')before calling any method.
- Cause: using
-
SM error:
Cannot read properties of undefined (reading 'now')- Cause: module expected
db.hybridClockwhich was not exposed. - Status: Fixed;
hybridClock,graph, andsyncChannelare exposed as getters.
- Cause: module expected
-
mapdoesn’t emit after loading the graph- Ensure you call
await gdb(...)beforedb.map(...). - Confirm your
query/$limit doesn’t filter out all nodes.
- Ensure you call
Migration checklist
- Replace all occurrences of
new GDB(name, options)withawait gdb(name, options). - Ensure the first use of
dbalways happens afterawait gdb(...). - If you use SM:
- Initialize with
{ sm: { superAdmins: ['0x1...', '0x2...'] } }(mandatorysuperAdminsarray). - The security context is set up automatically; no additional calls needed.
- Initialize with
- Review RBAC and use standardized actions (
read,write,link,sync,delete). - Test end-to-end: initial load,
put, update,remove,link, and P2P sync when applicable.
FAQ
-
Can I still use
db.ready?- It may exist in some contexts, but it’s not recommended. Prefer
await gdb(...).
- It may exist in some contexts, but it’s not recommended. Prefer
-
Did
maporgetsignatures change?- No. They still return
{ results, unsubscribe }or{ result, unsubscribe }accordingly.
- No. They still return
-
How do I filter and order in
map?- Use options:
{ query: {...}, field: 'timestamp', order: 'asc'|'desc', $limit, $after, $before }.
- Use options:
Full example (To‑Do List)
Before:Need help? Open an issue with before/after code and the observed error; we’ll help you migrate quickly.