@aptre/protobuf-es-lite 0.2.10 → 0.2.12

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.
Files changed (79) hide show
  1. package/bin/protoc-gen-es-lite +2 -2
  2. package/dist/assert.js +4 -11
  3. package/dist/binary-encoding.js +69 -42
  4. package/dist/binary.js +87 -105
  5. package/dist/codegen-info.d.ts +0 -1
  6. package/dist/codegen-info.js +12 -16
  7. package/dist/create-descriptor-set.js +114 -118
  8. package/dist/descriptor-set.js +1 -2
  9. package/dist/enum.js +2 -7
  10. package/dist/feature-set.d.ts +1 -1
  11. package/dist/feature-set.js +18 -22
  12. package/dist/field-wrapper.js +12 -17
  13. package/dist/field.js +35 -34
  14. package/dist/google/index.js +9 -41
  15. package/dist/google/protobuf/any.pb.d.ts +2 -2
  16. package/dist/google/protobuf/any.pb.js +3 -6
  17. package/dist/google/protobuf/api.pb.d.ts +2 -2
  18. package/dist/google/protobuf/api.pb.js +56 -21
  19. package/dist/google/protobuf/compiler/plugin.pb.d.ts +2 -2
  20. package/dist/google/protobuf/compiler/plugin.pb.js +15 -18
  21. package/dist/google/protobuf/descriptor.pb.d.ts +19 -19
  22. package/dist/google/protobuf/descriptor.pb.js +831 -223
  23. package/dist/google/protobuf/duration.pb.d.ts +2 -2
  24. package/dist/google/protobuf/duration.pb.js +3 -6
  25. package/dist/google/protobuf/empty.pb.d.ts +2 -2
  26. package/dist/google/protobuf/empty.pb.js +3 -6
  27. package/dist/google/protobuf/source_context.pb.d.ts +2 -2
  28. package/dist/google/protobuf/source_context.pb.js +3 -6
  29. package/dist/google/protobuf/struct.pb.d.ts +3 -3
  30. package/dist/google/protobuf/struct.pb.js +31 -18
  31. package/dist/google/protobuf/timestamp.pb.d.ts +2 -2
  32. package/dist/google/protobuf/timestamp.pb.js +3 -6
  33. package/dist/google/protobuf/type.pb.d.ts +5 -5
  34. package/dist/google/protobuf/type.pb.js +74 -36
  35. package/dist/google/protobuf/wrappers.pb.d.ts +2 -2
  36. package/dist/google/protobuf/wrappers.pb.js +11 -14
  37. package/dist/index.js +12 -60
  38. package/dist/is-message.js +9 -16
  39. package/dist/json.d.ts +0 -9
  40. package/dist/json.js +72 -102
  41. package/dist/message.d.ts +3 -3
  42. package/dist/message.js +50 -57
  43. package/dist/names.js +12 -23
  44. package/dist/partial.js +15 -24
  45. package/dist/proto-base64.js +1 -4
  46. package/dist/proto-double.js +1 -4
  47. package/dist/proto-int64.js +9 -12
  48. package/dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.js +4 -7
  49. package/dist/protoc-gen-es-lite/typescript.js +27 -36
  50. package/dist/protoplugin/create-es-plugin.js +14 -18
  51. package/dist/protoplugin/ecmascript/file-preamble.js +5 -9
  52. package/dist/protoplugin/ecmascript/generated-file.js +16 -20
  53. package/dist/protoplugin/ecmascript/import-path.js +13 -20
  54. package/dist/protoplugin/ecmascript/import-symbol.js +1 -5
  55. package/dist/protoplugin/ecmascript/index.js +2 -7
  56. package/dist/protoplugin/ecmascript/jsdoc.js +1 -5
  57. package/dist/protoplugin/ecmascript/opaque-printables.js +1 -2
  58. package/dist/protoplugin/ecmascript/parameter.js +10 -14
  59. package/dist/protoplugin/ecmascript/reify-wkt.js +12 -16
  60. package/dist/protoplugin/ecmascript/runtime-imports.js +5 -9
  61. package/dist/protoplugin/ecmascript/schema.js +16 -20
  62. package/dist/protoplugin/ecmascript/target.js +1 -2
  63. package/dist/protoplugin/ecmascript/transpile.js +15 -42
  64. package/dist/protoplugin/error.js +4 -10
  65. package/dist/protoplugin/index.js +2 -7
  66. package/dist/protoplugin/plugin.js +1 -2
  67. package/dist/protoplugin/run-node.js +6 -10
  68. package/dist/scalar.js +9 -15
  69. package/dist/service-type.js +4 -7
  70. package/dist/text-format.js +25 -30
  71. package/dist/unknown.js +7 -12
  72. package/dist/util.d.ts +1 -1
  73. package/dist/util.js +49 -55
  74. package/dist/varint.js +7 -17
  75. package/example/example.pb.ts +24 -18
  76. package/package.json +10 -7
  77. package/tsconfig.base.json +3 -3
  78. package/dist/type-registry.d.ts +0 -43
  79. package/dist/type-registry.js +0 -15
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isCompleteField = exports.isCompleteMessage = exports.isField = exports.isMessage = void 0;
4
- const field_js_1 = require("./field.js");
1
+ import { resolveMessageType } from "./field.js";
5
2
  /**
6
3
  * Check whether the given partial is a valid message.
7
4
  */
