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

Feature/73 default json mapper response #201

Conversation

maryiabydanova
Copy link
Contributor

@maryiabydanova maryiabydanova commented Nov 30, 2021

Resolves #73

  • Introduce factory similar like in splitMapper:
    • define JsonMapper type
    • wrap mapper into factory function
    • implement setting default
    • produce and export default jsonMapper created by the factory
  • prove that it works by covering new changes by unit tests
  • describe jsonMapper api in a Readme.md - docs: added jsonMapper overview siemienik.github.io#21

@codecov
Copy link

codecov bot commented Nov 30, 2021

Codecov Report

Merging #201 (f66674c) into master (faebc52) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #201   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           55        56    +1     
  Lines         1087      1098   +11     
  Branches       154       134   -20     
=========================================
+ Hits          1087      1098   +11     
Flag Coverage Δ
xlsx-import 100.00% <100.00%> (ø)
xlsx-renderer 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/xlsx-import/src/mappers/jsonMapper.ts 100.00% <100.00%> (ø)
.../xlsx-import/tests/unit/mappers/jsonMapper.test.ts 100.00% <100.00%> (ø)
...lsx-import/tests/unit/mappers/stringMapper.test.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update faebc52...f66674c. Read the comment docs.

Copy link
Owner

@Siemienik Siemienik left a comment

Choose a reason for hiding this comment

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

Hi @maryiabydanova
Thank you for the contribution, That's great!

I added some comments with proposals to update typings. These will enable TypeScript features:

interface IPerson {
    name: string
}

const nobody:IPerson = {name:'nobody'};
const personMapper = jsonMapper.default(nobody);
const person = personMapper<IPerson>('incorrect'); // person is always IPerson
// person.name === 'nobody'
const person2 = personMapper<IPerson>('{name:"Pablo"}'); // person2 is always IPerson
// person.name === 'Pablo'

Or with type discrimination:

interface IPerson {
    name:string
}
const invalidJson = new Error('The parsed json was invalid.');

const personMapper = jsonMapper.default<typeof invalidJson>(invalidJson);
const person = personMapper<IPerson>('incorrect');
if(person instanceof Error){
    throw person;
}
doSomethingWithPerson(person);

Would you mind running two commands in packages/xlsx-import?

npm run lint:fix
npm run format

They care about formatting.

packages/xlsx-import/src/mappers/jsonMapper.ts Outdated Show resolved Hide resolved
packages/xlsx-import/src/mappers/jsonMapper.ts Outdated Show resolved Hide resolved
packages/xlsx-import/src/mappers/jsonMapper.ts Outdated Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented Dec 5, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Siemienik Siemienik self-requested a review December 5, 2021 23:46
Copy link
Owner

@Siemienik Siemienik left a comment

Choose a reason for hiding this comment

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

LGTM

@Siemienik
Copy link
Owner

Siemienik commented Dec 12, 2021

Thank you @maryiabydanova, it works great!

I'm going to publish this release up to 20th Dec.

@Siemienik Siemienik merged commit 721e696 into Siemienik:master Dec 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To Release
Development

Successfully merging this pull request may close these issues.

Add customisation for default response from jsonMapper
2 participants