Skip to content

Commit cd1f2c4

Browse files
committed
Fixed httpraw parse, guild stat date docs (ty y21)
1 parent c20e490 commit cd1f2c4

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ following qualities:
1717
- 📄 Extensive documentation.
1818
- 📞 Keep-alive WebSocket client.
1919

20+
## Documentation
21+
2022
The API documentation can be viewed on the
2123
[Deno website](https://deno.land/x/tpy/mod.ts/).
2224

@@ -38,9 +40,9 @@ download the type dependencies locally.
3840

3941
```ts
4042
const client = new Tpy('PYLON_TOKEN');
41-
const user = await client.getUser();
43+
const { displayName, id } = await client.getUser();
4244

43-
console.log(`Logged in as ${user.displayName} (<@${user.id}>).`);
45+
console.log(`Logged in as ${displayName} (<@${id}>).`);
4446
```
4547

4648
#### Listen to a deployment's console output.
@@ -142,10 +144,13 @@ const kv = client.KV(
142144
(await client.getDeploymentfromGuild('GUILD_ID')).id,
143145
);
144146

145-
const key = 'cool';
147+
const key = '';
148+
146149
console.log(`Value of key "${key}":`, await kv.get(key));
150+
147151
await kv.put(key, 'rust');
148152
console.log(`Value of key "${key}":`, await kv.get(key));
153+
149154
await kv.delete(key);
150155
console.log(`Value of key "${key}":`, await kv.get(key));
151156
```

src/kv.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export default class TpyKV {
102102
`/deployments/${deploymentID}/kv/namespaces/${kvnamespace}/items/${key}`,
103103
'PUT',
104104
{ body: JSON.stringify({ 'bytes': value }) },
105+
false,
105106
);
106107
}
107108

@@ -273,6 +274,8 @@ export default class TpyKV {
273274
new Context({ deploymentID, kvnamespace }),
274275
`/deployments/${deploymentID}/kv/namespaces/${kvnamespace}/items/${key}`,
275276
'DELETE',
277+
{},
278+
false,
276279
);
277280

278281
if (!options?.prevValue) await del();

src/tpy.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,23 +266,29 @@ export default class Tpy {
266266
* @param requestInit Other fetch parameters.
267267
* @param parse Whether to parse out the body or not, default is true.
268268
*
269+
* @template T The return type of the response body.
270+
* @template Parse Follows the {@linkcode parse} parameter and should match values. Determines whether T is returned or not.
271+
*
269272
* @throws {TpyError<Response | Context>}
270273
*/
271-
async httpRaw<T>(
274+
async httpRaw<T, Parse extends boolean = true>(
272275
ctx: Context,
273276
resource: `/${string}`,
274277
method: Pylon.HTTPVerbs = 'GET',
275278
requestInit: RequestInit = {},
276-
parse = true,
277-
): Promise<T> {
279+
parse: Parse = (true as Parse),
280+
): Promise<Parse extends true ? T : void> {
278281
const response = await fetch(
279282
'https://pylon.bot/api' + resource,
280283
this.readyRequest(method, requestInit),
281284
);
282285

283286
if (response.ok) {
284-
if (parse) return await response.json() as T;
285-
return {} as T;
287+
return (
288+
parse
289+
? await response.json() as Parse extends true ? T : void
290+
: undefined as Parse extends true ? T : void
291+
);
286292
}
287293

288294
switch (response.status) {

src/types/guild.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ declare namespace Guild {
8383
*/
8484
export type Stats = Array<{
8585
/**
86-
* Date (Unix timestamp) of when statistics were captured.
86+
* Date (Unix timestamp) in seconds of when statistics were captured.
8787
*/
8888
date: number;
8989
/**

0 commit comments

Comments
 (0)