import type { MutableAtomToken, WritablePureSelectorFamilyToken, WritablePureSelectorToken, } from "atom.io" import { parseJson } from "atom.io/foundations/json" import { findInStore } from "../families/index.ts" import { newest } from "../lineage.ts" import { type Store, withdraw } from "../store/index.ts" import type { AsJSON, Transceiver } from "./transceiver.ts" export const getJsonTokenFromStore = >( store: Store, mutableAtomToken: MutableAtomToken, ): WritablePureSelectorToken> => { if (mutableAtomToken.family) { const target = newest(store) const jsonFamilyKey = `${mutableAtomToken.family.key}:JSON` const jsonFamilyToken: WritablePureSelectorFamilyToken, string> = { key: jsonFamilyKey, type: `writable_pure_selector_family`, } const family = withdraw(target, jsonFamilyToken) const subKey = parseJson(mutableAtomToken.family.subKey) const jsonToken = findInStore(store, family, subKey) return jsonToken } const token: WritablePureSelectorToken> = { type: `writable_pure_selector`, key: `${mutableAtomToken.key}:JSON`, } return token }