@bufbuild/protobuf 2.0.0-beta.1 → 2.0.0-beta.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 +15 -14
- package/dist/cjs/clone.js +1 -2
- package/dist/cjs/codegenv1/boot.js +2 -3
- package/dist/cjs/codegenv1/embed.js +3 -4
- package/dist/cjs/codegenv1/enum.d.ts +2 -2
- package/dist/cjs/codegenv1/enum.js +2 -3
- package/dist/cjs/codegenv1/extension.d.ts +2 -2
- package/dist/cjs/codegenv1/extension.js +1 -2
- package/dist/cjs/codegenv1/file.js +1 -2
- package/dist/cjs/codegenv1/message.d.ts +2 -2
- package/dist/cjs/codegenv1/message.js +1 -2
- package/dist/cjs/codegenv1/restore-json-names.js +1 -2
- package/dist/cjs/codegenv1/scalar.js +2 -3
- package/dist/cjs/codegenv1/service.d.ts +2 -2
- package/dist/cjs/codegenv1/service.js +1 -2
- package/dist/cjs/codegenv1/symbols.d.ts +5 -5
- package/dist/cjs/codegenv1/symbols.js +5 -5
- package/dist/cjs/codegenv1/types.d.ts +9 -7
- package/dist/cjs/create.js +5 -4
- package/dist/cjs/descriptors.d.ts +4 -0
- package/dist/cjs/equals.js +1 -2
- package/dist/cjs/extensions.js +7 -8
- package/dist/cjs/fields.js +2 -3
- package/dist/cjs/from-binary.js +3 -4
- package/dist/cjs/from-json.js +6 -7
- package/dist/cjs/is-message.js +1 -2
- package/dist/cjs/reflect/error.js +2 -2
- package/dist/cjs/reflect/guard.js +5 -6
- package/dist/cjs/reflect/names.js +2 -3
- package/dist/cjs/reflect/nested-types.js +2 -3
- package/dist/cjs/reflect/reflect-check.js +4 -5
- package/dist/cjs/reflect/reflect.js +3 -4
- package/dist/cjs/reflect/scalar.js +3 -4
- package/dist/cjs/reflect/unsafe.js +7 -7
- package/dist/cjs/registry.js +16 -10
- package/dist/cjs/to-binary.js +2 -3
- package/dist/cjs/to-json.js +5 -6
- package/dist/cjs/types.d.ts +8 -8
- package/dist/cjs/wire/base64-encoding.js +2 -3
- package/dist/cjs/wire/size-delimited.d.ts +1 -1
- package/dist/cjs/wire/size-delimited.js +3 -4
- package/dist/cjs/wire/text-encoding.js +2 -3
- package/dist/cjs/wire/text-format.js +2 -3
- package/dist/cjs/wire/varint.js +7 -8
- package/dist/cjs/wkt/any.js +4 -5
- package/dist/cjs/wkt/gen/google/protobuf/any_pb.d.ts +3 -3
- package/dist/cjs/wkt/gen/google/protobuf/api_pb.d.ts +5 -5
- package/dist/cjs/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +7 -7
- package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.d.ts +52 -52
- package/dist/cjs/wkt/gen/google/protobuf/duration_pb.d.ts +3 -3
- package/dist/cjs/wkt/gen/google/protobuf/empty_pb.d.ts +3 -3
- package/dist/cjs/wkt/gen/google/protobuf/field_mask_pb.d.ts +3 -3
- package/dist/cjs/wkt/gen/google/protobuf/source_context_pb.d.ts +3 -3
- package/dist/cjs/wkt/gen/google/protobuf/struct_pb.d.ts +6 -6
- package/dist/cjs/wkt/gen/google/protobuf/timestamp_pb.d.ts +3 -3
- package/dist/cjs/wkt/gen/google/protobuf/type_pb.d.ts +10 -10
- package/dist/cjs/wkt/gen/google/protobuf/wrappers_pb.d.ts +11 -11
- package/dist/cjs/wkt/timestamp.js +5 -6
- package/dist/cjs/wkt/wrappers.js +2 -3
- package/dist/esm/codegenv1/enum.d.ts +2 -2
- package/dist/esm/codegenv1/extension.d.ts +2 -2
- package/dist/esm/codegenv1/message.d.ts +2 -2
- package/dist/esm/codegenv1/service.d.ts +2 -2
- package/dist/esm/codegenv1/symbols.d.ts +5 -5
- package/dist/esm/codegenv1/symbols.js +5 -5
- package/dist/esm/codegenv1/types.d.ts +9 -7
- package/dist/esm/create.js +4 -2
- package/dist/esm/descriptors.d.ts +4 -0
- package/dist/esm/registry.js +12 -6
- package/dist/esm/to-json.js +2 -2
- package/dist/esm/types.d.ts +8 -8
- package/dist/esm/wire/size-delimited.d.ts +1 -1
- package/dist/esm/wkt/gen/google/protobuf/any_pb.d.ts +3 -3
- package/dist/esm/wkt/gen/google/protobuf/api_pb.d.ts +5 -5
- package/dist/esm/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +7 -7
- package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.d.ts +52 -52
- package/dist/esm/wkt/gen/google/protobuf/duration_pb.d.ts +3 -3
- package/dist/esm/wkt/gen/google/protobuf/empty_pb.d.ts +3 -3
- package/dist/esm/wkt/gen/google/protobuf/field_mask_pb.d.ts +3 -3
- package/dist/esm/wkt/gen/google/protobuf/source_context_pb.d.ts +3 -3
- package/dist/esm/wkt/gen/google/protobuf/struct_pb.d.ts +6 -6
- package/dist/esm/wkt/gen/google/protobuf/timestamp_pb.d.ts +3 -3
- package/dist/esm/wkt/gen/google/protobuf/type_pb.d.ts +10 -10
- package/dist/esm/wkt/gen/google/protobuf/wrappers_pb.d.ts +11 -11
- package/package.json +14 -7
package/README.md
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
# @bufbuild/protobuf
|
|
2
2
|
|
|
3
|
-
This package provides the runtime library for the
|
|
4
|
-
|
|
3
|
+
This package provides the runtime library for the [protoc-gen-es](https://www.npmjs.com/package/@bufbuild/protoc-gen-es)
|
|
4
|
+
code generator plugin.
|
|
5
5
|
|
|
6
6
|
## Protocol Buffers for ECMAScript
|
|
7
7
|
|
|
8
|
-
A complete implementation of [Protocol Buffers](https://
|
|
9
|
-
suitable for web browsers and Node.js.
|
|
8
|
+
A complete implementation of [Protocol Buffers](https://protobuf.dev/) in TypeScript,
|
|
9
|
+
suitable for web browsers and Node.js, created by [Buf](https://buf.build).
|
|
10
10
|
|
|
11
|
-
**Protobuf-ES** is
|
|
11
|
+
**Protobuf-ES** is a solid, modern alternative to existing Protobuf implementations for the JavaScript ecosystem. It's
|
|
12
|
+
the first project in this space to provide a comprehensive plugin framework and decouple the base types from RPC
|
|
13
|
+
functionality.
|
|
12
14
|
|
|
13
15
|
Some additional features that set it apart from the others:
|
|
14
16
|
|
|
15
17
|
- ECMAScript module support
|
|
16
18
|
- First-class TypeScript support
|
|
17
|
-
- Generation of idiomatic JavaScript and TypeScript code
|
|
18
|
-
- Generation of [much smaller bundles](https://github.com/bufbuild/protobuf-es/
|
|
19
|
-
- Implementation of all proto3 features, including the [canonical JSON format](https://
|
|
20
|
-
- Implementation of all proto2 features, except for extensions and the text format
|
|
19
|
+
- Generation of idiomatic JavaScript and TypeScript code
|
|
20
|
+
- Generation of [much smaller bundles](https://github.com/bufbuild/protobuf-es/tree/main/packages/bundle-size/)
|
|
21
|
+
- Implementation of all proto3 features, including the [canonical JSON format](https://protobuf.dev/programming-guides/proto3/#json)
|
|
22
|
+
- Implementation of all proto2 features, except for extensions and the text format
|
|
21
23
|
- Usage of standard JavaScript APIs instead of the [Closure Library](http://googlecode.blogspot.com/2009/11/introducing-closure-tools.html)
|
|
22
|
-
- Compatibility is covered by the
|
|
24
|
+
- Compatibility is covered by the Protocol Buffers [conformance tests](https://github.com/bufbuild/protobuf-es/tree/main/packages/protobuf-conformance/)
|
|
23
25
|
- Descriptor and reflection support
|
|
24
26
|
|
|
25
27
|
## Installation
|
|
@@ -30,14 +32,13 @@ npm install @bufbuild/protobuf
|
|
|
30
32
|
|
|
31
33
|
## Documentation
|
|
32
34
|
|
|
33
|
-
To learn how to work with `@bufbuild/protobuf
|
|
34
|
-
and the [generated code](https://github.com/bufbuild/protobuf-es/
|
|
35
|
+
To learn how to work with `@bufbuild/protobuf`, check out the docs for the [Runtime API](https://github.com/bufbuild/protobuf-es/tree/main/MANUAL.md#working-with-messages)
|
|
36
|
+
and the [generated code](https://github.com/bufbuild/protobuf-es/tree/main/MANUAL.md#generated-code).
|
|
35
37
|
|
|
36
38
|
Official documentation for the Protobuf-ES project can be found at [github.com/bufbuild/protobuf-es](https://github.com/bufbuild/protobuf-es).
|
|
37
39
|
|
|
38
|
-
For more information on Buf, check out the official [Buf documentation](https://
|
|
40
|
+
For more information on Buf, check out the official [Buf documentation](https://buf.build/docs/).
|
|
39
41
|
|
|
40
42
|
## Examples
|
|
41
43
|
|
|
42
44
|
A complete code example can be found in the **Protobuf-ES** repo [here](https://github.com/bufbuild/protobuf-es/tree/main/packages/protobuf-example).
|
|
43
|
-
|
package/dist/cjs/clone.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.clone =
|
|
16
|
+
exports.clone = clone;
|
|
17
17
|
const descriptors_js_1 = require("./descriptors.js");
|
|
18
18
|
const reflect_js_1 = require("./reflect/reflect.js");
|
|
19
19
|
const guard_js_1 = require("./reflect/guard.js");
|
|
@@ -23,7 +23,6 @@ const guard_js_1 = require("./reflect/guard.js");
|
|
|
23
23
|
function clone(schema, message) {
|
|
24
24
|
return cloneReflect((0, reflect_js_1.reflect)(schema, message)).message;
|
|
25
25
|
}
|
|
26
|
-
exports.clone = clone;
|
|
27
26
|
function cloneReflect(i) {
|
|
28
27
|
const o = (0, reflect_js_1.reflect)(i.desc);
|
|
29
28
|
for (const f of i.fields) {
|
|
@@ -13,7 +13,8 @@
|
|
|
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.
|
|
16
|
+
exports.boot = boot;
|
|
17
|
+
exports.bootFileDescriptorProto = bootFileDescriptorProto;
|
|
17
18
|
const restore_json_names_js_1 = require("./restore-json-names.js");
|
|
18
19
|
const registry_js_1 = require("../registry.js");
|
|
19
20
|
/**
|
|
@@ -31,7 +32,6 @@ function boot(boot) {
|
|
|
31
32
|
// non-null assertion because we just created the registry from the file we look up
|
|
32
33
|
return reg.getFile(root.name);
|
|
33
34
|
}
|
|
34
|
-
exports.boot = boot;
|
|
35
35
|
/**
|
|
36
36
|
* Creates the message google.protobuf.FileDescriptorProto from an object literal.
|
|
37
37
|
*
|
|
@@ -46,7 +46,6 @@ function bootFileDescriptorProto(init) {
|
|
|
46
46
|
});
|
|
47
47
|
return Object.assign(proto, Object.assign(Object.assign({ $typeName: "google.protobuf.FileDescriptorProto", dependency: [], publicDependency: [], weakDependency: [], service: [], extension: [] }, init), { messageType: init.messageType.map(bootDescriptorProto), enumType: init.enumType.map(bootEnumDescriptorProto) }));
|
|
48
48
|
}
|
|
49
|
-
exports.bootFileDescriptorProto = bootFileDescriptorProto;
|
|
50
49
|
function bootDescriptorProto(init) {
|
|
51
50
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
52
51
|
return {
|
|
@@ -13,7 +13,9 @@
|
|
|
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.
|
|
16
|
+
exports.embedFileDesc = embedFileDesc;
|
|
17
|
+
exports.pathInFileDesc = pathInFileDesc;
|
|
18
|
+
exports.createFileDescriptorProtoBoot = createFileDescriptorProtoBoot;
|
|
17
19
|
const names_js_1 = require("../reflect/names.js");
|
|
18
20
|
const fields_js_1 = require("../fields.js");
|
|
19
21
|
const base64_encoding_js_1 = require("../wire/base64-encoding.js");
|
|
@@ -46,7 +48,6 @@ function embedFileDesc(file) {
|
|
|
46
48
|
return createFileDescriptorProtoBoot(this.proto());
|
|
47
49
|
} }) : embed;
|
|
48
50
|
}
|
|
49
|
-
exports.embedFileDesc = embedFileDesc;
|
|
50
51
|
function stripJsonNames(d) {
|
|
51
52
|
for (const f of d.field) {
|
|
52
53
|
if (f.jsonName === (0, names_js_1.protoCamelCase)(f.name)) {
|
|
@@ -99,7 +100,6 @@ function pathInFileDesc(desc) {
|
|
|
99
100
|
return [...path, parent.nestedEnums.indexOf(desc)];
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
|
-
exports.pathInFileDesc = pathInFileDesc;
|
|
103
103
|
/**
|
|
104
104
|
* The file descriptor for google/protobuf/descriptor.proto cannot be embedded
|
|
105
105
|
* in serialized form, since it is required to parse itself.
|
|
@@ -135,7 +135,6 @@ function createFileDescriptorProtoBoot(proto) {
|
|
|
135
135
|
enumType: proto.enumType.map(createEnumDescriptorBoot),
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
|
-
exports.createFileDescriptorProtoBoot = createFileDescriptorProtoBoot;
|
|
139
138
|
function createDescriptorBoot(proto) {
|
|
140
139
|
assert(proto.extension.length == 0);
|
|
141
140
|
assert(!proto.oneofDecl.length);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { DescEnum, DescFile } from "../descriptors.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { GenEnum } from "./types.js";
|
|
3
3
|
import type { JsonValue } from "../json-value.js";
|
|
4
4
|
/**
|
|
5
5
|
* Hydrate an enum descriptor.
|
|
6
6
|
*
|
|
7
7
|
* @private
|
|
8
8
|
*/
|
|
9
|
-
export declare function enumDesc<Shape, JsonType extends JsonValue = JsonValue>(file: DescFile, path: number, ...paths: number[]):
|
|
9
|
+
export declare function enumDesc<Shape extends number, JsonType extends JsonValue = JsonValue>(file: DescFile, path: number, ...paths: number[]): GenEnum<Shape, JsonType>;
|
|
10
10
|
/**
|
|
11
11
|
* Construct a TypeScript enum object at runtime from a descriptor.
|
|
12
12
|
*/
|
|
@@ -13,7 +13,8 @@
|
|
|
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.
|
|
16
|
+
exports.enumDesc = enumDesc;
|
|
17
|
+
exports.tsEnum = tsEnum;
|
|
17
18
|
/**
|
|
18
19
|
* Hydrate an enum descriptor.
|
|
19
20
|
*
|
|
@@ -26,7 +27,6 @@ function enumDesc(file, path, ...paths) {
|
|
|
26
27
|
const e = paths.pop(); // we checked length above
|
|
27
28
|
return paths.reduce((acc, cur) => acc.nestedMessages[cur], file.messages[path]).nestedEnums[e];
|
|
28
29
|
}
|
|
29
|
-
exports.enumDesc = enumDesc;
|
|
30
30
|
/**
|
|
31
31
|
* Construct a TypeScript enum object at runtime from a descriptor.
|
|
32
32
|
*/
|
|
@@ -38,4 +38,3 @@ function tsEnum(desc) {
|
|
|
38
38
|
}
|
|
39
39
|
return enumObject;
|
|
40
40
|
}
|
|
41
|
-
exports.tsEnum = tsEnum;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Message } from "../types.js";
|
|
2
2
|
import type { DescFile } from "../descriptors.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { GenExtension } from "./types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Hydrate an extension descriptor.
|
|
6
6
|
*
|
|
7
7
|
* @private
|
|
8
8
|
*/
|
|
9
|
-
export declare function extDesc<Extendee extends Message, Value>(file: DescFile, path: number, ...paths: number[]):
|
|
9
|
+
export declare function extDesc<Extendee extends Message, Value>(file: DescFile, path: number, ...paths: number[]): GenExtension<Extendee, Value>;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.extDesc =
|
|
16
|
+
exports.extDesc = extDesc;
|
|
17
17
|
/**
|
|
18
18
|
* Hydrate an extension descriptor.
|
|
19
19
|
*
|
|
@@ -26,4 +26,3 @@ function extDesc(file, path, ...paths) {
|
|
|
26
26
|
const e = paths.pop(); // we checked length above
|
|
27
27
|
return paths.reduce((acc, cur) => acc.nestedMessages[cur], file.messages[path]).nestedExtensions[e];
|
|
28
28
|
}
|
|
29
|
-
exports.extDesc = extDesc;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.fileDesc =
|
|
16
|
+
exports.fileDesc = fileDesc;
|
|
17
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
19
|
const registry_js_1 = require("../registry.js");
|
|
@@ -33,4 +33,3 @@ function fileDesc(b64, imports) {
|
|
|
33
33
|
// non-null assertion because we just created the registry from the file we look up
|
|
34
34
|
return reg.getFile(root.name);
|
|
35
35
|
}
|
|
36
|
-
exports.fileDesc = fileDesc;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Message } from "../types.js";
|
|
2
2
|
import type { DescFile } from "../descriptors.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { GenMessage } from "./types.js";
|
|
4
4
|
import type { JsonValue } from "../json-value.js";
|
|
5
5
|
/**
|
|
6
6
|
* Hydrate a message descriptor.
|
|
7
7
|
*
|
|
8
8
|
* @private
|
|
9
9
|
*/
|
|
10
|
-
export declare function messageDesc<Shape extends Message, JsonType extends JsonValue = JsonValue>(file: DescFile, path: number, ...paths: number[]):
|
|
10
|
+
export declare function messageDesc<Shape extends Message, JsonType extends JsonValue = JsonValue>(file: DescFile, path: number, ...paths: number[]): GenMessage<Shape, JsonType>;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.messageDesc =
|
|
16
|
+
exports.messageDesc = messageDesc;
|
|
17
17
|
/**
|
|
18
18
|
* Hydrate a message descriptor.
|
|
19
19
|
*
|
|
@@ -22,4 +22,3 @@ exports.messageDesc = void 0;
|
|
|
22
22
|
function messageDesc(file, path, ...paths) {
|
|
23
23
|
return paths.reduce((acc, cur) => acc.nestedMessages[cur], file.messages[path]);
|
|
24
24
|
}
|
|
25
|
-
exports.messageDesc = messageDesc;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.restoreJsonNames =
|
|
16
|
+
exports.restoreJsonNames = restoreJsonNames;
|
|
17
17
|
const names_js_1 = require("../reflect/names.js");
|
|
18
18
|
const unsafe_js_1 = require("../reflect/unsafe.js");
|
|
19
19
|
/**
|
|
@@ -27,4 +27,3 @@ function restoreJsonNames(message) {
|
|
|
27
27
|
}
|
|
28
28
|
message.nestedType.forEach(restoreJsonNames);
|
|
29
29
|
}
|
|
30
|
-
exports.restoreJsonNames = restoreJsonNames;
|
|
@@ -13,7 +13,8 @@
|
|
|
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.
|
|
16
|
+
exports.scalarTypeScriptType = scalarTypeScriptType;
|
|
17
|
+
exports.scalarJsonType = scalarJsonType;
|
|
17
18
|
const descriptors_js_1 = require("../descriptors.js");
|
|
18
19
|
/**
|
|
19
20
|
* Return the TypeScript type (as a string) for the given scalar type.
|
|
@@ -36,7 +37,6 @@ function scalarTypeScriptType(scalar, longAsString) {
|
|
|
36
37
|
return "number";
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
|
-
exports.scalarTypeScriptType = scalarTypeScriptType;
|
|
40
40
|
/**
|
|
41
41
|
* Return the JSON type (as a string) for the given scalar type.
|
|
42
42
|
*/
|
|
@@ -65,4 +65,3 @@ function scalarJsonType(scalar) {
|
|
|
65
65
|
return "string";
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
exports.scalarJsonType = scalarJsonType;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GenService, GenServiceMethods } from "./types.js";
|
|
2
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 GenServiceMethods>(file: DescFile, path: number, ...paths: number[]): GenService<T>;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.serviceDesc =
|
|
16
|
+
exports.serviceDesc = serviceDesc;
|
|
17
17
|
/**
|
|
18
18
|
* Hydrate a service descriptor.
|
|
19
19
|
*
|
|
@@ -25,4 +25,3 @@ function serviceDesc(file, path, ...paths) {
|
|
|
25
25
|
}
|
|
26
26
|
return file.services[path];
|
|
27
27
|
}
|
|
28
|
-
exports.serviceDesc = serviceDesc;
|
|
@@ -106,27 +106,27 @@ export declare const symbols: {
|
|
|
106
106
|
readonly bootstrapWktFrom: "../../codegenv1/enum.js";
|
|
107
107
|
readonly from: string;
|
|
108
108
|
};
|
|
109
|
-
readonly
|
|
109
|
+
readonly GenFile: {
|
|
110
110
|
readonly typeOnly: true;
|
|
111
111
|
readonly bootstrapWktFrom: "../../codegenv1/types.js";
|
|
112
112
|
readonly from: string;
|
|
113
113
|
};
|
|
114
|
-
readonly
|
|
114
|
+
readonly GenEnum: {
|
|
115
115
|
readonly typeOnly: true;
|
|
116
116
|
readonly bootstrapWktFrom: "../../codegenv1/types.js";
|
|
117
117
|
readonly from: string;
|
|
118
118
|
};
|
|
119
|
-
readonly
|
|
119
|
+
readonly GenExtension: {
|
|
120
120
|
readonly typeOnly: true;
|
|
121
121
|
readonly bootstrapWktFrom: "../../codegenv1/types.js";
|
|
122
122
|
readonly from: string;
|
|
123
123
|
};
|
|
124
|
-
readonly
|
|
124
|
+
readonly GenMessage: {
|
|
125
125
|
readonly typeOnly: true;
|
|
126
126
|
readonly bootstrapWktFrom: "../../codegenv1/types.js";
|
|
127
127
|
readonly from: string;
|
|
128
128
|
};
|
|
129
|
-
readonly
|
|
129
|
+
readonly GenService: {
|
|
130
130
|
readonly typeOnly: true;
|
|
131
131
|
readonly bootstrapWktFrom: "../../codegenv1/types.js";
|
|
132
132
|
readonly from: string;
|
|
@@ -60,10 +60,10 @@ exports.symbols = {
|
|
|
60
60
|
messageDesc: { typeOnly: false, bootstrapWktFrom: "../../codegenv1/message.js", from: exports.packageName + "/codegenv1" },
|
|
61
61
|
serviceDesc: { typeOnly: false, bootstrapWktFrom: "../../codegenv1/service.js", from: exports.packageName + "/codegenv1" },
|
|
62
62
|
tsEnum: { typeOnly: false, bootstrapWktFrom: "../../codegenv1/enum.js", from: exports.packageName + "/codegenv1" },
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
GenFile: { typeOnly: true, bootstrapWktFrom: "../../codegenv1/types.js", from: exports.packageName + "/codegenv1" },
|
|
64
|
+
GenEnum: { typeOnly: true, bootstrapWktFrom: "../../codegenv1/types.js", from: exports.packageName + "/codegenv1" },
|
|
65
|
+
GenExtension: { typeOnly: true, bootstrapWktFrom: "../../codegenv1/types.js", from: exports.packageName + "/codegenv1" },
|
|
66
|
+
GenMessage: { typeOnly: true, bootstrapWktFrom: "../../codegenv1/types.js", from: exports.packageName + "/codegenv1" },
|
|
67
|
+
GenService: { typeOnly: true, bootstrapWktFrom: "../../codegenv1/types.js", from: exports.packageName + "/codegenv1" },
|
|
68
68
|
},
|
|
69
69
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Message } from "../types.js";
|
|
2
|
-
import type { DescEnum, DescExtension, DescField, DescFile, DescMessage, DescMethod, DescService } from "../descriptors.js";
|
|
2
|
+
import type { DescEnum, DescEnumValue, DescExtension, DescField, DescFile, DescMessage, DescMethod, DescService } from "../descriptors.js";
|
|
3
3
|
import type { JsonValue } from "../json-value.js";
|
|
4
4
|
/**
|
|
5
5
|
* Describes a protobuf source file.
|
|
6
6
|
*
|
|
7
7
|
* @private
|
|
8
8
|
*/
|
|
9
|
-
export type
|
|
9
|
+
export type GenFile = DescFile;
|
|
10
10
|
/**
|
|
11
11
|
* Describes a message declaration in a protobuf source file.
|
|
12
12
|
*
|
|
@@ -15,7 +15,7 @@ export type GenDescFile = DescFile;
|
|
|
15
15
|
*
|
|
16
16
|
* @private
|
|
17
17
|
*/
|
|
18
|
-
export type
|
|
18
|
+
export type GenMessage<RuntimeShape extends Message, JsonType = JsonValue> = Omit<DescMessage, "field"> & {
|
|
19
19
|
field: Record<MessageFieldNames<RuntimeShape>, DescField>;
|
|
20
20
|
} & brandv1<RuntimeShape, JsonType>;
|
|
21
21
|
/**
|
|
@@ -26,7 +26,9 @@ export type GenDescMessage<RuntimeShape extends Message, JsonType = JsonValue> =
|
|
|
26
26
|
*
|
|
27
27
|
* @private
|
|
28
28
|
*/
|
|
29
|
-
export type
|
|
29
|
+
export type GenEnum<RuntimeShape extends number, JsonType extends JsonValue = JsonValue> = Omit<DescEnum, "value"> & {
|
|
30
|
+
value: Record<RuntimeShape, DescEnumValue>;
|
|
31
|
+
} & brandv1<RuntimeShape, JsonType>;
|
|
30
32
|
/**
|
|
31
33
|
* Describes an extension in a protobuf source file.
|
|
32
34
|
*
|
|
@@ -35,7 +37,7 @@ export type GenDescEnum<RuntimeShape, JsonType extends JsonValue = JsonValue> =
|
|
|
35
37
|
*
|
|
36
38
|
* @private
|
|
37
39
|
*/
|
|
38
|
-
export type
|
|
40
|
+
export type GenExtension<Extendee extends Message = Message, RuntimeShape = unknown> = DescExtension & brandv1<Extendee, RuntimeShape>;
|
|
39
41
|
/**
|
|
40
42
|
* Describes a service declaration in a protobuf source file.
|
|
41
43
|
*
|
|
@@ -44,7 +46,7 @@ export type GenDescExtension<Extendee extends Message = Message, RuntimeShape =
|
|
|
44
46
|
*
|
|
45
47
|
* @private
|
|
46
48
|
*/
|
|
47
|
-
export type
|
|
49
|
+
export type GenService<RuntimeShape extends GenServiceMethods> = Omit<DescService, "method"> & {
|
|
48
50
|
method: {
|
|
49
51
|
[K in keyof RuntimeShape]: RuntimeShape[K] & DescMethod;
|
|
50
52
|
};
|
|
@@ -52,7 +54,7 @@ export type GenDescService<RuntimeShape extends GenDescServiceMethods> = Omit<De
|
|
|
52
54
|
/**
|
|
53
55
|
* @private
|
|
54
56
|
*/
|
|
55
|
-
export type
|
|
57
|
+
export type GenServiceMethods = Record<string, Pick<DescMethod, "input" | "output" | "methodKind">>;
|
|
56
58
|
declare class brandv1<A, B = unknown> {
|
|
57
59
|
protected v: "codegenv1";
|
|
58
60
|
protected a: A | boolean;
|
package/dist/cjs/create.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.create =
|
|
16
|
+
exports.create = create;
|
|
17
17
|
const is_message_js_1 = require("./is-message.js");
|
|
18
18
|
const descriptors_js_1 = require("./descriptors.js");
|
|
19
19
|
const scalar_js_1 = require("./reflect/scalar.js");
|
|
@@ -42,7 +42,6 @@ function create(schema, init) {
|
|
|
42
42
|
}
|
|
43
43
|
return message;
|
|
44
44
|
}
|
|
45
|
-
exports.create = create;
|
|
46
45
|
/**
|
|
47
46
|
* Sets field values from a MessageInitShape on a zero message.
|
|
48
47
|
*/
|
|
@@ -152,7 +151,9 @@ const messagePrototypes = new WeakMap();
|
|
|
152
151
|
function createZeroMessage(desc) {
|
|
153
152
|
let msg;
|
|
154
153
|
if (!needsPrototypeChain(desc)) {
|
|
155
|
-
msg = {
|
|
154
|
+
msg = {
|
|
155
|
+
$typeName: desc.typeName,
|
|
156
|
+
};
|
|
156
157
|
for (const member of desc.members) {
|
|
157
158
|
if (member.kind == "oneof" || member.presence == IMPLICIT) {
|
|
158
159
|
msg[member.localName] = createZeroField(member);
|
|
@@ -192,6 +193,7 @@ function createZeroMessage(desc) {
|
|
|
192
193
|
messagePrototypes.set(desc, { prototype, members });
|
|
193
194
|
}
|
|
194
195
|
msg = Object.create(prototype);
|
|
196
|
+
msg.$typeName = desc.typeName;
|
|
195
197
|
for (const member of desc.members) {
|
|
196
198
|
if (members.has(member)) {
|
|
197
199
|
continue;
|
|
@@ -209,7 +211,6 @@ function createZeroMessage(desc) {
|
|
|
209
211
|
msg[member.localName] = createZeroField(member);
|
|
210
212
|
}
|
|
211
213
|
}
|
|
212
|
-
msg.$typeName = desc.typeName;
|
|
213
214
|
return msg;
|
|
214
215
|
}
|
|
215
216
|
/**
|
|
@@ -106,6 +106,10 @@ export interface DescEnum {
|
|
|
106
106
|
* Values declared for this enumeration.
|
|
107
107
|
*/
|
|
108
108
|
readonly values: DescEnumValue[];
|
|
109
|
+
/**
|
|
110
|
+
* All values of this enum by their number.
|
|
111
|
+
*/
|
|
112
|
+
readonly value: Record<number, DescEnumValue>;
|
|
109
113
|
/**
|
|
110
114
|
* A prefix shared by all enum values.
|
|
111
115
|
* For example, `my_enum_` for `enum MyEnum {MY_ENUM_A=0; MY_ENUM_B=1;}`
|
package/dist/cjs/equals.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.equals =
|
|
16
|
+
exports.equals = equals;
|
|
17
17
|
const scalar_js_1 = require("./reflect/scalar.js");
|
|
18
18
|
const reflect_js_1 = require("./reflect/reflect.js");
|
|
19
19
|
/**
|
|
@@ -31,7 +31,6 @@ function equals(schema, a, b) {
|
|
|
31
31
|
}
|
|
32
32
|
return reflectEquals((0, reflect_js_1.reflect)(schema, a), (0, reflect_js_1.reflect)(schema, b));
|
|
33
33
|
}
|
|
34
|
-
exports.equals = equals;
|
|
35
34
|
function reflectEquals(a, b) {
|
|
36
35
|
for (const f of a.fields) {
|
|
37
36
|
if (!fieldEquals(f, a, b)) {
|
package/dist/cjs/extensions.js
CHANGED
|
@@ -13,7 +13,13 @@
|
|
|
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.
|
|
16
|
+
exports.getExtension = getExtension;
|
|
17
|
+
exports.setExtension = setExtension;
|
|
18
|
+
exports.clearExtension = clearExtension;
|
|
19
|
+
exports.hasExtension = hasExtension;
|
|
20
|
+
exports.hasOption = hasOption;
|
|
21
|
+
exports.getOption = getOption;
|
|
22
|
+
exports.createExtensionContainer = createExtensionContainer;
|
|
17
23
|
const create_js_1 = require("./create.js");
|
|
18
24
|
const from_binary_js_1 = require("./from-binary.js");
|
|
19
25
|
const reflect_js_1 = require("./reflect/reflect.js");
|
|
@@ -46,7 +52,6 @@ function getExtension(message, extension) {
|
|
|
46
52
|
}
|
|
47
53
|
return get();
|
|
48
54
|
}
|
|
49
|
-
exports.getExtension = getExtension;
|
|
50
55
|
/**
|
|
51
56
|
* Set an extension value on a message. If the message already has a value for
|
|
52
57
|
* this extension, the value is replaced.
|
|
@@ -68,7 +73,6 @@ function setExtension(message, extension, value) {
|
|
|
68
73
|
}
|
|
69
74
|
message.$unknown = ufs;
|
|
70
75
|
}
|
|
71
|
-
exports.setExtension = setExtension;
|
|
72
76
|
/**
|
|
73
77
|
* Remove an extension value from a message.
|
|
74
78
|
*
|
|
@@ -81,7 +85,6 @@ function clearExtension(message, extension) {
|
|
|
81
85
|
}
|
|
82
86
|
message.$unknown = message.$unknown.filter((uf) => uf.no !== extension.number);
|
|
83
87
|
}
|
|
84
|
-
exports.clearExtension = clearExtension;
|
|
85
88
|
/**
|
|
86
89
|
* Check whether an extension is set on a message.
|
|
87
90
|
*/
|
|
@@ -90,7 +93,6 @@ function hasExtension(message, extension) {
|
|
|
90
93
|
return (extension.extendee.typeName === message.$typeName &&
|
|
91
94
|
!!((_a = message.$unknown) === null || _a === void 0 ? void 0 : _a.find((uf) => uf.no === extension.number)));
|
|
92
95
|
}
|
|
93
|
-
exports.hasExtension = hasExtension;
|
|
94
96
|
/**
|
|
95
97
|
* Check whether an option is set on a descriptor.
|
|
96
98
|
*
|
|
@@ -105,7 +107,6 @@ function hasOption(element, option) {
|
|
|
105
107
|
}
|
|
106
108
|
return hasExtension(message, option);
|
|
107
109
|
}
|
|
108
|
-
exports.hasOption = hasOption;
|
|
109
110
|
/**
|
|
110
111
|
* Retrieve an option value from a descriptor.
|
|
111
112
|
*
|
|
@@ -122,7 +123,6 @@ function getOption(element, option) {
|
|
|
122
123
|
}
|
|
123
124
|
return getExtension(message, option);
|
|
124
125
|
}
|
|
125
|
-
exports.getOption = getOption;
|
|
126
126
|
function filterUnknownFields(unknownFields, extension) {
|
|
127
127
|
if (unknownFields === undefined)
|
|
128
128
|
return [];
|
|
@@ -162,7 +162,6 @@ function createExtensionContainer(extension, value) {
|
|
|
162
162
|
},
|
|
163
163
|
];
|
|
164
164
|
}
|
|
165
|
-
exports.createExtensionContainer = createExtensionContainer;
|
|
166
165
|
function assertExtendee(extension, message) {
|
|
167
166
|
if (extension.extendee.typeName != message.$typeName) {
|
|
168
167
|
throw new Error(`extension ${extension.typeName} can only be applied to message ${extension.extendee.typeName}`);
|
package/dist/cjs/fields.js
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
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.
|
|
16
|
+
exports.isFieldSet = isFieldSet;
|
|
17
|
+
exports.clearField = clearField;
|
|
17
18
|
const unsafe_js_1 = require("./reflect/unsafe.js");
|
|
18
19
|
/**
|
|
19
20
|
* Returns true if the field is set.
|
|
@@ -34,7 +35,6 @@ const unsafe_js_1 = require("./reflect/unsafe.js");
|
|
|
34
35
|
function isFieldSet(message, field) {
|
|
35
36
|
return (field.parent.typeName == message.$typeName && (0, unsafe_js_1.unsafeIsSet)(message, field));
|
|
36
37
|
}
|
|
37
|
-
exports.isFieldSet = isFieldSet;
|
|
38
38
|
/**
|
|
39
39
|
* Resets the field, so that isFieldSet() will return false.
|
|
40
40
|
*/
|
|
@@ -43,4 +43,3 @@ function clearField(message, field) {
|
|
|
43
43
|
(0, unsafe_js_1.unsafeClear)(message, field);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
exports.clearField = clearField;
|
package/dist/cjs/from-binary.js
CHANGED
|
@@ -13,7 +13,9 @@
|
|
|
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.
|
|
16
|
+
exports.fromBinary = fromBinary;
|
|
17
|
+
exports.mergeFromBinary = mergeFromBinary;
|
|
18
|
+
exports.readField = readField;
|
|
17
19
|
const descriptors_js_1 = require("./descriptors.js");
|
|
18
20
|
const scalar_js_1 = require("./reflect/scalar.js");
|
|
19
21
|
const reflect_js_1 = require("./reflect/reflect.js");
|
|
@@ -33,7 +35,6 @@ function fromBinary(schema, bytes, options) {
|
|
|
33
35
|
readMessage(msg, new binary_encoding_js_1.BinaryReader(bytes), makeReadOptions(options), false, bytes.byteLength);
|
|
34
36
|
return msg.message;
|
|
35
37
|
}
|
|
36
|
-
exports.fromBinary = fromBinary;
|
|
37
38
|
/**
|
|
38
39
|
* Parse from binary data, merging fields.
|
|
39
40
|
*
|
|
@@ -47,7 +48,6 @@ function mergeFromBinary(schema, target, bytes, options) {
|
|
|
47
48
|
readMessage((0, reflect_js_1.reflect)(schema, target, false), new binary_encoding_js_1.BinaryReader(bytes), makeReadOptions(options), false, bytes.byteLength);
|
|
48
49
|
return target;
|
|
49
50
|
}
|
|
50
|
-
exports.mergeFromBinary = mergeFromBinary;
|
|
51
51
|
/**
|
|
52
52
|
* If `delimited` is false, read the length given in `lengthOrDelimitedFieldNo`.
|
|
53
53
|
*
|
|
@@ -107,7 +107,6 @@ function readField(message, reader, field, wireType, options) {
|
|
|
107
107
|
break;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
exports.readField = readField;
|
|
111
110
|
// Read a map field, expecting key field = 1, value field = 2
|
|
112
111
|
function readMapEntry(reader, map, options) {
|
|
113
112
|
const field = map.field();
|