7
7
* @module
8
8
*/
9
9
10
- import { Tpy } from " ./tpy.ts" ;
11
- import type { Json , KV } from " ./types/pylon.d.ts" ;
12
- import { parametersPrompt , TpyError } from " ./error.ts" ;
13
- import { Context } from " ./context.ts" ;
10
+ import { Tpy } from ' ./tpy.ts' ;
11
+ import type { Json , KV } from ' ./types/pylon.d.ts' ;
12
+ import { parametersPrompt , TpyError } from ' ./error.ts' ;
13
+ import { Context } from ' ./context.ts' ;
14
14
15
15
/**
16
16
* A KVNamespace interface that (almost) matches the Pylon KVNamespace SDK class.
@@ -31,21 +31,21 @@ export class TpyKV {
31
31
constructor ( tpyInstance : Tpy , deploymentID : string , kvnamespace : string ) {
32
32
if ( ! tpyInstance || ! ( tpyInstance instanceof Tpy ) ) {
33
33
throw new TpyError (
34
- " Missing or Invalid Required Parameter" ,
34
+ ' Missing or Invalid Required Parameter' ,
35
35
parametersPrompt (
36
- ! tpyInstance ? " missing" : " incompatible" ,
37
- " tpyInstance"
36
+ ! tpyInstance ? ' missing' : ' incompatible' ,
37
+ ' tpyInstance' ,
38
38
) ,
39
- " tpyInstance" ,
40
- tpyInstance
39
+ ' tpyInstance' ,
40
+ tpyInstance ,
41
41
) ;
42
42
}
43
43
if ( ! deploymentID ) {
44
44
throw new TpyError (
45
- " Missing or Invalid Required Parameter" ,
46
- parametersPrompt ( " missing" , " deploymentID" ) ,
47
- " deploymentID" ,
48
- deploymentID
45
+ ' Missing or Invalid Required Parameter' ,
46
+ parametersPrompt ( ' missing' , ' deploymentID' ) ,
47
+ ' deploymentID' ,
48
+ deploymentID ,
49
49
) ;
50
50
}
51
51
this . tpyc = tpyInstance ;
@@ -66,13 +66,13 @@ export class TpyKV {
66
66
await this . tpyc . httpRaw (
67
67
new Context ( { deploymentID } ) ,
68
68
`/deployments/${ deploymentID } /kv/namespaces/${ kvnamespace } /items/${ key } ` ,
69
- " PUT" ,
69
+ ' PUT' ,
70
70
{
71
71
body : JSON . stringify ( {
72
- string : typeof value === " string" ? `"${ value } "` : value ,
72
+ string : typeof value === ' string' ? `"${ value } "` : value ,
73
73
} ) ,
74
74
} ,
75
- false
75
+ false ,
76
76
) ;
77
77
}
78
78
@@ -85,17 +85,17 @@ export class TpyKV {
85
85
async putArrayBuffer (
86
86
key : string ,
87
87
value : ArrayBuffer ,
88
- options ?: KV . OperationOptions . Put
88
+ options ?: KV . OperationOptions . Put ,
89
89
) {
90
90
if ( options ?. ifNotExists && ( await this . get ( key ) ) ) return ;
91
91
92
92
const { deploymentID, kvnamespace } = this ;
93
93
await this . tpyc . httpRaw (
94
94
new Context ( { deploymentID, kvnamespace } ) ,
95
95
`/deployments/${ deploymentID } /kv/namespaces/${ kvnamespace } /items/${ key } ` ,
96
- " PUT" ,
96
+ ' PUT' ,
97
97
{ body : JSON . stringify ( { bytes : value } ) } ,
98
- false
98
+ false ,
99
99
) ;
100
100
}
101
101
@@ -109,21 +109,21 @@ export class TpyKV {
109
109
const { deploymentID, kvnamespace } = this ;
110
110
const response = await this . tpyc . httpRaw < KV . GET . Items < T > > (
111
111
new Context ( { deploymentID, kvnamespace } ) ,
112
- `/deployments/${ deploymentID } /kv/namespaces/${ kvnamespace } /items`
112
+ `/deployments/${ deploymentID } /kv/namespaces/${ kvnamespace } /items` ,
113
113
) ;
114
114
let item : T | undefined ;
115
115
for ( let i = 0 ; i < response . length ; i ++ ) {
116
116
const p = response [ i ] ;
117
117
if ( p . key !== key ) continue ;
118
118
if ( ! p . value . string ) {
119
119
throw new TpyError (
120
- " Missing or Unexpected Value in Response" ,
120
+ ' Missing or Unexpected Value in Response' ,
121
121
`response[${ i } ].value.string is undefined` ,
122
122
`response[${ i } ].value.string` ,
123
- response
123
+ response ,
124
124
) ;
125
125
}
126
- item = [ "'" , '"' , "`" ] . includes ( p . value . string [ 0 ] )
126
+ item = [ '\'' , '"' , '`' ] . includes ( p . value . string [ 0 ] )
127
127
? JSON . parse ( p . value . string )
128
128
: p . value . string ;
129
129
break ;
@@ -140,7 +140,7 @@ export class TpyKV {
140
140
const { deploymentID, kvnamespace } = this ;
141
141
const response = await this . tpyc . httpRaw < KV . GET . Items > (
142
142
new Context ( { deploymentID, kvnamespace } ) ,
143
- `/deployments/${ deploymentID } /kv/namespaces/${ kvnamespace } /items`
143
+ `/deployments/${ deploymentID } /kv/namespaces/${ kvnamespace } /items` ,
144
144
) ;
145
145
let item : ArrayBuffer | undefined ;
146
146
for ( const p of response ) {
@@ -161,15 +161,15 @@ export class TpyKV {
161
161
const { deploymentID, kvnamespace } = this ;
162
162
let response = await this . tpyc . httpRaw < KV . GET . Items > (
163
163
new Context ( { deploymentID, kvnamespace } ) ,
164
- `/deployments/${ deploymentID } /kv/namespaces/${ kvnamespace } /items`
164
+ `/deployments/${ deploymentID } /kv/namespaces/${ kvnamespace } /items` ,
165
165
) ;
166
166
167
167
if ( options ?. limit ) response = response . slice ( 0 , options . limit ) ;
168
168
169
169
if ( options ?. from ) {
170
170
response = response . slice (
171
171
response . findIndex ( ( i ) => i . key === options . from ) + 1 ,
172
- response . length
172
+ response . length ,
173
173
) ;
174
174
}
175
175
@@ -185,18 +185,18 @@ export class TpyKV {
185
185
* @template T The type of the key's value.
186
186
*/
187
187
async items < T > (
188
- options ?: KV . OperationOptions . Items
188
+ options ?: KV . OperationOptions . Items ,
189
189
) : Promise < KV . GET . ItemsFlattened < T > > {
190
190
const { deploymentID, kvnamespace } = this ;
191
191
let response = await this . tpyc . httpRaw < KV . GET . Items > (
192
192
new Context ( { deploymentID, kvnamespace } ) ,
193
- `/deployments/${ deploymentID } /kv/namespaces/${ kvnamespace } /items`
193
+ `/deployments/${ deploymentID } /kv/namespaces/${ kvnamespace } /items` ,
194
194
) ;
195
195
196
196
if ( options ?. from ) {
197
197
response = response . slice (
198
198
response . findIndex ( ( i ) => i . key === options . from ) + 1 ,
199
- response . length
199
+ response . length ,
200
200
) ;
201
201
}
202
202
@@ -210,12 +210,12 @@ export class TpyKV {
210
210
: i . value . bytes ;
211
211
if ( ! j ) {
212
212
throw new TpyError (
213
- " Missing or Unexpected Value in Response" ,
213
+ ' Missing or Unexpected Value in Response' ,
214
214
`response[${ i } ].value.string and/or response[${ i } ].value.bytes are undefined` ,
215
215
[ `response[${ i } ].value.string` , `response[${ i } ].value.bytes` ] . join (
216
- ", "
216
+ ', ' ,
217
217
) ,
218
- response
218
+ response ,
219
219
) ;
220
220
}
221
221
return {
@@ -235,7 +235,7 @@ export class TpyKV {
235
235
(
236
236
await this . tpyc . httpRaw < KV . GET . Namespace > (
237
237
new Context ( { deploymentID, kvnamespace } ) ,
238
- `/deployments/${ deploymentID } /kv/namespaces`
238
+ `/deployments/${ deploymentID } /kv/namespaces` ,
239
239
)
240
240
) . find ( ( n ) => n . namespace == kvnamespace ) ?. count || 0
241
241
) ;
@@ -255,7 +255,7 @@ export class TpyKV {
255
255
await this . tpyc . httpRaw < KV . DELETE . Namespace > (
256
256
new Context ( { deploymentID, kvnamespace } ) ,
257
257
`/deployments/${ deploymentID } /kv/namespaces/${ kvnamespace } ` ,
258
- " DELETE"
258
+ ' DELETE' ,
259
259
)
260
260
) . keys_deleted ;
261
261
}
@@ -274,9 +274,9 @@ export class TpyKV {
274
274
await this . tpyc . httpRaw (
275
275
new Context ( { deploymentID, kvnamespace } ) ,
276
276
`/deployments/${ deploymentID } /kv/namespaces/${ kvnamespace } /items/${ key } ` ,
277
- " DELETE" ,
277
+ ' DELETE' ,
278
278
{ } ,
279
- false
279
+ false ,
280
280
) ;
281
281
282
282
if ( ! options ?. prevValue ) await del ( ) ;
0 commit comments