@bufbuild/protobuf 1.7.2 → 1.9.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/binary-encoding.d.ts +2 -2
- 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 +4 -2
- 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/message.d.ts +1 -0
- package/dist/cjs/message.js +1 -0
- 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/names.js +3 -3
- 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 +20 -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/binary-encoding.d.ts +2 -2
- 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 +4 -2
- 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/message.d.ts +1 -0
- package/dist/esm/message.js +1 -0
- 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} +228 -136
- package/dist/esm/private/names.js +3 -3
- 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 +13 -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 +4 -10
- 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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
/**
|
|
15
|
+
* Scalar value types. This is a subset of field types declared by protobuf
|
|
16
|
+
* enum google.protobuf.FieldDescriptorProto.Type The types GROUP and MESSAGE
|
|
17
|
+
* are omitted, but the numerical values are identical.
|
|
18
|
+
*/
|
|
19
|
+
export var ScalarType;
|
|
20
|
+
(function (ScalarType) {
|
|
21
|
+
// 0 is reserved for errors.
|
|
22
|
+
// Order is weird for historical reasons.
|
|
23
|
+
ScalarType[ScalarType["DOUBLE"] = 1] = "DOUBLE";
|
|
24
|
+
ScalarType[ScalarType["FLOAT"] = 2] = "FLOAT";
|
|
25
|
+
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
|
|
26
|
+
// negative values are likely.
|
|
27
|
+
ScalarType[ScalarType["INT64"] = 3] = "INT64";
|
|
28
|
+
ScalarType[ScalarType["UINT64"] = 4] = "UINT64";
|
|
29
|
+
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
|
|
30
|
+
// negative values are likely.
|
|
31
|
+
ScalarType[ScalarType["INT32"] = 5] = "INT32";
|
|
32
|
+
ScalarType[ScalarType["FIXED64"] = 6] = "FIXED64";
|
|
33
|
+
ScalarType[ScalarType["FIXED32"] = 7] = "FIXED32";
|
|
34
|
+
ScalarType[ScalarType["BOOL"] = 8] = "BOOL";
|
|
35
|
+
ScalarType[ScalarType["STRING"] = 9] = "STRING";
|
|
36
|
+
// Tag-delimited aggregate.
|
|
37
|
+
// Group type is deprecated and not supported in proto3. However, Proto3
|
|
38
|
+
// implementations should still be able to parse the group wire format and
|
|
39
|
+
// treat group fields as unknown fields.
|
|
40
|
+
// TYPE_GROUP = 10,
|
|
41
|
+
// TYPE_MESSAGE = 11, // Length-delimited aggregate.
|
|
42
|
+
// New in version 2.
|
|
43
|
+
ScalarType[ScalarType["BYTES"] = 12] = "BYTES";
|
|
44
|
+
ScalarType[ScalarType["UINT32"] = 13] = "UINT32";
|
|
45
|
+
// TYPE_ENUM = 14,
|
|
46
|
+
ScalarType[ScalarType["SFIXED32"] = 15] = "SFIXED32";
|
|
47
|
+
ScalarType[ScalarType["SFIXED64"] = 16] = "SFIXED64";
|
|
48
|
+
ScalarType[ScalarType["SINT32"] = 17] = "SINT32";
|
|
49
|
+
ScalarType[ScalarType["SINT64"] = 18] = "SINT64";
|
|
50
|
+
})(ScalarType || (ScalarType = {}));
|
|
51
|
+
/**
|
|
52
|
+
* JavaScript representation of fields with 64 bit integral types (int64, uint64,
|
|
53
|
+
* sint64, fixed64, sfixed64).
|
|
54
|
+
*
|
|
55
|
+
* This is a subset of google.protobuf.FieldOptions.JSType, which defines JS_NORMAL,
|
|
56
|
+
* JS_STRING, and JS_NUMBER. Protobuf-ES uses BigInt by default, but will use
|
|
57
|
+
* String if `[jstype = JS_STRING]` is specified.
|
|
58
|
+
*
|
|
59
|
+
* ```protobuf
|
|
60
|
+
* uint64 field_a = 1; // BigInt
|
|
61
|
+
* uint64 field_b = 2 [jstype = JS_NORMAL]; // BigInt
|
|
62
|
+
* uint64 field_b = 2 [jstype = JS_NUMBER]; // BigInt
|
|
63
|
+
* uint64 field_b = 2 [jstype = JS_STRING]; // String
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export var LongType;
|
|
67
|
+
(function (LongType) {
|
|
68
|
+
/**
|
|
69
|
+
* Use JavaScript BigInt.
|
|
70
|
+
*/
|
|
71
|
+
LongType[LongType["BIGINT"] = 0] = "BIGINT";
|
|
72
|
+
/**
|
|
73
|
+
* Use JavaScript String.
|
|
74
|
+
*
|
|
75
|
+
* Field option `[jstype = JS_STRING]`.
|
|
76
|
+
*/
|
|
77
|
+
LongType[LongType["STRING"] = 1] = "STRING";
|
|
78
|
+
})(LongType || (LongType = {}));
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
/* 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 */
|
|
15
15
|
import { Message } from "./message.js";
|
|
16
|
+
import { isMessage } from "./is-message.js";
|
|
16
17
|
/**
|
|
17
18
|
* toPlainMessage returns a new object by stripping
|
|
18
19
|
* all methods from a message, leaving only fields and
|
|
@@ -23,7 +24,7 @@ import { Message } from "./message.js";
|
|
|
23
24
|
* returned as-is.
|
|
24
25
|
*/
|
|
25
26
|
export function toPlainMessage(message) {
|
|
26
|
-
if (!(message
|
|
27
|
+
if (!isMessage(message)) {
|
|
27
28
|
return message;
|
|
28
29
|
}
|
|
29
30
|
const type = message.getType();
|
|
@@ -57,7 +58,7 @@ function toPlainValue(value) {
|
|
|
57
58
|
if (value === undefined) {
|
|
58
59
|
return value;
|
|
59
60
|
}
|
|
60
|
-
if (value
|
|
61
|
+
if (isMessage(value)) {
|
|
61
62
|
return toPlainMessage(value);
|
|
62
63
|
}
|
|
63
64
|
if (value instanceof Uint8Array) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protobuf",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.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": {
|
|
@@ -10,10 +10,9 @@
|
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"clean": "rm -rf ./dist/*",
|
|
13
|
-
"build": "npm run build:cjs && npm run build:esm
|
|
14
|
-
"build:cjs": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
|
|
15
|
-
"build:esm": "../../node_modules/typescript/bin/tsc --project tsconfig.json --
|
|
16
|
-
"build:proxy": "node ../../scripts/gen-esm-proxy.mjs .",
|
|
13
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
14
|
+
"build:cjs": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
|
|
15
|
+
"build:esm": "../../node_modules/typescript/bin/tsc --project tsconfig.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
|
|
17
16
|
"bootstrap:featureset-defaults": "upstream-inject-feature-defaults src/private/feature-set.ts",
|
|
18
17
|
"prebootstrap:wkt": "rm -rf .tmp && mkdir -p .tmp/google/protobuf && cp -rp src/google/protobuf/* .tmp/google/protobuf",
|
|
19
18
|
"bootstrap:wkt": "protoc --es_out=src --es_opt=bootstrap_wkt=true,ts_nocheck=false,target=ts --proto_path $(upstream-include wkt) $(upstream-files wkt) && license-header src/google/protobuf",
|
|
@@ -25,11 +24,6 @@
|
|
|
25
24
|
"main": "./dist/cjs/index.js",
|
|
26
25
|
"exports": {
|
|
27
26
|
".": {
|
|
28
|
-
"node": {
|
|
29
|
-
"import": "./dist/proxy/index.js",
|
|
30
|
-
"require": "./dist/cjs/index.js"
|
|
31
|
-
},
|
|
32
|
-
"module": "./dist/esm/index.js",
|
|
33
27
|
"import": "./dist/esm/index.js",
|
|
34
28
|
"require": "./dist/cjs/index.js"
|
|
35
29
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { IBinaryWriter } from "../binary-encoding.js";
|
|
2
|
-
import type { BinaryFormat, BinaryWriteOptions } from "../binary-format.js";
|
|
3
|
-
import type { FieldInfo } from "../field.js";
|
|
4
|
-
import { ScalarType } from "../field.js";
|
|
5
|
-
export declare function makeBinaryFormatCommon(): Omit<BinaryFormat, "writeMessage" | "writeField">;
|
|
6
|
-
export declare function writeMapEntry(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & {
|
|
7
|
-
kind: "map";
|
|
8
|
-
}, key: any, value: any): void;
|
|
9
|
-
export declare function writeMessageField(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & {
|
|
10
|
-
kind: "message";
|
|
11
|
-
}, value: any): void;
|
|
12
|
-
export declare function writeScalar(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any, emitIntrinsicDefault: boolean): void;
|
|
13
|
-
export declare function writePacked(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any[]): void;
|
|
@@ -1,91 +0,0 @@
|
|
|
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.makeBinaryFormatProto2 = void 0;
|
|
17
|
-
const field_js_1 = require("../field.js");
|
|
18
|
-
const binary_format_common_js_1 = require("./binary-format-common.js");
|
|
19
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/strict-boolean-expressions, no-case-declarations, prefer-const */
|
|
20
|
-
function makeBinaryFormatProto2() {
|
|
21
|
-
return Object.assign(Object.assign({}, (0, binary_format_common_js_1.makeBinaryFormatCommon)()), { writeField,
|
|
22
|
-
writeMessage(message, writer, options) {
|
|
23
|
-
const type = message.getType();
|
|
24
|
-
let field;
|
|
25
|
-
for (field of type.fields.byNumber()) {
|
|
26
|
-
let value, localName = field.localName;
|
|
27
|
-
if (field.oneof) {
|
|
28
|
-
const oneof = message[field.oneof.localName];
|
|
29
|
-
if (oneof.case !== localName) {
|
|
30
|
-
continue; // field is not selected, skip
|
|
31
|
-
}
|
|
32
|
-
value = oneof.value;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
value = message[localName];
|
|
36
|
-
// In contrast to proto3, we raise an error if a non-optional (proto2 required)
|
|
37
|
-
// field is missing a value.
|
|
38
|
-
if (value === undefined && !field.oneof && !field.opt) {
|
|
39
|
-
throw new Error(`cannot encode field ${type.typeName}.${field === null || field === void 0 ? void 0 : field.name} to binary: required field not set`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
writeField(field, value, writer, options);
|
|
43
|
-
}
|
|
44
|
-
if (options.writeUnknownFields) {
|
|
45
|
-
this.writeUnknownFields(message, writer);
|
|
46
|
-
}
|
|
47
|
-
return writer;
|
|
48
|
-
} });
|
|
49
|
-
}
|
|
50
|
-
exports.makeBinaryFormatProto2 = makeBinaryFormatProto2;
|
|
51
|
-
// TODO field presence: merge this function with proto3
|
|
52
|
-
function writeField(field, value, // eslint-disable-line @typescript-eslint/no-explicit-any -- `any` is the best choice for dynamic access
|
|
53
|
-
writer, options) {
|
|
54
|
-
const repeated = field.repeated;
|
|
55
|
-
switch (field.kind) {
|
|
56
|
-
case "scalar":
|
|
57
|
-
case "enum":
|
|
58
|
-
let scalarType = field.kind == "enum" ? field_js_1.ScalarType.INT32 : field.T;
|
|
59
|
-
if (repeated) {
|
|
60
|
-
if (field.packed) {
|
|
61
|
-
(0, binary_format_common_js_1.writePacked)(writer, scalarType, field.no, value);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
for (const item of value) {
|
|
65
|
-
(0, binary_format_common_js_1.writeScalar)(writer, scalarType, field.no, item, true);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else if (value !== undefined) {
|
|
70
|
-
// In contrast to proto3, we do not skip intrinsic default values.
|
|
71
|
-
// Explicit default values are not special cased either.
|
|
72
|
-
(0, binary_format_common_js_1.writeScalar)(writer, scalarType, field.no, value, true);
|
|
73
|
-
}
|
|
74
|
-
break;
|
|
75
|
-
case "message":
|
|
76
|
-
if (repeated) {
|
|
77
|
-
for (const item of value) {
|
|
78
|
-
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, item);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else if (value !== undefined) {
|
|
82
|
-
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, value);
|
|
83
|
-
}
|
|
84
|
-
break;
|
|
85
|
-
case "map":
|
|
86
|
-
for (const [key, val] of Object.entries(value)) {
|
|
87
|
-
(0, binary_format_common_js_1.writeMapEntry)(writer, options, field, key, val);
|
|
88
|
-
}
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
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.makeBinaryFormatProto3 = void 0;
|
|
17
|
-
const field_js_1 = require("../field.js");
|
|
18
|
-
const binary_format_common_js_1 = require("./binary-format-common.js");
|
|
19
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/strict-boolean-expressions, prefer-const, no-case-declarations */
|
|
20
|
-
function makeBinaryFormatProto3() {
|
|
21
|
-
return Object.assign(Object.assign({}, (0, binary_format_common_js_1.makeBinaryFormatCommon)()), { writeField,
|
|
22
|
-
writeMessage(message, writer, options) {
|
|
23
|
-
const type = message.getType();
|
|
24
|
-
for (const field of type.fields.byNumber()) {
|
|
25
|
-
let value, localName = field.localName;
|
|
26
|
-
if (field.oneof) {
|
|
27
|
-
const oneof = message[field.oneof.localName];
|
|
28
|
-
if (oneof.case !== localName) {
|
|
29
|
-
continue; // field is not selected, skip
|
|
30
|
-
}
|
|
31
|
-
value = oneof.value;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
value = message[localName];
|
|
35
|
-
}
|
|
36
|
-
writeField(field, value, writer, options);
|
|
37
|
-
}
|
|
38
|
-
if (options.writeUnknownFields) {
|
|
39
|
-
this.writeUnknownFields(message, writer);
|
|
40
|
-
}
|
|
41
|
-
return writer;
|
|
42
|
-
} });
|
|
43
|
-
}
|
|
44
|
-
exports.makeBinaryFormatProto3 = makeBinaryFormatProto3;
|
|
45
|
-
// TODO field presence: merge this function with proto2
|
|
46
|
-
function writeField(field, value, // eslint-disable-line @typescript-eslint/no-explicit-any -- `any` is the best choice for dynamic access
|
|
47
|
-
writer, options) {
|
|
48
|
-
const repeated = field.repeated;
|
|
49
|
-
switch (field.kind) {
|
|
50
|
-
case "scalar":
|
|
51
|
-
case "enum":
|
|
52
|
-
let scalarType = field.kind == "enum" ? field_js_1.ScalarType.INT32 : field.T;
|
|
53
|
-
if (repeated) {
|
|
54
|
-
if (field.packed) {
|
|
55
|
-
(0, binary_format_common_js_1.writePacked)(writer, scalarType, field.no, value);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
for (const item of value) {
|
|
59
|
-
(0, binary_format_common_js_1.writeScalar)(writer, scalarType, field.no, item, true);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else if (value !== undefined) {
|
|
64
|
-
(0, binary_format_common_js_1.writeScalar)(writer, scalarType, field.no, value, !!field.oneof || field.opt);
|
|
65
|
-
}
|
|
66
|
-
break;
|
|
67
|
-
case "message":
|
|
68
|
-
if (repeated) {
|
|
69
|
-
for (const item of value) {
|
|
70
|
-
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, item);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else if (value !== undefined) {
|
|
74
|
-
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, value);
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
case "map":
|
|
78
|
-
for (const [key, val] of Object.entries(value)) {
|
|
79
|
-
(0, binary_format_common_js_1.writeMapEntry)(writer, options, field, key, val);
|
|
80
|
-
}
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { JsonFormat, JsonValue, JsonWriteOptions } from "../json-format.js";
|
|
2
|
-
import type { FieldInfo } from "../field.js";
|
|
3
|
-
import { ScalarType } from "../field.js";
|
|
4
|
-
import type { EnumType } from "../enum.js";
|
|
5
|
-
type JsonFormatWriteFieldFn = (field: FieldInfo, value: any, options: JsonWriteOptions) => JsonValue | undefined;
|
|
6
|
-
export declare function makeJsonFormatCommon(nullAsZeroValue: boolean, makeWriteField: (writeEnumFn: typeof writeEnum, writeScalarFn: typeof writeScalar) => JsonFormatWriteFieldFn): JsonFormat;
|
|
7
|
-
declare function writeEnum(type: EnumType, value: number | undefined, emitZeroValue: boolean, enumAsInteger: boolean): JsonValue | undefined;
|
|
8
|
-
declare function writeScalar(type: ScalarType, value: any, emitZeroValue: boolean): JsonValue | undefined;
|
|
9
|
-
export {};
|
|
@@ -1,103 +0,0 @@
|
|
|
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.makeJsonFormatProto2 = void 0;
|
|
17
|
-
const field_wrapper_js_1 = require("./field-wrapper.js");
|
|
18
|
-
const assert_js_1 = require("./assert.js");
|
|
19
|
-
const json_format_common_js_1 = require("./json-format-common.js");
|
|
20
|
-
/* eslint-disable no-case-declarations, @typescript-eslint/restrict-plus-operands,@typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
21
|
-
function makeJsonFormatProto2() {
|
|
22
|
-
// TODO field presence: merge this function with proto3. the reading side already switches behavior on the nullAsZeroValue argument.
|
|
23
|
-
return (0, json_format_common_js_1.makeJsonFormatCommon)(false, (writeEnum, writeScalar) => {
|
|
24
|
-
return function writeField(field, value, options) {
|
|
25
|
-
if (field.kind == "map") {
|
|
26
|
-
const jsonObj = {};
|
|
27
|
-
switch (field.V.kind) {
|
|
28
|
-
case "scalar":
|
|
29
|
-
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
30
|
-
const val = writeScalar(field.V.T, entryValue, true);
|
|
31
|
-
(0, assert_js_1.assert)(val !== undefined);
|
|
32
|
-
jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
|
|
33
|
-
}
|
|
34
|
-
break;
|
|
35
|
-
case "message":
|
|
36
|
-
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
37
|
-
// JSON standard allows only (double quoted) string as property key
|
|
38
|
-
jsonObj[entryKey.toString()] = entryValue.toJson(options);
|
|
39
|
-
}
|
|
40
|
-
break;
|
|
41
|
-
case "enum":
|
|
42
|
-
const enumType = field.V.T;
|
|
43
|
-
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
44
|
-
(0, assert_js_1.assert)(entryValue === undefined || typeof entryValue == "number");
|
|
45
|
-
const val = writeEnum(enumType, entryValue, true, options.enumAsInteger);
|
|
46
|
-
(0, assert_js_1.assert)(val !== undefined);
|
|
47
|
-
jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
|
|
48
|
-
}
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
return options.emitDefaultValues || Object.keys(jsonObj).length > 0
|
|
52
|
-
? jsonObj
|
|
53
|
-
: undefined;
|
|
54
|
-
}
|
|
55
|
-
else if (field.repeated) {
|
|
56
|
-
const jsonArr = [];
|
|
57
|
-
switch (field.kind) {
|
|
58
|
-
case "scalar":
|
|
59
|
-
for (let i = 0; i < value.length; i++) {
|
|
60
|
-
jsonArr.push(writeScalar(field.T, value[i], true));
|
|
61
|
-
}
|
|
62
|
-
break;
|
|
63
|
-
case "enum":
|
|
64
|
-
for (let i = 0; i < value.length; i++) {
|
|
65
|
-
jsonArr.push(writeEnum(field.T, value[i], true, options.enumAsInteger));
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
case "message":
|
|
69
|
-
for (let i = 0; i < value.length; i++) {
|
|
70
|
-
jsonArr.push(value[i].toJson(options));
|
|
71
|
-
}
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
return options.emitDefaultValues || jsonArr.length > 0
|
|
75
|
-
? jsonArr
|
|
76
|
-
: undefined;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
// In contrast to proto3, we raise an error if a non-optional (proto2 required)
|
|
80
|
-
// field is missing a value.
|
|
81
|
-
if (value === undefined) {
|
|
82
|
-
if (!field.oneof && !field.opt) {
|
|
83
|
-
throw `required field not set`;
|
|
84
|
-
}
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
switch (field.kind) {
|
|
88
|
-
case "scalar":
|
|
89
|
-
// In contrast to proto3, we do not skip intrinsic default values.
|
|
90
|
-
// Explicit default values are not special cased either.
|
|
91
|
-
return writeScalar(field.T, value, true);
|
|
92
|
-
case "enum":
|
|
93
|
-
// In contrast to proto3, we do not skip intrinsic default values.
|
|
94
|
-
// Explicit default values are not special cased either.
|
|
95
|
-
return writeEnum(field.T, value, true, options.enumAsInteger);
|
|
96
|
-
case "message":
|
|
97
|
-
return (0, field_wrapper_js_1.wrapField)(field.T, value).toJson(options);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
exports.makeJsonFormatProto2 = makeJsonFormatProto2;
|
|
@@ -1,94 +0,0 @@
|
|
|
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.makeJsonFormatProto3 = void 0;
|
|
17
|
-
const field_wrapper_js_1 = require("./field-wrapper.js");
|
|
18
|
-
const assert_js_1 = require("./assert.js");
|
|
19
|
-
const json_format_common_js_1 = require("./json-format-common.js");
|
|
20
|
-
/* eslint-disable no-case-declarations, @typescript-eslint/restrict-plus-operands,@typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
21
|
-
function makeJsonFormatProto3() {
|
|
22
|
-
// TODO field presence: merge this function with proto2. the reading side already switches behavior on the nullAsZeroValue argument.
|
|
23
|
-
return (0, json_format_common_js_1.makeJsonFormatCommon)(true, (writeEnum, writeScalar) => {
|
|
24
|
-
return function writeField(field, value, options) {
|
|
25
|
-
if (field.kind == "map") {
|
|
26
|
-
const jsonObj = {};
|
|
27
|
-
switch (field.V.kind) {
|
|
28
|
-
case "scalar":
|
|
29
|
-
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
30
|
-
const val = writeScalar(field.V.T, entryValue, true);
|
|
31
|
-
(0, assert_js_1.assert)(val !== undefined);
|
|
32
|
-
jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
|
|
33
|
-
}
|
|
34
|
-
break;
|
|
35
|
-
case "message":
|
|
36
|
-
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
37
|
-
// JSON standard allows only (double quoted) string as property key
|
|
38
|
-
jsonObj[entryKey.toString()] = entryValue.toJson(options);
|
|
39
|
-
}
|
|
40
|
-
break;
|
|
41
|
-
case "enum":
|
|
42
|
-
const enumType = field.V.T;
|
|
43
|
-
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
44
|
-
(0, assert_js_1.assert)(entryValue === undefined || typeof entryValue == "number");
|
|
45
|
-
const val = writeEnum(enumType, entryValue, true, options.enumAsInteger);
|
|
46
|
-
(0, assert_js_1.assert)(val !== undefined);
|
|
47
|
-
jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
|
|
48
|
-
}
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
return options.emitDefaultValues || Object.keys(jsonObj).length > 0
|
|
52
|
-
? jsonObj
|
|
53
|
-
: undefined;
|
|
54
|
-
}
|
|
55
|
-
else if (field.repeated) {
|
|
56
|
-
const jsonArr = [];
|
|
57
|
-
switch (field.kind) {
|
|
58
|
-
case "scalar":
|
|
59
|
-
for (let i = 0; i < value.length; i++) {
|
|
60
|
-
jsonArr.push(writeScalar(field.T, value[i], true));
|
|
61
|
-
}
|
|
62
|
-
break;
|
|
63
|
-
case "enum":
|
|
64
|
-
for (let i = 0; i < value.length; i++) {
|
|
65
|
-
jsonArr.push(writeEnum(field.T, value[i], true, options.enumAsInteger));
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
case "message":
|
|
69
|
-
for (let i = 0; i < value.length; i++) {
|
|
70
|
-
jsonArr.push(value[i].toJson(options));
|
|
71
|
-
}
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
return options.emitDefaultValues || jsonArr.length > 0
|
|
75
|
-
? jsonArr
|
|
76
|
-
: undefined;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
if (value === undefined) {
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
switch (field.kind) {
|
|
83
|
-
case "scalar":
|
|
84
|
-
return writeScalar(field.T, value, !!field.oneof || field.opt || options.emitDefaultValues);
|
|
85
|
-
case "enum":
|
|
86
|
-
return writeEnum(field.T, value, !!field.oneof || field.opt || options.emitDefaultValues, options.enumAsInteger);
|
|
87
|
-
case "message":
|
|
88
|
-
return (0, field_wrapper_js_1.wrapField)(field.T, value).toJson(options);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
exports.makeJsonFormatProto3 = makeJsonFormatProto3;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { IBinaryWriter } from "../binary-encoding.js";
|
|
2
|
-
import type { BinaryFormat, BinaryWriteOptions } from "../binary-format.js";
|
|
3
|
-
import type { FieldInfo } from "../field.js";
|
|
4
|
-
import { ScalarType } from "../field.js";
|
|
5
|
-
export declare function makeBinaryFormatCommon(): Omit<BinaryFormat, "writeMessage" | "writeField">;
|
|
6
|
-
export declare function writeMapEntry(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & {
|
|
7
|
-
kind: "map";
|
|
8
|
-
}, key: any, value: any): void;
|
|
9
|
-
export declare function writeMessageField(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & {
|
|
10
|
-
kind: "message";
|
|
11
|
-
}, value: any): void;
|
|
12
|
-
export declare function writeScalar(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any, emitIntrinsicDefault: boolean): void;
|
|
13
|
-
export declare function writePacked(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any[]): void;
|