8
- function isMessage(arg, fields) {
5
+ export function isMessage(arg, fields) {
9
6
  if (arg == null || typeof arg !== "object") {
10
7
  return false;
11
8
  }
@@ -24,11 +21,10 @@ function isMessage(arg, fields) {
24
21
  }
25
22
  });
26
23
  }
27
- exports.isMessage = isMessage;
28
24
  /**
29
25
  * Check whether the given partial field is a valid field value.
30
26
  */
31
- function isField(value, field) {
27
+ export function isField(value, field) {
32
28
  if (value == null) {
33
29
  return false;
34
30
  }
@@ -46,7 +42,7 @@ function isField(value, field) {
46
42
  case "scalar":
47
43
  return true;
48
44
  case "message":
49
- const messageType = (0, field_js_1.resolveMessageType)(field.T);
45
+ const messageType = resolveMessageType(field.T);
50
46
  return isMessage(value, messageType.fields.list());
51
47
  case "enum":
52
48
  return typeof value === "number";
@@ -59,7 +55,7 @@ function isField(value, field) {
59
55
  case "enum":
60
56
  return typeof val === "number";
61
57
  case "message":
62
- const messageType = (0, field_js_1.resolveMessageType)(field.V.T);
58
+ const messageType = resolveMessageType(field.V.T);
63
59
  return isMessage(val, messageType.fields.list());
64
60
  default:
65
61
  return valueKind;
@@ -69,11 +65,10 @@ function isField(value, field) {
69
65
  return fieldKind;
70
66
  }
71
67
  }
72
- exports.isField = isField;
73
68
  /**
74
69
  * Check whether the given partial has all fields present recursively.
75
70
  */
76
- function isCompleteMessage(arg, fields) {
71
+ export function isCompleteMessage(arg, fields) {
77
72
  // arg is CompleteMessage<T> {
78
73
  if (arg == null || typeof arg !== "object") {
79
74
  return false;
@@ -89,11 +84,10 @@ function isCompleteMessage(arg, fields) {
89
84
  }
90
85
  });
91
86
  }
92
- exports.isCompleteMessage = isCompleteMessage;
93
87
  /**
94
88
  * Check whether the given partial field has a full value present recursively.
95
89
  */
96
- function isCompleteField(value, field) {
90
+ export function isCompleteField(value, field) {
97
91
  // value is CompleteField<F> {
98
92
  if (field.oneof) {
99
93
  // For oneof fields, only one field should be set
@@ -109,7 +103,7 @@ function isCompleteField(value, field) {
109
103
  case "scalar":
110
104
  return true;
111
105
  case "message":
112
- const messageType = (0, field_js_1.resolveMessageType)(field.T);
106
+ const messageType = resolveMessageType(field.T);
113
107
  return isCompleteMessage(value, messageType.fields.list());
114
108
  case "enum":
115
109
  return typeof value === "number";
@@ -122,7 +116,7 @@ function isCompleteField(value, field) {
122
116
  case "enum":
123
117
  return typeof val === "number";
124
118
  case "message":
125
- const messageType = (0, field_js_1.resolveMessageType)(field.V.T);
119
+ const messageType = resolveMessageType(field.V.T);
126
120
  return isCompleteMessage(val, messageType.fields.list());
127
121
  default:
128
122
  return valueKind;
@@ -132,4 +126,3 @@ function isCompleteField(value, field) {
132
126
  return fieldKind;
133
127
  }
134
128
  }
135
- exports.isCompleteField = isCompleteField;
package/dist/json.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { FieldInfo, FieldList } from "./field.js";
2
- import { IMessageTypeRegistry } from "./type-registry.js";
3
2
  /**
4
3
  * Options for parsing JSON data.
5
4
  */
@@ -10,10 +9,6 @@ export interface JsonReadOptions {
10
9
  * unrecognized enum string representations.
11
10
  */
12
11
  ignoreUnknownFields: boolean;
13
- /**
14
- * This option is required to read `google.protobuf.Any`
15
- */
16
- typeRegistry?: IMessageTypeRegistry;
17
12
  }
18
13
  /**
19
14
  * Options for serializing to JSON.
@@ -40,10 +35,6 @@ export interface JsonWriteOptions {
40
35
  * field name.
41
36
  */
42
37
  useProtoFieldName: boolean;
43
- /**
44
- * This option is required to write `google.protobuf.Any`
45
- */
46
- typeRegistry?: IMessageTypeRegistry;
47
38
  }
48
39
  /**
49
40
  * Options for serializing to JSON.
package/dist/json.js CHANGED
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clearField = exports.writeMessage = exports.readMessage = exports.makeWriteOptions = exports.makeReadOptions = void 0;
4
- const field_js_1 = require("./field.js");
5
- const assert_js_1 = require("./assert.js");
6
- const scalar_js_1 = require("./scalar.js");
7
- const field_wrapper_js_1 = require("./field-wrapper.js");
8
- const proto_int64_js_1 = require("./proto-int64.js");
9
- const proto_base64_js_1 = require("./proto-base64.js");
1
+ import { isFieldSet, resolveMessageType, } from "./field.js";
2
+ import { assert, assertFloat32, assertInt32, assertUInt32 } from "./assert.js";
3
+ import { LongType, ScalarType, scalarZeroValue, } from "./scalar.js";
4
+ import { wrapField } from "./field-wrapper.js";
5
+ import { protoInt64 } from "./proto-int64.js";
6
+ import { protoBase64 } from "./proto-base64.js";
10
7
  // Default options for parsing JSON.
11
8
  const jsonReadDefaults = {
12
9
  ignoreUnknownFields: false,
@@ -18,14 +15,12 @@ const jsonWriteDefaults = {
18
15
  useProtoFieldName: false,
19
16
  prettySpaces: 0,
20
17
  };
21
- function makeReadOptions(options) {
18
+ export function makeReadOptions(options) {
22
19
  return options ? { ...jsonReadDefaults, ...options } : jsonReadDefaults;
23
20
  }
24
- exports.makeReadOptions = makeReadOptions;
25
- function makeWriteOptions(options) {
21
+ export function makeWriteOptions(options) {
26
22
  return options ? { ...jsonWriteDefaults, ...options } : jsonWriteDefaults;
27
23
  }
28
- exports.makeWriteOptions = makeWriteOptions;
29
24
  function debugJsonValue(json) {
30
25
  if (json === null) {
31
26
  return "null";
@@ -39,7 +34,7 @@ function debugJsonValue(json) {
39
34
  return String(json);
40
35
  }
41
36
  }
42
- function readMessage(fields, typeName, json, options, message) {
37
+ export function readMessage(fields, typeName, json, options, message) {
43
38
  if (json == null || Array.isArray(json) || typeof json != "object") {
44
39
  throw new Error(`cannot decode message ${typeName} from JSON: ${debugJsonValue(json)}`);
45
40
  }
@@ -69,13 +64,12 @@ function readMessage(fields, typeName, json, options, message) {
69
64
  }
70
65
  return message;
71
66
  }
72
- exports.readMessage = readMessage;
73
- function writeMessage(message, fields, options) {
67
+ export function writeMessage(message, fields, options) {
74
68
  const json = {};
75
69
  let field;
76
70
  try {
77
71
  for (field of fields.byNumber()) {
78
- if (!(0, field_js_1.isFieldSet)(field, message)) {
72
+ if (!isFieldSet(field, message)) {
79
73
  // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
80
74
  if (field.req) {
81
75
  throw `required field not set`;
@@ -96,28 +90,6 @@ function writeMessage(message, fields, options) {
96
90
  jsonValue;
97
91
  }
98
92
  }
99
- // TODO: handle extensions
100
- /*
101
- const registry = options.typeRegistry;
102
- if (registry?.findExtensionFor) {
103
- for (const uf of listUnknownFields(message)) {
104
- const ext = registry.findExtensionFor(typeName, uf.no);
105
- if (ext && hasExtension(message, ext)) {
106
- // We pass on the options as BinaryReadOptions, so that users can bring their own
107
- // binary reader factory if necessary.
108
- const value = getExtension(
109
- message,
110
- ext,
111
- options as Partial<BinaryReadOptions>,
112
- );
113
- const jsonValue = writeField(ext.field, value, options);
114
- if (jsonValue !== undefined) {
115
- json[ext.field.jsonName] = jsonValue;
116
- }
117
- }
118
- }
119
- }
120
- */
121
93
  }
122
94
  catch (e) {
123
95
  const m = field ?
@@ -128,13 +100,12 @@ function writeMessage(message, fields, options) {
128
100
  }
129
101
  return json;
130
102
  }
131
- exports.writeMessage = writeMessage;
132
103
  // Read a JSON value for a field.
133
104
  // The "parentType" argument is only used to provide context in errors.
134
105
  function readField(target, jsonValue, field, options) {
135
106
  let localName = field.localName;
136
107
  if (field.repeated) {
137
- (0, assert_js_1.assert)(field.kind != "map");
108
+ assert(field.kind != "map");
138
109
  if (jsonValue === null) {
139
110
  return;
140
111
  }
@@ -151,7 +122,7 @@ function readField(target, jsonValue, field, options) {
151
122
  }
152
123
  switch (field.kind) {
153
124
  case "message":
154
- const messageType = (0, field_js_1.resolveMessageType)(field.T);
125
+ const messageType = resolveMessageType(field.T);
155
126
  targetArray.push(messageType.fromJson(jsonItem, options));
156
127
  break;
157
128
  case "enum":
@@ -203,7 +174,7 @@ function readField(target, jsonValue, field, options) {
203
174
  }
204
175
  switch (field.V.kind) {
205
176
  case "message":
206
- const messageType = (0, field_js_1.resolveMessageType)(field.V.T);
177
+ const messageType = resolveMessageType(field.V.T);
207
178
  targetMap[key] = messageType.fromJson(jsonMapValue, options);
208
179
  break;
209
180
  case "enum":
@@ -214,7 +185,7 @@ function readField(target, jsonValue, field, options) {
214
185
  break;
215
186
  case "scalar":
216
187
  try {
217
- targetMap[key] = readScalar(field.V.T, jsonMapValue, scalar_js_1.LongType.BIGINT, true);
188
+ targetMap[key] = readScalar(field.V.T, jsonMapValue, LongType.BIGINT, true);
218
189
  }
219
190
  catch (e) {
220
191
  let m = `cannot decode map value for field ${field.name} from JSON: ${debugJsonValue(jsonValue)}`;
@@ -234,7 +205,7 @@ function readField(target, jsonValue, field, options) {
234
205
  }
235
206
  switch (field.kind) {
236
207
  case "message":
237
- const messageType = (0, field_js_1.resolveMessageType)(field.T);
208
+ const messageType = resolveMessageType(field.T);
238
209
  if (jsonValue === null &&
239
210
  messageType.typeName != "google.protobuf.Value") {
240
211
  return;
@@ -312,7 +283,7 @@ function readEnum(type, json, ignoreUnknownFields, nullAsZeroValue) {
312
283
  function readScalar(type, json, longType, nullAsZeroValue) {
313
284
  if (json === null) {
314
285
  if (nullAsZeroValue) {
315
- return (0, scalar_js_1.scalarZeroValue)(type, longType);
286
+ return scalarZeroValue(type, longType);
316
287
  }
317
288
  return tokenNull;
318
289
  }
@@ -321,8 +292,8 @@ function readScalar(type, json, longType, nullAsZeroValue) {
321
292
  switch (type) {
322
293
  // float, double: JSON value will be a number or one of the special string values "NaN", "Infinity", and "-Infinity".
323
294
  // Either numbers or strings are accepted. Exponent notation is also accepted.
324
- case scalar_js_1.ScalarType.DOUBLE:
325
- case scalar_js_1.ScalarType.FLOAT:
295
+ case ScalarType.DOUBLE:
296
+ case ScalarType.FLOAT:
326
297
  if (json === "NaN")
327
298
  return Number.NaN;
328
299
  if (json === "Infinity")
@@ -349,15 +320,15 @@ function readScalar(type, json, longType, nullAsZeroValue) {
349
320
  // infinity and -infinity are handled by string representation above, so this is an error
350
321
  break;
351
322
  }
352
- if (type == scalar_js_1.ScalarType.FLOAT)
353
- (0, assert_js_1.assertFloat32)(float);
323
+ if (type == ScalarType.FLOAT)
324
+ assertFloat32(float);
354
325
  return float;
355
326
  // int32, fixed32, uint32: JSON value will be a decimal number. Either numbers or strings are accepted.
356
- case scalar_js_1.ScalarType.INT32:
357
- case scalar_js_1.ScalarType.FIXED32:
358
- case scalar_js_1.ScalarType.SFIXED32:
359
- case scalar_js_1.ScalarType.SINT32:
360
- case scalar_js_1.ScalarType.UINT32:
327
+ case ScalarType.INT32:
328
+ case ScalarType.FIXED32:
329
+ case ScalarType.SFIXED32:
330
+ case ScalarType.SINT32:
331
+ case ScalarType.UINT32:
361
332
  let int32;
362
333
  if (typeof json == "number")
363
334
  int32 = json;
@@ -367,34 +338,34 @@ function readScalar(type, json, longType, nullAsZeroValue) {
367
338
  }
368
339
  if (int32 === undefined)
369
340
  break;
370
- if (type == scalar_js_1.ScalarType.UINT32 || type == scalar_js_1.ScalarType.FIXED32)
371
- (0, assert_js_1.assertUInt32)(int32);
341
+ if (type == ScalarType.UINT32 || type == ScalarType.FIXED32)
342
+ assertUInt32(int32);
372
343
  else
373
- (0, assert_js_1.assertInt32)(int32);
344
+ assertInt32(int32);
374
345
  return int32;
375
346
  // int64, fixed64, uint64: JSON value will be a decimal string. Either numbers or strings are accepted.
376
- case scalar_js_1.ScalarType.INT64:
377
- case scalar_js_1.ScalarType.SFIXED64:
378
- case scalar_js_1.ScalarType.SINT64:
347
+ case ScalarType.INT64:
348
+ case ScalarType.SFIXED64:
349
+ case ScalarType.SINT64:
379
350
  if (typeof json != "number" && typeof json != "string")
380
351
  break;
381
- const long = proto_int64_js_1.protoInt64.parse(json);
352
+ const long = protoInt64.parse(json);
382
353
  // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
383
354
  return longType ? long.toString() : long;
384
- case scalar_js_1.ScalarType.FIXED64:
385
- case scalar_js_1.ScalarType.UINT64:
355
+ case ScalarType.FIXED64:
356
+ case ScalarType.UINT64:
386
357
  if (typeof json != "number" && typeof json != "string")
387
358
  break;
388
- const uLong = proto_int64_js_1.protoInt64.uParse(json);
359
+ const uLong = protoInt64.uParse(json);
389
360
  // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
390
361
  return longType ? uLong.toString() : uLong;
391
362
  // bool:
392
- case scalar_js_1.ScalarType.BOOL:
363
+ case ScalarType.BOOL:
393
364
  if (typeof json !== "boolean")
394
365
  break;
395
366
  return json;
396
367
  // string:
397
- case scalar_js_1.ScalarType.STRING:
368
+ case ScalarType.STRING:
398
369
  if (typeof json !== "string") {
399
370
  break;
400
371
  }
@@ -409,17 +380,17 @@ function readScalar(type, json, longType, nullAsZeroValue) {
409
380
  return json;
410
381
  // bytes: JSON value will be the data encoded as a string using standard base64 encoding with paddings.
411
382
  // Either standard or URL-safe base64 encoding with/without paddings are accepted.
412
- case scalar_js_1.ScalarType.BYTES:
383
+ case ScalarType.BYTES:
413
384
  if (json === "")
414
385
  return new Uint8Array(0);
415
386
  if (typeof json !== "string")
416
387
  break;
417
- return proto_base64_js_1.protoBase64.dec(json);
388
+ return protoBase64.dec(json);
418
389
  }
419
390
  throw new Error();
420
391
  }
421
392
  function readMapKey(type, json) {
422
- if (type === scalar_js_1.ScalarType.BOOL) {
393
+ if (type === ScalarType.BOOL) {
423
394
  // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
424
395
  switch (json) {
425
396
  case "true":
@@ -430,12 +401,12 @@ function readMapKey(type, json) {
430
401
  break;
431
402
  }
432
403
  }
433
- return readScalar(type, json, scalar_js_1.LongType.BIGINT, true).toString();
404
+ return readScalar(type, json, LongType.BIGINT, true).toString();
434
405
  }
435
406
  /**
436
407
  * Resets the field, so that isFieldSet() will return false.
437
408
  */
438
- function clearField(field, target) {
409
+ export function clearField(field, target) {
439
410
  const localName = field.localName;
440
411
  const implicitPresence = !field.opt && !field.req;
441
412
  if (field.repeated) {
@@ -454,7 +425,7 @@ function clearField(field, target) {
454
425
  break;
455
426
  case "scalar":
456
427
  target[localName] =
457
- implicitPresence ? (0, scalar_js_1.scalarZeroValue)(field.T, field.L) : undefined;
428
+ implicitPresence ? scalarZeroValue(field.T, field.L) : undefined;
458
429
  break;
459
430
  case "message":
460
431
  target[localName] = undefined;
@@ -462,7 +433,6 @@ function clearField(field, target) {
462
433
  }
463
434
  }
464
435
  }
465
- exports.clearField = clearField;
466
436
  // Decide whether an unset field should be emitted with JSON write option `emitDefaultValues`
467
437
  function canEmitFieldDefaultValue(field) {
468
438
  if (field.repeated || field.kind == "map") {
@@ -486,7 +456,7 @@ function canEmitFieldDefaultValue(field) {
486
456
  }
487
457
  function writeField(field, value, options) {
488
458
  if (field.kind == "map") {
489
- (0, assert_js_1.assert)(typeof value == "object" && value != null);
459
+ assert(typeof value == "object" && value != null);
490
460
  const jsonObj = {};
491
461
  const entries = Object.entries(value);
492
462
  switch (field.V.kind) {
@@ -498,7 +468,7 @@ function writeField(field, value, options) {
498
468
  case "message":
499
469
  for (const [entryKey, entryValue] of entries) {
500
470
  // JSON standard allows only (double quoted) string as property key
501
- const messageType = (0, field_js_1.resolveMessageType)(field.V.T);
471
+ const messageType = resolveMessageType(field.V.T);
502
472
  jsonObj[entryKey.toString()] = messageType.toJson(entryValue, options);
503
473
  }
504
474
  break;
@@ -515,7 +485,7 @@ function writeField(field, value, options) {
515
485
  : undefined;
516
486
  }
517
487
  if (field.repeated) {
518
- (0, assert_js_1.assert)(Array.isArray(value));
488
+ assert(Array.isArray(value));
519
489
  const jsonArr = [];
520
490
  switch (field.kind) {
521
491
  case "scalar":
@@ -544,26 +514,26 @@ function writeField(field, value, options) {
544
514
  case "enum":
545
515
  return writeEnum(field.T, value, options.enumAsInteger);
546
516
  case "message":
547
- const messageType = (0, field_js_1.resolveMessageType)(field.T);
548
- return messageType.toJson((0, field_wrapper_js_1.wrapField)(messageType.fieldWrapper, value));
517
+ const messageType = resolveMessageType(field.T);
518
+ return messageType.toJson(wrapField(messageType.fieldWrapper, value));
549
519
  }
550
520
  }
551
521
  function writeScalar(type, value) {
552
522
  switch (type) {
553
523
  // int32, fixed32, uint32: JSON value will be a decimal number. Either numbers or strings are accepted.
554
- case scalar_js_1.ScalarType.INT32:
555
- case scalar_js_1.ScalarType.SFIXED32:
556
- case scalar_js_1.ScalarType.SINT32:
557
- case scalar_js_1.ScalarType.FIXED32:
558
- case scalar_js_1.ScalarType.UINT32:
559
- (0, assert_js_1.assert)(typeof value == "number");
524
+ case ScalarType.INT32:
525
+ case ScalarType.SFIXED32:
526
+ case ScalarType.SINT32:
527
+ case ScalarType.FIXED32:
528
+ case ScalarType.UINT32:
529
+ assert(typeof value == "number");
560
530
  return value;
561
531
  // float, double: JSON value will be a number or one of the special string values "NaN", "Infinity", and "-Infinity".
562
532
  // Either numbers or strings are accepted. Exponent notation is also accepted.
563
- case scalar_js_1.ScalarType.FLOAT:
533
+ case ScalarType.FLOAT:
564
534
  // assertFloat32(value);
565
- case scalar_js_1.ScalarType.DOUBLE: // eslint-disable-line no-fallthrough
566
- (0, assert_js_1.assert)(typeof value == "number");
535
+ case ScalarType.DOUBLE: // eslint-disable-line no-fallthrough
536
+ assert(typeof value == "number");
567
537
  if (Number.isNaN(value))
568
538
  return "NaN";
569
539
  if (value === Number.POSITIVE_INFINITY)
@@ -572,32 +542,32 @@ function writeScalar(type, value) {
572
542
  return "-Infinity";
573
543
  return value;
574
544
  // string:
575
- case scalar_js_1.ScalarType.STRING:
576
- (0, assert_js_1.assert)(typeof value == "string");
545
+ case ScalarType.STRING:
546
+ assert(typeof value == "string");
577
547
  return value;
578
548
  // bool:
579
- case scalar_js_1.ScalarType.BOOL:
580
- (0, assert_js_1.assert)(typeof value == "boolean");
549
+ case ScalarType.BOOL:
550
+ assert(typeof value == "boolean");
581
551
  return value;
582
552
  // JSON value will be a decimal string. Either numbers or strings are accepted.
583
- case scalar_js_1.ScalarType.UINT64:
584
- case scalar_js_1.ScalarType.FIXED64:
585
- case scalar_js_1.ScalarType.INT64:
586
- case scalar_js_1.ScalarType.SFIXED64:
587
- case scalar_js_1.ScalarType.SINT64:
588
- (0, assert_js_1.assert)(typeof value == "bigint" ||
553
+ case ScalarType.UINT64:
554
+ case ScalarType.FIXED64:
555
+ case ScalarType.INT64:
556
+ case ScalarType.SFIXED64:
557
+ case ScalarType.SINT64:
558
+ assert(typeof value == "bigint" ||
589
559
  typeof value == "string" ||
590
560
  typeof value == "number");
591
561
  return value.toString();
592
562
  // bytes: JSON value will be the data encoded as a string using standard base64 encoding with paddings.
593
563
  // Either standard or URL-safe base64 encoding with/without paddings are accepted.
594
- case scalar_js_1.ScalarType.BYTES:
595
- (0, assert_js_1.assert)(value instanceof Uint8Array);
596
- return proto_base64_js_1.protoBase64.enc(value);
564
+ case ScalarType.BYTES:
565
+ assert(value instanceof Uint8Array);
566
+ return protoBase64.enc(value);
597
567
  }
598
568
  }
599
569
  function writeEnum(type, value, enumAsInteger) {
600
- (0, assert_js_1.assert)(typeof value == "number");
570
+ assert(typeof value == "number");
601
571
  if (type.typeName == "google.protobuf.NullValue") {
602
572
  return null;
603
573
  }
package/dist/message.d.ts CHANGED
@@ -55,15 +55,15 @@ export interface MessageType<T extends Message<T>> {
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>): CompleteMessage<T>;
58
+ fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): T;
59
59
  /**
60
60
  * Parse a message from a JSON value.
61
61
  */
62
- fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): CompleteMessage<T>;
62
+ fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): T;
63
63
  /**
64
64
  * Parse a message from a JSON string.
65
65
  */
66
- fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): CompleteMessage<T>;
66
+ fromJsonString(jsonString: string, 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`.