db/fact_holder_queries.ts

Raw queries against fact_holder — the possession record.

A fact_holder row says an actor has put a fact's bytes. PgFactStore writes one on every put that names a holder (HeldFactPutOptions.holder), deduplicated puts included: identical bytes put again by a second actor make that actor a holder too. Cell ref admission (auth/cell_ref_admission.ts) reads it back — a write may introduce a fact ref only for a fact the acting actor holds.

Same discipline as db/fact_queries.ts: deps: QueryDeps first (the caller owns the transaction), no audit side effects, idempotent writes.

view source

Declarations
#

5 declarations

FACT_HOLDER_COLUMNS
#

db/fact_holder_queries.ts view source

readonly ["actor_id", "hash", "created_at"] import {FACT_HOLDER_COLUMNS} from '@fuzdev/fuz_app/db/fact_holder_queries.js';

The fact_holder table's columns.

Twin of the Rust fuz_fact::FACT_HOLDER_COLUMNS (same names, same order). No query reads whole rows — admission reads hashes only — so the const is the drift guard's anchor rather than a projection source.

FactHolderRow
#

db/fact_holder_queries.ts view source

FactHolderRow import type {FactHolderRow} from '@fuzdev/fuz_app/db/fact_holder_queries.js';

Row shape of fact_holder.

actor_id

type Uuid

hash

type FactHash

created_at

type Date

query_fact_holder_table_exists
#

db/fact_holder_queries.ts view source

(deps: QueryDeps): Promise<boolean> import {query_fact_holder_table_exists} from '@fuzdev/fuz_app/db/fact_holder_queries.js';

Whether the fact_holder table exists — false on a database that mounts the cell verbs without the fact chain.

Probed before query_fact_holder_unheld, since naming a missing table would abort the caller's transaction. Twin of the Rust admission's to_regclass('fact_holder') probe, read from information_schema (which every supported driver answers).

deps

returns

Promise<boolean>

query_fact_holder_unheld
#

db/fact_holder_queries.ts view source

(deps: QueryDeps, actor_id: string & $brand<"Uuid">, hashes: readonly string[]): Promise<string[]> import {query_fact_holder_unheld} from '@fuzdev/fuz_app/db/fact_holder_queries.js';

The subset of hashes that actor_id does not hold, in input order.

Answered from fact_holder alone: a hash with no stored fact and a stored fact the actor never put read the same. Hashes are compared as text. The caller has checked the table exists.

deps

query deps

actor_id

the acting actor

type Uuid

hashes

the candidate hashes

type readonly string[]

returns

Promise<string[]>

the hashes with no (actor_id, hash) row

query_put_fact_holder
#

db/fact_holder_queries.ts view source

(deps: QueryDeps, actor_id: string & $brand<"Uuid">, hash: FactHash): Promise<void> import {query_put_fact_holder} from '@fuzdev/fuz_app/db/fact_holder_queries.js';

Record actor_id as a holder of hash, or refresh the row's created_at when it already holds it. The fact row must already exist (FK).

created_at is the holder's most recent put, which the orphan sweep reads as the fact's grace window: a re-put keeps an old orphan out of any sweep whose window covers the put.

deps

query deps

actor_id

the actor that brought the bytes

type Uuid

hash

the fact's hash

type FactHash

returns

Promise<void>

mutates

  • fact_holder — inserts the `(actor_id, hash)` row, or sets an existing row's `created_at` to now

Depends on
#

Imported by
#