Skip to content

graffiti-garden/implementation-local

Repository files navigation

Graffiti Local Implementation

This is a local implementation of the Graffiti API using PouchDB. By default, it automatically persist data in both the browser and Node.js using whatever stoage is available in each environment. It can also be configured to use an external CouchDB instance, but using a remote database is insecure.

Installation

In node.js, simply install the package with npm:

npm install @graffiti-garden/implementation-local

In the browser, you can use a CDN like jsDelivr. Add an import map the the <head> of your HTML file:

<head>
    <script type="importmap">
        {
            "imports": {
                "@graffiti-garden/implementation-local": "https://cdn.jsdelivr.net/npm/@graffiti-garden/implementation-local/dist/browser/index.js"
            }
        }
    </script>
</head>

In either case, you can then import the package like so:

import { GraffitiLocal } from "@graffiti-garden/implementation-local";
const graffiti = new GraffitiLocal()

Usage

This is an implementation of the Graffiti API, so to use it please refer to the Graffiti API documentation.

The only major difference is that options can be passed to the constructor to configure the PouchDB instance. The PouchDB instance will create a local database by default, in either the browser or Node.js. However, you could configure it to use an external CouchDB instance as follows:

import { GraffitiLocal } from "@graffiti-garden/implementation-local";
const graffiti = new GraffitiLocal({
  pouchDBOptions: {
    name: "http://admin:password@localhost:5984/graffiti",
  }
})

See the PouchDB documentation for more options.

Extending

Pieces of this implementation can be pulled out to use in other implementations.

// The basic database interface based on PouchDB
import { GraffitiLocalDatabase } from "@graffiti-garden/implementation-local/database";
// The log in and out methods and events - insecure but useful for testing
import { GraffitiLocalSessionManager } from "@graffiti-garden/implementation-local/session-manager";
// Various utilities for implementing the Graffiti API
import * as GraffitiUtilities from "@graffiti-garden/implementation-local/utilities";

TODO

  • Permanently delete content after it has been deleted for a certain amount of time
  • Obscure cursors and make them only usable once.
    • They should expire, too, if they have been around longer than the delete timer.

About

A local reference implementation of the Graffiti API using PouchDB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published