forattini-dev/s3db.js

View on GitHub

Showing 30 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

    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

      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

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

                  Function main has 36 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/4-read-stream-to-zip.js - About 1 hr to fix

                    Function getItems has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      async getItems({
                        continuationToken = null,
                      }: {
                        continuationToken?: string | null;
                      } = {}) {
                    Severity: Minor
                    Found in src/stream/resource-ids-read-stream.class.ts - About 1 hr to fix

                      Function getContinuationTokenAfterOffset has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                      Open

                        async getContinuationTokenAfterOffset({
                          prefix,
                          offset = 1000,
                        }: {
                          prefix?: string;
                      Severity: Minor
                      Found in src/s3-client.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 getKeysPage has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        async getKeysPage({
                          prefix,
                          offset = 0,
                          amount = 100,
                        }: {
                      Severity: Minor
                      Found in src/s3-client.class.ts - About 1 hr to fix

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

                              async deleteObjects(keys: string[]) {
                                const packages = chunk(keys, 1000);
                            
                                const { results, errors } = await PromisePool.for(packages)
                                  .withConcurrency(this.parallelism)
                            Severity: Minor
                            Found in src/s3-client.class.ts - About 1 hr to fix

                              Function getContinuationTokenAfterOffset has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                async getContinuationTokenAfterOffset({
                                  prefix,
                                  offset = 1000,
                                }: {
                                  prefix?: string;
                              Severity: Minor
                              Found in src/s3-client.class.ts - About 1 hr to fix

                                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
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language