@google-cloud/promisify 0.1.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +78 -0
- package/LICENSE +1 -1
- package/README.md +28 -3
- package/build/src/index.d.ts +40 -18
- package/build/src/index.js +137 -88
- package/package.json +22 -17
- package/build/src/index.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
[npm history][1]
|
|
4
|
+
|
|
5
|
+
[1]: https://www.npmjs.com/package/nodejs-promisify?activeTab=versions
|
|
6
|
+
|
|
7
|
+
## v0.4.0
|
|
8
|
+
|
|
9
|
+
02-12-2019 19:44 PST
|
|
10
|
+
|
|
11
|
+
### New features
|
|
12
|
+
- feat: add callbackify() and callbackifyAll() methods ([#82](https://github.com/googleapis/nodejs-promisify/pull/82))
|
|
13
|
+
|
|
14
|
+
### Documentation
|
|
15
|
+
- docs: update contributing path in README ([#86](https://github.com/googleapis/nodejs-promisify/pull/86))
|
|
16
|
+
- chore: move CONTRIBUTING.md to root ([#85](https://github.com/googleapis/nodejs-promisify/pull/85))
|
|
17
|
+
- docs: add lint/fix example to contributing guide ([#83](https://github.com/googleapis/nodejs-promisify/pull/83))
|
|
18
|
+
|
|
19
|
+
### Internal / Testing Changes
|
|
20
|
+
- build: create docs test npm scripts ([#88](https://github.com/googleapis/nodejs-promisify/pull/88))
|
|
21
|
+
- build: test using @grpc/grpc-js in CI ([#87](https://github.com/googleapis/nodejs-promisify/pull/87))
|
|
22
|
+
- build: ignore googleapis.com in doc link check ([#81](https://github.com/googleapis/nodejs-promisify/pull/81))
|
|
23
|
+
- build: check broken links in generated docs ([#79](https://github.com/googleapis/nodejs-promisify/pull/79))
|
|
24
|
+
- chore(deps): update dependency @types/sinon to v7 ([#78](https://github.com/googleapis/nodejs-promisify/pull/78))
|
|
25
|
+
- chore(build): inject yoshi automation key ([#77](https://github.com/googleapis/nodejs-promisify/pull/77))
|
|
26
|
+
- chore: update nyc and eslint configs ([#76](https://github.com/googleapis/nodejs-promisify/pull/76))
|
|
27
|
+
- chore: fix publish.sh permission +x ([#74](https://github.com/googleapis/nodejs-promisify/pull/74))
|
|
28
|
+
- fix(build): fix Kokoro release script ([#73](https://github.com/googleapis/nodejs-promisify/pull/73))
|
|
29
|
+
- build: add Kokoro configs for autorelease ([#72](https://github.com/googleapis/nodejs-promisify/pull/72))
|
|
30
|
+
- chore: always nyc report before calling codecov ([#69](https://github.com/googleapis/nodejs-promisify/pull/69))
|
|
31
|
+
- chore: nyc ignore build/test by default ([#68](https://github.com/googleapis/nodejs-promisify/pull/68))
|
|
32
|
+
- chore(build): update prettier config ([#66](https://github.com/googleapis/nodejs-promisify/pull/66))
|
|
33
|
+
- fix: get the build passing ([#65](https://github.com/googleapis/nodejs-promisify/pull/65))
|
|
34
|
+
- chore: update license file ([#64](https://github.com/googleapis/nodejs-promisify/pull/64))
|
|
35
|
+
- fix(build): fix system key decryption ([#60](https://github.com/googleapis/nodejs-promisify/pull/60))
|
|
36
|
+
- chore(deps): update dependency @types/sinon to v5.0.7 ([#58](https://github.com/googleapis/nodejs-promisify/pull/58))
|
|
37
|
+
- fix: Pin @types/sinon to last compatible version ([#57](https://github.com/googleapis/nodejs-promisify/pull/57))
|
|
38
|
+
- chore: add synth.metadata
|
|
39
|
+
- chore(deps): update dependency gts to ^0.9.0 ([#54](https://github.com/googleapis/nodejs-promisify/pull/54))
|
|
40
|
+
- chore: update eslintignore config ([#53](https://github.com/googleapis/nodejs-promisify/pull/53))
|
|
41
|
+
- chore: use latest npm on Windows ([#52](https://github.com/googleapis/nodejs-promisify/pull/52))
|
|
42
|
+
- chore: update CircleCI config ([#51](https://github.com/googleapis/nodejs-promisify/pull/51))
|
|
43
|
+
- chore: include build in eslintignore ([#48](https://github.com/googleapis/nodejs-promisify/pull/48))
|
|
44
|
+
- chore: update issue templates ([#44](https://github.com/googleapis/nodejs-promisify/pull/44))
|
|
45
|
+
- chore: remove old issue template ([#42](https://github.com/googleapis/nodejs-promisify/pull/42))
|
|
46
|
+
- build: run tests on node11 ([#41](https://github.com/googleapis/nodejs-promisify/pull/41))
|
|
47
|
+
- chores(build): do not collect sponge.xml from windows builds ([#40](https://github.com/googleapis/nodejs-promisify/pull/40))
|
|
48
|
+
- chores(build): run codecov on continuous builds ([#39](https://github.com/googleapis/nodejs-promisify/pull/39))
|
|
49
|
+
- chore: update new issue template ([#38](https://github.com/googleapis/nodejs-promisify/pull/38))
|
|
50
|
+
- chore(deps): update dependency sinon to v7 ([#33](https://github.com/googleapis/nodejs-promisify/pull/33))
|
|
51
|
+
- build: fix codecov uploading on Kokoro ([#34](https://github.com/googleapis/nodejs-promisify/pull/34))
|
|
52
|
+
- Update kokoro config ([#30](https://github.com/googleapis/nodejs-promisify/pull/30))
|
|
53
|
+
- Update CI config ([#28](https://github.com/googleapis/nodejs-promisify/pull/28))
|
|
54
|
+
- Don't publish sourcemaps ([#26](https://github.com/googleapis/nodejs-promisify/pull/26))
|
|
55
|
+
- Update kokoro config ([#24](https://github.com/googleapis/nodejs-promisify/pull/24))
|
|
56
|
+
- test: remove appveyor config ([#23](https://github.com/googleapis/nodejs-promisify/pull/23))
|
|
57
|
+
- Update CI config ([#22](https://github.com/googleapis/nodejs-promisify/pull/22))
|
|
58
|
+
- Enable prefer-const in the eslint config ([#21](https://github.com/googleapis/nodejs-promisify/pull/21))
|
|
59
|
+
- Enable no-var in eslint ([#19](https://github.com/googleapis/nodejs-promisify/pull/19))
|
|
60
|
+
- Update CI config ([#18](https://github.com/googleapis/nodejs-promisify/pull/18))
|
|
61
|
+
|
|
62
|
+
## v0.3.1
|
|
63
|
+
|
|
64
|
+
### Internal / Testing Changes
|
|
65
|
+
- Add synth script and update CI (#14)
|
|
66
|
+
- chore(deps): update dependency nyc to v13 (#12)
|
|
67
|
+
- chore: ignore package-lock.json (#11)
|
|
68
|
+
- chore(deps): lock file maintenance (#10)
|
|
69
|
+
- chore: update renovate config (#9)
|
|
70
|
+
- remove that whitespace (#8)
|
|
71
|
+
- chore(deps): lock file maintenance (#7)
|
|
72
|
+
- chore(deps): update dependency typescript to v3 (#6)
|
|
73
|
+
- chore: assert.deelEqual => assert.deepStrictEqual (#5)
|
|
74
|
+
- chore: move mocha options to mocha.opts (#4)
|
|
75
|
+
- chore(deps): update dependency gts to ^0.8.0 (#1)
|
|
76
|
+
- chore(deps): lock file maintenance (#3)
|
|
77
|
+
- chore(deps): lock file maintenance (#2)
|
|
78
|
+
|
package/LICENSE
CHANGED
|
@@ -199,4 +199,4 @@
|
|
|
199
199
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
200
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
201
|
See the License for the specific language governing permissions and
|
|
202
|
-
limitations under the License.
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,15 +1,40 @@
|
|
|
1
1
|
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
|
|
2
2
|
|
|
3
3
|
# @google-cloud/promisify
|
|
4
|
-
> A simple utility for promisifying functions and classes.
|
|
4
|
+
> A simple utility for promisifying and callbackifying functions and classes.
|
|
5
|
+
|
|
6
|
+
Google Cloud Common node.js module contains stuff used by other Cloud API modules.
|
|
7
|
+
|
|
8
|
+
* [github.com/googlecloudplatform/google-cloud-node](https://github.com/googlecloudplatform/google-cloud-node)
|
|
9
|
+
|
|
10
|
+
Read more about the client libraries for Cloud APIs, including the older
|
|
11
|
+
Google APIs Client Libraries, in [Client Libraries Explained][explained].
|
|
12
|
+
|
|
13
|
+
[explained]: https://cloud.google.com/apis/docs/client-libraries-explained
|
|
14
|
+
|
|
15
|
+
### Installing the package
|
|
16
|
+
|
|
17
|
+
It's unlikely you will need to install this package directly, as it will be
|
|
18
|
+
installed as a dependency when you install other `@google-cloud` packages.
|
|
19
|
+
|
|
20
|
+
## Versioning
|
|
21
|
+
|
|
22
|
+
This library follows [Semantic Versioning](http://semver.org/).
|
|
23
|
+
|
|
24
|
+
This library is considered to be in **alpha**. This means it is still a
|
|
25
|
+
work-in-progress and under active development. Any release is subject to
|
|
26
|
+
backwards-incompatible changes at any time.
|
|
27
|
+
|
|
28
|
+
More Information: [Google Cloud Platform Launch Stages][launch_stages]
|
|
29
|
+
|
|
30
|
+
[launch_stages]: https://cloud.google.com/terms/launch-stages
|
|
5
31
|
|
|
6
32
|
## Contributing
|
|
7
33
|
|
|
8
|
-
Contributions welcome! See the [Contributing Guide](https://github.com/
|
|
34
|
+
Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/nodejs-promisify/blob/master/CONTRIBUTING.md).
|
|
9
35
|
|
|
10
36
|
## License
|
|
11
37
|
|
|
12
38
|
Apache Version 2.0
|
|
13
39
|
|
|
14
40
|
See [LICENSE](https://github.com/googlecloudplatform/google-cloud-node/blob/master/LICENSE)
|
|
15
|
-
|
package/build/src/index.d.ts
CHANGED
|
@@ -31,24 +31,46 @@ export interface PromiseMethod extends Function {
|
|
|
31
31
|
export interface WithPromise {
|
|
32
32
|
Promise?: PromiseConstructor;
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
export interface CallbackifyAllOptions {
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @param {function} originalMethod - The method to promisify.
|
|
39
|
-
* @param {object=} options - Promise options.
|
|
40
|
-
* @param {boolean} options.singular - Resolve the promise with single arg instead of an array.
|
|
41
|
-
* @return {function} wrapped
|
|
36
|
+
* Array of methods to ignore when callbackifying.
|
|
42
37
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
* @param {module:common/service} Class - Service class.
|
|
49
|
-
* @param {object=} options - Configuration object.
|
|
50
|
-
*/
|
|
51
|
-
promisifyAll(Class: Function, options?: PromisifyAllOptions): void;
|
|
38
|
+
exclude?: string[];
|
|
39
|
+
}
|
|
40
|
+
export interface CallbackMethod extends Function {
|
|
41
|
+
callbackified_?: boolean;
|
|
52
42
|
}
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Wraps a callback style function to conditionally return a promise.
|
|
45
|
+
*
|
|
46
|
+
* @param {function} originalMethod - The method to promisify.
|
|
47
|
+
* @param {object=} options - Promise options.
|
|
48
|
+
* @param {boolean} options.singular - Resolve the promise with single arg instead of an array.
|
|
49
|
+
* @return {function} wrapped
|
|
50
|
+
*/
|
|
51
|
+
export declare function promisify(originalMethod: PromiseMethod, options?: PromisifyOptions): any;
|
|
52
|
+
/**
|
|
53
|
+
* Promisifies certain Class methods. This will not promisify private or
|
|
54
|
+
* streaming methods.
|
|
55
|
+
*
|
|
56
|
+
* @param {module:common/service} Class - Service class.
|
|
57
|
+
* @param {object=} options - Configuration object.
|
|
58
|
+
*/
|
|
59
|
+
export declare function promisifyAll(Class: Function, options?: PromisifyAllOptions): void;
|
|
60
|
+
/**
|
|
61
|
+
* Wraps a promisy type function to conditionally call a callback function.
|
|
62
|
+
*
|
|
63
|
+
* @param {function} originalMethod - The method to callbackify.
|
|
64
|
+
* @param {object=} options - Callback options.
|
|
65
|
+
* @param {boolean} options.singular - Pass to the callback a single arg instead of an array.
|
|
66
|
+
* @return {function} wrapped
|
|
67
|
+
*/
|
|
68
|
+
export declare function callbackify(originalMethod: CallbackMethod): CallbackMethod;
|
|
69
|
+
/**
|
|
70
|
+
* Callbackifies certain Class methods. This will not callbackify private or
|
|
71
|
+
* streaming methods.
|
|
72
|
+
*
|
|
73
|
+
* @param {module:common/service} Class - Service class.
|
|
74
|
+
* @param {object=} options - Configuration object.
|
|
75
|
+
*/
|
|
76
|
+
export declare function callbackifyAll(Class: Function, options?: CallbackifyAllOptions): void;
|
package/build/src/index.js
CHANGED
|
@@ -15,99 +15,148 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Wraps a callback style function to conditionally return a promise.
|
|
20
|
+
*
|
|
21
|
+
* @param {function} originalMethod - The method to promisify.
|
|
22
|
+
* @param {object=} options - Promise options.
|
|
23
|
+
* @param {boolean} options.singular - Resolve the promise with single arg instead of an array.
|
|
24
|
+
* @return {function} wrapped
|
|
25
|
+
*/
|
|
26
|
+
function promisify(originalMethod, options) {
|
|
27
|
+
if (originalMethod.promisified_) {
|
|
28
|
+
return originalMethod;
|
|
20
29
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
options = options || {};
|
|
31
|
+
const slice = Array.prototype.slice;
|
|
32
|
+
// tslint:disable-next-line:no-any
|
|
33
|
+
const wrapper = function () {
|
|
34
|
+
const context = this;
|
|
35
|
+
let last;
|
|
36
|
+
for (last = arguments.length - 1; last >= 0; last--) {
|
|
37
|
+
const arg = arguments[last];
|
|
38
|
+
if (typeof arg === 'undefined') {
|
|
39
|
+
continue; // skip trailing undefined.
|
|
40
|
+
}
|
|
41
|
+
if (typeof arg !== 'function') {
|
|
42
|
+
break; // non-callback last argument found.
|
|
43
|
+
}
|
|
44
|
+
return originalMethod.apply(context, arguments);
|
|
45
|
+
}
|
|
46
|
+
// peel trailing undefined.
|
|
47
|
+
const args = slice.call(arguments, 0, last + 1);
|
|
48
|
+
// tslint:disable-next-line:variable-name
|
|
49
|
+
let PromiseCtor = Promise;
|
|
50
|
+
// Because dedupe will likely create a single install of
|
|
51
|
+
// @google-cloud/common to be shared amongst all modules, we need to
|
|
52
|
+
// localize it at the Service level.
|
|
53
|
+
if (context && context.Promise) {
|
|
54
|
+
PromiseCtor = context.Promise;
|
|
32
55
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var arg = arguments[last];
|
|
41
|
-
if (typeof arg === 'undefined') {
|
|
42
|
-
continue; // skip trailing undefined.
|
|
56
|
+
return new PromiseCtor((resolve, reject) => {
|
|
57
|
+
// tslint:disable-next-line:no-any
|
|
58
|
+
args.push((...args) => {
|
|
59
|
+
const callbackArgs = slice.call(args);
|
|
60
|
+
const err = callbackArgs.shift();
|
|
61
|
+
if (err) {
|
|
62
|
+
return reject(err);
|
|
43
63
|
}
|
|
44
|
-
if (
|
|
45
|
-
|
|
64
|
+
if (options.singular && callbackArgs.length === 1) {
|
|
65
|
+
resolve(callbackArgs[0]);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
resolve(callbackArgs);
|
|
46
69
|
}
|
|
47
|
-
return originalMethod.apply(context, arguments);
|
|
48
|
-
}
|
|
49
|
-
// peel trailing undefined.
|
|
50
|
-
var args = slice.call(arguments, 0, last + 1);
|
|
51
|
-
// tslint:disable-next-line:variable-name
|
|
52
|
-
var PromiseCtor = Promise;
|
|
53
|
-
// Because dedupe will likely create a single install of
|
|
54
|
-
// @google-cloud/common to be shared amongst all modules, we need to
|
|
55
|
-
// localize it at the Service level.
|
|
56
|
-
if (context && context.Promise) {
|
|
57
|
-
PromiseCtor = context.Promise;
|
|
58
|
-
}
|
|
59
|
-
return new PromiseCtor(function (resolve, reject) {
|
|
60
|
-
// tslint:disable-next-line:no-any
|
|
61
|
-
args.push(function () {
|
|
62
|
-
var args = [];
|
|
63
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
64
|
-
args[_i] = arguments[_i];
|
|
65
|
-
}
|
|
66
|
-
var callbackArgs = slice.call(args);
|
|
67
|
-
var err = callbackArgs.shift();
|
|
68
|
-
if (err) {
|
|
69
|
-
return reject(err);
|
|
70
|
-
}
|
|
71
|
-
if (options.singular && callbackArgs.length === 1) {
|
|
72
|
-
resolve(callbackArgs[0]);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
resolve(callbackArgs);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
originalMethod.apply(context, args);
|
|
79
70
|
});
|
|
80
|
-
|
|
81
|
-
wrapper.promisified_ = true;
|
|
82
|
-
return wrapper;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Promisifies certain Class methods. This will not promisify private or
|
|
86
|
-
* streaming methods.
|
|
87
|
-
*
|
|
88
|
-
* @param {module:common/service} Class - Service class.
|
|
89
|
-
* @param {object=} options - Configuration object.
|
|
90
|
-
*/
|
|
91
|
-
// tslint:disable-next-line:variable-name
|
|
92
|
-
Util.prototype.promisifyAll = function (Class, options) {
|
|
93
|
-
var exclude = (options && options.exclude) || [];
|
|
94
|
-
var ownPropertyNames = Object.getOwnPropertyNames(Class.prototype);
|
|
95
|
-
var methods = ownPropertyNames.filter(function (methodName) {
|
|
96
|
-
// clang-format off
|
|
97
|
-
return (typeof Class.prototype[methodName] === 'function' && // is it a function?
|
|
98
|
-
!/(^_|(Stream|_)|promise$)|^constructor$/.test(methodName) && // is it promisable?
|
|
99
|
-
exclude.indexOf(methodName) === -1); // is it blacklisted?
|
|
100
|
-
// clang-format on
|
|
101
|
-
});
|
|
102
|
-
methods.forEach(function (methodName) {
|
|
103
|
-
var originalMethod = Class.prototype[methodName];
|
|
104
|
-
if (!originalMethod.promisified_) {
|
|
105
|
-
Class.prototype[methodName] = util.promisify(originalMethod, options);
|
|
106
|
-
}
|
|
71
|
+
originalMethod.apply(context, args);
|
|
107
72
|
});
|
|
108
73
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
exports.
|
|
74
|
+
wrapper.promisified_ = true;
|
|
75
|
+
return wrapper;
|
|
76
|
+
}
|
|
77
|
+
exports.promisify = promisify;
|
|
78
|
+
/**
|
|
79
|
+
* Promisifies certain Class methods. This will not promisify private or
|
|
80
|
+
* streaming methods.
|
|
81
|
+
*
|
|
82
|
+
* @param {module:common/service} Class - Service class.
|
|
83
|
+
* @param {object=} options - Configuration object.
|
|
84
|
+
*/
|
|
85
|
+
// tslint:disable-next-line:variable-name
|
|
86
|
+
function promisifyAll(Class, options) {
|
|
87
|
+
const exclude = (options && options.exclude) || [];
|
|
88
|
+
const ownPropertyNames = Object.getOwnPropertyNames(Class.prototype);
|
|
89
|
+
const methods = ownPropertyNames.filter((methodName) => {
|
|
90
|
+
// clang-format off
|
|
91
|
+
return (typeof Class.prototype[methodName] === 'function' && // is it a function?
|
|
92
|
+
!/(^_|(Stream|_)|promise$)|^constructor$/.test(methodName) && // is it promisable?
|
|
93
|
+
exclude.indexOf(methodName) === -1); // is it blacklisted?
|
|
94
|
+
// clang-format on
|
|
95
|
+
});
|
|
96
|
+
methods.forEach((methodName) => {
|
|
97
|
+
const originalMethod = Class.prototype[methodName];
|
|
98
|
+
if (!originalMethod.promisified_) {
|
|
99
|
+
Class.prototype[methodName] = exports.promisify(originalMethod, options);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
exports.promisifyAll = promisifyAll;
|
|
104
|
+
/**
|
|
105
|
+
* Wraps a promisy type function to conditionally call a callback function.
|
|
106
|
+
*
|
|
107
|
+
* @param {function} originalMethod - The method to callbackify.
|
|
108
|
+
* @param {object=} options - Callback options.
|
|
109
|
+
* @param {boolean} options.singular - Pass to the callback a single arg instead of an array.
|
|
110
|
+
* @return {function} wrapped
|
|
111
|
+
*/
|
|
112
|
+
function callbackify(originalMethod) {
|
|
113
|
+
if (originalMethod.callbackified_) {
|
|
114
|
+
return originalMethod;
|
|
115
|
+
}
|
|
116
|
+
// tslint:disable-next-line:no-any
|
|
117
|
+
const wrapper = function () {
|
|
118
|
+
const context = this;
|
|
119
|
+
if (typeof arguments[arguments.length - 1] !== 'function') {
|
|
120
|
+
return originalMethod.apply(context, arguments);
|
|
121
|
+
}
|
|
122
|
+
const cb = Array.prototype.pop.call(arguments);
|
|
123
|
+
originalMethod
|
|
124
|
+
.apply(context, arguments)
|
|
125
|
+
// tslint:disable-next-line:no-any
|
|
126
|
+
.then((res) => {
|
|
127
|
+
res = Array.isArray(res) ? res : [res];
|
|
128
|
+
cb(null, ...res);
|
|
129
|
+
}, (err) => cb(err));
|
|
130
|
+
};
|
|
131
|
+
wrapper.callbackified_ = true;
|
|
132
|
+
return wrapper;
|
|
133
|
+
}
|
|
134
|
+
exports.callbackify = callbackify;
|
|
135
|
+
/**
|
|
136
|
+
* Callbackifies certain Class methods. This will not callbackify private or
|
|
137
|
+
* streaming methods.
|
|
138
|
+
*
|
|
139
|
+
* @param {module:common/service} Class - Service class.
|
|
140
|
+
* @param {object=} options - Configuration object.
|
|
141
|
+
*/
|
|
142
|
+
function callbackifyAll(
|
|
143
|
+
// tslint:disable-next-line:variable-name
|
|
144
|
+
Class, options) {
|
|
145
|
+
const exclude = (options && options.exclude) || [];
|
|
146
|
+
const ownPropertyNames = Object.getOwnPropertyNames(Class.prototype);
|
|
147
|
+
const methods = ownPropertyNames.filter((methodName) => {
|
|
148
|
+
// clang-format off
|
|
149
|
+
return (typeof Class.prototype[methodName] === 'function' && // is it a function?
|
|
150
|
+
!/^_|(Stream|_)|^constructor$/.test(methodName) && // is it callbackifyable?
|
|
151
|
+
exclude.indexOf(methodName) === -1); // is it blacklisted?
|
|
152
|
+
// clang-format on
|
|
153
|
+
});
|
|
154
|
+
methods.forEach((methodName) => {
|
|
155
|
+
const originalMethod = Class.prototype[methodName];
|
|
156
|
+
if (!originalMethod.callbackified_) {
|
|
157
|
+
Class.prototype[methodName] = exports.callbackify(originalMethod);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
exports.callbackifyAll = callbackifyAll;
|
|
113
162
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,42 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@google-cloud/promisify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A simple utility for promisifying functions and classes.",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"types": "build/src/index.d.ts",
|
|
7
|
+
"repository": "googleapis/nodejs-promisify",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"test": "nyc mocha build/test",
|
|
9
|
-
"
|
|
10
|
+
"lint": "gts check",
|
|
10
11
|
"clean": "gts clean",
|
|
11
12
|
"compile": "tsc -p .",
|
|
12
13
|
"fix": "gts fix",
|
|
13
14
|
"prepare": "npm run compile",
|
|
14
15
|
"pretest": "npm run compile",
|
|
15
|
-
"posttest": "npm run
|
|
16
|
+
"posttest": "npm run lint",
|
|
17
|
+
"docs": "compodoc src/",
|
|
18
|
+
"presystem-test": "npm run compile",
|
|
19
|
+
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
|
|
20
|
+
"system-test": "mocha build/system-test",
|
|
21
|
+
"docs-test": "blcl docs -r --exclude www.googleapis.com",
|
|
22
|
+
"predocs-test": "npm run docs"
|
|
16
23
|
},
|
|
17
24
|
"keywords": [],
|
|
18
25
|
"files": [
|
|
19
|
-
"build/src"
|
|
26
|
+
"build/src",
|
|
27
|
+
"!build/src/**/*.map"
|
|
20
28
|
],
|
|
21
29
|
"author": "Google Inc.",
|
|
22
30
|
"license": "Apache-2.0",
|
|
23
31
|
"devDependencies": {
|
|
32
|
+
"@compodoc/compodoc": "^1.1.7",
|
|
24
33
|
"@types/mocha": "^5.2.4",
|
|
25
|
-
"@types/
|
|
26
|
-
"
|
|
34
|
+
"@types/node": "^10.5.2",
|
|
35
|
+
"@types/sinon": "^7.0.0",
|
|
36
|
+
"codecov": "^3.0.4",
|
|
37
|
+
"gts": "^0.9.0",
|
|
27
38
|
"hard-rejection": "^1.0.0",
|
|
39
|
+
"intelli-espower-loader": "^1.0.1",
|
|
28
40
|
"mocha": "^5.2.0",
|
|
29
|
-
"nyc": "^
|
|
30
|
-
"sinon": "^
|
|
41
|
+
"nyc": "^13.0.0",
|
|
42
|
+
"sinon": "^7.0.0",
|
|
31
43
|
"source-map-support": "^0.5.6",
|
|
32
|
-
"typescript": "^
|
|
33
|
-
|
|
34
|
-
"nyc": {
|
|
35
|
-
"exclude": [
|
|
36
|
-
"build/test"
|
|
37
|
-
]
|
|
38
|
-
},
|
|
39
|
-
"publishConfig": {
|
|
40
|
-
"access": "public"
|
|
44
|
+
"typescript": "^3.0.0",
|
|
45
|
+
"broken-link-checker-local": "^0.2.0"
|
|
41
46
|
}
|
|
42
47
|
}
|
package/build/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAwBH;IAAA;IAuGA,CAAC;IAtGC;;;;;;;OAOG;IACH,wBAAS,GAAT,UAAU,cAA6B,EAAE,OAA0B;QACjE,IAAI,cAAc,CAAC,YAAY,EAAE;YAC/B,OAAO,cAAc,CAAC;SACvB;QAED,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;QAExB,IAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC;QAEpC,kCAAkC;QAClC,IAAM,OAAO,GAAQ;YACnB,IAAM,OAAO,GAAG,IAAI,CAAC;YACrB,IAAI,IAAI,CAAC;YAET,KAAK,IAAI,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE;gBACnD,IAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;gBAE5B,IAAI,OAAO,GAAG,KAAK,WAAW,EAAE;oBAC9B,SAAS,CAAE,2BAA2B;iBACvC;gBAED,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;oBAC7B,MAAM,CAAE,oCAAoC;iBAC7C;gBAED,OAAO,cAAc,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;aACjD;YAED,2B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