@xyo-network/previous-hash-store-indexeddb 4.3.0 → 5.0.1
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/package.json +15 -11
- package/src/spec/IndexedDbPreviousHashStore.spec.ts +73 -0
- package/xy.config.ts +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/previous-hash-store-indexeddb",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -28,20 +28,24 @@
|
|
|
28
28
|
},
|
|
29
29
|
"module": "dist/neutral/index.mjs",
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"src"
|
|
34
|
+
],
|
|
31
35
|
"dependencies": {
|
|
32
|
-
"@xylabs/hex": "
|
|
33
|
-
"@xyo-network/previous-hash-store-model": "
|
|
34
|
-
"idb": "
|
|
36
|
+
"@xylabs/hex": "~5.0.3",
|
|
37
|
+
"@xyo-network/previous-hash-store-model": "~5.0.1",
|
|
38
|
+
"idb": "~8.0.3"
|
|
35
39
|
},
|
|
36
40
|
"devDependencies": {
|
|
37
|
-
"@types/node": "
|
|
41
|
+
"@types/node": "~24.2.0",
|
|
38
42
|
"@types/uuid": "10.0.0",
|
|
39
|
-
"@xylabs/ts-scripts-yarn3": "
|
|
40
|
-
"@xylabs/tsconfig": "
|
|
41
|
-
"fake-indexeddb": "
|
|
42
|
-
"typescript": "
|
|
43
|
-
"uuid": "
|
|
44
|
-
"vitest": "
|
|
43
|
+
"@xylabs/ts-scripts-yarn3": "~7.1.0",
|
|
44
|
+
"@xylabs/tsconfig": "~7.1.0",
|
|
45
|
+
"fake-indexeddb": "~6.0.1",
|
|
46
|
+
"typescript": "~5.9.2",
|
|
47
|
+
"uuid": "~11.1.0",
|
|
48
|
+
"vitest": "~3.2.4"
|
|
45
49
|
},
|
|
46
50
|
"publishConfig": {
|
|
47
51
|
"access": "public"
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Address } from '@xylabs/hex'
|
|
2
|
+
import {
|
|
3
|
+
IDBCursor,
|
|
4
|
+
IDBCursorWithValue,
|
|
5
|
+
IDBDatabase,
|
|
6
|
+
IDBFactory,
|
|
7
|
+
IDBIndex,
|
|
8
|
+
IDBKeyRange,
|
|
9
|
+
IDBObjectStore,
|
|
10
|
+
IDBOpenDBRequest,
|
|
11
|
+
IDBRequest,
|
|
12
|
+
IDBTransaction,
|
|
13
|
+
IDBVersionChangeEvent,
|
|
14
|
+
indexedDB,
|
|
15
|
+
} from 'fake-indexeddb'
|
|
16
|
+
import { v4 as uuid } from 'uuid'
|
|
17
|
+
import {
|
|
18
|
+
describe, expect, it,
|
|
19
|
+
} from 'vitest'
|
|
20
|
+
|
|
21
|
+
import { IndexedDbPreviousHashStore } from '../IndexedDbPreviousHashStore.ts'
|
|
22
|
+
|
|
23
|
+
// Shim via fake-indexeddb
|
|
24
|
+
globalThis.indexedDB = indexedDB
|
|
25
|
+
|
|
26
|
+
// Augment window with prototypes to ensure instance of comparisons work
|
|
27
|
+
globalThis.IDBCursor = IDBCursor
|
|
28
|
+
globalThis.IDBCursorWithValue = IDBCursorWithValue
|
|
29
|
+
globalThis.IDBDatabase = IDBDatabase
|
|
30
|
+
globalThis.IDBFactory = IDBFactory
|
|
31
|
+
globalThis.IDBIndex = IDBIndex
|
|
32
|
+
globalThis.IDBKeyRange = IDBKeyRange
|
|
33
|
+
globalThis.IDBObjectStore = IDBObjectStore
|
|
34
|
+
globalThis.IDBOpenDBRequest = IDBOpenDBRequest
|
|
35
|
+
globalThis.IDBRequest = IDBRequest
|
|
36
|
+
globalThis.IDBTransaction = IDBTransaction
|
|
37
|
+
globalThis.IDBVersionChangeEvent = IDBVersionChangeEvent
|
|
38
|
+
|
|
39
|
+
describe('IndexedDbPreviousHashStore', () => {
|
|
40
|
+
const previousHash = '2e8de18ece40481f132e6d2f05617e05cd896a9098d28ed65afdf0d72203b490'
|
|
41
|
+
|
|
42
|
+
describe('ctor', () => {
|
|
43
|
+
it('creates DB/Store with default values', () => {
|
|
44
|
+
const store = new IndexedDbPreviousHashStore()
|
|
45
|
+
expect(store).toBeInstanceOf(IndexedDbPreviousHashStore)
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
describe('getItem', () => {
|
|
49
|
+
it('with no value returns null', async () => {
|
|
50
|
+
const store = new IndexedDbPreviousHashStore()
|
|
51
|
+
const address = uuid().toLowerCase() as Address
|
|
52
|
+
expect(await store.getItem(address)).toBe(null)
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
describe('round trip storage', () => {
|
|
56
|
+
it('sets/retrieves an item', async () => {
|
|
57
|
+
const store = new IndexedDbPreviousHashStore()
|
|
58
|
+
const address = uuid().toLowerCase() as Address
|
|
59
|
+
await store.setItem(address, previousHash)
|
|
60
|
+
expect(await store.getItem(address)).toBe(previousHash)
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
describe('removeItem', () => {
|
|
64
|
+
it('removes an item', async () => {
|
|
65
|
+
const store = new IndexedDbPreviousHashStore()
|
|
66
|
+
const address = uuid().toLowerCase() as Address
|
|
67
|
+
await store.setItem(address, previousHash)
|
|
68
|
+
expect(await store.getItem(address)).toBe(previousHash)
|
|
69
|
+
await store.removeItem(address)
|
|
70
|
+
expect(await store.getItem(address)).toBe(null)
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
})
|