{"id":17509,"library":"baselet","title":"Baselet","description":"Baselet is a lightweight, file-system based database library for JavaScript and TypeScript applications, currently at version 0.3.0. It leverages `disklet` for persistent storage, allowing it to store data directly on disk without requiring external database servers. This makes it suitable for embedded applications, local storage, or serverless environments where a simple, durable key-value or document store is needed. Its primary differentiators include its small footprint, direct disk interaction via `disklet`, and a focus on simplicity. As a 0.x package, it is still under active development, and its API might evolve with subsequent minor versions, though a regular release cadence isn't yet established. Developers should anticipate potential API adjustments.","status":"active","version":"0.3.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/EdgeApp/baselet","tags":["javascript","typescript"],"install":[{"cmd":"npm install baselet","lang":"bash","label":"npm"},{"cmd":"yarn add baselet","lang":"bash","label":"yarn"},{"cmd":"pnpm add baselet","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core storage layer for all database operations, required for any Baselet instance.","package":"disklet","optional":false}],"imports":[{"note":"Use this factory function to initialize a Baselet database instance. It requires a Disklet instance and a path.","wrong":"const makeBaselet = require('baselet')","symbol":"makeBaselet","correct":"import { makeBaselet } from 'baselet'"},{"note":"This is the TypeScript interface defining the Baselet instance API. Use it for type annotations; it's not a runtime construct.","wrong":"import type Baselet from 'baselet'","symbol":"Baselet","correct":"import { Baselet } from 'baselet'"},{"note":"For CommonJS environments. Given its current version (0.x), Baselet generally supports CJS alongside ESM, but ESM is recommended for new projects.","symbol":"makeBaselet (CommonJS)","correct":"const { makeBaselet } = require('baselet')"}],"quickstart":{"code":"import { makeBaselet, Baselet } from 'baselet'\nimport { makeMemoryDisklet } from 'disklet' // Or makeNodeDisklet for Node.js, makeReactNativeDisklet for React Native\n\nasync function runBaseletExample() {\n  // 1. Create a disklet instance (using in-memory for this example, use file-system for persistence)\n  const disklet = makeMemoryDisklet()\n  const dbPath = 'my-app-data'\n\n  // 2. Initialize Baselet database\n  const db: Baselet = makeBaselet(disklet, dbPath)\n  console.log(`Baselet database initialized at path: ${dbPath}`)\n\n  // 3. Store some JSON data\n  const userId = 'user123'\n  const userData = { name: 'Alice', email: 'alice@example.com', age: 30 }\n  await db.setJson(userId, userData)\n  console.log(`Stored user data for ${userId}`)\n\n  // 4. Retrieve JSON data\n  const retrievedUserData = await db.getJson(userId)\n  console.log(`Retrieved user data for ${userId}:`, retrievedUserData)\n\n  // 5. Store a simple string\n  await db.setText('last-access', new Date().toISOString())\n  console.log('Stored last access time.')\n\n  // 6. Retrieve simple string\n  const lastAccess = await db.getText('last-access')\n  console.log('Last access time:', lastAccess)\n\n  // 7. Attempt to retrieve a non-existent key (should throw or reject)\n  try {\n    await db.getJson('non-existent-key')\n  } catch (error) {\n    console.log(`Attempted to get non-existent key: ${(error as Error).message}`)\n  }\n}\n\nrunBaseletExample().catch(console.error)","lang":"typescript","description":"Initializes an in-memory Baselet database, demonstrating how to store and retrieve JSON objects and raw text. Requires `disklet`."},"warnings":[{"fix":"Refer to the official GitHub repository's changelog or latest source code for API updates between versions. Pinning to exact patch versions is recommended for stability.","message":"As a 0.x package, the API of Baselet is subject to change without strict adherence to semantic versioning. Methods, signatures, or error handling might be modified in minor or patch releases.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"For persistent storage, ensure you use a file-system based disklet (e.g., `makeNodeDisklet` for Node.js or `makeReactNativeDisklet` for React Native) and provide a stable, writable path.","message":"Baselet's persistence depends entirely on the underlying 'disklet' instance. If using a memory-based disklet (e.g., `makeMemoryDisklet`), data will not persist across application restarts.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always use the Baselet API methods (e.g., `setJson`, `getJson`, `delete`) for all data operations within its managed database path to ensure data integrity.","message":"Directly manipulating files within the Baselet's storage path via disklet (or the underlying file system) outside of Baselet's API can lead to data corruption or unexpected behavior.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure you are calling `makeBaselet` correctly with a `Disklet` instance and a string path, and that `Baselet` is properly imported and the correct methods are being called.","cause":"The 'db' object is not a valid Baselet instance, possibly due to incorrect initialization, missing import, or an outdated Baselet version with a different API.","error":"TypeError: db.getJson is not a function"},{"fix":"Choose a new, empty directory path for your Baselet instance, or ensure the existing path is a writable directory and not a file.","cause":"The path provided to `makeBaselet` or the underlying `disklet` factory already exists but is a file, or is inaccessible/read-only, preventing Baselet from initializing its directory structure.","error":"Error: Path exists but is not a directory"},{"fix":"Run `npm install baselet disklet` or `yarn add baselet disklet` to ensure both Baselet and its core `disklet` dependency are installed and available.","cause":"The 'baselet' package is not installed or not correctly linked in your project's `node_modules`.","error":"Module not found: Error: Can't resolve 'baselet' or Cannot find module 'baselet'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}