@bufbuild/protobuf 0.4.0 → 0.5.0

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 CHANGED
@@ -5,35 +5,39 @@ This package provides the runtime library for the code generator plugin
5
5
 
6
6
  ## Protocol Buffers for ECMAScript
7
7
 
8
- A complete implementation of [Protocol Buffers](https://developers.google.com/protocol-buffers)
9
- in TypeScript, suitable for web browsers and Node.js.
10
- Learn more at [github.com/bufbuild/protobuf-es](https://github.com/bufbuild/protobuf-es).
8
+ A complete implementation of [Protocol Buffers](https://developers.google.com/protocol-buffers) in TypeScript,
9
+ suitable for web browsers and Node.js.
11
10
 
11
+ **Protobuf-ES** is intended to be a solid, modern alternative to existing Protobuf implementations for the JavaScript ecosystem. It is the first project in this space to provide a comprehensive plugin framework and decouple the base types from RPC functionality.
12
12
 
13
- It is a complete implementation of [Protocol Buffers](https://developers.google.com/protocol-buffers)
14
- in TypeScript, suitable for web browsers and Node.js.
13
+ Some additional features that set it apart from the others:
15
14
 
16
- For example, the following definition:
15
+ - ECMAScript module support
16
+ - First-class TypeScript support
17
+ - Generation of idiomatic JavaScript and TypeScript code.
18
+ - Generation of [much smaller bundles](packages/protobuf-bench)
19
+ - Implementation of all proto3 features, including the [canonical JSON format](https://developers.google.com/protocol-buffers/docs/proto3#json).
20
+ - Implementation of all proto2 features, except for extensions and the text format.
21
+ - 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 protocol buffers [conformance tests](packages/protobuf-conformance).
23
+ - Descriptor and reflection support
17
24
 
18
- ```protobuf
19
- message Person {
20
- string name = 1;
21
- int32 id = 2; // Unique ID number for this person.
22
- string email = 3;
23
- }
25
+ ## Installation
26
+
27
+ ```bash
28
+ npm install @bufbuild/protobuf
24
29
  ```
25
30
 
26
- Is compiled to an ECMAScript class that can be used like this:
31
+ ## Documentation
27
32
 
28
- ```typescript
29
- let pete = new Person({
30
- name: "pete",
31
- id: 123
32
- });
33
+ To learn how to work with `@bufbuild/protobuf` check out the docs for the [Runtime API](https://github.com/bufbuild/protobuf-es/blob/main/docs/runtime_api.md)
34
+ and the [generated code](https://github.com/bufbuild/protobuf-es/blob/main/docs/generated_code.md).
33
35
 
34
- let bytes = pete.toBinary();
35
- pete = Person.fromBinary(bytes);
36
- pete = Person.fromJsonString('{"name": "pete", "id": 123}');
37
- ```
36
+ Official documentation for the Protobuf-ES project can be found at [github.com/bufbuild/protobuf-es](https://github.com/bufbuild/protobuf-es).
37
+
38
+ For more information on Buf, check out the official [Buf documentation](https://docs.buf.build/introduction).
39
+
40
+ ## Examples
41
+
42
+ A complete code example can be found in the **Protobuf-ES** repo [here](https://github.com/bufbuild/protobuf-es/tree/main/packages/protobuf-example).
38
43
 
39
- Learn more at [github.com/bufbuild/protobuf-es](https://github.com/bufbuild/protobuf-es).
@@ -14,7 +14,7 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0;
17
- // @generated by protoc-gen-es v0.4.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v0.5.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
18
18
  // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
19
19
  /* eslint-disable */
20
20
  const proto3_js_1 = require("../../proto3.js");
@@ -14,7 +14,7 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0;
17
- // @generated by protoc-gen-es v0.4.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v0.5.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
18
18
  // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
19
19
  /* eslint-disable */
20
20
  const proto3_js_1 = require("../../proto3.js");
@@ -102,6 +102,9 @@ class Message {
102
102
  * unpacked, and this is only possible with a type registry to look up the
103
103
  * message type. As a result, attempting to serialize a message with this
104
104
  * type will throw an Error.
105
+ *
106
+ * Note that this method is protected because users should not need to invoke
107
+ * it directly -- they can use JSON.stringify.
105
108
  */
106
109
  toJSON() {
107
110
  return this.toJson({
@@ -11,7 +11,7 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- // @generated by protoc-gen-es v0.4.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v0.5.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
15
  // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
16
16
  /* eslint-disable */
17
17
  import { proto3 } from "../../proto3.js";
@@ -11,7 +11,7 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- // @generated by protoc-gen-es v0.4.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v0.5.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
15
  // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
16
16
  /* eslint-disable */
17
17
  import { proto3 } from "../../proto3.js";
@@ -99,6 +99,9 @@ export class Message {
99
99
  * unpacked, and this is only possible with a type registry to look up the
100
100
  * message type. As a result, attempting to serialize a message with this
101
101
  * type will throw an Error.
102
+ *
103
+ * Note that this method is protected because users should not need to invoke
104
+ * it directly -- they can use JSON.stringify.
102
105
  */
103
106
  toJSON() {
104
107
  return this.toJson({
@@ -40,10 +40,10 @@ export declare enum WireType {
40
40
  */
41
41
  Bit32 = 5
42
42
  }
43
- declare type TextEncoderLike = {
43
+ type TextEncoderLike = {
44
44
  encode(input?: string): Uint8Array;
45
45
  };
46
- declare type TextDecoderLike = {
46
+ type TextDecoderLike = {
47
47
  decode(input?: Uint8Array): string;
48
48
  };
49
49
  export interface IBinaryReader {
@@ -11,8 +11,8 @@ interface CodegenInfo {
11
11
  readonly scalarDefaultValue: typeof scalarDefaultValue;
12
12
  readonly reifyWkt: typeof reifyWkt;
13
13
  }
14
- declare type RuntimeSymbolName = "proto2" | "proto3" | "Message" | "PartialMessage" | "PlainMessage" | "FieldList" | "MessageType" | "BinaryReadOptions" | "BinaryWriteOptions" | "JsonReadOptions" | "JsonWriteOptions" | "JsonValue" | "JsonObject" | "protoInt64" | "ScalarType" | "MethodKind" | "MethodIdempotency" | "IMessageTypeRegistry";
15
- declare type RuntimeSymbolInfo = {
14
+ type RuntimeSymbolName = "proto2" | "proto3" | "Message" | "PartialMessage" | "PlainMessage" | "FieldList" | "MessageType" | "BinaryReadOptions" | "BinaryWriteOptions" | "JsonReadOptions" | "JsonWriteOptions" | "JsonValue" | "JsonObject" | "protoInt64" | "ScalarType" | "MethodKind" | "MethodIdempotency" | "IMessageTypeRegistry";
15
+ type RuntimeSymbolInfo = {
16
16
  typeOnly: boolean;
17
17
  publicImportPath: string;
18
18
  privateImportPath: string;
@@ -41,7 +41,7 @@ export interface DescriptorSet {
41
41
  /**
42
42
  * A union of all descriptors, discriminated by a `kind` property.
43
43
  */
44
- export declare type AnyDesc = DescFile | DescEnum | DescEnumValue | DescMessage | DescField | DescExtension | DescOneof | DescService | DescMethod;
44
+ export type AnyDesc = DescFile | DescEnum | DescEnumValue | DescMessage | DescField | DescExtension | DescOneof | DescService | DescMethod;
45
45
  /**
46
46
  * Describes a protobuf source file.
47
47
  */
@@ -239,7 +239,7 @@ export interface DescMessage {
239
239
  /**
240
240
  * Describes a field declaration in a protobuf source file.
241
241
  */
242
- export declare type DescField = DescFieldCommon & (DescFieldScalar | DescFieldMessage | DescFieldEnum | DescFieldMap) & {
242
+ export type DescField = DescFieldCommon & (DescFieldScalar | DescFieldMessage | DescFieldEnum | DescFieldMap) & {
243
243
  kind: "field";
244
244
  /**
245
245
  * The message this field is declared on.
@@ -249,7 +249,7 @@ export declare type DescField = DescFieldCommon & (DescFieldScalar | DescFieldMe
249
249
  /**
250
250
  * Describes an extension in a protobuf source file.
251
251
  */
252
- export declare type DescExtension = DescFieldCommon & (DescFieldScalar | DescFieldMessage | DescFieldEnum | DescFieldMap) & {
252
+ export type DescExtension = DescFieldCommon & (DescFieldScalar | DescFieldMessage | DescFieldEnum | DescFieldMap) & {
253
253
  kind: "extension";
254
254
  /**
255
255
  * The fully qualified name of the extension.
@@ -24,7 +24,7 @@ import type { MessageType } from "./message-type.js";
24
24
  * - "oneof": If the field is member of a oneof group.
25
25
  * - "default": Only proto2: An explicit default value.
26
26
  */
27
- export declare type FieldInfo = fiRules<fiScalar> | fiRules<fiEnum> | fiRules<fiMessage> | fiRules<fiMap>;
27
+ export type FieldInfo = fiRules<fiScalar> | fiRules<fiEnum> | fiRules<fiMessage> | fiRules<fiMap>;
28
28
  /**
29
29
  * Version of `FieldInfo` that allows the following properties
30
30
  * to be omitted:
@@ -34,7 +34,7 @@ export declare type FieldInfo = fiRules<fiScalar> | fiRules<fiEnum> | fiRules<fi
34
34
  * - "repeated": Can be omitted if false.
35
35
  * - "packed": Can be omitted if equal to the standard packing of the field.
36
36
  */
37
- export declare type PartialFieldInfo = fiPartialRules<fiScalar> | fiPartialRules<fiEnum> | fiPartialRules<fiMessage> | fiPartialRules<fiMap>;
37
+ export type PartialFieldInfo = fiPartialRules<fiScalar> | fiPartialRules<fiEnum> | fiPartialRules<fiMessage> | fiPartialRules<fiMap>;
38
38
  /**
39
39
  * Provides convenient access to field information of a oneof.
40
40
  */
@@ -180,7 +180,7 @@ interface fiMap extends fiShared {
180
180
  */
181
181
  readonly default: undefined;
182
182
  }
183
- declare type fiRules<T> = Omit<T, "oneof" | "repeat" | "repeated" | "packed" | "opt"> & ({
183
+ type fiRules<T> = Omit<T, "oneof" | "repeat" | "repeated" | "packed" | "opt"> & ({
184
184
  readonly repeated: false;
185
185
  readonly packed: false;
186
186
  readonly opt: false;
@@ -201,7 +201,7 @@ declare type fiRules<T> = Omit<T, "oneof" | "repeat" | "repeated" | "packed" | "
201
201
  readonly opt: false;
202
202
  readonly oneof: OneofInfo;
203
203
  });
204
- declare type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "jsonName" | "localName" | "oneof" | "repeat" | "repeated" | "packed" | "opt" | "default"> & ({
204
+ type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "jsonName" | "localName" | "oneof" | "repeat" | "repeated" | "packed" | "opt" | "default"> & ({
205
205
  readonly jsonName?: string;
206
206
  readonly repeated?: false;
207
207
  readonly packed?: false;
@@ -61,7 +61,7 @@ export declare function varint32write(value: number, bytes: number[]): void;
61
61
  * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L220
62
62
  */
63
63
  export declare function varint32read(this: ReaderLike): number;
64
- declare type ReaderLike = {
64
+ type ReaderLike = {
65
65
  buf: Uint8Array;
66
66
  pos: number;
67
67
  len: number;
@@ -101,10 +101,10 @@ export interface JsonWriteStringOptions extends JsonWriteOptions {
101
101
  * - object (with any JSON value as property)
102
102
  * - array (with any JSON value as element)
103
103
  */
104
- export declare type JsonValue = number | string | boolean | null | JsonObject | JsonValue[];
104
+ export type JsonValue = number | string | boolean | null | JsonObject | JsonValue[];
105
105
  /**
106
106
  * Represents a JSON object.
107
107
  */
108
- export declare type JsonObject = {
108
+ export type JsonObject = {
109
109
  [k: string]: JsonValue;
110
110
  };
@@ -65,8 +65,11 @@ export declare class Message<T extends Message<T> = AnyMessage> {
65
65
  * unpacked, and this is only possible with a type registry to look up the
66
66
  * message type. As a result, attempting to serialize a message with this
67
67
  * type will throw an Error.
68
+ *
69
+ * Note that this method is protected because users should not need to invoke
70
+ * it directly -- they can use JSON.stringify.
68
71
  */
69
- toJSON(): JsonValue;
72
+ protected toJSON(): JsonValue;
70
73
  /**
71
74
  * Retrieve the MessageType of this message - a singleton that represents
72
75
  * the protobuf message declaration and provides metadata for reflection-
@@ -79,10 +82,10 @@ export declare class Message<T extends Message<T> = AnyMessage> {
79
82
  * and oneof groups. It is recursive, meaning it applies this same logic to all
80
83
  * nested message fields as well.
81
84
  */
82
- export declare type PlainMessage<T extends Message<T>> = {
85
+ export type PlainMessage<T extends Message<T>> = {
83
86
  [P in keyof T as T[P] extends Function ? never : P]: PlainField<T[P]>;
84
87
  };
85
- declare type PlainField<F> = F extends (Date | Uint8Array | bigint | boolean | string | number) ? F : F extends Array<infer U> ? Array<PlainField<U>> : F extends ReadonlyArray<infer U> ? ReadonlyArray<PlainField<U>> : F extends Message<infer U> ? PlainMessage<U> : F extends OneofSelectedMessage<infer C, infer V> ? {
88
+ type PlainField<F> = F extends (Date | Uint8Array | bigint | boolean | string | number) ? F : F extends Array<infer U> ? Array<PlainField<U>> : F extends ReadonlyArray<infer U> ? ReadonlyArray<PlainField<U>> : F extends Message<infer U> ? PlainMessage<U> : F extends OneofSelectedMessage<infer C, infer V> ? {
86
89
  case: C;
87
90
  value: PlainField<V>;
88
91
  } : F extends {
@@ -104,10 +107,10 @@ declare type PlainField<F> = F extends (Date | Uint8Array | bigint | boolean | s
104
107
  * PartialMessage is similar to the built-in type Partial<T>, but recursive,
105
108
  * and respects `oneof` groups.
106
109
  */
107
- export declare type PartialMessage<T extends Message<T>> = {
110
+ export type PartialMessage<T extends Message<T>> = {
108
111
  [P in keyof T as T[P] extends Function ? never : P]?: PartialField<T[P]>;
109
112
  };
110
- declare type PartialField<F> = F extends (Date | Uint8Array | bigint | boolean | string | number) ? F : F extends Array<infer U> ? Array<PartialField<U>> : F extends ReadonlyArray<infer U> ? ReadonlyArray<PartialField<U>> : F extends Message<infer U> ? PartialMessage<U> : F extends OneofSelectedMessage<infer C, infer V> ? {
113
+ type PartialField<F> = F extends (Date | Uint8Array | bigint | boolean | string | number) ? F : F extends Array<infer U> ? Array<PartialField<U>> : F extends ReadonlyArray<infer U> ? ReadonlyArray<PartialField<U>> : F extends Message<infer U> ? PartialMessage<U> : F extends OneofSelectedMessage<infer C, infer V> ? {
111
114
  case: C;
112
115
  value: PartialMessage<V>;
113
116
  } : F extends {
@@ -118,7 +121,7 @@ declare type PartialField<F> = F extends (Date | Uint8Array | bigint | boolean |
118
121
  } ? {
119
122
  [key: string | number]: PartialMessage<U>;
120
123
  } : F;
121
- declare type OneofSelectedMessage<K extends string, M extends Message<M>> = {
124
+ type OneofSelectedMessage<K extends string, M extends Message<M>> = {
122
125
  case: K;
123
126
  value: M;
124
127
  };
@@ -1,6 +1,6 @@
1
1
  import type { FieldInfo, OneofInfo, PartialFieldInfo } from "../field.js";
2
2
  import type { FieldList } from "../field-list.js";
3
- export declare type FieldListSource = readonly PartialFieldInfo[] | readonly FieldInfo[] | (() => readonly PartialFieldInfo[]) | (() => readonly FieldInfo[]);
3
+ export type FieldListSource = readonly PartialFieldInfo[] | readonly FieldInfo[] | (() => readonly PartialFieldInfo[]) | (() => readonly FieldInfo[]);
4
4
  export declare class InternalFieldList implements FieldList {
5
5
  private readonly _fields;
6
6
  private readonly _normalizer;
@@ -1,7 +1,7 @@
1
1
  import type { JsonFormat, JsonValue, JsonWriteOptions } from "../json-format.js";
2
2
  import { FieldInfo, ScalarType } from "../field.js";
3
3
  import type { EnumType } from "../enum.js";
4
- declare type JsonFormatWriteFieldFn = (field: FieldInfo, value: any, options: JsonWriteOptions) => JsonValue | undefined;
4
+ type JsonFormatWriteFieldFn = (field: FieldInfo, value: any, options: JsonWriteOptions) => JsonValue | undefined;
5
5
  export declare function makeJsonFormatCommon(makeWriteField: (writeEnumFn: typeof writeEnum, writeScalarFn: typeof writeScalar) => JsonFormatWriteFieldFn): JsonFormat;
6
6
  declare function writeEnum(type: EnumType, value: number | undefined, emitIntrinsicDefault: boolean, enumAsInteger: boolean): JsonValue | undefined;
7
7
  declare function writeScalar(type: ScalarType, value: any, emitIntrinsicDefault: boolean): JsonValue | undefined;
@@ -2,6 +2,6 @@ import type { JsonValue } from "../json-format";
2
2
  /**
3
3
  *
4
4
  */
5
- export declare type OptionsMap = {
5
+ export type OptionsMap = {
6
6
  readonly [extensionName: string]: JsonValue;
7
7
  };
@@ -1,5 +1,5 @@
1
1
  import type { DescField, DescMessage, DescOneof } from "../descriptor-set.js";
2
- declare type DescWkt = {
2
+ type DescWkt = {
3
3
  typeName: "google.protobuf.Any";
4
4
  typeUrl: DescField;
5
5
  value: DescField;
@@ -29,7 +29,7 @@ export interface ServiceType {
29
29
  * - "idempotency": User-provided indication whether the method will cause
30
30
  * the same effect every time it is called.
31
31
  */
32
- export declare type MethodInfo<I extends Message<I> = AnyMessage, O extends Message<O> = AnyMessage> = MethodInfoUnary<I, O> | MethodInfoServerStreaming<I, O> | MethodInfoClientStreaming<I, O> | MethodInfoBiDiStreaming<I, O>;
32
+ 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>;
33
33
  /**
34
34
  * A unary method: rpc (Input) returns (Output)
35
35
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "license": "(Apache-2.0 AND BSD-3-Clause)",
5
5
  "description": "A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.",
6
6
  "repository": {