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

Reimplement Domain functions with code from the future #139

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b759a41
Type cast is necessary for current deno version
diogob May 21, 2024
d24bc2b
Add composable modules from the future with refreshed deno.json to us…
diogob May 21, 2024
5ff8b19
Rewrite safeResult in terms of composable
diogob May 22, 2024
96a645c
Extract composableToDF conversion. Assume input and environment are a…
diogob May 22, 2024
2c9fb8a
Write DF constructor using withSchema
diogob May 22, 2024
45994f3
Add composable-dependency
diogob May 22, 2024
2b42134
Fix issue building empty paths for schema error
diogob May 22, 2024
033198e
Reimplement all with compposables
diogob May 22, 2024
f768acb
Reimplement sequence using composables
diogob May 22, 2024
04e1be3
Reimplement branch using composables
diogob May 22, 2024
78046ed
Remove useless import
diogob May 22, 2024
4ad4df2
Export toComposable and fromComposable
diogob May 22, 2024
b131daf
Reimplement map with composables
diogob May 22, 2024
d8c4916
Add JSDoc for toComposable and fromComposable
diogob May 22, 2024
881a6e6
Tweak the README for the upcoming composables release
diogob May 22, 2024
f3952ee
Allow async maps, since they are useful, should behave in a similar w…
diogob Mar 8, 2024
a580927
toComposable should return the Composable success
diogob May 22, 2024
6e18e7f
Simplify toComposable since we now have constructors for success and …
diogob May 22, 2024
10f81fc
fix typo
diogob May 22, 2024
61db5cb
Re-export unchanged helpers from Future
gustavoguichard May 22, 2024
aff470f
Add central deps file and point to latest CF beta
diogob May 23, 2024
606ccd7
bump rc
diogob May 23, 2024
02326bf
npm generation packages
diogob May 23, 2024
7a745d3
Bump rc version with latest composable
gustavoguichard May 23, 2024
5ab1ac0
Bump rc
gustavoguichard May 23, 2024
20639a6
Update README.md
gustavoguichard May 23, 2024
416978f
Update README.md
gustavoguichard May 23, 2024
c1f8969
Update README.md
gustavoguichard May 23, 2024
dd2a838
bump rc and update composable dependency
diogob May 23, 2024
8df3a4d
Bump rc
gustavoguichard May 23, 2024
1e1ead1
Remove the example folder from this branch
gustavoguichard May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Keep your business logic clean with Domain Functions
# Keep your business logic clean with ~Domain Functions~ Composable Functions

The work in Domain Functions led us to a new, more generic library called Composable Functions.
We recommend you migrate following [our migration guide](https://github.com/seasonedcc/composable-functions/blob/main/migrating-df.md).
This guide also has some benefits that we see in migrating to the new library.
Moreover, so make the transition smoother, there is a new Domain Functions release (3.0) that introduces very few breaking changes and
uses the new library as a dependency. Using both libraries simultaneously is easy and an incremental migration is viable.

Domain Functions helps you decouple your business logic from your controllers, with first-class type inference from end to end.
It does this by enforcing the parameters' types at runtime (through [Zod](https://github.com/colinhacks/zod#what-is-zod) schemas) and always wrapping results (even exceptions) into a `Promise<Result<Output>>` type.
Expand Down
31 changes: 28 additions & 3 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
{
"version": "2.5.1",
"version": "2.7.0",
"tasks": {
"test": "deno test --allow-env --allow-net --unstable src",
"test": "deno test --allow-env --allow-net src",
"publish": "deno task build-npm && cd npm/ && npm publish",
"build-npm": "deno run -A scripts/build-npm.ts"
"build-npm": "deno run -A scripts/build-npm.ts",
"docs": "deno doc --html --name='composable-functions' ./mod.ts",
"docs-lint": "deno doc --lint ./mod.ts"
},
"lint": {
"include": [
"src/"
],
"rules": {
"exclude": [
"no-explicit-any",
"ban-types"
]
}
},
"compilerOptions": {
"types": ["./src/test.d.ts"]
},
"fmt": {
"useTabs": false,
"lineWidth": 80,
"indentWidth": 2,
"semiColons": false,
"singleQuote": true,
"proseWrap": "preserve",
"include": ["src/"]
}
}
67 changes: 65 additions & 2 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/all.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ describe('all', () => {
it('should return error when one of the domain functions fails', async () => {
const a = mdf(z.object({ id: z.number() }))(({ id }) => id)
const b = mdf(z.object({ id: z.number() }))(() => {
throw 'Error'
throw new Error('Error')
})

const c = all(a, b)
type _R = Expect<Equal<typeof c, DomainFunction<[number, never]>>>

assertEquals(await c({ id: 1 }), {
assertObjectMatch(await c({ id: 1 }), {
success: false,
errors: [{ message: 'Error', exception: 'Error' }],
errors: [{ message: 'Error' }],
inputErrors: [],
environmentErrors: [],
})
Expand Down
6 changes: 3 additions & 3 deletions src/collect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ describe('collect', () => {
it('should return error when one of the domain functions fails', async () => {
const a = mdf(z.object({ id: z.number() }))(({ id }) => id)
const b = mdf(z.object({ id: z.number() }))(() => {
throw 'Error'
throw new Error('Error')
})

const c = collect({ a, b })
type _R = Expect<Equal<typeof c, DomainFunction<{ a: number; b: never }>>>

assertEquals(await c({ id: 1 }), {
assertObjectMatch(await c({ id: 1 }), {
success: false,
errors: [{ message: 'Error', exception: 'Error' }],
errors: [{ message: 'Error' }],
inputErrors: [],
environmentErrors: [],
})
Expand Down
6 changes: 3 additions & 3 deletions src/constructor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ describe('makeDomainFunction', () => {

assertObjectMatch(await handler({ id: 1 }), {
success: false,
errors: [{ message: 'Error', exception: 'Error' }],
errors: [{ message: '"Error"' }],
inputErrors: [],
environmentErrors: [],
})
Expand All @@ -222,9 +222,9 @@ describe('makeDomainFunction', () => {
})
type _R = Expect<Equal<typeof handler, DomainFunction<never>>>

assertEquals(await handler({ id: 1 }), {
assertObjectMatch(await handler({ id: 1 }), {
success: false,
errors: [{ message: 'Error', exception: { message: 'Error' } }],
errors: [{ message: JSON.stringify({ message: 'Error' }) }],
inputErrors: [],
environmentErrors: [],
})
Expand Down
Loading
Loading