forattini-dev/s3db.js

View on GitHub
src/s3-resource.class.ts

Summary

Maintainability
F
3 days
Test Coverage

File s3-resource.class.ts has 413 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import * as path from "path";
import { nanoid } from "nanoid";
import CryptoJS from "crypto-js";
import EventEmitter from "events";
import { flatten, unflatten } from "flat";
Severity: Minor
Found in src/s3-resource.class.ts - About 5 hrs to fix

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

    export class S3Resource extends EventEmitter implements ResourceInterface {
      name: any;
      schema: any;
      mapObj: any;
      options: any;
    Severity: Minor
    Found in src/s3-resource.class.ts - About 2 hrs to fix

      Function studyOptions has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

        studyOptions() {
          if (!this.options.afterUnmap) this.options.beforeMap = {};
          if (!this.options.afterUnmap) this.options.afterUnmap = {};
      
          const schema: any = flatten(this.schema, { safe: true });
      Severity: Minor
      Found in src/s3-resource.class.ts - About 2 hrs 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 update has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async update(id: any, attributes: any) {
          const obj = await this.get(id);
      
          let attrs1 = flatten(attributes, { safe: true });
          let attrs2 = flatten(obj, { safe: true });
      Severity: Minor
      Found in src/s3-resource.class.ts - About 1 hr to fix

        Function studyOptions has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          studyOptions() {
            if (!this.options.afterUnmap) this.options.beforeMap = {};
            if (!this.options.afterUnmap) this.options.afterUnmap = {};
        
            const schema: any = flatten(this.schema, { safe: true });
        Severity: Minor
        Found in src/s3-resource.class.ts - About 1 hr to fix

          Function unmap has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            unmap(data: any) {
              const obj = Object.entries(data).reduce((acc: any, [key, value]) => {
                acc[this.reversedMapObj[key]] = value;
                return acc;
              }, {});
          Severity: Minor
          Found in src/s3-resource.class.ts - About 1 hr 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 insert has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            async insert(attributes: any) {
              let { id, ...attrs }: { id: any; attrs: any } = flatten(attributes, {
                safe: true,
              });
          
          
          Severity: Minor
          Found in src/s3-resource.class.ts - About 1 hr to fix

            Function getAll has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              async getAll() {
                if (this.s3Cache) {
                  const cached = await this.s3Cache.get({ action: "getAll" });
                  if (cached) return cached;
                }
            Severity: Minor
            Found in src/s3-resource.class.ts - About 1 hr to fix

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

                async getAll() {
                  if (this.s3Cache) {
                    const cached = await this.s3Cache.get({ action: "getAll" });
                    if (cached) return cached;
                  }
              Severity: Minor
              Found in src/s3-resource.class.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 map has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                map(data: any) {
                  let obj: any = { ...data };
              
                  for (const [attribute, actions] of Object.entries(this.options.beforeMap)) {
                    for (const action of actions as string[]) {
              Severity: Minor
              Found in src/s3-resource.class.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

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

                  const { results } = await PromisePool.for(objects)
                    .withConcurrency(this.s3db.parallelism)
                    .handleError(async (error, content) => {
                      this.emit("error", error, content);
                      this.s3db.emit("error", this.name, error, content);
              Severity: Major
              Found in src/s3-resource.class.ts and 1 other location - About 2 hrs to fix
              src/s3-resource.class.ts on lines 399..415

              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 80.

              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 2 locations. Consider refactoring.
              Open

                  const { results } = await PromisePool.for(packages)
                    .withConcurrency(this.s3db.parallelism)
                    .handleError(async (error, content) => {
                      this.emit("error", error, content);
                      this.s3db.emit("error", this.name, error, content);
              Severity: Major
              Found in src/s3-resource.class.ts and 1 other location - About 2 hrs to fix
              src/s3-resource.class.ts on lines 372..381

              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 80.

              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 2 locations. Consider refactoring.
              Open

                  if (!isValid) {
                    return Promise.reject(
                      new S3dbInvalidResource({
                        bucket: this.s3Client.bucket,
                        resourceName: this.name,
              Severity: Major
              Found in src/s3-resource.class.ts and 1 other location - About 1 hr to fix
              src/s3-resource.class.ts on lines 227..236

              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 57.

              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 2 locations. Consider refactoring.
              Open

                  if (!isValid) {
                    return Promise.reject(
                      new S3dbInvalidResource({
                        bucket: this.s3Client.bucket,
                        resourceName: this.name,
              Severity: Major
              Found in src/s3-resource.class.ts and 1 other location - About 1 hr to fix
              src/s3-resource.class.ts on lines 299..308

              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 57.

              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

                  if (this.s3Cache) {
                    const cached = await this.s3Cache.get({ action: "getAll" });
                    if (cached) return cached;
                  }
              Severity: Minor
              Found in src/s3-resource.class.ts and 2 other locations - About 30 mins to fix
              src/s3-resource.class.ts on lines 352..355
              src/s3-resource.class.ts on lines 431..434

              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 45.

              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

                  if (this.s3Cache) {
                    const cached = await this.s3Cache.get({ action: "listIds" });
                    if (cached) return cached;
                  }
              Severity: Minor
              Found in src/s3-resource.class.ts and 2 other locations - About 30 mins to fix
              src/s3-resource.class.ts on lines 352..355
              src/s3-resource.class.ts on lines 482..485

              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 45.

              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

                  if (this.s3Cache) {
                    const cached = await this.s3Cache.get({ action: "count" });
                    if (cached) return cached;
                  }
              Severity: Minor
              Found in src/s3-resource.class.ts and 2 other locations - About 30 mins to fix
              src/s3-resource.class.ts on lines 431..434
              src/s3-resource.class.ts on lines 482..485

              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 45.

              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