From d1562a131b6712dc4c5b11d91afccd0f7f0a05e6 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 18 Nov 2024 16:49:05 -0500 Subject: [PATCH] chore(swing-store): Consolidate keyType assertions (#10471) ## Description Minor cleanup noticed in passing. ### Security Considerations n/a ### Scaling Considerations n/a ### Documentation Considerations n/a ### Testing Considerations n/a ### Upgrade Considerations n/a --- packages/swing-store/src/exporter.js | 1 - packages/swing-store/src/kvStore.js | 1 + packages/swing-store/src/swingStore.js | 2 -- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/swing-store/src/exporter.js b/packages/swing-store/src/exporter.js index 4b39a8c69a3..e8a6cc9fb62 100644 --- a/packages/swing-store/src/exporter.js +++ b/packages/swing-store/src/exporter.js @@ -133,7 +133,6 @@ export function makeSwingStoreExporter(dirPath, options = {}) { * section */ function getHostKV(key) { - typeof key === 'string' || Fail`key must be a string`; getKeyType(key) === 'host' || Fail`getHostKV requires host keys`; // @ts-expect-error unknown return sqlKVGet.get(key); diff --git a/packages/swing-store/src/kvStore.js b/packages/swing-store/src/kvStore.js index 646aaf3ae1c..4f8b58b5825 100644 --- a/packages/swing-store/src/kvStore.js +++ b/packages/swing-store/src/kvStore.js @@ -15,6 +15,7 @@ import { Fail } from '@endo/errors'; * @param {string} key */ export function getKeyType(key) { + typeof key === 'string' || Fail`key must be a string`; if (key.startsWith('local.')) { return 'local'; } else if (key.startsWith('host.')) { diff --git a/packages/swing-store/src/swingStore.js b/packages/swing-store/src/swingStore.js index 3bcfe08b5a2..314a3eb73ab 100644 --- a/packages/swing-store/src/swingStore.js +++ b/packages/swing-store/src/swingStore.js @@ -337,7 +337,6 @@ export function makeSwingStore(dirPath, forceReset, options = {}) { const kernelKVStore = { ...kvStore, set(key, value) { - typeof key === 'string' || Fail`key must be a string`; const keyType = getKeyType(key); keyType !== 'host' || Fail`kernelKVStore refuses host keys`; kvStore.set(key, value); @@ -352,7 +351,6 @@ export function makeSwingStore(dirPath, forceReset, options = {}) { } }, delete(key) { - typeof key === 'string' || Fail`key must be a string`; const keyType = getKeyType(key); keyType !== 'host' || Fail`kernelKVStore refuses host keys`; kvStore.delete(key);