diff --git a/README.md b/README.md index 8c750e2..b5d0aaf 100644 --- a/README.md +++ b/README.md @@ -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)); diff --git a/TODO b/TODO deleted file mode 100644 index 12068af..0000000 --- a/TODO +++ /dev/null @@ -1,2 +0,0 @@ -do mod.ts again -examples \ No newline at end of file diff --git a/mod.ts b/mod.ts index 7a6a0e6..d764bd5 100644 --- a/mod.ts +++ b/mod.ts @@ -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); + * + * // 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, + * 'DEPLOYMENT_ID', + * ); + * ``` + * + * Even if a default is set, it can be overridden. + * + * ```ts + * client2.publishDeployment( + * {} as Deployment.POST.Request, + * '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 */ diff --git a/src/tpy.ts b/src/tpy.ts index f98a8ab..bf4e8b6 100644 --- a/src/tpy.ts +++ b/src/tpy.ts @@ -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; @@ -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; @@ -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, + 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( - new Context({ deploymentID: id }), - `/deployments/${id}`, + new Context({ deploymentID: dID }), + `/deployments/${dID}`, 'POST', { body: JSON.stringify(body), @@ -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; @@ -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}. */ @@ -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,