{"library":"many-level","title":"many-level","description":"many-level is a JavaScript library designed to share an abstract-level compatible database over network streams, acting as the spiritual successor to `multileveldown`. Currently at version 2.0.0, it allows a 'host' to expose a LevelDB-like database over any binary stream (e.g., TCP), while 'guests' can connect and interact with it as if it were a local `abstract-level` database instance. It leverages compact Protocol Buffers for efficient message encoding. The project follows a steady release cadence with significant updates marked by major version bumps addressing underlying stream mechanisms and protocol versions. A key differentiator is its optional seamless retry mechanism for guests, which helps maintain connectivity and resume operations, though it comes with a trade-off regarding snapshot guarantees. It ships with TypeScript types, providing a robust development experience.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install many-level"],"cli":null},"imports":["import { ManyLevelHost } from 'many-level'","import { ManyLevelGuest } from 'many-level'","import { Level } from 'level'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { ManyLevelHost, ManyLevelGuest } from 'many-level';\nimport { Level } from 'level';\nimport { pipeline } from 'readable-stream';\nimport { createServer, connect } from 'net';\nimport { rmSync } from 'fs';\n\n// Clean up previous test database if it exists\ntry {\n  rmSync('./db', { recursive: true, force: true });\n} catch (e) {\n  // ignore\n}\n\nconst dbPath = './db';\nconst hostDb = new Level(dbPath);\nconst host = new ManyLevelHost(hostDb);\n\nconst PORT = 9001;\n\nconst server = createServer(function (socket) {\n  pipeline(socket, host.createRpcStream(), socket, (err) => {\n    if (err) console.error('Host pipeline error:', err.message);\n    console.log('Host: Client disconnected.');\n  });\n});\n\nserver.listen(PORT, async () => {\n  console.log(`Host server listening on port ${PORT}`);\n\n  const guestDb = new ManyLevelGuest();\n  const guestSocket = connect(PORT);\n\n  pipeline(guestSocket, guestDb.createRpcStream(), guestSocket, (err) => {\n    if (err) console.error('Guest pipeline error:', err.message);\n    console.log('Guest: Disconnected from host.');\n  });\n\n  try {\n    await guestDb.put('hello', 'world');\n    console.log(`Guest: Successfully put 'hello': 'world'`);\n    const value = await guestDb.get('hello');\n    console.log(`Guest: Retrieved 'hello': '${value}'`);\n\n    await guestDb.del('hello');\n    console.log(`Guest: Successfully deleted 'hello'.`);\n\n    const hostValue = await hostDb.get('hello');\n    console.log(`Host: Value after guest operation: '${hostValue}'`);\n  } catch (error) {\n    console.error('Guest operation failed:', error.message);\n  } finally {\n    server.close(() => console.log('Host server closed.'));\n    await hostDb.close();\n    console.log('Host database closed.');\n    try {\n        rmSync(dbPath, { recursive: true, force: true });\n        console.log('Cleaned up database files.');\n    } catch (e) {\n        console.warn('Failed to clean up database files:', e.message);\n    }\n  }\n});","lang":"typescript","description":"This quickstart demonstrates setting up a `ManyLevelHost` server and connecting a `ManyLevelGuest` client, performing basic put/get/del operations, and ensuring proper shutdown.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}