forattini-dev/s3db.js

View on GitHub

Showing 60 of 60 total issues

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

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

        try {
          const options: any = {
            Bucket: this.bucket,
            Key: this.keyPrefix ? path.join(this.keyPrefix, key) : key,
          };
    Severity: Major
    Found in src/s3-client.class.ts and 1 other location - About 4 hrs to fix
    src/s3-client.class.ts on lines 169..194

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

    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

        try {
          const options: any = {
            Bucket: this.bucket,
            Key: this.keyPrefix ? path.join(this.keyPrefix, key) : key,
          };
    Severity: Major
    Found in src/s3-client.class.ts and 1 other location - About 4 hrs to fix
    src/s3-client.class.ts on lines 135..159

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

    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

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

    import * as path from "path";
    import { chunk } from "lodash";
    import { nanoid } from "nanoid";
    import { Stream } from "stream";
    import EventEmitter from "events";
    Severity: Minor
    Found in src/s3-client.class.ts - About 3 hrs to fix

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

        stream.on("end", () => {
          console.timeEnd("reading-data");
          process.stdout.write("\n");
          const { size } = fs.statSync(filename);
          console.log(`\nTotal size: ${(size / (1024 * 1000)).toFixed(2)} Mb`);
      Severity: Major
      Found in examples/3-read-stream-to-csv.js and 1 other location - About 3 hrs to fix
      examples/4-read-stream-to-zip.js on lines 46..51

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

      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

        stream.on("end", () => {
          console.timeEnd("reading-data");
          process.stdout.write("\n");
          const { size } = fs.statSync(filename);
          console.log(`\nTotal zip size: ${(size / (1024 * 1000)).toFixed(2)} Mb`);
      Severity: Major
      Found in examples/4-read-stream-to-zip.js and 1 other location - About 3 hrs to fix
      examples/3-read-stream-to-csv.js on lines 47..52

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

      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

      Function main has 72 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      async function main() {
        const s3db = new S3db({
          uri: ENV.CONNECTION_STRING,
          passphrase: ENV.PASSPRHASE,
          parallelism: ENV.PARALLELISM,
      Severity: Major
      Found in examples/5-write-stream.js - About 2 hrs to fix

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

          stream.on("end", () => {
            process.stdout.write("\n");
            console.timeEnd("reading");
            process.stdout.write("\n\n");
            console.log("Total cost:", s3db.client.costs.total.toFixed(4), "USD");
        Severity: Major
        Found in examples/2-read-stream.js and 1 other location - About 2 hrs to fix
        examples/5-write-stream.js on lines 88..93

        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

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

          writeStream.on("end", () => {
            process.stdout.write("\n");
            console.timeEnd("copying-data");
            process.stdout.write("\n\n");
            console.log("Total cost:", s3db.client.costs.total.toFixed(4), "USD");
        Severity: Major
        Found in examples/5-write-stream.js and 1 other location - About 2 hrs to fix
        examples/2-read-stream.js on lines 53..58

        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

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

            if (this.keyPrefix) {
              keys = keys
                .map((x) => x.replace(this.keyPrefix, ""))
                .map((x) => (x.startsWith("/") ? x.replace(`/`, "") : x));
            }
        Severity: Major
        Found in src/s3-client.class.ts and 1 other location - About 2 hrs to fix
        src/s3-client.class.ts on lines 421..425

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

        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 (this.keyPrefix) {
              keys = keys
                .map((x) => x.replace(this.keyPrefix, ""))
                .map((x) => (x.startsWith("/") ? x.replace(`/`, "") : x));
            }
        Severity: Major
        Found in src/s3-client.class.ts and 1 other location - About 2 hrs to fix
        src/s3-client.class.ts on lines 324..328

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

        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

        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

          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

          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 main has 44 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          async function main() {
            const s3db = new S3db({
              uri: ENV.CONNECTION_STRING + Date.now(),
              passphrase: ENV.PASSPRHASE,
              parallelism: ENV.PARALLELISM,
          Severity: Minor
          Found in examples/6-jwt-tokens.js - About 1 hr to fix

            Function main has 43 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            async function main() {
              const s3db = new S3db({
                uri: ENV.CONNECTION_STRING,
                passphrase: ENV.PASSPRHASE,
                parallelism: ENV.PARALLELISM,
            Severity: Minor
            Found in examples/2-read-stream.js - About 1 hr to fix

              Function main has 43 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              async function main() {
                const fake = Fakerator();
              
                const s3db = new S3db({
                  uri: ENV.CONNECTION_STRING,
              Severity: Minor
              Found in examples/1-bulk-insert.js - About 1 hr to fix

                Function _get has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                  async _get({ key }: { key: string }) {
                    try {
                      const res = await this.s3Client.getObject(key);
                
                      if (!res.Body) return "";
                Severity: Minor
                Found in src/cache/s3-cache.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 main has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                async function main() {
                  const s3db = new S3db({
                    uri: ENV.CONNECTION_STRING,
                    passphrase: ENV.PASSPRHASE,
                    parallelism: ENV.PARALLELISM,
                Severity: Minor
                Found in examples/3-read-stream-to-csv.js - About 1 hr to fix
                  Severity
                  Category
                  Status
                  Source
                  Language