Skip to content
This repository was archived by the owner on Jul 9, 2024. It is now read-only.

Conversation

@lerouxb
Copy link
Contributor

@lerouxb lerouxb commented Apr 28, 2022

"@types/jest": "^26.0.21",
"benchmark": "^2.1.4",
"bson": "^4.2.3",
"bson": "^4.6.3",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to bump bson so we can gain support for {t, i } in tests. See mongodb/js-bson#449

"prettier": "^1.19.1",
"ts-jest": "^26.5.4",
"typescript": "^3.9.9"
"typescript": "^4.3.5"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to bump typescript because bson became typescript and it was still expecting a @types/bson which kept giving me this error:

    test/index.spec.ts:1:23 - error TS7016: Could not find a declaration file for module 'bson'. '/Users/leroux.bodenstein/mongo/ejson-shell-parser/node_modules/bson/lib/bson.js' implicitly has an 'any' type.
      Try `npm install @types/bson` if it exists or add a new declaration (.d.ts) file containing `declare module 'bson';`

    1 import * as bson from 'bson';

Symbol: Symbol('symbol'),
Timestamp: Timestamp(123, 456),
Timestamp_object: Timestamp({ t: 1, i: 2 }),
Timestamp_long: Timestamp(new Long(1, 2)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying to come up with a test case that shows that Timestamp()'s params aren't always two numbers.

Copy link
Collaborator

@jarjee jarjee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

return new (bson as any).BSONSymbol(i);
},
Timestamp: function(low: any, high: any) {
if (typeof low === 'number' && typeof high === 'number') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only nit is possibly we need to change the parameters from low to high to something easier to read/understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went back and forth on that. My current thinking (and really this is still very easy to change) is that the function gets the 32-bit words in that order. BUT Timestamp is overloaded and can take either one or two params. So in a sense it is just an args array that we have to inspect and either pass through unchanged or do something specific with in this one case.

Which is kinda the long way of saying I can't think of anything better than maybe ...args: any[].

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe that's what we should do? I agree that it probably doesn't matter much either way, we're just passing stuff in and praying it's valid anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong preferences, I think it’s fine to keep them as they are or to switch them, the important thing is that it’s visible to readers that something is going on here and I think that is being achieved :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was about to suggest calling the params a and b, but that felt about as ridiculous, so I'm going to just merge :)

@lerouxb lerouxb merged commit a4656eb into master Apr 29, 2022
@lerouxb lerouxb deleted the swap-timestamp-params branch April 29, 2022 09:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants