|
6 | 6 | * README.md file in the root directory of this source tree. |
7 | 7 | */ |
8 | 8 |
|
| 9 | +const util = require('util') |
9 | 10 | var defaults = require('./defaults'); |
10 | 11 |
|
11 | 12 | function escapeElement(elementRepresentation) { |
@@ -137,11 +138,29 @@ function normalizeQueryConfig (config, values, callback) { |
137 | 138 | return config; |
138 | 139 | } |
139 | 140 |
|
| 141 | +const queryEventEmitterOverloadDeprecationMessage = ` |
| 142 | +Using the automatically created return value from client.query as an event emitter is deprecated. |
| 143 | +Use either the callback or promise interface. |
| 144 | +` |
| 145 | + |
| 146 | +const deprecateEventEmitter = function(Emitter) { |
| 147 | + const Result = function () { |
| 148 | + Emitter.apply(this, arguments) |
| 149 | + } |
| 150 | + util.inherits(Result, Emitter) |
| 151 | + Result.prototype._on = Result.prototype.on |
| 152 | + Result.prototype._once = Result.prototype.once |
| 153 | + Result.prototype.on = util.deprecate(Result.prototype.on, queryEventEmitterOverloadDeprecationMessage) |
| 154 | + Result.prototype.once = util.deprecate(Result.prototype.once, queryEventEmitterOverloadDeprecationMessage) |
| 155 | + return Result |
| 156 | +} |
| 157 | + |
140 | 158 | module.exports = { |
141 | 159 | prepareValue: function prepareValueWrapper (value) { |
142 | 160 | //this ensures that extra arguments do not get passed into prepareValue |
143 | 161 | //by accident, eg: from calling values.map(utils.prepareValue) |
144 | 162 | return prepareValue(value); |
145 | 163 | }, |
146 | | - normalizeQueryConfig: normalizeQueryConfig |
| 164 | + normalizeQueryConfig: normalizeQueryConfig, |
| 165 | + deprecateEventEmitter: deprecateEventEmitter, |
147 | 166 | }; |
0 commit comments