Adds studbook records and pedigree-based genetics analysis to Payload collections through a GET endpoint that computes and redacts results. Your app supplies the data and every access decision through callbacks. Optional numbering endpoints store studbook numbers in a collection that needs two unique database indexes; only MongoDB is tested. Early alpha, licensed PolyForm Noncommercial.
OnePedigree studbook: species-neutral studbook numbering, pedigree-based kinship, inbreeding, mean kinship, gene diversity and founder analysis, and PMx export, for any managed population.
Installation
npm i @extantape/onepedigree-studbook0
Stars
0
Forks
4
Open Issues
Yesterday
Last Updated
961
Weekly Downloads
v0.1.0-alpha.27
npm Version
51.8 KB
Unpacked Size
1
Dependencies
00 since Oct 25
| Date | Stars |
|---|---|
| Dec 5, 2026 | 0 |
| Dec 4, 2026 | 0 |
| Dec 3, 2026 | 0 |
| Dec 2, 2026 | 0 |
| Dec 1, 2026 | 0 |
| Nov 30, 2026 | 0 |
| Nov 29, 2026 | 0 |
| Nov 28, 2026 | 0 |
| Nov 27, 2026 | 0 |
| Nov 26, 2026 | 0 |
| Nov 25, 2026 | 0 |
| Nov 24, 2026 | 0 |
| Nov 23, 2026 | 0 |
| Nov 22, 2026 | 0 |
| Nov 21, 2026 | 0 |
| Nov 20, 2026 | 0 |
| Nov 19, 2026 | 0 |
| Nov 18, 2026 | 0 |
| Nov 17, 2026 | 0 |
| Nov 16, 2026 | 0 |
| Nov 15, 2026 | 0 |
| Nov 14, 2026 | 0 |
| Nov 13, 2026 | 0 |
| Nov 12, 2026 | 0 |
| Nov 11, 2026 | 0 |
| Nov 10, 2026 | 0 |
| Nov 9, 2026 | 0 |
| Nov 8, 2026 | 0 |
| Nov 7, 2026 | 0 |
| Nov 6, 2026 | 0 |
| Nov 5, 2026 | 0 |
| Nov 4, 2026 | 0 |
| Nov 3, 2026 | 0 |
| Nov 2, 2026 | 0 |
| Nov 1, 2026 | 0 |
| Oct 31, 2026 | 0 |
| Oct 30, 2026 | 0 |
| Oct 29, 2026 | 0 |
| Oct 28, 2026 | 0 |
| Oct 27, 2026 | 0 |
| Oct 26, 2026 | 0 |
| Oct 25, 2026 | 0 |
Shared by 2 plugins in ExtantApe/OnePedigree.
1K+1K since Nov 15
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 1,011 |
| Dec 4, 2026 | 1,311 |
| Dec 3, 2026 | 1,332 |
| Dec 2, 2026 | 1,308 |
| Dec 1, 2026 | 817 |
| Nov 30, 2026 | 684 |
| Nov 29, 2026 | 753 |
| Nov 28, 2026 | 687 |
| Nov 27, 2026 | 325 |
| Nov 26, 2026 | 269 |
| Nov 25, 2026 | 231 |
| Nov 24, 2026 | 189 |
| Nov 23, 2026 | 300 |
| Nov 22, 2026 | 192 |
| Nov 21, 2026 | 190 |
| Nov 20, 2026 | 186 |
| Nov 19, 2026 | 181 |
| Nov 18, 2026 | 175 |
| Nov 17, 2026 | 161 |
| Nov 16, 2026 | 0 |
| Nov 15, 2026 | 0 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1440463679-studbook)<a href="https://payloaddirectory.dev/plugins/1440463679-studbook"><img src="https://payloaddirectory.dev/badge/1440463679-studbook.svg" alt="Payload Directory"></a>README
Studbook-style records and analysis for any managed population, built on OnePedigree. Early alpha: the calculations below are tested against textbook values, and nothing here has been checked against a real studbook or PMx run yet.
nextStudbookNumber, renumber (keeps every old number) and checkStudbookNumbers (duplicates, reuse, malformed numbers; gaps are a notice).@extantape/onepedigree-studbook/payload adds GET /<collection>/studbook/:studbook to a Payload collection. Your app supplies the data and every access decision; the endpoint computes and redacts:
import { studbookEndpoint } from '@extantape/onepedigree-studbook/payload'
endpoints: [studbookEndpoint({
source: ({ studbook, req }) => loadStudbook(studbook, req), // read as the request's user; null is a 404
geneticsVisibleFor: ({ animal, req }) => isCoordinator(req) || ownsAnimal(req, animal),
canExport: ({ req }) => isCoordinatorOrKeeper(req),
holderLabel: (code, req) => holderNameFor(code, req), // or "Private holder"
})]
{ private: true }, and are never named as a parent, founder or holder.mult.geneticsVisibleFor says yes. Population GD, FGE and founders come back only when the reader may see every animal's numbers, private animals included, since GD would otherwise give the hidden ones away.?format=pmx returns the PMx .ped file to those canExport allows, and 403 to everyone else.true, counts as no.studbookNumberEndpoints({ source, numbers }) keeps studbook numbers in a collection of yours, one document per studbook and animal. POST …/studbook/:studbook/numbers { animal, temporary?, number? } gives a first number. POST …/numbers/renumber { animal, to? } moves an animal to a new number and keeps the old one; it's only offered when you name an oldNumbersField. Writes use the reader's own access, and numbers held by animals they can't see are never reused.
Breaking change in the release after 0.1.0-alpha.27: numbering now needs the two unique indexes below in the database. Until they are there, both endpoints answer 500 and write nothing.
The number collection needs two unique indexes, which studbookNumberIndexes(numbers) declares: add indexes: [...studbookNumberIndexes(numbers)] to it. They are what keeps one number off two animals and one animal to one document when requests arrive together. The database enforces them for every server process; two real server processes were not tested, and the tests stand in for the second one with a write made while the endpoint's write is held. A request that meets a number someone else just took reads again and takes the next one. Requests for one studbook in one process run one at a time, and so do requests that share a transaction. A number an animal has moved off stays reserved through oldNumbersField, which is read before each write and again after it. A renumber reads and writes in one transaction, so two changes to one animal from two processes can't overwrite each other on MongoDB with transactions (a replica set). Without database transactions, or on a SQL adapter at its default isolation, that last case isn't guarded between processes. Only MongoDB is tested.
Declaring the indexes doesn't build them. The MongoDB adapter builds them at startup only with ensureIndexes: true; with it off they are built in the background, and a failed build is silent. So before every write the endpoints ask the database which indexes it has. Unless both are there, unique, on exactly those two fields each and not partial, the answer is 500, nothing is written, and the server log says which index is missing and names up to three stored duplicates for each if that is why. To set it up:
Clear duplicates first, because the database can't build a unique index over them. In mongosh, with your own collection and field names:
const twice = (field) => db.getCollection('studbook-numbers').aggregate([
{ $group: { _id: { studbook: '$studbook', value: '$' + field }, count: { $sum: 1 }, ids: { $push: '$_id' } } },
{ $match: { count: { $gt: 1 } } },
])
twice('number') // one number on two animals
twice('animal') // two documents for one animal
Decide which document of each pair is right, and renumber or remove the other.
The indexes cover the whole number collection, so one stored duplicate blocks numbering in every studbook of that collection, including studbooks with no duplicate of their own. Run both searches across the whole collection, as above, and clear everything they find.
Start the server with ensureIndexes: true on the adapter. Payload then waits for the indexes before it finishes connecting.
If duplicates are still stored at step 2, the server doesn't start: Payload reports that it cannot connect to MongoDB, with MongoDB's own E11000 duplicate key error naming the index and the first duplicate value. That message is Payload's and MongoDB's, and this package can't reword it. Go back to step 1.
To get the clearer message at startup with ensureIndexes off, call studbookNumberIndexProblem(payload, numbers) in onInit. It gives null when both indexes are there, or the same text the endpoints log, and you can throw it. Just after a start with ensureIndexes off, the background build may still be running, so a message in onInit can come early, and numbering answers 500 for as long as the build takes. Turning ensureIndexes on avoids both.
On a database other than MongoDB the package can't list the indexes itself, so numbering is refused unless you pass indexesInDatabase in numbers: a function that answers true once the database has both. That path is not tested against a real SQL database.
When two server processes number the same animal at the same moment and pick the same number, one write is stored and the database refuses the other as a duplicate. The refused request answers 409 with "The number collection refused a write as a duplicate, and this animal already holds the number this request meant to give it. Either another request stored it at the same moment, or a hook of yours refused its own write to the number collection after this request stored it. Read the animal's current number before trying again." This is tested on MongoDB only.
A renumber can meet the same overlap: its write is refused because another animal just took the number, and before it reads again another request has moved this animal to that number. What it answers depends on database transactions. With transactions on, the refused write starts the renumber again from a fresh read. It finds the animal already moved and moves it once more, so it answers 200 with the next number, and the number the other request gave is kept among the old numbers. With transactions off, it answers the 409 above and stores nothing.
Only the number collection's own refusal counts for that 409: Payload's unique-value error for the number collection naming the studbook field with Payload's own "must be unique" wording, or MongoDB's duplicate-key error for that collection whose key is the studbook and number fields or the studbook and animal fields. A validation error that a hook of yours on the number collection raises with other wording is handled as the next paragraph says. A hook that copies Payload's wording exactly looks like a real refusal and gets the 409. A unique error from anywhere else, such as one a hook of yours raises after the write, is handled as the next paragraph says. A hook of yours that itself writes to the number collection can hit the same unique index. Payload's MongoDB adapter then raises the very error the endpoint counts. If the request's own number was already stored, the endpoint answers 409 although that number stays stored and only the hook's write was refused. The 409 text says both possibilities, so read the animal's current number after it. Better to keep such hooks from writing studbook numbers, or have them write to another collection.
With database transactions off, a hook of yours on the number collection that throws after a write (an afterChange, for example) can't undo the write. The endpoint then answers 201 or 200 with the stored number and a notices line saying a later step failed, and logs the error. With transactions on, the write is rolled back and the error is passed on.
Payload is an optional peer dependency; the main entry point doesn't use it.
Not affiliated with any zoo association or software vendor. "PMx" names the free analysis program whose input format this package will write.
PolyForm Noncommercial 1.0.0. See LICENSE.
payload
Parentage fields, cycle-safe writes and permission-aware pedigree endpoints for breeding and genealogy records
66902/wk0v3
payload plugin datacircle
Datacircle GTM API benchmark data as Payload endpoints, a selector field and a server-side client
77227/wk0v3
payload operations
Typed custom RPC operations for Payload with shared Zod contracts, server endpoints and type-safe clients
77208/wk3v3
payload plugin scan
Read barcodes and QR codes by camera or USB scanner, and resolve scan links by signed-in user without allowing probing
76328/wk0v3
payload plugin guard
Central access policy file, typed predicates and guarded endpoints for Payload plugins and Local API calls
73664/wk37v3