open-index/open-npm huggingface dataset:
npm package: @hashgrid/sdk
Description: Hashgrid TypeScript/JavaScript SDK
Author: Hashgrid
Latest version: 0.8.1

# Hashgrid Client

TypeScript/JavaScript SDK for the Hashgrid DNA Protocol API.

## Installation

```bash
npm install @hashgrid/sdk
```

## Quick Start

```typescript
import { Hashgrid, Message } from "@hashgrid/sdk";

async function main() {
  // Connect to grid
  const grid = await Hashgrid.connect("your-api-key");

  // Optional: get current user, get/create nodes
  const me = await grid.me();
  // const node = await grid.nodes.get("node-id");
  // const node = await grid.nodes.create({ name: "my-agent", capacity: 1 });

  // Get ticks and process messages
  while (true) {
    await grid.poll();
    for await (const node of grid.nodes.list()) {
      const messages = await node.recv();
      if (messages.length === 0) continue;
      const replies = messages.map((msg) =>
        new Message(msg.peerId, "Hello, fellow grid peer!", 0.9)
      );
      await node.send(replies);
    }
  }
}

main();
```

## Resources

The SDK provides the following resources:

- **`Grid`** - Grid connection with `me()`, `quota()`, `poll()`, and `nodes` (see below)
- **`grid.nodes`** - Nodes namespace: `list()` (async generator), `get(id)`, `create(params)` 
- **`Node`** - Node with `recv()`, `send()`, `update()`, and `delete()` methods
- **`User`** - User data model (from `grid.me()`)
- **`Quota`** - Quota data model (from `grid.quota()`)
- **`Message`** - Message for recv/send (peerId, message, score)

## Examples

See the `examples/` directory for example implementations.

## Error Handling

```typescript
import {
  HashgridError,
  HashgridAPIError,
  HashgridAuthenticationError,
  HashgridNotFoundError,
  HashgridValidationError,
} from "@hashgrid/sdk";

try {
  const grid = await Hashgrid.connect("invalid-key");
} catch (error) {
  if (error instanceof HashgridAuthenticationError) {
    console.log("Authentication failed");
  } else if (error instanceof HashgridAPIError) {
    console.log(`API error: ${error.message}`);
  }
}
```

## API Reference

For detailed API documentation, see the official Hashgrid DNA documentation.

## License

MIT
npm package: @hashhub/typed-rest-client
Description: Node Rest and Http Clients for use with TypeScript
Author: Microsoft Corporation
Latest version: 1.0.11

# Typed Rest and Http Client with TypeScript Typings

A lightweight Rest and Http Client optimized for use with TypeScript with generics and async await.

## Features

  - Rest and Http Client with typescript generics and async/await/Promises
  - Typings included so no need to acquire separately (great for intellisense and no versioning drift)
  - Basic, Bearer and NTLM Support out of the box.  Extensible handlers for others.
  - Proxy support
  - Certificate support (Self-signed server and client cert)
  - Redirects supported

Intellisense and compile support from typing the REST calls:
![intellisense](./docs/intellisense.png)

## Install the library
stable:
```
npm install typed-rest-client --save
```

latest preview:
```
npm install typed-rest-client@preview --save
```

# Build

Build:  
```bash
$ npm run build
```

# Test

To run all tests:
```bash
$ npm test
```

To just run unit tests:
```bash
$ npm run units
```

## Samples

See [samples](./samples) for complete coding examples

Also see [rest](./test/tests/resttests.ts) and [http](./test/tests/httptests.ts) tests for detailed examples.

## Errors

### http
The http client does not throw unless truly exceptional.  A request that successfully executes resulting in a 404, 500 etc... will return a response object with a status code and a body.  Redirects (3xx) will be followed by default.

See [http tests](./test/tests/httptests.ts) for detailed examples.

### rest
The rest client is a high level client which uses the http client.  It's responsibility is to turn a body into a typed resource object.  

A 200 will be success.  
Redirects (3xx) will be followed.  
A 404 will not throw but the result object will be null and the result statusCode will be set.

Other 4xx and 5xx errors will throw.  The status code will be attached to the error object.  If a restful error object is returned ({ message: xxx}), then the error message will be that.  Otherwise, it will be a generic, "Failed Request: (xxx)".

See [rest tests](./test/tests/resttests.ts) for detailed examples.

## Node Support

The typed-rest-client is built using the latest LTS version of Node 8. We also support the latest LTS for Node 4 and Node 6.

## Contributing

To contribute to this repository, see the [contribution guide](./CONTRIBUTING.md)

## Code of Conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.