@xyo-network/previous-hash-store-storage 4.3.0 → 5.0.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/previous-hash-store-storage",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -28,16 +28,20 @@
|
|
|
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": "^
|
|
36
|
+
"@xylabs/hex": "^5.0.0",
|
|
37
|
+
"@xyo-network/previous-hash-store-model": "^5.0.0",
|
|
34
38
|
"store2": "^2.14.4"
|
|
35
39
|
},
|
|
36
40
|
"devDependencies": {
|
|
37
41
|
"@types/node": "^24.1.0",
|
|
38
42
|
"@types/uuid": "^10.0.0",
|
|
39
|
-
"@xylabs/ts-scripts-yarn3": "^7.0.
|
|
40
|
-
"@xylabs/tsconfig": "^7.0.
|
|
43
|
+
"@xylabs/ts-scripts-yarn3": "^7.0.2",
|
|
44
|
+
"@xylabs/tsconfig": "^7.0.2",
|
|
41
45
|
"typescript": "^5.8.3",
|
|
42
46
|
"uuid": "^11.1.0",
|
|
43
47
|
"vitest": "^3.2.4"
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type Address, asHash } from '@xylabs/hex'
|
|
2
|
+
import { v4 as uuid } from 'uuid'
|
|
3
|
+
import {
|
|
4
|
+
describe, expect, it,
|
|
5
|
+
} from 'vitest'
|
|
6
|
+
|
|
7
|
+
import type { Storage } from '../StoragePreviousHashStore.ts'
|
|
8
|
+
import { StoragePreviousHashStore } from '../StoragePreviousHashStore.ts'
|
|
9
|
+
|
|
10
|
+
describe('StoragePreviousHashStore', () => {
|
|
11
|
+
const previousHash = asHash('2e8de18ece40481f132e6d2f05617e05cd896a9098d28ed65afdf0d72203b490', true)
|
|
12
|
+
const storageTypesRecord: Record<Storage, boolean> = {
|
|
13
|
+
local: true,
|
|
14
|
+
page: true,
|
|
15
|
+
session: true,
|
|
16
|
+
}
|
|
17
|
+
const StorageTypes: Storage[] = Object.keys(storageTypesRecord) as Storage[]
|
|
18
|
+
|
|
19
|
+
describe('ctor', () => {
|
|
20
|
+
it('with no opts uses default values', () => {
|
|
21
|
+
const store = new StoragePreviousHashStore()
|
|
22
|
+
expect(store).toBeInstanceOf(StoragePreviousHashStore)
|
|
23
|
+
expect(store.namespace).toBe(StoragePreviousHashStore.DefaultNamespace)
|
|
24
|
+
expect(store.type).toBe(StoragePreviousHashStore.DefaultStorageType)
|
|
25
|
+
})
|
|
26
|
+
it('with opts uses opt values', () => {
|
|
27
|
+
const namespace = 'test'
|
|
28
|
+
const type: Storage = 'session'
|
|
29
|
+
const store = new StoragePreviousHashStore({ namespace, type })
|
|
30
|
+
expect(store).toBeInstanceOf(StoragePreviousHashStore)
|
|
31
|
+
expect(store.namespace).toBe(namespace)
|
|
32
|
+
expect(store.type).toBe(type)
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
describe.each(StorageTypes)('%s', (_storageType: Storage) => {
|
|
36
|
+
describe('getItem', () => {
|
|
37
|
+
it('with no value returns null', async () => {
|
|
38
|
+
const store = new StoragePreviousHashStore()
|
|
39
|
+
const address = uuid().toLowerCase() as Address
|
|
40
|
+
expect(await store.getItem(address)).toBe(null)
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
describe('round trip storage', () => {
|
|
44
|
+
it('sets/retrieves an item', async () => {
|
|
45
|
+
const store = new StoragePreviousHashStore()
|
|
46
|
+
const address = uuid().toLowerCase() as Address
|
|
47
|
+
await store.setItem(address, previousHash)
|
|
48
|
+
expect(await store.getItem(address)).toBe(previousHash)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
describe('removeItem', () => {
|
|
52
|
+
it('removes an item', async () => {
|
|
53
|
+
const store = new StoragePreviousHashStore()
|
|
54
|
+
const address = uuid().toLowerCase() as Address
|
|
55
|
+
await store.setItem(address, previousHash)
|
|
56
|
+
expect(await store.getItem(address)).toBe(previousHash)
|
|
57
|
+
await store.removeItem(address)
|
|
58
|
+
expect(await store.getItem(address)).toBe(null)
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
})
|