@bsv/wallet-toolbox 1.3.9 → 1.3.11
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/docs/client.md +3 -0
- package/docs/storage.md +2 -0
- package/docs/wallet.md +3 -0
- package/out/src/sdk/WalletStorage.interfaces.d.ts +1 -0
- package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
- package/out/src/storage/StorageIdb.js +10 -10
- package/out/src/storage/StorageIdb.js.map +1 -1
- package/out/src/storage/WalletStorageManager.d.ts +1 -0
- package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/out/src/storage/WalletStorageManager.js +11 -3
- package/out/src/storage/WalletStorageManager.js.map +1 -1
- package/out/src/storage/remoting/StorageClient.d.ts +1 -1
- package/out/src/storage/remoting/StorageClient.d.ts.map +1 -1
- package/out/src/storage/remoting/StorageClient.js +1 -1
- package/out/src/storage/remoting/StorageClient.js.map +1 -1
- package/out/test/storage/idb/idbSpeed.test.js +1 -0
- package/out/test/storage/idb/idbSpeed.test.js.map +1 -1
- package/out/test/storage/idb/update.test.js +8 -8
- package/out/test/storage/idb/update.test.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/sdk/WalletStorage.interfaces.ts +1 -0
- package/src/storage/StorageIdb.ts +10 -10
- package/src/storage/WalletStorageManager.ts +12 -3
- package/src/storage/remoting/StorageClient.ts +2 -2
- package/test/storage/idb/idbSpeed.test.ts +2 -0
- package/test/storage/idb/update.test.ts +8 -9
package/package.json
CHANGED
|
@@ -2195,7 +2195,7 @@ export class StorageIdb extends StorageProvider implements sdk.WalletStorageProv
|
|
|
2195
2195
|
const val = entity[key]
|
|
2196
2196
|
if (val === null) {
|
|
2197
2197
|
entity[key] = undefined
|
|
2198
|
-
} else if (
|
|
2198
|
+
} else if (val instanceof Uint8Array) {
|
|
2199
2199
|
entity[key] = Array.from(val)
|
|
2200
2200
|
}
|
|
2201
2201
|
}
|
|
@@ -2223,7 +2223,7 @@ export class StorageIdb extends StorageProvider implements sdk.WalletStorageProv
|
|
|
2223
2223
|
booleanFields?: string[]
|
|
2224
2224
|
): Partial<T> {
|
|
2225
2225
|
if (!this.dbtype) throw new sdk.WERR_INTERNAL('must call verifyReadyForDatabaseAccess first')
|
|
2226
|
-
const v: any = update
|
|
2226
|
+
const v: any = { ...update }
|
|
2227
2227
|
if (v.created_at) v.created_at = this.validateEntityDate(v.created_at)
|
|
2228
2228
|
if (v.updated_at) v.updated_at = this.validateEntityDate(v.updated_at)
|
|
2229
2229
|
if (!v.created_at) delete v.created_at
|
|
@@ -2241,10 +2241,10 @@ export class StorageIdb extends StorageProvider implements sdk.WalletStorageProv
|
|
|
2241
2241
|
}
|
|
2242
2242
|
for (const key of Object.keys(v)) {
|
|
2243
2243
|
const val = v[key]
|
|
2244
|
-
if (Array.isArray(val) && (val.length === 0 ||
|
|
2245
|
-
v[key] =
|
|
2246
|
-
} else if (val ===
|
|
2247
|
-
v[key] =
|
|
2244
|
+
if (Array.isArray(val) && (val.length === 0 || Number.isInteger(val[0]))) {
|
|
2245
|
+
v[key] = Uint8Array.from(val)
|
|
2246
|
+
} else if (val === null) {
|
|
2247
|
+
v[key] = undefined
|
|
2248
2248
|
}
|
|
2249
2249
|
}
|
|
2250
2250
|
this.isDirty = true
|
|
@@ -2279,10 +2279,10 @@ export class StorageIdb extends StorageProvider implements sdk.WalletStorageProv
|
|
|
2279
2279
|
}
|
|
2280
2280
|
for (const key of Object.keys(v)) {
|
|
2281
2281
|
const val = v[key]
|
|
2282
|
-
if (Array.isArray(val) && (val.length === 0 ||
|
|
2283
|
-
v[key] =
|
|
2284
|
-
} else if (val ===
|
|
2285
|
-
v[key] =
|
|
2282
|
+
if (Array.isArray(val) && (val.length === 0 || Number.isInteger(val[0]))) {
|
|
2283
|
+
v[key] = Uint8Array.from(val)
|
|
2284
|
+
} else if (val === null) {
|
|
2285
|
+
v[key] = undefined
|
|
2286
2286
|
}
|
|
2287
2287
|
}
|
|
2288
2288
|
this.isDirty = true
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
} from '../storage/schema/tables'
|
|
23
23
|
import { wait } from '../utility/utilityHelpers'
|
|
24
24
|
import { StorageProvider } from './StorageProvider'
|
|
25
|
+
import { StorageClient } from './remoting/StorageClient'
|
|
25
26
|
|
|
26
27
|
class ManagedStorage {
|
|
27
28
|
isAvailable: boolean
|
|
@@ -704,6 +705,11 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
704
705
|
return log
|
|
705
706
|
}
|
|
706
707
|
|
|
708
|
+
getStoreEndpointURL(store: ManagedStorage): string | undefined {
|
|
709
|
+
if (store.storage.constructor.name === 'StorageClient') return (store.storage as StorageClient).endpointUrl
|
|
710
|
+
return undefined
|
|
711
|
+
}
|
|
712
|
+
|
|
707
713
|
getStores(): sdk.WalletStorageInfo[] {
|
|
708
714
|
const stores: sdk.WalletStorageInfo[] = []
|
|
709
715
|
if (this._active) {
|
|
@@ -715,7 +721,8 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
715
721
|
userId: this._active.user!.userId,
|
|
716
722
|
storageIdentityKey: this._active.settings!.storageIdentityKey,
|
|
717
723
|
storageName: this._active.settings!.storageName,
|
|
718
|
-
storageClass: this._active.storage.constructor.name
|
|
724
|
+
storageClass: this._active.storage.constructor.name,
|
|
725
|
+
endpointURL: this.getStoreEndpointURL(this._active)
|
|
719
726
|
})
|
|
720
727
|
}
|
|
721
728
|
for (const store of this._conflictingActives || []) {
|
|
@@ -727,7 +734,8 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
727
734
|
userId: store.user!.userId,
|
|
728
735
|
storageIdentityKey: store.settings!.storageIdentityKey,
|
|
729
736
|
storageName: store.settings!.storageName,
|
|
730
|
-
storageClass: store.storage.constructor.name
|
|
737
|
+
storageClass: store.storage.constructor.name,
|
|
738
|
+
endpointURL: this.getStoreEndpointURL(store)
|
|
731
739
|
})
|
|
732
740
|
}
|
|
733
741
|
for (const store of this._backups || []) {
|
|
@@ -739,7 +747,8 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
739
747
|
userId: store.user!.userId,
|
|
740
748
|
storageIdentityKey: store.settings!.storageIdentityKey,
|
|
741
749
|
storageName: store.settings!.storageName,
|
|
742
|
-
storageClass: store.storage.constructor.name
|
|
750
|
+
storageClass: store.storage.constructor.name,
|
|
751
|
+
endpointURL: this.getStoreEndpointURL(store)
|
|
743
752
|
})
|
|
744
753
|
}
|
|
745
754
|
return stores
|
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
* For details of the API implemented, follow the "See also" link for the `WalletStorageProvider` interface.
|
|
39
39
|
*/
|
|
40
40
|
export class StorageClient implements sdk.WalletStorageProvider {
|
|
41
|
-
|
|
41
|
+
readonly endpointUrl: string
|
|
42
42
|
private readonly authClient: AuthFetch
|
|
43
43
|
private nextId = 1
|
|
44
44
|
|
|
@@ -507,7 +507,7 @@ export class StorageClient implements sdk.WalletStorageProvider {
|
|
|
507
507
|
const val = entity[key]
|
|
508
508
|
if (val === null) {
|
|
509
509
|
entity[key] = undefined
|
|
510
|
-
} else if (
|
|
510
|
+
} else if (val instanceof Uint8Array) {
|
|
511
511
|
entity[key] = Array.from(val)
|
|
512
512
|
}
|
|
513
513
|
}
|
|
@@ -207,14 +207,13 @@ describe('update tests', () => {
|
|
|
207
207
|
expect(actualValue).toBe(value)
|
|
208
208
|
continue
|
|
209
209
|
}
|
|
210
|
-
if (typeof actualValue === 'object' && actualValue
|
|
211
|
-
const actualArray = actualValue
|
|
212
|
-
const expectedArray =
|
|
213
|
-
Buffer.isBuffer(value) || Array.isArray(value) ? Array.from(value as ArrayLike<number>) : value
|
|
210
|
+
if (typeof actualValue === 'object' && Array.isArray(actualValue)) {
|
|
211
|
+
const actualArray = actualValue
|
|
212
|
+
const expectedArray = value
|
|
214
213
|
expect(actualArray).toStrictEqual(expectedArray)
|
|
215
214
|
continue
|
|
216
215
|
}
|
|
217
|
-
expect(JSON.stringify(
|
|
216
|
+
expect(JSON.stringify(actualValue)).toStrictEqual(JSON.stringify(value))
|
|
218
217
|
}
|
|
219
218
|
} catch (error: any) {
|
|
220
219
|
console.error(
|
|
@@ -556,8 +555,8 @@ describe('update tests', () => {
|
|
|
556
555
|
expect(normalizedActual).toBe(normalizedExpected)
|
|
557
556
|
continue
|
|
558
557
|
}
|
|
559
|
-
if (
|
|
560
|
-
expect(
|
|
558
|
+
if (Array.isArray(actualValue)) {
|
|
559
|
+
expect(actualValue).toStrictEqual(value)
|
|
561
560
|
continue
|
|
562
561
|
}
|
|
563
562
|
expect(actualValue).toBe(value)
|
|
@@ -638,8 +637,8 @@ describe('update tests', () => {
|
|
|
638
637
|
expect(normalizedActual).toBe(normalizedExpected)
|
|
639
638
|
continue
|
|
640
639
|
}
|
|
641
|
-
if (
|
|
642
|
-
expect(
|
|
640
|
+
if (Array.isArray(actualValue)) {
|
|
641
|
+
expect(actualValue).toStrictEqual(value)
|
|
643
642
|
continue
|
|
644
643
|
}
|
|
645
644
|
expect(actualValue).toBe(value)
|