@bufbuild/protobuf 0.3.0 → 0.4.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.
@@ -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.3.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v0.4.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.3.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v0.4.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");
@@ -60,8 +60,14 @@ class Message {
60
60
  * Parse a message from a JSON string.
61
61
  */
62
62
  fromJsonString(jsonString, options) {
63
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- assigning to JsonValue is safe here
64
- return this.fromJson(JSON.parse(jsonString), options);
63
+ let json;
64
+ try {
65
+ json = JSON.parse(jsonString);
66
+ }
67
+ catch (e) {
68
+ throw new Error(`cannot decode ${this.getType().typeName} from JSON: ${e instanceof Error ? e.message : String(e)}`);
69
+ }
70
+ return this.fromJson(json, options);
65
71
  }
66
72
  /**
67
73
  * Serialize the message to binary data.
@@ -88,7 +94,7 @@ class Message {
88
94
  return JSON.stringify(value, null, (_a = options === null || options === void 0 ? void 0 : options.prettySpaces) !== null && _a !== void 0 ? _a : 0);
89
95
  }
90
96
  /**
91
- * Override for serializaton behavior. This will be invoked when calling
97
+ * Override for serialization behavior. This will be invoked when calling
92
98
  * JSON.stringify on this message (i.e. JSON.stringify(msg)).
93
99
  *
94
100
  * Note that this will not serialize google.protobuf.Any with a packed
@@ -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.3.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v0.4.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.3.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v0.4.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";
@@ -57,8 +57,14 @@ export class Message {
57
57
  * Parse a message from a JSON string.
58
58
  */
59
59
  fromJsonString(jsonString, options) {
60
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- assigning to JsonValue is safe here
61
- return this.fromJson(JSON.parse(jsonString), options);
60
+ let json;
61
+ try {
62
+ json = JSON.parse(jsonString);
63
+ }
64
+ catch (e) {
65
+ throw new Error(`cannot decode ${this.getType().typeName} from JSON: ${e instanceof Error ? e.message : String(e)}`);
66
+ }
67
+ return this.fromJson(json, options);
62
68
  }
63
69
  /**
64
70
  * Serialize the message to binary data.
@@ -85,7 +91,7 @@ export class Message {
85
91
  return JSON.stringify(value, null, (_a = options === null || options === void 0 ? void 0 : options.prettySpaces) !== null && _a !== void 0 ? _a : 0);
86
92
  }
87
93
  /**
88
- * Override for serializaton behavior. This will be invoked when calling
94
+ * Override for serialization behavior. This will be invoked when calling
89
95
  * JSON.stringify on this message (i.e. JSON.stringify(msg)).
90
96
  *
91
97
  * Note that this will not serialize google.protobuf.Any with a packed
@@ -57,7 +57,7 @@ export declare class Message<T extends Message<T> = AnyMessage> {
57
57
  */
58
58
  toJsonString(options?: Partial<JsonWriteStringOptions>): string;
59
59
  /**
60
- * Override for serializaton behavior. This will be invoked when calling
60
+ * Override for serialization behavior. This will be invoked when calling
61
61
  * JSON.stringify on this message (i.e. JSON.stringify(msg)).
62
62
  *
63
63
  * Note that this will not serialize google.protobuf.Any with a packed
@@ -76,16 +76,31 @@ export declare class Message<T extends Message<T> = AnyMessage> {
76
76
  }
77
77
  /**
78
78
  * PlainMessage<T> strips all methods from a message, leaving only fields
79
- * and oneof groups.
79
+ * and oneof groups. It is recursive, meaning it applies this same logic to all
80
+ * nested message fields as well.
80
81
  */
81
82
  export declare type PlainMessage<T extends Message<T>> = {
82
- [P in keyof T as T[P] extends Function ? never : P]: T[P];
83
+ [P in keyof T as T[P] extends Function ? never : P]: PlainField<T[P]>;
83
84
  };
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> ? {
86
+ case: C;
87
+ value: PlainField<V>;
88
+ } : F extends {
89
+ case: string | undefined;
90
+ value?: unknown;
91
+ } ? F : F extends {
92
+ [key: string | number]: Message<infer U>;
93
+ } ? {
94
+ [key: string | number]: PlainField<U>;
95
+ } : F;
84
96
  /**
85
97
  * PartialMessage<T> constructs a type from a message. The resulting type
86
98
  * only contains the protobuf field members of the message, and all of them
87
99
  * are optional.
88
100
  *
101
+ * Note that the optionality of the fields is the only difference between
102
+ * PartialMessage and PlainMessage.
103
+ *
89
104
  * PartialMessage is similar to the built-in type Partial<T>, but recursive,
90
105
  * and respects `oneof` groups.
91
106
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "0.3.0",
3
+ "version": "0.4.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": {