@aptre/protobuf-es-lite 0.2.7 → 0.2.8

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 (121) hide show
  1. package/.ignore +1 -0
  2. package/README.md +23 -24
  3. package/bin/protoc-gen-es-lite +3 -3
  4. package/dist/binary-encoding.d.ts +420 -0
  5. package/dist/binary-encoding.js +437 -0
  6. package/dist/binary.d.ts +35 -2
  7. package/dist/binary.js +64 -65
  8. package/dist/codegen-info.d.ts +43 -0
  9. package/dist/codegen-info.js +72 -0
  10. package/dist/create-descriptor-set.d.ts +36 -0
  11. package/dist/create-descriptor-set.js +936 -0
  12. package/dist/descriptor-set.d.ts +672 -0
  13. package/dist/{editions.js → descriptor-set.js} +0 -11
  14. package/dist/enum.d.ts +35 -1
  15. package/dist/feature-set.d.ts +19 -0
  16. package/dist/feature-set.js +103 -0
  17. package/dist/field-wrapper.d.ts +7 -3
  18. package/dist/field-wrapper.js +30 -1
  19. package/dist/field.d.ts +8 -19
  20. package/dist/field.js +15 -117
  21. package/dist/google/index.d.ts +9 -0
  22. package/dist/google/index.js +41 -0
  23. package/dist/google/protobuf/any.pb.d.ts +139 -0
  24. package/dist/google/protobuf/any.pb.js +42 -0
  25. package/dist/google/protobuf/api.pb.d.ts +252 -0
  26. package/dist/google/protobuf/api.pb.js +70 -0
  27. package/dist/google/protobuf/compiler/plugin.pb.d.ts +240 -0
  28. package/dist/google/protobuf/compiler/plugin.pb.js +203 -0
  29. package/dist/google/protobuf/descriptor.pb.d.ts +2132 -0
  30. package/dist/google/protobuf/descriptor.pb.js +1080 -0
  31. package/dist/google/protobuf/duration.pb.d.ts +92 -0
  32. package/dist/google/protobuf/duration.pb.js +42 -0
  33. package/dist/google/protobuf/empty.pb.d.ts +18 -0
  34. package/dist/google/protobuf/empty.pb.js +39 -0
  35. package/dist/google/protobuf/source_context.pb.d.ts +21 -0
  36. package/dist/google/protobuf/source_context.pb.js +41 -0
  37. package/dist/google/protobuf/struct.pb.d.ts +121 -0
  38. package/dist/google/protobuf/struct.pb.js +83 -0
  39. package/dist/google/protobuf/timestamp.pb.d.ts +121 -0
  40. package/dist/google/protobuf/timestamp.pb.js +42 -0
  41. package/dist/google/protobuf/type.pb.d.ts +464 -0
  42. package/dist/google/protobuf/type.pb.js +338 -0
  43. package/dist/google/protobuf/wrappers.pb.d.ts +183 -0
  44. package/dist/google/protobuf/wrappers.pb.js +107 -0
  45. package/dist/index.d.ts +8 -3
  46. package/dist/index.js +38 -8
  47. package/dist/is-message.d.ts +10 -2
  48. package/dist/is-message.js +74 -3
  49. package/dist/json.d.ts +68 -1
  50. package/dist/json.js +57 -81
  51. package/dist/message.d.ts +30 -61
  52. package/dist/message.js +61 -20
  53. package/dist/names.d.ts +43 -0
  54. package/dist/names.js +276 -0
  55. package/dist/partial.js +14 -15
  56. package/dist/proto-base64.d.ts +18 -0
  57. package/dist/proto-base64.js +128 -0
  58. package/dist/proto-double.d.ts +5 -0
  59. package/dist/proto-double.js +29 -0
  60. package/dist/proto-int64.d.ts +95 -0
  61. package/dist/proto-int64.js +116 -0
  62. package/dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.d.ts +1 -0
  63. package/dist/{protoc-gen-es-lite-plugin.js → protoc-gen-es-lite/protoc-gen-es-lite-plugin.js} +2 -2
  64. package/dist/{typescript.d.ts → protoc-gen-es-lite/typescript.d.ts} +3 -2
  65. package/dist/{typescript.js → protoc-gen-es-lite/typescript.js} +46 -34
  66. package/dist/protoplugin/create-es-plugin.d.ts +83 -0
  67. package/dist/protoplugin/create-es-plugin.js +119 -0
  68. package/dist/protoplugin/ecmascript/file-preamble.d.ts +2 -0
  69. package/dist/protoplugin/ecmascript/file-preamble.js +74 -0
  70. package/dist/protoplugin/ecmascript/generated-file.d.ts +116 -0
  71. package/dist/protoplugin/ecmascript/generated-file.js +407 -0
  72. package/dist/protoplugin/ecmascript/import-path.d.ts +65 -0
  73. package/dist/protoplugin/ecmascript/import-path.js +156 -0
  74. package/dist/protoplugin/ecmascript/import-symbol.d.ts +39 -0
  75. package/dist/protoplugin/ecmascript/import-symbol.js +37 -0
  76. package/dist/protoplugin/ecmascript/index.d.ts +7 -0
  77. package/dist/protoplugin/ecmascript/index.js +20 -0
  78. package/dist/protoplugin/ecmascript/jsdoc.d.ts +14 -0
  79. package/dist/protoplugin/ecmascript/jsdoc.js +93 -0
  80. package/dist/protoplugin/ecmascript/opaque-printables.d.ts +27 -0
  81. package/dist/protoplugin/ecmascript/opaque-printables.js +15 -0
  82. package/dist/protoplugin/ecmascript/parameter.d.ts +13 -0
  83. package/dist/protoplugin/ecmascript/parameter.js +161 -0
  84. package/dist/protoplugin/ecmascript/reify-wkt.d.ts +100 -0
  85. package/dist/protoplugin/ecmascript/reify-wkt.js +170 -0
  86. package/dist/protoplugin/ecmascript/runtime-imports.d.ts +6 -0
  87. package/dist/protoplugin/ecmascript/runtime-imports.js +28 -0
  88. package/dist/protoplugin/ecmascript/schema.d.ts +43 -0
  89. package/dist/protoplugin/ecmascript/schema.js +73 -0
  90. package/dist/protoplugin/ecmascript/target.d.ts +4 -0
  91. package/dist/protoplugin/ecmascript/target.js +15 -0
  92. package/dist/protoplugin/ecmascript/transpile.d.ts +2 -0
  93. package/dist/protoplugin/ecmascript/transpile.js +149 -0
  94. package/dist/protoplugin/error.d.ts +6 -0
  95. package/dist/protoplugin/error.js +43 -0
  96. package/dist/protoplugin/index.d.ts +8 -0
  97. package/dist/protoplugin/index.js +20 -0
  98. package/dist/protoplugin/plugin.d.ts +18 -0
  99. package/dist/protoplugin/plugin.js +15 -0
  100. package/dist/protoplugin/run-node.d.ts +12 -0
  101. package/dist/protoplugin/run-node.js +83 -0
  102. package/dist/scalar.d.ts +53 -1
  103. package/dist/scalar.js +87 -22
  104. package/dist/service-type.d.ts +95 -0
  105. package/dist/service-type.js +53 -0
  106. package/dist/text-format.d.ts +4 -0
  107. package/dist/text-format.js +189 -0
  108. package/dist/type-registry.d.ts +43 -0
  109. package/dist/type-registry.js +15 -0
  110. package/dist/unknown.d.ts +1 -1
  111. package/dist/util.d.ts +2 -2
  112. package/dist/util.js +46 -44
  113. package/dist/varint.d.ts +70 -0
  114. package/dist/varint.js +324 -0
  115. package/example/example.pb.ts +87 -0
  116. package/example/example.proto +1 -0
  117. package/example/tsconfig.json +8 -2
  118. package/package.json +19 -12
  119. package/tsconfig.json +4 -4
  120. package/dist/editions.d.ts +0 -6
  121. package/dist/protoc-gen-es-lite-plugin.d.ts +0 -1
