Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
///
import * as bson from 'bson';
let BSON = new bson.BSONPure.BSON();
let Long = bson.BSONPure.Long;
let doc = {long: Long.fromNumber(100)}
// Serialize a document
let data = BSON.serialize(doc, false, true, false);
console.log("data:", data);
// Deserialize the resulting Buffer
let doc_2 = BSON.deserialize(data);
console.log("doc_2:", doc_2);
BSON = new bson.BSONNative.BSON();
data = BSON.serialize(doc);
doc_2 = BSON.deserialize(data);
///
import * as bson from 'bson';
let BSON = new bson.BSONPure.BSON();
let Long = bson.BSONPure.Long;
let doc = {long: Long.fromNumber(100)}
// Serialize a document
let data = BSON.serialize(doc, false, true, false);
console.log("data:", data);
// Deserialize the resulting Buffer
let doc_2 = BSON.deserialize(data);
console.log("doc_2:", doc_2);
BSON = new bson.BSONNative.BSON();
data = BSON.serialize(doc);
doc_2 = BSON.deserialize(data);
const { EJSON } = require('bson')
const text = '{ "int32": { "$numberInt": "10" } }'
// prints { int32: { [String: '10'] _bsontype: 'Int32', value: '10' } }
console.log(EJSON.parse(text, { relaxed: false }))
// prints { int32: 10 }
console.log(EJSON.parse(text))
docs.forEach(function(third) { // document
var document = collection + '/' + third;
assert.equal(extname(third), '.bson');
var _id = third.split('.bson')[0];
var data = BSON.deserialize(fs.readFileSync(document, {
encoding: null
}));
assert.deepEqual(data, DOCS[_id]);
fs.unlinkSync(document);
});
fs.rmdirSync(collection);
// @flow
import BSON from "bson";
import { ObjectId } from "bson";
const bson = new BSON();
bson.serialize({ foo: "bar" });
// $ExpectError missing arg to serialize
bson.serialize();
// $ExpectError missing method
bson.wrong();
const id = new ObjectId();
id.toString();
// $ExpectError
id.wrong();
// $ExpectError
const wrongId = new ObjectId({});
acl,
contentType,
bodyUintArray
);
expect(result.location).toEqual(expectedLocation);
verify(
serviceMock.callFunction(anything(), anything(), anything())
).times(4);
const [funcNameArg4, funcArgsArg4, resultClassArg4]: any[] = capture(
serviceMock.callFunction
).last();
expect("put").toEqual(funcNameArg4);
expect(1).toEqual(funcArgsArg4.length);
expectedArgs.body = new BSON.Binary(new Buffer(bodyUintArray));
expect(expectedArgs).toEqual(funcArgsArg4[0]);
expect(ResultDecoders.PutObjectResultDecoder).toEqual(resultClassArg4);
// Should pass along errors
when(
serviceMock.callFunction(anything(), anything(), anything())
).thenThrow(new Error("whoops"));
try {
await client.putObject(bucket, key, acl, contentType, body);
fail();
} catch (_) {
// Do nothing
}
});
});
Request.prototype.reply = function(documents, options) {
options = options || {};
documents = Array.isArray(documents) ? documents : [documents];
// Unpack any variables we need
var cursorId = options.cursorId || Long.ZERO;
var responseFlags = typeof options.responseFlags === 'number' ? options.responseFlags : 0;
var startingFrom = typeof options.startingFrom === 'number' ? options.startingFrom : 0;
var numberReturned = documents.length;
// Additional response Options
var killConnectionAfterNBytes =
typeof options.killConnectionAfterNBytes === 'number'
? options.killConnectionAfterNBytes
: null;
// Create the Response document
var response;
if (options.compression) {
response = new CompressedResponse(
this.bson,
{
.then(response => {
expect(response.statusCode).toBe(200);
const expected = {
a: 42,
hello: "world"
};
expect(expected).toEqual(EJSON.parse(response.body!, { relaxed: true }));
// Error responses should be handled
when(transportMock.roundTrip(anything())).thenResolve({
headers: {},
statusCode: 500
});
return stitchRequestClient.doRequest(builder.build());
})
.catch((error: StitchServiceError) => {
.then(response => {
expect(response.statusCode).toEqual(200);
const expected = {
a: 42,
hello: "world"
};
expect(EJSON.parse(response.body!, { relaxed: true })).toEqual(expected);
// Error responses should be handled
when(transportMock.roundTrip(anything())).thenResolve({
headers: {},
statusCode: 500
});
return stitchRequestClient.doRequest(builder.build());
})
.catch((error: StitchServiceError) => {
// Unpack the cursor
var lowBits =
data[this.index] |
(data[this.index + 1] << 8) |
(data[this.index + 2] << 16) |
(data[this.index + 3] << 24);
this.index = this.index + 4;
var highBits =
data[this.index] |
(data[this.index + 1] << 8) |
(data[this.index + 2] << 16) |
(data[this.index + 3] << 24);
this.index = this.index + 4;
// Create long object
this.cursorId = new Long(lowBits, highBits);
// Unpack the starting from
this.startingFrom =
data[this.index] |
(data[this.index + 1] << 8) |
(data[this.index + 2] << 16) |
(data[this.index + 3] << 24);
this.index = this.index + 4;
// Unpack the number of objects returned
this.numberReturned =
data[this.index] |
(data[this.index + 1] << 8) |
(data[this.index + 2] << 16) |
(data[this.index + 3] << 24);
this.index = this.index + 4;