Comments (29)
I think this fork will became the new "official" repo.
szokodiakos#387 got merged, it is now officially the new official
from typegoose.
i think its better to be called in buildSchema / _buildSchema, because a class decorator is optional
from typegoose.
It's work fine now, very nice work guy!
I owe one beer, let's add a donation button into the typegoose doc page.
Thank you!
PS: A final suggestion... IMHO, Typegoose would raise an exception if someone uses two classes with the same name, without disambiguate them by collectionName
or customName
.
from typegoose.
Possible Solution:
- cache all decorator evaulations
- cache only inner-class ones
Cache Solutions:
- cache using Map<T, S>
- i dont know any other
Execution Solutions:
- execute the cached ones in buildSchema / _buildSchema
- i dont know any other
Drawback
- more memory consumption, because of storing functions
@B-Stefan what do you think?
from typegoose.
Exactly, I fell in this trap just trying to add a @TypeAlias
as class decorator.
Look at this:
https://stackoverflow.com/questions/57707455/typescript-decorator-get-class-decorator-value-from-method-decorator
I disagree with the answer, I think it's better to use a buffer to cache all metadata produced by method decorator, until class decorator is called.
from typegoose.
encountered a problem: caching is good and all, but how to make differing classes with the same name when schemaOptions nor options can be accessed in @prop? i couldnt find anything that makes a class / function unique ... so for now i made an (undocumented) variable __uniqueID
after doing the change to cached version, 3 tests fail, and i cannot figure out why (because it didnt fail before the cache change, and this only wraps all into another function)
WIP branch: https://github.com/hasezoey/typegoose/tree/r6/cache-inner-class-decorators
from typegoose.
i looked into it again, didnt got it work, though about another possible solution:
"strip" the logic (that calls schemas
and co) and do move them into _buildSchema
Update: found the issue, it is because the subSchemas (that dont have a call to make model, which should not be needed) got not build, and so it was "empty", i currently dont know a fix without forcing the user to always make a model out of it
from typegoose.
Update: added c8a5a18fc35b9c5461c0d78585ff566d57d550a7, which fixes the "build on subdocuments" error, but new ones show up, i think about for now (version 6) disabling the customName functions
PS: for something like this, it seems more easy to just "reinterpret"(/"recreate") mongoose into typescript
Update: could reduce it to 1 test failing (biguser)
from typegoose.
@hasezoey Thanks for working on this!
You are absolutely right - I ran into this issue yesterday again at another combination of nested entities.
from typegoose.
I'm going to pull your branch to try to solve the failing test. My proj constraint is to have more classes with the same name, this feature is strictly necessary to me. It would be a pity to give up, you're doing a very impressive work, I think this fork will became the new "official" repo.
from typegoose.
Update: could theoretically fix "all" the errors, except:
- "_id: false" is just not working on @prop, only on @arrayProp
@fabioformosa Please know that i have 4(and more) unpushed commits, and as i said above (in this comment) i almost fixed everything
from typegoose.
Ok, great! Let me know when you push the new version 6.0.0-27
, so I try it in my project.
It's ok at the moment not use _id: false
from typegoose.
It's ok at the moment not use _id: false
its a requirement in biguser's test currently, and clutters the database
Note:
currently a cache (that caches the build schemas (buildSchemas
in data.ts), but even after re-applying with schema.set("_id", false)
it didnt even change)
Update: made Automattic/mongoose#8137, as long as i dont get an update on it, i will disable the test(requirement) for it, and add a note, but as long as it persists, i cant release 6.0.0
from typegoose.
Update: i made it now commented out, and all tests pass, will squash all the WIP commits, and @fabioformosa could you evaluate/test it? (will make a pr, and update this comment)
Update: its #24
from typegoose.
@hasezoey This is working with my branch except for one test
expect(foundUser.job.jobType).to.not.have.property('_id');
is failing
from typegoose.
@B-Stefan even the new 58490e8?
from typegoose.
Did not tested this commit, yet.
from typegoose.
With 58490e8 all tests are green! 👍 nice work!
from typegoose.
nice work!
i would say its "not nice work" more like "hacky work" / "deactivating an existing feature" (@prop({ _id: false })
dosnt work anymore / only in arrayprop sometimes??)
PS: i really hope the mongoose issue will get resolved fast ... and that 5.7 gets finally released, tomorrow i will look into this (_id: false) once more, why it worked before, and now not, will report then again
Report from next day: i investigated it again, came to the conclusion to wait for Automattic/mongoose#8137 to either support "inline _id:false" or fix ?schema.set('_id', false)
or delete schema.paths._id
works...
from typegoose.
I pushed a commit in this sample project https://github.com/fabioformosa/typegoose-validation-error (you know it) branch typegoosev6
.
Add to package.json
the package of typegoose from branch r6/cache-inner-class-decorators
.
One test fails :(
from typegoose.
easy fix: i made i mistake, it should have been __uniqueID
, but when i set it it was _uniqueID
(notice the double underscore)
fixed in 9f77b49
PS: @fabioformosa i pushed an updated version to your repo (including that @hasezoey/typegoose
is now a git-npm module, if you dont use github & git with ssh, please change to https)
from typegoose.
@fabioformosa for now, the customName thing is disabled until this is fixed...
from typegoose.
PS: A final suggestion... IMHO, Typegoose would raise an exception if someone uses two classes with the same name, without disambiguate them by collectionName or customName.
Actually I ran into this a couple of days ago.
I had two classes with the same name and had to debug the reason why some properties where missing. An Error would be great!
from typegoose.
@fabioformosa for now, the customName thing is disabled until this is fixed...
Ah ok. Which is the unsolved issue?
from typegoose.
Ah ok. Which is the unsolved issue?
#23 (this) | #24 (pr for this)
from typegoose.
@fabioformosa @B-Stefan is this soft error enough? 33e5014
or should it throw instead of being "soft"?
from typegoose.
All tests pass! I tried also here https://github.com/fabioformosa/typegoose-validation-error and it's ok!
The only known issue is that about _id: false
in @prop
, isn't?
from typegoose.
yes, that is why it currently dosnt get merged, because _id: false
is an existing feature, which worked, and now somehow dosnt ... and until now i didnt got a response in the mongoose issue for it
from typegoose.
PR got squash Merged in ada5cfb
from typegoose.
Related Issues (20)
- Automatic populate assertion with type inference HOT 3
- Create virtual in typegoose HOT 1
- Union type HOT 1
- [BUG] - Using .lean() doesn't transform nested populate HOT 3
- Select only fields explicitly declared in class HOT 3
- From required to optional in child class HOT 1
- Why are Ref given as a lambda ? HOT 1
- isRefType function fails to identify wrapped ObjectId instances HOT 10
- Custom linter checks of Typegoose code HOT 1
- Error: Index already exist HOT 5
- Support for nest HOT 1
- Typescript throws errors when passing session in `documentModel.create({<some params>}, {session})` HOT 6
- Does typegoose support TypeScript's mixins (multiple inheritence)? HOT 1
- Cross Database Populate
- setGlobalOptions must be called before usages of @modelOptions() HOT 1
- How can I create a reference based on multiple foreign fields? HOT 1
- Babel to SWC: Inconsistent behavior when querying an undefined field HOT 8
- Not recognizing DocumentType<ModelClass> in the return type of CRUD methods (findOne, findById, etc) HOT 7
- Model doesn't work when used without existingConnection HOT 1
- Can't overwrite design:type using @prop({ type: [XYZ] }) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typegoose.