Debian Codegraph @

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