@bufbuild/protobuf 1.1.0 → 1.2.0

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.
@@ -25,6 +25,8 @@ exports.codegenInfo = {
25
25
  reifyWkt: reify_wkt_js_1.reifyWkt,
26
26
  getUnwrappedFieldType: field_wrapper_js_1.getUnwrappedFieldType,
27
27
  scalarDefaultValue: scalars_js_1.scalarDefaultValue,
28
+ safeIdentifier: names_js_1.safeIdentifier,
29
+ safeObjectProperty: names_js_1.safeObjectProperty,
28
30
  // prettier-ignore
29
31
  symbols: {
30
32
  proto2: { typeOnly: false, privateImportPath: "./proto2.js", publicImportPath: packageName },
@@ -141,16 +141,15 @@ function createRegistryFromDescriptors(input, replaceWkt = true) {
141
141
  const O = this.findMessage(method.output.typeName);
142
142
  (0, assert_js_1.assert)(I, `message "${method.input.typeName}" for ${method.toString()} not found`);
143
143
  (0, assert_js_1.assert)(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);
144
- const m = {
144
+ methods[(0, names_js_1.localName)(method)] = {
145
145
  name: method.name,
146
- localName: (0, names_js_1.localName)(method),
147
146
  I,
148
147
  O,
149
148
  kind: method.methodKind,
150
149
  idempotency: method.idempotency,
151
- options: {},
150
+ // We do not surface options at this time
151
+ // options: {},
152
152
  };
153
- methods[m.localName] = m;
154
153
  }
155
154
  return (services[typeName] = {
156
155
  typeName: desc.typeName,
@@ -14,7 +14,7 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0;
17
- // @generated by protoc-gen-es v1.1.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v1.2.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
18
18
  // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
19
19
  /* eslint-disable */
20
20
  const proto3_js_1 = require("../../proto3.js");
@@ -14,7 +14,7 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0;
17
- // @generated by protoc-gen-es v1.1.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v1.2.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
18
18
  // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
19
19
  /* eslint-disable */
20
20
  const proto3_js_1 = require("../../proto3.js");
@@ -13,7 +13,7 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.findEnumSharedPrefix = exports.fieldJsonName = exports.localOneofName = exports.localFieldName = exports.localName = void 0;
16
+ exports.safeIdentifier = exports.safeObjectProperty = exports.findEnumSharedPrefix = exports.fieldJsonName = exports.localOneofName = exports.localFieldName = exports.localName = void 0;
17
17
  /**
18
18
  * Returns the name of a protobuf element in generated code.
19
19
  *
@@ -34,10 +34,12 @@ function localName(desc) {
34
34
  const pkg = desc.file.proto.package;
35
35
  const offset = pkg === undefined ? 0 : pkg.length + 1;
36
36
  const name = desc.typeName.substring(offset).replace(/\./g, "_");
37
- if (reservedIdent[name]) {
38
- return name + "$";
39
- }
40
- return name;
37
+ // For services, we only care about safe identifiers, not safe object properties,
38
+ // but we have shipped v1 with a bug that respected object properties, and we
39
+ // do not want to introduce a breaking change, so we continue to escape for
40
+ // safe object properties.
41
+ // See https://github.com/bufbuild/protobuf-es/pull/391
42
+ return (0, exports.safeObjectProperty)((0, exports.safeIdentifier)(name));
41
43
  }
42
44
  case "enum_value": {
43
45
  const sharedPrefix = desc.parent.sharedPrefix;
@@ -45,10 +47,7 @@ function localName(desc) {
45
47
  return desc.name;
46
48
  }
47
49
  const name = desc.name.substring(sharedPrefix.length);
48
- if (reservedObjectProperties[name]) {
49
- return name + "$";
50
- }
51
- return name;
50
+ return (0, exports.safeObjectProperty)(name);
52
51
  }
53
52
  case "rpc": {
54
53
  let name = desc.name;
@@ -56,10 +55,7 @@ function localName(desc) {
56
55
  return name;
57
56
  }
58
57
  name = name[0].toLowerCase() + name.substring(1);
59
- if (reservedObjectProperties[name]) {
60
- return name + "$";
61
- }
62
- return name;
58
+ return (0, exports.safeObjectProperty)(name);
63
59
  }
64
60
  }
65
61
  }
@@ -68,15 +64,12 @@ exports.localName = localName;
68
64
  * Returns the name of a field in generated code.
69
65
  */
70
66
  function localFieldName(protoName, inOneof) {
71
- let name = protoCamelCase(protoName);
67
+ const name = protoCamelCase(protoName);
72
68
  if (inOneof) {
73
69
  // oneof member names are not properties, but values of the `case` property.
74
70
  return name;
75
71
  }
76
- if (reservedObjectProperties[name] || reservedMessageProperties[name]) {
77
- name = name + "$";
78
- }
79
- return name;
72
+ return (0, exports.safeObjectProperty)(safeMessageProperty(name));
80
73
  }
81
74
  exports.localFieldName = localFieldName;
82
75
  /**
@@ -156,91 +149,129 @@ function protoCamelCase(snakeCase) {
156
149
  }
157
150
  return b.join("");
158
151
  }
159
- // Names that cannot be used for identifiers, such as class names,
160
- // but _can_ be used for object properties.
161
- const reservedIdent = {
152
+ /**
153
+ * Names that cannot be used for identifiers, such as class names,
154
+ * but _can_ be used for object properties.
155
+ */
156
+ const reservedIdentifiers = new Set([
162
157
  // ECMAScript 2015 keywords
163
- break: true,
164
- case: true,
165
- catch: true,
166
- class: true,
167
- const: true,
168
- continue: true,
169
- debugger: true,
170
- default: true,
171
- delete: true,
172
- do: true,
173
- else: true,
174
- export: true,
175
- extends: true,
176
- false: true,
177
- finally: true,
178
- for: true,
179
- function: true,
180
- if: true,
181
- import: true,
182
- in: true,
183
- instanceof: true,
184
- new: true,
185
- null: true,
186
- return: true,
187
- super: true,
188
- switch: true,
189
- this: true,
190
- throw: true,
191
- true: true,
192
- try: true,
193
- typeof: true,
194
- var: true,
195
- void: true,
196
- while: true,
197
- with: true,
198
- yield: true,
158
+ "break",
159
+ "case",
160
+ "catch",
161
+ "class",
162
+ "const",
163
+ "continue",
164
+ "debugger",
165
+ "default",
166
+ "delete",
167
+ "do",
168
+ "else",
169
+ "export",
170
+ "extends",
171
+ "false",
172
+ "finally",
173
+ "for",
174
+ "function",
175
+ "if",
176
+ "import",
177
+ "in",
178
+ "instanceof",
179
+ "new",
180
+ "null",
181
+ "return",
182
+ "super",
183
+ "switch",
184
+ "this",
185
+ "throw",
186
+ "true",
187
+ "try",
188
+ "typeof",
189
+ "var",
190
+ "void",
191
+ "while",
192
+ "with",
193
+ "yield",
199
194
  // ECMAScript 2015 future reserved keywords
200
- enum: true,
201
- implements: true,
202
- interface: true,
203
- let: true,
204
- package: true,
205
- private: true,
206
- protected: true,
207
- public: true,
208
- static: true,
195
+ "enum",
196
+ "implements",
197
+ "interface",
198
+ "let",
199
+ "package",
200
+ "private",
201
+ "protected",
202
+ "public",
203
+ "static",
209
204
  // Class name cannot be 'Object' when targeting ES5 with module CommonJS
210
- Object: true,
205
+ "Object",
211
206
  // TypeScript keywords that cannot be used for types (as opposed to variables)
212
- bigint: true,
213
- number: true,
214
- boolean: true,
215
- string: true,
216
- object: true,
207
+ "bigint",
208
+ "number",
209
+ "boolean",
210
+ "string",
211
+ "object",
217
212
  // Identifiers reserved for the runtime, so we can generate legible code
218
- globalThis: true,
219
- Uint8Array: true,
220
- Partial: true,
221
- };
222
- // Names that cannot be used for object properties because they are reserved
223
- // by built-in JavaScript properties.
224
- const reservedObjectProperties = {
213
+ "globalThis",
214
+ "Uint8Array",
215
+ "Partial",
216
+ ]);
217
+ /**
218
+ * Names that cannot be used for object properties because they are reserved
219
+ * by built-in JavaScript properties.
220
+ */
221
+ const reservedObjectProperties = new Set([
225
222
  // names reserved by JavaScript
226
- constructor: true,
227
- toString: true,
228
- toJSON: true,
229
- valueOf: true,
230
- };
231
- // Names that cannot be used for object properties because they are reserved
232
- // by the runtime.
233
- const reservedMessageProperties = {
223
+ "constructor",
224
+ "toString",
225
+ "toJSON",
226
+ "valueOf",
227
+ ]);
228
+ /**
229
+ * Names that cannot be used for object properties because they are reserved
230
+ * by the runtime.
231
+ */
232
+ const reservedMessageProperties = new Set([
234
233
  // names reserved by the runtime
235
- getType: true,
236
- clone: true,
237
- equals: true,
238
- fromBinary: true,
239
- fromJson: true,
240
- fromJsonString: true,
241
- toBinary: true,
242
- toJson: true,
243
- toJsonString: true,
234
+ "getType",
235
+ "clone",
236
+ "equals",
237
+ "fromBinary",
238
+ "fromJson",
239
+ "fromJsonString",
240
+ "toBinary",
241
+ "toJson",
242
+ "toJsonString",
244
243
  // names reserved by the runtime for the future
245
- toObject: true,
244
+ "toObject",
245
+ ]);
246
+ const fallback = (name) => `${name}$`;
247
+ /**
248
+ * Will wrap names that are Object prototype properties or names reserved
249
+ * for `Message`s.
250
+ */
251
+ const safeMessageProperty = (name) => {
252
+ if (reservedMessageProperties.has(name)) {
253
+ return fallback(name);
254
+ }
255
+ return name;
256
+ };
257
+ /**
258
+ * Names that cannot be used for object properties because they are reserved
259
+ * by built-in JavaScript properties.
260
+ */
261
+ const safeObjectProperty = (name) => {
262
+ if (reservedObjectProperties.has(name)) {
263
+ return fallback(name);
264
+ }
265
+ return name;
266
+ };
267
+ exports.safeObjectProperty = safeObjectProperty;
268
+ /**
269
+ * Names that can be used for identifiers or class properties
270
+ */
271
+ const safeIdentifier = (name) => {
272
+ if (reservedIdentifiers.has(name)) {
273
+ return fallback(name);
274
+ }
275
+ return name;
246
276
  };
277
+ exports.safeIdentifier = safeIdentifier;
@@ -125,18 +125,18 @@ function makeUtilCommon() {
125
125
  if (va.case !== vb.case) {
126
126
  return false;
127
127
  }
128
- const k = va.case, s = m.findField(k);
128
+ const s = m.findField(va.case);
129
129
  if (s === undefined) {
130
130
  return true;
131
131
  }
132
132
  // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- oneof fields are never "map"
133
133
  switch (s.kind) {
134
134
  case "message":
135
- return s.T.equals(va[k], vb[k]);
135
+ return s.T.equals(va.value, vb.value);
136
136
  case "enum":
137
- return (0, scalars_js_1.scalarEquals)(field_js_1.ScalarType.INT32, va, vb);
137
+ return (0, scalars_js_1.scalarEquals)(field_js_1.ScalarType.INT32, va.value, vb.value);
138
138
  case "scalar":
139
- return (0, scalars_js_1.scalarEquals)(s.T, va, vb);
139
+ return (0, scalars_js_1.scalarEquals)(s.T, va.value, vb.value);
140
140
  }
141
141
  throw new Error(`oneof cannot contain ${s.kind}`);
142
142
  case "map":
@@ -39,8 +39,6 @@ exports.protoBase64 = {
39
39
  dec(base64Str) {
40
40
  // estimate byte size, not accounting for inner padding and whitespace
41
41
  let es = (base64Str.length * 3) / 4;
42
- // if (es % 3 !== 0)
43
- // throw new Error("invalid base64 string");
44
42
  if (base64Str[base64Str.length - 2] == "=")
45
43
  es -= 2;
46
44
  else if (base64Str[base64Str.length - 1] == "=")
@@ -11,7 +11,7 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- import { localName } from "./private/names.js";
14
+ import { localName, safeIdentifier, safeObjectProperty, } from "./private/names.js";
15
15
  import { getUnwrappedFieldType } from "./private/field-wrapper.js";
16
16
  import { scalarDefaultValue } from "./private/scalars.js";
17
17
  import { reifyWkt } from "./private/reify-wkt.js";
@@ -22,6 +22,8 @@ export const codegenInfo = {
22
22
  reifyWkt,
23
23
  getUnwrappedFieldType,
24
24
  scalarDefaultValue,
25
+ safeIdentifier,
26
+ safeObjectProperty,
25
27
  // prettier-ignore
26
28
  symbols: {
27
29
  proto2: { typeOnly: false, privateImportPath: "./proto2.js", publicImportPath: packageName },
@@ -138,16 +138,15 @@ export function createRegistryFromDescriptors(input, replaceWkt = true) {
138
138
  const O = this.findMessage(method.output.typeName);
139
139
  assert(I, `message "${method.input.typeName}" for ${method.toString()} not found`);
140
140
  assert(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);
141
- const m = {
141
+ methods[localName(method)] = {
142
142
  name: method.name,
143
- localName: localName(method),
144
143
  I,
145
144
  O,
146
145
  kind: method.methodKind,
147
146
  idempotency: method.idempotency,
148
- options: {},
147
+ // We do not surface options at this time
148
+ // options: {},
149
149
  };
150
- methods[m.localName] = m;
151
150
  }
152
151
  return (services[typeName] = {
153
152
  typeName: desc.typeName,
@@ -11,7 +11,7 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- // @generated by protoc-gen-es v1.1.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v1.2.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
15
  // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
16
16
  /* eslint-disable */
17
17
  import { proto3 } from "../../proto3.js";
@@ -11,7 +11,7 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- // @generated by protoc-gen-es v1.1.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v1.2.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
15
  // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
16
16
  /* eslint-disable */
17
17
  import { proto3 } from "../../proto3.js";
@@ -31,10 +31,12 @@ export function localName(desc) {
31
31
  const pkg = desc.file.proto.package;
32
32
  const offset = pkg === undefined ? 0 : pkg.length + 1;
33
33
  const name = desc.typeName.substring(offset).replace(/\./g, "_");
34
- if (reservedIdent[name]) {
35
- return name + "$";
36
- }
37
- return name;
34
+ // For services, we only care about safe identifiers, not safe object properties,
35
+ // but we have shipped v1 with a bug that respected object properties, and we
36
+ // do not want to introduce a breaking change, so we continue to escape for
37
+ // safe object properties.
38
+ // See https://github.com/bufbuild/protobuf-es/pull/391
39
+ return safeObjectProperty(safeIdentifier(name));
38
40
  }
39
41
  case "enum_value": {
40
42
  const sharedPrefix = desc.parent.sharedPrefix;
@@ -42,10 +44,7 @@ export function localName(desc) {
42
44
  return desc.name;
43
45
  }
44
46
  const name = desc.name.substring(sharedPrefix.length);
45
- if (reservedObjectProperties[name]) {
46
- return name + "$";
47
- }
48
- return name;
47
+ return safeObjectProperty(name);
49
48
  }
50
49
  case "rpc": {
51
50
  let name = desc.name;
@@ -53,10 +52,7 @@ export function localName(desc) {
53
52
  return name;
54
53
  }
55
54
  name = name[0].toLowerCase() + name.substring(1);
56
- if (reservedObjectProperties[name]) {
57
- return name + "$";
58
- }
59
- return name;
55
+ return safeObjectProperty(name);
60
56
  }
61
57
  }
62
58
  }
@@ -64,15 +60,12 @@ export function localName(desc) {
64
60
  * Returns the name of a field in generated code.
65
61
  */
66
62
  export function localFieldName(protoName, inOneof) {
67
- let name = protoCamelCase(protoName);
63
+ const name = protoCamelCase(protoName);
68
64
  if (inOneof) {
69
65
  // oneof member names are not properties, but values of the `case` property.
70
66
  return name;
71
67
  }
72
- if (reservedObjectProperties[name] || reservedMessageProperties[name]) {
73
- name = name + "$";
74
- }
75
- return name;
68
+ return safeObjectProperty(safeMessageProperty(name));
76
69
  }
77
70
  /**
78
71
  * Returns the name of a oneof group in generated code.
@@ -149,91 +142,127 @@ function protoCamelCase(snakeCase) {
149
142
  }
150
143
  return b.join("");
151
144
  }
152
- // Names that cannot be used for identifiers, such as class names,
153
- // but _can_ be used for object properties.
154
- const reservedIdent = {
145
+ /**
146
+ * Names that cannot be used for identifiers, such as class names,
147
+ * but _can_ be used for object properties.
148
+ */
149
+ const reservedIdentifiers = new Set([
155
150
  // ECMAScript 2015 keywords
156
- break: true,
157
- case: true,
158
- catch: true,
159
- class: true,
160
- const: true,
161
- continue: true,
162
- debugger: true,
163
- default: true,
164
- delete: true,
165
- do: true,
166
- else: true,
167
- export: true,
168
- extends: true,
169
- false: true,
170
- finally: true,
171
- for: true,
172
- function: true,
173
- if: true,
174
- import: true,
175
- in: true,
176
- instanceof: true,
177
- new: true,
178
- null: true,
179
- return: true,
180
- super: true,
181
- switch: true,
182
- this: true,
183
- throw: true,
184
- true: true,
185
- try: true,
186
- typeof: true,
187
- var: true,
188
- void: true,
189
- while: true,
190
- with: true,
191
- yield: true,
151
+ "break",
152
+ "case",
153
+ "catch",
154
+ "class",
155
+ "const",
156
+ "continue",
157
+ "debugger",
158
+ "default",
159
+ "delete",
160
+ "do",
161
+ "else",
162
+ "export",
163
+ "extends",
164
+ "false",
165
+ "finally",
166
+ "for",
167
+ "function",
168
+ "if",
169
+ "import",
170
+ "in",
171
+ "instanceof",
172
+ "new",
173
+ "null",
174
+ "return",
175
+ "super",
176
+ "switch",
177
+ "this",
178
+ "throw",
179
+ "true",
180
+ "try",
181
+ "typeof",
182
+ "var",
183
+ "void",
184
+ "while",
185
+ "with",
186
+ "yield",
192
187
  // ECMAScript 2015 future reserved keywords
193
- enum: true,
194
- implements: true,
195
- interface: true,
196
- let: true,
197
- package: true,
198
- private: true,
199
- protected: true,
200
- public: true,
201
- static: true,
188
+ "enum",
189
+ "implements",
190
+ "interface",
191
+ "let",
192
+ "package",
193
+ "private",
194
+ "protected",
195
+ "public",
196
+ "static",
202
197
  // Class name cannot be 'Object' when targeting ES5 with module CommonJS
203
- Object: true,
198
+ "Object",
204
199
  // TypeScript keywords that cannot be used for types (as opposed to variables)
205
- bigint: true,
206
- number: true,
207
- boolean: true,
208
- string: true,
209
- object: true,
200
+ "bigint",
201
+ "number",
202
+ "boolean",
203
+ "string",
204
+ "object",
210
205
  // Identifiers reserved for the runtime, so we can generate legible code
211
- globalThis: true,
212
- Uint8Array: true,
213
- Partial: true,
214
- };
215
- // Names that cannot be used for object properties because they are reserved
216
- // by built-in JavaScript properties.
217
- const reservedObjectProperties = {
206
+ "globalThis",
207
+ "Uint8Array",
208
+ "Partial",
209
+ ]);
210
+ /**
211
+ * Names that cannot be used for object properties because they are reserved
212
+ * by built-in JavaScript properties.
213
+ */
214
+ const reservedObjectProperties = new Set([
218
215
  // names reserved by JavaScript
219
- constructor: true,
220
- toString: true,
221
- toJSON: true,
222
- valueOf: true,
223
- };
224
- // Names that cannot be used for object properties because they are reserved
225
- // by the runtime.
226
- const reservedMessageProperties = {
216
+ "constructor",
217
+ "toString",
218
+ "toJSON",
219
+ "valueOf",
220
+ ]);
221
+ /**
222
+ * Names that cannot be used for object properties because they are reserved
223
+ * by the runtime.
224
+ */
225
+ const reservedMessageProperties = new Set([
227
226
  // names reserved by the runtime
228
- getType: true,
229
- clone: true,
230
- equals: true,
231
- fromBinary: true,
232
- fromJson: true,
233
- fromJsonString: true,
234
- toBinary: true,
235
- toJson: true,
236
- toJsonString: true,
227
+ "getType",
228
+ "clone",
229
+ "equals",
230
+ "fromBinary",
231
+ "fromJson",
232
+ "fromJsonString",
233
+ "toBinary",
234
+ "toJson",
235
+ "toJsonString",
237
236
  // names reserved by the runtime for the future
238
- toObject: true,
237
+ "toObject",
238
+ ]);
239
+ const fallback = (name) => `${name}$`;
240
+ /**
241
+ * Will wrap names that are Object prototype properties or names reserved
242
+ * for `Message`s.
243
+ */
244
+ const safeMessageProperty = (name) => {
245
+ if (reservedMessageProperties.has(name)) {
246
+ return fallback(name);
247
+ }
248
+ return name;
249
+ };
250
+ /**
251
+ * Names that cannot be used for object properties because they are reserved
252
+ * by built-in JavaScript properties.
253
+ */
254
+ export const safeObjectProperty = (name) => {
255
+ if (reservedObjectProperties.has(name)) {
256
+ return fallback(name);
257
+ }
258
+ return name;
259
+ };
260
+ /**
261
+ * Names that can be used for identifiers or class properties
262
+ */
263
+ export const safeIdentifier = (name) => {
264
+ if (reservedIdentifiers.has(name)) {
265
+ return fallback(name);
266
+ }
267
+ return name;
239
268
  };
@@ -122,18 +122,18 @@ export function makeUtilCommon() {
122
122
  if (va.case !== vb.case) {
123
123
  return false;
124
124
  }
125
- const k = va.case, s = m.findField(k);
125
+ const s = m.findField(va.case);
126
126
  if (s === undefined) {
127
127
  return true;
128
128
  }
129
129
  // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- oneof fields are never "map"
130
130
  switch (s.kind) {
131
131
  case "message":
132
- return s.T.equals(va[k], vb[k]);
132
+ return s.T.equals(va.value, vb.value);
133
133
  case "enum":
134
- return scalarEquals(ScalarType.INT32, va, vb);
134
+ return scalarEquals(ScalarType.INT32, va.value, vb.value);
135
135
  case "scalar":
136
- return scalarEquals(s.T, va, vb);
136
+ return scalarEquals(s.T, va.value, vb.value);
137
137
  }
138
138
  throw new Error(`oneof cannot contain ${s.kind}`);
139
139
  case "map":
@@ -36,8 +36,6 @@ export const protoBase64 = {
36
36
  dec(base64Str) {
37
37
  // estimate byte size, not accounting for inner padding and whitespace
38
38
  let es = (base64Str.length * 3) / 4;
39
- // if (es % 3 !== 0)
40
- // throw new Error("invalid base64 string");
41
39
  if (base64Str[base64Str.length - 2] == "=")
42
40
  es -= 2;
43
41
  else if (base64Str[base64Str.length - 1] == "=")
@@ -1,4 +1,4 @@
1
- import { localName } from "./private/names.js";
1
+ import { localName, safeIdentifier, safeObjectProperty } from "./private/names.js";
2
2
  import { getUnwrappedFieldType } from "./private/field-wrapper.js";
3
3
  import { scalarDefaultValue } from "./private/scalars.js";
4
4
  import { reifyWkt } from "./private/reify-wkt.js";
@@ -10,6 +10,8 @@ interface CodegenInfo {
10
10
  readonly wktSourceFiles: readonly string[];
11
11
  readonly scalarDefaultValue: typeof scalarDefaultValue;
12
12
  readonly reifyWkt: typeof reifyWkt;
13
+ readonly safeIdentifier: typeof safeIdentifier;
14
+ readonly safeObjectProperty: typeof safeObjectProperty;
13
15
  }
14
16
  type RuntimeSymbolName = "proto2" | "proto3" | "Message" | "PartialMessage" | "PlainMessage" | "FieldList" | "MessageType" | "BinaryReadOptions" | "BinaryWriteOptions" | "JsonReadOptions" | "JsonWriteOptions" | "JsonValue" | "JsonObject" | "protoInt64" | "ScalarType" | "MethodKind" | "MethodIdempotency" | "IMessageTypeRegistry";
15
17
  type RuntimeSymbolInfo = {
@@ -31,4 +31,13 @@ export declare function findEnumSharedPrefix(enumName: string, valueNames: strin
31
31
  * used by protoc to convert a field name to a JSON name.
32
32
  */
33
33
  declare function protoCamelCase(snakeCase: string): string;
34
+ /**
35
+ * Names that cannot be used for object properties because they are reserved
36
+ * by built-in JavaScript properties.
37
+ */
38
+ export declare const safeObjectProperty: (name: string) => string;
39
+ /**
40
+ * Names that can be used for identifiers or class properties
41
+ */
42
+ export declare const safeIdentifier: (name: string) => string;
34
43
  export {};
@@ -21,8 +21,6 @@ export interface ServiceType {
21
21
  * call. All methods provide the following properties:
22
22
  *
23
23
  * - "name": The original name of the protobuf rpc.
24
- * - "localName": A variation of the name that follows the lowerCamelCase
25
- * naming convention in ECMAScript.
26
24
  * - "I": The input message type.
27
25
  * - "O": The output message type.
28
26
  * - "kind": The method type.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "license": "(Apache-2.0 AND BSD-3-Clause)",
5
5
  "description": "A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.",
6
6
  "repository": {
@@ -24,6 +24,6 @@
24
24
  "types": "./dist/types/index.d.ts"
25
25
  },
26
26
  "files": [
27
- "dist/**/"
27
+ "dist/**"
28
28
  ]
29
29
  }