Skip to main content
Deno 2 is finally here ๐ŸŽ‰๏ธ
Learn more
Module

x/tpy/mod.ts

๐Ÿ”‘ A strongly typed Pylon API client.
Latest
import * as tpy from "https://deno.land/x/tpy@v1.0.0-RC/mod.ts";

Tpy, a strongly typed Pylon API client.

Example Instantiation

Users can optionally bind a client to a specific deployment ID, this is used as default values for methods that take in that parameter.

const client = new Tpy({
  token: 'PYLON_TOKEN',
});
client.KV('NAMESPACE', 'DEPLOYMENT_ID');
client.getDeployment('DEPLOYMENT_ID');
client.publishDeployment(
  {} as Deployment.POST.Request<false>,
  'DEPLOYMENT_ID',
);

// or

const client = new Tpy({
  token: 'PYLON_TOKEN',
  deploymentID: 'DEPLOYMENT_ID',
});
client.KV('NAMESPACE');
client.getDeployment();
client.publishDeployment({} as Deployment.POST.Request<false>);

Even if a default deployment ID is set, it can be overridden.

client.publishDeployment(
  {} as Deployment.POST.Request<false>,
  'ANOTHER_DEPLOYMENT_ID',
);

fetch API in Node.js

As of Node.js 18+, the runtime has a native implementation of the WHATWG fetch specification. Tpy allows users to optionally use this feature via setting the useNodeFetch parameter to false inside instantiation. (True by default.)

For versions below, environments will require installing the node-fetch package for Tpy to make requests. By default, it uses this package.

const client = new Tpy({
  token: 'PYLON_TOKEN',
  useNodeFetch: false,
});

Namespaces

Request and response structures related to the /deployments resource.

Not an API resource, this namespace behaves as a set of templates and other base types.

Schemas for GET /deployments/*.

Schemas for POST /deployments/*.

Request and response structures related to the /guilds resource.

Schemas for GET /guilds.

Not an API resource, this namespace behaves as a set of templates and other base types.

Typings based on and related to the Pylon API/SDK interfaces, such as KV, WebSocket, SDK KV function options, and more.

Structures regarding Pylon KV operations.

Schemas for DELETE /deployments/:id/kv/namespaces/*.

Schemas for GET /deployments/:id/kv/namespaces/*.

Function options for operations matching HTTP methods. Inherited from the Pylon SDK.

Schemas for PUT /deployments/:id/kv/namespaces/*.

Structures regarding the Pylon WebSocket interface.

Request and response structures related to the /user resource.

Schemas for GET /user.

Response schema for GET /user/guilds.

Classes

Provides parameter context about the current execution environment to provide error reporting data to generate reports that include said information comprised inside the given Context.

The central entity for interacting with the Pylon API; the entrypoint.

The central entity for interacting with the Pylon API; the entrypoint.

An error wrapper of TpyErrors that provides specific context of the environment to explain why it was thrown.

A KVNamespace interface that (almost) matches the Pylon KVNamespace SDK class.

An EventEmitter forwarder that keeps an emitter alive while a WebSocket reconnects. Listens to a deployment's console output.

Enums

A deployment's 'up' status. Altered by Pylon administrators.

The type of deployment.

Variables

The set of errors returned by TpyError that describes a set of error names (keys) which consists of two values: a string description and a method message to create a human-friendly defintion with specific context information.

Interfaces

Operation options for deleting a key.

Operation options for retrieving keys.

Operation options for retrieving an array of keys and values.

Operation options for setting values in a KV namespace.

Type Aliases

The base structure of some deployment related responses.

Deployment configurations; recieved as a string.

Pylon uses FastAPI, this is a FastAPI error.

Detailed script information of a deployment.

Response schema for GET /deployments/:id.

Request schema for POST /deployments/:id.

Response schema for POST /deployments/:id.

Response schema for GET /guilds/:id.

Response schema for GET /guilds/:id/stats.

Base guild payload.

HTTP Verbs supported by the Pylon API.

Types parsable by ES5's JSON.parse function.

An array of types parsable by ES5's JSON.parse function.

Response schema for DELETE /deployments/:id/kv/namespaces/:namespace.

Response schema for GET /deployments/:id/kv/namespaces/:namespace/items.

Surfaces Items.

Response schema for GET /deployments/:id/kv/namespaces.

Response schema for PUT /deployments/:id/kv/namespaces/:namespace/items/:key.

The method of logging this was caused by. Follows the Console interface methods supported on the Pylon SDK.

A WebSocket Response from a workbench URL. Implementing a generic provides type sense for the data object.

Response schema for GET /user/guilds.

Response schema for GET /user/guilds/available.

Response schema for GET /user.