@bufbuild/protobuf 1.1.1 → 1.2.1
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/google/protobuf/any_pb.js +4 -4
- package/dist/cjs/google/protobuf/api_pb.js +4 -4
- package/dist/cjs/google/protobuf/compiler/plugin_pb.js +4 -4
- package/dist/cjs/google/protobuf/descriptor_pb.js +106 -28
- package/dist/cjs/google/protobuf/duration_pb.js +1 -1
- package/dist/cjs/google/protobuf/empty_pb.js +1 -1
- package/dist/cjs/google/protobuf/field_mask_pb.js +2 -2
- package/dist/cjs/google/protobuf/source_context_pb.js +1 -1
- package/dist/cjs/google/protobuf/struct_pb.js +5 -5
- package/dist/cjs/google/protobuf/timestamp_pb.js +2 -2
- package/dist/cjs/google/protobuf/type_pb.js +27 -6
- package/dist/cjs/google/protobuf/wrappers_pb.js +9 -9
- package/dist/cjs/index.js +0 -3
- package/dist/cjs/private/binary-format-common.js +44 -6
- package/dist/cjs/private/names.js +128 -97
- package/dist/cjs/proto-base64.js +2 -10
- package/dist/esm/codegen-info.js +3 -1
- package/dist/esm/create-descriptor-set.js +1 -1
- package/dist/esm/google/protobuf/any_pb.js +5 -4
- package/dist/esm/google/protobuf/api_pb.js +7 -4
- package/dist/esm/google/protobuf/compiler/plugin_pb.js +8 -4
- package/dist/esm/google/protobuf/descriptor_pb.js +132 -27
- package/dist/esm/google/protobuf/duration_pb.js +2 -1
- package/dist/esm/google/protobuf/empty_pb.js +2 -1
- package/dist/esm/google/protobuf/field_mask_pb.js +3 -2
- package/dist/esm/google/protobuf/source_context_pb.js +2 -1
- package/dist/esm/google/protobuf/struct_pb.js +8 -5
- package/dist/esm/google/protobuf/timestamp_pb.js +3 -2
- package/dist/esm/google/protobuf/type_pb.js +32 -6
- package/dist/esm/google/protobuf/wrappers_pb.js +18 -9
- package/dist/esm/index.js +1 -4
- package/dist/esm/private/binary-format-common.js +45 -7
- package/dist/esm/private/message-type.js +1 -1
- package/dist/esm/private/names.js +125 -96
- package/dist/esm/private/util-common.js +1 -1
- package/dist/esm/proto-base64.js +2 -10
- package/dist/types/codegen-info.d.ts +3 -1
- package/dist/types/google/protobuf/any_pb.d.ts +3 -3
- package/dist/types/google/protobuf/api_pb.d.ts +1 -1
- package/dist/types/google/protobuf/descriptor_pb.d.ts +107 -3
- package/dist/types/google/protobuf/struct_pb.d.ts +1 -1
- package/dist/types/google/protobuf/timestamp_pb.d.ts +1 -1
- package/dist/types/google/protobuf/type_pb.d.ts +19 -1
- package/dist/types/index.d.ts +5 -4
- package/dist/types/private/binary-format-common.d.ts +3 -2
- package/dist/types/private/json-format-common.d.ts +2 -1
- package/dist/types/private/message-type.d.ts +2 -1
- package/dist/types/private/names.d.ts +9 -0
- package/dist/types/private/scalars.d.ts +2 -1
- package/dist/types/proto-base64.d.ts +1 -9
- package/package.json +2 -2
|
@@ -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.1 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";
|
|
@@ -37,18 +37,25 @@ export var Syntax;
|
|
|
37
37
|
* @generated from enum value: SYNTAX_PROTO3 = 1;
|
|
38
38
|
*/
|
|
39
39
|
Syntax[Syntax["PROTO3"] = 1] = "PROTO3";
|
|
40
|
+
/**
|
|
41
|
+
* Syntax `editions`.
|
|
42
|
+
*
|
|
43
|
+
* @generated from enum value: SYNTAX_EDITIONS = 2;
|
|
44
|
+
*/
|
|
45
|
+
Syntax[Syntax["EDITIONS"] = 2] = "EDITIONS";
|
|
40
46
|
})(Syntax || (Syntax = {}));
|
|
41
47
|
// Retrieve enum metadata with: proto3.getEnumType(Syntax)
|
|
42
48
|
proto3.util.setEnumType(Syntax, "google.protobuf.Syntax", [
|
|
43
49
|
{ no: 0, name: "SYNTAX_PROTO2" },
|
|
44
50
|
{ no: 1, name: "SYNTAX_PROTO3" },
|
|
51
|
+
{ no: 2, name: "SYNTAX_EDITIONS" },
|
|
45
52
|
]);
|
|
46
53
|
/**
|
|
47
54
|
* A protocol buffer message type.
|
|
48
55
|
*
|
|
49
56
|
* @generated from message google.protobuf.Type
|
|
50
57
|
*/
|
|
51
|
-
|
|
58
|
+
class Type extends Message {
|
|
52
59
|
constructor(data) {
|
|
53
60
|
super();
|
|
54
61
|
/**
|
|
@@ -81,6 +88,12 @@ export class Type extends Message {
|
|
|
81
88
|
* @generated from field: google.protobuf.Syntax syntax = 6;
|
|
82
89
|
*/
|
|
83
90
|
this.syntax = Syntax.PROTO2;
|
|
91
|
+
/**
|
|
92
|
+
* The source edition string, only valid when syntax is SYNTAX_EDITIONS.
|
|
93
|
+
*
|
|
94
|
+
* @generated from field: string edition = 7;
|
|
95
|
+
*/
|
|
96
|
+
this.edition = "";
|
|
84
97
|
proto3.util.initPartial(data, this);
|
|
85
98
|
}
|
|
86
99
|
static fromBinary(bytes, options) {
|
|
@@ -105,13 +118,15 @@ Type.fields = proto3.util.newFieldList(() => [
|
|
|
105
118
|
{ no: 4, name: "options", kind: "message", T: Option, repeated: true },
|
|
106
119
|
{ no: 5, name: "source_context", kind: "message", T: SourceContext },
|
|
107
120
|
{ no: 6, name: "syntax", kind: "enum", T: proto3.getEnumType(Syntax) },
|
|
121
|
+
{ no: 7, name: "edition", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
|
108
122
|
]);
|
|
123
|
+
export { Type };
|
|
109
124
|
/**
|
|
110
125
|
* A single field of a message type.
|
|
111
126
|
*
|
|
112
127
|
* @generated from message google.protobuf.Field
|
|
113
128
|
*/
|
|
114
|
-
|
|
129
|
+
class Field extends Message {
|
|
115
130
|
constructor(data) {
|
|
116
131
|
super();
|
|
117
132
|
/**
|
|
@@ -205,6 +220,7 @@ Field.fields = proto3.util.newFieldList(() => [
|
|
|
205
220
|
{ no: 10, name: "json_name", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
|
206
221
|
{ no: 11, name: "default_value", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
|
207
222
|
]);
|
|
223
|
+
export { Field };
|
|
208
224
|
/**
|
|
209
225
|
* Basic field types.
|
|
210
226
|
*
|
|
@@ -393,7 +409,7 @@ proto3.util.setEnumType(Field_Cardinality, "google.protobuf.Field.Cardinality",
|
|
|
393
409
|
*
|
|
394
410
|
* @generated from message google.protobuf.Enum
|
|
395
411
|
*/
|
|
396
|
-
|
|
412
|
+
class Enum extends Message {
|
|
397
413
|
constructor(data) {
|
|
398
414
|
super();
|
|
399
415
|
/**
|
|
@@ -420,6 +436,12 @@ export class Enum extends Message {
|
|
|
420
436
|
* @generated from field: google.protobuf.Syntax syntax = 5;
|
|
421
437
|
*/
|
|
422
438
|
this.syntax = Syntax.PROTO2;
|
|
439
|
+
/**
|
|
440
|
+
* The source edition string, only valid when syntax is SYNTAX_EDITIONS.
|
|
441
|
+
*
|
|
442
|
+
* @generated from field: string edition = 6;
|
|
443
|
+
*/
|
|
444
|
+
this.edition = "";
|
|
423
445
|
proto3.util.initPartial(data, this);
|
|
424
446
|
}
|
|
425
447
|
static fromBinary(bytes, options) {
|
|
@@ -443,13 +465,15 @@ Enum.fields = proto3.util.newFieldList(() => [
|
|
|
443
465
|
{ no: 3, name: "options", kind: "message", T: Option, repeated: true },
|
|
444
466
|
{ no: 4, name: "source_context", kind: "message", T: SourceContext },
|
|
445
467
|
{ no: 5, name: "syntax", kind: "enum", T: proto3.getEnumType(Syntax) },
|
|
468
|
+
{ no: 6, name: "edition", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
|
446
469
|
]);
|
|
470
|
+
export { Enum };
|
|
447
471
|
/**
|
|
448
472
|
* Enum value definition.
|
|
449
473
|
*
|
|
450
474
|
* @generated from message google.protobuf.EnumValue
|
|
451
475
|
*/
|
|
452
|
-
|
|
476
|
+
class EnumValue extends Message {
|
|
453
477
|
constructor(data) {
|
|
454
478
|
super();
|
|
455
479
|
/**
|
|
@@ -492,13 +516,14 @@ EnumValue.fields = proto3.util.newFieldList(() => [
|
|
|
492
516
|
{ no: 2, name: "number", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
|
|
493
517
|
{ no: 3, name: "options", kind: "message", T: Option, repeated: true },
|
|
494
518
|
]);
|
|
519
|
+
export { EnumValue };
|
|
495
520
|
/**
|
|
496
521
|
* A protocol buffer option, which can be attached to a message, field,
|
|
497
522
|
* enumeration, etc.
|
|
498
523
|
*
|
|
499
524
|
* @generated from message google.protobuf.Option
|
|
500
525
|
*/
|
|
501
|
-
|
|
526
|
+
class Option extends Message {
|
|
502
527
|
constructor(data) {
|
|
503
528
|
super();
|
|
504
529
|
/**
|
|
@@ -531,3 +556,4 @@ Option.fields = proto3.util.newFieldList(() => [
|
|
|
531
556
|
{ no: 1, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
|
532
557
|
{ no: 2, name: "value", kind: "message", T: Any },
|
|
533
558
|
]);
|
|
559
|
+
export { Option };
|
|
@@ -22,7 +22,7 @@ import { protoInt64 } from "../../proto-int64.js";
|
|
|
22
22
|
*
|
|
23
23
|
* @generated from message google.protobuf.DoubleValue
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
class DoubleValue extends Message {
|
|
26
26
|
constructor(data) {
|
|
27
27
|
super();
|
|
28
28
|
/**
|
|
@@ -75,6 +75,7 @@ DoubleValue.fieldWrapper = {
|
|
|
75
75
|
return value.value;
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
|
+
export { DoubleValue };
|
|
78
79
|
/**
|
|
79
80
|
* Wrapper message for `float`.
|
|
80
81
|
*
|
|
@@ -82,7 +83,7 @@ DoubleValue.fieldWrapper = {
|
|
|
82
83
|
*
|
|
83
84
|
* @generated from message google.protobuf.FloatValue
|
|
84
85
|
*/
|
|
85
|
-
|
|
86
|
+
class FloatValue extends Message {
|
|
86
87
|
constructor(data) {
|
|
87
88
|
super();
|
|
88
89
|
/**
|
|
@@ -135,6 +136,7 @@ FloatValue.fieldWrapper = {
|
|
|
135
136
|
return value.value;
|
|
136
137
|
}
|
|
137
138
|
};
|
|
139
|
+
export { FloatValue };
|
|
138
140
|
/**
|
|
139
141
|
* Wrapper message for `int64`.
|
|
140
142
|
*
|
|
@@ -142,7 +144,7 @@ FloatValue.fieldWrapper = {
|
|
|
142
144
|
*
|
|
143
145
|
* @generated from message google.protobuf.Int64Value
|
|
144
146
|
*/
|
|
145
|
-
|
|
147
|
+
class Int64Value extends Message {
|
|
146
148
|
constructor(data) {
|
|
147
149
|
super();
|
|
148
150
|
/**
|
|
@@ -195,6 +197,7 @@ Int64Value.fieldWrapper = {
|
|
|
195
197
|
return value.value;
|
|
196
198
|
}
|
|
197
199
|
};
|
|
200
|
+
export { Int64Value };
|
|
198
201
|
/**
|
|
199
202
|
* Wrapper message for `uint64`.
|
|
200
203
|
*
|
|
@@ -202,7 +205,7 @@ Int64Value.fieldWrapper = {
|
|
|
202
205
|
*
|
|
203
206
|
* @generated from message google.protobuf.UInt64Value
|
|
204
207
|
*/
|
|
205
|
-
|
|
208
|
+
class UInt64Value extends Message {
|
|
206
209
|
constructor(data) {
|
|
207
210
|
super();
|
|
208
211
|
/**
|
|
@@ -255,6 +258,7 @@ UInt64Value.fieldWrapper = {
|
|
|
255
258
|
return value.value;
|
|
256
259
|
}
|
|
257
260
|
};
|
|
261
|
+
export { UInt64Value };
|
|
258
262
|
/**
|
|
259
263
|
* Wrapper message for `int32`.
|
|
260
264
|
*
|
|
@@ -262,7 +266,7 @@ UInt64Value.fieldWrapper = {
|
|
|
262
266
|
*
|
|
263
267
|
* @generated from message google.protobuf.Int32Value
|
|
264
268
|
*/
|
|
265
|
-
|
|
269
|
+
class Int32Value extends Message {
|
|
266
270
|
constructor(data) {
|
|
267
271
|
super();
|
|
268
272
|
/**
|
|
@@ -315,6 +319,7 @@ Int32Value.fieldWrapper = {
|
|
|
315
319
|
return value.value;
|
|
316
320
|
}
|
|
317
321
|
};
|
|
322
|
+
export { Int32Value };
|
|
318
323
|
/**
|
|
319
324
|
* Wrapper message for `uint32`.
|
|
320
325
|
*
|
|
@@ -322,7 +327,7 @@ Int32Value.fieldWrapper = {
|
|
|
322
327
|
*
|
|
323
328
|
* @generated from message google.protobuf.UInt32Value
|
|
324
329
|
*/
|
|
325
|
-
|
|
330
|
+
class UInt32Value extends Message {
|
|
326
331
|
constructor(data) {
|
|
327
332
|
super();
|
|
328
333
|
/**
|
|
@@ -375,6 +380,7 @@ UInt32Value.fieldWrapper = {
|
|
|
375
380
|
return value.value;
|
|
376
381
|
}
|
|
377
382
|
};
|
|
383
|
+
export { UInt32Value };
|
|
378
384
|
/**
|
|
379
385
|
* Wrapper message for `bool`.
|
|
380
386
|
*
|
|
@@ -382,7 +388,7 @@ UInt32Value.fieldWrapper = {
|
|
|
382
388
|
*
|
|
383
389
|
* @generated from message google.protobuf.BoolValue
|
|
384
390
|
*/
|
|
385
|
-
|
|
391
|
+
class BoolValue extends Message {
|
|
386
392
|
constructor(data) {
|
|
387
393
|
super();
|
|
388
394
|
/**
|
|
@@ -435,6 +441,7 @@ BoolValue.fieldWrapper = {
|
|
|
435
441
|
return value.value;
|
|
436
442
|
}
|
|
437
443
|
};
|
|
444
|
+
export { BoolValue };
|
|
438
445
|
/**
|
|
439
446
|
* Wrapper message for `string`.
|
|
440
447
|
*
|
|
@@ -442,7 +449,7 @@ BoolValue.fieldWrapper = {
|
|
|
442
449
|
*
|
|
443
450
|
* @generated from message google.protobuf.StringValue
|
|
444
451
|
*/
|
|
445
|
-
|
|
452
|
+
class StringValue extends Message {
|
|
446
453
|
constructor(data) {
|
|
447
454
|
super();
|
|
448
455
|
/**
|
|
@@ -495,6 +502,7 @@ StringValue.fieldWrapper = {
|
|
|
495
502
|
return value.value;
|
|
496
503
|
}
|
|
497
504
|
};
|
|
505
|
+
export { StringValue };
|
|
498
506
|
/**
|
|
499
507
|
* Wrapper message for `bytes`.
|
|
500
508
|
*
|
|
@@ -502,7 +510,7 @@ StringValue.fieldWrapper = {
|
|
|
502
510
|
*
|
|
503
511
|
* @generated from message google.protobuf.BytesValue
|
|
504
512
|
*/
|
|
505
|
-
|
|
513
|
+
class BytesValue extends Message {
|
|
506
514
|
constructor(data) {
|
|
507
515
|
super();
|
|
508
516
|
/**
|
|
@@ -555,3 +563,4 @@ BytesValue.fieldWrapper = {
|
|
|
555
563
|
return value.value;
|
|
556
564
|
}
|
|
557
565
|
};
|
|
566
|
+
export { BytesValue };
|
package/dist/esm/index.js
CHANGED
|
@@ -17,14 +17,11 @@ export { protoInt64 } from "./proto-int64.js";
|
|
|
17
17
|
export { protoBase64 } from "./proto-base64.js";
|
|
18
18
|
export { protoDelimited } from "./proto-delimited.js";
|
|
19
19
|
export { codegenInfo } from "./codegen-info.js";
|
|
20
|
-
export { Message
|
|
20
|
+
export { Message } from "./message.js";
|
|
21
21
|
export { ScalarType } from "./field.js";
|
|
22
22
|
export { MethodKind, MethodIdempotency } from "./service-type.js";
|
|
23
23
|
export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
|
|
24
|
-
export {} from "./json-format.js";
|
|
25
|
-
export {} from "./descriptor-set.js";
|
|
26
24
|
export { createDescriptorSet } from "./create-descriptor-set.js";
|
|
27
|
-
export {} from "./type-registry.js";
|
|
28
25
|
export { createRegistry } from "./create-registry.js";
|
|
29
26
|
export { createRegistryFromDescriptors } from "./create-registry-from-desc.js";
|
|
30
27
|
// ideally, we would export these types with sub-path exports:
|
|
@@ -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 { BinaryReader, BinaryWriter, WireType
|
|
14
|
+
import { BinaryReader, BinaryWriter, WireType } from "../binary-encoding.js";
|
|
15
15
|
import { Message } from "../message.js";
|
|
16
16
|
import { ScalarType } from "../field.js";
|
|
17
17
|
import { wrapField } from "./field-wrapper.js";
|
|
@@ -109,14 +109,14 @@ export function makeBinaryFormatCommon() {
|
|
|
109
109
|
const messageType = field.T;
|
|
110
110
|
if (repeated) {
|
|
111
111
|
// safe to assume presence of array, oneof cannot contain repeated values
|
|
112
|
-
target[localName].push(
|
|
112
|
+
target[localName].push(readMessageField(reader, new messageType(), options));
|
|
113
113
|
}
|
|
114
114
|
else {
|
|
115
115
|
if (target[localName] instanceof Message) {
|
|
116
|
-
target[localName]
|
|
116
|
+
readMessageField(reader, target[localName], options);
|
|
117
117
|
}
|
|
118
118
|
else {
|
|
119
|
-
target[localName] =
|
|
119
|
+
target[localName] = readMessageField(reader, new messageType(), options);
|
|
120
120
|
if (messageType.fieldWrapper &&
|
|
121
121
|
!field.oneof &&
|
|
122
122
|
!field.repeated) {
|
|
@@ -135,6 +135,13 @@ export function makeBinaryFormatCommon() {
|
|
|
135
135
|
},
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
|
+
// Read a message, avoiding MessageType.fromBinary() to re-use the
|
|
139
|
+
// BinaryReadOptions and the IBinaryReader.
|
|
140
|
+
function readMessageField(reader, message, options) {
|
|
141
|
+
const format = message.getType().runtime.bin;
|
|
142
|
+
format.readMessage(message, reader, reader.uint32(), options);
|
|
143
|
+
return message;
|
|
144
|
+
}
|
|
138
145
|
// Read a map field, expecting key field = 1, value field = 2
|
|
139
146
|
function readMapEntry(field, reader, options) {
|
|
140
147
|
const length = reader.uint32(), end = reader.pos + length;
|
|
@@ -154,7 +161,7 @@ function readMapEntry(field, reader, options) {
|
|
|
154
161
|
val = reader.int32();
|
|
155
162
|
break;
|
|
156
163
|
case "message":
|
|
157
|
-
val = field.V.T
|
|
164
|
+
val = readMessageField(reader, new field.V.T(), options);
|
|
158
165
|
break;
|
|
159
166
|
}
|
|
160
167
|
break;
|
|
@@ -185,9 +192,40 @@ function readMapEntry(field, reader, options) {
|
|
|
185
192
|
}
|
|
186
193
|
return [key, val];
|
|
187
194
|
}
|
|
195
|
+
// Does not use scalarTypeInfo() for better performance.
|
|
188
196
|
function readScalar(reader, type) {
|
|
189
|
-
|
|
190
|
-
|
|
197
|
+
switch (type) {
|
|
198
|
+
case ScalarType.STRING:
|
|
199
|
+
return reader.string();
|
|
200
|
+
case ScalarType.BOOL:
|
|
201
|
+
return reader.bool();
|
|
202
|
+
case ScalarType.DOUBLE:
|
|
203
|
+
return reader.double();
|
|
204
|
+
case ScalarType.FLOAT:
|
|
205
|
+
return reader.float();
|
|
206
|
+
case ScalarType.INT32:
|
|
207
|
+
return reader.int32();
|
|
208
|
+
case ScalarType.INT64:
|
|
209
|
+
return reader.int64();
|
|
210
|
+
case ScalarType.UINT64:
|
|
211
|
+
return reader.uint64();
|
|
212
|
+
case ScalarType.FIXED64:
|
|
213
|
+
return reader.fixed64();
|
|
214
|
+
case ScalarType.BYTES:
|
|
215
|
+
return reader.bytes();
|
|
216
|
+
case ScalarType.FIXED32:
|
|
217
|
+
return reader.fixed32();
|
|
218
|
+
case ScalarType.SFIXED32:
|
|
219
|
+
return reader.sfixed32();
|
|
220
|
+
case ScalarType.SFIXED64:
|
|
221
|
+
return reader.sfixed64();
|
|
222
|
+
case ScalarType.SINT64:
|
|
223
|
+
return reader.sint64();
|
|
224
|
+
case ScalarType.UINT32:
|
|
225
|
+
return reader.uint32();
|
|
226
|
+
case ScalarType.SINT32:
|
|
227
|
+
return reader.sint32();
|
|
228
|
+
}
|
|
191
229
|
}
|
|
192
230
|
export function writeMapEntry(writer, options, field, key, value) {
|
|
193
231
|
writer.tag(field.no, WireType.LengthDelimited);
|
|
@@ -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 { Message
|
|
14
|
+
import { Message } from "../message.js";
|
|
15
15
|
/**
|
|
16
16
|
* Create a new message type using the given runtime.
|
|
17
17
|
*/
|
|
@@ -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
|
};
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
import { setEnumType } from "./enum.js";
|
|
15
|
-
import { Message
|
|
15
|
+
import { Message } from "../message.js";
|
|
16
16
|
import { ScalarType } from "../field.js";
|
|
17
17
|
import { scalarEquals } from "./scalars.js";
|
|
18
18
|
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-argument,no-case-declarations */
|