moderator-toolbox-nxg-for-reddit / util/wiki/schemas/proposals/codec

util/wiki/schemas/proposals/codec

Functions

emptyProposalsData()

emptyProposalsData(): ProposalsData

Defined in: extension/data/util/wiki/schemas/proposals/codec.ts:232

Returns a fresh empty ProposalsData (deep-cloned default).

Returns

ProposalsData


encodeProposalsData()

encodeProposalsData(data): ProposalsData

Defined in: extension/data/util/wiki/schemas/proposals/codec.ts:227

Serializes ProposalsData for storage. Currently an identity pass (plain JSON is stringified by the wiki write layer); exists as the encode seam paired with normalizeProposalsData for a future compression upgrade.

Parameters

data

ProposalsData

The proposals data to encode.

Returns

ProposalsData


normalizeProposalsData()

normalizeProposalsData(raw): ProposalsData

Defined in: extension/data/util/wiki/schemas/proposals/codec.ts:200

Coerces an untrusted parsed wiki blob into a valid ProposalsData. Unrecognized or malformed proposals are dropped. Never throws.

Parameters

raw

unknown

The parsed JSON read from the proposals wiki page (or anything).

Returns

ProposalsData

Variables

INVALID_PROPOSALS_JSON_REASON

const INVALID_PROPOSALS_JSON_REASON: "The proposals page contains invalid JSON. Fix it by hand before editing so existing proposals are not lost." = 'The proposals page contains invalid JSON. Fix it by hand before editing so existing proposals are not lost.'

Defined in: extension/data/util/wiki/schemas/proposals/codec.ts:240

Refusal message when the proposals page exists but isn’t valid JSON. Surfaced as unparseable so the mutate loop refuses to overwrite content it could not read.


proposalsCodec

const proposalsCodec: WikiPageCodec<ProposalsData>

Defined in: extension/data/util/wiki/schemas/proposals/codec.ts:254

The WikiPageCodec for the proposals page, used by the versioned wiki transport. parse REFUSES content it cannot read as JSON ({ok: false}), so a write can never clobber a page whose real contents we did not understand. The display path still degrades gracefully: it reads the codec’s empty value and ignores unparseable, so a corrupt page shows as empty rather than erroring. normalizeProposalsData keeps field-level tolerance for valid-but-partial JSON (dropping malformed individual proposals); a write against a newer schema version is refused separately by mutateProposals’s refuseWrite. Content is HTML-entity-escaped on the wiki, so parse must unescapeJSON before JSON.parse (matching readFromWiki).