Kinvey/js-sdk

View on GitHub

Showing 349 of 349 total issues

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

function setTable(dbName: string, tableName: string, table: Map<string, any>) {
  const docs = [];
  table.forEach((value) => docs.push(value));
  window.localStorage.setItem(`${dbName}.${tableName}`, JSON.stringify(docs));
}
Severity: Major
Found in packages/html5-sdk/src/storage/localstorage.ts and 1 other location - About 3 hrs to fix
packages/html5-sdk/src/storage/sessionstorage.ts on lines 14..18

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

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

function setTable(dbName: string, tableName: string, table: Map<string, any>) {
  const docs = [];
  table.forEach((value) => docs.push(value));
  window.sessionStorage.setItem(`${dbName}.${tableName}`, JSON.stringify(docs));
}
Severity: Major
Found in packages/html5-sdk/src/storage/sessionstorage.ts and 1 other location - About 3 hrs to fix
packages/html5-sdk/src/storage/localstorage.ts on lines 14..18

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

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

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

export class User {
  public data: UserData;

  constructor(data: UserData = {}) {
    this.data = data;
Severity: Minor
Found in packages/js-sdk/src/user/user.ts - About 3 hrs to fix

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

    export async function removeManyById(dbName: string, tableName: string, ids: string[]) {
      const table = getTable(dbName, tableName);
      const deleted = ids.map(id => table.delete(id));
      setTable(dbName, tableName, table);
      return deleted.filter(i => i).length;
    Severity: Major
    Found in packages/html5-sdk/src/storage/memory.ts and 3 other locations - About 3 hrs to fix
    packages/html5-sdk/src/storage/localstorage.ts on lines 56..61
    packages/html5-sdk/src/storage/sessionstorage.ts on lines 56..61
    packages/node-sdk/src/storage/memory.ts on lines 44..49

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

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

    export async function removeManyById(dbName: string, tableName: string, ids: string[]) {
      const table = getTable(dbName, tableName);
      const deleted = ids.map(id => table.delete(id));
      setTable(dbName, tableName, table);
      return deleted.filter(i => i).length;
    Severity: Major
    Found in packages/html5-sdk/src/storage/sessionstorage.ts and 3 other locations - About 3 hrs to fix
    packages/html5-sdk/src/storage/localstorage.ts on lines 56..61
    packages/html5-sdk/src/storage/memory.ts on lines 44..49
    packages/node-sdk/src/storage/memory.ts on lines 44..49

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

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

    export async function removeManyById(dbName: string, tableName: string, ids: string[]) {
      const table = getTable(dbName, tableName);
      const deleted = ids.map(id => table.delete(id));
      setTable(dbName, tableName, table);
      return deleted.filter(i => i).length;
    Severity: Major
    Found in packages/node-sdk/src/storage/memory.ts and 3 other locations - About 3 hrs to fix
    packages/html5-sdk/src/storage/localstorage.ts on lines 56..61
    packages/html5-sdk/src/storage/memory.ts on lines 44..49
    packages/html5-sdk/src/storage/sessionstorage.ts on lines 56..61

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

    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

    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

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

      export async function removeManyById(dbName: string, tableName: string, ids: string[]) {
        const table = getTable(dbName, tableName);
        const deleted = ids.map(id => table.delete(id));
        setTable(dbName, tableName, table);
        return deleted.filter(i => i).length;
      Severity: Major
      Found in packages/html5-sdk/src/storage/localstorage.ts and 3 other locations - About 3 hrs to fix
      packages/html5-sdk/src/storage/memory.ts on lines 44..49
      packages/html5-sdk/src/storage/sessionstorage.ts on lines 56..61
      packages/node-sdk/src/storage/memory.ts on lines 44..49

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

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

      function execute(dbName: string, tableName: string, sqlQueries: any, write = false): Promise<any> {
        const escapedTableName = `"${tableName}"`;
        const isMaster = tableName === MASTER_TABLE_NAME;
      
        return new Promise((resolve, reject) => {
      Severity: Major
      Found in packages/html5-sdk/src/storage/websql.ts - About 2 hrs to fix

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

          const request = new KinveyHttpRequest({
            method: HttpRequestMethod.POST,
            auth: KinveyHttpAuth.Session,
            url: formatKinveyBaasUrl(KinveyBaasNamespace.Push, '/unregister-device'),
            body: {
        Severity: Major
        Found in packages/nativescript-sdk/src/nativescript/push.ts and 1 other location - About 2 hrs to fix
        packages/nativescript-sdk/src/nativescript/push.ts on lines 26..37

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

        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 request = new KinveyHttpRequest({
            method: HttpRequestMethod.POST,
            auth: KinveyHttpAuth.Session,
            url: formatKinveyBaasUrl(KinveyBaasNamespace.Push, '/register-device'),
            body: {
        Severity: Major
        Found in packages/nativescript-sdk/src/nativescript/push.ts and 1 other location - About 2 hrs to fix
        packages/nativescript-sdk/src/nativescript/push.ts on lines 53..64

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

        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 user.ts has 276 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import { isArray } from 'lodash-es';
        import { Acl } from '../acl';
        import { Kmd } from '../kmd';
        import { getDeviceId } from '../device';
        import {
        Severity: Minor
        Found in packages/js-sdk/src/user/user.ts - About 2 hrs to fix

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

            while (ids.length) {
              const currentIds = ids.splice(0, 100);
              const deleteQuery = `DELETE FROM #{table} WHERE key IN (${currentIds.map(() => '?').join(', ')})`;
              responses.push(await execute(dbName, tableName, [[deleteQuery, currentIds]], true));
            }
          Severity: Major
          Found in packages/html5-sdk/src/storage/websql.ts and 1 other location - About 2 hrs to fix
          packages/nativescript-sdk/src/nativescript/storage/sqlite.ts on lines 99..103

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

            while (ids.length) {
              const currentIds = ids.splice(0, 100);
              const deleteQuery = `DELETE FROM #{table} WHERE key IN (${currentIds.map(() => '?').join(', ')})`;
              responses.push(await execute(dbName, tableName, [[deleteQuery, currentIds]], true));
            }
          Severity: Major
          Found in packages/nativescript-sdk/src/nativescript/storage/sqlite.ts and 1 other location - About 2 hrs to fix
          packages/html5-sdk/src/storage/websql.ts on lines 117..121

          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

          Function open has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

            async open(url = '/', options: PopupOptions = {}) {
              if (this._open !== true) {
                const activity = Application.android.startActivity || Application.android.foregroundActivity;
                let shouldClose = false;
                let success = false;
          Severity: Minor
          Found in packages/nativescript-sdk/src/nativescript/popup/popup.android.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

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

            get readerGroups() {
              return this.entity._acl && this.entity._acl.groups && isArray(this.entity._acl.groups.r) ? this.entity._acl.groups.r : [];
            }
          Severity: Major
          Found in packages/js-sdk/src/acl.ts and 1 other location - About 2 hrs to fix
          packages/js-sdk/src/acl.ts on lines 62..64

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

          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

            get writerGroups() {
              return this.entity._acl && this.entity._acl.groups && isArray(this.entity._acl.groups.w) ? this.entity._acl.groups.w : [];
            }
          Severity: Major
          Found in packages/js-sdk/src/acl.ts and 1 other location - About 2 hrs to fix
          packages/js-sdk/src/acl.ts on lines 53..55

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

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

            async setAuthorization(auth: KinveyHttpAuth): Promise<void> {
              const appKey = getAppKey();
              const appSecret = getAppSecret();
              const masterSecret = getMasterSecret();
              const session = await getSession();
          Severity: Major
          Found in packages/js-sdk/src/http/headers.ts - About 2 hrs to fix
            Severity
            Category
            Status
            Source
            Language