summit-plastic
v0.1.1
Published
An embedded JavaScript application engine built on Summit NodeDB.
Downloads
32
Maintainers
Readme
Summit-Plastic
Summit-Plastic is an embedded JavaScript application engine built on top of Summit NodeDB. It adds the application-level capabilities developers need—search, document indexing, ranking, realtime events, channels, and file storage—without reimplementing tables, rows, SQL, or the NodeDB storage format.
Install
npm install summit-plasticQuick start
import { Plastic } from "summit-plastic";
const app = new Plastic({ database: "app.db" });
await app.connect();
await app.documents.add({
id: "video-123",
title: "Minecraft Survival",
content: "A Minecraft survival gameplay video",
metadata: { category: "gaming", tags: ["minecraft", "survival"] }
});
const results = app.search("minecraft survival", {
filters: { "metadata.category": "gaming" },
limit: 10
});
console.log(results);
await app.close();connect() opens the NodeDB file and Plastic creates only its own adapter
tables/buckets. NodeDB remains the low-level database engine responsible for
pages, persistence, tables, rows, SQL, and buckets.
Data API
Plastic exposes a JSON-friendly table adapter:
const users = app.table("users");
users.insert({ id: "u1", name: "Kyle", age: 25 });
users.find({ age: 25 });
users.update("u1", { age: 26 });
users.remove("u1");Document operations automatically update a persisted term-vector/inverted
index and emit document:insert, document:update, and document:delete
events. Search supports stemming, normalization, stop-word removal, AND/OR
matching, prefix retrieval, phrase matching, BM25-style ranking with field
boosts, metadata filters, highlights, sorting, and pagination:
const page = app.searchPage('"minecraft survival"', {
operator: "AND",
fields: { title: 5, content: 1 },
highlight: true,
limit: 20
});Indexes
Custom fields can be added to the search index. Definitions are persisted in
Plastic metadata and loaded again on the next connect():
app.index.create({ collection: "videos", field: "title" });Documents can target a collection with collection: "videos", and search can
scope to it with { collection: "videos" }.
Authentication
Plastic includes an embedded authentication system with accounts, password hashing, sessions, and local developer login state.
import { Plastic } from "summit-plastic";
const app = new Plastic({ database: "app.db" });
await app.connect();
await app.auth.signup({
name: "Summit",
email: "[email protected]",
password: "password"
});
await app.auth.login({
email: "[email protected]",
password: "password"
});
const user = await app.auth.user();
console.log(user);Realtime and messaging
const chat = app.channel("general");
const unsubscribe = chat.subscribe((message) => console.log(message));
const message = chat.send({
user: "Kyle",
message: "Hello",
idempotencyKey: "client-message-1"
});
chat.edit(message.id, { message: "Hello everyone" });
chat.react(message.id, "Kyle", "👋");
chat.markRead("Kyle", message.id);
console.log(chat.history());
const server = await app.serve({ host: "127.0.0.1", port: 8787 });Channels persist membership, support cursor-based history, idempotent sends,
replies, edits, soft deletes, reactions, read receipts, and unread counts.
app.serve() starts a WebSocket server. RealtimeClient.subscribe() waits for
the server acknowledgement, then receives created, updated, deleted, reaction,
and read events for the subscribed channel.
File storage
Plastic buckets use NodeDB buckets for bytes and a Plastic metadata collection for file metadata:
const images = app.bucket("images");
await images.upload("photo.png", "./photo.png", {
contentType: "image/png"
});
const bytes = images.download("photo.png");CLI
npx summit-plastic init
npx summit-plastic database create app.db
npx summit-plastic add document.json --database app.db
npx summit-plastic search "minecraft" --database app.db
npx summit-plastic status --database app.db
npx summit-plastic serve --database app.db --port 8787The plastic command remains available as a compatibility alias. The CLI uses
Commander.js and Summit Marker for help, errors, and terminal output.
Development
npm testPlastic is an ES module package and requires Node.js 18 or newer.
