Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @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({});
const run = async () => {
// 获取当前文章
const article = await Article.findOne({ _id: bson.ObjectId(articleId) })
if (!article) {
process.exit(1)
}
const pcr = await PCR({
revision: "",
detectionPath: "",
folderName: '.chromium-browser-snapshots',
hosts: ["https://storage.googleapis.com", "https://npm.taobao.org/mirrors"],
retry: 3,
silent: false
})
// 获取浏览器
const browser = await (pcr.puppeteer.launch({
executablePath: pcr.executablePath,
documents: SOLAR_SYSTEM_DOCUMENTS
},
namespace: 'aggregations.solarSystem',
pipeline: [
{
...STAGE_DEFAULTS,
id: new ObjectId().toHexString(),
previewDocuments: MATCHING_SOLAR_SYSTEM_DOCUMENTS,
stageOperator: '$match',
stage: `{
type: "Terrestrial planet"
}`
},
{
...STAGE_DEFAULTS,
id: new ObjectId().toHexString(),
previewDocuments: [{ 'terrestrial planets': 4 }],
stageOperator: '$count',
stage: '"terrestrial planets"'
}
]
};
// gathering stats when items are in an array using $project accumulators
const ARRAY_STATS_EXAMPLE = {
...EXAMPLE,
namespace: 'aggregations.solarSystem',
pipeline: [
{
id: 0,
stageOperator: '$project',
stage: `{
describe('api/auth/register', () => {
const sandbox = sinon.sandbox.create();
const defaultServerId = new ObjectId().toHexString();
before(async () => {
await mongoose.connect('mongodb://localhost/myapp-test');
});
beforeEach(() => {
});
after(async () => {
mongoose.connection.close();
});
afterEach(async () => {
await User.remove({});
sandbox.restore();
});
it('returns 400 with invalid data', async () => {
return supertest(app.listen(null))
.post('/api/register')
function createScoreData(user: IUser, params: IScoreDataArguments) {
return {
gameId: params.game === undefined ? new ObjectId() : params.game._id,
score: params.score === undefined ? 10 : params.score,
username: user.username,
roundId: new ObjectId(),
userId: user._id,
rank: params.rank === undefined ? 'S' : params.rank,
mods: params.mods === undefined ? 0 : params.mods,
maxCombo: params.maxCombo === undefined ? 100 : params.maxCombo,
accuracy: params.accuracy === undefined ? 99 : params.accuracy,
misses: params.misses === undefined ? 0 : params.misses,
count100: 1,
date: new Date(),
passedRound: true,
};
}
orbitalPeriod: { value: 0.615, units: 'years' },
eccentricity: 0.0067,
meanOrbitalVelocity: { value: 35.02, units: 'km/sec' },
rotationPeriod: { value: 243.69, units: 'days' },
inclinationOfAxis: { value: 177.36, units: 'degrees' },
meanTemperature: 465,
gravity: { value: 8.87, units: 'm/s^2' },
escapeVelocity: { value: 10.36, units: 'km/sec' },
meanDensity: 5.25,
atmosphericComposition: 'CO2',
numberOfMoons: 0,
hasRings: false,
hasMagneticField: false
},
{
_id: new ObjectId('59a06674c8df9f3cd2ee7d52'),
name: 'Mercury',
type: 'Terrestrial planet',
orderFromSun: 1,
radius: { value: 4879, units: 'km' },
mass: { value: 3.3e23, units: 'kg' },
sma: { value: 57910000, units: 'km' },
orbitalPeriod: { value: 0.24, units: 'years' },
eccentricity: 0.2056,
meanOrbitalVelocity: { value: 47.36, units: 'km/sec' },
rotationPeriod: { value: 58.65, units: 'days' },
inclinationOfAxis: { value: 0, units: 'degrees' },
meanTemperature: 125,
gravity: { value: 3.24, units: 'm/s^2' },
escapeVelocity: { value: 4.25, units: 'km/sec' },
meanDensity: 5.43,
atmosphericComposition: '',
const STAGE_DEFAULTS = {
previewDocuments: [],
isExpanded: true,
error: null,
syntaxError: '',
isValid: true,
isEnabled: true,
isLoading: false,
isComplete: true
};
import { ObjectId } from 'bson';
const SOLAR_SYSTEM_DOCUMENTS = [
{
_id: new ObjectId('59a06674c8df9f3cd2ee7d54'),
name: 'Earth',
type: 'Terrestrial planet',
orderFromSun: 3,
radius: { value: 6378.137, units: 'km' },
mass: { value: 5.9723e24, units: 'kg' },
sma: { value: 149600000, units: 'km' },
orbitalPeriod: { value: 1, units: 'years' },
eccentricity: 0.0167,
meanOrbitalVelocity: { value: 29.78, units: 'km/sec' },
rotationPeriod: { value: 1, units: 'days' },
inclinationOfAxis: { value: 23.45, units: 'degrees' },
meanTemperature: 15,
gravity: { value: 9.8, units: 'm/s^2' },
escapeVelocity: { value: 11.18, units: 'km/sec' },
meanDensity: 5.52,
atmosphericComposition: 'N2+O2',
addArticleTask: async (req, res) => {
let task = new models.Task({
articleId: ObjectId(req.params.id),
platformId: ObjectId(req.body.platformId),
status: constants.status.NOT_STARTED,
createTs: new Date(),
updateTs: new Date(),
category: req.body.category,
tag: req.body.tag,
})
task = await task.save()
await res.json({
status: 'ok',
data: task,
})
},
}
request = (originUrl, requestOptions = {}, callback) => {
const connectionId = ObjectId().toString()
while (originUrl[0] === '/') {
originUrl = originUrl.substr(1)
}
const firstSlash = originUrl.indexOf('/')
const url = firstSlash === -1 ? '/' : originUrl.substr(firstSlash)
const hostname = firstSlash === -1 ? originUrl : originUrl.substring(0, firstSlash)
const headers = Object.assign({}, requestOptions.headers, {
'x-seashell-hostname': hostname,
'x-seashell-connection-id': connectionId,
'x-seashell-url': url,
'x-seashell-guard': 'request-chunk'
})
const _write = (chunk, extHeaders = {}) => {
const json = {
headers: Object.assign({}, headers, extHeaders),
Builds.prototype.all = function(jobid, fn) {
jobid = _.isString(jobid) ? new ObjectId(jobid) : jobid;
var promise = cruder.all(jobid)
.then(function(result) {
return result.map(function(build) {
return new Build(build);
});
});
if (fn) {
promise
.then(function(result) { fn(null, result); })
.catch(fn);
}
return promise;
};