-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for BigInt field types #21
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a test actually verifying BigInt works~~, also, you may wanna check utils.isNumber
too~~
Edit: nevermind, i thought this was a PR for typegoose (not auto-increment)
I tested this in an actual project I'm working on and it worked just fine, but I'll add a proper test here later today |
After looking into this further, it looks like Mongoose doesn't expose The way I had tested this originally in my personal project was, admittedly, quick and hacky. I just modified the transpiled JavaScript to add these checks, and it works just fine In fact you can verify that this type does exist and is accessible by simply logging it The issue is only that TypeScript thinks the property Not entirely sure how to proceed from here. This is a type defs issue now, not a functionality issue. I suppose I'll file an issue on the Mongoose side and then check back later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks better now, but the snapshots would need to be updated (yarn run test -u
, and verify it is what it should be)
also it looks like there are only tests for BigInt and AutoIncrementID
and not AutoIncrementSimple
?
Ah my apologies. I have never used yarn or jest before, and the test which failed was named with |
There were some errors which cropped up while adding the All tests pass now, though |
Codecov ReportPatch coverage is
📢 Thoughts on this report? Let us know!. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, code looks relatively good to me, though there are still some things i noticed:
- type
AutoIncrementIDOptions
optionsstartAt
andincrementBy
do not listbigint
as supported - type
AutoIncrementOptionsSimple
optionsincrementBy
do not listbigint
as supported - i would rather not change the IDSchema's type, but i guess it should not be a problem (old stuff should get automatically get converted to bigint from number)
also could you explain more on what the problem with negative was? |
My apologies for the late reply as well
I'm not sure what you mean here? Where should this be listed at? The types themselves are already updated to
In my testing yes, everything does get converted correctly
I do apologize but I've forgotten the specifics now, I've been prepping for the hurricane about to hit my state so that was the last thing on my mind 😅 |
i am sorry, it seems i look at some other versions of the code and didnt notice, all is good here, aside from |
@@ -39,13 +39,18 @@ export function AutoIncrementSimple( | |||
throw new Error(`Field "${field.field}" does not exists on the Schema!`); | |||
} | |||
// check if the field is an number | |||
if (!(schemaField instanceof mongoose.Schema.Types.Number)) { | |||
throw new Error(`Field "${field.field}" is not an SchemaNumber!`); | |||
if (schemaField.instance !== 'Number' && schemaField.instance !== 'BigInt') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this still be used once upgraded to mongoose 7.5, which has typescript types for BigInt
?
* Support for BigInt field types * refactor: switch from instanceof to field.instance for type checks to support BigInts * test: added BigInt tests * refactor: allow incrementBy and startAt to be BigInt, change count to BigInt and cast * test: added Simple tests and update snapshots * refactor: move incrementBy and startAt BigInt conversions to pre save callback * fix: type AutoIncrementIDTrackerSpec count is now bigint
i have merged this PR for now, but did a mistake and had to force-push it (bad commit message). i would still like a answer to #21 (comment) |
Released in |
Mongoose supports BigInts as a schema field type, and this library already works with them as-is. The only thing preventing this was a check for only
Number
of the field type