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

nekostore

v0.6.0

Published

Real-time synced data-store like Firestore with type

Downloads

13

Readme

Nekostore

npm status Travis Codecov David David

Real-time synchronized data store like Firestore for TypeScript.

Requirements

  • Node.js >= 10.0.0

Usage

Install

$ npm i -S nekostore

Import

import Nekostore from 'nekostore';
import BasicDriver from 'nekostore/src/driver/basic';

Create Nekostore instance

const driver: Driver = new BasicDriver();
const nekostore: Nekostore = new Nekostore(driver);

Get reference

See also

interface Data {
  foo: string;
  bar?: number;
}

interface ChildData {
  pyo: boolean;
}

const colRef: CollectionReference<Data> = nekostore.collection<Date>('c1');
const docRef: DocumentReference<Data> = colRef.doc('d1');

const childColRef: CollectionReference<ChildData> = docRef.collection<ChildData>('child');

Add document

const docRef: DocumentReference<Data> = await colRef.add({ foo: 'a', bar: 0 });

Get document

const snapshot: DocumentSnapshot<Data> = await docRef.get();
if (snapshot.exists()) {
  console.log(snapshot.data, snapshot.createTime, snapshot.updateTime);
}

Update document

await docRef.update({ bar: 1 });

Set document

const docRef: DocumentReference<Data> = colRef.('d2');
const s1: DocumentSnapshot<Data> = await docRef.get();
console.log(s1.exists()); // false

await docRef.set({ foo: 'b' });
const s2: DocumentSnapshot<Data> = await docRef.get();
console.log(s2.exists()); // true
console.log(snapshot.data); // { foo: 'b' }

Delete document

await docRef.delete();

Query

See also

function printDocumentsData(snapshot: QuerySnapshot<Data>): void {
  snapshot.docs.forEach((doc: DocumentChange<Data>): void => {
    console.log(doc.ref.id, doc.type, doc.exists(), doc.data);
  });
}

await colRef.add({ foo: 'a', bar: 0 }); // d1
await colRef.add({ foo: 'b', bar: 1 }); // d2
await colRef.add({ foo: 'c', bar: 2 }); // d3

Get all documents

const snapshot: QuerySnapshot<Data> = await colRef.get();
printDocumentsData(snapshot); // random order

Sort

const asc: QuerySnapshot<Data> = await colRef.orderBy('bar').get();
printDocumentsData(asc); // d1, d2, d3

const desc: QuerySnapshot<Data> = await colRef.orderBy('bar').get();
printDocumentsData(desc); // d3, d2, d1

Limit

const snapshot: QuerySnapshot<Data> = await colRef.orderBy('foo').limit(2).get();
printDocumentsData(snapshot); // d1, d2

EndAt EndBefore StartAfter StartAt

const s1: QuerySnapshot<Data> = await colRef.orderBy('bar').endAt(1).get();
printDocumentsData(s1); // d1, d2

const s2: QuerySnapshot<Data> = await colRef.orderBy('bar').endBefore(1).get();
printDocumentsData(s2); // d1

const s3: QuerySnapshot<Data> = await colRef.orderBy('bar').startAfter(1).get();
printDocumentsData(s3); // d3

const s4: QuerySnapshot<Data> = await colRef.orderBy('bar').startAt(1).get();
printDocumentsData(s4); // d2, d3

Where

const s1: QuerySnapshot<Data> = await colRef.where('foo', '==', 'c').get();
printDocumentsData(s1); // d3

const s2: QuerySnapshot<Data> = await colRef.orderBy('bar').where('foo', '>=', 'b').get();
printDocumentsData(s2); // d2, d3

const s3: QuerySnapshot<Data> = await colRef.orderBy('bar').where('foo', '<', 'b').get();
printDocumentsData(s3); // d1

Vue integration

import { Component, Vue, Prop } from 'vue-property-decorator';
import DocumentReference from 'nekostore/lib/DocumentReference';
import { Doc } from 'nekostore/lib/decorators';

@Component
class MyComponent extends Vue {
  @Prop({ type: Object, required: false, default: null }) ref!: DocumentReference<Data> | null;

  @Doc<Data, MyComponent>('ref') doc!: Data | null;
}
import { Component, Vue, Prop } from 'vue-property-decorator';
import { NonEmptyDocumentSnapshot } from 'nekostore/lib/DocumentSnapshot';
import Query from 'nekostore/lib/Query';
import { Collection } from 'nekostore/lib/decorators';

@Component
class MyComponent extends Vue {
  @Prop({ type: Object, required: false, default: null }) query!: Query<Data> | null;

  @Collection<Data, MyComponent>('query') docs!: NonEmptyDocumentSnapshot[] | null;
}

API Reference

See here