feathersjs/feathers-hooks-common

View on GitHub

Showing 47 of 47 total issues

File fgraphql.ts has 354 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import type { Application, HookContext, Query } from '@feathersjs/feathers';
import makeDebug from 'debug';
import type { parse, GraphQLFieldResolver } from 'graphql';
import type { SyncContextFunction } from '../types';
import { getItems } from '../utils/get-items';
Severity: Minor
Found in src/hooks/fgraphql.ts - About 4 hrs to fix

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

    function replaceItem(item: any, fields: any) {
      if (typeof item !== 'object' || item === null) return item;
    
      const newItem = {};
      fields.forEach((field: any) => {
    Severity: Major
    Found in src/hooks/keep-in-array.ts and 2 other locations - About 3 hrs to fix
    src/hooks/keep-query-in-array.ts on lines 41..53
    src/hooks/keep.ts on lines 32..44

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

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

    function replaceItem(item: any, fields: any) {
      if (typeof item !== 'object' || item === null) return item;
    
      const newItem = {};
      fields.forEach((field: any) => {
    Severity: Major
    Found in src/hooks/keep.ts and 2 other locations - About 3 hrs to fix
    src/hooks/keep-in-array.ts on lines 45..57
    src/hooks/keep-query-in-array.ts on lines 41..53

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

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

    function replaceItem(item: any, fields: any) {
      if (typeof item !== 'object' || item === null) return item;
    
      const newItem = {};
      fields.forEach((field: any) => {
    Severity: Major
    Found in src/hooks/keep-query-in-array.ts and 2 other locations - About 3 hrs to fix
    src/hooks/keep-in-array.ts on lines 45..57
    src/hooks/keep.ts on lines 32..44

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

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

    export function fgraphql<H extends HookContext = HookContext>(options1: FGraphQLHookOptions<H>) {
      debug('init call');
      const { parse, recordType, resolvers, runTime, query } = options1;
      let { schema } = options1;
    
    
    Severity: Major
    Found in src/hooks/fgraphql.ts - About 3 hrs to fix

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

      export function discardQuery<H extends HookContext = HookContext>(...fieldNames: string[]) {
        return (context: H) => {
          checkContext(context, 'before', null, 'discardQuery');
      
          const query = context.params.query || {};
      Severity: Major
      Found in src/hooks/discard-query.ts and 1 other location - About 3 hrs to fix
      src/hooks/keep-query.ts on lines 9..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 102.

      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

      export function keepQuery<H extends HookContext = HookContext>(...fieldNames: string[]) {
        return (context: H) => {
          checkContext(context, 'before', null, 'keepQuery');
      
          const query = context.params.query || {};
      Severity: Major
      Found in src/hooks/keep-query.ts and 1 other location - About 3 hrs to fix
      src/hooks/discard-query.ts on lines 9..19

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

      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 replaceIn(item: any, field: any, fieldNames: any) {
        const target = _get(item, field);
        if (target) {
          if (!Array.isArray(target))
            throw new BadRequest(
      Severity: Major
      Found in src/hooks/keep-query-in-array.ts and 1 other location - About 3 hrs to fix
      src/hooks/keep-in-array.ts on lines 29..43

      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

      function replaceIn(item: any, field: any, fieldNames: any) {
        const target = _get(item, field);
        if (target) {
          if (!Array.isArray(target))
            throw new BadRequest(
      Severity: Major
      Found in src/hooks/keep-in-array.ts and 1 other location - About 3 hrs to fix
      src/hooks/keep-query-in-array.ts on lines 25..39

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

      function populateAddChild(
        options: any,
        context: HookContext,
        parentItem: any,
        childSchema: any,
      Severity: Major
      Found in src/hooks/populate.ts - About 3 hrs to fix

        Function cache has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function cache<H extends HookContext = HookContext, T = any>(
          cacheMap: CacheMap<T>,
          keyField?: string,
          options?: CacheOptions<T>,
        ) {
        Severity: Minor
        Found in src/hooks/cache.ts - About 2 hrs to fix

          Function populate has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function populate<H extends HookContext = HookContext>(options: PopulateOptions<H>) {
            // options.schema is like { service: '...', permissions: '...', include: [ ... ] }
          
            const typeofSchema = typeof options.schema;
            if ((typeofSchema !== 'object' || options.schema === null) && typeofSchema !== 'function') {
          Severity: Minor
          Found in src/hooks/populate.ts - About 1 hr to fix

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

            export function serialize<H extends HookContext = HookContext>(
              schema1: SerializeSchema<H> | SyncContextFunction<SerializeSchema, H>,
            ) {
              return (context: H) => {
                const schema = typeof schema1 === 'function' ? schema1(context) : schema1;
            Severity: Minor
            Found in src/hooks/serialize.ts - About 1 hr to fix

              Function mongoKeys has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function mongoKeys<H extends HookContext = HookContext>(
                ObjectId: new (id?: string | number) => any,
                keyFields: string | string[],
              ) {
                keyFields = Array.isArray(keyFields) ? keyFields : [keyFields];
              Severity: Minor
              Found in src/hooks/mongo-keys.ts - About 1 hr to fix

                Function processRecord has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function processRecord(store: any, query: any, depth: any, rec: any, type: any, j: any): any {
                  debug(`processRecord rec# ${j} typeof ${typeof rec} Type ${type}`);
                  if (!rec) return; // Catch any null values from resolvers.
                
                  const queryPropNames = Object.keys(query);
                Severity: Minor
                Found in src/hooks/fgraphql.ts - About 1 hr to fix

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

                  function processRecordFieldResolver(
                    store: any,
                    query: any,
                    depth: any,
                    rec: any,
                  Severity: Minor
                  Found in src/hooks/fgraphql.ts - About 1 hr to fix

                    Function debug has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export function debug<H extends HookContext = HookContext>(msg: string, ...fieldNames: string[]) {
                      return (context: H) => {
                        // display timestamp
                        const now = new Date();
                        console.log(
                    Severity: Minor
                    Found in src/hooks/debug.ts - About 1 hr to fix

                      Function alterItems has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      export function alterItems<T = any, H extends HookContext = HookContext>(
                        cb: (record: T, context: H) => any,
                      ) {
                        if (!cb) {
                          cb = () => {};
                      Severity: Minor
                      Found in src/hooks/alter-items.ts - About 1 hr to fix

                        Function processRecordQuery has 10 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                          store: any,
                          query: any,
                          depth: any,
                          rec: any,
                          fieldName: any,
                        Severity: Major
                        Found in src/hooks/fgraphql.ts - About 1 hr to fix

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

                                  items.forEach((item: any) => {
                                    const idName = getIdName(keyField, item);
                                    const key = makeCacheKey(item[idName]);
                                    cacheMap.delete(key);
                                  });
                          Severity: Major
                          Found in src/hooks/cache.ts and 1 other location - About 1 hr to fix
                          src/hooks/cache.ts on lines 75..79

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

                          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

                          Severity
                          Category
                          Status
                          Source
                          Language