Debian Codegraph @

node/@bufbuild/protobuf/dist/esm/reflect/guard.js

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