-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b738363
Showing
24 changed files
with
5,561 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
version: 2.1 | ||
|
||
orbs: | ||
vfcommon: voiceflow/common@0.0.187 | ||
|
||
jobs: | ||
build-and-test: | ||
executor: vfcommon/default-executor | ||
steps: | ||
- checkout | ||
- vfcommon/install_node_modules | ||
- vfcommon/lint_report | ||
- vfcommon/dependency_tests: | ||
step_name: Dependency Tests | ||
- vfcommon/build | ||
- vfcommon/unit_tests | ||
- vfcommon/integration_tests | ||
|
||
workflows: | ||
|
||
test-and-release: | ||
jobs: | ||
- build-and-test: | ||
context: dev-test | ||
|
||
- vfcommon/release: | ||
context: dev-test | ||
requires: | ||
- build-and-test | ||
filters: | ||
branches: | ||
only: master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"specials": [ | ||
"bin", | ||
"eslint", | ||
"lint-staged", | ||
"istanbul", | ||
"commitizen", | ||
"husky", | ||
"prettier", | ||
"ttypescript" | ||
], | ||
"ignores": [ | ||
"@commitlint/*", | ||
"@types/*", | ||
"@voiceflow/commitlint-config", | ||
"@voiceflow/git-branch-check", | ||
"@voiceflow/tsconfig", | ||
"eslint-import-resolver-typescript", | ||
"fixpack", | ||
"istanbul", | ||
"husky", | ||
"lint-staged" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[vcbuild.bat] | ||
end_of_line = crlf | ||
|
||
[Makefile] | ||
indent_size = 8 | ||
indent_style = tab | ||
|
||
[{deps}/**] | ||
charset = ignore | ||
end_of_line = ignore | ||
indent_size = ignore | ||
indent_style = ignore | ||
trim_trailing_whitespace = ignore | ||
|
||
[{test/fixtures,deps,tools/node_modules,tools/gyp,tools/icu,tools/msvs}/**] | ||
insert_final_newline = false | ||
|
||
[*.js] | ||
trim_trailing_whitespace = false | ||
max_line_length = 150 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
coverage | ||
.nyc_output | ||
/build | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"formats": [ | ||
{ | ||
"name": "stylish", | ||
"output": "console" | ||
}, | ||
{ | ||
"name": "json", | ||
"output": "file", | ||
"path": "sonar/report.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
extends: ['@voiceflow/eslint-config', '@voiceflow/eslint-config/typescript'], | ||
overrides: [ | ||
{ | ||
files: ['test/**/*'], | ||
extends: ['@voiceflow/eslint-config/utility', '@voiceflow/eslint-config/mocha'], | ||
rules: { | ||
// off | ||
'no-unused-expressions': 'off', | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.DS_Store | ||
.idea | ||
node_modules | ||
dump.rdb | ||
|
||
coverage | ||
log/ | ||
|
||
# dotenv environment variables files | ||
/.env* | ||
!/.env.example | ||
!/.env.test | ||
|
||
.nyc_output | ||
|
||
# build folder | ||
build | ||
|
||
#Sonar report | ||
sonar/ | ||
nyc_coverage* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"hooks": { | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS", | ||
"pre-commit": "lint-staged", | ||
"pre-push": "git-branch-check" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
'package.json': ['fixpack'], | ||
'**/*.{js,ts}': ['eslint --fix'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "@istanbuljs/nyc-config-typescript", | ||
"include": [ | ||
"src/**" | ||
], | ||
"reporter": [ | ||
"html", | ||
"text", | ||
"text-summary", | ||
"lcov" | ||
], | ||
"report-dir": "nyc_coverage", | ||
"extension": [ | ||
".ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
coverage | ||
.idea | ||
.nyc_output | ||
/build | ||
/node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
branches: [ | ||
master | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ISC License | ||
|
||
Copyright 2021 Voiceflow Inc. | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
Bi-Directional Adapter | ||
========================= | ||
|
||
[![npm version](https://img.shields.io/npm/v/bidirectional-adapter.svg?style=flat-square)](https://www.npmjs.com/package/bidirectional-adapter) | ||
[![npm downloads](https://img.shields.io/npm/dm/bidirectional-adapter.svg?style=flat-square)](https://www.npmjs.com/package/bidirectional-adapter) | ||
|
||
Factory to create bi-directional adapters that can convert between two distinct data structures. | ||
Using adapters helps to decouple systems which share common data structures and may need to alter them | ||
independently without introducing conflicts in each other. | ||
|
||
## Why? | ||
|
||
You have multiple services which each operate on a single shared resource but want to represent the data | ||
differently in each service or want to isolate each service from data structure changes required by the other. | ||
|
||
With `bidirectional-adapter` you can define a simple entity which can be used to transform data between two formats. | ||
|
||
```ts | ||
const adapter = createAdapter<string, number>( | ||
(stringValue) => parseInt(stringValue, 10), | ||
(numericValue) => String(numericValue) | ||
); | ||
``` | ||
|
||
## Example | ||
|
||
```ts | ||
import axios from 'axios'; | ||
import createAdapter from 'bidirectional-adapter'; | ||
|
||
const accountAdapter = createAdapter( | ||
(dbAccount) => ({ | ||
id: dbAccount.user_id, | ||
name: `${dbAccount.user.firstName} ${dbAccount.user.lastName}`, | ||
email: dbAccount.user.email | ||
}), | ||
(appAccount) => ({ | ||
user_id: appAcount.id, | ||
user: { | ||
firstName: appAccount.name.split(' ')[0], | ||
lastName: appAccount.name.split(' ')[1] | ||
}, | ||
email: appAccount.email | ||
}) | ||
); | ||
|
||
const fetchAccount = (userID) => { | ||
// state is in the shape of propertyTwo | ||
// do reducer stuff here | ||
return axios.get(`/account/${userID}`).then(res => accountAdapter.fromDB(res.data)); | ||
}; | ||
|
||
const updateAccount = (account) => { | ||
// state is in the shape of propertyTwo | ||
// do reducer stuff here | ||
return axios.post(`/account/${userID}`, accountAdapter.toDB(account)); | ||
}; | ||
``` | ||
|
||
## Installation | ||
|
||
To use `bidirectional-adapter`, install it as a dependency: | ||
|
||
```bash | ||
# If you use npm: | ||
npm install bidirectional-adapter | ||
|
||
# Or if you use Yarn: | ||
yarn add bidirectional-adapter | ||
``` | ||
|
||
This assumes that you’re using a package manager such as [npm](http://npmjs.com/). | ||
|
||
## License | ||
|
||
[ISC](LICENSE.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: ['@voiceflow/commitlint-config'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require: | ||
- source-map-support/register | ||
|
||
timeout: 4000 | ||
exit: true | ||
recursive: true | ||
|
||
spec: | ||
- config/test/setup.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// perform mocha setup here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{ | ||
"name": "bidirectional-adapter", | ||
"description": "bi-directional adapter factory, used to decouple systems across shared data structures", | ||
"version": "1.0.0", | ||
"author": "Tyler Han, Ben Teichman", | ||
"bugs": { | ||
"url": "https://github.com/voiceflow/bidirectional-adapter/issues" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^11.0.0", | ||
"@istanbuljs/nyc-config-typescript": "^1.0.1", | ||
"@types/chai": "^4.2.15", | ||
"@types/mocha": "^9.0.0", | ||
"@voiceflow/commitlint-config": "^1.0.2", | ||
"@voiceflow/eslint-config": "^3.1.0", | ||
"@voiceflow/git-branch-check": "^1.1.3", | ||
"@voiceflow/prettier-config": "^1.0.5", | ||
"@voiceflow/tsconfig": "^1.0.0", | ||
"@zerollup/ts-transform-paths": "^1.7.18", | ||
"chai": "^4.3.0", | ||
"commitizen": "^4.2.3", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"depcheck": "^1.4.2", | ||
"eslint": "^7.20.0", | ||
"eslint-output": "^3.0.1", | ||
"fixpack": "^4.0.0", | ||
"husky": "^4.3.8", | ||
"istanbul": "^0.4.5", | ||
"lint-staged": "^10.5.4", | ||
"mocha": "^8.3.0", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.2.1", | ||
"source-map-support": "^0.5.19", | ||
"ts-mocha": "^8.0.0", | ||
"ts-node": "^9.1.1", | ||
"ttypescript": "^1.5.12", | ||
"typescript": "^4.4.2" | ||
}, | ||
"files": [ | ||
"build/" | ||
], | ||
"homepage": "https://github.com/voiceflow/bidirectional-adapter#readme", | ||
"keywords": [ | ||
"adapter", | ||
"data", | ||
"model", | ||
"voiceflow" | ||
], | ||
"license": "ISC", | ||
"main": "build/index.js", | ||
"prettier": "@voiceflow/prettier-config", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/voiceflow/bidirectional-adapter.git" | ||
}, | ||
"scripts": { | ||
"build": "yarn clean && ttsc --project ./tsconfig.build.json --declaration", | ||
"clean": "rimraf build", | ||
"commit": "cz", | ||
"eslint-output": "eslint-output", | ||
"lint": "eslint '**/*.{js,ts}'", | ||
"lint:output": "yarn run eslint-output --quiet \"**/*.{js,ts}\"", | ||
"lint:quiet": "yarn lint --quiet", | ||
"lint:report": "yarn lint:output", | ||
"prepublishOnly": "yarn build", | ||
"test": "yarn test:run", | ||
"test:dependencies": "depcheck", | ||
"test:integration": "NODE_ENV=test nyc --report-dir nyc_coverage_integration ts-mocha --paths --config ./config/test/.mocharc.yml 'test/**/*.it.ts'", | ||
"test:run": "NODE_ENV=test nyc ts-mocha --paths --config ./config/test/.mocharc.yml 'test/**/*.{unit,it}.ts'", | ||
"test:single": "NODE_ENV=test ts-mocha --paths --config ./config/test/.mocharc.yml", | ||
"test:unit": "NODE_ENV=test nyc --report-dir=nyc_coverage_unit ts-mocha --paths --config ./config/test/.mocharc.yml 'test/**/*.unit.ts'" | ||
}, | ||
"types": "build/index.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
"extends": ["github>voiceflow/renovate-config:creator"] | ||
} |
Oops, something went wrong.