@google-cloud/promisify 0.4.0 → 1.0.3
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 +33 -1
- package/README.md +96 -9
- package/build/src/index.js +7 -8
- package/package.json +12 -9
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,39 @@
|
|
|
4
4
|
|
|
5
5
|
[1]: https://www.npmjs.com/package/nodejs-promisify?activeTab=versions
|
|
6
6
|
|
|
7
|
+
### [1.0.3](https://www.github.com/googleapis/nodejs-promisify/compare/v1.0.2...v1.0.3) (2019-11-13)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* **docs:** add jsdoc-region-tag plugin ([#146](https://www.github.com/googleapis/nodejs-promisify/issues/146)) ([ff0ee74](https://www.github.com/googleapis/nodejs-promisify/commit/ff0ee7408f50e8f7147b8ccf7e10337aa5920076))
|
|
13
|
+
|
|
14
|
+
### [1.0.2](https://www.github.com/googleapis/nodejs-promisify/compare/v1.0.1...v1.0.2) (2019-06-26)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **docs:** link to reference docs section on googleapis.dev ([#128](https://www.github.com/googleapis/nodejs-promisify/issues/128)) ([5a8bd90](https://www.github.com/googleapis/nodejs-promisify/commit/5a8bd90))
|
|
20
|
+
|
|
21
|
+
### [1.0.1](https://www.github.com/googleapis/nodejs-promisify/compare/v1.0.0...v1.0.1) (2019-06-14)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* **docs:** move to new client docs URL ([#124](https://www.github.com/googleapis/nodejs-promisify/issues/124)) ([34d18cd](https://www.github.com/googleapis/nodejs-promisify/commit/34d18cd))
|
|
27
|
+
|
|
28
|
+
## [1.0.0](https://www.github.com/googleapis/nodejs-promisify/compare/v0.4.0...v1.0.0) (2019-05-02)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Build System
|
|
32
|
+
|
|
33
|
+
* upgrade engines field to >=8.10.0 ([#108](https://www.github.com/googleapis/nodejs-promisify/issues/108)) ([78ab89c](https://www.github.com/googleapis/nodejs-promisify/commit/78ab89c))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### BREAKING CHANGES
|
|
37
|
+
|
|
38
|
+
* upgrade engines field to >=8.10.0 (#108)
|
|
39
|
+
|
|
7
40
|
## v0.4.0
|
|
8
41
|
|
|
9
42
|
02-12-2019 19:44 PST
|
|
@@ -75,4 +108,3 @@
|
|
|
75
108
|
- chore(deps): update dependency gts to ^0.8.0 (#1)
|
|
76
109
|
- chore(deps): lock file maintenance (#3)
|
|
77
110
|
- chore(deps): lock file maintenance (#2)
|
|
78
|
-
|
package/README.md
CHANGED
|
@@ -1,29 +1,108 @@
|
|
|
1
|
+
[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
|
|
2
|
+
[//]: # "To regenerate it, use `python -m synthtool`."
|
|
1
3
|
<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
4
|
|
|
3
|
-
#
|
|
4
|
-
> A simple utility for promisifying and callbackifying functions and classes.
|
|
5
|
+
# [Google Cloud Common Promisify: Node.js Client](https://github.com/googleapis/nodejs-promisify)
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
[](https://cloud.google.com/terms/launch-stages)
|
|
8
|
+
[](https://www.npmjs.org/package/@google-cloud/promisify)
|
|
9
|
+
[](https://codecov.io/gh/googleapis/nodejs-promisify)
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
A simple utility for promisifying functions and classes.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
* [Google Cloud Common Promisify Node.js Client API Reference][client-docs]
|
|
18
|
+
|
|
19
|
+
* [github.com/googleapis/nodejs-promisify](https://github.com/googleapis/nodejs-promisify)
|
|
9
20
|
|
|
10
21
|
Read more about the client libraries for Cloud APIs, including the older
|
|
11
22
|
Google APIs Client Libraries, in [Client Libraries Explained][explained].
|
|
12
23
|
|
|
13
24
|
[explained]: https://cloud.google.com/apis/docs/client-libraries-explained
|
|
14
25
|
|
|
15
|
-
|
|
26
|
+
**Table of contents:**
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
* [Quickstart](#quickstart)
|
|
30
|
+
|
|
31
|
+
* [Installing the client library](#installing-the-client-library)
|
|
32
|
+
* [Using the client library](#using-the-client-library)
|
|
33
|
+
* [Samples](#samples)
|
|
34
|
+
* [Versioning](#versioning)
|
|
35
|
+
* [Contributing](#contributing)
|
|
36
|
+
* [License](#license)
|
|
37
|
+
|
|
38
|
+
## Quickstart
|
|
39
|
+
|
|
40
|
+
### Installing the client library
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @google-cloud/promisify
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### Using the client library
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
const {promisify} = require('@google-cloud/promisify');
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* This is a very basic example function that accepts a callback.
|
|
54
|
+
*/
|
|
55
|
+
function someCallbackFunction(name, callback) {
|
|
56
|
+
if (!name) {
|
|
57
|
+
callback(new Error('Name is required!'));
|
|
58
|
+
} else {
|
|
59
|
+
callback(null, `Well hello there, ${name}!`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// let's promisify it!
|
|
64
|
+
const somePromiseFunction = promisify(someCallbackFunction);
|
|
16
65
|
|
|
66
|
+
async function quickstart() {
|
|
67
|
+
// now we can just `await` the function to use it like a promisified method
|
|
68
|
+
const [result] = await somePromiseFunction('nodestronaut');
|
|
69
|
+
console.log(result);
|
|
70
|
+
}
|
|
71
|
+
quickstart();
|
|
72
|
+
|
|
73
|
+
```
|
|
17
74
|
It's unlikely you will need to install this package directly, as it will be
|
|
18
75
|
installed as a dependency when you install other `@google-cloud` packages.
|
|
19
76
|
|
|
77
|
+
|
|
78
|
+
## Samples
|
|
79
|
+
|
|
80
|
+
Samples are in the [`samples/`](https://github.com/googleapis/nodejs-promisify/tree/master/samples) directory. The samples' `README.md`
|
|
81
|
+
has instructions for running the samples.
|
|
82
|
+
|
|
83
|
+
| Sample | Source Code | Try it |
|
|
84
|
+
| --------------------------- | --------------------------------- | ------ |
|
|
85
|
+
| Quickstart | [source code](https://github.com/googleapis/nodejs-promisify/blob/master/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-promisify&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
The [Google Cloud Common Promisify Node.js Client API Reference][client-docs] documentation
|
|
90
|
+
also contains samples.
|
|
91
|
+
|
|
20
92
|
## Versioning
|
|
21
93
|
|
|
22
94
|
This library follows [Semantic Versioning](http://semver.org/).
|
|
23
95
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
backwards-incompatible
|
|
96
|
+
|
|
97
|
+
This library is considered to be **General Availability (GA)**. This means it
|
|
98
|
+
is stable; the code surface will not change in backwards-incompatible ways
|
|
99
|
+
unless absolutely necessary (e.g. because of critical security issues) or with
|
|
100
|
+
an extensive deprecation period. Issues and requests against **GA** libraries
|
|
101
|
+
are addressed with the highest priority.
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
27
106
|
|
|
28
107
|
More Information: [Google Cloud Platform Launch Stages][launch_stages]
|
|
29
108
|
|
|
@@ -37,4 +116,12 @@ Contributions welcome! See the [Contributing Guide](https://github.com/googleapi
|
|
|
37
116
|
|
|
38
117
|
Apache Version 2.0
|
|
39
118
|
|
|
40
|
-
See [LICENSE](https://github.com/
|
|
119
|
+
See [LICENSE](https://github.com/googleapis/nodejs-promisify/blob/master/LICENSE)
|
|
120
|
+
|
|
121
|
+
[client-docs]: https://googleapis.dev/nodejs/promisify/latest
|
|
122
|
+
|
|
123
|
+
[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
|
|
124
|
+
[projects]: https://console.cloud.google.com/project
|
|
125
|
+
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
|
|
126
|
+
|
|
127
|
+
[auth]: https://cloud.google.com/docs/authentication/getting-started
|
package/build/src/index.js
CHANGED
|
@@ -86,14 +86,14 @@ exports.promisify = promisify;
|
|
|
86
86
|
function promisifyAll(Class, options) {
|
|
87
87
|
const exclude = (options && options.exclude) || [];
|
|
88
88
|
const ownPropertyNames = Object.getOwnPropertyNames(Class.prototype);
|
|
89
|
-
const methods = ownPropertyNames.filter(
|
|
89
|
+
const methods = ownPropertyNames.filter(methodName => {
|
|
90
90
|
// clang-format off
|
|
91
91
|
return (typeof Class.prototype[methodName] === 'function' && // is it a function?
|
|
92
92
|
!/(^_|(Stream|_)|promise$)|^constructor$/.test(methodName) && // is it promisable?
|
|
93
93
|
exclude.indexOf(methodName) === -1); // is it blacklisted?
|
|
94
94
|
// clang-format on
|
|
95
95
|
});
|
|
96
|
-
methods.forEach(
|
|
96
|
+
methods.forEach(methodName => {
|
|
97
97
|
const originalMethod = Class.prototype[methodName];
|
|
98
98
|
if (!originalMethod.promisified_) {
|
|
99
99
|
Class.prototype[methodName] = exports.promisify(originalMethod, options);
|
|
@@ -120,10 +120,9 @@ function callbackify(originalMethod) {
|
|
|
120
120
|
return originalMethod.apply(context, arguments);
|
|
121
121
|
}
|
|
122
122
|
const cb = Array.prototype.pop.call(arguments);
|
|
123
|
-
originalMethod
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
.then((res) => {
|
|
123
|
+
originalMethod.apply(context, arguments).then(
|
|
124
|
+
// tslint:disable-next-line:no-any
|
|
125
|
+
(res) => {
|
|
127
126
|
res = Array.isArray(res) ? res : [res];
|
|
128
127
|
cb(null, ...res);
|
|
129
128
|
}, (err) => cb(err));
|
|
@@ -144,14 +143,14 @@ function callbackifyAll(
|
|
|
144
143
|
Class, options) {
|
|
145
144
|
const exclude = (options && options.exclude) || [];
|
|
146
145
|
const ownPropertyNames = Object.getOwnPropertyNames(Class.prototype);
|
|
147
|
-
const methods = ownPropertyNames.filter(
|
|
146
|
+
const methods = ownPropertyNames.filter(methodName => {
|
|
148
147
|
// clang-format off
|
|
149
148
|
return (typeof Class.prototype[methodName] === 'function' && // is it a function?
|
|
150
149
|
!/^_|(Stream|_)|^constructor$/.test(methodName) && // is it callbackifyable?
|
|
151
150
|
exclude.indexOf(methodName) === -1); // is it blacklisted?
|
|
152
151
|
// clang-format on
|
|
153
152
|
});
|
|
154
|
-
methods.forEach(
|
|
153
|
+
methods.forEach(methodName => {
|
|
155
154
|
const originalMethod = Class.prototype[methodName];
|
|
156
155
|
if (!originalMethod.callbackified_) {
|
|
157
156
|
Class.prototype[methodName] = exports.callbackify(originalMethod);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@google-cloud/promisify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.3",
|
|
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",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"presystem-test": "npm run compile",
|
|
19
19
|
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
|
|
20
20
|
"system-test": "mocha build/system-test",
|
|
21
|
-
"docs-test": "
|
|
21
|
+
"docs-test": "linkinator docs",
|
|
22
22
|
"predocs-test": "npm run docs"
|
|
23
23
|
},
|
|
24
24
|
"keywords": [],
|
|
@@ -29,19 +29,22 @@
|
|
|
29
29
|
"author": "Google Inc.",
|
|
30
30
|
"license": "Apache-2.0",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@compodoc/compodoc": "^1.1.
|
|
32
|
+
"@compodoc/compodoc": "^1.1.9",
|
|
33
33
|
"@types/mocha": "^5.2.4",
|
|
34
34
|
"@types/node": "^10.5.2",
|
|
35
35
|
"@types/sinon": "^7.0.0",
|
|
36
36
|
"codecov": "^3.0.4",
|
|
37
|
-
"gts": "^0.
|
|
38
|
-
"hard-rejection": "^
|
|
37
|
+
"gts": "^1.0.0",
|
|
38
|
+
"hard-rejection": "^2.0.0",
|
|
39
39
|
"intelli-espower-loader": "^1.0.1",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
40
|
+
"linkinator": "^1.5.0",
|
|
41
|
+
"mocha": "^6.0.0",
|
|
42
|
+
"nyc": "^14.0.0",
|
|
42
43
|
"sinon": "^7.0.0",
|
|
43
44
|
"source-map-support": "^0.5.6",
|
|
44
|
-
"typescript": "
|
|
45
|
-
|
|
45
|
+
"typescript": "~3.7.0"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=8.10.0"
|
|
46
49
|
}
|
|
47
50
|
}
|