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

Commit a4656eb

Browse files
authored
Merge pull request #109 from mongodb-js/swap-timestamp-params
reverse Timestamp() param order COMPASS-5733
2 parents c9c0145 + 339b817 commit a4656eb

File tree

4 files changed

+1732
-1871
lines changed

4 files changed

+1732
-1871
lines changed

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,24 @@
2626
"bson": "^4.2.3"
2727
},
2828
"devDependencies": {
29-
"@babel/core": "^7.14.3",
29+
"@babel/core": "^7.16.0",
3030
"@babel/plugin-proposal-class-properties": "^7.13.0",
3131
"@babel/plugin-proposal-object-rest-spread": "^7.11.0",
32-
"@babel/preset-env": "^7.13.12",
33-
"@babel/preset-typescript": "^7.13.0",
32+
"@babel/preset-env": "^7.15.6",
33+
"@babel/preset-typescript": "^7.15.6",
3434
"@preconstruct/cli": "^2.1.0",
35-
"@types/bson": "^4.0.3",
3635
"@types/estree": "^0.0.41",
3736
"@types/jest": "^26.0.21",
3837
"benchmark": "^2.1.4",
39-
"bson": "^4.2.3",
38+
"bson": "^4.6.3",
4039
"husky": ">=5",
4140
"jest": "^26.6.3",
4241
"lint-staged": ">=11",
4342
"mongodb-query-parser": "2.1.1",
4443
"np": "^7.4.0",
4544
"prettier": "^1.19.1",
4645
"ts-jest": "^26.5.4",
47-
"typescript": "^3.9.9"
46+
"typescript": "^4.3.5"
4847
},
4948
"preconstruct": {
5049
"umdName": "EJSONShellParser",

src/scope.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ const SCOPE: { [x: string]: Function } = {
6464
return new (bson as any).BSONSymbol(i);
6565
},
6666
Timestamp: function(low: any, high: any) {
67+
if (typeof low === 'number' && typeof high === 'number') {
68+
// https://www.mongodb.com/docs/manual/reference/bson-types/#timestamps
69+
// reverse the order to match the legacy shell
70+
return new bson.Timestamp({ t: low, i: high });
71+
}
72+
6773
return new bson.Timestamp(low, high);
6874
},
6975
ISODate: function(...args: any[]) {

test/index.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ it('should accept a complex query', function() {
4848
ObjectID: ObjectID("5e159ba7eac34211f2252aaa"),
4949
ObjectId: ObjectId("5e159ba7eac34211f2252aaa"),
5050
Symbol: Symbol('symbol'),
51-
Timestamp: Timestamp(123, 456),
51+
Timestamp: Timestamp(100, 0),
52+
Timestamp_object: Timestamp({ t: 1, i: 2 }),
53+
Timestamp_long: Timestamp(new Long(1, 2)),
5254
ISODate: ISODate("2020-01-01 12:00:00"),
5355
Date: Date("2020-01-01 12:00:00")
5456
}`)
@@ -80,7 +82,9 @@ it('should accept a complex query', function() {
8082
ObjectID: new bson.ObjectID('5e159ba7eac34211f2252aaa'),
8183
ObjectId: new bson.ObjectId('5e159ba7eac34211f2252aaa'),
8284
Symbol: new (bson as any).BSONSymbol('symbol'),
83-
Timestamp: new bson.Timestamp(123, 456),
85+
Timestamp: new bson.Timestamp({ t: 100, i: 0 }),
86+
Timestamp_object: new bson.Timestamp({ t: 1, i: 2 }),
87+
Timestamp_long: new bson.Timestamp(bson.Long.fromNumber(8589934593)),
8488
ISODate: new Date('2020-01-01 12:00:00'),
8589
Date: new Date('2020-01-01 12:00:00'),
8690
});
@@ -95,7 +99,7 @@ it('should support binary operators (like plus / minus)', function() {
9599
}`)
96100
).toEqual({
97101
_id: new bson.ObjectId('5e159ba7eac34211f2252aaa'),
98-
created: new bson.Timestamp(20, 10),
102+
created: new bson.Timestamp(10, 20),
99103
filter: { year: { $gte: 2020 } },
100104
});
101105
});

0 commit comments

Comments
 (0)