Debian Codegraph @

node/@bufbuild/protobuf/dist/commonjs/reflect/guard.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.isObject = isObject;
17 exports.isOneofADT = isOneofADT;
18 exports.isReflectList = isReflectList;
19 exports.isReflectMap = isReflectMap;
20 exports.isReflectMessage = isReflectMessage;
21 const unsafe_js_1 = require("./unsafe.js");
22 function isObject(arg) {
23 return arg !== null && typeof arg == "object" && !Array.isArray(arg);
24 }
25 function isOneofADT(arg) {
26 return (arg !== null &&
27 typeof arg == "object" &&
28 "case" in arg &&
29 ((typeof arg.case == "string" && "value" in arg && arg.value != null) ||
30 (arg.case === undefined &&
31 (!("value" in arg) || arg.value === undefined))));
32 }
33 function isReflectList(arg, field) {
34 var _a, _b, _c, _d;
35 if (isObject(arg) &&
36 unsafe_js_1.unsafeLocal in arg &&
37 "add" in arg &&
38 "field" in arg &&
39 typeof arg.field == "function") {
40 if (field !== undefined) {
41 const a = field;
42 const b = arg.field();
43 return (a.listKind == b.listKind &&
44 a.scalar === b.scalar &&
45 ((_a = a.message) === null || _a === void 0 ? void 0 : _a.typeName) === ((_b = b.message) === null || _b === void 0 ? void 0 : _b.typeName) &&
46 ((_c = a.enum) === null || _c === void 0 ? void 0 : _c.typeName) === ((_d = b.enum) === null || _d === void 0 ? void 0 : _d.typeName));
47 }
48 return true;
49 }
50 return false;
51 }
52 function isReflectMap(arg, field) {
53 var _a, _b, _c, _d;
54 if (isObject(arg) &&
55 unsafe_js_1.unsafeLocal in arg &&
56 "has" in arg &&
57 "field" in arg &&
58 typeof arg.field == "function") {
59 if (field !== undefined) {
60 const a = field, b = arg.field();
61 return (a.mapKey === b.mapKey &&
62 a.mapKind == b.mapKind &&
63 a.scalar === b.scalar &&
64 ((_a = a.message) === null || _a === void 0 ? void 0 : _a.typeName) === ((_b = b.message) === null || _b === void 0 ? void 0 : _b.typeName) &&
65 ((_c = a.enum) === null || _c === void 0 ? void 0 : _c.typeName) === ((_d = b.enum) === null || _d === void 0 ? void 0 : _d.typeName));
66 }
67 return true;
68 }
69 return false;
70 }
71 function isReflectMessage(arg, messageDesc) {
72 return (isObject(arg) &&
73 unsafe_js_1.unsafeLocal in arg &&
74 "desc" in arg &&
75 isObject(arg.desc) &&
76 arg.desc.kind === "message" &&
77 (messageDesc === undefined || arg.desc.typeName == messageDesc.typeName));
78 }