@bufbuild/protobuf 2.0.0-alpha.2 → 2.0.0-alpha.3
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/README.md +1 -1
- package/dist/cjs/clone.d.ts +1 -1
- package/dist/cjs/clone.js +2 -2
- package/dist/cjs/codegenv1/boot.d.ts +1 -1
- package/dist/cjs/codegenv1/boot.js +3 -5
- package/dist/cjs/codegenv1/embed.d.ts +1 -1
- package/dist/cjs/codegenv1/embed.js +39 -34
- package/dist/cjs/codegenv1/enum.d.ts +1 -1
- package/dist/cjs/codegenv1/extension.d.ts +1 -1
- package/dist/cjs/codegenv1/file.d.ts +1 -1
- package/dist/cjs/codegenv1/file.js +5 -7
- package/dist/cjs/codegenv1/index.d.ts +1 -0
- package/dist/cjs/codegenv1/index.js +1 -0
- package/dist/cjs/codegenv1/message.d.ts +1 -1
- package/dist/cjs/codegenv1/scalar.d.ts +5 -0
- package/dist/cjs/codegenv1/scalar.js +39 -0
- package/dist/cjs/codegenv1/service.d.ts +3 -3
- package/dist/cjs/codegenv1/types.d.ts +7 -9
- package/dist/cjs/create.d.ts +1 -1
- package/dist/cjs/create.js +6 -5
- package/dist/cjs/{desc-types.d.ts → descriptors.d.ts} +39 -7
- package/dist/cjs/descriptors.js +53 -0
- package/dist/cjs/equals.d.ts +1 -1
- package/dist/cjs/extensions.d.ts +1 -1
- package/dist/cjs/extensions.js +4 -3
- package/dist/cjs/fields.d.ts +1 -1
- package/dist/cjs/from-binary.d.ts +2 -2
- package/dist/cjs/from-binary.js +22 -22
- package/dist/cjs/from-json.d.ts +4 -4
- package/dist/cjs/from-json.js +200 -181
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/is-message.d.ts +1 -1
- package/dist/cjs/proto-int64.d.ts +4 -1
- package/dist/cjs/proto-int64.js +16 -6
- package/dist/cjs/reflect/error.d.ts +1 -1
- package/dist/cjs/reflect/guard.d.ts +1 -1
- package/dist/cjs/reflect/index.d.ts +0 -1
- package/dist/cjs/reflect/index.js +0 -1
- package/dist/cjs/reflect/names.d.ts +1 -1
- package/dist/cjs/reflect/names.js +1 -1
- package/dist/cjs/reflect/nested-types.d.ts +1 -1
- package/dist/cjs/reflect/reflect-check.d.ts +10 -1
- package/dist/cjs/reflect/reflect-check.js +126 -9
- package/dist/cjs/reflect/reflect-types.d.ts +4 -4
- package/dist/cjs/reflect/reflect.d.ts +1 -1
- package/dist/cjs/reflect/reflect.js +28 -27
- package/dist/cjs/reflect/scalar.d.ts +3 -55
- package/dist/cjs/reflect/scalar.js +26 -220
- package/dist/cjs/reflect/unsafe.d.ts +1 -1
- package/dist/cjs/reflect/unsafe.js +1 -1
- package/dist/cjs/{reflect/registry.d.ts → registry.d.ts} +2 -2
- package/dist/cjs/{reflect/registry.js → registry.js} +54 -36
- package/dist/cjs/to-binary.d.ts +1 -1
- package/dist/cjs/to-binary.js +27 -27
- package/dist/cjs/to-json.d.ts +7 -6
- package/dist/cjs/to-json.js +57 -44
- package/dist/cjs/types.d.ts +1 -1
- package/dist/cjs/wire/base64-encoding.js +2 -2
- package/dist/cjs/wire/binary-encoding.d.ts +20 -0
- package/dist/cjs/wire/binary-encoding.js +54 -8
- package/dist/cjs/wire/size-delimited.d.ts +1 -1
- package/dist/cjs/wire/text-format.d.ts +1 -2
- package/dist/cjs/wire/text-format.js +21 -19
- package/dist/cjs/wkt/any.d.ts +3 -3
- package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.d.ts +6 -0
- package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.js +1 -1
- package/dist/cjs/wkt/wrappers.d.ts +1 -1
- package/dist/esm/clone.d.ts +1 -1
- package/dist/esm/clone.js +1 -1
- package/dist/esm/codegenv1/boot.d.ts +1 -1
- package/dist/esm/codegenv1/boot.js +3 -5
- package/dist/esm/codegenv1/embed.d.ts +1 -1
- package/dist/esm/codegenv1/embed.js +9 -4
- package/dist/esm/codegenv1/enum.d.ts +1 -1
- package/dist/esm/codegenv1/extension.d.ts +1 -1
- package/dist/esm/codegenv1/file.d.ts +1 -1
- package/dist/esm/codegenv1/file.js +4 -6
- package/dist/esm/codegenv1/index.d.ts +1 -0
- package/dist/esm/codegenv1/index.js +1 -0
- package/dist/esm/codegenv1/message.d.ts +1 -1
- package/dist/esm/codegenv1/scalar.d.ts +5 -0
- package/dist/esm/codegenv1/scalar.js +35 -0
- package/dist/esm/codegenv1/service.d.ts +3 -3
- package/dist/esm/codegenv1/types.d.ts +7 -9
- package/dist/esm/create.d.ts +1 -1
- package/dist/esm/create.js +4 -3
- package/dist/esm/{desc-types.d.ts → descriptors.d.ts} +39 -7
- package/dist/esm/descriptors.js +50 -0
- package/dist/esm/equals.d.ts +1 -1
- package/dist/esm/extensions.d.ts +1 -1
- package/dist/esm/extensions.js +4 -3
- package/dist/esm/fields.d.ts +1 -1
- package/dist/esm/from-binary.d.ts +2 -2
- package/dist/esm/from-binary.js +4 -4
- package/dist/esm/from-json.d.ts +4 -4
- package/dist/esm/from-json.js +193 -174
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/is-message.d.ts +1 -1
- package/dist/esm/proto-int64.d.ts +4 -1
- package/dist/esm/proto-int64.js +16 -6
- package/dist/esm/reflect/error.d.ts +1 -1
- package/dist/esm/reflect/guard.d.ts +1 -1
- package/dist/esm/reflect/index.d.ts +0 -1
- package/dist/esm/reflect/index.js +0 -1
- package/dist/esm/reflect/names.d.ts +1 -1
- package/dist/esm/reflect/names.js +1 -1
- package/dist/esm/reflect/nested-types.d.ts +1 -1
- package/dist/esm/reflect/reflect-check.d.ts +10 -1
- package/dist/esm/reflect/reflect-check.js +119 -2
- package/dist/esm/reflect/reflect-types.d.ts +4 -4
- package/dist/esm/reflect/reflect-types.js +1 -0
- package/dist/esm/reflect/reflect.d.ts +1 -1
- package/dist/esm/reflect/reflect.js +10 -9
- package/dist/esm/reflect/scalar.d.ts +3 -55
- package/dist/esm/reflect/scalar.js +14 -205
- package/dist/esm/reflect/unsafe.d.ts +1 -1
- package/dist/esm/reflect/unsafe.js +1 -1
- package/dist/esm/{reflect/registry.d.ts → registry.d.ts} +2 -2
- package/dist/esm/{reflect/registry.js → registry.js} +44 -26
- package/dist/esm/to-binary.d.ts +1 -1
- package/dist/esm/to-binary.js +1 -1
- package/dist/esm/to-json.d.ts +7 -6
- package/dist/esm/to-json.js +42 -29
- package/dist/esm/types.d.ts +1 -1
- package/dist/esm/wire/base64-encoding.js +2 -2
- package/dist/esm/wire/binary-encoding.d.ts +20 -0
- package/dist/esm/wire/binary-encoding.js +47 -1
- package/dist/esm/wire/size-delimited.d.ts +1 -1
- package/dist/esm/wire/text-format.d.ts +1 -2
- package/dist/esm/wire/text-format.js +5 -3
- package/dist/esm/wkt/any.d.ts +3 -3
- package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.d.ts +6 -0
- package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.js +1 -1
- package/dist/esm/wkt/wrappers.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/desc-types.js +0 -15
- package/dist/cjs/reflect/assert.d.ts +0 -16
- package/dist/cjs/reflect/assert.js +0 -59
- package/dist/esm/desc-types.js +0 -14
- package/dist/esm/reflect/assert.d.ts +0 -16
- package/dist/esm/reflect/assert.js +0 -52
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Some additional features that set it apart from the others:
|
|
|
15
15
|
- ECMAScript module support
|
|
16
16
|
- First-class TypeScript support
|
|
17
17
|
- Generation of idiomatic JavaScript and TypeScript code.
|
|
18
|
-
- Generation of [much smaller bundles](https://github.com/bufbuild/protobuf-es/blob/main/packages/
|
|
18
|
+
- Generation of [much smaller bundles](https://github.com/bufbuild/protobuf-es/blob/main/packages/bundle-size)
|
|
19
19
|
- Implementation of all proto3 features, including the [canonical JSON format](https://developers.google.com/protocol-buffers/docs/proto3#json).
|
|
20
20
|
- Implementation of all proto2 features, except for extensions and the text format.
|
|
21
21
|
- Usage of standard JavaScript APIs instead of the [Closure Library](http://googlecode.blogspot.com/2009/11/introducing-closure-tools.html)
|
package/dist/cjs/clone.d.ts
CHANGED
package/dist/cjs/clone.js
CHANGED
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.clone = void 0;
|
|
17
|
+
const descriptors_js_1 = require("./descriptors.js");
|
|
17
18
|
const reflect_js_1 = require("./reflect/reflect.js");
|
|
18
19
|
const guard_js_1 = require("./reflect/guard.js");
|
|
19
|
-
const scalar_js_1 = require("./reflect/scalar.js");
|
|
20
20
|
/**
|
|
21
21
|
* Create a deep copy of a message, including extensions and unknown fields.
|
|
22
22
|
*/
|
|
@@ -69,7 +69,7 @@ function cloneSingular(field, value) {
|
|
|
69
69
|
if (field.message !== undefined && (0, guard_js_1.isReflectMessage)(value)) {
|
|
70
70
|
return cloneReflect(value);
|
|
71
71
|
}
|
|
72
|
-
if (field.scalar ==
|
|
72
|
+
if (field.scalar == descriptors_js_1.ScalarType.BYTES && value instanceof Uint8Array) {
|
|
73
73
|
// @ts-expect-error T cannot extend Uint8Array in practice
|
|
74
74
|
return value.slice();
|
|
75
75
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DescriptorProto_ExtensionRange, FieldDescriptorProto_Label, FieldDescriptorProto_Type, FieldOptions_OptionRetention, FieldOptions_OptionTargetType, FieldOptions_EditionDefault, EnumValueDescriptorProto, FileDescriptorProto } from "../wkt/gen/google/protobuf/descriptor_pb.js";
|
|
2
|
-
import type { DescFile } from "../
|
|
2
|
+
import type { DescFile } from "../descriptors.js";
|
|
3
3
|
/**
|
|
4
4
|
* Hydrate a file descriptor for google/protobuf/descriptor.proto from a plain
|
|
5
5
|
* object.
|
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.bootFileDescriptorProto = exports.boot = void 0;
|
|
17
17
|
const restore_json_names_js_1 = require("./restore-json-names.js");
|
|
18
|
-
const registry_js_1 = require("../
|
|
19
|
-
const assert_js_1 = require("../reflect/assert.js");
|
|
18
|
+
const registry_js_1 = require("../registry.js");
|
|
20
19
|
/**
|
|
21
20
|
* Hydrate a file descriptor for google/protobuf/descriptor.proto from a plain
|
|
22
21
|
* object.
|
|
@@ -29,9 +28,8 @@ function boot(boot) {
|
|
|
29
28
|
const root = bootFileDescriptorProto(boot);
|
|
30
29
|
root.messageType.forEach(restore_json_names_js_1.restoreJsonNames);
|
|
31
30
|
const reg = (0, registry_js_1.createFileRegistry)(root, () => undefined);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return file;
|
|
31
|
+
// non-null assertion because we just created the registry from the file we look up
|
|
32
|
+
return reg.getFile(root.name);
|
|
35
33
|
}
|
|
36
34
|
exports.boot = boot;
|
|
37
35
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DescEnum, DescExtension, DescMessage, DescService } from "../
|
|
1
|
+
import type { DescEnum, DescExtension, DescMessage, DescService } from "../descriptors.js";
|
|
2
2
|
import type { FileDescriptorProto } from "../wkt/gen/google/protobuf/descriptor_pb.js";
|
|
3
3
|
import type { FileDescriptorProtoBoot } from "./boot.js";
|
|
4
4
|
type EmbedUnknown = {
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.createFileDescriptorProtoBoot = exports.pathInFileDesc = exports.embedFileDesc = void 0;
|
|
17
17
|
const names_js_1 = require("../reflect/names.js");
|
|
18
|
-
const assert_js_1 = require("../reflect/assert.js");
|
|
19
18
|
const fields_js_1 = require("../fields.js");
|
|
20
19
|
const base64_encoding_js_1 = require("../wire/base64-encoding.js");
|
|
21
20
|
const to_binary_js_1 = require("../to-binary.js");
|
|
@@ -118,17 +117,17 @@ exports.pathInFileDesc = pathInFileDesc;
|
|
|
118
117
|
*/
|
|
119
118
|
function createFileDescriptorProtoBoot(proto) {
|
|
120
119
|
var _a;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
120
|
+
assert(proto.name == "google/protobuf/descriptor.proto");
|
|
121
|
+
assert(proto.package == "google.protobuf");
|
|
122
|
+
assert(!proto.dependency.length);
|
|
123
|
+
assert(!proto.publicDependency.length);
|
|
124
|
+
assert(!proto.weakDependency.length);
|
|
125
|
+
assert(!proto.service.length);
|
|
126
|
+
assert(!proto.extension.length);
|
|
127
|
+
assert(proto.sourceCodeInfo === undefined);
|
|
128
|
+
assert(proto.syntax == "" || proto.syntax == "proto2");
|
|
129
|
+
assert(!((_a = proto.options) === null || _a === void 0 ? void 0 : _a.features)); // we're dropping file options
|
|
130
|
+
assert(proto.edition === descriptor_pb_js_1.Edition.EDITION_UNKNOWN);
|
|
132
131
|
return {
|
|
133
132
|
name: proto.name,
|
|
134
133
|
package: proto.package,
|
|
@@ -138,10 +137,9 @@ function createFileDescriptorProtoBoot(proto) {
|
|
|
138
137
|
}
|
|
139
138
|
exports.createFileDescriptorProtoBoot = createFileDescriptorProtoBoot;
|
|
140
139
|
function createDescriptorBoot(proto) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
(0, assert_js_1.assert)(!proto.reservedName.length); // we're also dropping reserved_range
|
|
140
|
+
assert(proto.extension.length == 0);
|
|
141
|
+
assert(!proto.oneofDecl.length);
|
|
142
|
+
assert(!proto.options);
|
|
145
143
|
const b = {
|
|
146
144
|
name: proto.name,
|
|
147
145
|
};
|
|
@@ -156,18 +154,18 @@ function createDescriptorBoot(proto) {
|
|
|
156
154
|
}
|
|
157
155
|
if (proto.extensionRange.length) {
|
|
158
156
|
b.extensionRange = proto.extensionRange.map((r) => {
|
|
159
|
-
|
|
157
|
+
assert(!r.options);
|
|
160
158
|
return { start: r.start, end: r.end };
|
|
161
159
|
});
|
|
162
160
|
}
|
|
163
161
|
return b;
|
|
164
162
|
}
|
|
165
163
|
function createFieldDescriptorBoot(proto) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
164
|
+
assert((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldDescriptorProtoDesc.field.name));
|
|
165
|
+
assert((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldDescriptorProtoDesc.field.number));
|
|
166
|
+
assert((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldDescriptorProtoDesc.field.type));
|
|
167
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldDescriptorProtoDesc.field.oneofIndex));
|
|
168
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldDescriptorProtoDesc.field.jsonName) ||
|
|
171
169
|
proto.jsonName === (0, names_js_1.protoCamelCase)(proto.name));
|
|
172
170
|
const b = {
|
|
173
171
|
name: proto.name,
|
|
@@ -193,18 +191,18 @@ function createFieldDescriptorBoot(proto) {
|
|
|
193
191
|
}
|
|
194
192
|
function createFieldOptionsBoot(proto) {
|
|
195
193
|
const b = {};
|
|
196
|
-
|
|
194
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsDesc.field.ctype));
|
|
197
195
|
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsDesc.field.packed)) {
|
|
198
196
|
b.packed = proto.packed;
|
|
199
197
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
198
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsDesc.field.jstype));
|
|
199
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsDesc.field.lazy));
|
|
200
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsDesc.field.unverifiedLazy));
|
|
203
201
|
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsDesc.field.deprecated)) {
|
|
204
202
|
b.deprecated = proto.deprecated;
|
|
205
203
|
}
|
|
206
|
-
|
|
207
|
-
|
|
204
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsDesc.field.weak));
|
|
205
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsDesc.field.debugRedact));
|
|
208
206
|
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsDesc.field.retention)) {
|
|
209
207
|
b.retention = proto.retention;
|
|
210
208
|
}
|
|
@@ -217,18 +215,16 @@ function createFieldOptionsBoot(proto) {
|
|
|
217
215
|
edition: d.edition,
|
|
218
216
|
}));
|
|
219
217
|
}
|
|
220
|
-
|
|
221
|
-
|
|
218
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsDesc.field.features));
|
|
219
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsDesc.field.uninterpretedOption));
|
|
222
220
|
return b;
|
|
223
221
|
}
|
|
224
222
|
function createEnumDescriptorBoot(proto) {
|
|
225
|
-
|
|
226
|
-
(0, assert_js_1.assert)(!proto.reservedRange.length);
|
|
227
|
-
(0, assert_js_1.assert)(!proto.options);
|
|
223
|
+
assert(!proto.options);
|
|
228
224
|
return {
|
|
229
225
|
name: proto.name,
|
|
230
226
|
value: proto.value.map((v) => {
|
|
231
|
-
|
|
227
|
+
assert(!v.options);
|
|
232
228
|
return {
|
|
233
229
|
name: v.name,
|
|
234
230
|
number: v.number,
|
|
@@ -236,3 +232,12 @@ function createEnumDescriptorBoot(proto) {
|
|
|
236
232
|
}),
|
|
237
233
|
};
|
|
238
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Assert that condition is truthy or throw error.
|
|
237
|
+
*/
|
|
238
|
+
function assert(condition) {
|
|
239
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we want the implicit conversion to boolean
|
|
240
|
+
if (!condition) {
|
|
241
|
+
throw new Error();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
@@ -14,10 +14,9 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.fileDesc = void 0;
|
|
17
|
-
const
|
|
17
|
+
const base64_encoding_js_1 = require("../wire/base64-encoding.js");
|
|
18
18
|
const descriptor_pb_js_1 = require("../wkt/gen/google/protobuf/descriptor_pb.js");
|
|
19
|
-
const registry_js_1 = require("../
|
|
20
|
-
const assert_js_1 = require("../reflect/assert.js");
|
|
19
|
+
const registry_js_1 = require("../registry.js");
|
|
21
20
|
const restore_json_names_js_1 = require("./restore-json-names.js");
|
|
22
21
|
const from_binary_js_1 = require("../from-binary.js");
|
|
23
22
|
/**
|
|
@@ -27,12 +26,11 @@ const from_binary_js_1 = require("../from-binary.js");
|
|
|
27
26
|
*/
|
|
28
27
|
function fileDesc(b64, imports) {
|
|
29
28
|
var _a;
|
|
30
|
-
const root = (0, from_binary_js_1.fromBinary)(descriptor_pb_js_1.FileDescriptorProtoDesc, (0,
|
|
29
|
+
const root = (0, from_binary_js_1.fromBinary)(descriptor_pb_js_1.FileDescriptorProtoDesc, (0, base64_encoding_js_1.base64Decode)(b64));
|
|
31
30
|
root.messageType.forEach(restore_json_names_js_1.restoreJsonNames);
|
|
32
31
|
root.dependency = (_a = imports === null || imports === void 0 ? void 0 : imports.map((f) => f.proto.name)) !== null && _a !== void 0 ? _a : [];
|
|
33
32
|
const reg = (0, registry_js_1.createFileRegistry)(root, (protoFileName) => imports === null || imports === void 0 ? void 0 : imports.find((f) => f.proto.name === protoFileName));
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return file;
|
|
33
|
+
// non-null assertion because we just created the registry from the file we look up
|
|
34
|
+
return reg.getFile(root.name);
|
|
37
35
|
}
|
|
38
36
|
exports.fileDesc = fileDesc;
|
|
@@ -35,4 +35,5 @@ __exportStar(require("./file.js"), exports);
|
|
|
35
35
|
__exportStar(require("./message.js"), exports);
|
|
36
36
|
__exportStar(require("./service.js"), exports);
|
|
37
37
|
__exportStar(require("./symbols.js"), exports);
|
|
38
|
+
__exportStar(require("./scalar.js"), exports);
|
|
38
39
|
__exportStar(require("./types.js"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ScalarType } from "../descriptors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Return the TypeScript type (as a string) for the given scalar type.
|
|
4
|
+
*/
|
|
5
|
+
export declare function scalarTypeScriptType(scalar: ScalarType, longAsString: boolean): "string" | "boolean" | "bigint" | "bigint | string" | "Uint8Array" | "number";
|
|
@@ -0,0 +1,39 @@
|
|
|
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.scalarTypeScriptType = void 0;
|
|
17
|
+
const descriptors_js_1 = require("../descriptors.js");
|
|
18
|
+
/**
|
|
19
|
+
* Return the TypeScript type (as a string) for the given scalar type.
|
|
20
|
+
*/
|
|
21
|
+
function scalarTypeScriptType(scalar, longAsString) {
|
|
22
|
+
switch (scalar) {
|
|
23
|
+
case descriptors_js_1.ScalarType.STRING:
|
|
24
|
+
return "string";
|
|
25
|
+
case descriptors_js_1.ScalarType.BOOL:
|
|
26
|
+
return "boolean";
|
|
27
|
+
case descriptors_js_1.ScalarType.UINT64:
|
|
28
|
+
case descriptors_js_1.ScalarType.SFIXED64:
|
|
29
|
+
case descriptors_js_1.ScalarType.FIXED64:
|
|
30
|
+
case descriptors_js_1.ScalarType.SINT64:
|
|
31
|
+
case descriptors_js_1.ScalarType.INT64:
|
|
32
|
+
return longAsString ? "string" : "bigint";
|
|
33
|
+
case descriptors_js_1.ScalarType.BYTES:
|
|
34
|
+
return "Uint8Array";
|
|
35
|
+
default:
|
|
36
|
+
return "number";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.scalarTypeScriptType = scalarTypeScriptType;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { GenDescService,
|
|
2
|
-
import type { DescFile } from "../
|
|
1
|
+
import type { GenDescService, GenDescServiceMethods } from "./types.js";
|
|
2
|
+
import type { DescFile } from "../descriptors.js";
|
|
3
3
|
/**
|
|
4
4
|
* Hydrate a service descriptor.
|
|
5
5
|
*
|
|
6
6
|
* @private
|
|
7
7
|
*/
|
|
8
|
-
export declare function serviceDesc<T extends
|
|
8
|
+
export declare function serviceDesc<T extends GenDescServiceMethods>(file: DescFile, path: number, ...paths: number[]): GenDescService<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Message } from "../types.js";
|
|
2
|
-
import type { DescEnum, DescExtension, DescField, DescFile, DescMessage, DescService } from "../
|
|
2
|
+
import type { DescEnum, DescExtension, DescField, DescFile, DescMessage, DescMethod, DescService } from "../descriptors.js";
|
|
3
3
|
/**
|
|
4
4
|
* Describes a protobuf source file.
|
|
5
5
|
*
|
|
@@ -43,17 +43,15 @@ export type GenDescExtension<Extendee extends Message = Message, RuntimeShape =
|
|
|
43
43
|
*
|
|
44
44
|
* @private
|
|
45
45
|
*/
|
|
46
|
-
export type GenDescService<RuntimeShape extends
|
|
46
|
+
export type GenDescService<RuntimeShape extends GenDescServiceMethods> = Omit<DescService, "method"> & {
|
|
47
|
+
method: {
|
|
48
|
+
[K in keyof RuntimeShape]: RuntimeShape[K] & DescMethod;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
47
51
|
/**
|
|
48
52
|
* @private
|
|
49
53
|
*/
|
|
50
|
-
export type
|
|
51
|
-
[localName: string]: {
|
|
52
|
-
kind: "unary" | "server_streaming" | "client_streaming" | "bidi_streaming";
|
|
53
|
-
I: Message;
|
|
54
|
-
O: Message;
|
|
55
|
-
};
|
|
56
|
-
};
|
|
54
|
+
export type GenDescServiceMethods = Record<string, Pick<DescMethod, "input" | "output" | "methodKind">>;
|
|
57
55
|
declare class brand<A, B = unknown> {
|
|
58
56
|
protected a: A | boolean;
|
|
59
57
|
protected b: B | boolean;
|
package/dist/cjs/create.d.ts
CHANGED
package/dist/cjs/create.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.create = void 0;
|
|
17
17
|
const is_message_js_1 = require("./is-message.js");
|
|
18
|
+
const descriptors_js_1 = require("./descriptors.js");
|
|
18
19
|
const scalar_js_1 = require("./reflect/scalar.js");
|
|
19
20
|
const guard_js_1 = require("./reflect/guard.js");
|
|
20
21
|
const unsafe_js_1 = require("./reflect/unsafe.js");
|
|
@@ -87,14 +88,14 @@ function initMessage(messageDesc, message, init) {
|
|
|
87
88
|
return message;
|
|
88
89
|
}
|
|
89
90
|
function initScalar(field, value) {
|
|
90
|
-
if (field.scalar ==
|
|
91
|
+
if (field.scalar == descriptors_js_1.ScalarType.BYTES) {
|
|
91
92
|
return toU8Arr(value);
|
|
92
93
|
}
|
|
93
94
|
return value;
|
|
94
95
|
}
|
|
95
96
|
function initMap(field, value) {
|
|
96
97
|
if ((0, guard_js_1.isObject)(value)) {
|
|
97
|
-
if (field.scalar ==
|
|
98
|
+
if (field.scalar == descriptors_js_1.ScalarType.BYTES) {
|
|
98
99
|
return convertObjectValues(value, toU8Arr);
|
|
99
100
|
}
|
|
100
101
|
if (field.mapKind == "message") {
|
|
@@ -105,7 +106,7 @@ function initMap(field, value) {
|
|
|
105
106
|
}
|
|
106
107
|
function initList(field, value) {
|
|
107
108
|
if (Array.isArray(value)) {
|
|
108
|
-
if (field.scalar ==
|
|
109
|
+
if (field.scalar == descriptors_js_1.ScalarType.BYTES) {
|
|
109
110
|
return value.map(toU8Arr);
|
|
110
111
|
}
|
|
111
112
|
if (field.listKind == "message") {
|
|
@@ -221,11 +222,11 @@ function createZeroField(field) {
|
|
|
221
222
|
}
|
|
222
223
|
const defaultValue = field.getDefaultValue();
|
|
223
224
|
if (defaultValue !== undefined) {
|
|
224
|
-
return field.fieldKind == "scalar" && field.
|
|
225
|
+
return field.fieldKind == "scalar" && field.longAsString
|
|
225
226
|
? defaultValue.toString()
|
|
226
227
|
: defaultValue;
|
|
227
228
|
}
|
|
228
229
|
return field.fieldKind == "scalar"
|
|
229
|
-
? (0, scalar_js_1.scalarZeroValue)(field.scalar, field.
|
|
230
|
+
? (0, scalar_js_1.scalarZeroValue)(field.scalar, field.longAsString)
|
|
230
231
|
: field.enum.values[0].number;
|
|
231
232
|
}
|
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
import type { DescriptorProto, Edition, EnumDescriptorProto, EnumValueDescriptorProto, FeatureSet_FieldPresence, FieldDescriptorProto, FileDescriptorProto, MethodDescriptorProto, MethodOptions_IdempotencyLevel, OneofDescriptorProto, ServiceDescriptorProto } from "./wkt/gen/google/protobuf/descriptor_pb.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ScalarValue } from "./reflect/scalar.js";
|
|
3
3
|
export type SupportedEdition = Extract<Edition, Edition.EDITION_PROTO2 | Edition.EDITION_PROTO3 | Edition.EDITION_2023>;
|
|
4
4
|
type SupportedFieldPresence = Extract<FeatureSet_FieldPresence, FeatureSet_FieldPresence.EXPLICIT | FeatureSet_FieldPresence.IMPLICIT | FeatureSet_FieldPresence.LEGACY_REQUIRED>;
|
|
5
|
+
/**
|
|
6
|
+
* Scalar value types. This is a subset of field types declared by protobuf
|
|
7
|
+
* enum google.protobuf.FieldDescriptorProto.Type The types GROUP and MESSAGE
|
|
8
|
+
* are omitted, but the numerical values are identical.
|
|
9
|
+
*/
|
|
10
|
+
export declare enum ScalarType {
|
|
11
|
+
DOUBLE = 1,
|
|
12
|
+
FLOAT = 2,
|
|
13
|
+
INT64 = 3,
|
|
14
|
+
UINT64 = 4,
|
|
15
|
+
INT32 = 5,
|
|
16
|
+
FIXED64 = 6,
|
|
17
|
+
FIXED32 = 7,
|
|
18
|
+
BOOL = 8,
|
|
19
|
+
STRING = 9,
|
|
20
|
+
BYTES = 12,
|
|
21
|
+
UINT32 = 13,
|
|
22
|
+
SFIXED32 = 15,
|
|
23
|
+
SFIXED64 = 16,
|
|
24
|
+
SINT32 = 17,// Uses ZigZag encoding.
|
|
25
|
+
SINT64 = 18
|
|
26
|
+
}
|
|
5
27
|
/**
|
|
6
28
|
* A union of all descriptors, discriminated by a `kind` property.
|
|
7
29
|
*/
|
|
@@ -281,10 +303,13 @@ type descFieldScalar<T extends ScalarType = ScalarType> = T extends T ? {
|
|
|
281
303
|
*/
|
|
282
304
|
readonly scalar: T;
|
|
283
305
|
/**
|
|
284
|
-
*
|
|
285
|
-
*
|
|
306
|
+
* By default, 64-bit integral types (int64, uint64, sint64, fixed64,
|
|
307
|
+
* sfixed64) are represented with BigInt.
|
|
308
|
+
*
|
|
309
|
+
* If the field option `jstype = JS_STRING` is set, this property
|
|
310
|
+
* is true, and 64-bit integral types are represented with String.
|
|
286
311
|
*/
|
|
287
|
-
readonly
|
|
312
|
+
readonly longAsString: boolean;
|
|
288
313
|
/**
|
|
289
314
|
* The message type, if it is a message field.
|
|
290
315
|
*/
|
|
@@ -369,10 +394,13 @@ type descFieldListScalar<T extends ScalarType = ScalarType> = T extends T ? {
|
|
|
369
394
|
*/
|
|
370
395
|
readonly scalar: T;
|
|
371
396
|
/**
|
|
372
|
-
*
|
|
373
|
-
*
|
|
397
|
+
* By default, 64-bit integral types (int64, uint64, sint64, fixed64,
|
|
398
|
+
* sfixed64) are represented with BigInt.
|
|
399
|
+
*
|
|
400
|
+
* If the field option `jstype = JS_STRING` is set, this property
|
|
401
|
+
* is true, and 64-bit integral types are represented with String.
|
|
374
402
|
*/
|
|
375
|
-
readonly
|
|
403
|
+
readonly longAsString: boolean;
|
|
376
404
|
} : never;
|
|
377
405
|
type descFieldListEnum = {
|
|
378
406
|
readonly listKind: "enum";
|
|
@@ -526,6 +554,10 @@ export interface DescService {
|
|
|
526
554
|
* The RPCs this service declares.
|
|
527
555
|
*/
|
|
528
556
|
readonly methods: DescMethod[];
|
|
557
|
+
/**
|
|
558
|
+
* All methods of this service by their "localName".
|
|
559
|
+
*/
|
|
560
|
+
readonly method: Record<string, DescMethod>;
|
|
529
561
|
/**
|
|
530
562
|
* Marked as deprecated in the protobuf source.
|
|
531
563
|
*/
|
|
@@ -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.ScalarType = void 0;
|
|
17
|
+
/**
|
|
18
|
+
* Scalar value types. This is a subset of field types declared by protobuf
|
|
19
|
+
* enum google.protobuf.FieldDescriptorProto.Type The types GROUP and MESSAGE
|
|
20
|
+
* are omitted, but the numerical values are identical.
|
|
21
|
+
*/
|
|
22
|
+
var ScalarType;
|
|
23
|
+
(function (ScalarType) {
|
|
24
|
+
// 0 is reserved for errors.
|
|
25
|
+
// Order is weird for historical reasons.
|
|
26
|
+
ScalarType[ScalarType["DOUBLE"] = 1] = "DOUBLE";
|
|
27
|
+
ScalarType[ScalarType["FLOAT"] = 2] = "FLOAT";
|
|
28
|
+
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
|
|
29
|
+
// negative values are likely.
|
|
30
|
+
ScalarType[ScalarType["INT64"] = 3] = "INT64";
|
|
31
|
+
ScalarType[ScalarType["UINT64"] = 4] = "UINT64";
|
|
32
|
+
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
|
|
33
|
+
// negative values are likely.
|
|
34
|
+
ScalarType[ScalarType["INT32"] = 5] = "INT32";
|
|
35
|
+
ScalarType[ScalarType["FIXED64"] = 6] = "FIXED64";
|
|
36
|
+
ScalarType[ScalarType["FIXED32"] = 7] = "FIXED32";
|
|
37
|
+
ScalarType[ScalarType["BOOL"] = 8] = "BOOL";
|
|
38
|
+
ScalarType[ScalarType["STRING"] = 9] = "STRING";
|
|
39
|
+
// Tag-delimited aggregate.
|
|
40
|
+
// Group type is deprecated and not supported in proto3. However, Proto3
|
|
41
|
+
// implementations should still be able to parse the group wire format and
|
|
42
|
+
// treat group fields as unknown fields.
|
|
43
|
+
// TYPE_GROUP = 10,
|
|
44
|
+
// TYPE_MESSAGE = 11, // Length-delimited aggregate.
|
|
45
|
+
// New in version 2.
|
|
46
|
+
ScalarType[ScalarType["BYTES"] = 12] = "BYTES";
|
|
47
|
+
ScalarType[ScalarType["UINT32"] = 13] = "UINT32";
|
|
48
|
+
// TYPE_ENUM = 14,
|
|
49
|
+
ScalarType[ScalarType["SFIXED32"] = 15] = "SFIXED32";
|
|
50
|
+
ScalarType[ScalarType["SFIXED64"] = 16] = "SFIXED64";
|
|
51
|
+
ScalarType[ScalarType["SINT32"] = 17] = "SINT32";
|
|
52
|
+
ScalarType[ScalarType["SINT64"] = 18] = "SINT64";
|
|
53
|
+
})(ScalarType || (exports.ScalarType = ScalarType = {}));
|
package/dist/cjs/equals.d.ts
CHANGED
package/dist/cjs/extensions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyDesc, DescEnum, DescEnumValue, DescExtension, DescField, DescFile, DescMessage, DescMethod, DescOneof, DescService } from "./
|
|
1
|
+
import type { AnyDesc, DescEnum, DescEnumValue, DescExtension, DescField, DescFile, DescMessage, DescMethod, DescOneof, DescService } from "./descriptors.js";
|
|
2
2
|
import type { ReflectMessage } from "./reflect/reflect-types.js";
|
|
3
3
|
import type { Extendee, ExtensionValueShape } from "./types.js";
|
|
4
4
|
import type { EnumOptions, EnumValueOptions, FieldOptions, FileOptions, MessageOptions, MethodOptions, OneofOptions, ServiceOptions } from "./wkt/gen/google/protobuf/descriptor_pb.js";
|
package/dist/cjs/extensions.js
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.createExtensionContainer = exports.getOption = exports.hasOption = exports.hasExtension = exports.clearExtension = exports.setExtension = exports.getExtension = void 0;
|
|
17
|
-
const assert_js_1 = require("./reflect/assert.js");
|
|
18
17
|
const create_js_1 = require("./create.js");
|
|
19
18
|
const from_binary_js_1 = require("./from-binary.js");
|
|
20
19
|
const reflect_js_1 = require("./reflect/reflect.js");
|
|
@@ -155,7 +154,7 @@ function createExtensionContainer(extension, value) {
|
|
|
155
154
|
// Only message fields are undefined, rest will have a zero value.
|
|
156
155
|
const desc = extension.message;
|
|
157
156
|
if ((0, wrappers_js_1.isWrapperDesc)(desc)) {
|
|
158
|
-
return (0, scalar_js_1.scalarZeroValue)(desc.fields[0].scalar, desc.fields[0].
|
|
157
|
+
return (0, scalar_js_1.scalarZeroValue)(desc.fields[0].scalar, desc.fields[0].longAsString);
|
|
159
158
|
}
|
|
160
159
|
return (0, create_js_1.create)(desc);
|
|
161
160
|
}
|
|
@@ -165,5 +164,7 @@ function createExtensionContainer(extension, value) {
|
|
|
165
164
|
}
|
|
166
165
|
exports.createExtensionContainer = createExtensionContainer;
|
|
167
166
|
function assertExtendee(extension, message) {
|
|
168
|
-
|
|
167
|
+
if (extension.extendee.typeName != message.$typeName) {
|
|
168
|
+
throw new Error(`extension ${extension.typeName} can only be applied to message ${extension.extendee.typeName}`);
|
|
169
|
+
}
|
|
169
170
|
}
|
package/dist/cjs/fields.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type DescField, type DescMessage } from "./descriptors.js";
|
|
2
2
|
import type { MessageShape } from "./types.js";
|
|
3
3
|
import type { ReflectMessage } from "./reflect/index.js";
|
|
4
4
|
import { BinaryReader, WireType } from "./wire/binary-encoding.js";
|
|
@@ -27,7 +27,7 @@ export declare function fromBinary<Desc extends DescMessage>(messageDesc: Desc,
|
|
|
27
27
|
* If a message field is already present, it will be merged with the
|
|
28
28
|
* new data.
|
|
29
29
|
*/
|
|
30
|
-
export declare function mergeFromBinary<Desc extends DescMessage>(messageDesc: Desc, target: MessageShape<Desc>, bytes: Uint8Array, options?: Partial<BinaryReadOptions>):
|
|
30
|
+
export declare function mergeFromBinary<Desc extends DescMessage>(messageDesc: Desc, target: MessageShape<Desc>, bytes: Uint8Array, options?: Partial<BinaryReadOptions>): void;
|
|
31
31
|
/**
|
|
32
32
|
* @private
|
|
33
33
|
*/
|