google-gax
Advanced tools
Comparing version 2.28.0-alpha.0 to 2.28.0-alpha.1
@@ -33,2 +33,3 @@ "use strict"; | ||
const fallbackServiceStub_1 = require("./fallbackServiceStub"); | ||
const _1 = require("."); | ||
var pathTemplate_1 = require("./pathTemplate"); | ||
@@ -275,5 +276,7 @@ Object.defineProperty(exports, "PathTemplate", { enumerable: true, get: function () { return pathTemplate_1.PathTemplate; } }); | ||
function createApiCall(func, settings, descriptor) { | ||
if (descriptor && 'streaming' in descriptor) { | ||
if (descriptor && | ||
'streaming' in descriptor && | ||
descriptor.type !== _1.StreamType.SERVER_STREAMING) { | ||
return () => { | ||
throw new Error('The gRPC-fallback client library (e.g. browser version of the library) currently does not support streaming calls.'); | ||
throw new Error('The gRPC-fallback client library (e.g. browser version of the library) currently does not support client-streaming or bidi-stream calls.'); | ||
}; | ||
@@ -280,0 +283,0 @@ } |
@@ -18,4 +18,5 @@ /** | ||
import { AuthClient } from './fallback'; | ||
import { StreamArrayParser } from './streamArrayParser'; | ||
export interface FallbackServiceStub { | ||
[method: string]: (request: {}, options: {}, metadata: {}, callback: (err?: Error, response?: {} | undefined) => void) => { | ||
[method: string]: (request: {}, options: {}, metadata: {}, callback: (err?: Error, response?: {} | undefined) => void) => StreamArrayParser | { | ||
cancel: () => void; | ||
@@ -22,0 +23,0 @@ }; |
@@ -24,2 +24,4 @@ "use strict"; | ||
const featureDetection_1 = require("./featureDetection"); | ||
const streamArrayParser_1 = require("./streamArrayParser"); | ||
const stream_1 = require("stream"); | ||
function generateServiceStub(rpcs, protocol, servicePath, servicePort, authClient, requestEncoder, responseDecoder) { | ||
@@ -45,2 +47,3 @@ const fetch = featureDetection_1.hasWindowFetch() | ||
} | ||
const streamArrayParser = new streamArrayParser_1.StreamArrayParser(rpc); | ||
authClient | ||
@@ -65,16 +68,31 @@ .getRequestHeaders() | ||
.then((response) => { | ||
return Promise.all([ | ||
Promise.resolve(response.ok), | ||
response.arrayBuffer(), | ||
]); | ||
}) | ||
.then(([ok, buffer]) => { | ||
const response = responseDecoder(rpc, ok, buffer); | ||
callback(null, response); | ||
}) | ||
.catch((err) => { | ||
if (!cancelRequested || err.name !== 'AbortError') { | ||
callback(err); | ||
if (response.ok && rpc.responseStream) { | ||
stream_1.pipeline(response.body, streamArrayParser, (err) => { | ||
if (err && | ||
(!cancelRequested || | ||
(err instanceof Error && err.name !== 'AbortError'))) { | ||
callback(err); | ||
} | ||
}); | ||
return; | ||
} | ||
else { | ||
return Promise.all([ | ||
Promise.resolve(response.ok), | ||
response.arrayBuffer(), | ||
]) | ||
.then(([ok, buffer]) => { | ||
const response = responseDecoder(rpc, ok, buffer); | ||
callback(null, response); | ||
}) | ||
.catch((err) => { | ||
if (!cancelRequested || err.name !== 'AbortError') { | ||
callback(err); | ||
} | ||
}); | ||
} | ||
}); | ||
if (rpc.responseStream) { | ||
return streamArrayParser; | ||
} | ||
return { | ||
@@ -81,0 +99,0 @@ cancel: () => { |
@@ -50,2 +50,6 @@ "use strict"; | ||
const error = Object.assign(new GoogleError(json['error']['message']), json.error); | ||
// Map Http Status Code to gRPC Status Code | ||
if (json['error']['code']) { | ||
error.code = status_1.rpcCodeFromHttpStatusCode(json['error']['code']); | ||
} | ||
// Keep consistency with gRPC statusDetails fields. gRPC details has been occupied before. | ||
@@ -52,0 +56,0 @@ // Rename "detials" to "statusDetails". |
@@ -35,1 +35,3 @@ /** | ||
} | ||
export declare const HttpCodeToRpcCodeMap: Map<number, Status>; | ||
export declare function rpcCodeFromHttpStatusCode(httpStatusCode: number): number; |
@@ -18,3 +18,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Status = void 0; | ||
exports.rpcCodeFromHttpStatusCode = exports.HttpCodeToRpcCodeMap = exports.Status = void 0; | ||
// The following is a copy of the Status enum defined in @grpc/grpc-js, | ||
@@ -44,2 +44,36 @@ // src/constants.ts. We need to use some of these statuses here and there, | ||
})(Status = exports.Status || (exports.Status = {})); | ||
exports.HttpCodeToRpcCodeMap = new Map([ | ||
[400, Status.INVALID_ARGUMENT], | ||
[401, Status.UNAUTHENTICATED], | ||
[403, Status.PERMISSION_DENIED], | ||
[404, Status.NOT_FOUND], | ||
[409, Status.ABORTED], | ||
[416, Status.OUT_OF_RANGE], | ||
[429, Status.RESOURCE_EXHAUSTED], | ||
[499, Status.CANCELLED], | ||
[501, Status.UNIMPLEMENTED], | ||
[503, Status.UNAVAILABLE], | ||
[504, Status.DEADLINE_EXCEEDED], | ||
]); | ||
// Maps HTTP status codes to gRPC status codes above. | ||
function rpcCodeFromHttpStatusCode(httpStatusCode) { | ||
if (exports.HttpCodeToRpcCodeMap.has(httpStatusCode)) { | ||
return exports.HttpCodeToRpcCodeMap.get(httpStatusCode); | ||
} | ||
// All 2xx | ||
if (httpStatusCode >= 200 && httpStatusCode < 300) { | ||
return Status.OK; | ||
} | ||
// All other 4xx | ||
if (httpStatusCode >= 400 && httpStatusCode < 500) { | ||
return Status.FAILED_PRECONDITION; | ||
} | ||
// All other 5xx | ||
if (httpStatusCode >= 500 && httpStatusCode < 600) { | ||
return Status.INTERNAL; | ||
} | ||
// Everything else | ||
return Status.UNKNOWN; | ||
} | ||
exports.rpcCodeFromHttpStatusCode = rpcCodeFromHttpStatusCode; | ||
//# sourceMappingURL=status.js.map |
@@ -19,2 +19,3 @@ "use strict"; | ||
exports.StreamProxy = exports.StreamType = void 0; | ||
const streamArrayParser_1 = require("../streamArrayParser"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
@@ -71,2 +72,5 @@ const duplexify = require('duplexify'); | ||
const eventsToForward = ['metadata', 'response', 'status']; | ||
if (stream instanceof streamArrayParser_1.StreamArrayParser) { | ||
eventsToForward.push('data', 'end', 'error'); | ||
} | ||
eventsToForward.forEach(event => { | ||
@@ -73,0 +77,0 @@ stream.on(event, this.emit.bind(this, event)); |
{ | ||
"name": "google-gax", | ||
"version": "2.28.0-alpha.0", | ||
"version": "2.28.0-alpha.1", | ||
"description": "Google API Extensions", | ||
@@ -32,3 +32,3 @@ "main": "build/src/index.js", | ||
"devDependencies": { | ||
"@compodoc/compodoc": "1.1.15", | ||
"@compodoc/compodoc": "1.1.16", | ||
"@types/download": "^8.0.0", | ||
@@ -70,3 +70,3 @@ "@types/fs-extra": "^8.0.1", | ||
"pumpify": "^2.0.0", | ||
"puppeteer": "^11.0.0", | ||
"puppeteer": "^12.0.0", | ||
"rimraf": "^3.0.0", | ||
@@ -94,2 +94,3 @@ "sinon": "^12.0.0", | ||
"compile-http-protos": "pbjs -t static-module -r http_proto --keep-case google/api/http.proto -p ./protos > protos/http.js && pbts protos/http.js -o protos/http.d.ts", | ||
"compile-showcase-proto": "pbjs -t json google/showcase/v1beta1/echo.proto google/showcase/v1beta1/identity.proto google/showcase/v1beta1/messaging.proto google/showcase/v1beta1/testing.proto -p ./protos > test/fixtures/google-gax-packaging-test-app/protos/protos.json && pbjs -t static-module -r showcase_protos google/showcase/v1beta1/echo.proto google/showcase/v1beta1/identity.proto google/showcase/v1beta1/messaging.proto google/showcase/v1beta1/testing.proto -p ./protos > test/fixtures/google-gax-packaging-test-app/protos/protos.js && pbts test/fixtures/google-gax-packaging-test-app/protos/protos.js -o test/fixtures/google-gax-packaging-test-app/protos/protos.d.ts", | ||
"fix": "gts fix", | ||
@@ -96,0 +97,0 @@ "prepare": "npm run compile && node ./build/tools/prepublish.js && mkdirp build/protos && cp -r protos/* build/protos/", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10864429
408
163685