package/dist/scalar.js CHANGED
@@ -13,8 +13,73 @@
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.isScalarZeroValue = exports.scalarZeroValue = exports.scalarEquals = void 0;
17
- const protobuf_1 = require("@bufbuild/protobuf");
16
+ exports.isScalarZeroValue = exports.scalarZeroValue = exports.scalarEquals = exports.LongType = exports.ScalarType = void 0;
17
+ const proto_int64_js_1 = require("./proto-int64.js");
18
+ /**
19
+ * Scalar value types. This is a subset of field types declared by protobuf
20
+ * enum google.protobuf.FieldDescriptorProto.Type The types GROUP and MESSAGE
21
+ * are omitted, but the numerical values are identical.
22
+ */
23
+ var ScalarType;
24
+ (function (ScalarType) {
25
+ // 0 is reserved for errors.
26
+ // Order is weird for historical reasons.
27
+ ScalarType[ScalarType["DOUBLE"] = 1] = "DOUBLE";
28
+ ScalarType[ScalarType["FLOAT"] = 2] = "FLOAT";
29
+ // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
30
+ // negative values are likely.
31
+ ScalarType[ScalarType["INT64"] = 3] = "INT64";
32
+ ScalarType[ScalarType["UINT64"] = 4] = "UINT64";
33
+ // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
34
+ // negative values are likely.
35
+ ScalarType[ScalarType["INT32"] = 5] = "INT32";
36
+ ScalarType[ScalarType["FIXED64"] = 6] = "FIXED64";
37
+ ScalarType[ScalarType["FIXED32"] = 7] = "FIXED32";
38
+ ScalarType[ScalarType["BOOL"] = 8] = "BOOL";
39
+ ScalarType[ScalarType["STRING"] = 9] = "STRING";
40
+ // Tag-delimited aggregate.
41
+ // Group type is deprecated and not supported in proto3. However, Proto3
42
+ // implementations should still be able to parse the group wire format and
43
+ // treat group fields as unknown fields.
44
+ // TYPE_GROUP = 10,
45
+ // TYPE_MESSAGE = 11, // Length-delimited aggregate.
46
+ // New in version 2.
47
+ ScalarType[ScalarType["BYTES"] = 12] = "BYTES";
48
+ ScalarType[ScalarType["UINT32"] = 13] = "UINT32";
49
+ // TYPE_ENUM = 14,
50
+ ScalarType[ScalarType["SFIXED32"] = 15] = "SFIXED32";
51
+ ScalarType[ScalarType["SFIXED64"] = 16] = "SFIXED64";
52
+ ScalarType[ScalarType["SINT32"] = 17] = "SINT32";
53
+ ScalarType[ScalarType["SINT64"] = 18] = "SINT64";
54
+ })(ScalarType || (exports.ScalarType = ScalarType = {}));
55
+ /**
56
+ * JavaScript representation of fields with 64 bit integral types (int64, uint64,
57
+ * sint64, fixed64, sfixed64).
58
+ *
59
+ * This is a subset of google.protobuf.FieldOptions.JSType, which defines JS_NORMAL,
60
+ * JS_STRING, and JS_NUMBER. Protobuf-ES uses BigInt by default, but will use
61
+ * String if `[jstype = JS_STRING]` is specified.
62
+ *
63
+ * ```protobuf
64
+ * uint64 field_a = 1; // BigInt
65
+ * uint64 field_b = 2 [jstype = JS_NORMAL]; // BigInt
66
+ * uint64 field_b = 2 [jstype = JS_NUMBER]; // BigInt
67
+ * uint64 field_b = 2 [jstype = JS_STRING]; // String
68
+ * ```
69
+ */
70
+ var LongType;
71
+ (function (LongType) {
72
+ /**
73
+ * Use JavaScript BigInt.
74
+ */
75
+ LongType[LongType["BIGINT"] = 0] = "BIGINT";
76
+ /**
77
+ * Use JavaScript String.
78
+ *
79
+ * Field option `[jstype = JS_STRING]`.
80
+ */
81
+ LongType[LongType["STRING"] = 1] = "STRING";
82
+ })(LongType || (exports.LongType = LongType = {}));
18
83
  /**
19
84
  * Returns true if both scalar values are equal.
20
85
  */
