Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this._moduleExports.Server.prototype,
// Forced to ignore due to incomplete typings
// tslint:disable-next-line:ban-ts-ignore
// @ts-ignore
fn,
this._getPatchCommand(fn)
);
}
}
if (this._moduleExports.Cursor) {
this._logger.debug(
'patching mongodb-core.Cursor.prototype functions:',
this._CURSOR_METHODS
);
shimmer.massWrap(
[this._moduleExports.Cursor.prototype],
this._CURSOR_METHODS as never[],
// tslint:disable-next-line:no-any
this._getPatchCursor() as any
);
}
return this._moduleExports;
}
protected massWrap(nodule,names, wrapper) {
shimmer.massWrap(nodule, names, wrapper);
}
return function makeClientConstructor(
this: typeof grpcTypes.Client,
methods: grpcTypes.ServiceDefinition,
serviceName: string,
options: grpcTypes.GenericClientOptions
) {
const client = original.apply(this, arguments);
shimmer.massWrap(
client.prototype,
Object.keys(methods) as never[],
plugin.getPatchedClientMethods()
);
return client;
};
};
function shimModel(target) {
if (target.findById.__wrapped) return
shimmer.massWrap(target, ['findById', 'findByPrimary'], original => {
return function batchedFindById(id, options = {}) {
if ([null, undefined].indexOf(id) !== -1) {
return Promise.resolve(null)
}
if (options.transaction) {
return original.apply(this, arguments)
}
return loaderForModel(this, this.primaryKeyAttribute, this.primaryKeyField, options)
.load(id).then(rejectOnEmpty.bind(null, options))
}
})
}
protected applyPatch() {
this.logger.debug('Patched MongoDB');
if (this.moduleExports.Server) {
this.logger.debug('patching mongodb-core.Server.prototype.command');
shimmer.wrap(
this.moduleExports.Server.prototype,
'command' as never,
this.getPatchCommand()
);
this.logger.debug(
'patching mongodb-core.Server.prototype functions:',
this.SERVER_FNS
);
shimmer.massWrap(
[this.moduleExports.Server.prototype],
this.SERVER_FNS as never[],
this.getPatchQuery()
);
}
if (this.moduleExports.Cursor) {
this.logger.debug(
'patching mongodb-core.Cursor.prototype functions:',
this.CURSOR_FNS_FIRST
);
shimmer.massWrap(
[this.moduleExports.Cursor.prototype],
this.CURSOR_FNS_FIRST as never[],
this.getPatchCursor()
);
function shimModel(target) {
if (target.findByPk ? target.findByPk.__wrapped : target.findById.__wrapped) return;
shimmer.massWrap(target, methods(Sequelize.version).findByPk, original => {
return function batchedFindById(id, options = {}) {
if ([null, undefined].indexOf(id) !== -1) {
return Promise.resolve(null);
}
if (options.transaction || options.include || activeClsTransaction() || !options[EXPECTED_OPTIONS_KEY]) {
return original.apply(this, arguments);
}
const loaders = options[EXPECTED_OPTIONS_KEY].loaders;
let loader = loaders[this.name].byPrimaryKey;
if (options.raw) {
const cacheKey = getCacheKey(this, this.primaryKeyAttribute, {raw: options.raw});
loader = loaders.autogenerated.get(cacheKey);
if (!loader) {
loader = createModelAttributeLoader(this, this.primaryKeyAttribute, {raw: options.raw, logging: options.logging});
loaders.autogenerated.set(cacheKey, loader);
let instrumentMysql2 = function(mysql2, opts = {}) {
shimmer.massWrap(mysql2.Connection.prototype, ["execute", "query"], function(original) {
return function(...args) {
if (args.length < 1 || !api.traceActive()) {
return original.apply(this, args);
}
let query = args[0].sql;
if (typeof query === "undefined") {
query = args[0];
}
return api.startAsyncSpan(
{
[schema.EVENT_TYPE]: "mysql2",
[schema.PACKAGE_VERSION]: opts.packageVersion,
[schema.TRACE_SPAN_NAME]: "query",
"db.query": query,
},
}
if (!clientTarget.__iopipeShimmer) {
shimmer.massWrap(clientTarget, clientOps, wrapCommand);
clientTarget.__iopipeShimmer = true;
}
if (!collectionTarget.__iopipeShimmer) {
shimmer.massWrap(collectionTarget, collectionOps, wrapCommand);
collectionTarget.__iopipeShimmer = true;
}
if (!serverTarget.__iopipeShimmer) {
shimmer.massWrap(serverTarget, serverOps, wrapCommand);
serverTarget.__iopipeShimmer = true;
}
if (!cursorTarget.__iopipeShimmer) {
shimmer.massWrap(cursorTarget, cursorOps, wrapCommand);
cursorTarget.__iopipeShimmer = true;
}
return true;
function wrapCommand(original, command) {
if (typeof original !== 'function') {
return original;
}
return function wrappedCommand() {
const context = this;
const id = createId();
const args = Array.prototype.slice.call(arguments);
let cb, cbIdx, wrappedCb;
for (const i in args) {