Skip to content
This repository was archived by the owner on Feb 3, 2022. It is now read-only.

Commit 1a02262

Browse files
authoredJan 31, 2020
build(deps-dev): bump mongodb-js-precommit from 0.2.9 to 2.2.0 (#103)
1 parent 6ae4046 commit 1a02262

File tree

4 files changed

+1199
-1107
lines changed

4 files changed

+1199
-1107
lines changed
 

‎lib/modes/shell.js

+55-37
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,60 @@ var format = require('util').format;
44
/* eslint no-cond-assign:0 */
55

66
function toStrictQuotes(str) {
7-
return str
8-
// replace single quotes with double quotes
9-
.replace(/'/g, '"')
10-
// wrap field names in double quotes
11-
.replace(/([{,])\s*([^,{\s\'"]+)\s*:/g, '$1 "$2":');
7+
return (
8+
str
9+
// replace single quotes with double quotes
10+
.replace(/'/g, '"')
11+
// wrap field names in double quotes
12+
.replace(/([{,])\s*([^,{\s\'"]+)\s*:/g, '$1 "$2":')
13+
);
1214
}
1315

1416
function toStrictSimple(str) {
15-
return str
16-
// Timestamps
17-
.replace(/Timestamp\((\d+), (\d+)\)/g, '{ "$timestamp": { "t": $1, "i": $2 } }')
17+
return (
18+
str
19+
// Timestamps
20+
.replace(
21+
/Timestamp\((\d+), (\d+)\)/g,
22+
'{ "$timestamp": { "t": $1, "i": $2 } }'
23+
)
1824

19-
// MinKey and MaxKey are erroneously already printed in strict json format
20-
// @see https://jira.mongodb.org/browse/SERVER-19171
21-
// .replace(/MinKey/g, '{ "$minKey": 1 }')
22-
// .replace(/MaxKey/g, '{ "$maxKey": 1 }')
23-
24-
// ObjectIds
25-
.replace(/ObjectId\("([0-9abcdef]{24})"\)/g, '{ "$oid": "$1" }')
26-
// NumberLong
27-
.replace(/NumberLong\("?([0-9]+)"?\)/g, '{ "$numberLong": "$1" }')
28-
// numberDecimal
29-
.replace(/NumberDecimal\("([0-9.]+)"\)/g, '{ "$numberDecimal": "$1" }')
30-
// Date also prints the wrong format,
31-
// @see https://jira.mongodb.org/browse/SERVER-19171
32-
.replace(/ISODate\("(.+?)"\)/g, '{ "$date": "$1" }')
33-
// DBRef
34-
.replace(/DBRef\("(.+?)", (.+?)\)/g, function(match, ns, id) {
35-
id = toStrictSimple(id);
36-
return '{ "$ref": "' + ns + '", "$id": ' + id + ' }';
37-
})
38-
// undefined, shell is buggy here too,
39-
// @see https://jira.mongodb.org/browse/SERVER-6102
40-
.replace('undefined', '{ "$undefined": true }');
25+
// ObjectIds
26+
.replace(/ObjectId\("([0-9abcdef]{24})"\)/g, '{ "$oid": "$1" }')
27+
// NumberLong
28+
.replace(/NumberLong\("?([0-9]+)"?\)/g, '{ "$numberLong": "$1" }')
29+
// numberDecimal
30+
.replace(/NumberDecimal\("([0-9.]+)"\)/g, '{ "$numberDecimal": "$1" }')
31+
// Date also prints the wrong format,
32+
// @see https://jira.mongodb.org/browse/SERVER-19171
33+
.replace(/ISODate\("(.+?)"\)/g, '{ "$date": "$1" }')
34+
// DBRef
35+
.replace(/DBRef\("(.+?)", (.+?)\)/g, function(match, ns, id) {
36+
id = toStrictSimple(id);
37+
return '{ "$ref": "' + ns + '", "$id": ' + id + ' }';
38+
})
39+
// undefined, shell is buggy here too,
40+
// @see https://jira.mongodb.org/browse/SERVER-6102
41+
.replace('undefined', '{ "$undefined": true }')
42+
);
4143
}
4244

43-
4445
function toStrictRegEx(str) {
4546
var regex = /([,:]\s*)\/(.+?)\/([gims]{0,4})(\s+)/g;
4647
var match;
4748

4849
while ((match = regex.exec(str)) !== null) {
4950
var m2 = match[2].replace(/"/g, '"');
50-
str = str.replace(match[0], format(
51-
'%s{ "$regex": "%s", "$options": "%s" }%s',
52-
match[1], m2, match[3], match[4]));
51+
str = str.replace(
52+
match[0],
53+
format(
54+
'%s{ "$regex": "%s", "$options": "%s" }%s',
55+
match[1],
56+
m2,
57+
match[3],
58+
match[4]
59+
)
60+
);
5361
}
5462
return str;
5563
}
@@ -59,7 +67,10 @@ function toStrictBinData(str) {
5967
var match;
6068
while ((match = regex.exec(str)) !== null) {
6169
var hex = parseInt(match[1], 10).toString(16);
62-
str = str.replace(match[0], '{ "$binary": "' + match[2] + '", "$type": "' + hex + '" }');
70+
str = str.replace(
71+
match[0],
72+
'{ "$binary": "' + match[2] + '", "$type": "' + hex + '" }'
73+
);
6374
}
6475
return str;
6576
}
@@ -98,7 +109,10 @@ module.exports.serialize = {
98109
DBRef: function(v) {
99110
var id;
100111

101-
if (typeof v.oid === 'object' && module.exports.serialize[v.oid.constructor.name]) {
112+
if (
113+
typeof v.oid === 'object' &&
114+
module.exports.serialize[v.oid.constructor.name]
115+
) {
102116
id = module.exports.serialize[v.oid.constructor.name](v.oid);
103117
} else if (typeof v.oid === 'string') {
104118
id = '"' + v.oid + '"';
@@ -126,6 +140,10 @@ module.exports.serialize = {
126140
return format('/%s/%s', v.source, o);
127141
},
128142
Binary: function(v) {
129-
return format('BinData(%s, "%s")', v.sub_type.toString(10), v.buffer.toString('base64'));
143+
return format(
144+
'BinData(%s, "%s")',
145+
v.sub_type.toString(10),
146+
v.buffer.toString('base64')
147+
);
130148
}
131149
};

‎package-lock.json

+1,034-1,006
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"debug": "^4.1.1",
3535
"eslint-config-mongodb-js": "^5.0.3",
3636
"mocha": "~7.0.0",
37-
"mongodb-js-precommit": "^0.2.9",
37+
"mongodb-js-precommit": "^2.2.0",
3838
"mongodb-schema": "^8.2.1"
3939
}
4040
}

‎test/deserialize.test.js

+109-63
Original file line numberDiff line numberDiff line change
@@ -12,56 +12,75 @@ describe('Deserialize', function() {
1212
var codeWithScope = bson.Code('return true', {});
1313

1414
it('converts `{$numberLong: <str>}` to `bson.Long`', function() {
15-
assert(deserialize({
16-
$numberLong: '10'
17-
}).equals(bson.Long.fromString('10')));
15+
assert(
16+
deserialize({
17+
$numberLong: '10'
18+
}).equals(bson.Long.fromString('10'))
19+
);
1820
});
1921

2022
it('converts `{$numberLong: <str>}` to `bson.Long` (between 2^32 and 2^53)', function() {
21-
assert(deserialize({
22-
$numberLong: '4294967297'
23-
}).equals(bson.Long.fromString('4294967297')));
23+
assert(
24+
deserialize({
25+
$numberLong: '4294967297'
26+
}).equals(bson.Long.fromString('4294967297'))
27+
);
2428
});
2529

2630
it('converts `{$numberLong: <str>}` to `bson.Long` (greater than 2^53)', function() {
27-
assert.ok(deserialize({$numberLong: '1234567903'}) instanceof bson.Long);
28-
assert(deserialize({
29-
$numberLong: '18014398509481984'
30-
}).equals(bson.Long.fromString('18014398509481984')));
31+
assert.ok(deserialize({ $numberLong: '1234567903' }) instanceof bson.Long);
32+
assert(
33+
deserialize({
34+
$numberLong: '18014398509481984'
35+
}).equals(bson.Long.fromString('18014398509481984'))
36+
);
3137
});
3238

3339
it('converts `{$numberDecimal: <str>}` to `bson.Decimal128`', function() {
34-
assert.ok(deserialize({$numberDecimal: '1234.567'}) instanceof bson.Decimal128);
40+
assert.ok(
41+
deserialize({ $numberDecimal: '1234.567' }) instanceof bson.Decimal128
42+
);
3543
assert.equal(
36-
deserialize({$numberDecimal: '1234.567'}).toString(),
44+
deserialize({ $numberDecimal: '1234.567' }).toString(),
3745
bson.Decimal128.fromString('1234.567').toString()
3846
);
3947
});
4048

4149
it('converts `{$oid: <_id>}` to `bson.ObjectId`', function() {
42-
assert.deepEqual(deserialize({
43-
$oid: _id.toString()
44-
}), _id);
50+
assert.deepEqual(
51+
deserialize({
52+
$oid: _id.toString()
53+
}),
54+
_id
55+
);
4556
});
4657

4758
it('converts `{$binary: <base64 of buffer>}` to `bson.Binary`', function() {
48-
assert.equal(deserialize({
49-
$binary: bin.buffer.toString('base64')
50-
}).toString('base64'),
51-
bin.buffer.toString('base64'));
59+
assert.equal(
60+
deserialize({
61+
$binary: bin.buffer.toString('base64')
62+
}).toString('base64'),
63+
bin.buffer.toString('base64')
64+
);
5265
});
5366

5467
it('converts `{$code: <code>}` to `bson.Code`', function() {
55-
assert.equal(deserialize({
56-
$code: code.code
57-
}).code, code.code);
68+
assert.equal(
69+
deserialize({
70+
$code: code.code
71+
}).code,
72+
code.code
73+
);
5874
});
5975

6076
it('converts `{$code: <code>, $scope: <scope>}` to `bson.Code`', function() {
61-
assert.equal(deserialize({
62-
$code: codeWithScope.code,
63-
$scope: codeWithScope.scope
64-
}).scope, codeWithScope.scope);
77+
assert.equal(
78+
deserialize({
79+
$code: codeWithScope.code,
80+
$scope: codeWithScope.scope
81+
}).scope,
82+
codeWithScope.scope
83+
);
6584
});
6685

6786
it('converts `{$ref: <namespace>, $id: <string>}` to `bson.DBRef`', function() {
@@ -70,7 +89,8 @@ describe('Deserialize', function() {
7089
$ref: 'local.startup_log',
7190
$id: _id.toString()
7291
}).toString(),
73-
refStringId.toString());
92+
refStringId.toString()
93+
);
7494
});
7595

7696
it('converts `{$ref: <namespace>, $id: <ObjectID>}` to `bson.DBRef`', function() {
@@ -81,71 +101,97 @@ describe('Deserialize', function() {
81101
$oid: _id.toString()
82102
}
83103
}).toString(),
84-
ref.toString());
104+
ref.toString()
105+
);
85106
});
86107

87108
it('converts `{$timestamp: {$t: <low_>, $i: <high_>}` to `bson.Timestamp`', function() {
88-
assert.deepEqual(deserialize({
89-
$timestamp: {
90-
$t: 0,
91-
$i: 0
92-
}
93-
}), bson.Timestamp());
109+
assert.deepEqual(
110+
deserialize({
111+
$timestamp: {
112+
$t: 0,
113+
$i: 0
114+
}
115+
}),
116+
bson.Timestamp()
117+
);
94118
});
95119

96120
it('converts `{$minKey: 1}` to `bson.MinKey`', function() {
97-
assert.deepEqual(deserialize({
98-
$minKey: 1
99-
}), bson.MinKey());
121+
assert.deepEqual(
122+
deserialize({
123+
$minKey: 1
124+
}),
125+
bson.MinKey()
126+
);
100127
});
101128

102129
it('converts `{$maxKey: 1}` to `bson.MaxKey`', function() {
103-
assert.deepEqual(deserialize({
104-
$maxKey: 1
105-
}), bson.MaxKey());
130+
assert.deepEqual(
131+
deserialize({
132+
$maxKey: 1
133+
}),
134+
bson.MaxKey()
135+
);
106136
});
107137

108138
it('converts `{$date: <ms>}` to `Date`', function() {
109139
var d = new Date();
110-
assert.deepEqual(deserialize({
111-
$date: d.getTime()
112-
}), d);
140+
assert.deepEqual(
141+
deserialize({
142+
$date: d.getTime()
143+
}),
144+
d
145+
);
113146
});
114147

115148
it('converts `{$date: <ISO-8601>}` to `Date`', function() {
116149
var d = new Date();
117-
assert.deepEqual(deserialize({
118-
$date: d.toISOString()
119-
}), d);
150+
assert.deepEqual(
151+
deserialize({
152+
$date: d.toISOString()
153+
}),
154+
d
155+
);
120156
});
121157

122158
it('converts `{$date: {$numberLong: <ISO-8601>}}` to `Date`', function() {
123159
var d = new Date();
124-
assert.deepEqual(deserialize({
125-
$date: {
126-
$numberLong: '' + d.getTime()
127-
}
128-
}), d);
160+
assert.deepEqual(
161+
deserialize({
162+
$date: {
163+
$numberLong: '' + d.getTime()
164+
}
165+
}),
166+
d
167+
);
129168
});
130169

131170
it('converts `{$regex: <pattern>, $options: <flags>}` to `RegExp`', function() {
132-
assert.deepEqual(deserialize({
133-
$regex: 'mongodb.com$',
134-
$options: 'g'
135-
}).toString(),
136-
'/mongodb.com$/g');
171+
assert.deepEqual(
172+
deserialize({
173+
$regex: 'mongodb.com$',
174+
$options: 'g'
175+
}).toString(),
176+
'/mongodb.com$/g'
177+
);
137178
});
138179

139180
it('converts `{$undefined: true}` to `undefined`', function() {
140-
assert.deepEqual(deserialize({
141-
$undefined: true
142-
}), undefined);
181+
assert.deepEqual(
182+
deserialize({
183+
$undefined: true
184+
}),
185+
undefined
186+
);
143187
});
144188

145189
it('DOCS-3879: converts `{$date: <iso string>}` to a proper date', function() {
146-
assert.equal(deserialize({
147-
$date: '2014-08-25T17:49:42.288-0400'
148-
}).toUTCString(),
149-
'Mon, 25 Aug 2014 21:49:42 GMT');
190+
assert.equal(
191+
deserialize({
192+
$date: '2014-08-25T17:49:42.288-0400'
193+
}).toUTCString(),
194+
'Mon, 25 Aug 2014 21:49:42 GMT'
195+
);
150196
});
151197
});

0 commit comments

Comments
 (0)
This repository has been archived.