@@ -24,7 +89,7 @@ function scalarEquals(type, a, b) {
24
89
  return true;
25
90
  }
26
91
  // Special case BYTES - we need to compare each byte individually
27
- if (type == protobuf_1.ScalarType.BYTES) {
92
+ if (type == ScalarType.BYTES) {
28
93
  if (!(a instanceof Uint8Array) || !(b instanceof Uint8Array)) {
29
94
  return false;
30
95
  }
@@ -41,11 +106,11 @@ function scalarEquals(type, a, b) {
41
106
  // Special case 64-bit integers - we support number, string and bigint representation.
42
107
  // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
43
108
  switch (type) {
44
- case protobuf_1.ScalarType.UINT64:
45
- case protobuf_1.ScalarType.FIXED64:
46
- case protobuf_1.ScalarType.INT64:
47
- case protobuf_1.ScalarType.SFIXED64:
48
- case protobuf_1.ScalarType.SINT64:
109
+ case ScalarType.UINT64:
110
+ case ScalarType.FIXED64:
111
+ case ScalarType.INT64:
112
+ case ScalarType.SFIXED64:
113
+ case ScalarType.SINT64:
49
114
  // Loose comparison will match between 0n, 0 and "0".
50
115
  return a == b;
51
116
  }
@@ -59,21 +124,21 @@ exports.scalarEquals = scalarEquals;
59
124
  */
60
125
  function scalarZeroValue(type, longType) {
61
126
  switch (type) {
62
- case protobuf_1.ScalarType.BOOL:
127
+ case ScalarType.BOOL:
63
128
  return false;
64
- case protobuf_1.ScalarType.UINT64:
65
- case protobuf_1.ScalarType.FIXED64:
66
- case protobuf_1.ScalarType.INT64:
67
- case protobuf_1.ScalarType.SFIXED64:
68
- case protobuf_1.ScalarType.SINT64:
129
+ case ScalarType.UINT64:
130
+ case ScalarType.FIXED64:
131
+ case ScalarType.INT64:
132
+ case ScalarType.SFIXED64:
133
+ case ScalarType.SINT64:
69
134
  // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison -- acceptable since it's covered by tests
70
- return (longType == 0 ? protobuf_1.protoInt64.zero : "0");
71
- case protobuf_1.ScalarType.DOUBLE:
72
- case protobuf_1.ScalarType.FLOAT:
135
+ return (longType == 0 ? proto_int64_js_1.protoInt64.zero : "0");
136
+ case ScalarType.DOUBLE:
137
+ case ScalarType.FLOAT:
73
138
  return 0.0;
74
- case protobuf_1.ScalarType.BYTES:
139
+ case ScalarType.BYTES:
75
140
  return new Uint8Array(0);
76
- case protobuf_1.ScalarType.STRING:
141
+ case ScalarType.STRING:
77
142
  return "";
78
143
  default:
79
144
  // Handles INT32, UINT32, SINT32, FIXED32, SFIXED32.
@@ -91,11 +156,11 @@ exports.scalarZeroValue = scalarZeroValue;
91
156
  */
92
157
  function isScalarZeroValue(type, value) {
93
158
  switch (type) {
94
- case protobuf_1.ScalarType.BOOL:
159
+ case ScalarType.BOOL:
95
160
  return value === false;
96
- case protobuf_1.ScalarType.STRING:
161
+ case ScalarType.STRING:
97
162
  return value === "";
98
- case protobuf_1.ScalarType.BYTES:
163
+ case ScalarType.BYTES:
99
164
  return value instanceof Uint8Array && !value.byteLength;
100
165
  default:
101
166
  return value == 0; // Loose comparison matches 0n, 0 and "0"
@@ -0,0 +1,95 @@
1
+ import type { AnyMessage, Message, MessageType } from "./message.js";
2
+ /**
3
+ * ServiceType represents a protobuf services. It provides metadata for
4
+ * reflection-based operations.
5
+ */
6
+ export interface ServiceType {
7
+ /**
8
+ * The fully qualified name of the service.
9
+ */
10
+ readonly typeName: string;
11
+ /**
12
+ * A map of local name (safe to use in ECMAScript) to method.
13
+ */
14
+ readonly methods: {
15
+ [localName: string]: MethodInfo;
16
+ };
17
+ }
18
+ /**
19
+ * MethodInfo represents a method of a protobuf service, a remote procedure
20
+ * call. All methods provide the following properties:
21
+ *
22
+ * - "name": The original name of the protobuf rpc.
23
+ * - "I": The input message type.
24
+ * - "O": The output message type.
25
+ * - "kind": The method type.
26
+ * - "idempotency": User-provided indication whether the method will cause
27
+ * the same effect every time it is called.
28
+ */
29
+ export type MethodInfo<I extends Message<I> = AnyMessage, O extends Message<O> = AnyMessage> = MethodInfoUnary<I, O> | MethodInfoServerStreaming<I, O> | MethodInfoClientStreaming<I, O> | MethodInfoBiDiStreaming<I, O>;
30
+ /**
31
+ * A unary method: rpc (Input) returns (Output)
32
+ */
33
+ export interface MethodInfoUnary<I extends Message<I>, O extends Message<O>> extends miShared<I, O> {
34
+ readonly kind: MethodKind.Unary;
35
+ }
36
+ /**
37
+ * A server streaming method: rpc (Input) returns (stream Output)
38
+ */
39
+ export interface MethodInfoServerStreaming<I extends Message<I>, O extends Message<O>> extends miShared<I, O> {
40
+ readonly kind: MethodKind.ServerStreaming;
41
+ }
42
+ /**
43
+ * A client streaming method: rpc (stream Input) returns (Output)
44
+ */
45
+ export interface MethodInfoClientStreaming<I extends Message<I>, O extends Message<O>> extends miShared<I, O> {
46
+ readonly kind: MethodKind.ClientStreaming;
47
+ }
48
+ /**
49
+ * A method that streams bi-directionally: rpc (stream Input) returns (stream Output)
50
+ */
51
+ export interface MethodInfoBiDiStreaming<I extends Message<I>, O extends Message<O>> extends miShared<I, O> {
52
+ readonly kind: MethodKind.BiDiStreaming;
53
+ }
54
+ interface miShared<I extends Message<I> = AnyMessage, O extends Message<O> = AnyMessage> {
55
+ readonly name: string;
56
+ readonly I: MessageType<I>;
57
+ readonly O: MessageType<O>;
58
+ readonly idempotency?: MethodIdempotency;
59
+ }
60
+ /**
61
+ * MethodKind represents the four method types that can be declared in
62
+ * protobuf with the `stream` keyword:
63
+ *
64
+ * 1. Unary: rpc (Input) returns (Output)
65
+ * 2. ServerStreaming: rpc (Input) returns (stream Output)
66
+ * 3. ClientStreaming: rpc (stream Input) returns (Output)
67
+ * 4. BiDiStreaming: rpc (stream Input) returns (stream Output)
68
+ */
69
+ export declare enum MethodKind {
70
+ Unary = 0,
71
+ ServerStreaming = 1,
72
+ ClientStreaming = 2,
73
+ BiDiStreaming = 3
74
+ }
75
+ /**
76
+ * Is this method side-effect-free (or safe in HTTP parlance), or just
77
+ * idempotent, or neither? HTTP based RPC implementation may choose GET verb
78
+ * for safe methods, and PUT verb for idempotent methods instead of the
79
+ * default POST.
80
+ *
81
+ * This enum matches the protobuf enum google.protobuf.MethodOptions.IdempotencyLevel,
82
+ * defined in the well-known type google/protobuf/descriptor.proto, but
83
+ * drops UNKNOWN.
84
+ */
85
+ export declare enum MethodIdempotency {
86
+ /**
87
+ * Idempotent, no side effects.
88
+ */
89
+ NoSideEffects = 1,
90
+ /**
91
+ * Idempotent, but may have side effects.
92
+ */
93
+ Idempotent = 2
94
+ }
95
+ export {};
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.MethodIdempotency = exports.MethodKind = void 0;
17
+ /**
18
+ * MethodKind represents the four method types that can be declared in
19
+ * protobuf with the `stream` keyword:
20
+ *
21
+ * 1. Unary: rpc (Input) returns (Output)
22
+ * 2. ServerStreaming: rpc (Input) returns (stream Output)
23
+ * 3. ClientStreaming: rpc (stream Input) returns (Output)
24
+ * 4. BiDiStreaming: rpc (stream Input) returns (stream Output)
25
+ */
26
+ var MethodKind;
27
+ (function (MethodKind) {
28
+ MethodKind[MethodKind["Unary"] = 0] = "Unary";
29
+ MethodKind[MethodKind["ServerStreaming"] = 1] = "ServerStreaming";
30
+ MethodKind[MethodKind["ClientStreaming"] = 2] = "ClientStreaming";
31
+ MethodKind[MethodKind["BiDiStreaming"] = 3] = "BiDiStreaming";
32
+ })(MethodKind || (exports.MethodKind = MethodKind = {}));
33
+ /**
34
+ * Is this method side-effect-free (or safe in HTTP parlance), or just
35
+ * idempotent, or neither? HTTP based RPC implementation may choose GET verb
36
+ * for safe methods, and PUT verb for idempotent methods instead of the
37
+ * default POST.
38
+ *
39
+ * This enum matches the protobuf enum google.protobuf.MethodOptions.IdempotencyLevel,
40
+ * defined in the well-known type google/protobuf/descriptor.proto, but
41
+ * drops UNKNOWN.
42
+ */
43
+ var MethodIdempotency;
44
+ (function (MethodIdempotency) {
45
+ /**
46
+ * Idempotent, no side effects.
47
+ */
48
+ MethodIdempotency[MethodIdempotency["NoSideEffects"] = 1] = "NoSideEffects";
49
+ /**
50
+ * Idempotent, but may have side effects.
51
+ */
52
+ MethodIdempotency[MethodIdempotency["Idempotent"] = 2] = "Idempotent";
53
+ })(MethodIdempotency || (exports.MethodIdempotency = MethodIdempotency = {}));
@@ -0,0 +1,4 @@
1
+ import type { DescEnum } from "./descriptor-set.js";
2
+ import { ScalarType } from "./scalar.js";
3
+ export declare function parseTextFormatEnumValue(descEnum: DescEnum, value: string): number;
4
+ export declare function parseTextFormatScalarValue(type: ScalarType, value: string): number | boolean | string | bigint | Uint8Array;
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.parseTextFormatScalarValue = exports.parseTextFormatEnumValue = void 0;
17
+ const assert_js_1 = require("./assert.js");
18
+ const proto_int64_js_1 = require("./proto-int64.js");
19
+ const scalar_js_1 = require("./scalar.js");
20
+ function parseTextFormatEnumValue(descEnum, value) {
21
+ const enumValue = descEnum.values.find((v) => v.name === value);
22
+ (0, assert_js_1.assert)(enumValue, `cannot parse ${descEnum.name} default value: ${value}`);
23
+ return enumValue.number;
24
+ }
25
+ exports.parseTextFormatEnumValue = parseTextFormatEnumValue;
26
+ function parseTextFormatScalarValue(type, value) {
27
+ switch (type) {
28
+ case scalar_js_1.ScalarType.STRING:
29
+ return value;
30
+ case scalar_js_1.ScalarType.BYTES: {
31
+ const u = unescapeBytesDefaultValue(value);
32
+ if (u === false) {
33
+ throw new Error(`cannot parse ${scalar_js_1.ScalarType[type]} default value: ${value}`);
34
+ }
35
+ return u;
36
+ }
37
+ case scalar_js_1.ScalarType.INT64:
38
+ case scalar_js_1.ScalarType.SFIXED64:
39
+ case scalar_js_1.ScalarType.SINT64:
40
+ return proto_int64_js_1.protoInt64.parse(value);
41
+ case scalar_js_1.ScalarType.UINT64:
42
+ case scalar_js_1.ScalarType.FIXED64:
43
+ return proto_int64_js_1.protoInt64.uParse(value);
44
+ case scalar_js_1.ScalarType.DOUBLE:
45
+ case scalar_js_1.ScalarType.FLOAT:
46
+ switch (value) {
47
+ case "inf":
48
+ return Number.POSITIVE_INFINITY;
49
+ case "-inf":
50
+ return Number.NEGATIVE_INFINITY;
51
+ case "nan":
52
+ return Number.NaN;
53
+ default:
54
+ return parseFloat(value);
55
+ }
56
+ case scalar_js_1.ScalarType.BOOL:
57
+ return value === "true";
58
+ case scalar_js_1.ScalarType.INT32:
59
+ case scalar_js_1.ScalarType.UINT32:
60
+ case scalar_js_1.ScalarType.SINT32:
61
+ case scalar_js_1.ScalarType.FIXED32:
62
+ case scalar_js_1.ScalarType.SFIXED32:
63
+ return parseInt(value, 10);
64
+ }
65
+ }
66
+ exports.parseTextFormatScalarValue = parseTextFormatScalarValue;
67
+ /**
68
+ * Parses a text-encoded default value (proto2) of a BYTES field.
69
+ */
70
+ function unescapeBytesDefaultValue(str) {
71
+ const b = [];
72
+ const input = {
73
+ tail: str,
74
+ c: "",
75
+ next() {
76
+ if (this.tail.length == 0) {
77
+ return false;
78
+ }
79
+ this.c = this.tail[0];
80
+ this.tail = this.tail.substring(1);
81
+ return true;
82
+ },
83
+ take(n) {
84
+ if (this.tail.length >= n) {
85
+ const r = this.tail.substring(0, n);
86
+ this.tail = this.tail.substring(n);
87
+ return r;
88
+ }
89
+ return false;
90
+ },
91
+ };
92
+ while (input.next()) {
93
+ switch (input.c) {
94
+ case "\\":
95
+ if (input.next()) {
96
+ switch (input.c) {
97
+ case "\\":
98
+ b.push(input.c.charCodeAt(0));
99
+ break;
100
+ case "b":
101
+ b.push(0x08);
102
+ break;
103
+ case "f":
104
+ b.push(0x0c);
105
+ break;
106
+ case "n":
107
+ b.push(0x0a);
108
+ break;
109
+ case "r":
110
+ b.push(0x0d);
111
+ break;
112
+ case "t":
113
+ b.push(0x09);
114
+ break;
115
+ case "v":
116
+ b.push(0x0b);
117
+ break;
118
+ case "0":
119
+ case "1":
120
+ case "2":
121
+ case "3":
122
+ case "4":
123
+ case "5":
124
+ case "6":
125
+ case "7": {
126
+ const s = input.c;
127
+ const t = input.take(2);
128
+ if (t === false) {
129
+ return false;
130
+ }
131
+ const n = parseInt(s + t, 8);
132
+ if (isNaN(n)) {
133
+ return false;
134
+ }
135
+ b.push(n);
136
+ break;
137
+ }
138
+ case "x": {
139
+ const s = input.c;
140
+ const t = input.take(2);
141
+ if (t === false) {
142
+ return false;
143
+ }
144
+ const n = parseInt(s + t, 16);
145
+ if (isNaN(n)) {
146
+ return false;
147
+ }
148
+ b.push(n);
149
+ break;
150
+ }
151
+ case "u": {
152
+ const s = input.c;
153
+ const t = input.take(4);
154
+ if (t === false) {
155
+ return false;
156
+ }
157
+ const n = parseInt(s + t, 16);
158
+ if (isNaN(n)) {
159
+ return false;
160
+ }
161
+ const chunk = new Uint8Array(4);
162
+ const view = new DataView(chunk.buffer);
163
+ view.setInt32(0, n, true);
164
+ b.push(chunk[0], chunk[1], chunk[2], chunk[3]);
165
+ break;
166
+ }
167
+ case "U": {
168
+ const s = input.c;
169
+ const t = input.take(8);
170
+ if (t === false) {
171
+ return false;
172
+ }
173
+ const tc = proto_int64_js_1.protoInt64.uEnc(s + t);
174
+ const chunk = new Uint8Array(8);
175
+ const view = new DataView(chunk.buffer);
176
+ view.setInt32(0, tc.lo, true);
177
+ view.setInt32(4, tc.hi, true);
178
+ b.push(chunk[0], chunk[1], chunk[2], chunk[3], chunk[4], chunk[5], chunk[6], chunk[7]);
179
+ break;
180
+ }
181
+ }
182
+ }
183
+ break;
184
+ default:
185
+ b.push(input.c.charCodeAt(0));
186
+ }
187
+ }
188
+ return new Uint8Array(b);
189
+ }
@@ -0,0 +1,43 @@
1
+ import type { AnyMessage, Message, MessageType } from "./message.js";
2
+ import type { EnumType } from "./enum.js";
3
+ import type { ServiceType } from "./service-type.js";
4
+ /**
5
+ * IMessageTypeRegistry provides look-up for message types.
6
+ *
7
+ * You can conveniently create a registry using the createRegistry()
8
+ * function:
9
+ *
10
+ * ```ts
11
+ * import { createRegistry } from "@bufbuild/protobuf";
12
+ * import { MyMessage, MyOtherMessage } from "./gen/my_message.pb.js";
13
+ *
14
+ * const reg: IMessageTypeRegistry = createRegistry(
15
+ * MyMessage,
16
+ * MyOtherMessage,
17
+ * );
18
+ * ```
19
+ */
20
+ export interface IMessageTypeRegistry {
21
+ /**
22
+ * Find a message type by its protobuf type name.
23
+ */
24
+ findMessage<T extends Message<T> = AnyMessage>(typeName: string): MessageType<T> | undefined;
25
+ }
26
+ /**
27
+ * IEnumTypeRegistry provides look-up for enum types.
28
+ */
29
+ export interface IEnumTypeRegistry {
30
+ /**
31
+ * Find an enum type by its protobuf type name.
32
+ */
33
+ findEnum(typeName: string): EnumType | undefined;
34
+ }
35
+ /**
36
+ * IServiceTypeRegistry provides look-up for service types.
37
+ */
38
+ export interface IServiceTypeRegistry {
39
+ /**
40
+ * Find a service type by its protobuf type name.
41
+ */
42
+ findService(typeName: string): ServiceType | undefined;
43
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/unknown.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { WireType } from "@bufbuild/protobuf";
1
+ import { WireType } from "./binary-encoding.js";
2
2
  export declare const unknownFieldsSymbol: unique symbol;
3
3
  export declare function listUnknownFields(message: any): ReadonlyArray<{
4
4
  no: number;
package/dist/util.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { DescExtension, DescField } from "@bufbuild/protobuf";
2
- import type { Printable } from "@bufbuild/protoplugin/ecmascript";
1
+ import type { Printable } from "./protoplugin/ecmascript";
2
+ import { DescExtension, DescField } from "./descriptor-set.js";
3
3
  export declare function getFieldTypeInfo(field: DescField | DescExtension): {
4
4
  typing: Printable;
5
5
  optional: boolean;