feathersjs/feathers-hooks-common

View on GitHub

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

    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

      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

                          Function combine has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          export function combine<H extends HookContext = HookContext>(...serviceHooks: HookFunction<H>[]) {
                            // if (serviceHooks.length && Array.isArray(serviceHooks[0])) {
                            //   serviceHooks = serviceHooks[0];
                            // }
                          
                          
                          Severity: Minor
                          Found in src/utils/combine.ts - About 1 hr to fix

                            Function stashBefore has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            export function stashBefore<H extends HookContext = HookContext>(fieldName?: string) {
                              const beforeField = fieldName || 'before';
                            
                              return (context: H) => {
                                checkContext(context, 'before', ['get', 'update', 'patch', 'remove'], 'stashBefore');
                            Severity: Minor
                            Found in src/hooks/stash-before.ts - About 1 hr to fix

                              Function populateItem has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                              function populateItem(
                                options: any,
                                context: HookContext,
                                item: any,
                                includeSchema: any,
                              Severity: Minor
                              Found in src/hooks/populate.ts - About 1 hr to fix

                                Function serializeItem has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    function serializeItem(item: any, schema: any) {
                                      const computed: Record<string, any> = {};
                                      Object.keys(schema.computed || {}).forEach(name => {
                                        computed[name] = schema.computed[name](item, context); // needs closure
                                      });
                                Severity: Minor
                                Found in src/hooks/serialize.ts - About 1 hr to fix

                                  Function checkContext has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                  export function checkContext<H extends HookContext = HookContext>(
                                    context: H,
                                    type?: HookType | HookType[] | null,
                                    methods?: MethodName | MethodName[] | null,
                                    label = 'anonymous',
                                  Severity: Minor
                                  Found in src/utils/check-context.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 convertResolverResult has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                  function convertResolverResult(result: any, ourQuery: any, fieldName: any, type: any) {
                                    if (result === null || result === undefined) {
                                      return ourQuery.listType ? [] : null;
                                    }
                                  
                                  
                                  Severity: Minor
                                  Found in src/hooks/fgraphql.ts - About 55 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

                                  Function fgraphql has a Cognitive Complexity of 9 (exceeds 5 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: Minor
                                  Found in src/hooks/fgraphql.ts - About 55 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

                                  Function processRecord has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                  function processRecord(store: any, query: any, depth: any, rec: any, type: any, j: any): any {
                                  Severity: Minor
                                  Found in src/hooks/fgraphql.ts - About 45 mins to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language