@bufbuild/connect-web
Advanced tools
Comparing version 0.0.10 to 0.1.0
@@ -19,3 +19,2 @@ "use strict"; | ||
const protobuf_1 = require("@bufbuild/protobuf"); | ||
const protobuf_2 = require("@bufbuild/protobuf"); | ||
/** | ||
@@ -43,3 +42,3 @@ * ConnectError captures three pieces of information: a Code, an error | ||
this.metadata = new Headers(metadata); | ||
this.rawDetails = []; | ||
this.details = []; | ||
} | ||
@@ -50,8 +49,8 @@ } | ||
const typeRegistry = "typeName" in typeOrRegistry | ||
? protobuf_2.TypeRegistry.from(typeOrRegistry, ...moreTypes) | ||
? protobuf_1.TypeRegistry.from(typeOrRegistry, ...moreTypes) | ||
: typeOrRegistry; | ||
const details = []; | ||
for (const raw of error.rawDetails) { | ||
for (const data of error.details) { | ||
try { | ||
const any = "@type" in raw ? protobuf_2.Any.fromJson(raw, { typeRegistry }) : raw; | ||
const any = new protobuf_1.Any(data); | ||
const name = any.typeUrl.substring(any.typeUrl.lastIndexOf("/") + 1); | ||
@@ -61,4 +60,5 @@ const type = typeRegistry.findMessage(name); | ||
const message = new type(); | ||
any.unpackTo(message); | ||
details.push(message); | ||
if (any.unpackTo(message)) { | ||
details.push(message); | ||
} | ||
} | ||
@@ -103,3 +103,16 @@ } | ||
if ("details" in jsonValue && Array.isArray(jsonValue.details)) { | ||
error.rawDetails.push(...jsonValue.details); | ||
for (const detail of jsonValue.details) { | ||
if (detail === null || typeof detail != "object" || Array.isArray(detail) || typeof detail.type != "string" || typeof detail.value != "string") { | ||
throw newParseError(detail, `.details`); | ||
} | ||
try { | ||
error.details.push({ | ||
typeUrl: "type.googleapis.com/" + detail.type, | ||
value: protobuf_1.protoBase64.dec(detail.value), | ||
}); | ||
} | ||
catch (e) { | ||
throw newParseError(e, `.details`, false); | ||
} | ||
} | ||
} | ||
@@ -106,0 +119,0 @@ return error; |
@@ -23,2 +23,3 @@ "use strict"; | ||
const http_headers_js_1 = require("./http-headers.js"); | ||
const assert_fetch_api_js_1 = require("./assert-fetch-api.js"); | ||
/** | ||
@@ -31,2 +32,3 @@ * Create a Transport for the Connect protocol, which makes unary and | ||
var _a; | ||
(0, assert_fetch_api_js_1.assertFetchApi)(); | ||
const useBinaryFormat = (_a = options.useBinaryFormat) !== null && _a !== void 0 ? _a : false; | ||
@@ -41,3 +43,3 @@ return { | ||
method, | ||
url: `${options.baseUrl}/${service.typeName}/${method.name}`, | ||
url: `${options.baseUrl.replace(/\/$/, "")}/${service.typeName}/${method.name}`, | ||
init: { | ||
@@ -87,3 +89,3 @@ method: "POST", | ||
method, | ||
url: `${options.baseUrl}/${service.typeName}/${method.name}`, | ||
url: `${options.baseUrl.replace(/\/$/, "")}/${service.typeName}/${method.name}`, | ||
init: { | ||
@@ -263,19 +265,4 @@ method: "POST", | ||
} | ||
let error; | ||
if ("error" in jsonValue) { | ||
if (typeof jsonValue.error != "object" || | ||
jsonValue.error == null || | ||
Array.isArray(jsonValue.error)) { | ||
throw (0, connect_error_js_1.newParseError)(jsonValue, ".error"); | ||
} | ||
if (Object.keys(jsonValue.error).length > 0) { | ||
try { | ||
error = (0, connect_error_js_1.connectErrorFromJson)(jsonValue.error, metadata); | ||
} | ||
catch (e) { | ||
throw (0, connect_error_js_1.newParseError)(e, ".error", false); | ||
} | ||
} | ||
} | ||
const error = "error" in jsonValue ? (0, connect_error_js_1.connectErrorFromJson)(jsonValue.error, metadata) : undefined; | ||
return { metadata, error }; | ||
} |
@@ -23,2 +23,3 @@ "use strict"; | ||
const envelope_js_1 = require("./envelope.js"); | ||
const assert_fetch_api_js_1 = require("./assert-fetch-api.js"); | ||
/** | ||
@@ -35,2 +36,3 @@ * Create a Transport for the gRPC-web protocol. The protocol encodes | ||
function createGrpcWebTransport(options) { | ||
(0, assert_fetch_api_js_1.assertFetchApi)(); | ||
const transportOptions = options; | ||
@@ -45,3 +47,3 @@ return { | ||
method, | ||
url: `${options.baseUrl}/${service.typeName}/${method.name}`, | ||
url: `${options.baseUrl.replace(/\/$/, "")}/${service.typeName}/${method.name}`, | ||
init: { | ||
@@ -112,3 +114,3 @@ method: "POST", | ||
method, | ||
url: `${options.baseUrl}/${service.typeName}/${method.name}`, | ||
url: `${options.baseUrl.replace(/\/$/, "")}/${service.typeName}/${method.name}`, | ||
init: { | ||
@@ -255,3 +257,3 @@ method: "POST", | ||
const error = new connect_error_js_1.ConnectError(status.message, status.code, undefined, header); | ||
error.rawDetails.push(...status.details); | ||
error.details.push(...status.details); | ||
return error; | ||
@@ -258,0 +260,0 @@ } |
@@ -15,4 +15,3 @@ // Copyright 2021-2022 Buf Technologies, Inc. | ||
import { Code, codeFromString, codeToString } from "./code.js"; | ||
import { proto3, } from "@bufbuild/protobuf"; | ||
import { Any, TypeRegistry } from "@bufbuild/protobuf"; | ||
import { Any, proto3, protoBase64, TypeRegistry } from "@bufbuild/protobuf"; | ||
/** | ||
@@ -40,3 +39,3 @@ * ConnectError captures three pieces of information: a Code, an error | ||
this.metadata = new Headers(metadata); | ||
this.rawDetails = []; | ||
this.details = []; | ||
} | ||
@@ -49,5 +48,5 @@ } | ||
const details = []; | ||
for (const raw of error.rawDetails) { | ||
for (const data of error.details) { | ||
try { | ||
const any = "@type" in raw ? Any.fromJson(raw, { typeRegistry }) : raw; | ||
const any = new Any(data); | ||
const name = any.typeUrl.substring(any.typeUrl.lastIndexOf("/") + 1); | ||
@@ -57,4 +56,5 @@ const type = typeRegistry.findMessage(name); | ||
const message = new type(); | ||
any.unpackTo(message); | ||
details.push(message); | ||
if (any.unpackTo(message)) { | ||
details.push(message); | ||
} | ||
} | ||
@@ -98,3 +98,16 @@ } | ||
if ("details" in jsonValue && Array.isArray(jsonValue.details)) { | ||
error.rawDetails.push(...jsonValue.details); | ||
for (const detail of jsonValue.details) { | ||
if (detail === null || typeof detail != "object" || Array.isArray(detail) || typeof detail.type != "string" || typeof detail.value != "string") { | ||
throw newParseError(detail, `.details`); | ||
} | ||
try { | ||
error.details.push({ | ||
typeUrl: "type.googleapis.com/" + detail.type, | ||
value: protoBase64.dec(detail.value), | ||
}); | ||
} | ||
catch (e) { | ||
throw newParseError(e, `.details`, false); | ||
} | ||
} | ||
} | ||
@@ -101,0 +114,0 @@ return error; |
@@ -20,2 +20,3 @@ // Copyright 2021-2022 Buf Technologies, Inc. | ||
import { mergeHeaders } from "./http-headers.js"; | ||
import { assertFetchApi } from "./assert-fetch-api.js"; | ||
/** | ||
@@ -28,2 +29,3 @@ * Create a Transport for the Connect protocol, which makes unary and | ||
var _a; | ||
assertFetchApi(); | ||
const useBinaryFormat = (_a = options.useBinaryFormat) !== null && _a !== void 0 ? _a : false; | ||
@@ -38,3 +40,3 @@ return { | ||
method, | ||
url: `${options.baseUrl}/${service.typeName}/${method.name}`, | ||
url: `${options.baseUrl.replace(/\/$/, "")}/${service.typeName}/${method.name}`, | ||
init: { | ||
@@ -84,3 +86,3 @@ method: "POST", | ||
method, | ||
url: `${options.baseUrl}/${service.typeName}/${method.name}`, | ||
url: `${options.baseUrl.replace(/\/$/, "")}/${service.typeName}/${method.name}`, | ||
init: { | ||
@@ -259,19 +261,4 @@ method: "POST", | ||
} | ||
let error; | ||
if ("error" in jsonValue) { | ||
if (typeof jsonValue.error != "object" || | ||
jsonValue.error == null || | ||
Array.isArray(jsonValue.error)) { | ||
throw newParseError(jsonValue, ".error"); | ||
} | ||
if (Object.keys(jsonValue.error).length > 0) { | ||
try { | ||
error = connectErrorFromJson(jsonValue.error, metadata); | ||
} | ||
catch (e) { | ||
throw newParseError(e, ".error", false); | ||
} | ||
} | ||
} | ||
const error = "error" in jsonValue ? connectErrorFromJson(jsonValue.error, metadata) : undefined; | ||
return { metadata, error }; | ||
} |
@@ -20,2 +20,3 @@ // Copyright 2021-2022 Buf Technologies, Inc. | ||
import { createEnvelopeReadableStream, encodeEnvelopes } from "./envelope.js"; | ||
import { assertFetchApi } from "./assert-fetch-api.js"; | ||
/** | ||
@@ -32,2 +33,3 @@ * Create a Transport for the gRPC-web protocol. The protocol encodes | ||
export function createGrpcWebTransport(options) { | ||
assertFetchApi(); | ||
const transportOptions = options; | ||
@@ -42,3 +44,3 @@ return { | ||
method, | ||
url: `${options.baseUrl}/${service.typeName}/${method.name}`, | ||
url: `${options.baseUrl.replace(/\/$/, "")}/${service.typeName}/${method.name}`, | ||
init: { | ||
@@ -109,3 +111,3 @@ method: "POST", | ||
method, | ||
url: `${options.baseUrl}/${service.typeName}/${method.name}`, | ||
url: `${options.baseUrl.replace(/\/$/, "")}/${service.typeName}/${method.name}`, | ||
init: { | ||
@@ -251,3 +253,3 @@ method: "POST", | ||
const error = new ConnectError(status.message, status.code, undefined, header); | ||
error.rawDetails.push(...status.details); | ||
error.details.push(...status.details); | ||
return error; | ||
@@ -254,0 +256,0 @@ } |
import { Code } from "./code.js"; | ||
import { AnyMessage, IMessageTypeRegistry, JsonValue, Message, MessageType } from "@bufbuild/protobuf"; | ||
import { Any } from "@bufbuild/protobuf"; | ||
import { Any, AnyMessage, IMessageTypeRegistry, JsonValue, Message, MessageType } from "@bufbuild/protobuf"; | ||
/** | ||
@@ -30,3 +29,3 @@ * ConnectError captures three pieces of information: a Code, an error | ||
*/ | ||
readonly rawDetails: RawErrorDetail[]; | ||
readonly details: Pick<Any, "typeUrl" | "value">[]; | ||
/** | ||
@@ -54,11 +53,2 @@ * The error message, but without a status code in front. | ||
/** | ||
* A raw error detail is a google.protobuf.Any, or it's JSON representation. | ||
* This type is used for error details that we could not unwrap because | ||
* we are missing type information. | ||
*/ | ||
export declare type RawErrorDetail = Any | { | ||
"@type": string; | ||
[key: string]: JsonValue; | ||
}; | ||
/** | ||
* Parse a Connect error from a JSON value. | ||
@@ -65,0 +55,0 @@ * Will return a ConnectError, but throw one in case the JSON is malformed. |
{ | ||
"name": "@bufbuild/connect-web", | ||
"version": "0.0.10", | ||
"version": "0.1.0", | ||
"license": "Apache-2.0", | ||
@@ -26,3 +26,3 @@ "repository": { | ||
"peerDependencies": { | ||
"@bufbuild/protobuf": "^0.0.9" | ||
"@bufbuild/protobuf": "0.0.10" | ||
}, | ||
@@ -29,0 +29,0 @@ "devDependencies": { |
@@ -41,2 +41,4 @@ # @bufbuild/connect-web | ||
Learn more at [github.com/bufbuild/connect-web](https://github.com/bufbuild/connect-web). | ||
To get started, head over to the [docs](https://connect.build/docs/web/getting-started) | ||
for a tutorial, or take a look at [our examples](https://github.com/bufbuild/connect-web-integration) | ||
for integration with various frameworks. |
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
152985
48
3508
44