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

chessq

v0.3.1

Published

GraphQL API for the Universal Chess Interface

Downloads

4

Readme

chessQ, v0.3.0

build status

GraphQL API for Universal Chess Interface

This started as a mock API I wrote as a proof-of-concept for Chess.com. The implementation prooved difficult because the UCI protocol is stream-based, and not designed for a call-response type API that GraphQL provides. Nonetheless, this library represents a good progress. Ideas for further improvement can be found in the TODO.md file.

For this version, the implementation wraps an GraphQL API around an embedded stockfish engine (transpiled from original source to JavaScript).

Here are the package.json targets:

  • npm run start
    • starts the GraphQL server
  • npm run test
    • runs the unit tests
  • other run targets are:
    • dev
      • hot server which reloads on code changes
    • mock
      • for API testing; the engine id is fixed at 1 rather than generated randomly
    • test-api
      • GraphQL API tests; server must be run in mock mode (see previous)

The schema

I will assume some familiarity with GraphQL. When the server is launched (npm run start, for example), you will see:

🚀 Server ready at http://localhost:3001/graphql
🚀 Subscriptions ready at ws://localhost:3001/graphql

Subscriptions are a GraphQL feature that allows a client to subscribe to events that are emitted form the stockfish engine wrapper. As of this writing, most of the GraphQL API is call-response, however when running analysis, info strings (unparsed) are returned via subscription. Note that the url shown for subscriptions is for internal use only. See below.

Launching an engine and doing analysis

The tests in test-api, when run, are a good illustration of API interaction, including subscribing to info events. If you wish to use the GraphQL "playground", then point your browser to http://localhost:3001/graphql. Here are some commands to start with (mind the order of execution!):

get version

query v {version}

create an engine instance

query e {
  createEngine {
    engineId
    state
  }
}

initiate the UCI protocol

mutation u {
  Engine(id: "1") {
  	uci {
      identity {
        name
        author 
      }
      uciok
    }
  }
}

set [spin|button|check|combo] option

These sound line UI settings, but are really engine options of various types. See the UCI documentation for the various arguments are.

mutation o {
  Engine(id: "1") {
  	setSpinOption(name:"Contempt" value: 100) 
  }
}

Check if the engine is ready for analyzing

mutation r {
    Engine(id: "1") {
  	isready {
      response
    } 
  }
}

go

The go command returns the engine's evaluation of the best move for the current position

mutation g {
    Engine(id: "1") {
  	go {
			value
    } 
  }
}

go infinite

The engine will continue to evaluate the position until stopped. As it does so, it will emit info responses; you must be subscribed to these to receive them. In the GraphQL "playground", a subscription must be started in a separate browser tab (same url):

subscription s {
  info
}

and, in the other tab:

mutation gi {
    Engine(id: "1") {
  	goInfinite 
  }
}

To stop the analysis:

mutation st {
    Engine(id: "1") {
  	stop {
			value
    } 
  }
}

The value returned (eventually, the engine does not stop immediately) will be the best move.

quiting the engine

mutation q {
  Engine(id: "1") {
    quit
  }
}