Debian Codegraph @

node/@bufbuild/protobuf/dist/commonjs/wkt/wrappers.js

raw
1 "use strict";
2 // Copyright 2021-2026 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.isWrapper = isWrapper;
17 exports.isWrapperDesc = isWrapperDesc;
18 exports.hasCustomJsonRepresentation = hasCustomJsonRepresentation;
19 function isWrapper(arg) {
20 return isWrapperTypeName(arg.$typeName);
21 }
22 function isWrapperDesc(messageDesc) {
23 const f = messageDesc.fields[0];
24 return (isWrapperTypeName(messageDesc.typeName) &&
25 f !== undefined &&
26 f.fieldKind == "scalar" &&
27 f.name == "value" &&
28 f.number == 1);
29 }
30 /**
31 * Returns true if the descriptor is a well-known type with a custom JSON
32 * representation per the protobuf JSON spec. Examples: Timestamp as an
33 * RFC 3339 string, Duration as "5s", wrappers as the unwrapped scalar.
34 *
35 * When packed inside `google.protobuf.Any`, these messages are serialized
36 * as `{"@type": ..., "value": <custom form>}`; all other messages embed
37 * their fields directly.
38 */
39 function hasCustomJsonRepresentation(desc) {
40 switch (desc.typeName) {
41 case "google.protobuf.Any":
42 case "google.protobuf.Timestamp":
43 case "google.protobuf.Duration":
44 case "google.protobuf.FieldMask":
45 case "google.protobuf.Struct":
46 case "google.protobuf.Value":
47 case "google.protobuf.ListValue":
48 return true;
49 default:
50 return isWrapperDesc(desc);
51 }
52 }
53 const wrapperTypeNames = /*@__PURE__*/ new Set([
54 "google.protobuf.DoubleValue",
55 "google.protobuf.FloatValue",
56 "google.protobuf.Int64Value",
57 "google.protobuf.UInt64Value",
58 "google.protobuf.Int32Value",
59 "google.protobuf.UInt32Value",
60 "google.protobuf.BoolValue",
61 "google.protobuf.StringValue",
62 "google.protobuf.BytesValue",
63 ]);
64 function isWrapperTypeName(name) {
65 return wrapperTypeNames.has(name);
66 }