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

Add module: Base64 #40

Merged
merged 4 commits into from
Sep 20, 2022
Merged

Add module: Base64 #40

merged 4 commits into from
Sep 20, 2022

Conversation

newswim
Copy link
Collaborator

@newswim newswim commented Sep 19, 2022

closes #23
closes #44

Note:

  • I diverted slightly from the validator.js module by making these url-safe by default. I don't have a great rationale for doing this, aside from it felt like the more correct general use-case. (Ended up adding a new module, Base64Url.
  • This also contains some additional generated code that resulted from running yarn generate:schemables

Follow-up [edited]

  • I learned quite a bit about Base64 encoding (and specifically RFC 4648), I think I'd like to follow up on this and potentially provide different modules that check that we're fully adhering to the spec.. but for now at least, this just follows the same checks provided by validator.js.

Copy link
Owner

@jacob-alford jacob-alford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Great work, just a few comments to address, and question about possibly splitting base64 it up into different modules, or making the param non-optional

src/string/Base64.ts Outdated Show resolved Hide resolved
src/Decoder.ts Outdated Show resolved Hide resolved
* @category Model
*/
export type SchemableParams1<S extends URIS> = (
options?: Base64SchemableOptions
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 I'm open to optional params, but I ended up choosing against it for UUID because otherwise it doesn't make much sense why there's a function call for the combinator:

const User = SC.make(S => 
  S.struct({
    token: S.Base64()
  })
)

vs an explicit params, which make it clearer why it's a function call:

const User = SC.make(S => 
  S.struct({
    token: S.Base64({ urlSafe: true })
  })
)

And like you mentioned, an alternative for these simple configs would be to split them up into different modules

Copy link
Collaborator Author

@newswim newswim Sep 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up adding an additional module. I'll open a new issue to cover this. And it's probably worth discussing this some more since I expect we'll need to find out a middle ground between representing all possible variants, and having an API that is reasonably compact and appropriate for most use cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #44

src/string/Base64.ts Outdated Show resolved Hide resolved
tests/Base64.test.ts Show resolved Hide resolved
tests/Base64.test.ts Show resolved Hide resolved
jacob-alford
jacob-alford previously approved these changes Sep 20, 2022
Copy link
Owner

@jacob-alford jacob-alford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful 🎉

@newswim newswim merged commit fc1d7e5 into main Sep 20, 2022
@newswim newswim deleted the dm/add-string--base64 branch September 20, 2022 18:51
@newswim newswim mentioned this pull request Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Base64Url string module Add Base64 string module
2 participants