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

@karma.run/sdk

v0.7.0

Published

karma.run SDK

Downloads

22

Readme

@karma.run/sdk

License NPM Package

Install

npm install @karma.run/sdk` or `yarn add @karma.run/sdk

Usage

import {Remote} from '@karma.run/sdk'

import * as xpr from '@karma.run/sdk/expression'
import * as mdl from '@karma.run/sdk/model'
import * as val from '@karma.run/sdk/value'
import * as utl from '@karma.run/sdk/utility'

const remote = new Remote('http://localhost:8080/')

remote
  .login('admin', 'password')
  .then(async session => {
    console.log(session.toString())

    // Fetch tags
    const tags = await session.do(xpr.all(xpr.tag(utl.Tag.Tag)))
    console.log('Tags:', tags)

    // Create model
    const model = mdl.struct({
      foo: mdl.string,
      bar: mdl.int64
    })

    const modelResult = await session.do(utl.createModels({model}))
    console.log('Model result:', modelResult)

    // Decode value
    const value = {foo: '123', bar: 123}
    const valueResult = await session.do(
      xpr.create(xpr.data(d => d.ref(modelResult.model)), () =>
        xpr.data(model.decode(value).toDataConstructor())
      )
    )
    console.log('Value result:', valueResult)

    // Filter list of integers
    const data = xpr.data(d => d.list([d.int8(3), d.int8(2), d.int8(1)]))
    const filterResult = await session.do(
      xpr.filterList(data, (_index, value) => xpr.gtInt8(value, xpr.int8(2)))
    )
    console.log('Filter Result:', filterResult)
  })
  .catch(err => {
    console.error(err.toString())
  })

Concepts

Values

There are 21 classes that implement the Value interface. They are the JS/TS representation of karma.data values:

Bool, DateTime, Float, Int16, Int32, Int64, Int8, List, Map, Null, Ref, Set, String, Struct, Symbol, Tuple, Uint16, Uint32, Uint64, Uint8, Union

Each Value class has a corresponding constructor on the package top-level, having the same name as the class but with a lower-case first letter. For example a Uint64 can be constructed calling the constructor function named uint64.

As a special case, because null is a reserved keyword in JS, we export a package-level name nil assigned to an instance of val.Null for convenience.

All Value classes implement two methods: toJSON() and toDataConstructor().

toJSON

As you may know, a call to JSON.stringify(o) with an object o that has a toJSON() method will first call that method to delegate serialization.

This method transforms a Value object into the JSON-structure expected by karma.data's json codec.

toDataConstructor

The method toDataConstructor returns a DataConstructor expression, which can be wrapped in a call to xpr.data to embed static data in an expression.

Expressions

There are hundreds of expression classes with corresponding convenience constructors, just as with Values. These classes all extend the abstract class Expression. For example, there is an All class, which can be constructed using the all convenience constructor.

In addition, expressions can be constructed by chaining. Every expression has methods corresponding to the constructors with a given first expresison argument. For example xpr.tag("_tag").all() is equivalent to xpr.all(xpr.tag("_tag")).

All Expression classes implement the method toValue() that returns a Value object. This is the value-representation of an expression, which can be JSON-encoded to send over the wire in karma.data's json codec.

Models

There are 26 Model classes: Recursion, Annotation, Optional, Unique, Tuple, List, Union, Any, Struct, Map, Float, Bool, String, Ref, DateTime, Enum, Set, Int8, Int16, Int32, Int64, Uint8, Uint16, Uint32, Uint64, Null.

All Model classes implement two methods: decode(json : any) and toValue(), both returning Value objects.

decode

This method takes a wire-representation of karma.data's json codec and converts it into a Value objects, interpreting the data according to the given Model.

toValue

This method transforms a Model object into its' Value object representation. From there, it can be converted into a data constructor or JSON.