File tree Expand file tree Collapse file tree 4 files changed +23
-9
lines changed Expand file tree Collapse file tree 4 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ following qualities:
17
17
- 📄 Extensive documentation.
18
18
- 📞 Keep-alive WebSocket client.
19
19
20
+ ## Documentation
21
+
20
22
The API documentation can be viewed on the
21
23
[ Deno website] ( https://deno.land/x/tpy/mod.ts/ ) .
22
24
@@ -38,9 +40,9 @@ download the type dependencies locally.
38
40
39
41
``` ts
40
42
const client = new Tpy (' PYLON_TOKEN' );
41
- const user = await client .getUser ();
43
+ const { displayName, id } = await client .getUser ();
42
44
43
- console .log (` Logged in as ${user . displayName } (<@${user . id }>). ` );
45
+ console .log (` Logged in as ${displayName } (<@${id }>). ` );
44
46
```
45
47
46
48
#### Listen to a deployment's console output.
@@ -142,10 +144,13 @@ const kv = client.KV(
142
144
(await client .getDeploymentfromGuild (' GUILD_ID' )).id ,
143
145
);
144
146
145
- const key = ' cool' ;
147
+ const key = ' ' ;
148
+
146
149
console .log (` Value of key "${key }": ` , await kv .get (key ));
150
+
147
151
await kv .put (key , ' rust' );
148
152
console .log (` Value of key "${key }": ` , await kv .get (key ));
153
+
149
154
await kv .delete (key );
150
155
console .log (` Value of key "${key }": ` , await kv .get (key ));
151
156
```
Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ export default class TpyKV {
102
102
`/deployments/${ deploymentID } /kv/namespaces/${ kvnamespace } /items/${ key } ` ,
103
103
'PUT' ,
104
104
{ body : JSON . stringify ( { 'bytes' : value } ) } ,
105
+ false ,
105
106
) ;
106
107
}
107
108
@@ -273,6 +274,8 @@ export default class TpyKV {
273
274
new Context ( { deploymentID, kvnamespace } ) ,
274
275
`/deployments/${ deploymentID } /kv/namespaces/${ kvnamespace } /items/${ key } ` ,
275
276
'DELETE' ,
277
+ { } ,
278
+ false ,
276
279
) ;
277
280
278
281
if ( ! options ?. prevValue ) await del ( ) ;
Original file line number Diff line number Diff line change @@ -266,23 +266,29 @@ export default class Tpy {
266
266
* @param requestInit Other fetch parameters.
267
267
* @param parse Whether to parse out the body or not, default is true.
268
268
*
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
+ *
269
272
* @throws {TpyError<Response | Context> }
270
273
*/
271
- async httpRaw < T > (
274
+ async httpRaw < T , Parse extends boolean = true > (
272
275
ctx : Context ,
273
276
resource : `/${string } `,
274
277
method : Pylon . HTTPVerbs = 'GET' ,
275
278
requestInit : RequestInit = { } ,
276
- parse = true ,
277
- ) : Promise < T > {
279
+ parse : Parse = ( true as Parse ) ,
280
+ ) : Promise < Parse extends true ? T : void > {
278
281
const response = await fetch (
279
282
'https://pylon.bot/api' + resource ,
280
283
this . readyRequest ( method , requestInit ) ,
281
284
) ;
282
285
283
286
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
+ ) ;
286
292
}
287
293
288
294
switch ( response . status ) {
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ declare namespace Guild {
83
83
*/
84
84
export type Stats = Array < {
85
85
/**
86
- * Date (Unix timestamp) of when statistics were captured.
86
+ * Date (Unix timestamp) in seconds of when statistics were captured.
87
87
*/
88
88
date : number ;
89
89
/**
You can’t perform that action at this time.
0 commit comments