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

Testing: mocked and memory #14

Merged
merged 12 commits into from
Dec 21, 2018
Merged
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ addons:
sonarcloud:
organization: "discipl" # the key of the org you chose at step #3
script:
- npm test
# other script steps might be done before running the actual analysis
- sonar-scanner
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sonar-scanner; fi'
110 changes: 110 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"babel-plugin-dynamic-import-node": "^2.2.0",
"chai": "^4.2.0",
"discipl-core-memory": "git+https://github.com/discipl/discipl-core-memory.git",
"mocha": "^5.2.0"
"mocha": "^5.2.0",
"sinon": "^7.2.2"
}
}
22 changes: 16 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ var disciplCoreConnectors = []
*/
const initializeConnector = async (connector) => {
if(!Object.keys(disciplCoreConnectors).includes(connector)) {
import(CONNECTOR_MODULE_PREFIX+connector).then(module => {
let connectorModuleClass = module.default
disciplCoreConnectors[connector] = new connectorModuleClass()
})
let module = await import(CONNECTOR_MODULE_PREFIX+connector);
let connectorModuleClass = module.default
registerConnector(connector, new connectorModuleClass())
}
}

Expand All @@ -33,6 +32,16 @@ const getConnector = async (connector) => {
return disciplCoreConnectors[connector]
}

/**
* Registers a connector explicitly.
*
* @param name of the connector. Packages containing a connector follow the naming convention CONNECTOR_MODULE_PREFIX + name
* @param connector instantiated object representing the connector
*/
const registerConnector = (name, connector) => {
disciplCoreConnectors[name] = connector;
}

/**
* extracts connector name and reference from a link string and returns it as a json object in the form of: {connector, reference}
*/
Expand Down Expand Up @@ -233,13 +242,13 @@ const exportLD = async (SsidDidOrLink, maxdepth = 3, ssid = null, visitedStack =

let res = await get(currentLink, ssid)
if(res != null) {
data = res.data
let data = res.data
if(res.previous && (SsidDidOrLink.indexOf(DID_PREFIX) == 0)) {
console.log('Get previous of channel'+res.previous)
exportData[currentSsid.did] = await exportLD(res.previous, maxdepth, ssid, visitedStack)
}
exportData[currentSsid.did][currentLink] = {}
for(elem in data) {
for(let elem in data) {
exportData[currentSsid.did][currentLink][elem] = {}
let value = data[elem]
try {
Expand Down Expand Up @@ -268,6 +277,7 @@ const revoke = async (ssid, link) => {

export {
getConnector,
registerConnector,
newSsid,
claim,
attest,
Expand Down
Loading