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

@holochain-open-dev/cell-client

v0.9.1

Published

Temporary wrapper around @holochain/client and @holo-host/web-sdk

Downloads

20

Readme

Cell Client

Temporary wrapper around @holochain/client and @holo-host/web-sdk.

This is useful to build agnostic UIs, that can potentially connect both with Holo and with Holochain infrastructure transparently.

Note that this will only be useful until there is a unified API for both cases.

Installing

npm i @holochain-open-dev/cell-client

Setup

Connecting to Holochain

import { HolochainClient } from "@holochain-open-dev/cell-client";
import { RoleName, AppWebsocket } from "@holochain/client";

async function setupClient() {
  const appWebsocket = await AppWebsocket.connect(
    "ws://localhost:8888"
  );

  const client = new HolochainClient(appWebsocket);

  return client;
}

Connecting to Chaperone (Holo)

Follow the main instructions for the @holo-host/web-sdk here. Then, create a HoloClient:

import { HoloClient } from "@holochain-open-dev/cell-client";
import WebSdk from '@holo-host/web-sdk'

async function setupClient() {
  const client = await WebSdk.connect({
    chaperoneUrl: 'http://localhost:24274' // Connect to holo-dev-server
    authFormCustomization: {
      logoUrl: "my-logo.png",
      appName: "My App",
      requireRegistrationCode: false
    }
  });

  // We just started up, so we're still connecting. Let's wait for isAvailable == true
  const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
  while (!client.agent.isAvailable) {
    await sleep(50)
    // In a real UI, we would register an event handler for `client.on('agent-state')`
    // and store the agent state in a reactive UI state so that our components can just branch on isAvailable.
  }

  // WebSdk defaults to an anonymous connection where you can't write to the source chain. Sign in so we can commit something
  await client.signIn()
  
  // The credentials overlay is now visible to the user. Wait for them to sign in
  while (client.agent.isAnonymous || !client.agent.isAvailable) {
    await sleep(50)
    // Again, this while/sleep pattern is for demo only. See comment above about doing this using an event handler
  }

  const appInfo = await client.appInfo();

  return new HoloClient(client, appInfo);
}

Usage

There are two layers that you can use:

HolochainClient / HoloClient (both implement the AgnosticClient interface)

Use this layer if you need to be switching which cell you are making the call to. This is specially needed in apps that use the pattern of cloning cells.

const client: HolochainClient = await setupClient();

const appInfo = await client.appWebsocket.appInfo({
  installed_app_id: 'test-app'
});

// Find the cell you want to make the call to
const cellId = appInfo.cell_data[0].cell_id;

const response = await client.callZome(cellId, "my-zome", "my_fn_name", {
  this: "is a sample payload",
});

const { unsubscribe } = client.addSignalHandler((signal) =>
  console.log("Received signal from any of the cells", signal)
);

...

// You can unsubscribe from listening to the signal whenever needed
unsubscribe();

Here, use AgnosticClient instead of HolochainClient or HoloClient if you want your calls to be Holo/Holochain agnostic.

CellClient

Use this layer if you only have one cell, or predefined set of cells.

const client: HolochainClient = await setupClient();

const appInfo = await client.appWebsocket.appInfo({
  installed_app_id: 'test-app'
});

// Find the cell you want to make the call to
const cell = appInfo.cell_data[0];

const cellClient = new CellClient(client, cell);

// Now the calls and signals will only interact with the desired cell
const response = await cellClient.callZome("my-zome", "my_fn_name", {
  this: "is a sample payload",
});

const { unsubscribe } = client.addSignalHandler((signal) =>
  console.log(`Received signal for cell`, cell, signal)
);

...

// You can unsubscribe from listening to the signal whenever needed
unsubscribe();