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

via-core

v0.4.2

Published

Document oriented models

Downloads

5

Readme

via-core

Description

Core interfaces, errors, helpers, etc.

Install

npm install
gulp build.node

API

Proxy

A proxy is an object responsible of interactions with the data source.

interface Proxy {
  format: string;
  build (schema: ViaSchema): Promise<any>;
  create (data: Object): Promise<Object>;
  read (filter: Object, options?: ReadOptions): Promise<Cursor>;
  readById (id: string, options?: ReadOptions): Promise<Object>;
  update (filter: Document, update: Object, options?: UpdateOptions): Promise<UpdateResult>;
  updateById (id: string, rev: string, update: Object, options?: UpdateOneOptions): Promise<UpdateResult>;
  delete (): Promise<any>;
}

.format: string

A string describing the data format returned by the database. Either json or bson.

.build (schema: ViaSchema): Promise<any>

Ensures that the required tables, collections, databases, and so on are created.

.create (data: Object): Promise<Object>

Creates a new entry in the database for the supplied plain object. Returns the data stored in the database, it may have additional fields (such as _id pr _rev).

.read (filter: Object, options?: ReadOptions): Promise<Cursor>

interface Cursor {
  toArray (): Promise<any[]>;
}

interface ReadOptions {
  fields?: Dictionary<boolean>;
  skip?: number;
  limit?: number;
  sort?: string[];
  timeout?: number;
}

The filter is a plain Mongo Query Document. You can choose the fields you want to select. (By default, the proxy will try to return all the fields). Given this document:

{
    foo: "foo string",
    quz: "quz string",
    child: {
        hello: "world!",
        bar: 42
    },
    atoms: [
        {
            name: "hydrogen",
            number: 1
        },
        {
            name: "carbon",
            number: 6
        }
    ]
}

And this projection:

{
    "foo": true,
    "child.bar": true,
    "atoms[].name": true
}

The result will contain at least:

{
    foo: "foo string",
    child: {
        bar: 42
    },
    atoms: [
        {
            name: "hydrogen"
        },
        {
            name: "carbon"
        }
    ]
}

.update (filter: Document, update: Object, options?: UpdateOptions): Promise<UpdateResult>

update is a diff object (obtained by the related Schema)

interface UpdateOptions {
  timeout?: number;
}

interface UpdateOneOptions {
  timeout?: number;
}

interface UpdateResult {
  updateCount: number;
}

Type<T, D>

| Parameter | Description | |-------------|-------------------------| | T | Closest Typescript type | | D | Diff type |

read(format: string, val: any, options?: any): Bluebird.Thenable<T>

Attempt to read the value retrieved from the supplied format. Tries its best to return a valid value.

readTrusted(format: string, val: any, options?: any): Bluebird.Thenable<T>

Similar to read but allowed to emit extraneous tests when you have control over the encoded value.

write(format: string, val: T, options?: any): Bluebird.Thenable<any>

Prepare the value to be encoded in the supplied format.

test(val: any, options?: any): Bluebird.Thenable<Error>

Checks if the value matches the type. If the value is valid, test returns null, otherwise it returns an Error explaining why the value is not valid.

equals(val1: T, val2: T, options?: any): Bluebird.Thenable<boolean>

Returns a boolean indicating if both values are equal.

clone(val: T, options?: any): Bluebird.Thenable<T>

Returns a deep copy of val.

diff(oldVal: T, newVal: T, options?: any): Bluebird.Thenable<D>

Returns a diff representing the changes from oldVal to newVal.

patch(oldVal: T, diff: D, options?: any): Bluebird.Thenable<T>

Applyes the diff to oldVal in order to obtain newVal.

revert(newVal: T, diff: D, options?: any): Bluebird.Thenable<T>

The reverse of patch.

Schema

interface SchemaDiff {
  create: Dictionary<data>,
  update: Dictionary<diff>,
  delete: Dictionary<data>
}