@bufbuild/protobuf 1.7.2 → 1.8.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/dist/cjs/codegen-info.d.ts +6 -1
- package/dist/cjs/codegen-info.js +4 -3
- package/dist/cjs/create-descriptor-set.js +45 -33
- package/dist/cjs/create-registry-from-desc.js +60 -110
- package/dist/cjs/descriptor-set.d.ts +13 -9
- package/dist/cjs/field.d.ts +25 -51
- package/dist/cjs/field.js +0 -66
- package/dist/cjs/google/protobuf/compiler/plugin_pb.d.ts +18 -0
- package/dist/cjs/google/protobuf/compiler/plugin_pb.js +2 -0
- package/dist/cjs/google/protobuf/descriptor_pb.d.ts +33 -33
- package/dist/cjs/google/protobuf/descriptor_pb.js +23 -10
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/google/protobuf/wrappers_pb.js +19 -19
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +6 -4
- package/dist/cjs/is-message.d.ts +22 -0
- package/dist/cjs/is-message.js +52 -0
- package/dist/cjs/json-format.d.ts +1 -2
- package/dist/cjs/private/binary-format.d.ts +7 -0
- package/dist/cjs/private/{binary-format-common.js → binary-format.js} +150 -53
- package/dist/cjs/private/extensions.js +1 -1
- package/dist/cjs/private/feature-set.js +1 -1
- package/dist/cjs/private/field-normalize.d.ts +9 -0
- package/dist/cjs/private/field-normalize.js +69 -0
- package/dist/cjs/private/field-wrapper.d.ts +1 -1
- package/dist/cjs/private/field-wrapper.js +12 -12
- package/dist/cjs/private/field.d.ts +1 -0
- package/dist/cjs/private/field.js +1 -0
- package/dist/cjs/private/json-format.d.ts +2 -0
- package/dist/cjs/private/{json-format-common.js → json-format.js} +261 -170
- package/dist/cjs/private/proto-runtime.d.ts +1 -1
- package/dist/cjs/private/proto-runtime.js +8 -4
- package/dist/cjs/private/reflect.d.ts +9 -0
- package/dist/cjs/private/reflect.js +79 -0
- package/dist/cjs/private/reify-wkt.js +11 -11
- package/dist/cjs/private/scalars.d.ts +9 -18
- package/dist/cjs/private/scalars.js +36 -80
- package/dist/cjs/private/text-format.d.ts +1 -1
- package/dist/cjs/private/text-format.js +17 -17
- package/dist/cjs/private/util-common.js +17 -14
- package/dist/cjs/proto-delimited.js +2 -3
- package/dist/cjs/proto2.js +29 -68
- package/dist/cjs/proto3.js +30 -77
- package/dist/cjs/scalar.d.ts +53 -0
- package/dist/cjs/scalar.js +81 -0
- package/dist/cjs/to-plain-message.js +3 -4
- package/dist/esm/codegen-info.d.ts +6 -1
- package/dist/esm/codegen-info.js +6 -5
- package/dist/esm/create-descriptor-set.js +22 -10
- package/dist/esm/create-registry-from-desc.js +62 -111
- package/dist/esm/descriptor-set.d.ts +13 -9
- package/dist/esm/descriptor-set.js +1 -1
- package/dist/esm/field.d.ts +25 -51
- package/dist/esm/field.js +1 -65
- package/dist/esm/google/protobuf/compiler/plugin_pb.d.ts +18 -0
- package/dist/esm/google/protobuf/compiler/plugin_pb.js +2 -0
- package/dist/esm/google/protobuf/descriptor_pb.d.ts +33 -33
- package/dist/esm/google/protobuf/descriptor_pb.js +23 -10
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/google/protobuf/wrappers_pb.js +1 -1
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/is-message.d.ts +22 -0
- package/dist/esm/is-message.js +48 -0
- package/dist/esm/json-format.d.ts +1 -2
- package/dist/esm/json-format.js +1 -1
- package/dist/esm/private/binary-format.d.ts +7 -0
- package/dist/esm/private/{binary-format-common.js → binary-format.js} +126 -25
- package/dist/esm/private/extensions.js +2 -2
- package/dist/esm/private/feature-set.js +1 -1
- package/dist/esm/private/field-normalize.d.ts +9 -0
- package/dist/esm/private/field-normalize.js +65 -0
- package/dist/esm/private/field-wrapper.d.ts +1 -1
- package/dist/esm/private/field-wrapper.js +3 -2
- package/dist/esm/private/field.d.ts +1 -0
- package/dist/esm/private/field.js +1 -0
- package/dist/esm/private/json-format.d.ts +2 -0
- package/dist/esm/private/{json-format-common.js → json-format.js} +227 -135
- package/dist/esm/private/proto-runtime.d.ts +1 -1
- package/dist/esm/private/proto-runtime.js +8 -4
- package/dist/esm/private/reflect.d.ts +9 -0
- package/dist/esm/private/reflect.js +74 -0
- package/dist/esm/private/reify-wkt.js +1 -1
- package/dist/esm/private/scalars.d.ts +9 -18
- package/dist/esm/private/scalars.js +15 -59
- package/dist/esm/private/text-format.d.ts +1 -1
- package/dist/esm/private/text-format.js +1 -1
- package/dist/esm/private/util-common.js +10 -6
- package/dist/esm/proto-delimited.js +2 -3
- package/dist/esm/proto2.js +29 -68
- package/dist/esm/proto3.js +31 -78
- package/dist/esm/scalar.d.ts +53 -0
- package/dist/esm/scalar.js +78 -0
- package/dist/esm/to-plain-message.js +3 -2
- package/package.json +2 -8
- package/dist/cjs/private/binary-format-common.d.ts +0 -13
- package/dist/cjs/private/binary-format-proto2.d.ts +0 -2
- package/dist/cjs/private/binary-format-proto2.js +0 -91
- package/dist/cjs/private/binary-format-proto3.d.ts +0 -2
- package/dist/cjs/private/binary-format-proto3.js +0 -83
- package/dist/cjs/private/json-format-common.d.ts +0 -9
- package/dist/cjs/private/json-format-proto2.d.ts +0 -2
- package/dist/cjs/private/json-format-proto2.js +0 -103
- package/dist/cjs/private/json-format-proto3.d.ts +0 -2
- package/dist/cjs/private/json-format-proto3.js +0 -94
- package/dist/esm/private/binary-format-common.d.ts +0 -13
- package/dist/esm/private/binary-format-proto2.d.ts +0 -2
- package/dist/esm/private/binary-format-proto2.js +0 -87
- package/dist/esm/private/binary-format-proto3.d.ts +0 -2
- package/dist/esm/private/binary-format-proto3.js +0 -79
- package/dist/esm/private/json-format-common.d.ts +0 -9
- package/dist/esm/private/json-format-proto2.d.ts +0 -2
- package/dist/esm/private/json-format-proto2.js +0 -99
- package/dist/esm/private/json-format-proto3.d.ts +0 -2
- package/dist/esm/private/json-format-proto3.js +0 -90
- package/dist/proxy/index.d.ts +0 -1
- package/dist/proxy/index.js +0 -1
|
@@ -50,4 +50,4 @@ export interface ProtoRuntime {
|
|
|
50
50
|
*/
|
|
51
51
|
makeExtension<E extends Message<E> = AnyMessage, V = unknown>(typeName: string, extendee: MessageType<E>, field: ExtensionFieldSource): Extension<E, V>;
|
|
52
52
|
}
|
|
53
|
-
export declare function makeProtoRuntime(syntax: string,
|
|
53
|
+
export declare function makeProtoRuntime(syntax: string, newFieldList: Util["newFieldList"], initFields: Util["initFields"]): ProtoRuntime;
|
|
@@ -17,12 +17,16 @@ exports.makeProtoRuntime = void 0;
|
|
|
17
17
|
const enum_js_1 = require("./enum.js");
|
|
18
18
|
const message_type_js_1 = require("./message-type.js");
|
|
19
19
|
const extensions_js_1 = require("./extensions.js");
|
|
20
|
-
|
|
20
|
+
const json_format_js_1 = require("./json-format.js");
|
|
21
|
+
const binary_format_js_1 = require("./binary-format.js");
|
|
22
|
+
const util_common_js_1 = require("./util-common.js");
|
|
23
|
+
function makeProtoRuntime(syntax, newFieldList, initFields) {
|
|
21
24
|
return {
|
|
22
25
|
syntax,
|
|
23
|
-
json,
|
|
24
|
-
bin,
|
|
25
|
-
util,
|
|
26
|
+
json: (0, json_format_js_1.makeJsonFormat)(),
|
|
27
|
+
bin: (0, binary_format_js_1.makeBinaryFormat)(),
|
|
28
|
+
util: Object.assign(Object.assign({}, (0, util_common_js_1.makeUtilCommon)()), { newFieldList,
|
|
29
|
+
initFields }),
|
|
26
30
|
makeMessageType(typeName, fields, opt) {
|
|
27
31
|
return (0, message_type_js_1.makeMessageType)(this, typeName, fields, opt);
|
|
28
32
|
},
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FieldInfo } from "../field.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if the field is set.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isFieldSet(field: FieldInfo, target: Record<string, any>): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Resets the field, so that isFieldSet() will return false.
|
|
8
|
+
*/
|
|
9
|
+
export declare function clearField(field: FieldInfo, target: Record<string, any>): void;
|
|
@@ -0,0 +1,79 @@
|
|
|
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.clearField = exports.isFieldSet = void 0;
|
|
17
|
+
const scalars_js_1 = require("./scalars.js");
|
|
18
|
+
/**
|
|
19
|
+
* Returns true if the field is set.
|
|
20
|
+
*/
|
|
21
|
+
function isFieldSet(field, target) {
|
|
22
|
+
const localName = field.localName;
|
|
23
|
+
if (field.repeated) {
|
|
24
|
+
return target[localName].length > 0;
|
|
25
|
+
}
|
|
26
|
+
if (field.oneof) {
|
|
27
|
+
return target[field.oneof.localName].case === localName; // eslint-disable-line @typescript-eslint/no-unsafe-member-access
|
|
28
|
+
}
|
|
29
|
+
switch (field.kind) {
|
|
30
|
+
case "enum":
|
|
31
|
+
case "scalar":
|
|
32
|
+
if (field.opt || field.req) {
|
|
33
|
+
// explicit presence
|
|
34
|
+
return target[localName] !== undefined;
|
|
35
|
+
}
|
|
36
|
+
// implicit presence
|
|
37
|
+
if (field.kind == "enum") {
|
|
38
|
+
return target[localName] !== field.T.values[0].no;
|
|
39
|
+
}
|
|
40
|
+
return !(0, scalars_js_1.isScalarZeroValue)(field.T, target[localName]);
|
|
41
|
+
case "message":
|
|
42
|
+
return target[localName] !== undefined;
|
|
43
|
+
case "map":
|
|
44
|
+
return Object.keys(target[localName]).length > 0; // eslint-disable-line @typescript-eslint/no-unsafe-argument
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.isFieldSet = isFieldSet;
|
|
48
|
+
/**
|
|
49
|
+
* Resets the field, so that isFieldSet() will return false.
|
|
50
|
+
*/
|
|
51
|
+
function clearField(field, target) {
|
|
52
|
+
const localName = field.localName;
|
|
53
|
+
const implicitPresence = !field.opt && !field.req;
|
|
54
|
+
if (field.repeated) {
|
|
55
|
+
target[localName] = [];
|
|
56
|
+
}
|
|
57
|
+
else if (field.oneof) {
|
|
58
|
+
target[field.oneof.localName] = { case: undefined };
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
switch (field.kind) {
|
|
62
|
+
case "map":
|
|
63
|
+
target[localName] = {};
|
|
64
|
+
break;
|
|
65
|
+
case "enum":
|
|
66
|
+
target[localName] = implicitPresence ? field.T.values[0].no : undefined;
|
|
67
|
+
break;
|
|
68
|
+
case "scalar":
|
|
69
|
+
target[localName] = implicitPresence
|
|
70
|
+
? (0, scalars_js_1.scalarZeroValue)(field.T, field.L)
|
|
71
|
+
: undefined;
|
|
72
|
+
break;
|
|
73
|
+
case "message":
|
|
74
|
+
target[localName] = undefined;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.clearField = clearField;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.reifyWkt = void 0;
|
|
17
|
-
const
|
|
17
|
+
const scalar_js_1 = require("../scalar.js");
|
|
18
18
|
/**
|
|
19
19
|
* @deprecated please use reifyWkt from @bufbuild/protoplugin/ecmascript instead
|
|
20
20
|
*
|
|
@@ -33,10 +33,10 @@ function reifyWkt(message) {
|
|
|
33
33
|
case "google.protobuf.Any": {
|
|
34
34
|
const typeUrl = message.fields.find((f) => f.number == 1 &&
|
|
35
35
|
f.fieldKind == "scalar" &&
|
|
36
|
-
f.scalar ===
|
|
36
|
+
f.scalar === scalar_js_1.ScalarType.STRING);
|
|
37
37
|
const value = message.fields.find((f) => f.number == 2 &&
|
|
38
38
|
f.fieldKind == "scalar" &&
|
|
39
|
-
f.scalar ===
|
|
39
|
+
f.scalar === scalar_js_1.ScalarType.BYTES);
|
|
40
40
|
if (typeUrl && value) {
|
|
41
41
|
return {
|
|
42
42
|
typeName: message.typeName,
|
|
@@ -49,10 +49,10 @@ function reifyWkt(message) {
|
|
|
49
49
|
case "google.protobuf.Timestamp": {
|
|
50
50
|
const seconds = message.fields.find((f) => f.number == 1 &&
|
|
51
51
|
f.fieldKind == "scalar" &&
|
|
52
|
-
f.scalar ===
|
|
52
|
+
f.scalar === scalar_js_1.ScalarType.INT64);
|
|
53
53
|
const nanos = message.fields.find((f) => f.number == 2 &&
|
|
54
54
|
f.fieldKind == "scalar" &&
|
|
55
|
-
f.scalar ===
|
|
55
|
+
f.scalar === scalar_js_1.ScalarType.INT32);
|
|
56
56
|
if (seconds && nanos) {
|
|
57
57
|
return {
|
|
58
58
|
typeName: message.typeName,
|
|
@@ -65,10 +65,10 @@ function reifyWkt(message) {
|
|
|
65
65
|
case "google.protobuf.Duration": {
|
|
66
66
|
const seconds = message.fields.find((f) => f.number == 1 &&
|
|
67
67
|
f.fieldKind == "scalar" &&
|
|
68
|
-
f.scalar ===
|
|
68
|
+
f.scalar === scalar_js_1.ScalarType.INT64);
|
|
69
69
|
const nanos = message.fields.find((f) => f.number == 2 &&
|
|
70
70
|
f.fieldKind == "scalar" &&
|
|
71
|
-
f.scalar ===
|
|
71
|
+
f.scalar === scalar_js_1.ScalarType.INT32);
|
|
72
72
|
if (seconds && nanos) {
|
|
73
73
|
return {
|
|
74
74
|
typeName: message.typeName,
|
|
@@ -96,15 +96,15 @@ function reifyWkt(message) {
|
|
|
96
96
|
}
|
|
97
97
|
const numberValue = message.fields.find((f) => f.number == 2 &&
|
|
98
98
|
f.fieldKind == "scalar" &&
|
|
99
|
-
f.scalar ===
|
|
99
|
+
f.scalar === scalar_js_1.ScalarType.DOUBLE &&
|
|
100
100
|
f.oneof === kind);
|
|
101
101
|
const stringValue = message.fields.find((f) => f.number == 3 &&
|
|
102
102
|
f.fieldKind == "scalar" &&
|
|
103
|
-
f.scalar ===
|
|
103
|
+
f.scalar === scalar_js_1.ScalarType.STRING &&
|
|
104
104
|
f.oneof === kind);
|
|
105
105
|
const boolValue = message.fields.find((f) => f.number == 4 &&
|
|
106
106
|
f.fieldKind == "scalar" &&
|
|
107
|
-
f.scalar ===
|
|
107
|
+
f.scalar === scalar_js_1.ScalarType.BOOL &&
|
|
108
108
|
f.oneof === kind);
|
|
109
109
|
const structValue = message.fields.find((f) => f.number == 5 && f.oneof === kind);
|
|
110
110
|
if ((structValue === null || structValue === void 0 ? void 0 : structValue.fieldKind) !== "message" ||
|
|
@@ -141,7 +141,7 @@ function reifyWkt(message) {
|
|
|
141
141
|
case "google.protobuf.FieldMask": {
|
|
142
142
|
const paths = message.fields.find((f) => f.number == 1 &&
|
|
143
143
|
f.fieldKind == "scalar" &&
|
|
144
|
-
f.scalar ===
|
|
144
|
+
f.scalar === scalar_js_1.ScalarType.STRING &&
|
|
145
145
|
f.repeated);
|
|
146
146
|
if (paths) {
|
|
147
147
|
return { typeName: message.typeName, paths };
|
|
@@ -1,27 +1,18 @@
|
|
|
1
|
-
import { LongType, ScalarType } from "../
|
|
2
|
-
import type {
|
|
3
|
-
import { WireType } from "../binary-encoding.js";
|
|
1
|
+
import { LongType, ScalarType } from "../scalar.js";
|
|
2
|
+
import type { ScalarValue } from "../scalar.js";
|
|
4
3
|
/**
|
|
5
4
|
* Returns true if both scalar values are equal.
|
|
6
5
|
*/
|
|
7
6
|
export declare function scalarEquals(type: ScalarType, a: string | boolean | number | bigint | Uint8Array | undefined, b: string | boolean | number | bigint | Uint8Array | undefined): boolean;
|
|
8
7
|
/**
|
|
9
|
-
* Returns the
|
|
10
|
-
* proto3 semantics.
|
|
8
|
+
* Returns the zero value for the given scalar type.
|
|
11
9
|
*/
|
|
12
|
-
export declare function
|
|
10
|
+
export declare function scalarZeroValue<T extends ScalarType, L extends LongType>(type: T, longType: L): ScalarValue<T, L>;
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
12
|
+
* Returns true for a zero-value. For example, an integer has the zero-value `0`,
|
|
13
|
+
* a boolean is `false`, a string is `""`, and bytes is an empty Uint8Array.
|
|
15
14
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* [1]: name of the appropriate method of IBinaryWriter
|
|
19
|
-
* [2]: whether the given value is a default value for proto3 semantics
|
|
20
|
-
*
|
|
21
|
-
* If argument `value` is omitted, [2] is always false.
|
|
15
|
+
* In proto3, zero-values are not written to the wire, unless the field is
|
|
16
|
+
* optional or repeated.
|
|
22
17
|
*/
|
|
23
|
-
export declare function
|
|
24
|
-
WireType,
|
|
25
|
-
Exclude<keyof IBinaryWriter, "tag" | "raw" | "fork" | "join" | "finish">,
|
|
26
|
-
boolean
|
|
27
|
-
];
|
|
18
|
+
export declare function isScalarZeroValue(type: ScalarType, value: unknown): boolean;
|
|
@@ -13,11 +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.
|
|
17
|
-
const field_js_1 = require("../field.js");
|
|
18
|
-
const binary_encoding_js_1 = require("../binary-encoding.js");
|
|
16
|
+
exports.isScalarZeroValue = exports.scalarZeroValue = exports.scalarEquals = void 0;
|
|
19
17
|
const proto_int64_js_1 = require("../proto-int64.js");
|
|
20
|
-
|
|
18
|
+
const scalar_js_1 = require("../scalar.js");
|
|
21
19
|
/**
|
|
22
20
|
* Returns true if both scalar values are equal.
|
|
23
21
|
*/
|
|
@@ -27,7 +25,7 @@ function scalarEquals(type, a, b) {
|
|
|
27
25
|
return true;
|
|
28
26
|
}
|
|
29
27
|
// Special case BYTES - we need to compare each byte individually
|
|
30
|
-
if (type ==
|
|
28
|
+
if (type == scalar_js_1.ScalarType.BYTES) {
|
|
31
29
|
if (!(a instanceof Uint8Array) || !(b instanceof Uint8Array)) {
|
|
32
30
|
return false;
|
|
33
31
|
}
|
|
@@ -44,11 +42,11 @@ function scalarEquals(type, a, b) {
|
|
|
44
42
|
// Special case 64-bit integers - we support number, string and bigint representation.
|
|
45
43
|
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
46
44
|
switch (type) {
|
|
47
|
-
case
|
|
48
|
-
case
|
|
49
|
-
case
|
|
50
|
-
case
|
|
51
|
-
case
|
|
45
|
+
case scalar_js_1.ScalarType.UINT64:
|
|
46
|
+
case scalar_js_1.ScalarType.FIXED64:
|
|
47
|
+
case scalar_js_1.ScalarType.INT64:
|
|
48
|
+
case scalar_js_1.ScalarType.SFIXED64:
|
|
49
|
+
case scalar_js_1.ScalarType.SINT64:
|
|
52
50
|
// Loose comparison will match between 0n, 0 and "0".
|
|
53
51
|
return a == b;
|
|
54
52
|
}
|
|
@@ -58,26 +56,25 @@ function scalarEquals(type, a, b) {
|
|
|
58
56
|
}
|
|
59
57
|
exports.scalarEquals = scalarEquals;
|
|
60
58
|
/**
|
|
61
|
-
* Returns the
|
|
62
|
-
* proto3 semantics.
|
|
59
|
+
* Returns the zero value for the given scalar type.
|
|
63
60
|
*/
|
|
64
|
-
function
|
|
61
|
+
function scalarZeroValue(type, longType) {
|
|
65
62
|
switch (type) {
|
|
66
|
-
case
|
|
63
|
+
case scalar_js_1.ScalarType.BOOL:
|
|
67
64
|
return false;
|
|
68
|
-
case
|
|
69
|
-
case
|
|
70
|
-
case
|
|
71
|
-
case
|
|
72
|
-
case
|
|
65
|
+
case scalar_js_1.ScalarType.UINT64:
|
|
66
|
+
case scalar_js_1.ScalarType.FIXED64:
|
|
67
|
+
case scalar_js_1.ScalarType.INT64:
|
|
68
|
+
case scalar_js_1.ScalarType.SFIXED64:
|
|
69
|
+
case scalar_js_1.ScalarType.SINT64:
|
|
73
70
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison -- acceptable since it's covered by tests
|
|
74
|
-
return longType == 0 ? proto_int64_js_1.protoInt64.zero : "0";
|
|
75
|
-
case
|
|
76
|
-
case
|
|
71
|
+
return (longType == 0 ? proto_int64_js_1.protoInt64.zero : "0");
|
|
72
|
+
case scalar_js_1.ScalarType.DOUBLE:
|
|
73
|
+
case scalar_js_1.ScalarType.FLOAT:
|
|
77
74
|
return 0.0;
|
|
78
|
-
case
|
|
75
|
+
case scalar_js_1.ScalarType.BYTES:
|
|
79
76
|
return new Uint8Array(0);
|
|
80
|
-
case
|
|
77
|
+
case scalar_js_1.ScalarType.STRING:
|
|
81
78
|
return "";
|
|
82
79
|
default:
|
|
83
80
|
// Handles INT32, UINT32, SINT32, FIXED32, SFIXED32.
|
|
@@ -85,65 +82,24 @@ function scalarDefaultValue(type, longType) {
|
|
|
85
82
|
return 0;
|
|
86
83
|
}
|
|
87
84
|
}
|
|
88
|
-
exports.
|
|
85
|
+
exports.scalarZeroValue = scalarZeroValue;
|
|
89
86
|
/**
|
|
90
|
-
*
|
|
87
|
+
* Returns true for a zero-value. For example, an integer has the zero-value `0`,
|
|
88
|
+
* a boolean is `false`, a string is `""`, and bytes is an empty Uint8Array.
|
|
91
89
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* [1]: name of the appropriate method of IBinaryWriter
|
|
95
|
-
* [2]: whether the given value is a default value for proto3 semantics
|
|
96
|
-
*
|
|
97
|
-
* If argument `value` is omitted, [2] is always false.
|
|
90
|
+
* In proto3, zero-values are not written to the wire, unless the field is
|
|
91
|
+
* optional or repeated.
|
|
98
92
|
*/
|
|
99
|
-
function
|
|
100
|
-
const isUndefined = value === undefined;
|
|
101
|
-
let wireType = binary_encoding_js_1.WireType.Varint;
|
|
102
|
-
let isIntrinsicDefault = value === 0;
|
|
103
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- INT32, UINT32, SINT32 are covered by the defaults
|
|
93
|
+
function isScalarZeroValue(type, value) {
|
|
104
94
|
switch (type) {
|
|
105
|
-
case
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
case
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
wireType = binary_encoding_js_1.WireType.Bit64;
|
|
114
|
-
break;
|
|
115
|
-
case field_js_1.ScalarType.FLOAT:
|
|
116
|
-
wireType = binary_encoding_js_1.WireType.Bit32;
|
|
117
|
-
break;
|
|
118
|
-
case field_js_1.ScalarType.INT64:
|
|
119
|
-
isIntrinsicDefault = isUndefined || value == 0; // Loose comparison matches 0n, 0 and "0"
|
|
120
|
-
break;
|
|
121
|
-
case field_js_1.ScalarType.UINT64:
|
|
122
|
-
isIntrinsicDefault = isUndefined || value == 0; // Loose comparison matches 0n, 0 and "0"
|
|
123
|
-
break;
|
|
124
|
-
case field_js_1.ScalarType.FIXED64:
|
|
125
|
-
isIntrinsicDefault = isUndefined || value == 0; // Loose comparison matches 0n, 0 and "0"
|
|
126
|
-
wireType = binary_encoding_js_1.WireType.Bit64;
|
|
127
|
-
break;
|
|
128
|
-
case field_js_1.ScalarType.BYTES:
|
|
129
|
-
isIntrinsicDefault = isUndefined || !value.byteLength;
|
|
130
|
-
wireType = binary_encoding_js_1.WireType.LengthDelimited;
|
|
131
|
-
break;
|
|
132
|
-
case field_js_1.ScalarType.FIXED32:
|
|
133
|
-
wireType = binary_encoding_js_1.WireType.Bit32;
|
|
134
|
-
break;
|
|
135
|
-
case field_js_1.ScalarType.SFIXED32:
|
|
136
|
-
wireType = binary_encoding_js_1.WireType.Bit32;
|
|
137
|
-
break;
|
|
138
|
-
case field_js_1.ScalarType.SFIXED64:
|
|
139
|
-
isIntrinsicDefault = isUndefined || value == 0;
|
|
140
|
-
wireType = binary_encoding_js_1.WireType.Bit64;
|
|
141
|
-
break;
|
|
142
|
-
case field_js_1.ScalarType.SINT64:
|
|
143
|
-
isIntrinsicDefault = isUndefined || value == 0;
|
|
144
|
-
break;
|
|
95
|
+
case scalar_js_1.ScalarType.BOOL:
|
|
96
|
+
return value === false;
|
|
97
|
+
case scalar_js_1.ScalarType.STRING:
|
|
98
|
+
return value === "";
|
|
99
|
+
case scalar_js_1.ScalarType.BYTES:
|
|
100
|
+
return value instanceof Uint8Array && !value.byteLength;
|
|
101
|
+
default:
|
|
102
|
+
return value == 0; // Loose comparison matches 0n, 0 and "0"
|
|
145
103
|
}
|
|
146
|
-
const method = field_js_1.ScalarType[type].toLowerCase();
|
|
147
|
-
return [wireType, method, isUndefined || isIntrinsicDefault];
|
|
148
104
|
}
|
|
149
|
-
exports.
|
|
105
|
+
exports.isScalarZeroValue = isScalarZeroValue;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { DescEnum } from "../descriptor-set.js";
|
|
2
|
-
import { ScalarType } from "../
|
|
2
|
+
import { ScalarType } from "../scalar.js";
|
|
3
3
|
export declare function parseTextFormatEnumValue(descEnum: DescEnum, value: string): number;
|
|
4
4
|
export declare function parseTextFormatScalarValue(type: ScalarType, value: string): number | boolean | string | bigint | Uint8Array;
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.parseTextFormatScalarValue = exports.parseTextFormatEnumValue = void 0;
|
|
17
17
|
const assert_js_1 = require("./assert.js");
|
|
18
|
-
const field_js_1 = require("../field.js");
|
|
19
18
|
const proto_int64_js_1 = require("../proto-int64.js");
|
|
19
|
+
const scalar_js_1 = require("../scalar.js");
|
|
20
20
|
function parseTextFormatEnumValue(descEnum, value) {
|
|
21
21
|
const enumValue = descEnum.values.find((v) => v.name === value);
|
|
22
22
|
(0, assert_js_1.assert)(enumValue, `cannot parse ${descEnum.name} default value: ${value}`);
|
|
@@ -25,24 +25,24 @@ function parseTextFormatEnumValue(descEnum, value) {
|
|
|
25
25
|
exports.parseTextFormatEnumValue = parseTextFormatEnumValue;
|
|
26
26
|
function parseTextFormatScalarValue(type, value) {
|
|
27
27
|
switch (type) {
|
|
28
|
-
case
|
|
28
|
+
case scalar_js_1.ScalarType.STRING:
|
|
29
29
|
return value;
|
|
30
|
-
case
|
|
30
|
+
case scalar_js_1.ScalarType.BYTES: {
|
|
31
31
|
const u = unescapeBytesDefaultValue(value);
|
|
32
32
|
if (u === false) {
|
|
33
|
-
throw new Error(`cannot parse ${
|
|
33
|
+
throw new Error(`cannot parse ${scalar_js_1.ScalarType[type]} default value: ${value}`);
|
|
34
34
|
}
|
|
35
35
|
return u;
|
|
36
36
|
}
|
|
37
|
-
case
|
|
38
|
-
case
|
|
39
|
-
case
|
|
37
|
+
case scalar_js_1.ScalarType.INT64:
|
|
38
|
+
case scalar_js_1.ScalarType.SFIXED64:
|
|
39
|
+
case scalar_js_1.ScalarType.SINT64:
|
|
40
40
|
return proto_int64_js_1.protoInt64.parse(value);
|
|
41
|
-
case
|
|
42
|
-
case
|
|
41
|
+
case scalar_js_1.ScalarType.UINT64:
|
|
42
|
+
case scalar_js_1.ScalarType.FIXED64:
|
|
43
43
|
return proto_int64_js_1.protoInt64.uParse(value);
|
|
44
|
-
case
|
|
45
|
-
case
|
|
44
|
+
case scalar_js_1.ScalarType.DOUBLE:
|
|
45
|
+
case scalar_js_1.ScalarType.FLOAT:
|
|
46
46
|
switch (value) {
|
|
47
47
|
case "inf":
|
|
48
48
|
return Number.POSITIVE_INFINITY;
|
|
@@ -53,13 +53,13 @@ function parseTextFormatScalarValue(type, value) {
|
|
|
53
53
|
default:
|
|
54
54
|
return parseFloat(value);
|
|
55
55
|
}
|
|
56
|
-
case
|
|
56
|
+
case scalar_js_1.ScalarType.BOOL:
|
|
57
57
|
return value === "true";
|
|
58
|
-
case
|
|
59
|
-
case
|
|
60
|
-
case
|
|
61
|
-
case
|
|
62
|
-
case
|
|
58
|
+
case scalar_js_1.ScalarType.INT32:
|
|
59
|
+
case scalar_js_1.ScalarType.UINT32:
|
|
60
|
+
case scalar_js_1.ScalarType.SINT32:
|
|
61
|
+
case scalar_js_1.ScalarType.FIXED32:
|
|
62
|
+
case scalar_js_1.ScalarType.SFIXED32:
|
|
63
63
|
return parseInt(value, 10);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.makeUtilCommon = void 0;
|
|
17
17
|
const enum_js_1 = require("./enum.js");
|
|
18
|
-
const message_js_1 = require("../message.js");
|
|
19
|
-
const field_js_1 = require("../field.js");
|
|
20
18
|
const scalars_js_1 = require("./scalars.js");
|
|
19
|
+
const scalar_js_1 = require("../scalar.js");
|
|
20
|
+
const is_message_js_1 = require("../is-message.js");
|
|
21
21
|
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-argument,no-case-declarations */
|
|
22
22
|
function makeUtilCommon() {
|
|
23
23
|
return {
|
|
@@ -30,6 +30,7 @@ function makeUtilCommon() {
|
|
|
30
30
|
for (const member of type.fields.byMember()) {
|
|
31
31
|
const localName = member.localName, t = target, s = source;
|
|
32
32
|
if (s[localName] === undefined) {
|
|
33
|
+
// TODO if source is a Message instance, we should use isFieldSet() here to support future field presence
|
|
33
34
|
continue;
|
|
34
35
|
}
|
|
35
36
|
switch (member.kind) {
|
|
@@ -42,12 +43,12 @@ function makeUtilCommon() {
|
|
|
42
43
|
let val = s[localName].value;
|
|
43
44
|
if (sourceField &&
|
|
44
45
|
sourceField.kind == "message" &&
|
|
45
|
-
!(val
|
|
46
|
+
!(0, is_message_js_1.isMessage)(val, sourceField.T)) {
|
|
46
47
|
val = new sourceField.T(val);
|
|
47
48
|
}
|
|
48
49
|
else if (sourceField &&
|
|
49
50
|
sourceField.kind === "scalar" &&
|
|
50
|
-
sourceField.T ===
|
|
51
|
+
sourceField.T === scalar_js_1.ScalarType.BYTES) {
|
|
51
52
|
val = toU8Arr(val);
|
|
52
53
|
}
|
|
53
54
|
t[localName] = { case: sk, value: val };
|
|
@@ -55,7 +56,7 @@ function makeUtilCommon() {
|
|
|
55
56
|
case "scalar":
|
|
56
57
|
case "enum":
|
|
57
58
|
let copy = s[localName];
|
|
58
|
-
if (member.T ===
|
|
59
|
+
if (member.T === scalar_js_1.ScalarType.BYTES) {
|
|
59
60
|
copy = member.repeated
|
|
60
61
|
? copy.map(toU8Arr)
|
|
61
62
|
: toU8Arr(copy);
|
|
@@ -66,7 +67,7 @@ function makeUtilCommon() {
|
|
|
66
67
|
switch (member.V.kind) {
|
|
67
68
|
case "scalar":
|
|
68
69
|
case "enum":
|
|
69
|
-
if (member.V.T ===
|
|
70
|
+
if (member.V.T === scalar_js_1.ScalarType.BYTES) {
|
|
70
71
|
for (const [k, v] of Object.entries(s[localName])) {
|
|
71
72
|
t[localName][k] = toU8Arr(v);
|
|
72
73
|
}
|
|
@@ -92,9 +93,9 @@ function makeUtilCommon() {
|
|
|
92
93
|
case "message":
|
|
93
94
|
const mt = member.T;
|
|
94
95
|
if (member.repeated) {
|
|
95
|
-
t[localName] = s[localName].map((val) => val
|
|
96
|
+
t[localName] = s[localName].map((val) => (0, is_message_js_1.isMessage)(val, mt) ? val : new mt(val));
|
|
96
97
|
}
|
|
97
|
-
else
|
|
98
|
+
else {
|
|
98
99
|
const val = s[localName];
|
|
99
100
|
if (mt.fieldWrapper) {
|
|
100
101
|
if (
|
|
@@ -107,13 +108,14 @@ function makeUtilCommon() {
|
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
else {
|
|
110
|
-
t[localName] = val
|
|
111
|
+
t[localName] = (0, is_message_js_1.isMessage)(val, mt) ? val : new mt(val);
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
break;
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
},
|
|
118
|
+
// TODO use isFieldSet() here to support future field presence
|
|
117
119
|
equals(type, a, b) {
|
|
118
120
|
if (a === b) {
|
|
119
121
|
return true;
|
|
@@ -135,7 +137,7 @@ function makeUtilCommon() {
|
|
|
135
137
|
case "scalar":
|
|
136
138
|
return va.every((a, i) => (0, scalars_js_1.scalarEquals)(m.T, a, vb[i]));
|
|
137
139
|
case "enum":
|
|
138
|
-
return va.every((a, i) => (0, scalars_js_1.scalarEquals)(
|
|
140
|
+
return va.every((a, i) => (0, scalars_js_1.scalarEquals)(scalar_js_1.ScalarType.INT32, a, vb[i]));
|
|
139
141
|
}
|
|
140
142
|
throw new Error(`repeated cannot contain ${m.kind}`);
|
|
141
143
|
}
|
|
@@ -143,7 +145,7 @@ function makeUtilCommon() {
|
|
|
143
145
|
case "message":
|
|
144
146
|
return m.T.equals(va, vb);
|
|
145
147
|
case "enum":
|
|
146
|
-
return (0, scalars_js_1.scalarEquals)(
|
|
148
|
+
return (0, scalars_js_1.scalarEquals)(scalar_js_1.ScalarType.INT32, va, vb);
|
|
147
149
|
case "scalar":
|
|
148
150
|
return (0, scalars_js_1.scalarEquals)(m.T, va, vb);
|
|
149
151
|
case "oneof":
|
|
@@ -159,7 +161,7 @@ function makeUtilCommon() {
|
|
|
159
161
|
case "message":
|
|
160
162
|
return s.T.equals(va.value, vb.value);
|
|
161
163
|
case "enum":
|
|
162
|
-
return (0, scalars_js_1.scalarEquals)(
|
|
164
|
+
return (0, scalars_js_1.scalarEquals)(scalar_js_1.ScalarType.INT32, va.value, vb.value);
|
|
163
165
|
case "scalar":
|
|
164
166
|
return (0, scalars_js_1.scalarEquals)(s.T, va.value, vb.value);
|
|
165
167
|
}
|
|
@@ -171,7 +173,7 @@ function makeUtilCommon() {
|
|
|
171
173
|
const messageType = m.V.T;
|
|
172
174
|
return keys.every((k) => messageType.equals(va[k], vb[k]));
|
|
173
175
|
case "enum":
|
|
174
|
-
return keys.every((k) => (0, scalars_js_1.scalarEquals)(
|
|
176
|
+
return keys.every((k) => (0, scalars_js_1.scalarEquals)(scalar_js_1.ScalarType.INT32, va[k], vb[k]));
|
|
175
177
|
case "scalar":
|
|
176
178
|
const scalarType = m.V.T;
|
|
177
179
|
return keys.every((k) => (0, scalars_js_1.scalarEquals)(scalarType, va[k], vb[k]));
|
|
@@ -180,6 +182,7 @@ function makeUtilCommon() {
|
|
|
180
182
|
}
|
|
181
183
|
});
|
|
182
184
|
},
|
|
185
|
+
// TODO use isFieldSet() here to support future field presence
|
|
183
186
|
clone(message) {
|
|
184
187
|
const type = message.getType(), target = new type(), any = target;
|
|
185
188
|
for (const member of type.fields.byMember()) {
|
|
@@ -215,7 +218,7 @@ function cloneSingularField(value) {
|
|
|
215
218
|
if (value === undefined) {
|
|
216
219
|
return value;
|
|
217
220
|
}
|
|
218
|
-
if (
|
|
221
|
+
if ((0, is_message_js_1.isMessage)(value)) {
|
|
219
222
|
return value.clone();
|
|
220
223
|
}
|
|
221
224
|
if (value instanceof Uint8Array) {
|
|
@@ -34,7 +34,6 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
|
34
34
|
};
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.protoDelimited = void 0;
|
|
37
|
-
const binary_format_common_js_1 = require("./private/binary-format-common.js");
|
|
38
37
|
const binary_encoding_js_1 = require("./binary-encoding.js");
|
|
39
38
|
/**
|
|
40
39
|
* protoDelimited provides functions to serialize and parse size-delimited
|
|
@@ -51,14 +50,14 @@ exports.protoDelimited = {
|
|
|
51
50
|
* Serialize a message, prefixing it with its size.
|
|
52
51
|
*/
|
|
53
52
|
enc(message, options) {
|
|
54
|
-
const opt =
|
|
53
|
+
const opt = message.getType().runtime.bin.makeWriteOptions(options);
|
|
55
54
|
return opt.writerFactory().bytes(message.toBinary(opt)).finish();
|
|
56
55
|
},
|
|
57
56
|
/**
|
|
58
57
|
* Parse a size-delimited message, ignoring extra bytes.
|
|
59
58
|
*/
|
|
60
59
|
dec(type, bytes, options) {
|
|
61
|
-
const opt =
|
|
60
|
+
const opt = type.runtime.bin.makeReadOptions(options);
|
|
62
61
|
return type.fromBinary(opt.readerFactory(bytes).bytes(), opt);
|
|
63
62
|
},
|
|
64
63
|
/**
|