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

util/wiki/schemas/subredditnotes/codec

Functions

buildIndexFromWikiPages()

buildIndexFromWikiPages(pages, notePrefix, now?): SubredditNoteIndex

Defined in: extension/data/util/wiki/schemas/subredditnotes/codec.ts:136

Builds a note index by scanning existing wiki page names for the given note page prefix. Used as a migration path when no index page exists yet.

Parameters

pages

string[]

All wiki page names on the subreddit.

notePrefix

string

The note page prefix for the subreddit’s wiki layout (e.g. 'notes/' or 'toolbox-nxg/notes/').

now?

number = ...

Timestamp recorded as the created/updated time of every note.

Returns

SubredditNoteIndex


computeIndexAggregates()

computeIndexAggregates(notes): object

Defined in: extension/data/util/wiki/schemas/subredditnotes/codec.ts:26

Computes the v2 pre-aggregated tag and author lists from a notes array: sorted, unique, recomputed from scratch so they can never go stale relative to the notes they describe.

Parameters

notes

SubredditNoteMeta[]

The note metadata entries to aggregate.

Returns

object

authors

authors: string[]

tags

tags: string[]


encodeLegacyIndex()

encodeLegacyIndex(index): SubredditNoteIndexV1

Defined in: extension/data/util/wiki/schemas/subredditnotes/codec.ts:43

Converts an index to the legacy v1 wire shape for the old notes/index page: notes only, no aggregate fields, so older toolbox builds see exactly the format they expect.

Parameters

index

Pick<SubredditNoteIndex, "notes">

The index to down-convert.

Returns

SubredditNoteIndexV1


makeEmptyIndex()

makeEmptyIndex(): SubredditNoteIndex

Defined in: extension/data/util/wiki/schemas/subredditnotes/codec.ts:16

Returns

SubredditNoteIndex

An empty note index at the current schema version.


mergeLegacyIndex()

mergeLegacyIndex(nxg, legacy): object

Defined in: extension/data/util/wiki/schemas/subredditnotes/codec.ts:113

Merges a legacy notes/index page into the canonical NXG index by slug union - the index analog of the usernotes reconcile path:

  • Slugs only in the legacy index were created by 6.x and are appended.

  • Slugs only in the NXG index are kept: a 6.x deletion is indistinguishable from a failed mirror write, so deletions never propagate legacy->NXG.

  • Slugs in both keep the NXG entry (it carries the richer v2 metadata). The aggregates are recomputed when anything changed.

Parameters

nxg

SubredditNoteIndex

The canonical normalized NXG index.

legacy

SubredditNoteIndex

The normalized legacy index to fold in.

Returns

object

changed

changed: boolean

index

normalizeIndex()

normalizeIndex(value, now?): SubredditNoteIndex | null

Defined in: extension/data/util/wiki/schemas/subredditnotes/codec.ts:66

Validates and normalizes a raw parsed index value into a canonical SubredditNoteIndex. The v2 aggregate fields are always recomputed from the notes regardless of input version, so both v1 pages and stale v2 aggregates self-heal on load. Returns null if the value is not a recognizable index shape.

Parameters

value

unknown

now?

number = ...

Returns

SubredditNoteIndex | null


noteTitleFromSlug()

noteTitleFromSlug(slug): string

Defined in: extension/data/util/wiki/schemas/subredditnotes/codec.ts:50

Converts a slug like my-note-slug into a title-cased string My Note Slug.

Parameters

slug

string

Returns

string