Skip to content

Commit

Permalink
deployment id docs/param move, mod.ts/readme docs
Browse files Browse the repository at this point in the history
  • Loading branch information
insyri committed Oct 19, 2022
1 parent cd1f2c4 commit 1f25477
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ console.log(

```ts
const client = new Tpy('PYLON_TOKEN');
const kvnamespace = 'tags';
const kvnamespace = 'NAMESPACE';
const kv = client.KV(
kvnamespace,
(await client.getDeploymentfromGuild('GUILD_ID')).id,
);

const key = '';
const key = 'cool_lang';

console.log(`Value of key "${key}":`, await kv.get(key));

Expand Down
2 changes: 0 additions & 2 deletions TODO

This file was deleted.

37 changes: 30 additions & 7 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
/**
* A strongly typed Pylon API client.
* Tpy, a strongly typed Pylon API client.
*
* The center of Tpy starts at the default {@linkcode Tpy} class,
* defining the Pylon token and optionally a global deployment ID.
*
* ```ts
* const client = new Tpy(Deno.env.get('PYLON_TOKEN')!, 'DEPLOYMENT_ID');
* client.KV('NAMESPACE');
* client.getDeployment();
* client.publishDeployment({} as Deployment.POST.Request<false>);
*
* // or
*
* const client2 = new Tpy(Deno.env.get('PYLON_TOKEN')!);
* client2.KV('NAMESPACE', 'DEPLOYMENT_ID');
* client2.getDeployment('DEPLOYMENT_ID');
* client2.publishDeployment(
* {} as Deployment.POST.Request<false>,
* 'DEPLOYMENT_ID',
* );
* ```
*
* Even if a default is set, it can be overridden.
*
* ```ts
* client2.publishDeployment(
* {} as Deployment.POST.Request<false>,
* 'ANOTHER_DEPLOYMENT_ID',
* );
* ```
*
* Tpy works on all JavaScript runtimes, including Node.js.
* (See {@link README.md README.md} for the NPM link.)
* As it's only dependencies are type-based and rather small,
* Tpy is extremely portable and easy to look through.
* These parts that make up Tpy are components that are
* specific to their functional use; Tpy is modular.
* @module
*/

Expand Down
39 changes: 27 additions & 12 deletions src/tpy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Context from './context.ts';
*/
export default class Tpy {
/**
* The specified deployment ID used for deployment ID entries as a default.
* A default deployment ID used to occupy `deploymentID` parameter entries.
*/
readonly deploymentID?: StringifiedNumber;
private readonly token: string;
Expand Down Expand Up @@ -95,7 +95,7 @@ export default class Tpy {
* Gets the deployment information.
*
* @param deploymentID The ID of the deployment to get. If empty, the function
* will use the set deploymentID in the class. (`this.deploymentID`)
* will use the set {@linkcode Tpy.deploymentID} in the class.
*/
async getDeployment(deploymentID?: StringifiedNumber) {
const dID = deploymentID || this.deploymentID;
Expand All @@ -120,16 +120,27 @@ export default class Tpy {
* Makes a POST request to publish a deployment; returns details
* of the new deployment.
*
* @param id The script/deployment ID to publish to.
* @param deploymentID The script/deployment ID to publish to. If empty, the function
* will use the set {@linkcode Tpy.deploymentID} in the class.
* @param body Project specifications.
*/
async publishDeployment(
id: StringifiedNumber,
body: Deployment.POST.Request<false>,
deploymentID?: StringifiedNumber,
) {
const dID = deploymentID || this.deploymentID;
if (!(dID)) {
throw new TpyError(
'Missing or Invalid Required Parameter',
parametersPrompt('missing', ['deploymentID', 'this.deploymentID']),
['deploymentID', 'this.deploymentID'].join(', '),
dID,
);
}

return await this.httpRaw<Deployment.POST.Response>(
new Context({ deploymentID: id }),
`/deployments/${id}`,
new Context({ deploymentID: dID }),
`/deployments/${dID}`,
'POST',
{
body: JSON.stringify(body),
Expand Down Expand Up @@ -165,15 +176,17 @@ export default class Tpy {
/**
* Connects to the Pylon workbench WebSocket.
*
* @param id The deployment ID to follow the WebSocket when it disconnects.
* @param deploymentID The deployment ID to follow the WebSocket when it disconnects. If empty, the function
* will use the set {@linkcode Tpy.deploymentID} in the class.
*/
connectSocket(id: StringifiedNumber) {
return new TpyWs(this, id);
connectSocket(deploymentID: StringifiedNumber) {
return new TpyWs(this, deploymentID);
}

/**
* Gets all the namespaces under the given deployment ID.
* @param deploymentID The deployment ID to look under.
* @param deploymentID The deployment ID to look under. If empty, the function
* will use the set {@linkcode Tpy.deploymentID} in the class.
*/
async getNamespaces(deploymentID?: StringifiedNumber) {
const dID = deploymentID || this.deploymentID;
Expand All @@ -193,8 +206,9 @@ export default class Tpy {

/**
* Gets all the namespace items under the given deployment ID.
* @param deploymentID The deployment ID to look under.
* @param namespace The namespace to look under.
* @param deploymentID The deployment ID to look under. If empty, the function
* will use the set {@linkcode Tpy.deploymentID} in the class.
*
* @template T The type of the `value` object inside {@linkcode Pylon.KV.GET.ItemsFlattened}.
*/
Expand Down Expand Up @@ -238,8 +252,9 @@ export default class Tpy {

/**
* Creates a new {@link TpyKV} instantiation, much like the Pylon SDK's KVNamespace class.
* @param deploymentID The deployment ID to look under.
* @param namespace The namespace to look under.
* @param deploymentID The deployment ID to look under. If empty, the function
* will use the set {@linkcode Tpy.deploymentID} in the class.
*/
KV(
namespace: string,
Expand Down

0 comments on commit 1f25477

Please sign in to comment.