db/cell_field_queries.ts

Raw queries against the cell_field table.

Named-relation primitive: each row is (source_id, name) → target_id, a JSON-object-shaped edge from one cell to another. (source_id, name) is unique — one target per name per source. Multiplicity by composition (target a collection cell whose items[] are the multi-valued tags), not by allowing duplicate field rows.

Reads filter both endpoints by cell.deleted_at IS NULL so relations dangling off a soft-deleted cell don't surface to the live graph.

query_cell_field_set upserts on the (source_id, name) PK so re-pointing a name updates target_id in place — JSON-object semantics (obj.foo = bar overwrites whatever was there).

view source

Declarations
#

7 declarations

CellFieldRow
#

db/cell_field_queries.ts view source

CellFieldRow import type {CellFieldRow} from '@fuzdev/fuz_app/db/cell_field_queries.js';

Row shape returned by cell_field SELECTs.

source_id

type Uuid

name

type string

target_id

type Uuid

created_at

type Date

CellFieldSetQueryInput
#

query_cell_field_delete
#

db/cell_field_queries.ts view source

(deps: QueryDeps, source_id: string & $brand<"Uuid">, name: string): Promise<CellFieldRow | null> import {query_cell_field_delete} from '@fuzdev/fuz_app/db/cell_field_queries.js';

Delete a field row by primary key. Returns the deleted row so callers can audit the prior target_id without a pre-fetch.

deps

source_id

type string & $brand<"Uuid">

name

type string

returns

Promise<CellFieldRow | null>

the deleted row, or null when no row matched (idempotent delete: a 200 response is correct even when nothing was deleted)

query_cell_field_get
#

db/cell_field_queries.ts view source

(deps: QueryDeps, source_id: string & $brand<"Uuid">, name: string): Promise<CellFieldRow | null> import {query_cell_field_get} from '@fuzdev/fuz_app/db/cell_field_queries.js';

Fetch one field row by primary key.

Does NOT JOIN cell — the caller decides whether to filter by deleted_at. Used by handlers that need the row's current target_id for audit envelopes before issuing the delete.

deps

query deps

source_id

source cell id

type string & $brand<"Uuid">

name

field name

type string

returns

Promise<CellFieldRow | null>

the row or null when not found

query_cell_field_list_for_source
#

db/cell_field_queries.ts view source

(deps: QueryDeps, source_id: string & $brand<"Uuid">, options?: { limit?: number | undefined; name_after?: string | undefined; } | undefined): Promise<CellFieldRow[]> import {query_cell_field_list_for_source} from '@fuzdev/fuz_app/db/cell_field_queries.js';

Forward fields list (source.fields[]).

Filters target by deleted_at IS NULL so relations to tombstoned cells don't surface; the source filter is the caller's responsibility (gated upstream by can_view_cell(source)).

deps

query deps

source_id

source cell id

type string & $brand<"Uuid">

options?

type { limit?: number | undefined; name_after?: string | undefined; } | undefined
optional

returns

Promise<CellFieldRow[]>

matching rows, oldest first by name (lex order)

query_cell_field_list_for_target
#

db/cell_field_queries.ts view source

(deps: QueryDeps, target_id: string & $brand<"Uuid">, options?: { limit?: number | undefined; } | undefined): Promise<CellFieldRow[]> import {query_cell_field_list_for_target} from '@fuzdev/fuz_app/db/cell_field_queries.js';

Reverse fields list (target.upfields[]).

Returns rows whose target_id = $1, joined to cell on source_id so relations from tombstoned sources don't surface. The caller-side authz filter (per-source can_view_cell) runs after the SQL fetch — see the 2-layer authz contract on cell_field_list({target_id}).

Bounded by limit (the wire cell_field_list cap) so a heavily inbound-linked target can't force an unbounded fetch + per-source authz pass on the public, IP-rate-limited reverse endpoint.

deps

query deps

target_id

target cell id

type string & $brand<"Uuid">

options?

limit caps the row count

type { limit?: number | undefined; } | undefined
optional

returns

Promise<CellFieldRow[]>

matching rows, oldest first by source created_at

query_cell_field_set
#

db/cell_field_queries.ts view source

(deps: QueryDeps, input: CellFieldSetQueryInput): Promise<CellFieldRow> import {query_cell_field_set} from '@fuzdev/fuz_app/db/cell_field_queries.js';

Insert or update a field row.

UPSERT on (source_id, name) — re-setting the same name updates target_id and bumps created_at (timestamp reflects last write). Idempotent at the row level: caller can re-issue with the same input without checking existence first.

deps

query deps

input

source, name, target

returns

Promise<CellFieldRow>

the inserted-or-updated row

Depends on
#

Imported by
#