Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Maximum call stack size exceeded #86

Closed
ivanguimam opened this issue Mar 15, 2018 · 1 comment
Closed

Maximum call stack size exceeded #86

ivanguimam opened this issue Mar 15, 2018 · 1 comment

Comments

@ivanguimam
Copy link
Contributor

ivanguimam commented Mar 15, 2018

I have the following structure

export class Db {
  private db

  constructor(db:any) {
    this.db = db
  }

  protected findOne(query):Promise {
    return new Promise(async (res, rej) => {
      this.db.findOne(query, (err, doc) => {
        if (err) {
          rej({ error: err })
        } else {
          if (!!doc) {
            doc.id = doc._id
            res(doc)
          } else {
            rej({ error: 'NOT_FOUND' })
          }
        }
      })
    })
  }
}

user.ts

import { UserFactory } from '../../factory/user/user.entity'
import { Db } from '../db/db'

export class User extends Db {
  constructor(db:any) {
    super(db)
  }

  findByEmailAndPasswod(email:string, password:string):Promise {
    return super.findOne({ email, password })
  }
}

database.ts

import { User } from './user/user'

const Datastore = require('nedb')
require('dotenv').load()

let db = new Datastore({ filename: `database/datastore/data.${process.env.target}.db`, autoload: true })

let a:any = {}
export const DataBase = {
  user: new User(db)
}

login.ts (I have other files equal to this)

import { AuthAssets } from './assets'
import { generateToken } from '../utils/jwt'
import { DataBase } from '../../database/database'

module.exports = {
  path: `/auth/login`,
  method: 'POST',
  render: async (req:any, res:any) => {
    const { email, password } = req.body

    try {
      let user = await DataBase.user.findByEmailAndPasswod(email, password)
      res.status(200).send({ user: user })
    } catch(e) {
      if (e.error === 'NOT_FOUND') res.status(401).send(e)
      else res.status(500).send(e)
    }
  }
}

dyson.js

const DYSON = require('dyson')
const PATH = require('path')

let options = {
  configDir: PATH.join(__dirname, 'out-tsc', 'mock'),
  port: 3333
}
const configs = DYSON.getConfigurations(options);
const appBefore = DYSON.createServer(options);
const appAfter = DYSON.registerServices(appBefore, options, configs)

console.log('DYSON STARTED PORT 3333')

When I try to run the Dyzon I get a "Maximum call stack size exceeded "

command: "node dyson.js"

Error:

RangeError: Maximum call stack size exceeded
at findRecursive (/home/ivan/repositories/luva_acessoria/frontend/node_modules/dyson/lib/loader.js:12:23)
at findRecursive (/home/ivan/repositories/luva_acessoria/frontend/node_modules/dyson/lib/loader.js:23:22)
at findRecursive (/home/ivan/repositories/luva_acessoria/frontend/node_modules/dyson/lib/loader.js:23:22)
at findRecursive (/home/ivan/repositories/luva_acessoria/frontend/node_modules/dyson/lib/loader.js:23:22)
at findRecursive (/home/ivan/repositories/luva_acessoria/frontend/node_modules/dyson/lib/loader.js:23:22)
at findRecursive (/home/ivan/repositories/luva_acessoria/frontend/node_modules/dyson/lib/loader.js:23:22)
at findRecursive (/home/ivan/repositories/luva_acessoria/frontend/node_modules/dyson/lib/loader.js:23:22)
at findRecursive (/home/ivan/repositories/luva_acessoria/frontend/node_modules/dyson/lib/loader.js:23:22)
at findRecursive (/home/ivan/repositories/luva_acessoria/frontend/node_modules/dyson/lib/loader.js:23:22)
at findRecursive (/home/ivan/repositories/luva_acessoria/frontend/node_modules/dyson/lib/loader.js:23:22)

Datastore {
  inMemoryOnly: false,
  autoload: true,
  timestampData: false,
  filename: 'database/datastore/data.DEV.db',
  compareStrings: undefined,
  persistence: 
   Persistence {
     db: [Circular],
     inMemoryOnly: false,
     filename: 'database/datastore/data.DEV.db',
     corruptAlertThreshold: 0.1,
     afterSerialization: [Function],
     beforeDeserialization: [Function],
     method: undefined },
  executor: 
   Executor {
     buffer: [],
     ready: false,
     queue: 
      { tasks: [Array],
        concurrency: 1,
        saturated: null,
        empty: null,
        drain: null,
        push: [Function: push],
        unshift: [Function: unshift],
        process: [Function: process],
        length: [Function: length],
        running: [Function: running] } },
  indexes: 
   { _id: 
      Index {
        fieldName: '_id',
        unique: true,
        sparse: false,
        treeOptions: [Object],
        tree: [Object] } },
  ttlIndexes: {},
  method: undefined }
Persistence {
  db: 
   Datastore {
     inMemoryOnly: false,
     autoload: true,
     timestampData: false,
     filename: 'database/datastore/data.DEV.db',
     compareStrings: undefined,
     persistence: [Circular],
     executor: Executor { buffer: [], ready: false, queue: [Object] },
     indexes: { _id: [Object] },
     ttlIndexes: {},
     method: undefined },
  inMemoryOnly: false,
  filename: 'database/datastore/data.DEV.db',
  corruptAlertThreshold: 0.1,
  afterSerialization: [Function],
  beforeDeserialization: [Function],
  method: undefined }
@ivanguimam
Copy link
Contributor Author

I managed to solve, when the typescript compiled my files it generated a folder "mock", so far so good, because that was how it was configured my "tsconfig.json". The problem was that inside the folder "mock" it created another folder "mock" ai the script of the dyson entered in a recursion

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant