From c297c191f3acea4fccf0bb67bd3c1cc0728033c8 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 27 Aug 2024 07:51:10 -0700 Subject: [PATCH] chore: clean up dead code --- .../64:crabble-start/test-crabble-start.js | 6 +- proposals/75:upgrade-16/vatDetails.js | 100 ------------------ 2 files changed, 3 insertions(+), 103 deletions(-) delete mode 100644 proposals/75:upgrade-16/vatDetails.js diff --git a/proposals/64:crabble-start/test-crabble-start.js b/proposals/64:crabble-start/test-crabble-start.js index 800106d2..8a8da349 100644 --- a/proposals/64:crabble-start/test-crabble-start.js +++ b/proposals/64:crabble-start/test-crabble-start.js @@ -50,8 +50,8 @@ import { } from './core-eval-support.js'; /** @typedef {Awaited>} TestContext */ -/** @type {import('ava').TestFn}} */ -const test = anyTest; + +const test = /** @type {import('ava').TestFn}} */ (anyTest); const assetInfo = { /** @type {Record} */ @@ -208,7 +208,7 @@ const getFileSize = async (src, fileName) => { return size; }; -/** @param {import('./lib/webAsset.js').FileRd} src */ +/** @param {import('@agoric/synthetic-chain').FileRd} src */ const readBundleSizes = async src => { const info = staticConfig.buildInfo; const bundleSizes = await Promise.all( diff --git a/proposals/75:upgrade-16/vatDetails.js b/proposals/75:upgrade-16/vatDetails.js deleted file mode 100644 index ccf24608..00000000 --- a/proposals/75:upgrade-16/vatDetails.js +++ /dev/null @@ -1,100 +0,0 @@ -import dbOpenAmbient from 'better-sqlite3'; - -const HOME = process.env.HOME; - -/** @type {(val: T | undefined) => T} */ -export const NonNullish = val => { - if (!val) throw Error('required'); - return val; -}; - -/** - * @file look up vat incarnation from kernel DB - * @see {getIncarnation} - */ - -const swingstorePath = `${HOME}/.agoric/data/agoric/swingstore.sqlite`; - -/** - * SQL short-hand - * - * @param {import('better-sqlite3').Database} db - */ -export const dbTool = db => { - const prepare = (strings, ...params) => { - const dml = strings.join('?'); - return { stmt: db.prepare(dml), params }; - }; - const sql = (strings, ...args) => { - const { stmt, params } = prepare(strings, ...args); - return stmt.all(...params); - }; - sql.get = (strings, ...args) => { - const { stmt, params } = prepare(strings, ...args); - return stmt.get(...params); - }; - return sql; -}; - -/** - * @param {import('better-sqlite3').Database} db - */ -const makeSwingstore = db => { - const sql = dbTool(db); - - /** @param {string} key */ - const kvGet = key => sql.get`select * from kvStore where key = ${key}`.value; - /** @param {string} key */ - const kvGetJSON = key => JSON.parse(kvGet(key)); - - /** @param {string} vatID */ - const lookupVat = vatID => { - return Object.freeze({ - source: () => kvGetJSON(`${vatID}.source`), - options: () => kvGetJSON(`${vatID}.options`), - currentSpan: () => - sql.get`select * from transcriptSpans where isCurrent = 1 and vatID = ${vatID}`, - }); - }; - - return Object.freeze({ - /** @param {string} vatName */ - findVat: vatName => { - /** @type {string[]} */ - const dynamicIDs = kvGetJSON('vat.dynamicIDs'); - const targetVat = dynamicIDs.find(vatID => - lookupVat(vatID).options().name.includes(vatName), - ); - if (!targetVat) throw Error(`vat not found: ${vatName}`); - return targetVat; - }, - /** @param {string} vatName */ - findVats: vatName => { - /** @type {string[]} */ - const dynamicIDs = kvGetJSON('vat.dynamicIDs'); - return dynamicIDs.filter(vatID => - lookupVat(vatID).options().name.includes(vatName), - ); - }, - lookupVat, - }); -}; - -/** @param {string} vatName */ -export const getDetailsMatchingVats = async vatName => { - const kStore = makeSwingstore( - dbOpenAmbient(swingstorePath, { readonly: true }), - ); - - const vatIDs = kStore.findVats(vatName); - const infos = []; - for (const vatID of vatIDs) { - const vatInfo = kStore.lookupVat(vatID); - const source = vatInfo.source(); - // @ts-expect-error cast - const { incarnation } = vatInfo.currentSpan(); - infos.push({ vatName, vatID, incarnation, ...source }); - } - - return infos; -};