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

@strategies/speckle

v3.0.1

Published

Speckle API client

Downloads

3

Readme

@strategies/speckle

A TypeScript client for Speckle's API. The client was designed with a node ref pattern, allowing you to build references to data nodes in the API and only resolve them when they are needed.

Install

yarn add @strategies/speckle

Usage

Setup

You start by creating your client:

import { Speckle } from '@strategies/speckle';

const api = new Speckle({
	server: 'https://speckle.domain.com' // defaults to https://speckle.xyz
	token: 'geasgweagenwlenlaksegnelw'   // optional, unless private
});

Reading Data

From the root object, you can resolve streams:

const streams = await api.streams;

Once you know the id of the stream you want, you can create a reference to it:

const stream = api.Stream('dgaease');

The client uses a node ref pattern where you create reference objects that map onto the identifiable API nodes. When you created the stream above, you didn't load anything from the API yet; you have created only a reference to that node. Now that you have a reference, you can carry it around in your application until you need it, allowing you to start mapping out the API dependencies for each component in your app.

Once you need data from a reference, you can resolve it:

let streamData = await stream.get;

This will return data about the stream you have referenced. Once resolved, it will remain cached so that await stream.get will resolve immediately the next times it is called. If you need to refresh the cached data:

streamData = await stream.refresh();

Other information you can read regarding the stream are:

const branches = await stream.branches;
const collaborates = await stream.collaborators;

Other nodes you can access from the stream are:

const commit = stream.Commit('geagweweffasdf');
const obj = stream.Object('geadsnewkensd');

Writing Data

Now that you have your references, we can send data back from our application into the Speckle API. Let's say we have some data:

const speckleObj = {
	id: 'geadsnewkensd',
	speckle_type: 'base',
	x: 0,
	y: 10,
	z: -5,
};

We can send that:

await obj.write(speckleObj);

We can commit that:

await stream.commit(
	obj, 
	"We're doing it!", // message, optional
	"main"             // branch, defaults to "main"
);

And we could do it all at once:

await stream.writeAndCommitObject(speckleObj, "We're doing it!", "main");

URL

Every SpeckleNode has a .url getter which will provide the URL for that node in the API:

(new Speckle()).Stream('abcdefg').Object('hijklmn').url                                     // https://speckle.xyz/streams/abcdefg/objects/hijklmn
(new Speckle({ server: 'https://speckle.me.com' })).Stream('opqrstu').Commit('vwxyzab').url // https://speckle.me.com/streams/opqrstu/commits/vwxyzab

Chainable and/or Composable

The goal of this client was to not just create methods that map directly onto the API endpoints, as many clients do, but to provide reference objects that can be easily passed around in your application. This allows you to write data more generically without having to worry about passing in all of the variables necessary to compose a nice long query each time. How this is organized is through the hierarchy of the API (e.g. an object node requires a stream node).

To instantiate this hierarchy in your app, you have two ways of doing so:

Chaining

const objData = await (new Speckle()).Stream('aafeasf').Object('dgeadse').get;

Composing

const { SpeckleStream, SpeckleObject } from '@strategies/speckle';

const objData = await (new SpeckleObject('dgeadse', new SpeckleStream('aafeasf', new Speckle()))).get;

Collaborating

All collaborators welcome! Either submit issues or pull requests, or contact [email protected].

License

MIT