@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
package/dist/message.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,15 +11,13 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.createMessage = exports.createMessageType = exports.cloneMessage = exports.compareMessages = void 0;
17
- const field_js_1 = require("./field.js");
18
- const partial_js_1 = require("./partial.js");
19
- const scalar_js_1 = require("./scalar.js");
20
- const binary_js_1 = require("./binary.js");
21
- const json_js_1 = require("./json.js");
14
+ import { newFieldList, resolveMessageType, } from "./field.js";
15
+ import { applyPartialMessage } from "./partial.js";
16
+ import { ScalarType, scalarEquals } from "./scalar.js";
17
+ import { makeReadOptions as makeBinaryReadOptions, readMessage as readBinaryMessage, makeWriteOptions as makeBinaryWriteOptions, writeMessage as writeBinaryMessage, } from "./binary.js";
18
+ import { makeReadOptions as makeJsonReadOptions, readMessage as readJsonMessage, makeWriteOptions as makeJsonWriteOptions, writeMessage as writeJsonMessage, } from "./json.js";
22
19
  // compareMessages compares two messages for equality.
23
- function compareMessages(fields, a, b) {
20
+ export function compareMessages(fields, a, b) {
24
21
  if (a == null && b == null) {
25
22
  return true;
26
23
  }
@@ -40,22 +37,22 @@ function compareMessages(fields, a, b) {
40
37
  // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- repeated fields are never "map"
41
38
  switch (m.kind) {
42
39
  case "message":
43
- const messageType = (0, field_js_1.resolveMessageType)(m.T);
40
+ const messageType = resolveMessageType(m.T);
44
41
  return va.every((a, i) => messageType.equals(a, vb[i]));
45
42
  case "scalar":
46
- return va.every((a, i) => (0, scalar_js_1.scalarEquals)(m.T, a, vb[i]));
43
+ return va.every((a, i) => scalarEquals(m.T, a, vb[i]));
47
44
  case "enum":
48
- return va.every((a, i) => (0, scalar_js_1.scalarEquals)(scalar_js_1.ScalarType.INT32, a, vb[i]));
45
+ return va.every((a, i) => scalarEquals(ScalarType.INT32, a, vb[i]));
49
46
  }
50
47
  throw new Error(`repeated cannot contain ${m.kind}`);
51
48
  }
52
49
  switch (m.kind) {
53
50
  case "message":
54
- return (0, field_js_1.resolveMessageType)(m.T).equals(va, vb);
51
+ return resolveMessageType(m.T).equals(va, vb);
55
52
  case "enum":
56
- return (0, scalar_js_1.scalarEquals)(scalar_js_1.ScalarType.INT32, va, vb);
53
+ return scalarEquals(ScalarType.INT32, va, vb);
57
54
  case "scalar":
58
- return (0, scalar_js_1.scalarEquals)(m.T, va, vb);
55
+ return scalarEquals(m.T, va, vb);
59
56
  case "oneof":
60
57
  if (va.case !== vb.case) {
61
58
  return false;
@@ -67,37 +64,36 @@ function compareMessages(fields, a, b) {
67
64
  // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- oneof fields are never "map"
68
65
  switch (s.kind) {
69
66
  case "message":
70
- const messageType = (0, field_js_1.resolveMessageType)(s.T);
67
+ const messageType = resolveMessageType(s.T);
71
68
  return messageType.equals(va.value, vb.value);
72
69
  case "enum":
73
- return (0, scalar_js_1.scalarEquals)(scalar_js_1.ScalarType.INT32, va.value, vb.value);
70
+ return scalarEquals(ScalarType.INT32, va.value, vb.value);
74
71
  case "scalar":
75
- return (0, scalar_js_1.scalarEquals)(s.T, va.value, vb.value);
72
+ return scalarEquals(s.T, va.value, vb.value);
76
73
  }
77
74
  throw new Error(`oneof cannot contain ${s.kind}`);
78
75
  case "map":
79
76
  const keys = Object.keys(va).concat(Object.keys(vb));
80
77
  switch (m.V.kind) {
81
78
  case "message":
82
- const messageType = (0, field_js_1.resolveMessageType)(m.V.T);
79
+ const messageType = resolveMessageType(m.V.T);
83
80
  return keys.every((k) => messageType.equals(va[k], vb[k]));
84
81
  case "enum":
85
- return keys.every((k) => (0, scalar_js_1.scalarEquals)(scalar_js_1.ScalarType.INT32, va[k], vb[k]));
82
+ return keys.every((k) => scalarEquals(ScalarType.INT32, va[k], vb[k]));
86
83
  case "scalar":
87
84
  const scalarType = m.V.T;
88
- return keys.every((k) => (0, scalar_js_1.scalarEquals)(scalarType, va[k], vb[k]));
85
+ return keys.every((k) => scalarEquals(scalarType, va[k], vb[k]));
89
86
  }
90
87
  }
91
88
  });
92
89
  }
93
- exports.compareMessages = compareMessages;
94
90
  // clone a single field value - i.e. the element type of repeated fields, the value type of maps
95
91
  function cloneSingularField(value, fieldInfo) {
96
92
  if (value === undefined) {
97
93
  return value;
98
94
  }
99
95
  if (fieldInfo.kind === "message") {
100
- return cloneMessage(value, (0, field_js_1.resolveMessageType)(fieldInfo.T).fields);
96
+ return cloneMessage(value, resolveMessageType(fieldInfo.T).fields);
101
97
  }
102
98
  if (fieldInfo.kind === "oneof") {
103
99
  if (value.case === undefined) {
@@ -120,7 +116,7 @@ function cloneSingularField(value, fieldInfo) {
120
116
  return value;
121
117
  }
122
118
  // TODO use isFieldSet() here to support future field presence
123
- function cloneMessage(message, fields) {
119
+ export function cloneMessage(message, fields) {
124
120
  const clone = {};
125
121
  for (const member of fields.byMember()) {
126
122
  const source = message[member.localName];
@@ -148,23 +144,22 @@ function cloneMessage(message, fields) {
148
144
  }
149
145
  return clone;
150
146
  }
151
- exports.cloneMessage = cloneMessage;
152
147
  /**
153
148
  * createMessageType creates a new message type.
154
149
  *
155
150
  * The argument `packedByDefault` specifies whether fields that do not specify
156
151
  * `packed` should be packed (proto3) or unpacked (proto2).
157
152
  */
158
- function createMessageType(params) {
153
+ export function createMessageType(params) {
159
154
  const { fields: fieldsSource, typeName, packedByDefault, delimitedMessageEncoding, fieldWrapper, } = params;
160
- const fields = (0, field_js_1.newFieldList)(fieldsSource, packedByDefault);
155
+ const fields = newFieldList(fieldsSource, packedByDefault);
161
156
  const mt = {
162
157
  typeName,
163
158
  fields,
164
159
  fieldWrapper,
165
160
  create(partial) {
166
161
  const message = createMessage(fields);
167
- (0, partial_js_1.applyPartialMessage)(partial, message, fields);
162
+ applyPartialMessage(partial, message, fields);
168
163
  return message;
169
164
  },
170
165
  equals(a, b) {
@@ -177,15 +172,15 @@ function createMessageType(params) {
177
172
  return cloneMessage(a, fields);
178
173
  },
179
174
  fromBinary(bytes, options) {
180
- const message = this.create();
181
- const opt = (0, binary_js_1.makeReadOptions)(options);
182
- (0, binary_js_1.readMessage)(message, fields, opt.readerFactory(bytes), bytes.byteLength, opt, delimitedMessageEncoding);
175
+ const message = {};
176
+ const opt = makeBinaryReadOptions(options);
177
+ readBinaryMessage(message, fields, opt.readerFactory(bytes), bytes.byteLength, opt, delimitedMessageEncoding);
183
178
  return message;
184
179
  },
185
180
  fromJson(jsonValue, options) {
186
- const message = this.create();
187
- const opts = (0, json_js_1.makeReadOptions)(options);
188
- (0, json_js_1.readMessage)(fields, typeName, jsonValue, opts, message);
181
+ const message = {};
182
+ const opts = makeJsonReadOptions(options);
183
+ readJsonMessage(fields, typeName, jsonValue, opts, message);
189
184
  return message;
190
185
  },
191
186
  fromJsonString(jsonString, options) {
@@ -199,14 +194,14 @@ function createMessageType(params) {
199
194
  return this.fromJson(json, options);
200
195
  },
201
196
  toBinary(a, options) {
202
- const opt = (0, binary_js_1.makeWriteOptions)(options);
197
+ const opt = makeBinaryWriteOptions(options);
203
198
  const writer = opt.writerFactory();
204
- (0, binary_js_1.writeMessage)(a, fields, writer, opt);
199
+ writeBinaryMessage(a, fields, writer, opt);
205
200
  return writer.finish();
206
201
  },
207
202
  toJson(a, options) {
208
- const opt = (0, json_js_1.makeWriteOptions)(options);
209
- return (0, json_js_1.writeMessage)(a, fields, opt);
203
+ const opt = makeJsonWriteOptions(options);
204
+ return writeJsonMessage(a, fields, opt);
210
205
  },
211
206
  toJsonString(a, options) {
212
207
  const value = this.toJson(a, options);
@@ -218,11 +213,10 @@ function createMessageType(params) {
218
213
  }
219
214
  return mt;
220
215
  }
221
- exports.createMessageType = createMessageType;
222
216
  /**
223
217
  * createMessage recursively builds a message filled with zero values based on the given FieldList.
224
218
  */
225
- function createMessage(fields) {
219
+ export function createMessage(fields) {
226
220
  const message = {};
227
221
  for (const field of fields.list()) {
228
222
  const fieldKind = field.kind;
@@ -233,29 +227,29 @@ function createMessage(fields) {
233
227
  }
234
228
  else {
235
229
  switch (field.T) {
236
- case scalar_js_1.ScalarType.DOUBLE:
237
- case scalar_js_1.ScalarType.FLOAT:
230
+ case ScalarType.DOUBLE:
231
+ case ScalarType.FLOAT:
238
232
  message[field.localName] = 0;
239
233
  break;
240
- case scalar_js_1.ScalarType.INT64:
241
- case scalar_js_1.ScalarType.UINT64:
242
- case scalar_js_1.ScalarType.INT32:
243
- case scalar_js_1.ScalarType.FIXED64:
244
- case scalar_js_1.ScalarType.FIXED32:
245
- case scalar_js_1.ScalarType.UINT32:
246
- case scalar_js_1.ScalarType.SFIXED32:
247
- case scalar_js_1.ScalarType.SFIXED64:
248
- case scalar_js_1.ScalarType.SINT32:
249
- case scalar_js_1.ScalarType.SINT64:
234
+ case ScalarType.INT64:
235
+ case ScalarType.UINT64:
236
+ case ScalarType.INT32:
237
+ case ScalarType.FIXED64:
238
+ case ScalarType.FIXED32:
239
+ case ScalarType.UINT32:
240
+ case ScalarType.SFIXED32:
241
+ case ScalarType.SFIXED64:
242
+ case ScalarType.SINT32:
243
+ case ScalarType.SINT64:
250
244
  message[field.localName] = 0;
251
245
  break;
252
- case scalar_js_1.ScalarType.BOOL:
246
+ case ScalarType.BOOL:
253
247
  message[field.localName] = false;
254
248
  break;
255
- case scalar_js_1.ScalarType.STRING:
249
+ case ScalarType.STRING:
256
250
  message[field.localName] = "";
257
251
  break;
258
- case scalar_js_1.ScalarType.BYTES:
252
+ case ScalarType.BYTES:
259
253
  message[field.localName] =
260
254
  new Uint8Array();
261
255
  break;
@@ -275,7 +269,7 @@ function createMessage(fields) {
275
269
  message[field.localName] = undefined;
276
270
  continue;
277
271
  }
278
- const messageType = (0, field_js_1.resolveMessageType)(field.T);
272
+ const messageType = resolveMessageType(field.T);
279
273
  if (field.repeated) {
280
274
  message[field.localName] = [];
281
275
  }
@@ -292,4 +286,3 @@ function createMessage(fields) {
292
286
  }
293
287
  return message;
294
288
  }
295
- exports.createMessage = createMessage;
package/dist/names.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,8 +11,6 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.safeIdentifier = exports.safeObjectProperty = exports.protoCamelCase = exports.camelToSnakeCase = exports.findEnumSharedPrefix = exports.localOneofName = exports.localFieldName = exports.localName = void 0;
17
14
  /**
18
15
  * Returns the name of a protobuf element in generated code.
19
16
  *
@@ -22,7 +19,7 @@ exports.safeIdentifier = exports.safeObjectProperty = exports.protoCamelCase = e
22
19
  * the type name. For nested messages and enumerations, the names are joined
23
20
  * with an underscore. For methods, the first character is made lowercase.
24
21
  */
25
- function localName(desc) {
22
+ export function localName(desc) {
26
23
  switch (desc.kind) {
27
24
  case "field":
28
25
  return localFieldName(desc.name, desc.oneof !== undefined);
@@ -40,7 +37,7 @@ function localName(desc) {
40
37
  // do not want to introduce a breaking change, so we continue to escape for
41
38
  // safe object properties.
42
39
  // See https://github.com/bufbuild/protobuf-es/pull/391
43
- return (0, exports.safeObjectProperty)((0, exports.safeIdentifier)(name));
40
+ return safeObjectProperty(safeIdentifier(name));
44
41
  }
45
42
  case "enum_value": {
46
43
  let name = desc.name;
@@ -48,7 +45,7 @@ function localName(desc) {
48
45
  if (sharedPrefix !== undefined) {
49
46
  name = name.substring(sharedPrefix.length);
50
47
  }
51
- return (0, exports.safeObjectProperty)(name);
48
+ return safeObjectProperty(name);
52
49
  }
53
50
  case "rpc": {
54
51
  let name = desc.name;
@@ -56,35 +53,32 @@ function localName(desc) {
56
53
  return name;
57
54
  }
58
55
  name = name[0].toLowerCase() + name.substring(1);
59
- return (0, exports.safeObjectProperty)(name);
56
+ return safeObjectProperty(name);
60
57
  }
61
58
  }
62
59
  }
63
- exports.localName = localName;
64
60
  /**
65
61
  * Returns the name of a field in generated code.
66
62
  */
67
- function localFieldName(protoName, inOneof) {
63
+ export function localFieldName(protoName, inOneof) {
68
64
  const name = protoCamelCase(protoName);
69
65
  if (inOneof) {
70
66
  // oneof member names are not properties, but values of the `case` property.
71
67
  return name;
72
68
  }
73
- return (0, exports.safeObjectProperty)(safeMessageProperty(name));
69
+ return safeObjectProperty(safeMessageProperty(name));
74
70
  }
75
- exports.localFieldName = localFieldName;
76
71
  /**
77
72
  * Returns the name of a oneof group in generated code.
78
73
  */
79
- function localOneofName(protoName) {
74
+ export function localOneofName(protoName) {
80
75
  return localFieldName(protoName, false);
81
76
  }
82
- exports.localOneofName = localOneofName;
83
77
  /**
84
78
  * Finds a prefix shared by enum values, for example `MY_ENUM_` for
85
79
  * `enum MyEnum {MY_ENUM_A=0; MY_ENUM_B=1;}`.
86
80
  */
87
- function findEnumSharedPrefix(enumName, valueNames) {
81
+ export function findEnumSharedPrefix(enumName, valueNames) {
88
82
  const prefix = camelToSnakeCase(enumName) + "_";
89
83
  for (const name of valueNames) {
90
84
  if (!name.toLowerCase().startsWith(prefix)) {
@@ -101,20 +95,18 @@ function findEnumSharedPrefix(enumName, valueNames) {
101
95
  }
102
96
  return prefix;
103
97
  }
104
- exports.findEnumSharedPrefix = findEnumSharedPrefix;
105
98
  /**
106
99
  * Converts lowerCamelCase or UpperCamelCase into lower_snake_case.
107
100
  * This is used to find shared prefixes in an enum.
108
101
  */
109
- function camelToSnakeCase(camel) {
102
+ export function camelToSnakeCase(camel) {
110
103
  return (camel.substring(0, 1) + camel.substring(1).replace(/[A-Z]/g, (c) => "_" + c)).toLowerCase();
111
104
  }
112
- exports.camelToSnakeCase = camelToSnakeCase;
113
105
  /**
114
106
  * Converts snake_case to protoCamelCase according to the convention
115
107
  * used by protoc to convert a field name to a JSON name.
116
108
  */
117
- function protoCamelCase(snakeCase) {
109
+ export function protoCamelCase(snakeCase) {
118
110
  let capNext = false;
119
111
  const b = [];
120
112
  for (let i = 0; i < snakeCase.length; i++) {
@@ -147,7 +139,6 @@ function protoCamelCase(snakeCase) {
147
139
  }
148
140
  return b.join("");
149
141
  }
150
- exports.protoCamelCase = protoCamelCase;
151
142
  /**
152
143
  * Names that cannot be used for identifiers, such as class names,
153
144
  * but _can_ be used for object properties.
@@ -257,20 +248,18 @@ const safeMessageProperty = (name) => {
257
248
  * Names that cannot be used for object properties because they are reserved
258
249
  * by built-in JavaScript properties.
259
250
  */
260
- const safeObjectProperty = (name) => {
251
+ export const safeObjectProperty = (name) => {
261
252
  if (reservedObjectProperties.has(name)) {
262
253
  return fallback(name);
263
254
  }
264
255
  return name;
265
256
  };
266
- exports.safeObjectProperty = safeObjectProperty;
267
257
  /**
268
258
  * Names that can be used for identifiers or class properties
269
259
  */
270
- const safeIdentifier = (name) => {
260
+ export const safeIdentifier = (name) => {
271
261
  if (reservedIdentifiers.has(name)) {
272
262
  return fallback(name);
273
263
  }
274
264
  return name;
275
265
  };
276
- exports.safeIdentifier = safeIdentifier;
package/dist/partial.js CHANGED
@@ -1,18 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyPartialMessage = void 0;
4
- const field_js_1 = require("./field.js");
5
- const is_message_js_1 = require("./is-message.js");
6
- const scalar_js_1 = require("./scalar.js");
1
+ import { resolveMessageType } from "./field.js";
2
+ import { ScalarType } from "./scalar.js";
7
3
  // applyPartialMessage applies a partial message to a message.
8
- function applyPartialMessage(source, target, fields) {
4
+ export function applyPartialMessage(source, target, fields) {
9
5
  if (source === undefined) {
10
6
  return;
11
7
  }
12
8
  for (const member of fields.byMember()) {
13
9
  const localName = member.localName, t = target, s = source;
14
10
  if (s[localName] === undefined) {
15
- // TODO if source is a Message instance, we should use isFieldSet() here to support future field presence
16
11
  continue;
17
12
  }
18
13
  switch (member.kind) {
@@ -24,14 +19,13 @@ function applyPartialMessage(source, target, fields) {
24
19
  const sourceField = member.findField(sk);
25
20
  let val = s[localName].value;
26
21
  if (sourceField?.kind == "message") {
27
- const messageType = (0, field_js_1.resolveMessageType)(sourceField.T);
28
- if (!(0, is_message_js_1.isCompleteMessage)(val, messageType.fields.list())) {
29
- val = messageType.create(val);
22
+ if (val === undefined) {
23
+ val = {};
30
24
  }
31
25
  }
32
26
  else if (sourceField &&
33
27
  sourceField.kind === "scalar" &&
34
- sourceField.T === scalar_js_1.ScalarType.BYTES) {
28
+ sourceField.T === ScalarType.BYTES) {
35
29
  val = toU8Arr(val);
36
30
  }
37
31
  t[localName] = { case: sk, value: val };
@@ -39,7 +33,7 @@ function applyPartialMessage(source, target, fields) {
39
33
  case "scalar":
40
34
  case "enum":
41
35
  let copy = s[localName];
42
- if (member.T === scalar_js_1.ScalarType.BYTES) {
36
+ if (member.T === ScalarType.BYTES) {
43
37
  copy =
44
38
  member.repeated ?
45
39
  copy.map(toU8Arr)
@@ -51,7 +45,7 @@ function applyPartialMessage(source, target, fields) {
51
45
  switch (member.V.kind) {
52
46
  case "scalar":
53
47
  case "enum":
54
- if (member.V.T === scalar_js_1.ScalarType.BYTES) {
48
+ if (member.V.T === ScalarType.BYTES) {
55
49
  for (const [k, v] of Object.entries(s[localName])) {
56
50
  t[localName][k] = toU8Arr(v);
57
51
  }
@@ -61,13 +55,13 @@ function applyPartialMessage(source, target, fields) {
61
55
  }
62
56
  break;
63
57
  case "message":
64
- const messageType = (0, field_js_1.resolveMessageType)(member.V.T);
58
+ const messageType = resolveMessageType(member.V.T);
65
59
  for (const k of Object.keys(s[localName])) {
66
60
  let val = s[localName][k];
67
61
  if (!messageType.fieldWrapper) {
68
- // We only take partial input for messages that are not a wrapper type.
69
- // For those messages, we recursively normalize the partial input.
70
- val = messageType.create(val);
62
+ if (val === undefined) {
63
+ val = {};
64
+ }
71
65
  }
72
66
  t[localName][k] = val;
73
67
  }
@@ -75,9 +69,9 @@ function applyPartialMessage(source, target, fields) {
75
69
  }
76
70
  break;
77
71
  case "message":
78
- const mt = (0, field_js_1.resolveMessageType)(member.T);
72
+ const mt = resolveMessageType(member.T);
79
73
  if (member.repeated) {
80
- t[localName] = s[localName].map((val) => (0, is_message_js_1.isCompleteMessage)(val, mt.fields.list()) ? val : mt.create(val));
74
+ t[localName] = s[localName].map((val) => val ?? {});
81
75
  }
82
76
  else {
83
77
  const val = s[localName];
@@ -92,16 +86,13 @@ function applyPartialMessage(source, target, fields) {
92
86
  }
93
87
  }
94
88
  else {
95
- const messageType = mt;
96
- t[localName] =
97
- (0, is_message_js_1.isCompleteMessage)(val, messageType.fields.list()) ? val : (messageType.create(val));
89
+ t[localName] = val ?? {};
98
90
  }
99
91
  }
100
92
  break;
101
93
  }
102
94
  }
103
95
  }
104
- exports.applyPartialMessage = applyPartialMessage;
105
96
  // converts any ArrayLike<number> to Uint8Array if necessary.
106
97
  function toU8Arr(input) {
107
98
  return input instanceof Uint8Array ? input : new Uint8Array(input);
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,8 +11,6 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.protoBase64 = void 0;
17
14
  /* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unnecessary-condition, prefer-const */
18
15
  // lookup table from base64 character to byte
19
16
  let encTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
@@ -24,7 +21,7 @@ for (let i = 0; i < encTable.length; i++)
24
21
  // support base64url variants
25
22
  decTable["-".charCodeAt(0)] = encTable.indexOf("+");
26
23
  decTable["_".charCodeAt(0)] = encTable.indexOf("/");
27
- exports.protoBase64 = {
24
+ export const protoBase64 = {
28
25
  /**
29
26
  * Decodes a base64 string to a byte array.
30
27
  *
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,8 +11,6 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.protoDouble = void 0;
17
14
  // Export global Number constants. This is done so that we can safely use
18
15
  // these global constants when generating code and be assured we're using
19
16
  // the correct values. We cannot rely on globalThis since we support ES2017
@@ -22,7 +19,7 @@ exports.protoDouble = void 0;
22
19
  // a message name of Number. Instead we can export them here since this will
23
20
  // be in a different scope as the generated code and we are guaranteed to use
24
21
  // the intended global values.
25
- exports.protoDouble = {
22
+ export const protoDouble = {
26
23
  NaN: Number.NaN,
27
24
  POSITIVE_INFINITY: Number.POSITIVE_INFINITY,
28
25
  NEGATIVE_INFINITY: Number.NEGATIVE_INFINITY,
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,10 +11,8 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.protoInt64 = void 0;
17
- const assert_js_1 = require("./assert.js");
18
- const varint_js_1 = require("./varint.js");
14
+ import { assert } from "./assert.js";
15
+ import { int64FromString, int64ToString, uInt64ToString } from "./varint.js";
19
16
  function makeInt64Support() {
20
17
  const dv = new DataView(new ArrayBuffer(8));
21
18
  // note that Safari 14 implements BigInt, but not the DataView methods
@@ -72,8 +69,8 @@ function makeInt64Support() {
72
69
  },
73
70
  };
74
71
  }
75
- const assertInt64String = (value) => (0, assert_js_1.assert)(/^-?[0-9]+$/.test(value), `int64 invalid: ${value}`);
76
- const assertUInt64String = (value) => (0, assert_js_1.assert)(/^[0-9]+$/.test(value), `uint64 invalid: ${value}`);
72
+ const assertInt64String = (value) => assert(/^-?[0-9]+$/.test(value), `int64 invalid: ${value}`);
73
+ const assertUInt64String = (value) => assert(/^[0-9]+$/.test(value), `uint64 invalid: ${value}`);
77
74
  return {
78
75
  zero: "0",
79
76
  supported: false,
@@ -96,21 +93,21 @@ function makeInt64Support() {
96
93
  value = value.toString();
97
94
  }
98
95
  assertInt64String(value);
99
- return (0, varint_js_1.int64FromString)(value);
96
+ return int64FromString(value);
100
97
  },
101
98
  uEnc(value) {
102
99
  if (typeof value != "string") {
103
100
  value = value.toString();
104
101
  }
105
102
  assertUInt64String(value);
106
- return (0, varint_js_1.int64FromString)(value);
103
+ return int64FromString(value);
107
104
  },
108
105
  dec(lo, hi) {
109
- return (0, varint_js_1.int64ToString)(lo, hi);
106
+ return int64ToString(lo, hi);
110
107
  },
111
108
  uDec(lo, hi) {
112
- return (0, varint_js_1.uInt64ToString)(lo, hi);
109
+ return uInt64ToString(lo, hi);
113
110
  },
114
111
  };
115
112
  }
116
- exports.protoInt64 = makeInt64Support();
113
+ export const protoInt64 = makeInt64Support();
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2024 Aperture Robotics, LLC.
3
2
  // Copyright 2021-2024 Buf Technologies, Inc.
4
3
  //
@@ -13,13 +12,11 @@
13
12
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
13
  // See the License for the specific language governing permissions and
15
14
  // limitations under the License.
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.protocGenEsLite = void 0;
18
- const index_js_1 = require("../protoplugin/index.js");
19
- const typescript_js_1 = require("./typescript.js");
15
+ import { createEcmaScriptPlugin } from "../protoplugin/index.js";
16
+ import { generateTs } from "./typescript.js";
20
17
  // import { version } from "../package.json";
21
- exports.protocGenEsLite = (0, index_js_1.createEcmaScriptPlugin)({
18
+ export const protocGenEsLite = createEcmaScriptPlugin({
22
19
  name: "protoc-gen-es-lite",
23
20
  version: `unknown`,
24
- generateTs: typescript_js_1.generateTs,
21
+ generateTs,
25
22
  });