@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.
- package/dist/cjs/codegen-info.js +2 -0
- package/dist/cjs/create-registry-from-desc.js +3 -4
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/private/names.js +128 -97
- package/dist/cjs/private/util-common.js +4 -4
- package/dist/cjs/proto-base64.js +0 -2
- package/dist/esm/codegen-info.js +3 -1
- package/dist/esm/create-registry-from-desc.js +3 -4
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/private/names.js +125 -96
- package/dist/esm/private/util-common.js +4 -4
- package/dist/esm/proto-base64.js +0 -2
- package/dist/types/codegen-info.d.ts +3 -1
- package/dist/types/private/names.d.ts +9 -0
- package/dist/types/service-type.d.ts +0 -2
- package/package.json +2 -2
package/dist/cjs/codegen-info.js
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
|
164
|
-
case
|
|
165
|
-
catch
|
|
166
|
-
class
|
|
167
|
-
const
|
|
168
|
-
continue
|
|
169
|
-
debugger
|
|
170
|
-
default
|
|
171
|
-
delete
|
|
172
|
-
do
|
|
173
|
-
else
|
|
174
|
-
export
|
|
175
|
-
extends
|
|
176
|
-
false
|
|
177
|
-
finally
|
|
178
|
-
for
|
|
179
|
-
function
|
|
180
|
-
if
|
|
181
|
-
import
|
|
182
|
-
in
|
|
183
|
-
instanceof
|
|
184
|
-
new
|
|
185
|
-
null
|
|
186
|
-
return
|
|
187
|
-
super
|
|
188
|
-
switch
|
|
189
|
-
this
|
|
190
|
-
throw
|
|
191
|
-
true
|
|
192
|
-
try
|
|
193
|
-
typeof
|
|
194
|
-
var
|
|
195
|
-
void
|
|
196
|
-
while
|
|
197
|
-
with
|
|
198
|
-
yield
|
|
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
|
|
201
|
-
implements
|
|
202
|
-
interface
|
|
203
|
-
let
|
|
204
|
-
package
|
|
205
|
-
private
|
|
206
|
-
protected
|
|
207
|
-
public
|
|
208
|
-
static
|
|
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
|
|
205
|
+
"Object",
|
|
211
206
|
// TypeScript keywords that cannot be used for types (as opposed to variables)
|
|
212
|
-
bigint
|
|
213
|
-
number
|
|
214
|
-
boolean
|
|
215
|
-
string
|
|
216
|
-
object
|
|
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
|
|
219
|
-
Uint8Array
|
|
220
|
-
Partial
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
|
227
|
-
toString
|
|
228
|
-
toJSON
|
|
229
|
-
valueOf
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
|
236
|
-
clone
|
|
237
|
-
equals
|
|
238
|
-
fromBinary
|
|
239
|
-
fromJson
|
|
240
|
-
fromJsonString
|
|
241
|
-
toBinary
|
|
242
|
-
toJson
|
|
243
|
-
toJsonString
|
|
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
|
|
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
|
|
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
|
|
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":
|
package/dist/cjs/proto-base64.js
CHANGED
|
@@ -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] == "=")
|
package/dist/esm/codegen-info.js
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
|
157
|
-
case
|
|
158
|
-
catch
|
|
159
|
-
class
|
|
160
|
-
const
|
|
161
|
-
continue
|
|
162
|
-
debugger
|
|
163
|
-
default
|
|
164
|
-
delete
|
|
165
|
-
do
|
|
166
|
-
else
|
|
167
|
-
export
|
|
168
|
-
extends
|
|
169
|
-
false
|
|
170
|
-
finally
|
|
171
|
-
for
|
|
172
|
-
function
|
|
173
|
-
if
|
|
174
|
-
import
|
|
175
|
-
in
|
|
176
|
-
instanceof
|
|
177
|
-
new
|
|
178
|
-
null
|
|
179
|
-
return
|
|
180
|
-
super
|
|
181
|
-
switch
|
|
182
|
-
this
|
|
183
|
-
throw
|
|
184
|
-
true
|
|
185
|
-
try
|
|
186
|
-
typeof
|
|
187
|
-
var
|
|
188
|
-
void
|
|
189
|
-
while
|
|
190
|
-
with
|
|
191
|
-
yield
|
|
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
|
|
194
|
-
implements
|
|
195
|
-
interface
|
|
196
|
-
let
|
|
197
|
-
package
|
|
198
|
-
private
|
|
199
|
-
protected
|
|
200
|
-
public
|
|
201
|
-
static
|
|
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
|
|
198
|
+
"Object",
|
|
204
199
|
// TypeScript keywords that cannot be used for types (as opposed to variables)
|
|
205
|
-
bigint
|
|
206
|
-
number
|
|
207
|
-
boolean
|
|
208
|
-
string
|
|
209
|
-
object
|
|
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
|
|
212
|
-
Uint8Array
|
|
213
|
-
Partial
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
|
220
|
-
toString
|
|
221
|
-
toJSON
|
|
222
|
-
valueOf
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
|
229
|
-
clone
|
|
230
|
-
equals
|
|
231
|
-
fromBinary
|
|
232
|
-
fromJson
|
|
233
|
-
fromJsonString
|
|
234
|
-
toBinary
|
|
235
|
-
toJson
|
|
236
|
-
toJsonString
|
|
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
|
|
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
|
|
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
|
|
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":
|
package/dist/esm/proto-base64.js
CHANGED
|
@@ -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.
|
|
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
|
}
|