oceanprotocol/ocean.js

View on GitHub
src/services/Provider.ts

Summary

Maintainability
F
1 wk
Test Coverage
F
59%

File Provider.ts has 752 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import fetch from 'cross-fetch'
import { ethers, Signer, providers } from 'ethers'
import { LoggerInstance } from '../utils'
import {
  Arweave,
Severity: Major
Found in src/services/Provider.ts - About 1 day to fix

    Provider has 22 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class Provider {
      /**
       * Returns the provider endpoints
       * @param {string} providerUri - the provider url
       * @return {Promise<any>}
    Severity: Minor
    Found in src/services/Provider.ts - About 2 hrs to fix

      Function computeStart has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        public async computeStart(
          providerUri: string,
          consumer: Signer,
          computeEnv: string,
          dataset: ComputeAsset,
      Severity: Major
      Found in src/services/Provider.ts - About 2 hrs to fix

        Function computeDelete has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          public async computeDelete(
            did: string,
            consumer: Signer,
            jobId: string,
            providerUri: string,
        Severity: Major
        Found in src/services/Provider.ts - About 2 hrs to fix

          Function computeStop has 54 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            public async computeStop(
              did: string,
              consumerAddress: string,
              jobId: string,
              providerUri: string,
          Severity: Major
          Found in src/services/Provider.ts - About 2 hrs to fix

            Function computeStatus has 45 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              public async computeStatus(
                providerUri: string,
                consumerAddress: string,
                jobId?: string,
                agreementId?: string,
            Severity: Minor
            Found in src/services/Provider.ts - About 1 hr to fix

              Function initializeCompute has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                public async initializeCompute(
                  assets: ComputeAsset[],
                  algorithm: ComputeAlgorithm,
                  computeEnv: string,
                  validUntil: number,
              Severity: Minor
              Found in src/services/Provider.ts - About 1 hr to fix

                Function initialize has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  public async initialize(
                    did: string,
                    serviceId: string,
                    fileIndex: number,
                    consumerAddress: string,
                Severity: Minor
                Found in src/services/Provider.ts - About 1 hr to fix

                  Function checkDidFiles has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    public async checkDidFiles(
                      did: string,
                      serviceId: string,
                      providerUri: string,
                      withChecksum: boolean = false,
                  Severity: Minor
                  Found in src/services/Provider.ts - About 1 hr to fix

                    Function getFileInfo has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                    Wontfix

                      public async getFileInfo(
                        file: UrlFile | Arweave | Ipfs | GraphqlQuery | Smartcontract,
                        providerUri: string,
                        withChecksum: boolean = false,
                        signal?: AbortSignal
                    Severity: Minor
                    Found in src/services/Provider.ts - About 1 hr to fix

                      Function getComputeEnvironments has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        public async getComputeEnvironments(
                          providerUri: string,
                          signal?: AbortSignal
                        ): Promise<{ [chainId: number]: ComputeEnvironment[] }> {
                          const providerEndpoints = await this.getEndpoints(providerUri)
                      Severity: Minor
                      Found in src/services/Provider.ts - About 1 hr to fix

                        Function getDownloadUrl has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          public async getDownloadUrl(
                            did: string,
                            serviceId: string,
                            fileIndex: number,
                            transferTxId: string,
                        Severity: Minor
                        Found in src/services/Provider.ts - About 1 hr to fix

                          Function getComputeResultUrl has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            public async getComputeResultUrl(
                              providerUri: string,
                              consumer: Signer,
                              jobId: string,
                              index: number
                          Severity: Minor
                          Found in src/services/Provider.ts - About 1 hr to fix

                            Function computeStatus has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                            Open

                              public async computeStatus(
                                providerUri: string,
                                consumerAddress: string,
                                jobId?: string,
                                agreementId?: string,
                            Severity: Minor
                            Found in src/services/Provider.ts - About 55 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Function computeDelete has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                              public async computeDelete(
                                did: string,
                                consumer: Signer,
                                jobId: string,
                                providerUri: string,
                            Severity: Minor
                            Found in src/services/Provider.ts - About 35 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Function initialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                              public async initialize(
                                did: string,
                                serviceId: string,
                                fileIndex: number,
                                consumerAddress: string,
                            Severity: Minor
                            Found in src/services/Provider.ts - About 35 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Function getNonce has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                              public async getNonce(
                                providerUri: string,
                                consumerAddress: string,
                                signal?: AbortSignal,
                                providerEndpoints?: any,
                            Severity: Minor
                            Found in src/services/Provider.ts - About 35 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Function computeStop has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                              public async computeStop(
                                did: string,
                                consumerAddress: string,
                                jobId: string,
                                providerUri: string,
                            Severity: Minor
                            Found in src/services/Provider.ts - About 25 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Function computeStart has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                              public async computeStart(
                                providerUri: string,
                                consumer: Signer,
                                computeEnv: string,
                                dataset: ComputeAsset,
                            Severity: Minor
                            Found in src/services/Provider.ts - About 25 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Function checkDidFiles has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                              public async checkDidFiles(
                                did: string,
                                serviceId: string,
                                providerUri: string,
                                withChecksum: boolean = false,
                            Severity: Minor
                            Found in src/services/Provider.ts - About 25 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Function getFileInfo has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                              public async getFileInfo(
                                file: UrlFile | Arweave | Ipfs | GraphqlQuery | Smartcontract,
                                providerUri: string,
                                withChecksum: boolean = false,
                                signal?: AbortSignal
                            Severity: Minor
                            Found in src/services/Provider.ts - About 25 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Function isValidProvider has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                              public async isValidProvider(url: string, signal?: AbortSignal): Promise<boolean> {
                                try {
                                  const response = await fetch(url, {
                                    method: 'GET',
                                    headers: { 'Content-Type': 'application/json' },
                            Severity: Minor
                            Found in src/services/Provider.ts - About 25 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Similar blocks of code found in 3 locations. Consider refactoring.
                            Open

                                try {
                                  response = await fetch(computeDeleteUrl, {
                                    method: 'DELETE',
                                    body: JSON.stringify(payload),
                                    headers: { 'Content-Type': 'application/json' },
                            Severity: Major
                            Found in src/services/Provider.ts and 2 other locations - About 3 hrs to fix
                            src/services/Provider.ts on lines 583..595
                            src/services/Provider.ts on lines 665..677

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 103.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 3 locations. Consider refactoring.
                            Open

                                try {
                                  response = await fetch(computeStopUrl, {
                                    method: 'PUT',
                                    body: JSON.stringify(payload),
                                    headers: { 'Content-Type': 'application/json' },
                            Severity: Major
                            Found in src/services/Provider.ts and 2 other locations - About 3 hrs to fix
                            src/services/Provider.ts on lines 583..595
                            src/services/Provider.ts on lines 851..863

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 103.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 3 locations. Consider refactoring.
                            Open

                                try {
                                  response = await fetch(computeStartUrl, {
                                    method: 'POST',
                                    body: JSON.stringify(payload),
                                    headers: { 'Content-Type': 'application/json' },
                            Severity: Major
                            Found in src/services/Provider.ts and 2 other locations - About 3 hrs to fix
                            src/services/Provider.ts on lines 665..677
                            src/services/Provider.ts on lines 851..863

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 103.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Identical blocks of code found in 2 locations. Consider refactoring.
                            Open

                                try {
                                  response = await fetch(path, {
                                    method: 'POST',
                                    body: JSON.stringify(args),
                                    headers: { 'Content-Type': 'application/json' },
                            Severity: Major
                            Found in src/services/Provider.ts and 1 other location - About 2 hrs to fix
                            src/services/Provider.ts on lines 267..278

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 91.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Identical blocks of code found in 2 locations. Consider refactoring.
                            Open

                                try {
                                  response = await fetch(path, {
                                    method: 'POST',
                                    body: JSON.stringify(args),
                                    headers: { 'Content-Type': 'application/json' },
                            Severity: Major
                            Found in src/services/Provider.ts and 1 other location - About 2 hrs to fix
                            src/services/Provider.ts on lines 212..223

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 91.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Identical blocks of code found in 2 locations. Consider refactoring.
                            Open

                                if (response?.ok) {
                                  const results: FileInfo[] = await response.json()
                                  for (const result of results) {
                                    files.push(result)
                                  }
                            Severity: Major
                            Found in src/services/Provider.ts and 1 other location - About 1 hr to fix
                            src/services/Provider.ts on lines 279..285

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 62.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Identical blocks of code found in 2 locations. Consider refactoring.
                            Open

                                if (response?.ok) {
                                  const results: FileInfo[] = await response.json()
                                  for (const result of results) {
                                    files.push(result)
                                  }
                            Severity: Major
                            Found in src/services/Provider.ts and 1 other location - About 1 hr to fix
                            src/services/Provider.ts on lines 224..230

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 62.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 3 locations. Consider refactoring.
                            Open

                                  const response = await fetch(path, {
                                    method: 'POST',
                                    body: JSON.stringify(data),
                                    headers: { 'Content-Type': 'application/octet-stream' },
                                    signal
                            Severity: Major
                            Found in src/services/Provider.ts and 2 other locations - About 40 mins to fix
                            src/services/Aquarius.ts on lines 102..107
                            src/services/Aquarius.ts on lines 170..177

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 49.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            There are no issues that match your filters.

                            Category
                            Status