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

@asmartbear/version-vectors

v1.6.2

Published

Simple, fast utilities for manipulating version vectors and vector clocks

Downloads

64

Readme

Version Vectors

Simple, fast utilities for manipulating version vectors and vector clocks. (Same data structure, different semantic purpose.)

Algorithms are static functions, so they can operate on existing POJOs rather than creating additional allocations.

Features

  • Typescript. Written in Typescript, distributed as regular Javascript; includes Typescript declarations.
  • 100% unit test coverage. And a large variety of corner-case tests.

Usage

Use through npm, or get the source from Github.

Types and functions:

/**
 * A native data type that can be used as the "timestamp" field in a version-vector.
 *
 * There are good use-cases both for numeric counters (simple, more compact) or strings (e.g. https://www.npmjs.com/package/@asmartbear/logical-time).
 * The utilities below work on both.
 */
export declare type Timestamp = string | number;
/**
 * Dot: a single Replica ID / Timestamp pair.
 */
export declare type Dot<C extends Timestamp> = [string, C];
/**
 * Version-vector: A map of replica IDs to counter, which can be a string or integer -- something native and ordered
 */
export declare type VV<C extends Timestamp> = Record<string, C>;
/**
 * The result of comparing two version vectors; the answers are non-linear!
 */
export declare enum CompareResult {
    EQUAL = 0,
    LEFT_DOMINATES = 1,
    RIGHT_DOMINATES = 2,
    CONFLICTED = 3
}
/**
 * Returns a string representation of the version vector.
 */
export declare function toString<C extends Timestamp>(v: VV<C>): string;
/**
 * Returns true only if the given version vector is empty, having no dots.
 */
export declare function isEmpty<C extends Timestamp>(v: VV<C>): boolean;
/**
 * Makes a copy of a vector.
 */
export declare function clone<C extends Timestamp>(v: VV<C>): VV<C>;
/**
 * Adds a replica/timestamp pair to a vector if it doesn't exist, or updates _only if newer_ if it already exists.
 * If you have a `Dot` object, you can invoke like `accumulateDot(v, ...dot)`.
 *
 * @param v version vector to update
 * @return the same object `v`
 */
export declare function accumulateDot<C extends Timestamp>(v: VV<C>, replicaId: string, timestamp: C): VV<C>;
/**
 * Sets one vector to the union of the two vectors: All elements, and the largest values of each.
 *
 * @param v version vector to update
 * @param u version vector to accumulate into v
 * @return the same object `v`
 */
export declare function accumulateUnion<C extends Timestamp>(v: VV<C>, u: VV<C>): VV<C>;
/**
 * For all elements from the second vector that individually dominate the first, remove
 * those elements from the first.
 *
 * @param v version vector to update
 * @param u version vector to remove out of v
 * @return the same object `v`
 */
export declare function accumulateSubtract<C extends Timestamp>(v: VV<C>, u: VV<C>): VV<C>;
/**
 * Sets one vector to the intersection of the two vectors: Only the shared elements, and the minimum timestamp of each.
 *
 * @param v version vector to update
 * @param u version vector to accumulate into v
 * @return the same object `v`
 */
export declare function accumulateIntersection<C extends Timestamp>(v: VV<C>, u: VV<C>): VV<C>;
/**
 * Compares two vectors. Finds equalty, dominance, or conflict.
 *
 * @param v the "left" version vector to compare
 * @param u the "right" version vector to compare
 * @return one of four possible results; see enum
 */
export declare function compare<C extends Timestamp>(v: VV<C>, u: VV<C>): CompareResult;
/**
 * Compares a vector with a dot. Finds equalty, dominance, or conflict.
 *
 * @param v the "left" version vector to compare
 * @param u the "right" version vector to compare
 * @return one of four possible results; see enum
 */
export declare function compareDot<C extends Timestamp>(v: VV<C>, dot: Dot<C>): CompareResult;
/**
 * True if the version vector dominates the dot, which means strict domination or equal.
 * Equivalent to when `compareDot()` is `LEFT_DOMINATES` or `EQUAL`, but is more efficient.
 */
export declare function dominatesDot<C extends Timestamp>(v: VV<C>, dot: Dot<C>): boolean;
/**
 * Compares two dots as timestamps, first based on time, then tie-breaking by replica ID.
 *
 * @returns `-1`, `0`, or `1` depending on whether a < b, a == b, or a > b respectively
 */
export declare function compareDotTimestamps<C extends Timestamp>(a: Dot<C>, b: Dot<C>): 1 | 0 | -1;
/**
 * Returns the largest dot (replica/timestamp pair) in the vector, ordered by time.
 */
export declare function largestDot<C extends Timestamp>(v: VV<C>): Dot<C>;