Skip to content

Commit

Permalink
Merge pull request #119 from seasonedcc/take-5
Browse files Browse the repository at this point in the history
Extracting primitives inspired by ATMP
  • Loading branch information
diogob authored Nov 29, 2023
2 parents bf5cb0a + 1215cc2 commit ae6169e
Show file tree
Hide file tree
Showing 31 changed files with 1,150 additions and 377 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist/
npm
npm
docs
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"tasks": {
"test": "deno test --allow-env --allow-net --unstable 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='domain-functions' ./mod.ts"
}
}
92 changes: 48 additions & 44 deletions deno.lock

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

2 changes: 1 addition & 1 deletion src/all.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
assertEquals,
assertObjectMatch,
} from './test-prelude.ts'
import { z } from 'https://deno.land/x/[email protected]/mod.ts'
import { z } from './test-prelude.ts'

import { mdf } from './constructor.ts'
import { all } from './domain-functions.ts'
Expand Down
46 changes: 46 additions & 0 deletions src/apply-environment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { assertEquals, describe, it } from './test-prelude.ts'
import { z } from './test-prelude.ts'

import { mdf } from './constructor.ts'
import { applyEnvironment } from './domain-functions.ts'

describe('applyEnvironment', () => {
it('fails when environment fails parser', async () => {
const getEnv = mdf(z.unknown(), z.number())((_, e) => e)

const getEnvWithEnvironment = applyEnvironment(
getEnv,
'invalid environment',
)

assertEquals(await getEnvWithEnvironment('some input'), {
success: false,
errors: [],
inputErrors: [],
environmentErrors: [
{
message: 'Expected number, received string',
path: [],
},
],
})
})

it('should apply environment', async () => {
const getEnv = mdf(z.unknown(), z.string())((_, e) => e)

const getEnvWithEnvironment = applyEnvironment(
getEnv,
'constant environment',
)

assertEquals(await getEnvWithEnvironment('some input'), {
success: true,
data: 'constant environment',
errors: [],
inputErrors: [],
environmentErrors: [],
})
})
})

2 changes: 1 addition & 1 deletion src/branch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
assertEquals,
assertObjectMatch,
} from './test-prelude.ts'
import { z } from 'https://deno.land/x/[email protected]/mod.ts'
import { z } from './test-prelude.ts'

import { mdf } from './constructor.ts'
import { branch, pipe, all } from './domain-functions.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/collect-sequence.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, assertEquals } from './test-prelude.ts'
import { z } from 'https://deno.land/x/[email protected]/mod.ts'
import { z } from './test-prelude.ts'

import { mdf } from './constructor.ts'
import { collectSequence } from './domain-functions.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/collect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
assertObjectMatch,
assertEquals,
} from './test-prelude.ts'
import { z } from 'https://deno.land/x/[email protected]/mod.ts'
import { z } from './test-prelude.ts'

import { mdf } from './constructor.ts'
import { collect } from './domain-functions.ts'
Expand Down
Loading

0 comments on commit ae6169e

Please sign in to comment.