@aptre/protobuf-es-lite 0.3.0 → 0.3.1

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.
@@ -5,8 +5,8 @@ import { ScalarType } from "./scalar.js";
5
5
  * ergonomic for use as a message field.
6
6
  */
7
7
  export interface FieldWrapper<T = any, U = any> {
8
- wrapField(value: U): T;
9
- unwrapField(value: T): U;
8
+ wrapField(value: U | null | undefined): T;
9
+ unwrapField(value: T): U | null | undefined;
10
10
  }
11
11
  /**
12
12
  * Wrap a primitive message field value in its corresponding wrapper
@@ -27,7 +27,7 @@
27
27
  // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
28
  // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
29
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
- import { applyPartialMessage, createMessageType, ScalarType } from "../../index.js";
30
+ import { applyPartialMessage, createMessageType, ScalarType, } from "../../index.js";
31
31
  export const protobufPackage = "google.protobuf";
32
32
  // Any_Wkt contains the well-known-type overrides for Any.
33
33
  const Any_Wkt = {
@@ -42,7 +42,10 @@ const Any_Wkt = {
42
42
  }
43
43
  const message = messageType.fromBinary(msg.value);
44
44
  let json = messageType.toJson(message, options);
45
- if (typeName.startsWith("google.protobuf.") || (json === null || Array.isArray(json) || typeof json !== "object")) {
45
+ if (typeName.startsWith("google.protobuf.") ||
46
+ json === null ||
47
+ Array.isArray(json) ||
48
+ typeof json !== "object") {
46
49
  json = { value: json };
47
50
  }
48
51
  json["@type"] = typeName;
@@ -50,7 +53,9 @@ const Any_Wkt = {
50
53
  },
51
54
  fromJson(json, options) {
52
55
  if (json === null || Array.isArray(json) || typeof json != "object") {
53
- throw new Error(`cannot decode message google.protobuf.Any from JSON: expected object but got ${json === null ? "null" : Array.isArray(json) ? "array" : typeof json}`);
56
+ throw new Error(`cannot decode message google.protobuf.Any from JSON: expected object but got ${json === null ? "null"
57
+ : Array.isArray(json) ? "array"
58
+ : typeof json}`);
54
59
  }
55
60
  if (Object.keys(json).length == 0) {
56
61
  return {};
@@ -64,7 +69,8 @@ const Any_Wkt = {
64
69
  throw new Error(`cannot decode message google.protobuf.Any from JSON: ${typeUrl} is not in the type registry`);
65
70
  }
66
71
  let message;
67
- if (typeName.startsWith("google.protobuf.") && Object.prototype.hasOwnProperty.call(json, "value")) {
72
+ if (typeName.startsWith("google.protobuf.") &&
73
+ Object.prototype.hasOwnProperty.call(json, "value")) {
68
74
  message = messageType.fromJson(json["value"], options);
69
75
  }
70
76
  else {
@@ -91,11 +97,16 @@ const Any_Wkt = {
91
97
  unpack(msg, registry) {
92
98
  const typeUrl = msg.typeUrl;
93
99
  const messageType = !!typeUrl && registry.findMessage(typeUrl);
94
- return messageType ? { message: messageType.fromBinary(msg.value), messageType } : undefined;
100
+ return messageType ?
101
+ { message: messageType.fromBinary(msg.value), messageType }
102
+ : undefined;
95
103
  },
96
104
  is(msg, msgType) {
97
105
  const name = msg.typeUrl;
98
- return !!name && (typeof msgType === 'string' ? name === msgType : name === msgType.typeName);
106
+ return (!!name &&
107
+ (typeof msgType === "string" ?
108
+ name === msgType
109
+ : name === msgType.typeName));
99
110
  },
100
111
  };
101
112
  // Any contains the message type declaration for Any.
@@ -40,7 +40,13 @@ export const Method = createMessageType({
40
40
  { no: 3, name: "request_streaming", kind: "scalar", T: ScalarType.BOOL },
41
41
  { no: 4, name: "response_type_url", kind: "scalar", T: ScalarType.STRING },
42
42
  { no: 5, name: "response_streaming", kind: "scalar", T: ScalarType.BOOL },
43
- { no: 6, name: "options", kind: "message", T: () => Option, repeated: true },
43
+ {
44
+ no: 6,
45
+ name: "options",
46
+ kind: "message",
47
+ T: () => Option,
48
+ repeated: true,
49
+ },
44
50
  { no: 7, name: "syntax", kind: "enum", T: Syntax_Enum },
45
51
  ],
46
52
  packedByDefault: true,
@@ -59,8 +65,20 @@ export const Api = createMessageType({
59
65
  typeName: "google.protobuf.Api",
60
66
  fields: [
61
67
  { no: 1, name: "name", kind: "scalar", T: ScalarType.STRING },
62
- { no: 2, name: "methods", kind: "message", T: () => Method, repeated: true },
63
- { no: 3, name: "options", kind: "message", T: () => Option, repeated: true },
68
+ {
69
+ no: 2,
70
+ name: "methods",
71
+ kind: "message",
72
+ T: () => Method,
73
+ repeated: true,
74
+ },
75
+ {
76
+ no: 3,
77
+ name: "options",
78
+ kind: "message",
79
+ T: () => Option,
80
+ repeated: true,
81
+ },
64
82
  { no: 4, name: "version", kind: "scalar", T: ScalarType.STRING },
65
83
  { no: 5, name: "source_context", kind: "message", T: () => SourceContext },
66
84
  { no: 6, name: "mixins", kind: "message", T: () => Mixin, repeated: true },