@google-cloud/promisify 0.3.1 → 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 +55 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/build/src/index.d.ts +26 -0
- package/build/src/index.js +58 -0
- package/package.json +14 -16
- package/build/src/index.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,61 @@
|
|
|
4
4
|
|
|
5
5
|
[1]: https://www.npmjs.com/package/nodejs-promisify?activeTab=versions
|
|
6
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
|
+
|
|
7
62
|
## v0.3.1
|
|
8
63
|
|
|
9
64
|
### Internal / Testing Changes
|
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,7 +1,7 @@
|
|
|
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
5
|
|
|
6
6
|
Google Cloud Common node.js module contains stuff used by other Cloud API modules.
|
|
7
7
|
|
|
@@ -31,7 +31,7 @@ More Information: [Google Cloud Platform Launch Stages][launch_stages]
|
|
|
31
31
|
|
|
32
32
|
## Contributing
|
|
33
33
|
|
|
34
|
-
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).
|
|
35
35
|
|
|
36
36
|
## License
|
|
37
37
|
|
package/build/src/index.d.ts
CHANGED
|
@@ -31,6 +31,15 @@ export interface PromiseMethod extends Function {
|
|
|
31
31
|
export interface WithPromise {
|
|
32
32
|
Promise?: PromiseConstructor;
|
|
33
33
|
}
|
|
34
|
+
export interface CallbackifyAllOptions {
|
|
35
|
+
/**
|
|
36
|
+
* Array of methods to ignore when callbackifying.
|
|
37
|
+
*/
|
|
38
|
+
exclude?: string[];
|
|
39
|
+
}
|
|
40
|
+
export interface CallbackMethod extends Function {
|
|
41
|
+
callbackified_?: boolean;
|
|
42
|
+
}
|
|
34
43
|
/**
|
|
35
44
|
* Wraps a callback style function to conditionally return a promise.
|
|
36
45
|
*
|
|
@@ -48,3 +57,20 @@ export declare function promisify(originalMethod: PromiseMethod, options?: Promi
|
|
|
48
57
|
* @param {object=} options - Configuration object.
|
|
49
58
|
*/
|
|
50
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
|
@@ -101,4 +101,62 @@ function promisifyAll(Class, options) {
|
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
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;
|
|
104
162
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
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
7
|
"repository": "googleapis/nodejs-promisify",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"test": "
|
|
10
|
-
"test-only": "nyc mocha build/test",
|
|
11
|
-
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json",
|
|
9
|
+
"test": "nyc mocha build/test",
|
|
12
10
|
"lint": "gts check",
|
|
13
11
|
"clean": "gts clean",
|
|
14
12
|
"compile": "tsc -p .",
|
|
@@ -16,34 +14,34 @@
|
|
|
16
14
|
"prepare": "npm run compile",
|
|
17
15
|
"pretest": "npm run compile",
|
|
18
16
|
"posttest": "npm run lint",
|
|
19
|
-
"docs": "
|
|
17
|
+
"docs": "compodoc src/",
|
|
20
18
|
"presystem-test": "npm run compile",
|
|
21
19
|
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
|
|
22
|
-
"system-test": "mocha build/system-test"
|
|
20
|
+
"system-test": "mocha build/system-test",
|
|
21
|
+
"docs-test": "blcl docs -r --exclude www.googleapis.com",
|
|
22
|
+
"predocs-test": "npm run docs"
|
|
23
23
|
},
|
|
24
24
|
"keywords": [],
|
|
25
25
|
"files": [
|
|
26
|
-
"build/src"
|
|
26
|
+
"build/src",
|
|
27
|
+
"!build/src/**/*.map"
|
|
27
28
|
],
|
|
28
29
|
"author": "Google Inc.",
|
|
29
30
|
"license": "Apache-2.0",
|
|
30
31
|
"devDependencies": {
|
|
32
|
+
"@compodoc/compodoc": "^1.1.7",
|
|
31
33
|
"@types/mocha": "^5.2.4",
|
|
32
34
|
"@types/node": "^10.5.2",
|
|
33
|
-
"@types/sinon": "^
|
|
35
|
+
"@types/sinon": "^7.0.0",
|
|
34
36
|
"codecov": "^3.0.4",
|
|
35
|
-
"gts": "^0.
|
|
37
|
+
"gts": "^0.9.0",
|
|
36
38
|
"hard-rejection": "^1.0.0",
|
|
37
39
|
"intelli-espower-loader": "^1.0.1",
|
|
38
40
|
"mocha": "^5.2.0",
|
|
39
41
|
"nyc": "^13.0.0",
|
|
40
|
-
"sinon": "^
|
|
42
|
+
"sinon": "^7.0.0",
|
|
41
43
|
"source-map-support": "^0.5.6",
|
|
42
|
-
"typescript": "^3.0.0"
|
|
43
|
-
|
|
44
|
-
"nyc": {
|
|
45
|
-
"exclude": [
|
|
46
|
-
"build/test"
|
|
47
|
-
]
|
|
44
|
+
"typescript": "^3.0.0",
|
|
45
|
+
"broken-link-checker-local": "^0.2.0"
|
|
48
46
|
}
|
|
49
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;;;;;;;GAOG;AACH,SAAgB,SAAS,CACrB,cAA6B,EAAE,OAA0B;IAC3D,IAAI,cAAc,CAAC,YAAY,EAAE;QAC/B,OAAO,cAAc,CAAC;KACvB;IAED,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;IAExB,MAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC;IAEpC,kCAAkC;IAClC,MAAM,OAAO,GAAQ;QACnB,MAAM,OAAO,GAAG,IAAI,CAAC;QACrB,IAAI,IAAI,CAAC;QAET,KAAK,IAAI,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE;YACnD,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;YAE5B,IAAI,OAAO,GAAG,KAAK,WAAW,EAAE;gBAC9B,SAAS,CAAE,2BAA2B;aACvC;YAED,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;gBAC7B,MAAM,CAAE,oCAAoC;aAC7C;YAED,OAAO,cAAc,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;SACjD;QAED,2BAA2B;QAC3B,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,EA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