server/fact_write.ts

Shared helper for routing fact bytes between embedded (PG bytes column) and external (filesystem + put_ref) storage tiers based on size.

External writes go through atomic temp+rename so the facts row never references a partial file; idempotence comes from POSIX rename overwrite + INSERT ... ON CONFLICT DO NOTHING in the fact-store queries layer.

view source

Declarations
#

2 declarations

write_fact
#

server/fact_write.ts view source

(fact_store: FactStore, embedded_threshold: number, facts_dir: string, bytes: Uint8Array<ArrayBufferLike>, options: WriteFactOptions): Promise<...> import {write_fact} from '@fuzdev/fuz_app/server/fact_write.js';

Write bytes as a fact, choosing embedded (PG) vs external (disk + put_ref) based on embedded_threshold. Returns the canonical blake3: hash either way.

fact_store

the FactStore (typically PgFactStore)

type FactStore

embedded_threshold

bytes ≤ threshold → embedded; > threshold → disk

type number

facts_dir

root of the sharded facts directory tree on disk

type string

bytes

the raw fact bytes

type Uint8Array<ArrayBufferLike>

options

content type for the fact metadata

returns

Promise<string & $brand<"FactHash">>

the fact's blake3:<hex64> hash

WriteFactOptions
#

Depends on
#