Skip to content
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

chore: fix ContentType usage #2353

Merged
merged 2 commits into from Jul 12, 2023
Merged

chore: fix ContentType usage #2353

merged 2 commits into from Jul 12, 2023

Conversation

karolsojko
Copy link
Member

@karolsojko karolsojko commented Jul 12, 2023

Origin

Noticed that there were errors on the server side coming from the @standardnotes/features package caused by the content type comparisons. So I decided to replace the old ContentType usage with new one on the app

What this PR does

  • Changes all function parameter declarations of param: ContentType to param: string as the old ContentType was essentially just a string alias. It did not safe-guard the content type on runtime - just a dev env helper.
  • Changes invocations of those functions from f.e. ContentType.File to ContentType.TYPES.File

What this PR does not

  • it does not replace the parameters with proper ContentType types because that requires more implementation logic and should be done in consecutive PRs. More details below.

How to use ContenType

ContentType is a proper domain value object now which safe-guards its definition during runtime. Here is how to use it:

import { ContentType } from '@standardnotes/domain-core'

// as a function param - this ensures the parameter is a valid content type
function foobar(contentType: ContentType) {
  console.log(contentType.value)
}

// constructing the value object
const contentTypeString = '...'

const contentTypeOrError = ContentType.create(contentTypeString)
if (contentTypeOrError.isFailed()) {
  // the string passed to the value object had an invalid content type that is not allowed
}
const contentType = contentTypeOrError.getValue()
foobar(contentType)

// constructing from predefined strings
const contentType = ContentType.create(ContentType.TYPES.File).getValue()
foobar(contentType)

@karolsojko karolsojko merged commit 325737b into main Jul 12, 2023
5 checks passed
@karolsojko karolsojko deleted the fix_content_type branch July 12, 2023 11:53
amanharwara pushed a commit that referenced this pull request Jul 12, 2023
* chore: fix ContentType usage

* chore: fix specs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant