Coder Social home page Coder Social logo

Comments (37)

hasezoey avatar hasezoey commented on June 19, 2024 1

btw the npm package changed to @typegoose/typegoose and version 6.0.0 released

and version 6.0.0 fixed many things, please look at the changelog for more infomation

main things that could affect this here:

  • better errors
  • DEO (Decorator execution order)
  • data changes

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

sorry but i dont understand your issue
the only thing i could get out of your issue and what clearly answered:

  • Do you have models that a circular?

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

I understand circular dependencies but I don't believe my models have any? could it be that all of the classes that reference each other have the typegoose inheritance? would that be a problem?

I am basically trying to 'find all' and return a list but im getting that error, however I can log the objects but can't return the objects. If you need more iinformation, please ask for it.

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

however I can log the objects but can't return the objects

i dont understand what you mean with that


and i ask for circular dependencies, because there are known issues

Please provide an example class & how you access it

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

So i'm logging the object list of the model using the find all function but afterwards in my function to return the object, it comes up with that error. Function for reference:

// Get Webhook List
    public async getAllCustomerWebhookList(): Promise<CustomerWebhooksListDto[]> {
        try {
            const bigWebhookData = await this.webhooksListModel.find().exec();
            this.logger.log(`Big Webhook Data: ${bigWebhookData}`);
            return bigWebhookData;
        } catch (error) {
            this.logger.error(`Get Webhooks List - Failed! ${error}`);
        }
    }

Logs:

[Nest] 73288   - 04/10/2019, 14:04:42   [Mongo - Webhooks - Service] Big Webhook Data: {
  _id: 5d9734fc7a4a0a193497da12,
  customerID: 8039563,
  customerName: 'LANDSEC',
  webhooksList: { _id: 5d9734fc7a4a0a193497da13, settings: [], count: 0 }
},{
  _id: 5d9742885952d51dc473bb6e,
  customerID: 2328405,
  customerName: 'NAME',
  webhooksList: { _id: 5d9742885952d51dc473bb6f, settings: [], count: 0 }
},{
  _id: 5d9743695f659c1e4993df13,
  customerID: 8039563,
  customerName: 'LANDSEC',
  webhooksList: { _id: 5d9743695f659c1e4993df14, settings: [], count: 0 }
}
[Nest] 73288   - 04/10/2019, 14:04:42   [App StartUp - Service] Webhook List Data Failed to Retrieve: RangeError: Maximum call stack size exceeded +62ms

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

could you post the whole class of // Get Webhook List, because i dont understand what would be the issue

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024
import { Injectable, Logger } from '@nestjs/common';
import { InjectModel } from 'nestjs-typegoose';
import { ModelType } from '@hasezoey/typegoose';
import { CustomerWebhooksListDto } from 'src/DTOs/data/customer/customer-webhooks-list.dto';
import { inspect } from 'util';

@Injectable()
export class WebhooksDBService {
    private logger: Logger = new Logger('Mongo - Webhooks - Service');
    constructor(@InjectModel(CustomerWebhooksListDto) private readonly webhooksListModel: ModelType<CustomerWebhooksListDto>) {}

    // CREATE --------------------------------------------------------------------------------------
    // public async method to save data into database - saves webhook list data
    public async setCustomerWebhookList(customerWebhooksListDto: CustomerWebhooksListDto): Promise<CustomerWebhooksListDto> {
        const searchDB: boolean = await this.webhooksListModel.exists(customerWebhooksListDto);
        if (!searchDB) {
            const savedWebhookList = new this.webhooksListModel(customerWebhooksListDto);
            return await savedWebhookList.save();
        } else {
            this.logger.log('This has already been saved');
            return customerWebhooksListDto;
        }
    }

    // public async method to save array of customer webhooks list data into the database
    public async setAllCustomerWebhookList(webhookListDtoList: CustomerWebhooksListDto[]): Promise<CustomerWebhooksListDto[]> {
        try {
            const setArrayWebhooks = await this.webhooksListModel.insertMany(webhookListDtoList);
            return setArrayWebhooks;
        } catch (error) {
            this.logger.log(`Set All Customer Webhooks Data - Failed ${error}`);
        }
    }

    // READ ----------------------------------------------------------------------------------------
    // Get Webhook List
    public async getCustomerWebhookList(): Promise<CustomerWebhooksListDto> {
        try {
            return await this.webhooksListModel.findOne({}, {_id: 0}).sort({_id: -1}).exec();
        } catch (error) {
            this.logger.error(`Get Webhooks List - Failed! ${error}`);
        }
    }

    // Get Webhook List
    public async getAllCustomerWebhookList(): Promise<CustomerWebhooksListDto[]> {
        try {
            const bigWebhookData = await this.webhooksListModel.find().exec();
            this.logger.log(`Big Webhook Data: ${bigWebhookData}`);
            return bigWebhookData;
        } catch (error) {
            this.logger.error(`Get Webhooks List - Failed! ${error}`);
        }
    }

    // DELETE --------------------------------------------------------------------------------------
    public async deleteWebhooksList(): Promise<any> {
        try {
            return await this.webhooksListModel.deleteMany({}).exec();
        } catch (error) {
            this.logger.error(`Delete Webhooks List - Failed! ${error}`);
        }
    }
}

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

could you post your model too? (CustomerWebhooksListDto)

otherwise i cant reproduce it from the information i currently have:

import { arrayProp, getModelForClass, prop, Ref } from "@typegoose/typegoose"; // @typegoose/[email protected]
import * as mongoose from "mongoose"; // [email protected]

class WebHook {
    @prop()
    public somedata?: string;
}

class Project {
    @arrayProp({ itemsRef: "WebHook" })
    public webHooks!: Ref<WebHook>[];
}
const WebHookModel = getModelForClass(WebHook);
const ProjectModel = getModelForClass(Project);

(async () => {
    await mongoose.connect(`mongodb://localhost:27017/`, { useNewUrlParser: true, dbName: "verify67" });

    const hook1 = await WebHookModel.create({ somedata: "Hello Data 1" });
    const hook2 = await WebHookModel.create({ somedata: "Hello Data 2" });

    const project1 = await ProjectModel.create({ webHooks: [hook1, hook2] });

    const found = await ProjectModel.find().exec();
    console.log("found:", found);

    await mongoose.disconnect();
})();

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

And please read https://guides.github.com/features/mastering-markdown/ on how to format longer code

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

I posted them earlier in a zip file, i will post them here too.
Customer Webhooks (top-level: 1)

import { prop, Typegoose, Ref } from '@hasezoey/typegoose';
import { IsNumber, IsNotEmpty, IsString } from 'class-validator';
import { Type } from 'class-transformer';
import { WebhookListDto } from '../webhooks/webhookList.dto';
import { CustomerWebhooksList } from '../../../interfaces/customer.interfaces';

export class CustomerWebhooksListDto extends Typegoose implements CustomerWebhooksList {
    @IsNotEmpty()
    @IsNumber()
    @prop({required: true})
    customerID!: number | string;

    @IsNotEmpty()
    @IsString()
    @prop({required: true})
    customerName!: string;

    @IsNotEmpty()
    @Type(() => WebhookListDto)
    @prop({required: true})
    webhooksList!: WebhookListDto;
}

Webhook List (Level-2 below it):

