@bufbuild/protobuf 0.0.1-alpha.1 → 0.0.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.
Files changed (127) hide show
  1. package/README.md +21 -1
  2. package/dist/cjs/binary-encoding.js +402 -410
  3. package/dist/cjs/descriptor-registry.js +407 -449
  4. package/dist/cjs/descriptor-set.js +416 -513
  5. package/dist/cjs/field.js +30 -30
  6. package/dist/cjs/google/protobuf/any_pb.js +122 -140
  7. package/dist/cjs/google/protobuf/api_pb.js +177 -224
  8. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +125 -227
  9. package/dist/cjs/google/protobuf/descriptor_pb.js +1029 -1888
  10. package/dist/cjs/google/protobuf/duration_pb.js +72 -88
  11. package/dist/cjs/google/protobuf/empty_pb.js +17 -17
  12. package/dist/cjs/google/protobuf/field_mask_pb.js +77 -94
  13. package/dist/cjs/google/protobuf/source_context_pb.js +25 -25
  14. package/dist/cjs/google/protobuf/struct_pb.js +144 -181
  15. package/dist/cjs/google/protobuf/timestamp_pb.js +86 -123
  16. package/dist/cjs/google/protobuf/type_pb.js +406 -462
  17. package/dist/cjs/google/protobuf/wrappers_pb.js +407 -470
  18. package/dist/cjs/index.js +24 -122
  19. package/dist/cjs/message.js +81 -89
  20. package/dist/cjs/private/assert.js +20 -26
  21. package/dist/cjs/private/base64.js +79 -78
  22. package/dist/cjs/private/binary-format-common.js +195 -208
  23. package/dist/cjs/private/binary-format-proto2.js +75 -109
  24. package/dist/cjs/private/binary-format-proto3.js +57 -90
  25. package/dist/cjs/private/enum.js +38 -43
  26. package/dist/cjs/private/field-list.js +51 -50
  27. package/dist/cjs/private/field-wrapper.js +8 -10
  28. package/dist/cjs/private/field.js +22 -25
  29. package/dist/cjs/private/goog-varint.js +275 -0
  30. package/dist/cjs/private/json-format-common.js +414 -440
  31. package/dist/cjs/private/json-format-proto2.js +78 -89
  32. package/dist/cjs/private/json-format-proto3.js +69 -93
  33. package/dist/cjs/private/message-type.js +26 -27
  34. package/dist/cjs/private/names.js +58 -62
  35. package/dist/cjs/private/proto-runtime.js +11 -16
  36. package/dist/cjs/private/scalars.js +100 -103
  37. package/dist/cjs/private/util-common.js +180 -210
  38. package/dist/cjs/proto-int64.js +111 -112
  39. package/dist/cjs/proto2.js +50 -63
  40. package/dist/cjs/proto3.js +61 -74
  41. package/dist/cjs/service-type.js +14 -17
  42. package/dist/cjs/type-registry.js +33 -31
  43. package/dist/esm/binary-encoding.js +401 -414
  44. package/dist/esm/descriptor-registry.js +409 -458
  45. package/dist/esm/descriptor-set.js +417 -478
  46. package/dist/esm/field.js +29 -29
  47. package/dist/esm/google/protobuf/any_pb.js +122 -140
  48. package/dist/esm/google/protobuf/api_pb.js +177 -197
  49. package/dist/esm/google/protobuf/compiler/plugin_pb.js +123 -216
  50. package/dist/esm/google/protobuf/descriptor_pb.js +1013 -1804
  51. package/dist/esm/google/protobuf/duration_pb.js +72 -88
  52. package/dist/esm/google/protobuf/empty_pb.js +17 -17
  53. package/dist/esm/google/protobuf/field_mask_pb.js +77 -94
  54. package/dist/esm/google/protobuf/source_context_pb.js +25 -25
  55. package/dist/esm/google/protobuf/struct_pb.js +143 -180
  56. package/dist/esm/google/protobuf/timestamp_pb.js +86 -123
  57. package/dist/esm/google/protobuf/type_pb.js +401 -421
  58. package/dist/esm/google/protobuf/wrappers_pb.js +406 -397
  59. package/dist/esm/index.js +1 -1
  60. package/dist/esm/message.js +81 -89
  61. package/dist/esm/private/assert.js +19 -21
  62. package/dist/esm/private/base64.js +79 -78
  63. package/dist/esm/private/binary-format-common.js +196 -207
  64. package/dist/esm/private/binary-format-proto2.js +76 -81
  65. package/dist/esm/private/binary-format-proto3.js +58 -67
  66. package/dist/esm/private/enum.js +38 -43
  67. package/dist/esm/private/field-list.js +51 -50
  68. package/dist/esm/private/field-wrapper.js +8 -10
  69. package/dist/esm/private/field.js +22 -22
  70. package/dist/esm/private/goog-varint.js +266 -0
  71. package/dist/esm/private/json-format-common.js +414 -435
  72. package/dist/esm/private/json-format-proto2.js +76 -81
  73. package/dist/esm/private/json-format-proto3.js +66 -80
  74. package/dist/esm/private/message-type.js +27 -28
  75. package/dist/esm/private/names.js +57 -57
  76. package/dist/esm/private/proto-runtime.js +11 -11
  77. package/dist/esm/private/scalars.js +99 -99
  78. package/dist/esm/private/util-common.js +180 -192
  79. package/dist/esm/proto-int64.js +111 -112
  80. package/dist/esm/proto2.js +50 -57
  81. package/dist/esm/proto3.js +61 -68
  82. package/dist/esm/service-type.js +12 -12
  83. package/dist/esm/type-registry.js +33 -31
  84. package/dist/types/binary-encoding.d.ts +398 -398
  85. package/dist/types/binary-format.d.ts +69 -91
  86. package/dist/types/descriptor-registry.d.ts +23 -29
  87. package/dist/types/descriptor-set.d.ts +107 -128
  88. package/dist/types/enum.d.ts +21 -21
  89. package/dist/types/field-list.d.ts +21 -21
  90. package/dist/types/field.d.ts +191 -231
  91. package/dist/types/google/protobuf/any_pb.d.ts +56 -77
  92. package/dist/types/google/protobuf/api_pb.d.ts +144 -187
  93. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +195 -257
  94. package/dist/types/google/protobuf/descriptor_pb.d.ts +1360 -1737
  95. package/dist/types/google/protobuf/duration_pb.d.ts +30 -50
  96. package/dist/types/google/protobuf/empty_pb.d.ts +9 -28
  97. package/dist/types/google/protobuf/field_mask_pb.d.ts +17 -37
  98. package/dist/types/google/protobuf/source_context_pb.d.ts +16 -35
  99. package/dist/types/google/protobuf/struct_pb.d.ts +64 -115
  100. package/dist/types/google/protobuf/timestamp_pb.d.ts +31 -51
  101. package/dist/types/google/protobuf/type_pb.d.ts +355 -422
  102. package/dist/types/google/protobuf/wrappers_pb.d.ts +181 -297
  103. package/dist/types/index.d.ts +4 -27
  104. package/dist/types/json-format.d.ts +70 -89
  105. package/dist/types/message-type.d.ts +38 -46
  106. package/dist/types/message.d.ts +73 -99
  107. package/dist/types/private/assert.d.ts +1 -4
  108. package/dist/types/private/binary-format-common.d.ts +6 -32
  109. package/dist/types/private/enum.d.ts +4 -11
  110. package/dist/types/private/field-list.d.ts +14 -21
  111. package/dist/types/private/field-wrapper.d.ts +5 -11
  112. package/dist/types/private/field.d.ts +12 -12
  113. package/dist/types/{google/varint.d.ts → private/goog-varint.d.ts} +6 -13
  114. package/dist/types/private/json-format-common.d.ts +5 -27
  115. package/dist/types/private/message-type.d.ts +3 -8
  116. package/dist/types/private/names.d.ts +1 -4
  117. package/dist/types/private/options-map.d.ts +1 -1
  118. package/dist/types/private/proto-runtime.d.ts +29 -42
  119. package/dist/types/private/scalars.d.ts +5 -12
  120. package/dist/types/private/util-common.d.ts +1 -4
  121. package/dist/types/private/util.d.ts +29 -41
  122. package/dist/types/proto-int64.d.ts +42 -42
  123. package/dist/types/service-type.d.ts +37 -57
  124. package/dist/types/type-registry.d.ts +13 -15
  125. package/package.json +2 -2
  126. package/dist/cjs/google/varint.js +0 -280
  127. package/dist/esm/google/varint.js +0 -265
