reddit / devvit

Reddit for Developers
https://developers.reddit.com
BSD 3-Clause "New" or "Revised" License
73 stars 17 forks source link

fix: allow WikiPage.#revisionAuthor to be undefined #109

Closed PitchforkAssistant closed 1 week ago

PitchforkAssistant commented 2 weeks ago

Possibly fixes #108

๐Ÿ’ธ TL;DR

Allows WikiPage.#revisionAuthor to be undefined, as that is a possibility for some wiki pages.

๐Ÿ“œ Details

Removes assertNonNull(data.revisionBy?.data, 'Wiki page author details are missing'); from the WikiPage constructor and sets #revisionAuthor to be of type User | undefined depending on whether data.revisionBy exists. Updates get revisionAuthor() and toJSON() to reflect the type change.

It's worth noting that revisionBy is already marked as potentially undefined in the WikiPage interface from @devvit/protos. revisionId and revisionDate are not marked that way, but would also be returned as null by the Data API in this same edge case of a wiki page with no revision history.

๐Ÿงช Testing Steps / Validation

Untested, as I am unable to set up the environment to produce a successful build even with no changes. TypeScript language server doesn't show any new errors though. Additionally, there are no existing tests for WikiPage found in /packages/public-api/src/apis/reddit/tests.

โœ… Checks

PitchforkAssistant commented 2 weeks ago

Made the requested change now that I was finally able to compile and notice the issue with the undefined check.

And I agree that the README could use better instructions for compiling specific packages like the public-api one.
I ended up clearing everything except that package, changing out several of its dependencies for valid @next versions (packages like the matching @devvit/shared-types and @devvit/protos are not included with this repo), and copying the src/devvit/internals/semanticColors.ts and src/types/icons.js files from an already published version because generating them requires dependencies that aren't public (@reddit/faceplate-ui).