import { WebhookDto } from './webhook.dto';
import { IsNotEmpty, IsNumber, IsArray, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';
import { prop, arrayProp } from '@hasezoey/typegoose';
import { WebhookList } from '../../../interfaces/webhooks.interface';

// Webhook List Data Type
export class WebhookListDto implements WebhookList {

    @IsNotEmpty()
    @IsNumber()
    @prop({required: true})
    readonly count!: number;

    @ValidateNested()
    @IsNotEmpty()
    @IsArray()
    @Type(() => WebhookDto)
    @arrayProp({required: true, items: WebhookDto})
    readonly settings!: WebhookDto[];
}

Webhook (Level 3 ):

import { IsString, IsNumber, IsNotEmpty } from 'class-validator';
import { prop } from '@hasezoey/typegoose';
import { Webhook } from '../../../interfaces/webhooks.interface';

// Webhooks Data Type
export class WebhookDto implements Webhook {
    @IsNotEmpty()
    @IsString()
    @prop({required: true})
    readonly wid!: string;

    @IsNotEmpty()
    @IsString()
    @prop({required: true})
    readonly name!: string;

    @IsNotEmpty()
    @IsNumber()
    @prop({required: true})
    readonly 'updated_ts'!: number;

    @IsNotEmpty()
    @IsString()
    @prop({required: true})
    readonly 'secure_token'!: string;
}

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

And i'll start reading it now

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

I posted them earlier in a zip file, i will post them here too.

sorry i dont download zipped code

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

@aidanmcdonagh22 btw which typegoose version do you use?

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

"@hasezoey/typegoose@^5.9.2":
version "5.9.2"
resolved "https://registry.yarnpkg.com/@hasezoey/typegoose/-/typegoose-5.9.2.tgz#10e949ba04da61156416448f9d5990794dd15fd3"
integrity sha512-PwbOGJi9IggUF8E2K3fEHSEoBgXV3nlDd1H6m/rjC9iWG1GeKHAp9gp0SPZh3e/5rJ3vWbfWbyukD/pMT3tbxA==
dependencies:
reflect-metadata "^0.1.13"

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

okay, could you send a link for the documentation or is it the same? and also is the types refrerence 'yarn add @types/typegoose' or 'yarn add @types/typegoose/typegoose'? thanks again!

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

okay, could you send a link for the documentation or is it the same?

< 6.0.0 did only have the README documentation, > 6.0.0 uses the github-page documentation https://typegoose.github.io/typegoose/


btw why are readonly 'updated_ts'!: number; and readonly 'secure_token'!: string; names made to strings?

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

what's used instead of modeltype now? and which class are you referencing?

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

what's used instead of modeltype now?

in 6.0.0 it got publicly-facing replace with ReturnModelType, but if you really need it / the previous dosnt work, which in some unknown cases it does not work, you can import it via @typegoose/typegoose/lib/types https://typegoose.github.io/typegoose/docs/types/returnModelType/

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

and for these purposes i made a migration guide, which should include all changes that are necessary to know / to do https://typegoose.github.io/typegoose/guides/migrate-to-6/

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

ahhh brilliant, shame i didn't realise this earlier. I'll have a look at the migration guide now.

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

Earlier when you asked 'btw why are readonly 'updated_ts'!: number; and readonly 'secure_token'!: string; names made to strings?' which class were you refering to?

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

Level 3

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

because my tslint states 'variable name must be in lowerCamelCase, PascalCase or UPPER_CASE (variable-name)' but this is data that i don't really want to change the name of.

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

ok just wanted to be sure

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

I'll remake my classes now, thank you. If i get stuck i'll drop something here.

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

instead of 'ModelType' should i use 'ReturnModelType' or am I implementing the model creation in the DTO classes then injecting them in?

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

am I implementing the model creation in the DTO classes then injecting them in?

i dont know what you mean and always try to use ReturnModelType when working with a class that has been made to a model, otherwise when its a document, use DocumentType

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

Yeah I'm making a class into a model then was injecting it into another class where i would use methods for data CRUD. So instead of
@InjectModel(ListAccessPointsSettingsDto) private readonly listAccessPointsSettingsModel: ModelType<ListAccessPointsSettingsDto> would i use:
@InjectModel(ListAccessPointsSettingsDto) private readonly listAccessPointsSettingsModel: ReturnModelType<typeof ListAccessPointsSettingsDto> ?

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

yes, when typescript dosnt give you any errors, this should work

disclaimer: i still never used type-graphql / nestjs

from typegoose.

B-Stefan avatar B-Stefan commented on June 19, 2024

@aidanmcdonagh22 type-graphql / nestjs should work fine with typegoose v6.x.x.
We are using the same stack.

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

im using nestjs-typegoose but it's using the old repo as the dependency, so all of the methods are technically old/deprecated as they work off the old package.

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

I'm trying to use the mongooseModule from '@nestjs/mongoose' to then inject the existing mongoose connection into my dto classes and be able to run my static class methods for CRUD. I'm currently connecting fine but my classes aren't doing any functionality. The classes have no compile time or run time errors. I'm assuming the solution is to remove @nestjs/typegoose and try and create connections on each class?

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

Iv'e just realised that the package has been updated, I think I've just been confused. The documentation needs moving and old documnetation should refer to new repo. This can be closed!

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

Both packages have been updated and I'm back to this issue, all other issues are solved. The range error appears and i wonder if it's the way I have designed my class for typegoose. I can log the object and see the output but I can't return the object still. When I have a class array within my class, am I just using 'ref:' or am I just using 'items:' or both? would this make a difference? Could it be that the class transform is activating on the object return as a validator for all objects and is therefore overloading the call stack?

from typegoose.

aidanmcdonagh22 avatar aidanmcdonagh22 commented on June 19, 2024

@hasezoey any thoughts?

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

when you are able to log it, but not able "to return it", it isnt a typegoose issue, for more, please create an "minimal" reproduceable class (without type-graphql / nest)

from typegoose.

hasezoey avatar hasezoey commented on June 19, 2024

I will close this because this issue got off-topic and is most likely not a typegoose-specific problem

PS @aidanmcdonagh22 did you got your issues fixed?

from typegoose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.