@rangedb/js 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +14 -6
- package/index.js +26 -9
- package/package.json +6 -3
package/dist/index.d.ts
CHANGED
|
@@ -121,23 +121,31 @@ export class RangeDB {
|
|
|
121
121
|
*/
|
|
122
122
|
getMetadata(): Promise<JSONObject | JSONArray>;
|
|
123
123
|
/**
|
|
124
|
-
* Get a raw ArrayBuffer from database for given key or null if not exists
|
|
124
|
+
* Get a raw ArrayBuffer from database for given key or null if not exists.
|
|
125
125
|
*
|
|
126
|
-
* @param {bigint} key
|
|
126
|
+
* @param {bigint | number} key
|
|
127
127
|
*
|
|
128
128
|
* @returns {Promise<ArrayBuffer | null>}
|
|
129
|
-
|
|
130
|
-
getRaw(key: bigint): Promise<ArrayBuffer | null>;
|
|
129
|
+
*/
|
|
130
|
+
getRaw(key: bigint | number): Promise<ArrayBuffer | null>;
|
|
131
|
+
/**
|
|
132
|
+
* Get a string from database for a given key or null if not exists
|
|
133
|
+
*
|
|
134
|
+
* @param {bigint | number} key
|
|
135
|
+
*
|
|
136
|
+
* @returns {Promise<string | null>}
|
|
137
|
+
*/
|
|
138
|
+
getString(key: bigint | number): Promise<string | null>;
|
|
131
139
|
/**
|
|
132
140
|
* Get a JSON from database for a given key or null if not exists
|
|
133
141
|
* It may throw JSON parsing error
|
|
134
142
|
*
|
|
135
|
-
* @param {bigint} key
|
|
143
|
+
* @param {bigint | number} key
|
|
136
144
|
*
|
|
137
145
|
* @returns {Promise<JSONValue | null>}
|
|
138
146
|
* @throws {SyntaxError}
|
|
139
147
|
*/
|
|
140
|
-
getJson(key: bigint): Promise<JSONValue | null>;
|
|
148
|
+
getJson(key: bigint | number): Promise<JSONValue | null>;
|
|
141
149
|
}
|
|
142
150
|
export type RangeDBOptions = {
|
|
143
151
|
/**
|
package/index.js
CHANGED
|
@@ -101,7 +101,7 @@ export class RangeDB {
|
|
|
101
101
|
* @returns {Promise<ArrayBuffer>}
|
|
102
102
|
*/
|
|
103
103
|
async readRange(start, end) {
|
|
104
|
-
const {headers, arrayBuffer} = await fetch(this.url, {
|
|
104
|
+
const { headers, arrayBuffer } = await fetch(this.url, {
|
|
105
105
|
headers: {
|
|
106
106
|
range: `bytes=${start}-${end}`,
|
|
107
107
|
},
|
|
@@ -291,13 +291,16 @@ export class RangeDB {
|
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
/**
|
|
294
|
-
* Get a raw ArrayBuffer from database for given key or null if not exists
|
|
294
|
+
* Get a raw ArrayBuffer from database for given key or null if not exists.
|
|
295
295
|
*
|
|
296
|
-
* @param {bigint} key
|
|
296
|
+
* @param {bigint | number} key
|
|
297
297
|
*
|
|
298
298
|
* @returns {Promise<ArrayBuffer | null>}
|
|
299
|
-
|
|
299
|
+
*/
|
|
300
300
|
async getRaw(key) {
|
|
301
|
+
if (typeof key === 'number') {
|
|
302
|
+
key = BigInt(key)
|
|
303
|
+
}
|
|
301
304
|
if (!this.index) {
|
|
302
305
|
await this.getIndex()
|
|
303
306
|
}
|
|
@@ -312,21 +315,35 @@ export class RangeDB {
|
|
|
312
315
|
return RangeDB.findInChunk(key, chunkBuffer)
|
|
313
316
|
}
|
|
314
317
|
|
|
318
|
+
/**
|
|
319
|
+
* Get a string from database for a given key or null if not exists
|
|
320
|
+
*
|
|
321
|
+
* @param {bigint | number} key
|
|
322
|
+
*
|
|
323
|
+
* @returns {Promise<string | null>}
|
|
324
|
+
*/
|
|
325
|
+
async getString(key) {
|
|
326
|
+
const buffer = await this.getRaw(key)
|
|
327
|
+
if (buffer === null) {
|
|
328
|
+
return null
|
|
329
|
+
}
|
|
330
|
+
return new TextDecoder().decode(buffer)
|
|
331
|
+
}
|
|
332
|
+
|
|
315
333
|
/**
|
|
316
334
|
* Get a JSON from database for a given key or null if not exists
|
|
317
335
|
* It may throw JSON parsing error
|
|
318
336
|
*
|
|
319
|
-
* @param {bigint} key
|
|
337
|
+
* @param {bigint | number} key
|
|
320
338
|
*
|
|
321
339
|
* @returns {Promise<JSONValue | null>}
|
|
322
340
|
* @throws {SyntaxError}
|
|
323
341
|
*/
|
|
324
342
|
async getJson(key) {
|
|
325
|
-
const
|
|
326
|
-
if (
|
|
343
|
+
const str = await this.getString(key)
|
|
344
|
+
if (str === null) {
|
|
327
345
|
return null
|
|
328
346
|
}
|
|
329
|
-
|
|
330
|
-
return JSON.parse(string)
|
|
347
|
+
return JSON.parse(str)
|
|
331
348
|
}
|
|
332
349
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rangedb/js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"repository": {
|
|
6
|
+
"url": "https://github.com/RangeDB/rangedb"
|
|
7
|
+
},
|
|
5
8
|
"main": "./index.js",
|
|
6
9
|
"types": "./dist/index.d.ts",
|
|
7
10
|
"exports": {
|
|
@@ -11,7 +14,7 @@
|
|
|
11
14
|
}
|
|
12
15
|
},
|
|
13
16
|
"scripts": {
|
|
14
|
-
"build:types": "
|
|
17
|
+
"build:types": "tsc",
|
|
15
18
|
"prepare": "npm run build:types",
|
|
16
19
|
"test": "node --test --experimental-test-coverage",
|
|
17
20
|
"test:watch": "node --test --watch"
|
|
@@ -25,6 +28,6 @@
|
|
|
25
28
|
],
|
|
26
29
|
"publishConfig": {
|
|
27
30
|
"access": "public",
|
|
28
|
-
"provenance":
|
|
31
|
+
"provenance": true
|
|
29
32
|
}
|
|
30
33
|
}
|