@@ -5,98 +5,65 @@ const field_js_1 = require("../field.js");
5
5
  const binary_format_common_js_1 = require("./binary-format-common.js");
6
6
  /* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/strict-boolean-expressions, prefer-const, no-case-declarations */
7
7
  function makeBinaryFormatProto3() {
8
- return {
9
- ...(0, binary_format_common_js_1.makeBinaryFormatCommon)(),
10
- writeMessage(message, writer, options) {
11
- const type = message.getType();
12
- for (const field of type.fields.byNumber()) {
13
- let value, // this will be our field value, whether it is member of a oneof or regular field
14
- repeated = field.repeated,
15
- localName = field.localName;
16
- if (field.oneof) {
17
- const oneof = message[field.oneof.localName];
18
- if (oneof.case !== localName) {
19
- continue; // field is not selected, skip
20
- }
21
- value = oneof.value;
22
- } else {
23
- value = message[localName];
24
- }
25
- switch (field.kind) {
26
- case "scalar":
27
- case "enum":
28
- let scalarType =
29
- field.kind == "enum" ? field_js_1.ScalarType.INT32 : field.T;
30
- if (repeated) {
31
- if (field.packed) {
32
- (0, binary_format_common_js_1.writePacked)(
33
- writer,
34
- scalarType,
35
- field.no,
36
- value
37
- );
38
- } else {
39
- for (const item of value) {
40
- (0, binary_format_common_js_1.writeScalar)(
41
- writer,
42
- scalarType,
43
- field.no,
44
- item,
45
- true
46
- );
8
+ return {
9
+ ...(0, binary_format_common_js_1.makeBinaryFormatCommon)(),
10
+ writeMessage(message, writer, options) {
11
+ const type = message.getType();
12
+ for (const field of type.fields.byNumber()) {
13
+ let value, // this will be our field value, whether it is member of a oneof or regular field
14
+ repeated = field.repeated, localName = field.localName;
15
+ if (field.oneof) {
16
+ const oneof = message[field.oneof.localName];
17
+ if (oneof.case !== localName) {
18
+ continue; // field is not selected, skip
19
+ }
20
+ value = oneof.value;
21
+ }
22
+ else {
23
+ value = message[localName];
24
+ }
25
+ switch (field.kind) {
26
+ case "scalar":
27
+ case "enum":
28
+ let scalarType = field.kind == "enum" ? field_js_1.ScalarType.INT32 : field.T;
29
+ if (repeated) {
30
+ if (field.packed) {
31
+ (0, binary_format_common_js_1.writePacked)(writer, scalarType, field.no, value);
32
+ }
33
+ else {
34
+ for (const item of value) {
35
+ (0, binary_format_common_js_1.writeScalar)(writer, scalarType, field.no, item, true);
36
+ }
37
+ }
38
+ }
39
+ else {
40
+ if (value !== undefined) {
41
+ (0, binary_format_common_js_1.writeScalar)(writer, scalarType, field.no, value, !!field.oneof || field.opt);
42
+ }
43
+ }
44
+ break;
45
+ case "message":
46
+ if (repeated) {
47
+ for (const item of value) {
48
+ (0, binary_format_common_js_1.writeMessageField)(writer, options, field.T, field.no, item);
49
+ }
50
+ }
51
+ else {
52
+ (0, binary_format_common_js_1.writeMessageField)(writer, options, field.T, field.no, value);
53
+ }
54
+ break;
55
+ case "map":
56
+ for (const [key, val] of Object.entries(value)) {
57
+ (0, binary_format_common_js_1.writeMapEntry)(writer, options, field, key, val);
58
+ }
59
+ break;
47
60
  }
48
- }
49
- } else {
50
- if (value !== undefined) {
51
- (0, binary_format_common_js_1.writeScalar)(
52
- writer,
53
- scalarType,
54
- field.no,
55
- value,
56
- !!field.oneof || field.opt
57
- );
58
- }
59
- }
60
- break;
61
- case "message":
62
- if (repeated) {
63
- for (const item of value) {
64
- (0, binary_format_common_js_1.writeMessageField)(
65
- writer,
66
- options,
67
- field.T,
68
- field.no,
69
- item
70
- );
71
- }
72
- } else {
73
- (0, binary_format_common_js_1.writeMessageField)(
74
- writer,
75
- options,
76
- field.T,
77
- field.no,
78
- value
79
- );
80
61
  }
81
- break;
82
- case "map":
83
- for (const [key, val] of Object.entries(value)) {
84
- (0, binary_format_common_js_1.writeMapEntry)(
85
- writer,
86
- options,
87
- field,
88
- key,
89
- val
90
- );
62
+ if (options.writeUnknownFields) {
63
+ this.writeUnknownFields(message, writer);
91
64
  }
92
- break;
93
- }
94
- }
95
- if (options.writeUnknownFields) {
96
- this.writeUnknownFields(message, writer);
97
- }
98
- return writer;
99
- },
100
- };
65
+ return writer;
66
+ },
67
+ };
101
68
  }
102
69
  exports.makeBinaryFormatProto3 = makeBinaryFormatProto3;
@@ -9,26 +9,23 @@ const enumTypeSymbol = Symbol("@bufbuild/protobuf/enum-type");
9
9
  * enum, it raises an error.
10
10
  */
11
11
  function getEnumType(enumObject) {
12
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-explicit-any
13
- const t = enumObject[enumTypeSymbol];
14
- (0, assert_js_1.assert)(t, "missing enum type on enum object");
15
- return t; // eslint-disable-line @typescript-eslint/no-unsafe-return
12
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-explicit-any
13
+ const t = enumObject[enumTypeSymbol];
14
+ (0, assert_js_1.assert)(t, "missing enum type on enum object");
15
+ return t; // eslint-disable-line @typescript-eslint/no-unsafe-return
16
16
  }
17
17
  exports.getEnumType = getEnumType;
18
18
  /**
19
19
  * Sets reflection information on a generated enum.
20
20
  */
21
- function setEnumType(
22
- enumObject,
23
- typeName,
24
- values
25
- // We do not surface options at this time
26
- // opt?: {
27
- // options?: { readonly [extensionName: string]: JsonValue };
28
- // },
21
+ function setEnumType(enumObject, typeName, values
22
+ // We do not surface options at this time
23
+ // opt?: {
24
+ // options?: { readonly [extensionName: string]: JsonValue };
25
+ // },
29
26
  ) {
30
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
31
- enumObject[enumTypeSymbol] = makeEnumType(typeName, values);
27
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
28
+ enumObject[enumTypeSymbol] = makeEnumType(typeName, values);
32
29
  }
33
30
  exports.setEnumType = setEnumType;
34
31
  // We do not surface options at this time
@@ -36,35 +33,33 @@ exports.setEnumType = setEnumType;
36
33
  /**
37
34
  * Create a new EnumType with the given values.
38
35
  */
39
- function makeEnumType(
40
- typeName,
41
- values
42
- // We do not surface options at this time
43
- // opt?: {
44
- // options?: { readonly [extensionName: string]: JsonValue };
45
- // },
36
+ function makeEnumType(typeName, values
37
+ // We do not surface options at this time
38
+ // opt?: {
39
+ // options?: { readonly [extensionName: string]: JsonValue };
40
+ // },
46
41
  ) {
47
- const names = Object.create(null);
48
- const numbers = Object.create(null);
49
- const normalValues = [];
50
- for (const value of values) {
51
- // We do not surface options at this time
52
- // const value: EnumValueInfo = {...v, options: v.options ?? emptyReadonlyObject};
53
- normalValues.push(value);
54
- names[value.name] = value;
55
- numbers[value.no] = value;
56
- }
57
- return {
58
- typeName,
59
- values: normalValues,
60
- // We do not surface options at this time
61
- // options: opt?.options ?? Object.create(null),
62
- findName(name) {
63
- return names[name];
64
- },
65
- findNumber(no) {
66
- return numbers[no];
67
- },
68
- };
42
+ const names = Object.create(null);
43
+ const numbers = Object.create(null);
44
+ const normalValues = [];
45
+ for (const value of values) {
46
+ // We do not surface options at this time
47
+ // const value: EnumValueInfo = {...v, options: v.options ?? emptyReadonlyObject};
48
+ normalValues.push(value);
49
+ names[value.name] = value;
50
+ numbers[value.no] = value;
51
+ }
52
+ return {
53
+ typeName,
54
+ values: normalValues,
55
+ // We do not surface options at this time
56
+ // options: opt?.options ?? Object.create(null),
57
+ findName(name) {
58
+ return names[name];
59
+ },
60
+ findNumber(no) {
61
+ return numbers[no];
62
+ },
63
+ };
69
64
  }
70
65
  exports.makeEnumType = makeEnumType;
@@ -2,61 +2,62 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InternalFieldList = void 0;
4
4
  class InternalFieldList {
5
- constructor(fields, normalizer) {
6
- this._fields = fields;
7
- this._normalizer = normalizer;
8
- }
9
- findJsonName(jsonName) {
10
- if (!this.jsonNames) {
11
- const t = {};
12
- for (const f of this.list()) {
13
- t[f.jsonName] = t[f.name] = f;
14
- }
15
- this.jsonNames = t;
5
+ constructor(fields, normalizer) {
6
+ this._fields = fields;
7
+ this._normalizer = normalizer;
16
8
  }
17
- return this.jsonNames[jsonName];
18
- }
19
- find(fieldNo) {
20
- if (!this.numbers) {
21
- const t = {};
22
- for (const f of this.list()) {
23
- t[f.no] = f;
24
- }
25
- this.numbers = t;
9
+ findJsonName(jsonName) {
10
+ if (!this.jsonNames) {
11
+ const t = {};
12
+ for (const f of this.list()) {
13
+ t[f.jsonName] = t[f.name] = f;
14
+ }
15
+ this.jsonNames = t;
16
+ }
17
+ return this.jsonNames[jsonName];
26
18
  }
27
- return this.numbers[fieldNo];
28
- }
29
- list() {
30
- if (!this.all) {
31
- this.all = this._normalizer(this._fields);
19
+ find(fieldNo) {
20
+ if (!this.numbers) {
21
+ const t = {};
22
+ for (const f of this.list()) {
23
+ t[f.no] = f;
24
+ }
25
+ this.numbers = t;
26
+ }
27
+ return this.numbers[fieldNo];
32
28
  }
33
- return this.all;
34
- }
35
- byNumber() {
36
- if (!this.numbersAsc) {
37
- this.numbersAsc = this.list()
38
- .concat()
39
- .sort((a, b) => a.no - b.no);
29
+ list() {
30
+ if (!this.all) {
31
+ this.all = this._normalizer(this._fields);
32
+ }
33
+ return this.all;
34
+ }
35
+ byNumber() {
36
+ if (!this.numbersAsc) {
37
+ this.numbersAsc = this.list()
38
+ .concat()
39
+ .sort((a, b) => a.no - b.no);
40
+ }
41
+ return this.numbersAsc;
40
42
  }
41
- return this.numbersAsc;
42
- }
43
- byMember() {
44
- if (!this.members) {
45
- this.members = [];
46
- const a = this.members;
47
- let o;
48
- for (const f of this.list()) {
49
- if (f.oneof) {
50
- if (f.oneof !== o) {
51
- o = f.oneof;
52
- a.push(o);
53
- }
54
- } else {
55
- a.push(f);
43
+ byMember() {
44
+ if (!this.members) {
45
+ this.members = [];
46
+ const a = this.members;
47
+ let o;
48
+ for (const f of this.list()) {
49
+ if (f.oneof) {
50
+ if (f.oneof !== o) {
51
+ o = f.oneof;
52
+ a.push(o);
53
+ }
54
+ }
55
+ else {
56
+ a.push(f);
57
+ }
58
+ }
56
59
  }
57
- }
60
+ return this.members;
58
61
  }
59
- return this.members;
60
- }
61
62
  }
62
63
  exports.InternalFieldList = InternalFieldList;
@@ -5,21 +5,19 @@ exports.unwrapField = exports.wrapField = void 0;
5
5
  * Wrap field values whose message type has a wrapper.
6
6
  */
7
7
  function wrapField(type, value) {
8
- if (value instanceof type) {
9
- return value;
10
- }
11
- if (type.fieldWrapper) {
12
- return type.fieldWrapper.wrapField(value);
13
- }
14
- throw new Error(
15
- `cannot unwrap field value, ${type.typeName} does not define a field wrapper`
16
- );
8
+ if (value instanceof type) {
9
+ return value;
10
+ }
11
+ if (type.fieldWrapper) {
12
+ return type.fieldWrapper.wrapField(value);
13
+ }
14
+ throw new Error(`cannot unwrap field value, ${type.typeName} does not define a field wrapper`);
17
15
  }
18
16
  exports.wrapField = wrapField;
19
17
  /**
20
18
  * Unwrap field values whose message type has a wrapper.
21
19
  */
22
20
  function unwrapField(type, value) {
23
- return type.fieldWrapper ? type.fieldWrapper.unwrapField(value) : value;
21
+ return type.fieldWrapper ? type.fieldWrapper.unwrapField(value) : value;
24
22
  }
25
23
  exports.unwrapField = unwrapField;
@@ -4,31 +4,28 @@ exports.InternalOneofInfo = void 0;
4
4
  const names_js_1 = require("./names.js");
5
5
  const assert_js_1 = require("./assert.js");
6
6
  class InternalOneofInfo {
7
- constructor(name) {
8
- this.kind = "oneof";
9
- this.repeated = false;
10
- this.packed = false;
11
- this.opt = false;
12
- this.default = undefined;
13
- this.fields = [];
14
- this.name = name;
15
- this.localName = (0, names_js_1.makeOneofName)(name);
16
- }
17
- addField(field) {
18
- (0, assert_js_1.assert)(
19
- field.oneof === this,
20
- `field ${field.name} not one of ${this.name}`
21
- );
22
- this.fields.push(field);
23
- }
24
- findField(localName) {
25
- if (!this._lookup) {
26
- this._lookup = Object.create(null);
27
- for (let i = 0; i < this.fields.length; i++) {
28
- this._lookup[this.fields[i].localName] = this.fields[i];
29
- }
7
+ constructor(name) {
8
+ this.kind = "oneof";
9
+ this.repeated = false;
10
+ this.packed = false;
11
+ this.opt = false;
12
+ this.default = undefined;
13
+ this.fields = [];
14
+ this.name = name;
15
+ this.localName = (0, names_js_1.makeOneofName)(name);
16
+ }
17
+ addField(field) {
18
+ (0, assert_js_1.assert)(field.oneof === this, `field ${field.name} not one of ${this.name}`);
19
+ this.fields.push(field);
20
+ }
21
+ findField(localName) {
22
+ if (!this._lookup) {
23
+ this._lookup = Object.create(null);
24
+ for (let i = 0; i < this.fields.length; i++) {
25
+ this._lookup[this.fields[i].localName] = this.fields[i];
26
+ }
27
+ }
28
+ return this._lookup[localName];
30
29
  }
31
- return this._lookup[localName];
32
- }
33
30
  }
34
31
  exports.InternalOneofInfo = InternalOneofInfo;