@bufbuild/protobuf 2.1.0 → 2.2.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.
@@ -1,5 +1,5 @@
1
1
  import type { GenEnum, GenExtension, GenMessage } from "./codegenv1/types.js";
2
- import type { DescEnum, DescExtension, DescMessage } from "./descriptors.js";
2
+ import type { DescEnum, DescExtension, DescMessage, DescMethod } from "./descriptors.js";
3
3
  import type { OneofADT } from "./reflect/guard.js";
4
4
  import type { WireType } from "./wire/index.js";
5
5
  import type { JsonValue } from "./json-value.js";
@@ -54,6 +54,26 @@ export type UnknownField = {
54
54
  readonly wireType: WireType;
55
55
  readonly data: Uint8Array;
56
56
  };
57
+ /**
58
+ * Describes a streaming RPC declaration.
59
+ */
60
+ export type DescMethodStreaming<I extends DescMessage = DescMessage, O extends DescMessage = DescMessage> = DescMethodClientStreaming<I, O> | DescMethodServerStreaming<I, O> | DescMethodBiDiStreaming<I, O>;
61
+ /**
62
+ * Describes a unary RPC declaration.
63
+ */
64
+ export type DescMethodUnary<I extends DescMessage = DescMessage, O extends DescMessage = DescMessage> = DescMethodTyped<"unary", I, O>;
65
+ /**
66
+ * Describes a server streaming RPC declaration.
67
+ */
68
+ export type DescMethodServerStreaming<I extends DescMessage = DescMessage, O extends DescMessage = DescMessage> = DescMethodTyped<"server_streaming", I, O>;
69
+ /**
70
+ * Describes a client streaming RPC declaration.
71
+ */
72
+ export type DescMethodClientStreaming<I extends DescMessage = DescMessage, O extends DescMessage = DescMessage> = DescMethodTyped<"client_streaming", I, O>;
73
+ /**
74
+ * Describes a bidi streaming RPC declaration.
75
+ */
76
+ export type DescMethodBiDiStreaming<I extends DescMessage = DescMessage, O extends DescMessage = DescMessage> = DescMethodTyped<"bidi_streaming", I, O>;
57
77
  /**
58
78
  * The init type for a message, which makes all fields optional.
59
79
  * The init type is accepted by the function create().
@@ -74,4 +94,18 @@ type OneofSelectedMessage<K extends string, M extends Message> = {
74
94
  case: K;
75
95
  value: M;
76
96
  };
97
+ type DescMethodTyped<K extends DescMethod["methodKind"], I extends DescMessage, O extends DescMessage> = Omit<DescMethod, "methodKind" | "input" | "output"> & {
98
+ /**
99
+ * One of the four available method types.
100
+ */
101
+ readonly methodKind: K;
102
+ /**
103
+ * The message type for requests.
104
+ */
105
+ readonly input: I;
106
+ /**
107
+ * The message type for responses.
108
+ */
109
+ readonly output: O;
110
+ };
77
111
  export {};
@@ -94,7 +94,10 @@ class BinaryWriter {
94
94
  * Return all bytes written and reset this writer.
95
95
  */
96
96
  finish() {
97
- this.chunks.push(new Uint8Array(this.buf)); // flush the buffer
97
+ if (this.buf.length) {
98
+ this.chunks.push(new Uint8Array(this.buf)); // flush the buffer
99
+ this.buf = [];
100
+ }
98
101
  let len = 0;
99
102
  for (let i = 0; i < this.chunks.length; i++)
100
103
  len += this.chunks[i].length;
@@ -1,5 +1,5 @@
1
1
  import type { GenEnum, GenExtension, GenMessage } from "./codegenv1/types.js";
2
- import type { DescEnum, DescExtension, DescMessage } from "./descriptors.js";
2
+ import type { DescEnum, DescExtension, DescMessage, DescMethod } from "./descriptors.js";
3
3
  import type { OneofADT } from "./reflect/guard.js";
4
4
  import type { WireType } from "./wire/index.js";
5
5
  import type { JsonValue } from "./json-value.js";
@@ -54,6 +54,26 @@ export type UnknownField = {
54
54
  readonly wireType: WireType;
55
55
  readonly data: Uint8Array;
56
56
  };
57
+ /**
58
+ * Describes a streaming RPC declaration.
59
+ */
60
+ export type DescMethodStreaming<I extends DescMessage = DescMessage, O extends DescMessage = DescMessage> = DescMethodClientStreaming<I, O> | DescMethodServerStreaming<I, O> | DescMethodBiDiStreaming<I, O>;
61
+ /**
62
+ * Describes a unary RPC declaration.
63
+ */
64
+ export type DescMethodUnary<I extends DescMessage = DescMessage, O extends DescMessage = DescMessage> = DescMethodTyped<"unary", I, O>;
65
+ /**
66
+ * Describes a server streaming RPC declaration.
67
+ */
68
+ export type DescMethodServerStreaming<I extends DescMessage = DescMessage, O extends DescMessage = DescMessage> = DescMethodTyped<"server_streaming", I, O>;
69
+ /**
70
+ * Describes a client streaming RPC declaration.
71
+ */
72
+ export type DescMethodClientStreaming<I extends DescMessage = DescMessage, O extends DescMessage = DescMessage> = DescMethodTyped<"client_streaming", I, O>;
73
+ /**
74
+ * Describes a bidi streaming RPC declaration.
75
+ */
76
+ export type DescMethodBiDiStreaming<I extends DescMessage = DescMessage, O extends DescMessage = DescMessage> = DescMethodTyped<"bidi_streaming", I, O>;
57
77
  /**
58
78
  * The init type for a message, which makes all fields optional.
59
79
  * The init type is accepted by the function create().
@@ -74,4 +94,18 @@ type OneofSelectedMessage<K extends string, M extends Message> = {
74
94
  case: K;
75
95
  value: M;
76
96
  };
97
+ type DescMethodTyped<K extends DescMethod["methodKind"], I extends DescMessage, O extends DescMessage> = Omit<DescMethod, "methodKind" | "input" | "output"> & {
98
+ /**
99
+ * One of the four available method types.
100
+ */
101
+ readonly methodKind: K;
102
+ /**
103
+ * The message type for requests.
104
+ */
105
+ readonly input: I;
106
+ /**
107
+ * The message type for responses.
108
+ */
109
+ readonly output: O;
110
+ };
77
111
  export {};
@@ -91,7 +91,10 @@ export class BinaryWriter {
91
91
  * Return all bytes written and reset this writer.
92
92
  */
93
93
  finish() {
94
- this.chunks.push(new Uint8Array(this.buf)); // flush the buffer
94
+ if (this.buf.length) {
95
+ this.chunks.push(new Uint8Array(this.buf)); // flush the buffer
96
+ this.buf = [];
97
+ }
95
98
  let len = 0;
96
99
  for (let i = 0; i < this.chunks.length; i++)
97
100
  len += this.chunks[i].length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "2.1.0",
3
+ "version": "2.2.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
  "keywords": [