@bufbuild/protobuf 1.6.0 → 1.7.1
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.js +2 -3
- package/dist/cjs/binary-format.d.ts +17 -0
- package/dist/cjs/binary-format.js +1 -1
- package/dist/cjs/codegen-info.d.ts +4 -4
- package/dist/cjs/codegen-info.js +2 -1
- package/dist/cjs/create-descriptor-set.d.ts +7 -1
- package/dist/cjs/create-descriptor-set.js +56 -50
- package/dist/cjs/create-registry-from-desc.d.ts +2 -2
- package/dist/cjs/create-registry-from-desc.js +53 -9
- package/dist/cjs/create-registry.d.ts +3 -2
- package/dist/cjs/create-registry.js +56 -37
- package/dist/cjs/descriptor-set.js +1 -1
- package/dist/cjs/enum.js +1 -1
- package/dist/cjs/extension-accessor.d.ts +35 -0
- package/dist/cjs/extension-accessor.js +108 -0
- package/dist/cjs/extension.d.ts +24 -0
- package/dist/cjs/extension.js +15 -0
- package/dist/cjs/field-list.js +1 -1
- package/dist/cjs/field.js +1 -1
- package/dist/cjs/google/protobuf/any_pb.js +1 -1
- package/dist/cjs/google/protobuf/api_pb.js +1 -1
- package/dist/cjs/google/protobuf/compiler/plugin_pb.js +1 -1
- package/dist/cjs/google/protobuf/descriptor_pb.js +2 -2
- package/dist/cjs/google/protobuf/duration_pb.js +1 -1
- package/dist/cjs/google/protobuf/empty_pb.js +1 -1
- package/dist/cjs/google/protobuf/field_mask_pb.js +1 -1
- package/dist/cjs/google/protobuf/source_context_pb.js +1 -1
- package/dist/cjs/google/protobuf/struct_pb.js +2 -2
- package/dist/cjs/google/protobuf/timestamp_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +2 -2
- package/dist/cjs/google/protobuf/wrappers_pb.js +1 -1
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +7 -2
- package/dist/cjs/json-format.d.ts +5 -5
- package/dist/cjs/json-format.js +1 -1
- package/dist/cjs/message-type.js +1 -1
- package/dist/cjs/message.js +1 -1
- package/dist/cjs/private/assert.js +1 -1
- package/dist/cjs/private/binary-format-common.d.ts +2 -3
- package/dist/cjs/private/binary-format-common.js +80 -78
- package/dist/cjs/private/binary-format-proto2.js +59 -64
- package/dist/cjs/private/binary-format-proto3.js +44 -40
- package/dist/cjs/private/enum.js +1 -1
- package/dist/cjs/private/extensions.d.ts +34 -0
- package/dist/cjs/private/extensions.js +86 -0
- package/dist/cjs/private/feature-set.d.ts +6 -8
- package/dist/cjs/private/feature-set.js +41 -42
- package/dist/cjs/private/field-list.js +1 -1
- package/dist/cjs/private/field-wrapper.d.ts +2 -2
- package/dist/cjs/private/field-wrapper.js +1 -1
- package/dist/cjs/private/field.js +1 -1
- package/dist/cjs/private/json-format-common.d.ts +3 -3
- package/dist/cjs/private/json-format-common.js +228 -173
- package/dist/cjs/private/json-format-proto2.js +3 -2
- package/dist/cjs/private/json-format-proto3.js +8 -6
- package/dist/cjs/private/message-type.js +1 -1
- package/dist/cjs/private/names.d.ts +2 -2
- package/dist/cjs/private/names.js +3 -2
- package/dist/cjs/private/options-map.js +1 -1
- package/dist/cjs/private/proto-runtime.d.ts +6 -0
- package/dist/cjs/private/proto-runtime.js +5 -1
- package/dist/cjs/private/reify-wkt.js +1 -1
- package/dist/cjs/private/scalars.js +1 -1
- package/dist/cjs/private/text-format.js +1 -1
- package/dist/cjs/private/util-common.js +1 -1
- package/dist/cjs/private/util.js +1 -1
- package/dist/cjs/proto-base64.js +1 -1
- package/dist/cjs/proto-delimited.js +1 -1
- package/dist/cjs/proto-double.js +1 -1
- package/dist/cjs/proto-int64.js +1 -1
- package/dist/cjs/proto2.js +1 -1
- package/dist/cjs/proto3.js +1 -1
- package/dist/cjs/service-type.js +1 -1
- package/dist/cjs/to-plain-message.js +1 -1
- package/dist/cjs/type-registry.d.ts +14 -0
- package/dist/cjs/type-registry.js +1 -1
- package/dist/esm/binary-encoding.js +2 -3
- package/dist/esm/binary-format.d.ts +17 -0
- package/dist/esm/binary-format.js +1 -1
- package/dist/esm/codegen-info.d.ts +4 -4
- package/dist/esm/codegen-info.js +2 -1
- package/dist/esm/create-descriptor-set.d.ts +7 -1
- package/dist/esm/create-descriptor-set.js +57 -51
- package/dist/esm/create-registry-from-desc.d.ts +2 -2
- package/dist/esm/create-registry-from-desc.js +53 -9
- package/dist/esm/create-registry.d.ts +3 -2
- package/dist/esm/create-registry.js +56 -37
- package/dist/esm/descriptor-set.js +1 -1
- package/dist/esm/enum.js +1 -1
- package/dist/esm/extension-accessor.d.ts +35 -0
- package/dist/esm/extension-accessor.js +101 -0
- package/dist/esm/extension.d.ts +24 -0
- package/dist/esm/extension.js +14 -0
- package/dist/esm/field-list.js +1 -1
- package/dist/esm/field.js +1 -1
- package/dist/esm/google/protobuf/any_pb.js +1 -1
- package/dist/esm/google/protobuf/api_pb.js +1 -1
- package/dist/esm/google/protobuf/compiler/plugin_pb.js +1 -1
- package/dist/esm/google/protobuf/descriptor_pb.js +2 -2
- package/dist/esm/google/protobuf/duration_pb.js +1 -1
- package/dist/esm/google/protobuf/empty_pb.js +1 -1
- package/dist/esm/google/protobuf/field_mask_pb.js +1 -1
- package/dist/esm/google/protobuf/source_context_pb.js +1 -1
- package/dist/esm/google/protobuf/struct_pb.js +2 -2
- package/dist/esm/google/protobuf/timestamp_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +2 -2
- 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/json-format.d.ts +5 -5
- package/dist/esm/json-format.js +1 -1
- package/dist/esm/message-type.js +1 -1
- package/dist/esm/message.js +1 -1
- package/dist/esm/private/assert.js +1 -1
- package/dist/esm/private/binary-format-common.d.ts +2 -3
- package/dist/esm/private/binary-format-common.js +80 -77
- package/dist/esm/private/binary-format-proto2.js +59 -64
- package/dist/esm/private/binary-format-proto3.js +44 -40
- package/dist/esm/private/enum.js +1 -1
- package/dist/esm/private/extensions.d.ts +34 -0
- package/dist/esm/private/extensions.js +81 -0
- package/dist/esm/private/feature-set.d.ts +6 -8
- package/dist/esm/private/feature-set.js +40 -41
- package/dist/esm/private/field-list.js +1 -1
- package/dist/esm/private/field-wrapper.d.ts +2 -2
- package/dist/esm/private/field-wrapper.js +1 -1
- package/dist/esm/private/field.js +1 -1
- package/dist/esm/private/json-format-common.d.ts +3 -3
- package/dist/esm/private/json-format-common.js +228 -173
- package/dist/esm/private/json-format-proto2.js +3 -2
- package/dist/esm/private/json-format-proto3.js +8 -6
- package/dist/esm/private/message-type.js +1 -1
- package/dist/esm/private/names.d.ts +2 -2
- package/dist/esm/private/names.js +3 -2
- package/dist/esm/private/options-map.js +1 -1
- package/dist/esm/private/proto-runtime.d.ts +6 -0
- package/dist/esm/private/proto-runtime.js +5 -1
- package/dist/esm/private/reify-wkt.js +1 -1
- package/dist/esm/private/scalars.js +1 -1
- package/dist/esm/private/text-format.js +1 -1
- package/dist/esm/private/util-common.js +1 -1
- package/dist/esm/private/util.js +1 -1
- package/dist/esm/proto-base64.js +1 -1
- package/dist/esm/proto-delimited.js +1 -1
- package/dist/esm/proto-double.js +1 -1
- package/dist/esm/proto-int64.js +1 -1
- package/dist/esm/proto2.js +1 -1
- package/dist/esm/proto3.js +1 -1
- package/dist/esm/service-type.js +1 -1
- package/dist/esm/to-plain-message.js +1 -1
- package/dist/esm/type-registry.d.ts +14 -0
- package/dist/esm/type-registry.js +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright 2021-
|
|
2
|
+
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
3
3
|
//
|
|
4
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
// you may not use this file except in compliance with the License.
|
|
@@ -13,60 +13,59 @@
|
|
|
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.createFeatureResolver =
|
|
16
|
+
exports.createFeatureResolver = void 0;
|
|
17
17
|
const descriptor_pb_js_1 = require("../google/protobuf/descriptor_pb.js");
|
|
18
18
|
const proto_base64_js_1 = require("../proto-base64.js");
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Return the edition feature defaults supported by @bufbuild/protobuf.
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
function getFeatureSetDefaults(options) {
|
|
23
|
+
return descriptor_pb_js_1.FeatureSetDefaults.fromBinary(proto_base64_js_1.protoBase64.dec(
|
|
24
|
+
/*upstream-inject-feature-defaults-start*/ "ChESDAgBEAIYAiABKAEwAhjmBwoREgwIAhABGAEgAigBMAEY5wcKERIMCAEQARgBIAIoATABGOgHIOYHKOgH" /*upstream-inject-feature-defaults-end*/), options);
|
|
25
|
+
}
|
|
24
26
|
/**
|
|
25
|
-
* Create an edition feature resolver with the given feature set defaults
|
|
27
|
+
* Create an edition feature resolver with the given feature set defaults, or
|
|
28
|
+
* the feature set defaults supported by @bufbuild/protobuf.
|
|
26
29
|
*/
|
|
27
|
-
function createFeatureResolver(compiledFeatureSetDefaults) {
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
+
function createFeatureResolver(edition, compiledFeatureSetDefaults, serializationOptions) {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
const fds = compiledFeatureSetDefaults !== null && compiledFeatureSetDefaults !== void 0 ? compiledFeatureSetDefaults : getFeatureSetDefaults(serializationOptions);
|
|
33
|
+
const min = fds.minimumEdition;
|
|
34
|
+
const max = fds.maximumEdition;
|
|
30
35
|
if (min === undefined ||
|
|
31
36
|
max === undefined ||
|
|
32
|
-
|
|
37
|
+
fds.defaults.some((d) => d.edition === undefined)) {
|
|
33
38
|
throw new Error("Invalid FeatureSetDefaults");
|
|
34
39
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (e > edition) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
if (highestMatch !== undefined && highestMatch.e > e) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
highestMatch = {
|
|
56
|
-
e,
|
|
57
|
-
f: (_b = c.features) !== null && _b !== void 0 ? _b : new descriptor_pb_js_1.FeatureSet(),
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
if (highestMatch === undefined) {
|
|
61
|
-
throw new Error(`No valid default found for edition ${descriptor_pb_js_1.Edition[edition]}`);
|
|
62
|
-
}
|
|
63
|
-
defaultsBin = highestMatch.f.toBinary();
|
|
64
|
-
defaultsBinByEdition.set(edition, defaultsBin);
|
|
40
|
+
if (edition < min) {
|
|
41
|
+
throw new Error(`Edition ${descriptor_pb_js_1.Edition[edition]} is earlier than the minimum supported edition ${descriptor_pb_js_1.Edition[min]}`);
|
|
42
|
+
}
|
|
43
|
+
if (max < edition) {
|
|
44
|
+
throw new Error(`Edition ${descriptor_pb_js_1.Edition[edition]} is later than the maximum supported edition ${descriptor_pb_js_1.Edition[max]}`);
|
|
45
|
+
}
|
|
46
|
+
let highestMatch = undefined;
|
|
47
|
+
for (const c of fds.defaults) {
|
|
48
|
+
const e = (_a = c.edition) !== null && _a !== void 0 ? _a : 0;
|
|
49
|
+
if (e > edition) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (highestMatch !== undefined && highestMatch.e > e) {
|
|
53
|
+
continue;
|
|
65
54
|
}
|
|
66
|
-
|
|
55
|
+
highestMatch = {
|
|
56
|
+
e,
|
|
57
|
+
f: (_b = c.features) !== null && _b !== void 0 ? _b : new descriptor_pb_js_1.FeatureSet(),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (highestMatch === undefined) {
|
|
61
|
+
throw new Error(`No valid default found for edition ${descriptor_pb_js_1.Edition[edition]}`);
|
|
62
|
+
}
|
|
63
|
+
const featureSetBin = highestMatch.f.toBinary(serializationOptions);
|
|
64
|
+
return (...rest) => {
|
|
65
|
+
const f = descriptor_pb_js_1.FeatureSet.fromBinary(featureSetBin, serializationOptions);
|
|
67
66
|
for (const c of rest) {
|
|
68
67
|
if (c !== undefined) {
|
|
69
|
-
f.fromBinary(c.toBinary());
|
|
68
|
+
f.fromBinary(c.toBinary(serializationOptions), serializationOptions);
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
71
|
if (!validateMergedFeatures(f)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Message } from "../message.js";
|
|
2
2
|
import type { MessageType } from "../message-type.js";
|
|
3
|
-
import type { DescField } from "../descriptor-set.js";
|
|
3
|
+
import type { DescExtension, DescField } from "../descriptor-set.js";
|
|
4
4
|
import { ScalarType } from "../field.js";
|
|
5
5
|
/**
|
|
6
6
|
* A field wrapper unwraps a message to a primitive value that is more
|
|
@@ -22,4 +22,4 @@ export declare function wrapField<T extends Message<T>>(type: MessageType<T>, va
|
|
|
22
22
|
* If the given field uses one of the well-known wrapper types, return
|
|
23
23
|
* the primitive type it wraps.
|
|
24
24
|
*/
|
|
25
|
-
export declare function getUnwrappedFieldType(field: DescField): ScalarType | undefined;
|
|
25
|
+
export declare function getUnwrappedFieldType(field: DescField | DescExtension): ScalarType | undefined;
|
|
@@ -3,7 +3,7 @@ import type { FieldInfo } from "../field.js";
|
|
|
3
3
|
import { ScalarType } from "../field.js";
|
|
4
4
|
import type { EnumType } from "../enum.js";
|
|
5
5
|
type JsonFormatWriteFieldFn = (field: FieldInfo, value: any, options: JsonWriteOptions) => JsonValue | undefined;
|
|
6
|
-
export declare function makeJsonFormatCommon(makeWriteField: (writeEnumFn: typeof writeEnum, writeScalarFn: typeof writeScalar) => JsonFormatWriteFieldFn): JsonFormat;
|
|
7
|
-
declare function writeEnum(type: EnumType, value: number | undefined,
|
|
8
|
-
declare function writeScalar(type: ScalarType, value: any,
|
|
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
9
|
export {};
|