Skip to content

Commit

Permalink
Merge pull request #48 from seasonedcc/update-examples
Browse files Browse the repository at this point in the history
Update arktype and remix examples and add docs and an adapter to arktype
  • Loading branch information
gustavoguichard authored May 23, 2024
2 parents cac614a + b6f3d79 commit 6343eb2
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 197 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ A set of types and functions to make compositions easy and safe.
- [Migrating from domain-functions](#migrating-from-domain-functions)
- [Handling external input](#handling-external-input)
- [Defining constants for multiple functions (environments)](#defining-constants-for-multiple-functions-environments)
- [Using custom parsers](#using-custom-parsers)
- [Using Deno](#using-deno)
- [Acknowledgements](#acknowledgements)

Expand Down Expand Up @@ -254,6 +255,7 @@ const getProfile = composable(async (id: string) => {
#### [Migrating from domain-functions](./migrating-df.md)
#### [Handling external input](./with-schema.md)
#### [Defining constants for multiple functions (environments)](./environments.md)
#### [Using custom parsers](./examples/arktype/README.md)

## Using Deno

Expand Down
9 changes: 9 additions & 0 deletions examples/arktype/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Use composable-functions with a custom parser

This simple example can be a reference to adapt composable-functions to any other parser library.

There are two approaches to use composable-functions with a custom parser:
- Create an adapter function that will receive a schema and return a schema in the shape of a `ParserSchena`. Example: [the `adapt` function](./src/adapters.ts).
- Create your custom `withSchema` and `applySchema` that will validate your input and environment and return a `Result`. Example: [the `withArkSchema` and `applyArkSchema` functions](./src/adapters.ts).

Check out the [`./src`](./src/) directory to understand how we implemented both approaches with [`arktype`](https://github.com/arktypeio/arktype).
4 changes: 2 additions & 2 deletions examples/arktype/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"private": true,
"version": "0.0.0",
"type": "module",
"main": "src/index.ts",
"main": "src/usage.ts",
"scripts": {
"dev": "tsx src/index.ts"
"dev": "tsx src/usage.ts"
},
"devDependencies": {
"tsx": "^4.7.2"
Expand Down
Loading

0 comments on commit 6343eb2

Please sign in to comment.