Debian Codegraph @

node/@bufbuild/protobuf/dist/commonjs/codegenv2/boot.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.boot = boot;
17 exports.bootFileDescriptorProto = bootFileDescriptorProto;
18 const restore_json_names_js_1 = require("./restore-json-names.js");
19 const registry_js_1 = require("../registry.js");
20 /**
21 * Hydrate a file descriptor for google/protobuf/descriptor.proto from a plain
22 * object.
23 *
24 * See createFileDescriptorProtoBoot() for details.
25 *
26 * @private
27 */
28 function boot(boot) {
29 const root = bootFileDescriptorProto(boot);
30 root.messageType.forEach(restore_json_names_js_1.restoreJsonNames);
31 const reg = (0, registry_js_1.createFileRegistry)(root, () => undefined);
32 // biome-ignore lint/style/noNonNullAssertion: non-null assertion because we just created the registry from the file we look up
33 return reg.getFile(root.name);
34 }
35 /**
36 * Creates the message google.protobuf.FileDescriptorProto from an object literal.
37 *
38 * See createFileDescriptorProtoBoot() for details.
39 *
40 * @private
41 */
42 function bootFileDescriptorProto(init) {
43 const proto = Object.create({
44 syntax: "",
45 edition: 0,
46 });
47 return Object.assign(proto, Object.assign(Object.assign({ $typeName: "google.protobuf.FileDescriptorProto", dependency: [], publicDependency: [], weakDependency: [], optionDependency: [], service: [], extension: [] }, init), { messageType: init.messageType.map(bootDescriptorProto), enumType: init.enumType.map(bootEnumDescriptorProto) }));
48 }
49 function bootDescriptorProto(init) {
50 var _a, _b, _c, _d, _e, _f, _g, _h;
51 const proto = Object.create({
52 visibility: 0,
53 });
54 return Object.assign(proto, {
55 $typeName: "google.protobuf.DescriptorProto",
56 name: init.name,
57 field: (_b = (_a = init.field) === null || _a === void 0 ? void 0 : _a.map(bootFieldDescriptorProto)) !== null && _b !== void 0 ? _b : [],
58 extension: [],
59 nestedType: (_d = (_c = init.nestedType) === null || _c === void 0 ? void 0 : _c.map(bootDescriptorProto)) !== null && _d !== void 0 ? _d : [],
60 enumType: (_f = (_e = init.enumType) === null || _e === void 0 ? void 0 : _e.map(bootEnumDescriptorProto)) !== null && _f !== void 0 ? _f : [],
61 extensionRange: (_h = (_g = init.extensionRange) === null || _g === void 0 ? void 0 : _g.map((e) => (Object.assign({ $typeName: "google.protobuf.DescriptorProto.ExtensionRange" }, e)))) !== null && _h !== void 0 ? _h : [],
62 oneofDecl: [],
63 reservedRange: [],
64 reservedName: [],
65 });
66 }
67 function bootFieldDescriptorProto(init) {
68 const proto = Object.create({
69 label: 1,
70 typeName: "",
71 extendee: "",
72 defaultValue: "",
73 oneofIndex: 0,
74 jsonName: "",
75 proto3Optional: false,
76 });
77 return Object.assign(proto, Object.assign(Object.assign({ $typeName: "google.protobuf.FieldDescriptorProto" }, init), { options: init.options ? bootFieldOptions(init.options) : undefined }));
78 }
79 function bootFieldOptions(init) {
80 var _a, _b, _c;
81 const proto = Object.create({
82 ctype: 0,
83 packed: false,
84 jstype: 0,
85 lazy: false,
86 unverifiedLazy: false,
87 deprecated: false,
88 weak: false,
89 debugRedact: false,
90 retention: 0,
91 });
92 return Object.assign(proto, Object.assign(Object.assign({ $typeName: "google.protobuf.FieldOptions" }, init), { targets: (_a = init.targets) !== null && _a !== void 0 ? _a : [], editionDefaults: (_c = (_b = init.editionDefaults) === null || _b === void 0 ? void 0 : _b.map((e) => (Object.assign({ $typeName: "google.protobuf.FieldOptions.EditionDefault" }, e)))) !== null && _c !== void 0 ? _c : [], uninterpretedOption: [] }));
93 }
94 function bootEnumDescriptorProto(init) {
95 const proto = Object.create({
96 visibility: 0,
97 });
98 return Object.assign(proto, {
99 $typeName: "google.protobuf.EnumDescriptorProto",
100 name: init.name,
101 reservedName: [],
102 reservedRange: [],
103 value: init.value.map((e) => (Object.assign({ $typeName: "google.protobuf.EnumValueDescriptorProto" }, e))),
104 });
105 }