Run prettier

This commit is contained in:
Yarmo Mackenbach 2021-04-19 13:38:00 +02:00
parent ae606ce710
commit 5f5f663e4b
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
2 changed files with 65 additions and 68 deletions

View file

@ -36,14 +36,14 @@ class Claim {
*/ */
constructor(uri, fingerprint) { constructor(uri, fingerprint) {
// Import JSON // Import JSON
if ('claimVersion' in uri) { if (typeof uri === 'object' && 'claimVersion' in uri) {
switch (data.claimVersion) { switch (data.claimVersion) {
case 1: case 1:
this.uri = data.uri this._uri = data.uri
this.fingerprint = data.fingerprint this._fingerprint = data.fingerprint
this.state = data.state this._state = data.state
this.dataMatches = data.dataMatches this._dataMatches = data.dataMatches
this.verification = data.verification this._verification = data.verification
break break
default: default:
@ -66,11 +66,11 @@ class Claim {
} }
} }
this.uri = uri ? uri : null this._uri = uri ? uri : null
this.fingerprint = fingerprint ? fingerprint : null this._fingerprint = fingerprint ? fingerprint : null
this.state = E.ClaimState.INIT this._state = E.ClaimState.INIT
this.dataMatches = null this._dataMatches = null
this.verification = null this._verification = null
} }
/** /**
@ -79,7 +79,7 @@ class Claim {
* @returns {string} * @returns {string}
*/ */
get uri() { get uri() {
return this.uri return this._uri
} }
/** /**
@ -88,7 +88,7 @@ class Claim {
* @returns {string} * @returns {string}
*/ */
get fingerprint() { get fingerprint() {
return this.fingerprint return this._fingerprint
} }
/** /**
@ -97,7 +97,7 @@ class Claim {
* @returns {string} * @returns {string}
*/ */
get state() { get state() {
return this.state return this._state
} }
/** /**
@ -106,10 +106,10 @@ class Claim {
* @returns {object} * @returns {object}
*/ */
get matches() { get matches() {
if (this.state === E.ClaimState.INIT) { if (this._state === E.ClaimState.INIT) {
throw new Error('This claim has not yet been matched') throw new Error('This claim has not yet been matched')
} }
return this.dataMatches return this._dataMatches
} }
/** /**
@ -118,10 +118,11 @@ class Claim {
* @returns {object} * @returns {object}
*/ */
get result() { get result() {
if (this.state !== E.ClaimState.VERIFIED) { if (this._state !== E.ClaimState.VERIFIED) {
throw new Error('This claim has not yet been verified') throw new Error('This claim has not yet been verified')
} }
return this.verification return this.verification
_
} }
/** /**
@ -130,7 +131,7 @@ class Claim {
* @param {string} uri - The new claim URI * @param {string} uri - The new claim URI
*/ */
set uri(uri) { set uri(uri) {
if (this.state !== E.ClaimState.INIT) { if (this._state !== E.ClaimState.INIT) {
throw new Error( throw new Error(
'Cannot change the URI, this claim has already been matched' 'Cannot change the URI, this claim has already been matched'
) )
@ -142,7 +143,7 @@ class Claim {
// Remove leading and trailing spaces // Remove leading and trailing spaces
uri = uri.replace(/^\s+|\s+$/g, '') uri = uri.replace(/^\s+|\s+$/g, '')
this.uri = uri this._uri = uri
} }
/** /**
@ -151,12 +152,12 @@ class Claim {
* @param {string} fingerprint - The new fingerprint * @param {string} fingerprint - The new fingerprint
*/ */
set fingerprint(fingerprint) { set fingerprint(fingerprint) {
if (this.state === E.ClaimState.VERIFIED) { if (this._state === E.ClaimState.VERIFIED) {
throw new Error( throw new Error(
'Cannot change the fingerprint, this claim has already been verified' 'Cannot change the fingerprint, this claim has already been verified'
) )
} }
this.fingerprint = fingerprint this._fingerprint = fingerprint
} }
/** /**
@ -191,30 +192,30 @@ class Claim {
* @function * @function
*/ */
match() { match() {
if (this.state !== E.ClaimState.INIT) { if (this._state !== E.ClaimState.INIT) {
throw new Error('This claim was already matched') throw new Error('This claim was already matched')
} }
if (this.uri === null) { if (this._uri === null) {
throw new Error('This claim has no URI') throw new Error('This claim has no URI')
} }
this.dataMatches = [] this._dataMatches = []
claimDefinitions.list.every((name, i) => { claimDefinitions.list.every((name, i) => {
const def = claimDefinitions.data[name] const def = claimDefinitions.data[name]
// If the candidate is invalid, continue matching // If the candidate is invalid, continue matching
if (!def.reURI.test(this.uri)) { if (!def.reURI.test(this._uri)) {
return true return true
} }
const candidate = def.processURI(this.uri) const candidate = def.processURI(this._uri)
if (candidate.match.isAmbiguous) { if (candidate.match.isAmbiguous) {
// Add to the possible candidates // Add to the possible candidates
this.dataMatches.push(candidate) this._dataMatches.push(candidate)
} else { } else {
// Set a single candidate and stop // Set a single candidate and stop
this.dataMatches = [candidate] this._dataMatches = [candidate]
return false return false
} }
@ -222,7 +223,7 @@ class Claim {
return true return true
}) })
this.state = E.ClaimState.MATCHED this._state = E.ClaimState.MATCHED
} }
/** /**
@ -235,13 +236,13 @@ class Claim {
* @param {object} [opts] - Options for proxy, fetchers * @param {object} [opts] - Options for proxy, fetchers
*/ */
async verify(opts) { async verify(opts) {
if (this.state === E.ClaimState.INIT) { if (this._state === E.ClaimState.INIT) {
throw new Error('This claim has not yet been matched') throw new Error('This claim has not yet been matched')
} }
if (this.state === E.ClaimState.VERIFIED) { if (this._state === E.ClaimState.VERIFIED) {
throw new Error('This claim has already been verified') throw new Error('This claim has already been verified')
} }
if (this.fingerprint === null) { if (this._fingerprint === null) {
throw new Error('This claim has no fingerprint') throw new Error('This claim has no fingerprint')
} }
@ -249,8 +250,8 @@ class Claim {
opts = mergeOptions(defaults.opts, opts ? opts : {}) opts = mergeOptions(defaults.opts, opts ? opts : {})
// For each match // For each match
for (let index = 0; index < this.dataMatches.length; index++) { for (let index = 0; index < this._dataMatches.length; index++) {
const claimData = this.dataMatches[index] const claimData = this._dataMatches[index]
let verificationResult, let verificationResult,
proofData = null, proofData = null,
@ -267,7 +268,7 @@ class Claim {
verificationResult = verifications.run( verificationResult = verifications.run(
proofData.result, proofData.result,
claimData, claimData,
this.fingerprint this._fingerprint
) )
verificationResult.proof = { verificationResult.proof = {
fetcher: proofData.fetcher, fetcher: proofData.fetcher,
@ -290,13 +291,13 @@ class Claim {
if (verificationResult.completed) { if (verificationResult.completed) {
// Store the result, keep a single match and stop verifying // Store the result, keep a single match and stop verifying
this.verification = verificationResult this._verification = verificationResult
this.dataMatches = [claimData] this._dataMatches = [claimData]
index = this.dataMatches.length index = this._dataMatches.length
} }
} }
this.state = E.ClaimState.VERIFIED this._state = E.ClaimState.VERIFIED
} }
/** /**
@ -307,13 +308,15 @@ class Claim {
* @returns {boolean} * @returns {boolean}
*/ */
isAmbiguous() { isAmbiguous() {
if (this.state === E.ClaimState.INIT) { if (this._state === E.ClaimState.INIT) {
throw new Error('The claim has not been matched yet') throw new Error('The claim has not been matched yet')
} }
if (this.dataMatches.length === 0) { if (this._dataMatches.length === 0) {
throw new Error('The claim has no matches') throw new Error('The claim has no matches')
} }
return this.dataMatches.length > 1 || this.dataMatches[0].match.isAmbiguous return (
this._dataMatches.length > 1 || this._dataMatches[0].match.isAmbiguous
)
} }
/** /**
@ -325,11 +328,11 @@ class Claim {
toJSON() { toJSON() {
return { return {
claimVersion: 1, claimVersion: 1,
uri: this.uri, uri: this._uri,
fingerprint: this.fingerprint, fingerprint: this._fingerprint,
state: this.state, state: this._state,
dataMatches: this.dataMatches, dataMatches: this._dataMatches,
verification: this.verification, verification: _this.verification,
} }
} }
} }

View file

@ -250,13 +250,11 @@ router.get('/get/twitter/:tweetid', async (req, res) => {
return res.status(200).json({ data: data, message: 'Success', error: {} }) return res.status(200).json({ data: data, message: 'Success', error: {} })
}) })
.catch((error) => { .catch((error) => {
return res return res.status(error.statusCode || 400).json({
.status(error.statusCode || 400) data: [],
.json({ message: 'Request could not be fulfilled',
data: [], error: error,
message: 'Request could not be fulfilled', })
error: error,
})
}) })
}) })
@ -277,13 +275,11 @@ router.get('/get/matrix/:matrixroomid/:matrixeventid', async (req, res) => {
return res.status(200).json({ data: data, message: 'Success', error: {} }) return res.status(200).json({ data: data, message: 'Success', error: {} })
}) })
.catch((error) => { .catch((error) => {
return res return res.status(error.statusCode || 400).json({
.status(error.statusCode || 400) data: [],
.json({ message: 'Request could not be fulfilled',
data: [], error: error,
message: 'Request could not be fulfilled', })
error: error,
})
}) })
}) })
@ -318,13 +314,11 @@ router.get('/get/irc/:ircserver/:ircnick', async (req, res) => {
} }
}) })
} catch (error) { } catch (error) {
return res return res.status(400).json({
.status(400) data: [],
.json({ message: 'Request could not be fulfilled',
data: [], error: error,
message: 'Request could not be fulfilled', })
error: error,
})
} }
}) })