@aptre/protobuf-es-lite 0.2.14 → 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.
- package/dist/create-descriptor-set.js +1 -1
- package/dist/message.d.ts +3 -3
- package/dist/message.js +16 -10
- package/package.json +1 -1
|
@@ -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
|
@@ -55,15 +55,15 @@ 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>): 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>): 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>): 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`.
|
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
|
-
|
|
177
|
-
|
|
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
|
-
|
|
183
|
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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.
|
|
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"
|