feat(cache): jiti-owned cache-or-lookup layer + TON jetton enrichment#15
Merged
Conversation
8499f7e to
b523318
Compare
… in tokenTransfers
Adds a generic, multi-namespace "cache-or-lookup" enrichment layer that jiti owns end to
end — in-process L1, single-flight, negative caching, TTL/immutability, read-through/
write-through, the per-namespace resolvers, AND the resolver RPC. A consumer injects only
durable storage.
- src/cache: registry (namespace policies), core (cacheGet/cacheSet), CacheStorage interface.
- src/cache/resolvers/ton-jetton: resolves a jetton wallet -> {owner, master} via get_wallet_data
(TEP-74) over the free Orbs gateway with host rotation; registers the immutable
`ton-jetton-wallet` namespace. This is the one place jiti performs network RPC, and only on
the enrichment path.
- src/cache/storage/postgres: a ready-made createPostgresCacheStorage(uri) — a jiti consumer
(indexer, nbd) hands it a Postgres URI and injects the result. `pg` is an OPTIONAL peer
dependency, lazy-required so it never bundles or loads for consumers that don't use the cache
(e.g. oscar's pacemaker).
The token-transfers template enriches TON jetton transfers (`tokenType:'TOKEN'`, `to` = wallet,
`token` undefined) -> rewrites `to = owner`, `token = master` BEFORE the contractAddress/
walletAddress filters, but ONLY when the caller injects `_ctx.cacheStorage`. With no storage
injected, transform is sync and byte-identical to before — every existing caller (oscar
pacemaker, etc.) is unaffected. Filter logic extracted to applyTransferFilters.
b523318 to
1344b4c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves the entire cache-or-lookup enrichment layer into jiti (per direction): jiti owns the cache orchestration and the resolvers and the resolver RPC. A consumer injects only durable storage — and jiti ships a ready-made Postgres adapter so the consumer just hands it a URI.
What jiti now owns (
src/cache/)index.ts):cacheGet/cacheSet— in-process L1, single-flight, negative caching, TTL/immutability, read-through/write-through. Generic + multi-namespace.registry.ts): per-namespace policy (resolver, TTL, negative-TTL).CacheStorageinterface (types.ts): the only thing a consumer implements.resolvers/ton-jetton.ts): wallet →{owner, master}viaget_wallet_data(TEP-74) over the free Orbs gateway with host rotation; registers the immutableton-jetton-walletnamespace. The one place jiti does network RPC, only on the enrichment path.storage/postgres.ts):createPostgresCacheStorage({ connectionUri })— indexer/nbd import it, pass a URI, inject. Thejiti_cachetable self-creates.pgis an optional peer dependency, lazy-required so it never bundles/loads for consumers that don't use the cache (e.g. oscar's pacemaker) — verified not in the parcel bundle.token-transfers
Enriches TON jetton transfers (
tokenType:'TOKEN',to= wallet,tokenundefined) →to = owner,token = master, before the contractAddress/walletAddress filters — but only when_ctx.cacheStorageis injected. Opt-in / non-breaking: no storage →transformis sync and byte-identical to today; existing callers (oscar pacemaker, etc.) unaffected.Consumer side (follow-up, indexer)
Indexer drops its own jiti-cache + resolver and shrinks to:
import { createPostgresCacheStorage } from '@indexing/jiti', pass the recent-DB URI (gated byJITI_CACHE_DB_URI), inject as_ctx.cacheStorage. NBD does the same at migration.Notes
createPostgresCacheStorageindist/types.d.ts;pgexternalized.npm test(fetches real blocks, needsAPI_KEY) not run locally — sync path unchanged, existing template tests unaffected.eval-require targets CommonJS consumers (indexer/nbd are CJS).