1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

linter fixes

This commit is contained in:
Pedro Gutiérrez 2019-02-21 18:14:07 +01:00 committed by Pedro Gutiérrez
parent 6b3541bbc5
commit 0410793286
15 changed files with 40 additions and 34 deletions

View File

@ -1,9 +1,9 @@
import Config from "../models/Config"
import save = require("save-file")
import { File } from "../ddo/MetaData"
import Config from "../models/Config"
import Account from "../ocean/Account"
import Logger from "../utils/Logger"
import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider"
import Logger from '../utils/Logger'
const { save } = require('save-file')
const apiPath = "/api/v1/brizo/services"
@ -76,7 +76,7 @@ export default class Brizo {
try {
await this.downloadFile(
consumeUrl,
url.split('/').pop() || `file-${i}`,
url.split("/").pop() || `file-${i}`,
destination,
)
} catch (e) {

View File

@ -53,7 +53,6 @@ export class DDO {
this.service = (ddo && ddo.service) || []
}
public shortId(): string {
return this.id.replace("did:op:", "")
}

View File

@ -38,7 +38,7 @@ export default class Ocean {
Logger.setLevel(
typeof config.verbose !== "number"
? (config.verbose ? LogLevel.Log : LogLevel.None)
: <LogLevel>config.verbose
: config.verbose as LogLevel,
)
ConfigProvider.setConfig(config)

View File

@ -56,7 +56,7 @@ export default class OceanAccounts {
try {
await account.requestTokens(amount)
return true
} catch(e) {
} catch (e) {
return false
}
}

View File

@ -1,7 +1,7 @@
import AquariusProvider from "../aquarius/AquariusProvider"
import BrizoProvider from "../brizo/BrizoProvider"
import Account from "./Account"
import { generateId } from "../utils/GeneratorHelpers"
import Account from "./Account"
import DID from "./DID"
import ServiceAgreement from "./ServiceAgreements/ServiceAgreement"

View File

@ -6,16 +6,16 @@ import { Condition } from "../ddo/Condition"
import { DDO } from "../ddo/DDO"
import { MetaData } from "../ddo/MetaData"
import { Service, ServiceAuthorization } from "../ddo/Service"
import EventListener from "../keeper/EventListener"
import Keeper from "../keeper/Keeper"
import SecretStoreProvider from "../secretstore/SecretStoreProvider"
import Logger from "../utils/Logger"
import Account from "./Account"
import DID from "./DID"
import OceanAgreements from "./OceanAgreements"
import ServiceAgreement from "./ServiceAgreements/ServiceAgreement"
import ServiceAgreementTemplate from "./ServiceAgreements/ServiceAgreementTemplate"
import Access from "./ServiceAgreements/Templates/Access"
import EventListener from "../keeper/EventListener"
import ServiceAgreement from "./ServiceAgreements/ServiceAgreement"
import Logger from '../utils/Logger'
/**
* Assets submodule of Ocean Protocol.
@ -128,7 +128,7 @@ export default class OceanAssets {
},
{
type: "Authorization",
services: 'SecretStore',
services: "SecretStore",
serviceEndpoint: secretStoreUri,
serviceDefinitionId: String(serviceDefinitionIdCount++),
},
@ -181,9 +181,10 @@ export default class OceanAssets {
return storedDdo
}
public async consume (agreementId: string, did: string, serviceDefinitionId: string, consumerAccount: Account, resultPath: string): Promise<string>
public async consume (agreementId: string, did: string, serviceDefinitionId: string, consumerAccount: Account): Promise<true>
public async consume (
// tslint:disable-next-line
public async consume(agreementId: string, did: string, serviceDefinitionId: string, consumerAccount: Account, resultPath: string): Promise<string>
public async consume(agreementId: string, did: string, serviceDefinitionId: string, consumerAccount: Account): Promise<true>
public async consume(
agreementId: string,
did: string,
serviceDefinitionId: string,
@ -193,9 +194,9 @@ export default class OceanAssets {
const brizo = BrizoProvider.getBrizo()
const ddo = await this.resolve(did)
const {metadata} = ddo.findServiceByType('Metadata')
const {metadata} = ddo.findServiceByType("Metadata")
const authorizationService = ddo.findServiceByType('Authorization')
const authorizationService = ddo.findServiceByType("Authorization")
const accessService = ddo.findServiceById(serviceDefinitionId)
const files = metadata.base.encryptedFiles
@ -203,7 +204,7 @@ export default class OceanAssets {
const {serviceEndpoint} = accessService
if (!serviceEndpoint) {
throw new Error('Consume asset failed, service definition is missing the `serviceEndpoint`.')
throw new Error("Consume asset failed, service definition is missing the `serviceEndpoint`.")
}
const secretStoreUrl = authorizationService.service === "SecretStore" && authorizationService.serviceEndpoint

View File

@ -47,7 +47,7 @@ export default class OceanTokens {
try {
await account.requestTokens(amount)
return true
} catch(e) {
} catch (e) {
return false
}
}

View File

@ -26,7 +26,13 @@ export default class ServiceAgreement extends OceanBase {
const valueHashes: string[] = ServiceAgreement.createValueHashes(values)
const timeoutValues: number[] = ServiceAgreement.getTimeoutValuesFromService(service)
const serviceAgreementHashSignature = await ServiceAgreement.createSAHashSignature(service, serviceAgreementId, valueHashes, timeoutValues, consumer)
const serviceAgreementHashSignature = await ServiceAgreement.createSAHashSignature(
service,
serviceAgreementId,
valueHashes,
timeoutValues,
consumer,
)
Logger.log("SA hash signature:", serviceAgreementHashSignature)

View File

@ -14,7 +14,7 @@ export default class SecretStoreProvider {
config = {...config}
// Cleaning undefined parameters
Object.keys(config)
.forEach(key => config[key] || delete config[key])
.forEach((key) => config[key] || delete config[key])
if (!Object.keys(config).length) {
if (!SecretStoreProvider.secretStore) {

View File

@ -1,8 +1,8 @@
import {v4} from "uuid"
export function generateId(length = 64) {
let id = ''
while(id.length < length) {
let id = ""
while (id.length < length) {
id += v4().replace(/-/g, "")
}
return id.substr(0, length)

View File

@ -7,7 +7,6 @@ export enum LogLevel {
}
export default class Logger {
private static logLevel: LogLevel = LogLevel.Verbose
public static setLevel(level: LogLevel) {
this.logLevel = level
@ -28,6 +27,7 @@ export default class Logger {
public static error(...args: any[]) {
Logger.dispatch("error", LogLevel.Error, ...args)
}
private static logLevel: LogLevel = LogLevel.Verbose
private static dispatch(verb: string, level: LogLevel, ...args: any[]) {
if (this.logLevel >= level) {

View File

@ -2,8 +2,8 @@ import {assert} from "chai"
import ConfigProvider from "../../src/ConfigProvider"
import DIDRegistry from "../../src/keeper/contracts/DIDRegistry"
import Account from "../../src/ocean/Account"
import { generateId } from "../../src/utils/GeneratorHelpers"
import Ocean from "../../src/ocean/Ocean"
import { generateId } from "../../src/utils/GeneratorHelpers"
import Logger from "../../src/utils/Logger"
import config from "../config"
import TestContractHandler from "./TestContractHandler"

View File

@ -20,9 +20,9 @@ describe("OceanAccounts", () => {
describe("#getInstance()", () => {
it("should get an instance of OceanAccounts", async () => {
const oceanAccounts: OceanAccounts = await OceanAccounts.getInstance()
const oceanAccountsInstance: OceanAccounts = await OceanAccounts.getInstance()
assert.instanceOf(oceanAccounts, OceanAccounts, "No returned OceanAccounts instance")
assert.instanceOf(oceanAccountsInstance, OceanAccounts, "No returned OceanAccounts instance")
})
})
@ -30,14 +30,14 @@ describe("OceanAccounts", () => {
it("should return the list of accounts", async () => {
const accounts = await oceanAccounts.list()
accounts.map(account => assert.instanceOf(account, Account))
accounts.map((account) => assert.instanceOf(account, Account))
})
})
describe("#balance()", () => {
it("should return the balance of an account", async () => {
const [account] = await oceanAccounts.list()
spy.on(account, 'getBalance', () => ({eth: 1, ocn: 5}))
spy.on(account, "getBalance", () => ({eth: 1, ocn: 5}))
const balance = await oceanAccounts.balance(account)
assert.deepEqual(balance, {eth: 1, ocn: 5})
@ -47,7 +47,7 @@ describe("OceanAccounts", () => {
describe("#requestTokens()", () => {
it("should return the balance of an account", async () => {
const [account] = await oceanAccounts.list()
spy.on(account, 'requestTokens', () => 10)
spy.on(account, "requestTokens", () => 10)
const success = await oceanAccounts.requestTokens(account, 10)
assert.isTrue(success)

View File

@ -31,9 +31,9 @@ describe("OceanSecretStore", () => {
describe("#getInstance()", () => {
it("should get an instance of OceanSecretStore", async () => {
const oceanSecretStore: OceanSecretStore = await OceanSecretStore.getInstance()
const oceanSecretStoreInstance: OceanSecretStore = await OceanSecretStore.getInstance()
assert.instanceOf(oceanSecretStore, OceanSecretStore, "No returned OceanSecretStore instance")
assert.instanceOf(oceanSecretStoreInstance, OceanSecretStore, "No returned OceanSecretStore instance")
})
})

View File

@ -5,11 +5,11 @@ import { DDO } from "../../src/ddo/DDO"
import { Service } from "../../src/ddo/Service"
import Account from "../../src/ocean/Account"
import DID from "../../src/ocean/DID"
import { generateId } from "../../src/utils/GeneratorHelpers"
import Ocean from "../../src/ocean/Ocean"
import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement"
import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate"
import Access from "../../src/ocean/ServiceAgreements/Templates/Access"
import { generateId } from "../../src/utils/GeneratorHelpers"
import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProvider"
import config from "../config"
import TestContractHandler from "../keeper/TestContractHandler"
@ -164,7 +164,7 @@ describe("ServiceAgreement", () => {
try {
// Allowing 1 more retry
await consumerAccount.requestTokens(metaDataService.metadata.base.price)
} catch(e) {
} catch (e) {
await consumerAccount.requestTokens(metaDataService.metadata.base.price)
}