npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kba/anno-store

v0.0.8

Published

Open Annotation Store (base class)

Downloads

4

Readme

anno-store

Interface for stores

Implementing a store

To implement a store, override the Public API with this convention:

  • Prepend and underscore to the method name
  • Method takes exactly two parameters: context and callback
  • All positional parameters become keys in the context object

For example to override the create(anno, options, callback) method:

// my-store/index.js
class MyStore extends require('@kba/anno-store') {
  
  _create(options, callback) {
    const anno = options.anno
    // ...
    return callback(...)
  }
}

Public API

static load(loadingModule)

Modules may call this static method to instantiate a store from the environment and using the packages installed in the calling package.

// my-package/index.js
const store = require('@kba/anno-store').load(module)
store.init(...)

use(middleware)

Use middleware for auth etc.

init(options, cb)

Initialize a connection to the store.

  • @param {Options} options
  • @param {String} options.user
  • @param {function} callback

wipe(options, callback)

Wipe the store, revisions and all.

  • @param {Options} options
  • @param {String} options.user
  • @param {function} callback

disconnect(options, callback)

Disconnect a store. A disconnected store cannot be used until init is called again.

  • @param {Options} options
  • @param {String} options.user
  • @param {function} callback

get(annoId, options, cb)

Retrieve an annotation.

  • @param {String|Array<String>} annoIds
  • @param {Object} options
    • @param {Boolean} options.latest Return the latest revision only
    • @param {Boolean} options.metadataOnly Return only metadata
    • @param {Boolean} options.skipVersions Omit versions
    • @param {Boolean} options.skipReplies Omit replies
  • @param {String} options.user
  • @param {function} callback

create(anno, options, callback)

Create an annotation.

  • @param {Object} anno
  • @param {Options} options
  • @param String options.slug Proposal for the ID to create
  • @param {String} options.user
  • @param {function} callback

revise(annoId, anno, options, callback)

Revise an annotation.

  • @param {String} annoId
  • @param {Object} anno
  • @param {Options} options
    • @param {String} options.user
  • @param {function} callback

delete(annoId, options, callback)

remove(annoId, options, callback)

Delete an annotation, i.e. set the deleted date.

  • @param {String} annoId
  • @param {Options} options
  • @param {Boolean} options.forceDelete Set to true to hint the store to actually delete, not just mark deleted
  • @param {String} options.user
  • @param {function} callback

search(query, options, callback)

Search the store.

  • @param {Object} query
  • @param {Options} options
  • @param {String} options.user
  • @param {function} callback

reply(annoId, anno, options, callback)

comment(annoId, anno, options, callback)

Reply to an annotation

  • @param {String} annoId
  • @param {Object} anno
  • @param {Options} options
  • @param {String} options.user
  • @param {function} callback

aclcheck(targets, options, callback)

  • @param {Array} targets
  • @param {Options} options
  • @param {function} callback

import(anno, options, callback)

Replaces the complete annotation with the passed annotation, not just revise it.

  • @param {Object} anno
  • @param {Options} options
    • @param String options.slug Proposal for the ID to create
    • @param {String} options.user
  • @param {function} callback

Protected API

These methods are available for store implementations but should not be used by consumers.

_idFromURL(url)

Get only the slug part of a URL

_urlFromId(annoId)

Generate a full URL to an annotation by its id.

_normalizeTarget(annoDoc)

TODO no idempotency of targets with normalization -> disabled for now

_normalizeType(anno)

Make sure anno.type exists, is an Array and contains Annotation

deleteId(anno)

Delete the id and store it in via.

  • @param Object anno

_genid(slug='')

Generate an ID for the annotation from slug and a "nice" slugid