-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(rr): config parsing #662
Conversation
return { | ||
name, | ||
path, | ||
kind: "YmlConfig", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use enums
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seaerchin That's a good point! I think I used to do it like this:
enum ESomeEnum {
ValOne: "1",
ValTwo: "2"
}
type EFinalType = ESomeEnum.ValOne | ESomeEnum.ValTwo
Then we use the EFinalType for the actual assertion. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this actually results in the same thing HAHA
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seaerchin same thing as in the same issue described in the links above? how so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh ps, i haven't had time to look at this due to being caught up in the release but this has the same effect because the discriminated union still only allows the same set of values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes true, but felt it is cleaner with the use of discriminated unions + enums rather than strings
} | ||
|
||
export interface EditedConfigDto extends BaseEditedItemDto { | ||
type: "nav" | "setting" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using enums will be cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above ;--;
import { Brand } from "@root/types/util" | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export class ConfigService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have a test file for this new service?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not at present, will add in a future PR
.orElse(() => this.parseCollectionPage(pathInfo)) | ||
|
||
isMarkdownPage = (pageName: string): Result<string, PageParseError> => { | ||
if (pageName.endsWith(".md")) return ok(pageName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can we just return a boolean value instead? Using neverthrow here feels too verbose for a function like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually the problem here is that we want to distinguish MarkdownPages
from other things (eg: YmlConfig
or HtmlPages
) - the problem with returning boolean
is that we lose context wrt what the pageName
is beyond its immediate containing function.
i can change this to string is MarkdownPage
and brand this string to prevent the verbosity - wdyt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm isnt that beyond the scope of this function, which is to just tell if this page is of type MarkdownPages
?
if not should we then rename this to getPageType
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is an example of a type guard and the naming is usually (by convention, at least) of the form isType
separately, telling if the page is of a specific type should assert that the page is that type, and not merely boolean otherwise downstream we would require calling again
) { | ||
return ok({ name: Brand.fromString(name), kind: "ContactUsPage" }) | ||
} | ||
return err(new NotFoundError()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to return the specific file that wasnt found here? (ie the path?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point but actually i feel like we should extend NotFoundError
to have a PageNotFoundError
; the reason why idw to return just the pagename alone is cos we might have more errors in the future and no semantic meaning is tied to the path @__@
so like the page not found error would have a property page name, which can be used downstream to distinguish the type of page (if required) + provide a helpful message for displaying to FE.
didnt do here cos laze ._. (would have to do so for more errors to avoid inconsistency - maybe we can do this down the line)
CICD tests are failing, may I trouble you you to take a look at them? |
e03a740
to
4bc729a
Compare
3ca54e8
to
a496ee1
Compare
3cf6a41
to
db69fa6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Tests] The full testing plan will be in the corresponding FE PR for buttons right? If not, please dismiss this review
fileUrl: `${FRONTEND_URL}/sites/${MOCK_REPO_NAME_ONE}/homepage`, | ||
lastEditedBy: MOCK_USER_EMAIL_TWO, // TODO: This should be MOCK_USER_EMAIL_ONE | ||
cmsFileUrl: `${FRONTEND_URL}/sites/${MOCK_REPO_NAME_ONE}/homepage`, | ||
lastEditedBy: MOCK_USER_EMAIL_TWO, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sanity check here: is this removal of todo intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can i clarify this - isn't the removed property added back below?
name: MOCK_GITHUB_FILENAME_ALPHA_ONE, | ||
path: [], | ||
stagingUrl: `${MOCK_DEPLOYMENT_DBENTRY_ONE.stagingUrl}${MOCK_PAGE_PERMALINK}`, | ||
fileUrl: `${FRONTEND_URL}/sites/${MOCK_REPO_NAME_ONE}/homepage`, | ||
lastEditedBy: MOCK_USER_EMAIL_TWO, // TODO: This should be MOCK_USER_EMAIL_ONE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sanity check again: checking in if this removal is intended
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can i clarify this - isn't the removed property added back below?
if (err instanceof MissingSiteError || err instanceof NotFoundError) { | ||
return res.status(404).json({ message: err.message }) | ||
} | ||
return res.status(500).json({ message: err.message }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we return a generic error instead? Worried of the existance of errors bubbling up and sensitive info being leaked to our frontend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the NotFoundError
was constructed either with no arguments (defaults to generic error messages of Something went wrong
) or a default string (no sensitive info) or a formatted string containing the requested rawPath
, similarly for MissingSiteError
, it's just constructed with a default message of the requested site was not found in isomer
, which i think is ok.
lmk if rawPath
is a concern
db69fa6
to
ea8051b
Compare
Problem
Our current model of parsing is simplified and only works for pages; this PR adds parsing for configuration files (nav + setting)
Closes IS-54
Solution