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

cloudstate-darwin-x64

v0.1.1-43

Published

<h1 align="center">Cloudstate</h1>

Downloads

69

Readme

THIS IS A DEPENDENCY OF freestyle-sh AND SHOULD NOT BE USED DIRECTLY

Cloudstate is a JavaScript database runtime. It is a foundational component of Freestyle's full stack JavaScript hosting.

[!TIP] Try out cloudstate via a freestyle template. Read our getting started guide to learn more.

If you're interested in learning more about how cloudstate works behind the scenes, read on.

You can install the cloudstate cli alongside the freestyle cli. Run npm install -g freestyle-sh@beta or you can build it from source.

cloudstate run ./script.js

The lowest level way to store data in cloudstate is via the cloudstate run command. You can use the global setRoot function with an id and object to store data.

const object = {
  counter: 0,
};

setRoot("test-root", object);

To retrieve an object from the database, call getRoot and pass in the identifier you used to store the object.

const object = getRoot("test-root");

If you have multiple references to the same object, those references will be preserved. The values of each property are also lazy loaded, so you don't need to worry about the complexity of objects stored in a single setRoot call.

const obj = {};
const objects = {
  a: obj,
  b: obj,
};

setRoot("objects", objects);
const objects = getRoot("objects");
objects.a === objects.b; // true

cloudstate serve ./script.js

A more structured way to store data in cloudstate is via the cloudstate serve command. Instead of writing what the script should execute, you write classes. When you put a static id on a class, it will be automatically constructed and stored using setRoot for you. Methods will be exposed as endpoints which you can call via http.

export class CounterCS {
  static id = "counter";
  count = 0;

  increment() {
    return ++this.count;
  }
}
curl -X POST http://localhost:3000/cloudstate/instances/counter/increment -H "Content-Type: application/json" -d '{"params": []}'

npx freestyle dev

The highest level api is built into freestyle's dev tooling. You can define classes anywhere in a full stack project using a decorator and they be automatically compiled into a single file and served.

import { cloudstate } from "freestyle-sh";

@cloudstate
class CounterCS {
  static id = "counter";
  count = 0;

  increment() {
    return ++this.count;
  }
}

Then you can easily query that data using useCloud.

import { type CounterCS } from "./schema.js";
import { useCloud } from "freestyle-sh";

const counter = useCloud<typeof CounterCS>("counter");

await counter.increment();

To learn more read the freestyle docs.

Contributing

Building Locally

Support for JavaScript Objects