npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bevingh/ledger

v0.1.0

Published

Wallet row-lock debit/credit helpers parameterized by DB executor (FOR UPDATE + balance mutation + idempotency_key) — wallet_row_lock_engine only.

Readme

@bevingh/ledger

Phase 3 / PR-17 — extracted (last package). wallet_row_lock_engine only. No Prisma, no Moolre, no tax ledger.

Purpose

Wallet row-lock debit helpers parameterized by a DB executor (SELECT … FOR UPDATE + balance mutation + unique idempotency_key) — Didipay champion.

| Field | Value | |---|---| | surfaceShape | pure_core | | dependsOnPackages | @bevingh/money, @bevingh/idempotency (real implementations) | | extractionOrderHint | 7 | | status | extracted (implementation + tests) |

Permanent boundaries (do not “resolve and remove”)

| Out of scope | Why | |---|---| | tax_accounting_ledger / LedgerEntry P&L | Different semantic (KD5); document-only in Phase 1 | | loan_payment_lock (swift-cedi) | Project-specific per KD5 — permanently | | fulfillment status flips | @bevingh/fulfillment | | Prisma hard-coded | Caller supplies WalletLedgerExecutor | | Moolre / any external disbursement | Product side effect after ledger commit — see below |

Public API

import { executeWalletDebit, checkSpendEligibility } from '@bevingh/ledger';
import { assertPesewas } from '@bevingh/money'; // used internally for amounts

const result = await executeWalletDebit(
  {
    walletId,
    amount: 600,              // integer pesewas — validated via @bevingh/money
    idempotencyKey: key,      // domain unique via @bevingh/idempotency runWithDomainUniqueKey
    sourceBucket: 'primary',
  },
  executor, // your Prisma/SQL implementation of WalletLedgerExecutor
);

if (result.outcome === 'applied') {
  // ONLY NOW: external disbursement (Moolre, etc.) — not inside the package
  await initiateDisbursement(...).catch(queueRetry);
} else {
  // outcome === 'replayed' — same idempotency key, no second debit
}

| Export | Role | |---|---| | executeWalletDebit | Atomic debit orchestration | | WalletLedgerExecutor | Injected lock / plan / debit / insert / unique-detect | | checkSpendEligibility / computeAllocationTick | Pure Didipay policy | | LedgerError | Domain errors |

Correct vs Didipay’s current coupling

Didipay today (do not copy into package core):

BEGIN; FOR UPDATE; debit; insert txn; COMMIT;
Moolre.initiateDisbursement(...).catch(...)  // fire-and-forget, no ledger rollback

Package contract:

result = executeWalletDebit(...)   // atomic wallet + txn only
if (result.outcome === 'applied') {
  // caller-owned disbursement + retry — cannot be accidentally inside executor
}

Idempotency + money wiring

| Dependency | How used | |---|---| | @bevingh/money assertPesewas | Reject float / zero / negative spend amounts | | @bevingh/idempotency runWithDomainUniqueKey | Fits Didipay unique idempotency_key column — findExisting → execute → unique race re-find |

Tests (adapted from Didipay scripts)

| Scenario | Source | |---|---| | 3× concurrent spend 600 on balance 1000 → 1 win, balance 400 | concurrency-test.ts | | Deposit 1000, spend 300, funds reconcile | integrity-test.ts | | Same idempotency key → no double-debit | domain unique | | Invalid pesewas rejected | @bevingh/money | | Disbursement failure does not undo debit | separation doc test |

npm run test -w @bevingh/ledger
npm run build -w @bevingh/ledger

Champion files (read-only)

  • Didipay ledger.service.ts, policyEngine.ts
  • Didipay scripts/concurrency-test.ts, integrity-test.ts