@aptre/protobuf-es-lite 0.2.13 → 0.2.15

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.
@@ -895,7 +895,7 @@ function declarationString() {
895
895
  if (defaultValue !== undefined) {
896
896
  if (this.proto.type == FieldDescriptorProto_Type.BYTES ||
897
897
  this.proto.type == FieldDescriptorProto_Type.STRING) {
898
- defaultValue = '"' + defaultValue.replace('"', '\\"') + '"';
898
+ defaultValue = '"' + defaultValue.replace(/"/g, '\\"') + '"';
899
899
  }
900
900
  options.push(`default = ${defaultValue}`);
901
901
  }
package/dist/message.d.ts CHANGED
@@ -45,7 +45,7 @@ export interface MessageType<T extends Message<T> = AnyMessage> {
45
45
  /**
46
46
  * Create a deep copy.
47
47
  */
48
- clone(a: Message<T> | undefined | null): Message<T> | undefined | null;
48
+ clone(a: T | undefined | null): T | undefined | null;
49
49
  /**
50
50
  * Parse from binary data, merging fields.
51
51
  *
@@ -55,20 +55,20 @@ export interface MessageType<T extends Message<T> = AnyMessage> {
55
55
  * If a message field is already present, it will be merged with the
56
56
  * new data.
57
57
  */
58
- fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Message<T>;
58
+ fromBinary(bytes: Uint8Array | null | undefined, options?: Partial<BinaryReadOptions>): T;
59
59
  /**
60
60
  * Parse a message from a JSON value.
61
61
  */
62
- fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): Message<T>;
62
+ fromJson(jsonValue: JsonValue | null | undefined, options?: Partial<JsonReadOptions>): T;
63
63
  /**
64
64
  * Parse a message from a JSON string.
65
65
  */
66
- fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): Message<T>;
66
+ fromJsonString(jsonString: string | null | undefined, options?: Partial<JsonReadOptions>): T;
67
67
  /**
68
68
  * Returns true if the given arguments have equal field values, recursively.
69
69
  * Will also return true if both messages are `undefined` or `null`.
70
70
  */
71
- equals(a: Message<T> | undefined | null, b: Message<T> | undefined | null): boolean;
71
+ equals(a: T | undefined | null, b: T | undefined | null): boolean;
72
72
  /**
73
73
  * Serialize the message to binary data.
74
74
  */
package/dist/message.js CHANGED
@@ -173,23 +173,29 @@ export function createMessageType(params) {
173
173
  },
174
174
  fromBinary(bytes, options) {
175
175
  const message = {};
176
- const opt = makeBinaryReadOptions(options);
177
- readBinaryMessage(message, fields, opt.readerFactory(bytes), bytes.byteLength, opt, delimitedMessageEncoding);
176
+ if (bytes && bytes.length) {
177
+ const opt = makeBinaryReadOptions(options);
178
+ readBinaryMessage(message, fields, opt.readerFactory(bytes), bytes.byteLength, opt, delimitedMessageEncoding);
179
+ }
178
180
  return message;
179
181
  },
180
182
  fromJson(jsonValue, options) {
181
183
  const message = {};
182
- const opts = makeJsonReadOptions(options);
183
- readJsonMessage(fields, typeName, jsonValue, opts, message);
184
+ if (jsonValue != null) {
185
+ const opts = makeJsonReadOptions(options);
186
+ readJsonMessage(fields, typeName, jsonValue, opts, message);
187
+ }
184
188
  return message;
185
189
  },
186
190
  fromJsonString(jsonString, options) {
187
- let json;
188
- try {
189
- json = JSON.parse(jsonString);
190
- }
191
- catch (e) {
192
- throw new Error(`cannot decode ${typeName} from JSON: ${e instanceof Error ? e.message : String(e)}`);
191
+ let json = null;
192
+ if (jsonString) {
193
+ try {
194
+ json = JSON.parse(jsonString);
195
+ }
196
+ catch (e) {
197
+ throw new Error(`cannot decode ${typeName} from JSON: ${e instanceof Error ? e.message : String(e)}`);
198
+ }
193
199
  }
194
200
  return this.fromJson(json, options);
195
201
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aptre/protobuf-es-lite",
3
3
  "description": "Lightweight Protobuf codegen for TypeScript and JavaScript.",
4
- "version": "0.2.13",
4
+ "version": "0.2.15",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "url": "git+ssh://git@github.com/aperturerobotics/protobuf-es-lite.git"