Skip to content

Commit 1f25477

Browse files
committed
deployment id docs/param move, mod.ts/readme docs
1 parent cd1f2c4 commit 1f25477

File tree

4 files changed

+59
-23
lines changed

4 files changed

+59
-23
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ console.log(
138138

139139
```ts
140140
const client = new Tpy('PYLON_TOKEN');
141-
const kvnamespace = 'tags';
141+
const kvnamespace = 'NAMESPACE';
142142
const kv = client.KV(
143143
kvnamespace,
144144
(await client.getDeploymentfromGuild('GUILD_ID')).id,
145145
);
146146

147-
const key = '';
147+
const key = 'cool_lang';
148148

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

TODO

Lines changed: 0 additions & 2 deletions
This file was deleted.

mod.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
/**
2-
* A strongly typed Pylon API client.
2+
* Tpy, a strongly typed Pylon API client.
3+
*
4+
* The center of Tpy starts at the default {@linkcode Tpy} class,
5+
* defining the Pylon token and optionally a global deployment ID.
6+
*
7+
* ```ts
8+
* const client = new Tpy(Deno.env.get('PYLON_TOKEN')!, 'DEPLOYMENT_ID');
9+
* client.KV('NAMESPACE');
10+
* client.getDeployment();
11+
* client.publishDeployment({} as Deployment.POST.Request<false>);
12+
*
13+
* // or
14+
*
15+
* const client2 = new Tpy(Deno.env.get('PYLON_TOKEN')!);
16+
* client2.KV('NAMESPACE', 'DEPLOYMENT_ID');
17+
* client2.getDeployment('DEPLOYMENT_ID');
18+
* client2.publishDeployment(
19+
* {} as Deployment.POST.Request<false>,
20+
* 'DEPLOYMENT_ID',
21+
* );
22+
* ```
23+
*
24+
* Even if a default is set, it can be overridden.
25+
*
26+
* ```ts
27+
* client2.publishDeployment(
28+
* {} as Deployment.POST.Request<false>,
29+
* 'ANOTHER_DEPLOYMENT_ID',
30+
* );
31+
* ```
332
*
4-
* Tpy works on all JavaScript runtimes, including Node.js.
5-
* (See {@link README.md README.md} for the NPM link.)
6-
* As it's only dependencies are type-based and rather small,
7-
* Tpy is extremely portable and easy to look through.
8-
* These parts that make up Tpy are components that are
9-
* specific to their functional use; Tpy is modular.
1033
* @module
1134
*/
1235

src/tpy.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Context from './context.ts';
1717
*/
1818
export default class Tpy {
1919
/**
20-
* The specified deployment ID used for deployment ID entries as a default.
20+
* A default deployment ID used to occupy `deploymentID` parameter entries.
2121
*/
2222
readonly deploymentID?: StringifiedNumber;
2323
private readonly token: string;
@@ -95,7 +95,7 @@ export default class Tpy {
9595
* Gets the deployment information.
9696
*
9797
* @param deploymentID The ID of the deployment to get. If empty, the function
98-
* will use the set deploymentID in the class. (`this.deploymentID`)
98+
* will use the set {@linkcode Tpy.deploymentID} in the class.
9999
*/
100100
async getDeployment(deploymentID?: StringifiedNumber) {
101101
const dID = deploymentID || this.deploymentID;
@@ -120,16 +120,27 @@ export default class Tpy {
120120
* Makes a POST request to publish a deployment; returns details
121121
* of the new deployment.
122122
*
123-
* @param id The script/deployment ID to publish to.
123+
* @param deploymentID The script/deployment ID to publish to. If empty, the function
124+
* will use the set {@linkcode Tpy.deploymentID} in the class.
124125
* @param body Project specifications.
125126
*/
126127
async publishDeployment(
127-
id: StringifiedNumber,
128128
body: Deployment.POST.Request<false>,
129+
deploymentID?: StringifiedNumber,
129130
) {
131+
const dID = deploymentID || this.deploymentID;
132+
if (!(dID)) {
133+
throw new TpyError(
134+
'Missing or Invalid Required Parameter',
135+
parametersPrompt('missing', ['deploymentID', 'this.deploymentID']),
136+
['deploymentID', 'this.deploymentID'].join(', '),
137+
dID,
138+
);
139+
}
140+
130141
return await this.httpRaw<Deployment.POST.Response>(
131-
new Context({ deploymentID: id }),
132-
`/deployments/${id}`,
142+
new Context({ deploymentID: dID }),
143+
`/deployments/${dID}`,
133144
'POST',
134145
{
135146
body: JSON.stringify(body),
@@ -165,15 +176,17 @@ export default class Tpy {
165176
/**
166177
* Connects to the Pylon workbench WebSocket.
167178
*
168-
* @param id The deployment ID to follow the WebSocket when it disconnects.
179+
* @param deploymentID The deployment ID to follow the WebSocket when it disconnects. If empty, the function
180+
* will use the set {@linkcode Tpy.deploymentID} in the class.
169181
*/
170-
connectSocket(id: StringifiedNumber) {
171-
return new TpyWs(this, id);
182+
connectSocket(deploymentID: StringifiedNumber) {
183+
return new TpyWs(this, deploymentID);
172184
}
173185

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

194207
/**
195208
* Gets all the namespace items under the given deployment ID.
196-
* @param deploymentID The deployment ID to look under.
197209
* @param namespace The namespace to look under.
210+
* @param deploymentID The deployment ID to look under. If empty, the function
211+
* will use the set {@linkcode Tpy.deploymentID} in the class.
198212
*
199213
* @template T The type of the `value` object inside {@linkcode Pylon.KV.GET.ItemsFlattened}.
200214
*/
@@ -238,8 +252,9 @@ export default class Tpy {
238252

239253
/**
240254
* Creates a new {@link TpyKV} instantiation, much like the Pylon SDK's KVNamespace class.
241-
* @param deploymentID The deployment ID to look under.
242255
* @param namespace The namespace to look under.
256+
* @param deploymentID The deployment ID to look under. If empty, the function
257+
* will use the set {@linkcode Tpy.deploymentID} in the class.
243258
*/
244259
KV(
245260
namespace: string,

0 commit comments

Comments
 (0)