From 19b8e53440b34c5be7dd2bab8c9ea7bb5b096a33 Mon Sep 17 00:00:00 2001 From: insyri <60794909+insyri@users.noreply.github.com> Date: Fri, 2 Dec 2022 22:48:42 -0500 Subject: [PATCH] ' -> " and fixes #16 --- README.md | 34 +++++------ deno.jsonc | 2 +- mod.ts | 20 +++---- node-transform.ps1 | 3 +- src/context.ts | 4 +- src/error.ts | 46 +++++++-------- src/kv.ts | 40 ++++++------- src/tpy.ts | 116 +++++++++++++++++++------------------- src/types/deployment.d.ts | 10 ++-- src/types/guild.d.ts | 8 +-- src/types/pylon.d.ts | 4 +- src/types/user.d.ts | 4 +- src/ws.ts | 50 ++++++++-------- 13 files changed, 171 insertions(+), 170 deletions(-) diff --git a/README.md b/README.md index 1cfed21..1b53113 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ download the type dependencies locally. #### Get the token's matching user. ```ts -const client = new Tpy({ token: 'PYLON_TOKEN' }); +const client = new Tpy({ token: "PYLON_TOKEN" }); const { displayName, id } = await client.getUser(); console.log(`Logged in as ${displayName} (<@${id}>).`); @@ -69,7 +69,7 @@ await ws.connect(); With the following Pylon code: ```ts -discord.on('MESSAGE_CREATE', async (message) => { +discord.on("MESSAGE_CREATE", async (message) => { console.log( // string message.author.username, @@ -84,8 +84,8 @@ discord.on('MESSAGE_CREATE', async (message) => { #### Get a guild's statistics. ```ts -const client = new Tpy({ token: 'PYLON_TOKEN' }); -const guildStats = await client.getGuildStats('GUILD_ID'); +const client = new Tpy({ token: "PYLON_TOKEN" }); +const guildStats = await client.getGuildStats("GUILD_ID"); const mostRecent = guildStats.find((e) => e.date === Math.min(...guildStats.map((e) => e.date)) )!; @@ -101,8 +101,8 @@ console.log( ```ts const client = new Tpy({ - token: 'PYLON_TOKEN', - deploymentID: 'DEPLOYMENT_ID', + token: "PYLON_TOKEN", + deploymentID: "DEPLOYMENT_ID", }); const { config } = await client.getDeployment(); const { cronTasks } = config.tasks; @@ -113,19 +113,19 @@ const cronTasksFormatted = cronTasks.map(({ cronString, name }) => console.log( `Listening to ${events.length} discord event(s): - ${events.join(', ')}\n`, - `Running ${cronTasks.length} cron job(s):\n${cronTasksFormatted.join('\n')}`, + ${events.join(", ")}\n`, + `Running ${cronTasks.length} cron job(s):\n${cronTasksFormatted.join("\n")}`, ); ``` #### Get the keys in a KV namespace. ```ts -const client = new Tpy({ token: 'PYLON_TOKEN' }); -const kvnamespace = 'tags'; +const client = new Tpy({ token: "PYLON_TOKEN" }); +const kvnamespace = "tags"; const kv = client.KV( kvnamespace, - await client.getDeploymentIDfromGuild('GUILD_ID'), + await client.getDeploymentIDfromGuild("GUILD_ID"), ); const keys = await kv.list({ limit: 10 }); @@ -133,25 +133,25 @@ const amountOfKeys = await kv.count(); console.log( `There are ${amountOfKeys} key(s) within the ${kvnamespace} KV namespace, these are the first 10 (or less). - ${keys.join(', ')}`, + ${keys.join(", ")}`, ); ``` #### Get and modify values within a KV namespace. ```ts -const client = new Tpy({ token: 'PYLON_TOKEN' }); -const kvnamespace = 'NAMESPACE'; +const client = new Tpy({ token: "PYLON_TOKEN" }); +const kvnamespace = "NAMESPACE"; const kv = client.KV( kvnamespace, - await client.getDeploymentIDfromGuild('GUILD_ID'), + await client.getDeploymentIDfromGuild("GUILD_ID"), ); -const key = 'cool_lang'; +const key = "cool_lang"; console.log(`Value of key "${key}":`, await kv.get(key)); -await kv.put(key, 'rust'); +await kv.put(key, "rust"); console.log(`Value of key "${key}":`, await kv.get(key)); await kv.delete(key); diff --git a/deno.jsonc b/deno.jsonc index 753793c..b86d842 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -12,7 +12,7 @@ }, "fmt": { "options": { - "singleQuote": true, + "singleQuote": false, "useTabs": false, "indentWidth": 2, "lineWidth": 80 diff --git a/mod.ts b/mod.ts index 3b83818..d20c24c 100644 --- a/mod.ts +++ b/mod.ts @@ -60,17 +60,17 @@ // Used for docs. // deno-lint-ignore no-unused-vars -import { type Tpy } from './src/tpy.ts'; +import { type Tpy } from "./src/tpy.ts"; -export { Tpy as default } from './src/tpy.ts'; -export { TpyWs } from './src/ws.ts'; -export { TpyKV } from './src/kv.ts'; -export { TpyError, TpyErrors } from './src/error.ts'; -export { Context } from './src/context.ts'; +export { Tpy as default } from "./src/tpy.ts"; +export { TpyWs } from "./src/ws.ts"; +export { TpyKV } from "./src/kv.ts"; +export { TpyError, TpyErrors } from "./src/error.ts"; +export { Context } from "./src/context.ts"; -import type * as Guild from './src/types/guild.d.ts'; -import type * as Deployment from './src/types/deployment.d.ts'; -import type * as User from './src/types/user.d.ts'; -import type * as Pylon from './src/types/pylon.d.ts'; +import type * as Guild from "./src/types/guild.d.ts"; +import type * as Deployment from "./src/types/deployment.d.ts"; +import type * as User from "./src/types/user.d.ts"; +import type * as Pylon from "./src/types/pylon.d.ts"; export type { Deployment, Guild, Pylon, User }; diff --git a/node-transform.ps1 b/node-transform.ps1 index 1474b55..2f829e7 100644 --- a/node-transform.ps1 +++ b/node-transform.ps1 @@ -18,6 +18,7 @@ $Destination = "node" $NodePackageLocation = "$Destination/package.json" $ImportRegex = "(?<=(?<=\n|^)(im|ex)port(?:(?!(\.d)?\.ts).|\n)*)(\.d)?\.ts" $NodeOnlyRegex = "\/\/ build:node-only " +$DiscordAPIRegex = "(?<=discord-api-types\/[a-z]+\/v8)\/guild" [string[]]$PresentFiles = @() $ItemList + $DeleteList | ForEach-Object { @@ -61,7 +62,7 @@ If ($Version) { # Node Import Syntax Fix Get-ChildItem $Destination -Recurse -Filter *.ts | ForEach-Object { $Content = Get-Content $_.FullName -Raw - $Content -replace "($ImportRegex|$NodeOnlyRegex)", "" > $_.FullName + $Content -replace "($ImportRegex|$NodeOnlyRegex|$DiscordAPIRegex)", "" > $_.FullName } # Verification diff --git a/src/context.ts b/src/context.ts index 9d1f691..5d8ca5c 100644 --- a/src/context.ts +++ b/src/context.ts @@ -91,11 +91,11 @@ export class Context { /** * A null context number. */ - static nullNumber = '-1'; + static nullNumber = "-1"; /** * A null context string. */ - static nullString = ''; + static nullString = ""; /** * Whether the given context matches a nullish context value. diff --git a/src/error.ts b/src/error.ts index cc4d22e..c313a22 100644 --- a/src/error.ts +++ b/src/error.ts @@ -55,7 +55,7 @@ export interface ITpyErrorsProperty { * @template T The type of {@linkcode rawInfo}. */ export class TpyError extends Error - implements Omit { + implements Omit { /** * A short description of the Tpy error. */ @@ -109,61 +109,61 @@ export class TpyError extends Error * defintion with specific context information. */ export const TpyErrors = { - 'Internal Server Error': { + "Internal Server Error": { message: (s: string) => serverRespondedWith(s), description: `Sometimes thrown when a request's authorization header is invalid.`, }, - 'Missing or Unexpected Value in Response': { + "Missing or Unexpected Value in Response": { message: (s: string) => `Response structure validation failed: ${s}.`, - description: 'Response structure is incomplete or has unexpected behavior.', + description: "Response structure is incomplete or has unexpected behavior.", }, - 'Missing or Invalid JSON in Request Body': { + "Missing or Invalid JSON in Request Body": { message: (s: string) => `With given field(s) ${s} were unsatisfactory; contains invalid JSON.`, description: `The fetch contents sent were did not have the required JSON body.`, }, - 'Guild Not Found': { - message: (s: string) => couldNotBeFound('Guild ID', s), + "Guild Not Found": { + message: (s: string) => couldNotBeFound("Guild ID", s), description: `The guild specified was not found.`, }, - 'Deployment Not Found': { - message: (s: string) => couldNotBeFound('Deployment ID', s), + "Deployment Not Found": { + message: (s: string) => couldNotBeFound("Deployment ID", s), description: `The deployment specified was not found.`, }, - 'HTTP Method Not Allowed': { + "HTTP Method Not Allowed": { message: (s: string) => serverRespondedWith(s), - description: 'The HTTP method is not allowed.', + description: "The HTTP method is not allowed.", }, - 'Unidentifiable Error': { + "Unidentifiable Error": { message: (s: string) => `Unidentifiable error caught, deterministic via fields: ${s}`, description: - 'The error was unidentifiable, see details with `.rawInfo`.', + "The error was unidentifiable, see details with `.rawInfo`.", }, - 'URL Resource Not Found': { + "URL Resource Not Found": { message: (s: string) => serverRespondedWith(s), - description: 'The URL resource on the web server was not found.', + description: "The URL resource on the web server was not found.", }, Unauthorized: { message: (s: string) => serverRespondedWith(s), - description: 'Required credentials were missing from the request.', + description: "Required credentials were missing from the request.", }, Forbidden: { message: (s: string) => serverRespondedWith(s), description: - 'Access to the resource is denied despite included credentials.', + "Access to the resource is denied despite included credentials.", }, - 'Missing or Invalid Required Parameter': { + "Missing or Invalid Required Parameter": { message: (s: string) => `Required parameter(s) ${s} were missing or invalid.`, - description: 'Required parameter(s) were missing or invalid.', + description: "Required parameter(s) were missing or invalid.", }, - 'Nullish Context': { + "Nullish Context": { message: (s: string) => `Context parameter ${s} is nullish, where access is necessary.`, - description: 'A context parameter was missing where it was needed.', + description: "A context parameter was missing where it was needed.", }, }; @@ -194,11 +194,11 @@ export function responseBody(s: string) { * @param params The parameter(s) in this context. */ export function parametersPrompt( - issue: 'missing' | 'incompatible', + issue: "missing" | "incompatible", params: string | string[], ) { return `Parameter(s) are ${issue}: ${ - Array.isArray(params) ? params.join(', ') : params + Array.isArray(params) ? params.join(", ") : params }`; } diff --git a/src/kv.ts b/src/kv.ts index 4817d8a..6f33bc8 100644 --- a/src/kv.ts +++ b/src/kv.ts @@ -7,10 +7,10 @@ * @module */ -import { Tpy } from './tpy.ts'; -import type { Json, KV } from './types/pylon.d.ts'; -import { parametersPrompt, TpyError } from './error.ts'; -import { Context } from './context.ts'; +import { Tpy } from "./tpy.ts"; +import type { Json, KV } from "./types/pylon.d.ts"; +import { parametersPrompt, TpyError } from "./error.ts"; +import { Context } from "./context.ts"; /** * A KVNamespace interface that (almost) matches the Pylon KVNamespace SDK class. @@ -31,20 +31,20 @@ export class TpyKV { constructor(tpyInstance: Tpy, deploymentID: string, kvnamespace: string) { if (!tpyInstance || !(tpyInstance instanceof Tpy)) { throw new TpyError( - 'Missing or Invalid Required Parameter', + "Missing or Invalid Required Parameter", parametersPrompt( - !tpyInstance ? 'missing' : 'incompatible', - 'tpyInstance', + !tpyInstance ? "missing" : "incompatible", + "tpyInstance", ), - 'tpyInstance', + "tpyInstance", tpyInstance, ); } if (!deploymentID) { throw new TpyError( - 'Missing or Invalid Required Parameter', - parametersPrompt('missing', 'deploymentID'), - 'deploymentID', + "Missing or Invalid Required Parameter", + parametersPrompt("missing", "deploymentID"), + "deploymentID", deploymentID, ); } @@ -66,10 +66,10 @@ export class TpyKV { await this.tpyc.httpRaw( new Context({ deploymentID }), `/deployments/${deploymentID}/kv/namespaces/${kvnamespace}/items/${key}`, - 'PUT', + "PUT", { body: JSON.stringify({ - string: typeof value === 'string' ? `"${value}"` : value, + string: typeof value === "string" ? `"${value}"` : value, }), }, false, @@ -93,7 +93,7 @@ export class TpyKV { await this.tpyc.httpRaw( new Context({ deploymentID, kvnamespace }), `/deployments/${deploymentID}/kv/namespaces/${kvnamespace}/items/${key}`, - 'PUT', + "PUT", { body: JSON.stringify({ bytes: value }) }, false, ); @@ -117,13 +117,13 @@ export class TpyKV { if (p.key !== key) continue; if (!p.value.string) { throw new TpyError( - 'Missing or Unexpected Value in Response', + "Missing or Unexpected Value in Response", `response[${i}].value.string is undefined`, `response[${i}].value.string`, response, ); } - item = ['\'', '"', '`'].includes(p.value.string[0]) + item = ["'", '"', "`"].includes(p.value.string[0]) ? JSON.parse(p.value.string) : p.value.string; break; @@ -210,10 +210,10 @@ export class TpyKV { : i.value.bytes; if (!j) { throw new TpyError( - 'Missing or Unexpected Value in Response', + "Missing or Unexpected Value in Response", `response[${i}].value.string and/or response[${i}].value.bytes are undefined`, [`response[${i}].value.string`, `response[${i}].value.bytes`].join( - ', ', + ", ", ), response, ); @@ -255,7 +255,7 @@ export class TpyKV { await this.tpyc.httpRaw( new Context({ deploymentID, kvnamespace }), `/deployments/${deploymentID}/kv/namespaces/${kvnamespace}`, - 'DELETE', + "DELETE", ) ).keys_deleted; } @@ -274,7 +274,7 @@ export class TpyKV { await this.tpyc.httpRaw( new Context({ deploymentID, kvnamespace }), `/deployments/${deploymentID}/kv/namespaces/${kvnamespace}/items/${key}`, - 'DELETE', + "DELETE", {}, false, ); diff --git a/src/tpy.ts b/src/tpy.ts index d27638f..5e86b0d 100644 --- a/src/tpy.ts +++ b/src/tpy.ts @@ -9,14 +9,14 @@ import { responseBody, responseHTTP, TpyError, -} from './error.ts'; -import type * as Deployment from './types/deployment.d.ts'; -import type * as Guild from './types/guild.d.ts'; -import type * as User from './types/user.d.ts'; -import type { HTTPVerbs, KV } from './types/pylon.d.ts'; -import { TpyWs } from './ws.ts'; -import { TpyKV } from './kv.ts'; -import { Context } from './context.ts'; +} from "./error.ts"; +import type * as Deployment from "./types/deployment.d.ts"; +import type * as Guild from "./types/guild.d.ts"; +import type * as User from "./types/user.d.ts"; +import type { HTTPVerbs, KV } from "./types/pylon.d.ts"; +import { TpyWs } from "./ws.ts"; +import { TpyKV } from "./kv.ts"; +import { Context } from "./context.ts"; /** * The central entity for interacting with the Pylon API; the entrypoint. @@ -55,19 +55,19 @@ export class Tpy { if (!token) { throw new TpyError( - 'Missing or Unexpected Value in Response', - parametersPrompt('missing', 'token'), - 'token', + "Missing or Unexpected Value in Response", + parametersPrompt("missing", "token"), + "token", token, ); } this.token = token; if (deploymentID) this.deploymentID = deploymentID; // If this is Node.js - if ('process' in globalThis && useNodeFetch) { + if ("process" in globalThis && useNodeFetch) { const fetch = ( - ...args: Parameters - ) => import('node-fetch').then(({ default: fetch }) => fetch(...args)); + ...args: Parameters + ) => import("node-fetch").then(({ default: fetch }) => fetch(...args)); ( globalThis.fetch) = fetch; } } @@ -76,7 +76,7 @@ export class Tpy { * Gets the user's account details associated with the included credentials. */ async getUser() { - return await this.httpRaw(new Context({}), '/user'); + return await this.httpRaw(new Context({}), "/user"); } /** @@ -85,7 +85,7 @@ export class Tpy { async getAvailableGuilds() { return await this.httpRaw( new Context({}), - '/user/guilds/available', + "/user/guilds/available", ); } @@ -134,9 +134,9 @@ export class Tpy { const dID = deploymentID || this.deploymentID; if (!dID) { throw new TpyError( - 'Missing or Invalid Required Parameter', - parametersPrompt('missing', ['deploymentID', 'this.deploymentID']), - ['deploymentID', 'this.deploymentID'].join(', '), + "Missing or Invalid Required Parameter", + parametersPrompt("missing", ["deploymentID", "this.deploymentID"]), + ["deploymentID", "this.deploymentID"].join(", "), dID, ); } @@ -164,9 +164,9 @@ export class Tpy { const dID = deploymentID || this.deploymentID; if (!dID) { throw new TpyError( - 'Missing or Invalid Required Parameter', - parametersPrompt('missing', ['deploymentID', 'this.deploymentID']), - ['deploymentID', 'this.deploymentID'].join(', '), + "Missing or Invalid Required Parameter", + parametersPrompt("missing", ["deploymentID", "this.deploymentID"]), + ["deploymentID", "this.deploymentID"].join(", "), dID, ); } @@ -174,7 +174,7 @@ export class Tpy { return (await this.httpRaw( new Context({ deploymentID: dID }), `/deployments/${dID}`, - 'POST', + "POST", { body: JSON.stringify(body), }, @@ -200,7 +200,7 @@ export class Tpy { method, headers: { Authorization: this.token, - 'Content-Type': 'application/json', + "Content-Type": "application/json", }, ...other, } as RequestInit; @@ -216,9 +216,9 @@ export class Tpy { const dID = deploymentID || this.deploymentID; if (!dID) { throw new TpyError( - 'Missing or Invalid Required Parameter', - parametersPrompt('missing', ['deploymentID', 'this.deploymentID']), - ['deploymentID', 'this.deploymentID'].join(', '), + "Missing or Invalid Required Parameter", + parametersPrompt("missing", ["deploymentID", "this.deploymentID"]), + ["deploymentID", "this.deploymentID"].join(", "), dID, ); } @@ -234,9 +234,9 @@ export class Tpy { const dID = deploymentID || this.deploymentID; if (!dID) { throw new TpyError( - 'Missing or Invalid Required Parameter', - parametersPrompt('missing', ['deploymentID', 'this.deploymentID']), - ['deploymentID', 'this.deploymentID'].join(', '), + "Missing or Invalid Required Parameter", + parametersPrompt("missing", ["deploymentID", "this.deploymentID"]), + ["deploymentID", "this.deploymentID"].join(", "), dID, ); } @@ -261,9 +261,9 @@ export class Tpy { const dID = deploymentID || this.deploymentID; if (!dID) { throw new TpyError( - 'Missing or Invalid Required Parameter', - parametersPrompt('missing', ['deploymentID', 'this.deploymentID']), - ['deploymentID', 'this.deploymentID'].join(', '), + "Missing or Invalid Required Parameter", + parametersPrompt("missing", ["deploymentID", "this.deploymentID"]), + ["deploymentID", "this.deploymentID"].join(", "), dID, ); } @@ -277,7 +277,7 @@ export class Tpy { const p = response[i]; if (!p.value.string) { throw new TpyError( - 'Missing or Unexpected Value in Response', + "Missing or Unexpected Value in Response", `response[${i}\].value.string is undefined`, `response[${i}\].value.string`, response, @@ -302,9 +302,9 @@ export class Tpy { const dID = deploymentID || this.deploymentID; if (!dID) { throw new TpyError( - 'Missing or Invalid Required Parameter', - parametersPrompt('missing', ['deploymentID', 'this.deploymentID']), - ['deploymentID', 'this.deploymentID'].join(', '), + "Missing or Invalid Required Parameter", + parametersPrompt("missing", ["deploymentID", "this.deploymentID"]), + ["deploymentID", "this.deploymentID"].join(", "), dID, ); } @@ -328,12 +328,12 @@ export class Tpy { async httpRaw( ctx: Context, resource: `/${string}`, - method: HTTPVerbs = 'GET', + method: HTTPVerbs = "GET", requestInit: RequestInit = {}, parse: Parse = true as Parse, ): Promise { const response = await fetch( - 'https://pylon.bot/api' + resource, + "https://pylon.bot/api" + resource, this.readyRequest(method, requestInit), ); @@ -346,45 +346,45 @@ export class Tpy { switch (response.status) { case 404: { const r = await response.text(); - if (r.startsWith('\u26A0\uFE0F')) { + if (r.startsWith("\u26A0\uFE0F")) { throw new TpyError( - 'URL Resource Not Found', + "URL Resource Not Found", responseBody(r), response.status.toString(), response, ); } - if (r === 'could not find deployment') { + if (r === "could not find deployment") { if (Context.isNullish(ctx.deploymentID)) { throw new TpyError( - 'Nullish Context', + "Nullish Context", ctx.deploymentID, - 'ctx.deploymentID', + "ctx.deploymentID", ctx, ); } throw new TpyError( - 'Deployment Not Found', + "Deployment Not Found", responseBody(r), ctx.deploymentID, response, ); } - if (r === 'could not find guild') { + if (r === "could not find guild") { if (Context.isNullish(ctx.guildID)) { throw new TpyError( - 'Nullish Context', + "Nullish Context", ctx.guildID, - 'ctx.guildID', + "ctx.guildID", ctx, ); } throw new TpyError( - 'Guild Not Found', + "Guild Not Found", responseBody(r), ctx.guildID, response, @@ -395,7 +395,7 @@ export class Tpy { case 401: throw new TpyError( - 'Unauthorized', + "Unauthorized", responseHTTP(response.status.toString()), response.status.toString(), response, @@ -403,7 +403,7 @@ export class Tpy { case 403: throw new TpyError( - 'Forbidden', + "Forbidden", responseHTTP(response.status.toString()), response.status.toString(), response, @@ -411,7 +411,7 @@ export class Tpy { case 405: throw new TpyError( - 'HTTP Method Not Allowed', + "HTTP Method Not Allowed", responseHTTP(response.status.toString()), response.status.toString(), response, @@ -419,11 +419,11 @@ export class Tpy { case 400: { const res = await response.json(); - if ('msg' in res && res['msg'] === 'missing json body') { + if ("msg" in res && res["msg"] === "missing json body") { throw new TpyError( - 'Missing or Invalid JSON in Request Body', + "Missing or Invalid JSON in Request Body", responseHTTP(response.status.toString()), - JSON.stringify(res['msg']), + JSON.stringify(res["msg"]), response, ); } @@ -432,7 +432,7 @@ export class Tpy { case 500: throw new TpyError( - 'Internal Server Error', + "Internal Server Error", responseHTTP(response.status.toString()), response.status.toString(), response, @@ -440,10 +440,10 @@ export class Tpy { } throw new TpyError( - 'Unidentifiable Error', + "Unidentifiable Error", `Response is ok: ${response.ok}`, JSON.stringify({ - 'response.ok': response.ok, + "response.ok": response.ok, }), response, ); diff --git a/src/types/deployment.d.ts b/src/types/deployment.d.ts index 1f0bc16..8edbf4a 100644 --- a/src/types/deployment.d.ts +++ b/src/types/deployment.d.ts @@ -6,8 +6,8 @@ * @module */ -import type { GuildStructures } from './guild.d.ts'; -import type { GatewayDispatchEvents } from 'discord-api-types/gateway/v8.ts'; +import type { GuildStructures } from "./guild.d.ts"; +import type { GatewayDispatchEvents } from "discord-api-types/gateway/v8.ts"; /** * Not an API resource, this namespace behaves as a set of templates and other @@ -223,7 +223,7 @@ export namespace GET { /** * The new deployment script information. */ - script: Omit, 'contents'>; + script: Omit, "contents">; }; } @@ -239,7 +239,7 @@ export namespace POST { */ export type Request = Omit< DeploymentStructures.Script, - 'id' + "id" >; /** @@ -259,6 +259,6 @@ export namespace POST { /** * The new deployment script information. */ - script?: Omit, 'contents'>; + script?: Omit, "contents">; }; } diff --git a/src/types/guild.d.ts b/src/types/guild.d.ts index 103611c..fa7ff3a 100644 --- a/src/types/guild.d.ts +++ b/src/types/guild.d.ts @@ -6,9 +6,9 @@ * @module */ -import { RESTPostAPIGuildsJSONBody } from 'discord-api-types/rest/v8/guild.ts'; -import { APIUnavailableGuild } from 'discord-api-types/payloads/v8/guild.ts'; -import { DeploymentStructures } from './deployment.d.ts'; +import { RESTPostAPIGuildsJSONBody } from "discord-api-types/rest/v8/guild.ts"; +import { APIUnavailableGuild } from "discord-api-types/payloads/v8/guild.ts"; +import { DeploymentStructures } from "./deployment.d.ts"; /** * Not an API resource, this namespace behaves as a set of templates and other @@ -68,7 +68,7 @@ export namespace GET { /** * `true` if the guild is unavailable due to an outage. */ - unavailable: APIUnavailableGuild['unavailable']; + unavailable: APIUnavailableGuild["unavailable"]; }; /** diff --git a/src/types/pylon.d.ts b/src/types/pylon.d.ts index 2186c20..660df92 100644 --- a/src/types/pylon.d.ts +++ b/src/types/pylon.d.ts @@ -11,7 +11,7 @@ /** * HTTP Verbs supported by the Pylon API. */ -export type HTTPVerbs = 'GET' | 'POST' | 'PUT' | 'DELETE'; +export type HTTPVerbs = "GET" | "POST" | "PUT" | "DELETE"; /** * Types parsable by ES5's `JSON.parse` function. @@ -273,5 +273,5 @@ export namespace PylonWebSocket { * The method of logging this was caused by. Follows the Console * interface methods supported on the Pylon SDK. */ - export type ConsoleMethods = 'error' | 'debug' | 'info' | 'warn' | 'log'; + export type ConsoleMethods = "error" | "debug" | "info" | "warn" | "log"; } diff --git a/src/types/user.d.ts b/src/types/user.d.ts index 4ff18dc..ba44fcd 100644 --- a/src/types/user.d.ts +++ b/src/types/user.d.ts @@ -6,8 +6,8 @@ * @module */ -import type { Unpacked } from './util.d.ts'; -import type { GuildStructures } from './guild.d.ts'; +import type { Unpacked } from "./util.d.ts"; +import type { GuildStructures } from "./guild.d.ts"; /** * Schemas for `GET /user`. diff --git a/src/ws.ts b/src/ws.ts index 5ae1ddc..c4dd4f0 100644 --- a/src/ws.ts +++ b/src/ws.ts @@ -16,11 +16,11 @@ // build:node-only type ErrorEvent, // build:node-only type MessageEvent, // build:node-only } from "ws"; -import { Tpy } from './tpy.ts'; -import type { Unpacked } from './types/util.d.ts'; -import type { PylonWebSocket } from './types/pylon.d.ts'; -import { EventEmitter } from 'events'; -import { parametersPrompt, TpyError } from './error.ts'; +import { Tpy } from "./tpy.ts"; +import type { Unpacked } from "./types/util.d.ts"; +import type { PylonWebSocket } from "./types/pylon.d.ts"; +import { EventEmitter } from "events"; +import { parametersPrompt, TpyError } from "./error.ts"; type messageTypes = typeof TpyWs.prototype.messageTypes[number]; @@ -33,7 +33,7 @@ type messageTypes = typeof TpyWs.prototype.messageTypes[number]; * with customizable timeouts. */ export class TpyWs { - readonly messageTypes = ['message', 'open', 'close', 'error'] as const; + readonly messageTypes = ["message", "open", "close", "error"] as const; private tpyClient: Tpy; private deploymentID: string; private tryToConnect = true; @@ -63,20 +63,20 @@ export class TpyWs { ) { if (!tpyInstance || !(tpyInstance instanceof Tpy)) { throw new TpyError( - 'Missing or Invalid Required Parameter', + "Missing or Invalid Required Parameter", parametersPrompt( - !tpyInstance ? 'missing' : 'incompatible', - 'tpyInstance', + !tpyInstance ? "missing" : "incompatible", + "tpyInstance", ), - 'tpyInstance', + "tpyInstance", tpyInstance, ); } if (!deploymentID) { throw new TpyError( - 'Missing or Invalid Required Parameter', - parametersPrompt('missing', 'deploymentID'), - 'deploymentID', + "Missing or Invalid Required Parameter", + parametersPrompt("missing", "deploymentID"), + "deploymentID", deploymentID, ); } @@ -92,7 +92,7 @@ export class TpyWs { * * @event */ - on(type: 'open', callback: (data: Event) => void): EventEmitter; + on(type: "open", callback: (data: Event) => void): EventEmitter; /** * Adds an event listener to WebSocket events. * @param type Fired when the WebSocket is closed. @@ -100,7 +100,7 @@ export class TpyWs { * * @event */ - on(type: 'close', callback: (data: CloseEvent) => void): EventEmitter; + on(type: "close", callback: (data: CloseEvent) => void): EventEmitter; /** * Adds an event listener to WebSocket events. * @param type Fired when the WebSocket captures an error. @@ -112,7 +112,7 @@ export class TpyWs { * * @event */ - on(type: 'error', callback: (data: ErrorEvent | Event) => void): EventEmitter; + on(type: "error", callback: (data: ErrorEvent | Event) => void): EventEmitter; /** * Adds an event listener to WebSocket events. * @param type Fired when the WebSocket recieves a message. @@ -123,15 +123,15 @@ export class TpyWs { * @event */ on( - type: 'message', + type: "message", callback: (data: Unpacked>) => void, ): EventEmitter; on(type: messageTypes, callback: unknown) { - if (typeof callback != 'function') { + if (typeof callback != "function") { throw new TpyError( - 'Missing or Invalid Required Parameter', - parametersPrompt('incompatible', 'callback'), - 'callback', + "Missing or Invalid Required Parameter", + parametersPrompt("incompatible", "callback"), + "callback", typeof callback, ); } @@ -156,12 +156,12 @@ export class TpyWs { } private onOpen(event: Event) { - this.eventEmitter.emit('open', event); + this.eventEmitter.emit("open", event); } private onError(event: Event | ErrorEvent) { if (!this.websocket) return; - this.eventEmitter.emit('error', event); + this.eventEmitter.emit("error", event); try { this.websocket.close(); @@ -174,11 +174,11 @@ export class TpyWs { } private onClose(event: CloseEvent) { - this.eventEmitter.emit('close', event); + this.eventEmitter.emit("close", event); } private onMessage(event: MessageEvent) { - this.eventEmitter.emit('message', JSON.parse(String(event.data))[0]); + this.eventEmitter.emit("message", JSON.parse(String(event.data))[0]); } /**