Kinvey/js-sdk

View on GitHub
packages/js-sdk/src/datastore/cachestore.ts

Summary

Maintainability
F
6 days
Test Coverage

File cachestore.ts has 435 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { isArray, times } from 'lodash-es';
import { Observable } from 'rxjs';
import { Query } from '../query';
import { KinveyError } from '../errors/kinvey';
import { MissingConfigurationError } from '../errors/missingConfiguration';
Severity: Minor
Found in packages/js-sdk/src/datastore/cachestore.ts - About 6 hrs to fix

    Function _pullInternal has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

      async _pullInternal(query: Query = new Query(), pullOptions: any = {}, options: { paginationCountsOnly?: boolean } = {}) : Promise<any[]|number> {
        const network = new NetworkStore(this.collectionName);
        const cache = new DataStoreCache(this.collectionName, this.tag);
        const queryCache = new QueryCache(this.tag);
        const useDeltaSet = pullOptions.useDeltaSet === true || this.useDeltaSet;
    Severity: Minor
    Found in packages/js-sdk/src/datastore/cachestore.ts - About 4 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 _pullInternal has 84 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async _pullInternal(query: Query = new Query(), pullOptions: any = {}, options: { paginationCountsOnly?: boolean } = {}) : Promise<any[]|number> {
        const network = new NetworkStore(this.collectionName);
        const cache = new DataStoreCache(this.collectionName, this.tag);
        const queryCache = new QueryCache(this.tag);
        const useDeltaSet = pullOptions.useDeltaSet === true || this.useDeltaSet;
    Severity: Major
    Found in packages/js-sdk/src/datastore/cachestore.ts - About 3 hrs to fix

      CacheStore has 26 functions (exceeds 20 allowed). Consider refactoring.
      Open

      export class CacheStore {
        public collectionName: string;
        public tag?: string;
        public useDeltaSet: boolean;
        public useAutoPagination: boolean;
      Severity: Minor
      Found in packages/js-sdk/src/datastore/cachestore.ts - About 3 hrs to fix

        Function removeById has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

          async removeById(id: string, options: any = {}) {
            const autoSync = options.autoSync === true || this.autoSync;
            const cache = new DataStoreCache(this.collectionName, this.tag);
            const sync = new Sync(this.collectionName, this.tag);
            let count = 0;
        Severity: Minor
        Found in packages/js-sdk/src/datastore/cachestore.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 findById has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

          findById(id: string, options: any = {}) {
            const stream = Observable.create(async (observer: any) => {
              try {
                // if (!id) {
                //   throw new Error('No id was provided. A valid id is required.');
        Severity: Minor
        Found in packages/js-sdk/src/datastore/cachestore.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 _createMany has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private async _createMany(docs: any, options: any = {}) {
            const apiVersion = getApiVersion();
            if (apiVersion < 5) {
              throw new KinveyError('Unable to create an array of entities. Please create entities one by one or use API version 5 or newer.');
            }
        Severity: Minor
        Found in packages/js-sdk/src/datastore/cachestore.ts - About 1 hr to fix

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

            findById(id: string, options: any = {}) {
              const stream = Observable.create(async (observer: any) => {
                try {
                  // if (!id) {
                  //   throw new Error('No id was provided. A valid id is required.');
          Severity: Minor
          Found in packages/js-sdk/src/datastore/cachestore.ts - About 1 hr to fix

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

              async removeById(id: string, options: any = {}) {
                const autoSync = options.autoSync === true || this.autoSync;
                const cache = new DataStoreCache(this.collectionName, this.tag);
                const sync = new Sync(this.collectionName, this.tag);
                let count = 0;
            Severity: Minor
            Found in packages/js-sdk/src/datastore/cachestore.ts - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                          if (pushResult.error) {
                            count -= 1;
                          }
              Severity: Major
              Found in packages/js-sdk/src/datastore/cachestore.ts - About 45 mins to fix

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

                  async pullById(id: string, options: any = {}) {
                    const network = new NetworkStore(this.collectionName);
                    const cache = new DataStoreCache(this.collectionName, this.tag);
                
                    // Push sync queue
                Severity: Minor
                Found in packages/js-sdk/src/datastore/cachestore.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 2 locations. Consider refactoring.
                Open

                  group(aggregation: Aggregation, options: any = {}) {
                    const autoSync = options.autoSync === true || this.autoSync;
                    const cache = new DataStoreCache(this.collectionName, this.tag);
                    const stream = Observable.create(async (observer: any) => {
                      try {
                Severity: Major
                Found in packages/js-sdk/src/datastore/cachestore.ts and 1 other location - About 1 day to fix
                packages/js-sdk/src/datastore/cachestore.ts on lines 66..86

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

                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

                  count(query?: Query, options: any = {}) {
                    const autoSync = options.autoSync === true || this.autoSync;
                    const cache = new DataStoreCache(this.collectionName, this.tag);
                    const stream = Observable.create(async (observer: any) => {
                      try {
                Severity: Major
                Found in packages/js-sdk/src/datastore/cachestore.ts and 1 other location - About 1 day to fix
                packages/js-sdk/src/datastore/cachestore.ts on lines 88..108

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

                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 (autoSync) {
                      const query = new Query().equalTo('_id', syncDoc._id);
                      const pushResults = await sync.push(query, options);
                      const pushResult = pushResults.shift();
                
                
                Severity: Major
                Found in packages/js-sdk/src/datastore/cachestore.ts and 1 other location - About 2 hrs to fix
                packages/js-sdk/src/datastore/cachestore.ts on lines 259..269

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

                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 (autoSync) {
                      const query = new Query().equalTo('_id', syncDoc._id);
                      const pushResults = await sync.push(query, options);
                      const pushResult = pushResults.shift();
                
                
                Severity: Major
                Found in packages/js-sdk/src/datastore/cachestore.ts and 1 other location - About 2 hrs to fix
                packages/js-sdk/src/datastore/cachestore.ts on lines 183..193

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

                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 (count > 0) {
                      // TODO in newer version
                      // if (autoSync) {
                      //   await sync.push();
                      //   return this.pull(query, Object.assign({}, { useDeltaSet, useAutoPagination, autoSync }, options));
                Severity: Major
                Found in packages/js-sdk/src/datastore/cachestore.ts and 1 other location - About 1 hr to fix
                packages/js-sdk/src/datastore/cachestore.ts on lines 523..537

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

                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 (count > 0) {
                      // TODO in newer version
                      // if (autoSync) {
                      //   await sync.push();
                      //   return this.pull(query, Object.assign({}, { useDeltaSet, useAutoPagination, autoSync }, options));
                Severity: Major
                Found in packages/js-sdk/src/datastore/cachestore.ts and 1 other location - About 1 hr to fix
                packages/js-sdk/src/datastore/cachestore.ts on lines 395..409

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

                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

                  async pendingSyncDocs(query?: Query) {
                    const sync = new Sync(this.collectionName, this.tag);
                    return sync.find(queryToSyncQuery(query));
                  }
                Severity: Minor
                Found in packages/js-sdk/src/datastore/cachestore.ts and 1 other location - About 45 mins to fix
                packages/js-sdk/src/datastore/cachestore.ts on lines 578..581

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

                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

                  async clearSync(query?: Query) {
                    const sync = new Sync(this.collectionName, this.tag);
                    return sync.remove(queryToSyncQuery(query));
                  }
                Severity: Minor
                Found in packages/js-sdk/src/datastore/cachestore.ts and 1 other location - About 45 mins to fix
                packages/js-sdk/src/datastore/cachestore.ts on lines 564..567

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

                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