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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gesslar/negotiator

v0.1.0

Published

Schema validation, terms, and contracts. Avada Schemata!

Readme

@gesslar/negotiator

Welcome to the wonderful world of SCHEMA VALIDATION and CONTRACT NEGOTIATION and... uhmm TERMS ARTICULATION!

That sounded impressive.

Installation

# npm
npm i -D @gesslar/negotiator

# pnpm
pnpm i -D @gesslar/negotiator

# yarn
yarn add -D @gesslar/negotiator

# bun
bun add -d @gesslar/negotiator

# cinnabon
cinna bon -yum @gesslar/negotiator

Usage

Negotiator is environment aware and automatically detects whether it is being used in a web browser or in Node.js. You can optionally specify the node or browser variant explicitly.

Browser

esm.sh (recommended for CDN usage)

esm.sh automatically resolves npm dependencies, so no additional setup is needed:

<script type="module">
  import {Schemer, Terms, Contract} from 'https://esm.sh/@gesslar/negotiator'
</script>

For TypeScript editor support, use the ?dts parameter:

https://esm.sh/@gesslar/negotiator?dts

Alternatively, install the package locally for development to get full TypeScript support.

Node.js

import * as N from "@gesslar/negotiator"
import {Contract, Schemer, Terms} from "@gesslar/negotiator"
import {Schemer} from "@gesslar/negotiator/node"
import {Contract, Schemer, Terms as SideshowBob} from '@gesslar/negotiator/browser'

Examples

Schemer: Schema Validation

Create validators from JSON Schema objects:

import {Schemer} from "@gesslar/negotiator"

// Create a validator from a schema
const userSchema = {
  type: "object",
  properties: {
    name: {type: "string"},
    age: {type: "number"},
    email: {type: "string"}
  },
  required: ["name", "email"]
}

const validator = await Schemer.from(userSchema)

// Validate data
const validUser = {name: "Alice", email: "[email protected]", age: 30}
validator(validUser) // true

// Check errors if validation fails
const invalidUser = {name: "Bob"} // missing email
if (!validator(invalidUser)) {
  const errors = Schemer.reportValidationErrors(validator.errors)
  console.log(errors)
}

Load schemas from URLs (browser) or files (Node.js):

// Browser: Load from URL
const validator = await Schemer.fromUrl(new URL("https://example.com/schema.json"))

// Node.js: Load from file
import {FileObject} from "@gesslar/toolkit"
const file = new FileObject("schema.json", directoryObject)
const validator = await Schemer.fromFile(file)

Terms: Define Data Contracts

Create terms definitions to describe what you provide or accept:

import {Terms} from "@gesslar/negotiator"

// Provider terms: what you offer
const providerTerms = new Terms({
  provides: {
    user: {
      dataType: "object",
      required: true,
      contains: {
        id: {dataType: "string", required: true},
        name: {dataType: "string", required: true},
        email: {dataType: "string", required: true}
      }
    }
  }
})

// Consumer terms: what you need
const consumerTerms = new Terms({
  accepts: {
    user: {
      dataType: "object",
      required: true,
      contains: {
        id: {dataType: "string", required: true},
        name: {dataType: "string", required: true}
      }
    }
  }
})

Parse terms from JSON or YAML:

// From JSON string
const jsonTerms = `{
  "accepts": {
    "config": {
      "dataType": "object",
      "required": true
    }
  }
}`
const terms = new Terms(await Terms.parse(jsonTerms))

// From YAML string
const yamlTerms = `
provides:
  data:
    dataType: array
    required: true
`
const yamlTermsObj = new Terms(await Terms.parse(yamlTerms))

Contract: Negotiate Compatibility

Negotiate contracts between providers and consumers:

import {Contract, Terms} from "@gesslar/negotiator"

const provider = new Terms({
  provides: {
    user: {
      dataType: "object",
      required: true,
      contains: {
        id: {dataType: "string", required: true},
        name: {dataType: "string", required: true},
        email: {dataType: "string", required: true}
      }
    }
  }
})

const consumer = new Terms({
  accepts: {
    user: {
      dataType: "object",
      required: true,
      contains: {
        id: {dataType: "string", required: true},
        name: {dataType: "string", required: true}
      }
    }
  }
})

// Negotiate contract
try {
  const contract = new Contract(provider, consumer)
  console.log(contract.isNegotiated) // true
} catch (error) {
  console.error("Negotiation failed:", error.message)
}

Contracts fail when requirements aren't met:

// Provider doesn't have required field
const insufficientProvider = new Terms({
  provides: {
    user: {
      dataType: "object",
      required: true,
      contains: {
        name: {dataType: "string", required: true}
        // Missing 'id' that consumer requires
      }
    }
  }
})

const contract = new Contract(insufficientProvider, consumer)
// Throws: "Contract negotiation failed: Provider missing required capability: id"

Real-World Example: Plugin System

import {Contract, Terms, Schemer} from "@gesslar/negotiator"

// Plugin defines what it provides
const pluginTerms = new Terms({
  provides: {
    forecast: {
      dataType: "object",
      required: true,
      contains: {
        temperature: {dataType: "number", required: true},
        condition: {dataType: "string", required: true}
      }
    }
  }
})

// App defines what it accepts
const appTerms = new Terms({
  accepts: {
    forecast: {
      dataType: "object",
      required: true,
      contains: {
        temperature: {dataType: "number", required: true}
      }
    }
  }
})

// Negotiate compatibility
const contract = new Contract(pluginTerms, appTerms)

// Validate plugin data at runtime
const validator = await Schemer.from({
  type: "object",
  properties: {
    forecast: {
      type: "object",
      properties: {
        temperature: {type: "number"},
        condition: {type: "string"}
      },
      required: ["temperature", "condition"]
    }
  },
  required: ["forecast"]
})

const pluginData = {
  forecast: {temperature: 72, condition: "Sunny"}
}

validator(pluginData) // true

Are they gone yet? That ... is some dry topic, for sure. Who writes a contract negotiation schema validation terms thingamajig anyway.

uggghhhh

Anyway, so as I say, you ...

Oh. Someone's still here. Okay. clears throat

This module has been brought to you today by the letters, F, and U. And by the number 87.

Also, all of my code here is under the Unlicense because seriously, and I cannot stress this enough, absolutely nothing in this is worth protecting. If anything, it could maybe use a nap, or, what's the opposite of a nap... uhhhhh karaoke?

bye

Post-it Note

“Negotiator lets independent systems prove they’re compatible before exchanging data.”

^ ChatGPT said I should put that there because something about being the anchor? But it also said to put it at the top and that's not how anchors work, ChatGPT.