protoc-gen-pothos 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/protoc-gen-pothos.cjs +82 -14
- package/dist/protoc-gen-pothos.cjs.map +1 -1
- package/dist/protoc-gen-pothos.js +78 -10
- package/dist/protoc-gen-pothos.js.map +1 -1
- package/dist/src/dslgen/printers/util.d.ts +6 -0
- package/dist/src/dslgen/printers/util.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/dslgen/printers/util.ts +124 -8
|
@@ -24,14 +24,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
));
|
|
25
25
|
|
|
26
26
|
// src/protoc-gen-pothos.ts
|
|
27
|
-
var
|
|
27
|
+
var import_protoplugin4 = require("@bufbuild/protoplugin");
|
|
28
28
|
|
|
29
29
|
// src/plugin.ts
|
|
30
|
-
var
|
|
30
|
+
var import_protoplugin3 = require("@bufbuild/protoplugin");
|
|
31
31
|
var import_protoc_plugin_helpers = require("@proto-graphql/protoc-plugin-helpers");
|
|
32
32
|
|
|
33
33
|
// package.json
|
|
34
|
-
var version = "0.7.
|
|
34
|
+
var version = "0.7.1";
|
|
35
35
|
|
|
36
36
|
// src/codegen/stringify.ts
|
|
37
37
|
var import_dprint_node = __toESM(require("dprint-node"), 1);
|
|
@@ -243,6 +243,8 @@ __name(literalOf, "literalOf");
|
|
|
243
243
|
|
|
244
244
|
// src/dslgen/printers/util.ts
|
|
245
245
|
var path = __toESM(require("path"), 1);
|
|
246
|
+
var import_reflect = require("@bufbuild/protobuf/reflect");
|
|
247
|
+
var import_protoplugin2 = require("@bufbuild/protoplugin");
|
|
246
248
|
var import_codegen_core = require("@proto-graphql/codegen-core");
|
|
247
249
|
function pothosRefName(type) {
|
|
248
250
|
return `${type.typeName}$Ref`;
|
|
@@ -304,19 +306,85 @@ function protoTypeSymbol(proto, opts) {
|
|
|
304
306
|
}
|
|
305
307
|
__name(protoTypeSymbol, "protoTypeSymbol");
|
|
306
308
|
function protoSchemaSymbol(proto, opts) {
|
|
307
|
-
const
|
|
308
|
-
proto.name
|
|
309
|
-
];
|
|
310
|
-
let current = proto;
|
|
311
|
-
while (current.parent != null) {
|
|
312
|
-
current = current.parent;
|
|
313
|
-
chunks.unshift(current.name);
|
|
314
|
-
}
|
|
315
|
-
const symbolName = `${chunks.join("_")}Schema`;
|
|
309
|
+
const symbolName = resolveProtobufEsDescName(proto);
|
|
316
310
|
const importPath = protoImportPath(proto, opts);
|
|
317
311
|
return (0, import_protoplugin.createImportSymbol)(symbolName, importPath);
|
|
318
312
|
}
|
|
319
313
|
__name(protoSchemaSymbol, "protoSchemaSymbol");
|
|
314
|
+
function protobufEsSalt(i) {
|
|
315
|
+
if (i === 0) return "";
|
|
316
|
+
if (i === 1) return "$";
|
|
317
|
+
return `$${i - 1}`;
|
|
318
|
+
}
|
|
319
|
+
__name(protobufEsSalt, "protobufEsSalt");
|
|
320
|
+
function idealShapeName(desc, i) {
|
|
321
|
+
return (0, import_protoplugin2.safeIdentifier)(protobufEsIdentifierForNested(desc) + protobufEsSalt(i));
|
|
322
|
+
}
|
|
323
|
+
__name(idealShapeName, "idealShapeName");
|
|
324
|
+
function protobufEsIdentifierForNested(desc) {
|
|
325
|
+
const pkg = desc.file.proto.package;
|
|
326
|
+
const offset = pkg.length > 0 ? pkg.length + 1 : 0;
|
|
327
|
+
return desc.typeName.substring(offset).replace(/\./g, "_");
|
|
328
|
+
}
|
|
329
|
+
__name(protobufEsIdentifierForNested, "protobufEsIdentifierForNested");
|
|
330
|
+
function idealDescName(desc, i) {
|
|
331
|
+
const salt = protobufEsSalt(i);
|
|
332
|
+
if (desc.kind === "file") {
|
|
333
|
+
const name = `file_${desc.name.replace(/[^a-zA-Z0-9_]+/g, "_")}`;
|
|
334
|
+
return (0, import_protoplugin2.safeIdentifier)(name + salt);
|
|
335
|
+
}
|
|
336
|
+
if (desc.kind === "enum" || desc.kind === "message") {
|
|
337
|
+
return (0, import_protoplugin2.safeIdentifier)(protobufEsIdentifierForNested(desc) + "Schema" + salt);
|
|
338
|
+
}
|
|
339
|
+
return (0, import_protoplugin2.safeIdentifier)(protobufEsIdentifierForNested(desc) + salt);
|
|
340
|
+
}
|
|
341
|
+
__name(idealDescName, "idealDescName");
|
|
342
|
+
var descNameCache = /* @__PURE__ */ new WeakMap();
|
|
343
|
+
function resolveProtobufEsDescName(proto) {
|
|
344
|
+
const file = proto.file;
|
|
345
|
+
const cached = descNameCache.get(file);
|
|
346
|
+
if (cached) {
|
|
347
|
+
const name = cached.get(proto);
|
|
348
|
+
if (name !== void 0) return name;
|
|
349
|
+
}
|
|
350
|
+
const taken = /* @__PURE__ */ new Set();
|
|
351
|
+
const descNames = /* @__PURE__ */ new Map();
|
|
352
|
+
for (const desc of (0, import_reflect.nestedTypes)(file)) {
|
|
353
|
+
if (desc.kind !== "enum" && desc.kind !== "message") continue;
|
|
354
|
+
let name;
|
|
355
|
+
for (let i = 0; ; i++) {
|
|
356
|
+
name = idealShapeName(desc, i);
|
|
357
|
+
if (!taken.has(name)) break;
|
|
358
|
+
}
|
|
359
|
+
taken.add(name);
|
|
360
|
+
}
|
|
361
|
+
{
|
|
362
|
+
let fileName;
|
|
363
|
+
for (let i = 0; ; i++) {
|
|
364
|
+
fileName = idealDescName(file, i);
|
|
365
|
+
if (!taken.has(fileName)) break;
|
|
366
|
+
}
|
|
367
|
+
taken.add(fileName);
|
|
368
|
+
}
|
|
369
|
+
for (const desc of (0, import_reflect.nestedTypes)(file)) {
|
|
370
|
+
let name;
|
|
371
|
+
for (let i = 0; ; i++) {
|
|
372
|
+
name = idealDescName(desc, i);
|
|
373
|
+
if (!taken.has(name)) break;
|
|
374
|
+
}
|
|
375
|
+
taken.add(name);
|
|
376
|
+
if (desc.kind === "message" || desc.kind === "enum") {
|
|
377
|
+
descNames.set(desc, name);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
descNameCache.set(file, descNames);
|
|
381
|
+
const result = descNames.get(proto);
|
|
382
|
+
if (result === void 0) {
|
|
383
|
+
throw new Error(`Unable to determine protobuf-es desc name for ${proto.toString()}`);
|
|
384
|
+
}
|
|
385
|
+
return result;
|
|
386
|
+
}
|
|
387
|
+
__name(resolveProtobufEsDescName, "resolveProtobufEsDescName");
|
|
320
388
|
function protobufCreateSymbol() {
|
|
321
389
|
return (0, import_protoplugin.createImportSymbol)("create", "@bufbuild/protobuf");
|
|
322
390
|
}
|
|
@@ -820,7 +888,7 @@ function generateFiles(schema, file) {
|
|
|
820
888
|
__name(generateFiles, "generateFiles");
|
|
821
889
|
|
|
822
890
|
// src/plugin.ts
|
|
823
|
-
var protocGenPothos = (0,
|
|
891
|
+
var protocGenPothos = (0, import_protoplugin3.createEcmaScriptPlugin)({
|
|
824
892
|
name: "protoc-gen-pothos",
|
|
825
893
|
version: `v${version}`,
|
|
826
894
|
generateTs: (0, import_protoc_plugin_helpers.createTsGenerator)({
|
|
@@ -838,5 +906,5 @@ var protocGenPothos = (0, import_protoplugin2.createEcmaScriptPlugin)({
|
|
|
838
906
|
});
|
|
839
907
|
|
|
840
908
|
// src/protoc-gen-pothos.ts
|
|
841
|
-
(0,
|
|
909
|
+
(0, import_protoplugin4.runNodeJs)(protocGenPothos);
|
|
842
910
|
//# sourceMappingURL=protoc-gen-pothos.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/protoc-gen-pothos.ts","../src/plugin.ts","../package.json","../src/codegen/stringify.ts","../src/printer.ts","../src/dslgen/printers/index.ts","../src/dslgen/printers/enumType.ts","../src/codegen/code-builder.ts","../src/codegen/types.ts","../src/codegen/helpers.ts","../src/dslgen/printers/util.ts","../src/dslgen/printers/inputObjectType.ts","../src/dslgen/printers/field.ts","../src/dslgen/printers/fieldResolver/enumFieldResolver.ts","../src/dslgen/printers/fieldResolver/nonNullResolver.ts","../src/dslgen/printers/fieldResolver/oneofUnionResolver.ts","../src/dslgen/printers/objectType.ts","../src/dslgen/printers/oneofUnionType.ts"],"sourcesContent":["import { runNodeJs } from \"@bufbuild/protoplugin\";\n\nimport { protocGenPothos } from \"./plugin.js\";\n\nrunNodeJs(protocGenPothos);\n","import { createEcmaScriptPlugin } from \"@bufbuild/protoplugin\";\nimport {\n createTsGenerator,\n parsePothosOptions,\n} from \"@proto-graphql/protoc-plugin-helpers\";\n\nimport { version } from \"../package.json\";\nimport { formatCode } from \"./codegen/stringify.js\";\nimport { generateFiles } from \"./printer.js\";\n\nexport const protocGenPothos = createEcmaScriptPlugin({\n name: \"protoc-gen-pothos\",\n version: `v${version}`,\n generateTs: createTsGenerator({\n generateFiles,\n dsl: \"pothos\",\n }),\n parseOptions: parsePothosOptions,\n // NOTE: force `target=ts` and apply formatting\n transpile: (files) => {\n return files.map((f) => ({\n ...f,\n content: formatCode(f.content),\n }));\n },\n});\n","{\n \"name\": \"protoc-gen-pothos\",\n \"version\": \"0.7.0\",\n \"description\": \"Generate DSL for Pothos GraphQL from Protocol Buffers IDL\",\n \"keywords\": [\n \"graphql\",\n \"grpc\",\n \"pothos\",\n \"protobuf\",\n \"typescript\"\n ],\n \"bin\": {\n \"protoc-gen-pothos\": \"./bin/protoc-gen-pothos.cjs\"\n },\n \"repository\": \"git@github.com:proto-graphql/proto-graphql-js.git\",\n \"author\": \"izumin5210 <m@izum.in>\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.cjs\"\n }\n }\n },\n \"files\": [\n \"bin/\",\n \"docs/\",\n \"!docs/development/**\",\n \"src/\",\n \"dist/\",\n \"!src/**/*.test.ts\",\n \"!src/**/__tests__/\"\n ],\n \"sideEffects\": false,\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">= 14.0.0\"\n },\n \"dependencies\": {\n \"@bufbuild/protobuf\": \"catalog:\",\n \"@bufbuild/protoplugin\": \"catalog:\",\n \"@proto-graphql/codegen-core\": \"workspace:*\",\n \"@proto-graphql/protoc-plugin-helpers\": \"workspace:*\",\n \"dprint-node\": \"catalog:\"\n },\n \"devDependencies\": {\n \"@pothos/core\": \"catalog:test\",\n \"@proto-graphql/e2e-testapis-protobuf-es\": \"workspace:*\",\n \"@proto-graphql/e2e-testapis-protobuf-es-v2\": \"workspace:*\",\n \"@proto-graphql/e2e-testapis-ts-proto\": \"workspace:*\",\n \"@proto-graphql/e2e-testapis-ts-proto-with-forcelong-number\": \"workspace:*\",\n \"@proto-graphql/testapis-proto\": \"workspace:*\",\n \"@proto-graphql/tsconfig\": \"workspace:*\",\n \"@vitest/coverage-v8\": \"^4.0.0\",\n \"graphql\": \"catalog:test\",\n \"graphql-scalars\": \"^1.24.0\",\n \"tsx\": \"^4.21.0\"\n },\n \"scripts\": {\n \"build\": \"tsup && cp -r ../../docs/protoc-gen-pothos docs\",\n \"clean\": \"rm -rf dist docs\",\n \"test\": \"vitest run --passWithNoTests\",\n \"test:coverage\": \"vitest run --coverage\"\n }\n}\n","import dprint from \"dprint-node\";\n\nexport function formatCode(code: string): string {\n return dprint.format(\"file.ts\", code, {\n lineWidth: 80,\n indentWidth: 2,\n useTabs: false,\n semiColons: \"always\",\n quoteStyle: \"alwaysDouble\",\n quoteProps: \"asNeeded\",\n newLineKind: \"lf\",\n useBraces: \"whenNotSingleLine\",\n bracePosition: \"sameLineUnlessHanging\",\n singleBodyPosition: \"maintain\",\n nextControlFlowPosition: \"sameLine\",\n trailingCommas: \"onlyMultiLine\",\n operatorPosition: \"nextLine\",\n preferHanging: false,\n preferSingleLine: true,\n \"arrowFunction.useParentheses\": \"force\",\n });\n}\n","import type { DescFile } from \"@bufbuild/protobuf\";\nimport type { Schema } from \"@bufbuild/protoplugin\";\nimport {\n collectTypesFromFile,\n createRegistryFromSchema,\n filenameFromProtoFile,\n} from \"@proto-graphql/codegen-core\";\nimport type { Options } from \"@proto-graphql/protoc-plugin-helpers\";\n\nimport { createTypeDslPrintables } from \"./dslgen/index.js\";\n\nconst allowedProtobufs = [\"ts-proto\", \"protobuf-es-v1\", \"protobuf-es\"];\n\nexport function generateFiles(\n schema: Schema<Options<\"pothos\">>,\n file: DescFile,\n): void {\n const opts = schema.options;\n\n if (!allowedProtobufs.includes(opts.printer.protobuf)) {\n opts.printer.protobuf = \"ts-proto\"; // default\n }\n\n const registry = createRegistryFromSchema(schema);\n const types = collectTypesFromFile(file, opts.type, schema.allFiles);\n\n const f = schema.generateFile(filenameFromProtoFile(file, opts.printer));\n const printables = [\n ...createTypeDslPrintables(types, registry, opts.printer),\n ];\n\n // ヘッダー出力(preamble プロパティに格納される)\n f.preamble(file);\n\n if (printables.length === 0) {\n f.print(\"export {};\");\n return;\n }\n\n // 各型の Printable を直接出力\n for (const p of printables) {\n f.print(...p);\n f.print(); // 空行で区切り\n }\n}\n","import type { createRegistry } from \"@bufbuild/protobuf\";\nimport {\n EnumType,\n InputObjectType,\n ObjectType,\n OneofUnionType,\n SquashedOneofUnionType,\n} from \"@proto-graphql/codegen-core\";\n\nimport type { Printable } from \"../../codegen/index.js\";\nimport { createEnumTypeCode } from \"./enumType.js\";\nimport { createInputObjectTypeCode } from \"./inputObjectType.js\";\nimport { createObjectTypeCode } from \"./objectType.js\";\nimport { createOneofUnionTypeCode } from \"./oneofUnionType.js\";\nimport type { PothosPrinterOptions } from \"./util.js\";\n\nexport function createTypeDslPrintables(\n types: (\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n )[],\n registry: ReturnType<typeof createRegistry>,\n opts: PothosPrinterOptions,\n): Printable[][] {\n return types.flatMap((type) => {\n if (type instanceof ObjectType) {\n return [createObjectTypeCode(type, registry, opts)];\n }\n if (type instanceof InputObjectType) {\n return [createInputObjectTypeCode(type, registry, opts)];\n }\n if (type instanceof EnumType) {\n return [createEnumTypeCode(type, registry, opts)];\n }\n if (\n type instanceof OneofUnionType ||\n type instanceof SquashedOneofUnionType\n ) {\n return [createOneofUnionTypeCode(type, registry, opts)];\n }\n\n const _exhaustiveCheck: never = type;\n throw \"unreachable\";\n });\n}\n","import type { Registry } from \"@bufbuild/protobuf\";\nimport {\n type EnumType,\n protobufGraphQLExtensions,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n createImportSymbol,\n joinCode,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport {\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n protoTypeSymbol,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export cosnt Hello$Ref: EnumRef<Hello, Hello> = builder.enumType(\"Hello\", {\n * values: [\n * // ...\n * ],\n * // ...\n * })\n * ```\n */\nexport function createEnumTypeCode(\n type: EnumType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const typeOpts = {\n description: type.description,\n values: code`{${joinCode(\n type.values\n .filter((v) => !v.isIgnored() && !v.isUnespecified())\n .map(\n (ev) =>\n code`${ev.name}: ${literalOf(\n compactForCodegen({\n description: ev.description,\n deprecationReason: ev.deprecationReason,\n value: ev.number,\n extensions: protobufGraphQLExtensions(ev, registry),\n }),\n )},`,\n ),\n )}} as const`,\n extensions: protobufGraphQLExtensions(type, registry),\n };\n\n const protoTypeExpr = protoTypeSymbol(type.proto, opts);\n const enumRefSymbol = createImportSymbol(\"EnumRef\", \"@pothos/core\");\n // EnumRef<Hello, Hello>\n const refTypeExpr = code`${enumRefSymbol}<${protoTypeExpr}, ${protoTypeExpr}>`;\n\n return code`\n export const ${pothosRefPrintable(type)}: ${refTypeExpr} =\n ${pothosBuilderPrintable(opts)}.enumType(${literalOf(\n type.typeName,\n )}, ${literalOf(compactForCodegen(typeOpts))});\n `;\n}\n","import type { ImportSymbol, Printable } from \"./types.js\";\n\nexport const PRINTABLE_ARRAY_MARKER = Symbol.for(\n \"proto-graphql:printable-array\",\n);\n\nexport type PrintableArray = Printable[] & { [PRINTABLE_ARRAY_MARKER]: true };\n\nexport function isPrintableArray(value: unknown): value is PrintableArray {\n return Array.isArray(value) && PRINTABLE_ARRAY_MARKER in value;\n}\n\nexport function markAsPrintableArray(arr: Printable[]): PrintableArray {\n Object.defineProperty(arr, PRINTABLE_ARRAY_MARKER, {\n value: true,\n enumerable: false,\n writable: false,\n configurable: false,\n });\n return arr as PrintableArray;\n}\n\ntype CodeValue =\n | string\n | number\n | ImportSymbol\n | Printable[]\n | null\n | undefined;\n\nexport function code(\n strings: TemplateStringsArray,\n ...values: CodeValue[]\n): PrintableArray {\n const result: Printable[] = [];\n\n for (let i = 0; i < strings.length; i++) {\n if (strings[i] !== \"\") {\n result.push(strings[i]);\n }\n\n if (i < values.length) {\n const value = values[i];\n if (value == null) {\n result.push(String(value));\n } else if (typeof value === \"string\") {\n if (value !== \"\") {\n result.push(value);\n }\n } else if (typeof value === \"number\") {\n result.push(String(value));\n } else if (Array.isArray(value)) {\n result.push(...value);\n } else {\n result.push(value as Printable);\n }\n }\n }\n\n if (result.length === 0) {\n result.push(\"\");\n }\n\n return markAsPrintableArray(result);\n}\n","export type {\n ImportSymbol,\n Printable,\n} from \"@bufbuild/protoplugin\";\n\nexport { createImportSymbol } from \"@bufbuild/protoplugin\";\n\nimport type { ImportSymbol } from \"@bufbuild/protoplugin\";\n\nexport function isImportSymbol(value: unknown): value is ImportSymbol {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"kind\" in value &&\n (value as Record<string, unknown>).kind === \"es_symbol\"\n );\n}\n","import {\n isPrintableArray,\n markAsPrintableArray,\n type PrintableArray,\n} from \"./code-builder.js\";\nimport type { Printable } from \"./types.js\";\nimport { isImportSymbol } from \"./types.js\";\n\nexport function joinCode(\n codes: Printable[][],\n separator?: string,\n): Printable[] {\n if (codes.length === 0) {\n return [];\n }\n\n const result: Printable[] = [];\n for (let i = 0; i < codes.length; i++) {\n result.push(...codes[i]);\n if (separator !== undefined && i < codes.length - 1) {\n result.push(separator);\n }\n }\n return result;\n}\n\nfunction escapeString(str: string): string {\n return str\n .replace(/\\\\/g, \"\\\\\\\\\")\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, \"\\\\n\")\n .replace(/\\r/g, \"\\\\r\")\n .replace(/\\t/g, \"\\\\t\");\n}\n\n/**\n * Remove nullish values recursively, preserving PrintableArrays.\n * This is a variant of compact() from codegen-core that doesn't lose the PrintableArray marker.\n */\nexport function compactForCodegen(v: unknown): unknown {\n if (typeof v !== \"object\") return v;\n if (v == null) return v;\n if (Array.isArray(v)) {\n if (isPrintableArray(v)) {\n return v;\n }\n return v.map(compactForCodegen);\n }\n return compactObjForCodegen(v as Record<string, unknown>);\n}\n\nfunction compactObjForCodegen(\n obj: Record<string, unknown>,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(obj)) {\n const v = obj[key];\n if (v != null) {\n result[key] = compactForCodegen(v);\n }\n }\n return result;\n}\n\nexport function literalOf(value: unknown): PrintableArray {\n if (value === null) {\n return markAsPrintableArray([\"null\"]);\n }\n\n if (value === undefined) {\n return markAsPrintableArray([\"undefined\"]);\n }\n\n if (typeof value === \"string\") {\n return markAsPrintableArray([`\"${escapeString(value)}\"`]);\n }\n\n if (typeof value === \"number\") {\n return markAsPrintableArray([String(value)]);\n }\n\n if (typeof value === \"boolean\") {\n return markAsPrintableArray([String(value)]);\n }\n\n if (Array.isArray(value)) {\n if (isPrintableArray(value)) {\n return value;\n }\n\n if (value.length === 0) {\n return markAsPrintableArray([\"[]\"]);\n }\n\n const elements: Printable[] = [\"[\"];\n for (let i = 0; i < value.length; i++) {\n if (i > 0) {\n elements.push(\", \");\n }\n elements.push(...literalOf(value[i]));\n }\n elements.push(\"]\");\n return markAsPrintableArray(elements);\n }\n\n if (typeof value === \"object\") {\n // ImportSymbol should be returned as-is (wrapped in PrintableArray)\n if (isImportSymbol(value)) {\n return markAsPrintableArray([value]);\n }\n\n const obj = value as Record<string, unknown>;\n const keys = Object.keys(obj);\n\n if (keys.length === 0) {\n return markAsPrintableArray([\"{}\"]);\n }\n\n const elements: Printable[] = [\"{ \"];\n for (let i = 0; i < keys.length; i++) {\n if (i > 0) {\n elements.push(\", \");\n }\n const key = keys[i];\n // Always quote keys to match ts-poet literalOf behavior\n elements.push(`\"${escapeString(key)}\": `);\n elements.push(...literalOf(obj[key]));\n }\n elements.push(\" }\");\n return markAsPrintableArray(elements);\n }\n\n return markAsPrintableArray([String(value)]);\n}\n","import * as path from \"node:path\";\n\nimport type { DescEnum, DescMessage } from \"@bufbuild/protobuf\";\nimport {\n type EnumType,\n filename,\n type InputObjectField,\n type InputObjectType,\n type InterfaceType,\n type ObjectField,\n ObjectOneofField,\n type ObjectType,\n type OneofUnionType,\n type PrinterOptions,\n type SquashedOneofUnionType,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n createImportSymbol,\n type ImportSymbol,\n type Printable,\n} from \"../../codegen/index.js\";\n\nexport type PothosPrinterOptions = Extract<PrinterOptions, { dsl: \"pothos\" }>;\n\nexport function pothosRefName(\n type:\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n | InterfaceType,\n): string {\n return `${type.typeName}$Ref`;\n}\n\nexport function shapeTypeName(type: InputObjectType): string {\n return `${type.typeName}$Shape`;\n}\n\ntype TypeWithFilename =\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n | InterfaceType;\n\nfunction resolveImportOrLocal(\n field: { parent: TypeWithFilename; type: TypeWithFilename },\n opts: PothosPrinterOptions,\n symbolName: string,\n localPrintable: () => Printable[],\n): Printable[] {\n const fromFile = filename(field.parent, opts);\n const toFile = filename(field.type, opts);\n if (fromFile === toFile) return localPrintable();\n\n const importPath = `./${toFile.replace(/\\.ts$/, \"\")}`;\n return code`${createImportSymbol(symbolName, importPath)}`;\n}\n\nexport function fieldTypeRefPrintable(\n field:\n | ObjectField<\n ObjectType | EnumType | InterfaceType | SquashedOneofUnionType\n >\n | InputObjectField<InputObjectType | EnumType>\n | ObjectOneofField,\n opts: PothosPrinterOptions,\n): Printable[] {\n if (field instanceof ObjectOneofField) return pothosRefPrintable(field.type);\n\n return resolveImportOrLocal(field, opts, pothosRefName(field.type), () =>\n pothosRefPrintable(field.type),\n );\n}\n\nexport function shapeTypePrintable(type: InputObjectType): Printable[] {\n return code`${shapeTypeName(type)}`;\n}\n\nexport function fieldTypeShapePrintable(\n field: InputObjectField<InputObjectType>,\n opts: PothosPrinterOptions,\n): Printable[] {\n return resolveImportOrLocal(field, opts, shapeTypeName(field.type), () =>\n shapeTypePrintable(field.type),\n );\n}\n\nexport function toProtoFuncName(type: InputObjectType): string {\n return `${type.typeName}$toProto`;\n}\n\nexport function toProtoFuncPrintable(\n field: InputObjectField<InputObjectType>,\n opts: PothosPrinterOptions,\n): Printable[] {\n return resolveImportOrLocal(\n field,\n opts,\n toProtoFuncName(field.type),\n () => code`${toProtoFuncName(field.type)}`,\n );\n}\n\nexport function pothosRefPrintable(\n type:\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n | InterfaceType,\n): Printable[] {\n return code`${pothosRefName(type)}`;\n}\n\nexport function pothosBuilderPrintable(\n opts: Pick<PothosPrinterOptions, \"pothos\">,\n): Printable[] {\n // protoplugin が自動的に相対パスを計算するため、builderPath をそのまま使用\n return code`${createImportSymbol(\"builder\", opts.pothos.builderPath)}`;\n}\n\nexport function protoTypeSymbol(\n proto: DescMessage | DescEnum,\n opts: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): ImportSymbol {\n const chunks = [proto.name];\n let current: DescMessage | DescEnum = proto;\n while (current.parent != null) {\n current = current.parent;\n chunks.unshift(current.name);\n }\n const symbolName = chunks.join(\"_\");\n const importPath = protoImportPath(proto, opts);\n return createImportSymbol(symbolName, importPath);\n}\n\n/**\n * protobuf-es v2 用: Schema シンボル (例: UserSchema, Parent_ChildSchema) を生成\n */\nexport function protoSchemaSymbol(\n proto: DescMessage | DescEnum,\n opts: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): ImportSymbol {\n const chunks = [proto.name];\n let current: DescMessage | DescEnum = proto;\n while (current.parent != null) {\n current = current.parent;\n chunks.unshift(current.name);\n }\n const symbolName = `${chunks.join(\"_\")}Schema`;\n const importPath = protoImportPath(proto, opts);\n return createImportSymbol(symbolName, importPath);\n}\n\n/**\n * @bufbuild/protobuf から create 関数を import\n */\nexport function protobufCreateSymbol(): ImportSymbol {\n return createImportSymbol(\"create\", \"@bufbuild/protobuf\");\n}\n\n/**\n * @bufbuild/protobuf から isMessage 関数を import\n */\nexport function protobufIsMessageSymbol(): ImportSymbol {\n return createImportSymbol(\"isMessage\", \"@bufbuild/protobuf\");\n}\n\n/**\n * @bufbuild/protobuf から MessageShape 型を import\n */\nexport function protobufMessageShapeSymbol(): ImportSymbol {\n return createImportSymbol(\"MessageShape\", \"@bufbuild/protobuf\");\n}\n\n/**\n * v2 用: ObjectRef の型パラメータとして使用する型を生成\n * - protobuf-es v2: MessageShape<typeof XxxSchema>\n * - protobuf-es v1: Xxx (クラス)\n * - ts-proto: Xxx (interface)\n */\nexport function protoRefTypePrintable(\n proto: DescMessage,\n opts: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): Printable[] {\n switch (opts.protobuf) {\n case \"ts-proto\":\n case \"protobuf-es-v1\": {\n return code`${protoTypeSymbol(proto, opts)}`;\n }\n case \"protobuf-es\": {\n return code`${protobufMessageShapeSymbol()}<typeof ${protoSchemaSymbol(proto, opts)}>`;\n }\n }\n}\n\nfunction protoImportPath(\n t: DescMessage | DescEnum,\n o: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): string {\n let importPath: string;\n switch (o.protobuf) {\n case \"ts-proto\": {\n importPath = t.file.name;\n break;\n }\n case \"protobuf-es-v1\":\n case \"protobuf-es\": {\n const { dir, name } = path.parse(t.file.name);\n importPath = `${dir}/${name}_pb`;\n break;\n }\n default: {\n o.protobuf satisfies never;\n throw new Error(`unexpected protobuf option: ${o.protobuf}`);\n }\n }\n return `${o.importPrefix ? `${o.importPrefix}/` : \"./\"}${importPath}`.replace(\n /(?<!:)\\/\\//,\n \"/\",\n );\n}\n","import type { Registry } from \"@bufbuild/protobuf\";\nimport {\n EnumType,\n type InputObjectField,\n InputObjectType,\n protobufGraphQLExtensions,\n ScalarType,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n createImportSymbol,\n joinCode,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport { createFieldRefCode, createNoopFieldRefCode } from \"./field.js\";\nimport {\n fieldTypeShapePrintable,\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n protobufCreateSymbol,\n protoSchemaSymbol,\n protoTypeSymbol,\n shapeTypePrintable,\n toProtoFuncName,\n toProtoFuncPrintable,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export type HelloInput$Shape = {\n * // ...\n * }\n * export const HelloInput$Ref: pothos.InputObjectRef<Hello$SHape> = builder.inputRef(\"HelloInput\").implement({\n * description: \"...\",\n * fields: (t) => ({\n * // ...\n * }),\n * })\n *\n * export function HelloInput$toProto () {\n * return {\n * // ...\n * }\n * }\n *\n * ```\n */\nexport function createInputObjectTypeCode(\n type: InputObjectType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const fields = type.fields.filter(\n (f) =>\n !(\n type.options.ignoreNonMessageOneofFields &&\n f.proto.oneof != null &&\n !(f.type instanceof InputObjectType)\n ),\n );\n\n const shapeTypeCode = code`\n export type ${shapeTypePrintable(type)} = {\n ${joinCode(\n fields.map((f) => {\n let typeNode: Printable[];\n if (f.type instanceof InputObjectType) {\n typeNode = fieldTypeShapePrintable(\n f as InputObjectField<InputObjectType>,\n opts,\n );\n if (f.isList()) typeNode = code`Array<${typeNode}>`;\n } else {\n typeNode = code`${protoTypeSymbol(type.proto, opts)}[${literalOf(\n tsFieldName(f.proto, opts).toString(),\n )}]`;\n }\n return f.isNullable()\n ? code`${f.name}?: ${typeNode} | null,`\n : code`${f.name}: ${\n f.type instanceof ScalarType && f.type.isCustomScalar()\n ? code`NonNullable<${typeNode}>`\n : typeNode\n },`;\n }),\n )}\n };\n `;\n\n // In protobuf-es v2, Message types have internal properties like $unknown and $typeName,\n // which can cause type mismatches between Pothos's inferred types and the InputShape type.\n // To work around this, we use a type assertion for protobuf-es v2.\n const needsTypeAssertion = opts.protobuf === \"protobuf-es\";\n const inputObjectRefType = code`${createImportSymbol(\n \"InputObjectRef\",\n \"@pothos/core\",\n )}<${shapeTypePrintable(type)}>`;\n\n const refCode = code`\n export const ${pothosRefPrintable(type)}: ${inputObjectRefType} =\n ${pothosBuilderPrintable(opts)}.inputRef<${shapeTypePrintable(\n type,\n )}>(${literalOf(type.typeName)}).implement(\n ${literalOf(\n compactForCodegen({\n fields: code`t => ({${\n fields.length > 0\n ? joinCode(\n fields.map(\n (f) =>\n code`${f.name}: ${createFieldRefCode(\n f,\n registry,\n opts,\n )}`,\n ),\n \", \",\n )\n : code`_: ${createNoopFieldRefCode({ input: true })}`\n }})`,\n extensions: protobufGraphQLExtensions(type, registry),\n description: type.description,\n }),\n )}\n )${needsTypeAssertion ? code` as ${inputObjectRefType}` : \"\"};\n `;\n\n const codes: Printable[][] = [shapeTypeCode, refCode];\n\n if (opts.protobuf === \"protobuf-es-v1\" || opts.protobuf === \"protobuf-es\") {\n codes.push(createToProtoFuncCode(type, fields, opts));\n }\n\n return joinCode(codes, \"\\n\\n\");\n}\n\nfunction createToProtoFuncCode(\n type: InputObjectType,\n fields: InputObjectField<ScalarType | EnumType | InputObjectType>[],\n opts: PothosPrinterOptions,\n): Printable[] {\n const oneofFields: Record<string, InputObjectField<InputObjectType>[]> = {};\n for (const f of fields) {\n if (f.proto.oneof == null) continue;\n if (!(f.type instanceof InputObjectType)) {\n // Non-message oneof members are ignored in toProto generation.\n // The strict validation path is handled in type construction.\n continue;\n }\n\n oneofFields[f.proto.oneof.name] = [\n ...(oneofFields[f.proto.oneof.name] || []),\n f as InputObjectField<InputObjectType>,\n ];\n }\n\n const protoTypeSym = protoTypeSymbol(type.proto, opts);\n\n const fieldAssignments = joinCode(\n fields\n .filter((f) => f.proto.oneof == null)\n .map((f) => {\n const localName = tsFieldName(f.proto, opts).toString();\n if (f.type instanceof InputObjectType) {\n const toProtoFunc = toProtoFuncPrintable(\n f as InputObjectField<InputObjectType>,\n opts,\n );\n if (f.isList()) {\n return code`${localName}: input?.${f.name}?.map(v => ${toProtoFunc}(v)),`;\n }\n return code`${localName}: input?.${f.name} ? ${toProtoFunc}(input.${f.name}) : undefined,`;\n }\n if (f.type instanceof ScalarType || f.type instanceof EnumType) {\n return code`${localName}: input?.${f.name} ?? undefined,`;\n }\n f.type satisfies never;\n throw new Error(\"unreachable\");\n }),\n \"\\n\",\n );\n\n const oneofAssignments = joinCode(\n Object.values(oneofFields).map((fields) => {\n const oneofName = tsFieldName(\n // biome-ignore lint/style/noNonNullAssertion: we know it's not null\n fields[0]!.proto.oneof!,\n opts,\n ).toString();\n const cases = fields.map((f) => {\n const caseName = tsFieldName(f.proto, opts).toString();\n return code`input?.${f.name} ? { case: \"${caseName}\", value: ${toProtoFuncPrintable(f, opts)}(input.${f.name}) } :`;\n });\n return code`${oneofName}: ${joinCode(cases, \" \")} undefined,`;\n }),\n \"\\n\",\n );\n\n if (opts.protobuf === \"protobuf-es\") {\n const protoSchemaSym = protoSchemaSymbol(type.proto, opts);\n return code`\n export function ${toProtoFuncName(type)} (input: ${shapeTypePrintable(\n type,\n )} | null | undefined): ${protoTypeSym} {\n return ${protobufCreateSymbol()}(${protoSchemaSym}, {\n ${fieldAssignments}\n ${oneofAssignments}\n });\n }\n `;\n }\n\n return code`\n export function ${toProtoFuncName(type)} (input: ${shapeTypePrintable(\n type,\n )} | null | undefined): ${protoTypeSym} {\n return new ${protoTypeSym}({\n ${fieldAssignments}\n ${oneofAssignments}\n });\n }\n `;\n}\n","import type { createRegistry, DescField } from \"@bufbuild/protobuf\";\nimport {\n EnumType,\n InputObjectField,\n ObjectField,\n ObjectOneofField,\n ObjectType,\n protobufGraphQLExtensions,\n ScalarType,\n SquashedOneofUnionType,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport { createEnumResolverCode } from \"./fieldResolver/enumFieldResolver.js\";\nimport { createNonNullResolverCode } from \"./fieldResolver/nonNullResolver.js\";\nimport { createOneofUnionResolverCode } from \"./fieldResolver/oneofUnionResolver.js\";\nimport { fieldTypeRefPrintable, type PothosPrinterOptions } from \"./util.js\";\n\nfunction createGetFieldValueCodePrintable(\n source: string,\n proto: DescField,\n opts: PothosPrinterOptions,\n): Printable[] {\n return code`${source}.${tsFieldName(proto, opts)}`;\n}\n\n/**\n * @example\n * ```ts\n * t.expose(\"name\", {\n * type: \"Boolean\",\n * nullable: true,\n * description: \"...\",\n * })\n * ```\n * ```ts\n * t.field({\n * type: \"Boolean\",\n * nullable: true,\n * description: \"...\",\n * resolve() {\n * return true\n * }\n * })\n * ```\n */\nexport function createFieldRefCode(\n field: ObjectField<any> | ObjectOneofField | InputObjectField<any>,\n registry: ReturnType<typeof createRegistry>,\n opts: PothosPrinterOptions,\n): Printable[] {\n const isInput = field instanceof InputObjectField;\n const baseType =\n field.type instanceof ScalarType\n ? literalOf(field.type.typeName)\n : fieldTypeRefPrintable(field, opts);\n\n const sourceExpr = \"source\";\n let resolverCode: Printable[] | undefined;\n if (!isInput) {\n if (field instanceof ObjectOneofField) {\n resolverCode = createOneofUnionResolverCode(\n code`${sourceExpr}`,\n field,\n opts,\n );\n } else {\n const valueExpr = createGetFieldValueCodePrintable(\n sourceExpr,\n field.proto,\n opts,\n );\n const nullableInProto =\n field.type instanceof ObjectType ||\n (field.type instanceof ScalarType &&\n !field.type.isPrimitive() &&\n !field.type.isWrapperType());\n if (nullableInProto && !field.isNullable()) {\n resolverCode = createNonNullResolverCode(valueExpr);\n }\n if (field.type instanceof EnumType && field instanceof ObjectField) {\n resolverCode = createEnumResolverCode(valueExpr, field, opts);\n }\n if (\n field.type instanceof SquashedOneofUnionType &&\n field instanceof ObjectField\n ) {\n resolverCode = createOneofUnionResolverCode(valueExpr, field, opts);\n }\n if (field.type instanceof ScalarType && field.type.isBytes()) {\n if (field.isList()) {\n resolverCode = code`return ${valueExpr}.map(v => Buffer.from(v));`;\n } else if (field.isNullable()) {\n resolverCode = code`return ${valueExpr} == null ? null : Buffer.from(${valueExpr});`;\n } else {\n resolverCode = code`return Buffer.from(${valueExpr});`;\n }\n }\n }\n }\n\n const nullableValue = isInput !== field.isNullable(); /* Logical XOR */\n const fieldOpts = {\n type: field.isList() ? code`[${baseType}]` : baseType,\n [isInput ? \"required\" : \"nullable\"]: field.isList()\n ? { list: nullableValue, items: isInput /* always non-null */ }\n : nullableValue,\n description: field.description,\n deprecationReason: field.deprecationReason,\n resolve: resolverCode ? code`${sourceExpr} => {${resolverCode}}` : null,\n extensions: protobufGraphQLExtensions(field, registry),\n };\n\n const shouldUseFieldFunc = isInput || resolverCode != null;\n return shouldUseFieldFunc\n ? code`t.field(${literalOf(compactForCodegen(fieldOpts))})`\n : code`t.expose(${literalOf(\n tsFieldName(field.proto as DescField, opts),\n )}, ${literalOf(compactForCodegen(fieldOpts))})`;\n}\n\n/**\n * @example\n * ```ts\n * t.field( {\n * type: \"Boolean\",\n * nullable: true,\n * description: \"noop field\",\n * resolve() {\n * return true\n * }\n * })\n * ```\n */\nexport function createNoopFieldRefCode(opts: { input: boolean }): Printable[] {\n return code`\n t.field({\n type: \"Boolean\",\n ${opts.input ? \"required: false\" : \"nullable: true\"},\n description: \"noop field\",\n ${opts.input ? \"\" : \"resolve: () => true,\"}\n })\n `;\n}\n","import type {\n EnumType,\n EnumTypeValue,\n ObjectField,\n PrinterOptions,\n} from \"@proto-graphql/codegen-core\";\n\nimport { code, joinCode, type Printable } from \"../../../codegen/index.js\";\nimport { protoTypeSymbol } from \"../util.js\";\n\n/**\n * @example nullable\n * ```ts\n * if (!root.myEnum || root.myEnum === _$enums.myEnum.MY_ENUM_UNSPECIFIED) {\n * return null\n * }\n * return root.myEnum\n * ```\n * @example notNull\n * ```ts\n * if (!root.myEnum || root.myEnum === _$enums.myEnum.MY_ENUM_UNSPECIFIED) {\n * throw new Error(\"Message.field is required field. but got null or unspecified.\")\n * }\n * return root.myEnum\n * ```\n */\nexport function createEnumResolverCode(\n valueExpr: Printable[],\n field: ObjectField<EnumType>,\n opts: PrinterOptions,\n): Printable[] {\n const createBlockStmtCodes = (valueExpr: Printable[]): Printable[][] => {\n const chunks: Printable[][] = [];\n\n if (field.type.unspecifiedValue != null) {\n const escapeCode =\n field.isNullable() && !field.isList()\n ? code`return null;`\n : code`throw new Error(\"${field.name} is required field. But got unspecified.\");`;\n chunks.push(code`\n if (${valueExpr} === ${protoTypeSymbol(\n field.type.proto,\n opts,\n )}.${enumValueJsName(field.type, field.type.unspecifiedValue, opts)}) {\n ${escapeCode}\n }\n `);\n }\n for (const ev of field.type.valuesWithIgnored) {\n if (!ev.isIgnored()) continue;\n chunks.push(code`\n if (${valueExpr} === ${protoTypeSymbol(\n field.type.proto,\n opts,\n )}.${enumValueJsName(field.type, ev, opts)}) {\n throw new Error(\"${ev.name} is ignored in GraphQL schema\");\n }\n `);\n }\n\n return chunks;\n };\n\n if (field.isList()) {\n const stmts = createBlockStmtCodes(code`item`);\n if (stmts.length === 0) {\n return code`return ${valueExpr}`;\n }\n return code`return ${valueExpr}.map(item => {\n ${joinCode(stmts)}\n return item;\n })`;\n }\n\n return code`\n ${joinCode(createBlockStmtCodes(valueExpr))}\n return ${valueExpr};\n `;\n}\n\nfunction enumValueJsName(\n _et: EnumType,\n ev: EnumTypeValue,\n opts: PrinterOptions,\n): string {\n switch (opts.protobuf) {\n case \"ts-proto\":\n return ev.proto.name;\n case \"protobuf-es-v1\":\n case \"protobuf-es\":\n return ev.proto.localName;\n }\n}\n","import { code, type Printable } from \"../../../codegen/index.js\";\n\nexport function createNonNullResolverCode(valueExpr: Printable[]): Printable[] {\n return code`\n return ${valueExpr}!;\n `;\n}\n","import {\n ObjectField,\n ObjectOneofField,\n type ObjectType,\n type PrinterOptions,\n type SquashedOneofUnionType,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport { code, joinCode, type Printable } from \"../../../codegen/index.js\";\nimport { protoTypeSymbol } from \"../util.js\";\n\n/**\n * @example nullable\n * ```ts\n * const value = source.v1 ?? source.v2 ?? source.v3;\n * if (value != null) {\n * throw new Error(\"...\");\n * }\n * return value\n * ```\n */\nexport function createOneofUnionResolverCode(\n sourceExpr: Printable[],\n field: ObjectOneofField | ObjectField<SquashedOneofUnionType>,\n opts: PrinterOptions,\n): Printable[] {\n const createBlockStmtCode = (\n sourceExpr: Printable[],\n { nullable, list }: { nullable: boolean; list: boolean },\n ): Printable[] => {\n switch (opts.protobuf) {\n case \"ts-proto\": {\n return createBlockStmtCodeForTsProto(sourceExpr, field, opts, {\n nullable,\n });\n }\n case \"protobuf-es-v1\":\n case \"protobuf-es\": {\n return createBlockStmtCodeForProtobufEs(sourceExpr, field, opts, {\n nullable,\n list,\n });\n }\n }\n };\n\n if (field instanceof ObjectField && field.isList()) {\n return code`\n return ${sourceExpr}.map(item => {\n ${createBlockStmtCode(code`item`, { nullable: false, list: true })}\n })\n `;\n }\n\n return createBlockStmtCode(sourceExpr, {\n nullable: field.isNullable(),\n list: false,\n });\n}\n\nfunction createBlockStmtCodeForTsProto(\n sourceExpr: Printable[],\n field: ObjectOneofField | ObjectField<SquashedOneofUnionType>,\n opts: PrinterOptions,\n { nullable }: { nullable: boolean },\n): Printable[] {\n const createFieldExpr = (memberField: ObjectField<any>): Printable[] => {\n if (field instanceof ObjectOneofField) {\n return code`${sourceExpr}.${tsFieldName(memberField.proto, opts).toString()}`;\n }\n return code`${sourceExpr}?.${tsFieldName(memberField.proto, opts).toString()}`;\n };\n\n return code`\n const value = ${joinCode(field.type.fields.map(createFieldExpr), \" ?? \")};\n if (value == null) {\n ${\n nullable\n ? \"return null\"\n : `throw new Error(\"${field.name} should not be null\")`\n };\n }\n return value;\n `;\n}\n\nfunction createBlockStmtCodeForProtobufEs(\n sourceExpr: Printable[],\n field: ObjectOneofField | ObjectField<SquashedOneofUnionType>,\n opts: PrinterOptions,\n { nullable, list }: { nullable: boolean; list: boolean },\n): Printable[] {\n let valueExpr: Printable[];\n if (field instanceof ObjectOneofField) {\n valueExpr = code`${sourceExpr}.${tsFieldName(field.proto, opts).toString()}.value`;\n } else if (field instanceof ObjectField) {\n valueExpr = code`${sourceExpr}${list ? \"\" : \"?\"}.${tsFieldName(\n field.type.oneofUnionType.proto,\n opts,\n ).toString()}.value`;\n } else {\n field satisfies never;\n throw new Error(\"unreachable\");\n }\n\n // In protobuf-es, accessing .value on a oneof returns a union of all member types.\n // However, some members may be ignored in the GraphQL Union type,\n // so we need to assert to the expected type containing only non-ignored members.\n const memberTypeSymbols = field.type.fields.map((f) =>\n protoTypeSymbol((f.type as ObjectType).proto, opts),\n );\n const typeAssertion =\n memberTypeSymbols.length > 0\n ? code`${joinCode(\n memberTypeSymbols.map((s) => code`${s}`),\n \" | \",\n )} | undefined`\n : code`undefined`;\n\n if (nullable) {\n return code`return (${valueExpr} ?? null) as ${typeAssertion} | null;`;\n }\n return code`\n const value = ${valueExpr} as ${typeAssertion};\n if (value == null) {\n throw new Error(\"${field.name} should not be null\");\n }\n return value;\n `;\n}\n","import type { DescField, Registry } from \"@bufbuild/protobuf\";\nimport {\n InterfaceType,\n type ObjectType,\n protobufGraphQLExtensions,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n joinCode,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport { createFieldRefCode, createNoopFieldRefCode } from \"./field.js\";\nimport {\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n protobufIsMessageSymbol,\n protoRefTypePrintable,\n protoSchemaSymbol,\n protoTypeSymbol,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export const Hello$Ref = builder.objectRef<_$hello$hello_pb.Hello>(\"Hello\")\n * builder.objectType(Hello$Ref, {\n * name: \"Hello\",\n * // ...\n * })\n * ```\n */\nexport function createObjectTypeCode(\n type: ObjectType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const isInterface = type instanceof InterfaceType;\n const typeOpts = {\n name: type.typeName,\n fields: code`t => ({${\n type.fields.length > 0\n ? joinCode(\n type.fields.map(\n (f) => code`${f.name}: ${createFieldRefCode(f, registry, opts)},`,\n ),\n )\n : code`_: ${createNoopFieldRefCode({ input: false })}`\n }})`,\n description: type.description,\n isTypeOf: isInterface\n ? undefined\n : createIsTypeOfFuncCode(type, registry, opts),\n extensions: protobufGraphQLExtensions(type, registry),\n };\n const buildRefFunc = code`${pothosBuilderPrintable(opts)}.${\n isInterface ? \"interface\" : \"object\"\n }Ref`;\n const buildTypeFunc = code`${pothosBuilderPrintable(opts)}.${\n isInterface ? \"interface\" : \"object\"\n }Type`;\n const refFuncTypeArg = isInterface\n ? code`\n Pick<\n ${protoRefTypePrintable(type.proto, opts)},\n ${joinCode(\n type.fields.map((f) =>\n literalOf(tsFieldName(f.proto as DescField, opts)),\n ),\n \"|\",\n )}\n >`\n : protoRefTypePrintable(type.proto, opts);\n\n return code`\n export const ${pothosRefPrintable(\n type,\n )} = ${buildRefFunc}<${refFuncTypeArg}>(${literalOf(type.typeName)});\n ${buildTypeFunc}(${pothosRefPrintable(type)}, ${literalOf(compactForCodegen(typeOpts))});\n `;\n}\n\nfunction createIsTypeOfFuncCode(\n type: ObjectType,\n _registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n switch (opts.protobuf) {\n case \"ts-proto\": {\n return code`\n (source) => {\n return (source as ${protoTypeSymbol(type.proto, opts)} | { $type: string & {} }).$type\n === ${literalOf(type.proto.typeName)};\n }\n `;\n }\n case \"protobuf-es-v1\": {\n return code`\n (source) => {\n return source instanceof ${protoTypeSymbol(type.proto, opts)}\n }\n `;\n }\n case \"protobuf-es\": {\n return code`\n (source) => {\n return ${protobufIsMessageSymbol()}(source, ${protoSchemaSymbol(type.proto, opts)})\n }\n `;\n }\n }\n}\n","import type { Registry } from \"@bufbuild/protobuf\";\nimport {\n type OneofUnionType,\n protobufGraphQLExtensions,\n type SquashedOneofUnionType,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport {\n fieldTypeRefPrintable,\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export cosnt Oneof = builder.unionType(\"Oneof\", {\n * types: [...],\n * // ...\n * })\n * ```\n */\nexport function createOneofUnionTypeCode(\n type: OneofUnionType | SquashedOneofUnionType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const typeOpts = {\n types: type.fields.map((f) => fieldTypeRefPrintable(f, opts)),\n description: type.description,\n extensions: protobufGraphQLExtensions(type, registry),\n };\n return code`\n export const ${pothosRefPrintable(type)} =\n ${pothosBuilderPrintable(opts)}.unionType(${literalOf(\n type.typeName,\n )}, ${literalOf(compactForCodegen(typeOpts))});\n `;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,sBAA0B;;;ACA1B,IAAAC,sBAAuC;AACvC,mCAGO;;;ACFL,cAAW;;;ACFb,yBAAmB;AAEZ,SAASC,WAAWC,OAAY;AACrC,SAAOC,mBAAAA,QAAOC,OAAO,WAAWF,OAAM;IACpCG,WAAW;IACXC,aAAa;IACbC,SAAS;IACTC,YAAY;IACZC,YAAY;IACZC,YAAY;IACZC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,QAAMC,IAAIb,OAAOc,iBAAaC,4CAAsBd,MAAMC,KAAKG,OAAO,CAAA;AACtE,QAAMW,aAAa;OACdC,wBAAwBR,OAAOF,UAAUL,KAAKG,OAAO;;AAI1DQ,IAAEK,SAASjB,IAAAA;AAEX,MAAIe,WAAWG,WAAW,GAAG;AAC3BN,MAAEO,MAAM,YAAA;AACR;EACF;AAGA,aAAWC,KAAKL,YAAY;AAC1BH,MAAEO,MAAK,GAAIC,CAAAA;AACXR,MAAEO,MAAK;EACT;AACF;AA/BgBrB;;;AHHT,IAAMuB,sBAAkBC,4CAAuB;EACpDC,MAAM;EACNC,SAAS,IAAIA,OAAAA;EACbC,gBAAYC,gDAAkB;IAC5BC;IACAC,KAAK;EACP,CAAA;EACAC,cAAcC;;EAEdC,WAAW,wBAACC,UAAAA;AACV,WAAOA,MAAMC,IAAI,CAACC,OAAO;MACvB,GAAGA;MACHC,SAASC,WAAWF,EAAEC,OAAO;IAC/B,EAAA;EACF,GALW;AAMb,CAAA;;;IDrBAE,+BAAUC,eAAAA;","names":["import_protoplugin","import_protoplugin","formatCode","code","dprint","format","lineWidth","indentWidth","useTabs","semiColons","quoteStyle","quoteProps","newLineKind","useBraces","bracePosition","singleBodyPosition","nextControlFlowPosition","trailingCommas","operatorPosition","preferHanging","preferSingleLine","import_codegen_core","import_codegen_core","import_codegen_core","PRINTABLE_ARRAY_MARKER","Symbol","for","isPrintableArray","value","Array","isArray","markAsPrintableArray","arr","Object","defineProperty","enumerable","writable","configurable","code","strings","values","result","i","length","push","String","isImportSymbol","value","kind","joinCode","codes","separator","length","result","i","push","undefined","escapeString","str","replace","compactForCodegen","v","Array","isArray","isPrintableArray","map","compactObjForCodegen","obj","key","Object","keys","literalOf","value","markAsPrintableArray","String","elements","isImportSymbol","pothosRefName","type","typeName","shapeTypeName","resolveImportOrLocal","field","opts","symbolName","localPrintable","fromFile","filename","parent","toFile","importPath","replace","code","createImportSymbol","fieldTypeRefPrintable","ObjectOneofField","pothosRefPrintable","shapeTypePrintable","fieldTypeShapePrintable","toProtoFuncName","toProtoFuncPrintable","pothosBuilderPrintable","pothos","builderPath","protoTypeSymbol","proto","chunks","name","current","unshift","join","protoImportPath","protoSchemaSymbol","protobufCreateSymbol","protobufIsMessageSymbol","protobufMessageShapeSymbol","protoRefTypePrintable","protobuf","t","o","file","dir","parse","Error","importPrefix","createEnumTypeCode","type","registry","opts","typeOpts","description","values","code","joinCode","filter","v","isIgnored","isUnespecified","map","ev","name","literalOf","compactForCodegen","deprecationReason","value","number","extensions","protobufGraphQLExtensions","protoTypeExpr","protoTypeSymbol","proto","enumRefSymbol","createImportSymbol","refTypeExpr","pothosRefPrintable","pothosBuilderPrintable","typeName","import_codegen_core","import_codegen_core","createEnumResolverCode","valueExpr","field","opts","createBlockStmtCodes","chunks","type","unspecifiedValue","escapeCode","isNullable","isList","code","name","push","protoTypeSymbol","proto","enumValueJsName","ev","valuesWithIgnored","isIgnored","stmts","length","joinCode","_et","protobuf","localName","createNonNullResolverCode","valueExpr","code","import_codegen_core","createOneofUnionResolverCode","sourceExpr","field","opts","createBlockStmtCode","nullable","list","protobuf","createBlockStmtCodeForTsProto","createBlockStmtCodeForProtobufEs","ObjectField","isList","code","isNullable","createFieldExpr","memberField","ObjectOneofField","tsFieldName","proto","toString","joinCode","type","fields","map","name","valueExpr","oneofUnionType","Error","memberTypeSymbols","f","protoTypeSymbol","typeAssertion","length","s","createGetFieldValueCodePrintable","source","proto","opts","code","tsFieldName","createFieldRefCode","field","registry","isInput","InputObjectField","baseType","type","ScalarType","literalOf","typeName","fieldTypeRefPrintable","sourceExpr","resolverCode","ObjectOneofField","createOneofUnionResolverCode","valueExpr","nullableInProto","ObjectType","isPrimitive","isWrapperType","isNullable","createNonNullResolverCode","EnumType","ObjectField","createEnumResolverCode","SquashedOneofUnionType","isBytes","isList","nullableValue","fieldOpts","list","items","description","deprecationReason","resolve","extensions","protobufGraphQLExtensions","shouldUseFieldFunc","compactForCodegen","createNoopFieldRefCode","input","createInputObjectTypeCode","type","registry","opts","fields","filter","f","options","ignoreNonMessageOneofFields","proto","oneof","InputObjectType","shapeTypeCode","code","shapeTypePrintable","joinCode","map","typeNode","fieldTypeShapePrintable","isList","protoTypeSymbol","literalOf","tsFieldName","toString","isNullable","name","ScalarType","isCustomScalar","needsTypeAssertion","protobuf","inputObjectRefType","createImportSymbol","refCode","pothosRefPrintable","pothosBuilderPrintable","typeName","compactForCodegen","length","createFieldRefCode","createNoopFieldRefCode","input","extensions","protobufGraphQLExtensions","description","codes","push","createToProtoFuncCode","oneofFields","protoTypeSym","fieldAssignments","localName","toProtoFunc","toProtoFuncPrintable","EnumType","Error","oneofAssignments","Object","values","oneofName","cases","caseName","protoSchemaSym","protoSchemaSymbol","toProtoFuncName","protobufCreateSymbol","import_codegen_core","createObjectTypeCode","type","registry","opts","isInterface","InterfaceType","typeOpts","name","typeName","fields","code","length","joinCode","map","f","createFieldRefCode","createNoopFieldRefCode","input","description","isTypeOf","undefined","createIsTypeOfFuncCode","extensions","protobufGraphQLExtensions","buildRefFunc","pothosBuilderPrintable","buildTypeFunc","refFuncTypeArg","protoRefTypePrintable","proto","literalOf","tsFieldName","pothosRefPrintable","compactForCodegen","_registry","protobuf","protoTypeSymbol","protobufIsMessageSymbol","protoSchemaSymbol","import_codegen_core","createOneofUnionTypeCode","type","registry","opts","typeOpts","types","fields","map","f","fieldTypeRefPrintable","description","extensions","protobufGraphQLExtensions","code","pothosRefPrintable","pothosBuilderPrintable","literalOf","typeName","compactForCodegen","createTypeDslPrintables","types","registry","opts","flatMap","type","ObjectType","createObjectTypeCode","InputObjectType","createInputObjectTypeCode","EnumType","createEnumTypeCode","OneofUnionType","SquashedOneofUnionType","createOneofUnionTypeCode","_exhaustiveCheck","allowedProtobufs","generateFiles","schema","file","opts","options","includes","printer","protobuf","registry","createRegistryFromSchema","types","collectTypesFromFile","type","allFiles","f","generateFile","filenameFromProtoFile","printables","createTypeDslPrintables","preamble","length","print","p","protocGenPothos","createEcmaScriptPlugin","name","version","generateTs","createTsGenerator","generateFiles","dsl","parseOptions","parsePothosOptions","transpile","files","map","f","content","formatCode","runNodeJs","protocGenPothos"]}
|
|
1
|
+
{"version":3,"sources":["../src/protoc-gen-pothos.ts","../src/plugin.ts","../package.json","../src/codegen/stringify.ts","../src/printer.ts","../src/dslgen/printers/index.ts","../src/dslgen/printers/enumType.ts","../src/codegen/code-builder.ts","../src/codegen/types.ts","../src/codegen/helpers.ts","../src/dslgen/printers/util.ts","../src/dslgen/printers/inputObjectType.ts","../src/dslgen/printers/field.ts","../src/dslgen/printers/fieldResolver/enumFieldResolver.ts","../src/dslgen/printers/fieldResolver/nonNullResolver.ts","../src/dslgen/printers/fieldResolver/oneofUnionResolver.ts","../src/dslgen/printers/objectType.ts","../src/dslgen/printers/oneofUnionType.ts"],"sourcesContent":["import { runNodeJs } from \"@bufbuild/protoplugin\";\n\nimport { protocGenPothos } from \"./plugin.js\";\n\nrunNodeJs(protocGenPothos);\n","import { createEcmaScriptPlugin } from \"@bufbuild/protoplugin\";\nimport {\n createTsGenerator,\n parsePothosOptions,\n} from \"@proto-graphql/protoc-plugin-helpers\";\n\nimport { version } from \"../package.json\";\nimport { formatCode } from \"./codegen/stringify.js\";\nimport { generateFiles } from \"./printer.js\";\n\nexport const protocGenPothos = createEcmaScriptPlugin({\n name: \"protoc-gen-pothos\",\n version: `v${version}`,\n generateTs: createTsGenerator({\n generateFiles,\n dsl: \"pothos\",\n }),\n parseOptions: parsePothosOptions,\n // NOTE: force `target=ts` and apply formatting\n transpile: (files) => {\n return files.map((f) => ({\n ...f,\n content: formatCode(f.content),\n }));\n },\n});\n","{\n \"name\": \"protoc-gen-pothos\",\n \"version\": \"0.7.1\",\n \"description\": \"Generate DSL for Pothos GraphQL from Protocol Buffers IDL\",\n \"keywords\": [\n \"graphql\",\n \"grpc\",\n \"pothos\",\n \"protobuf\",\n \"typescript\"\n ],\n \"bin\": {\n \"protoc-gen-pothos\": \"./bin/protoc-gen-pothos.cjs\"\n },\n \"repository\": \"git@github.com:proto-graphql/proto-graphql-js.git\",\n \"author\": \"izumin5210 <m@izum.in>\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.cjs\"\n }\n }\n },\n \"files\": [\n \"bin/\",\n \"docs/\",\n \"!docs/development/**\",\n \"src/\",\n \"dist/\",\n \"!src/**/*.test.ts\",\n \"!src/**/__tests__/\"\n ],\n \"sideEffects\": false,\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">= 14.0.0\"\n },\n \"dependencies\": {\n \"@bufbuild/protobuf\": \"catalog:\",\n \"@bufbuild/protoplugin\": \"catalog:\",\n \"@proto-graphql/codegen-core\": \"workspace:*\",\n \"@proto-graphql/protoc-plugin-helpers\": \"workspace:*\",\n \"dprint-node\": \"catalog:\"\n },\n \"devDependencies\": {\n \"@pothos/core\": \"catalog:test\",\n \"@proto-graphql/e2e-testapis-protobuf-es\": \"workspace:*\",\n \"@proto-graphql/e2e-testapis-protobuf-es-v2\": \"workspace:*\",\n \"@proto-graphql/e2e-testapis-ts-proto\": \"workspace:*\",\n \"@proto-graphql/e2e-testapis-ts-proto-with-forcelong-number\": \"workspace:*\",\n \"@proto-graphql/testapis-proto\": \"workspace:*\",\n \"@proto-graphql/tsconfig\": \"workspace:*\",\n \"@vitest/coverage-v8\": \"^4.0.0\",\n \"graphql\": \"catalog:test\",\n \"graphql-scalars\": \"^1.24.0\",\n \"tsx\": \"^4.21.0\"\n },\n \"scripts\": {\n \"build\": \"tsup && cp -r ../../docs/protoc-gen-pothos docs\",\n \"clean\": \"rm -rf dist docs\",\n \"test\": \"vitest run --passWithNoTests\",\n \"test:coverage\": \"vitest run --coverage\"\n }\n}\n","import dprint from \"dprint-node\";\n\nexport function formatCode(code: string): string {\n return dprint.format(\"file.ts\", code, {\n lineWidth: 80,\n indentWidth: 2,\n useTabs: false,\n semiColons: \"always\",\n quoteStyle: \"alwaysDouble\",\n quoteProps: \"asNeeded\",\n newLineKind: \"lf\",\n useBraces: \"whenNotSingleLine\",\n bracePosition: \"sameLineUnlessHanging\",\n singleBodyPosition: \"maintain\",\n nextControlFlowPosition: \"sameLine\",\n trailingCommas: \"onlyMultiLine\",\n operatorPosition: \"nextLine\",\n preferHanging: false,\n preferSingleLine: true,\n \"arrowFunction.useParentheses\": \"force\",\n });\n}\n","import type { DescFile } from \"@bufbuild/protobuf\";\nimport type { Schema } from \"@bufbuild/protoplugin\";\nimport {\n collectTypesFromFile,\n createRegistryFromSchema,\n filenameFromProtoFile,\n} from \"@proto-graphql/codegen-core\";\nimport type { Options } from \"@proto-graphql/protoc-plugin-helpers\";\n\nimport { createTypeDslPrintables } from \"./dslgen/index.js\";\n\nconst allowedProtobufs = [\"ts-proto\", \"protobuf-es-v1\", \"protobuf-es\"];\n\nexport function generateFiles(\n schema: Schema<Options<\"pothos\">>,\n file: DescFile,\n): void {\n const opts = schema.options;\n\n if (!allowedProtobufs.includes(opts.printer.protobuf)) {\n opts.printer.protobuf = \"ts-proto\"; // default\n }\n\n const registry = createRegistryFromSchema(schema);\n const types = collectTypesFromFile(file, opts.type, schema.allFiles);\n\n const f = schema.generateFile(filenameFromProtoFile(file, opts.printer));\n const printables = [\n ...createTypeDslPrintables(types, registry, opts.printer),\n ];\n\n // ヘッダー出力(preamble プロパティに格納される)\n f.preamble(file);\n\n if (printables.length === 0) {\n f.print(\"export {};\");\n return;\n }\n\n // 各型の Printable を直接出力\n for (const p of printables) {\n f.print(...p);\n f.print(); // 空行で区切り\n }\n}\n","import type { createRegistry } from \"@bufbuild/protobuf\";\nimport {\n EnumType,\n InputObjectType,\n ObjectType,\n OneofUnionType,\n SquashedOneofUnionType,\n} from \"@proto-graphql/codegen-core\";\n\nimport type { Printable } from \"../../codegen/index.js\";\nimport { createEnumTypeCode } from \"./enumType.js\";\nimport { createInputObjectTypeCode } from \"./inputObjectType.js\";\nimport { createObjectTypeCode } from \"./objectType.js\";\nimport { createOneofUnionTypeCode } from \"./oneofUnionType.js\";\nimport type { PothosPrinterOptions } from \"./util.js\";\n\nexport function createTypeDslPrintables(\n types: (\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n )[],\n registry: ReturnType<typeof createRegistry>,\n opts: PothosPrinterOptions,\n): Printable[][] {\n return types.flatMap((type) => {\n if (type instanceof ObjectType) {\n return [createObjectTypeCode(type, registry, opts)];\n }\n if (type instanceof InputObjectType) {\n return [createInputObjectTypeCode(type, registry, opts)];\n }\n if (type instanceof EnumType) {\n return [createEnumTypeCode(type, registry, opts)];\n }\n if (\n type instanceof OneofUnionType ||\n type instanceof SquashedOneofUnionType\n ) {\n return [createOneofUnionTypeCode(type, registry, opts)];\n }\n\n const _exhaustiveCheck: never = type;\n throw \"unreachable\";\n });\n}\n","import type { Registry } from \"@bufbuild/protobuf\";\nimport {\n type EnumType,\n protobufGraphQLExtensions,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n createImportSymbol,\n joinCode,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport {\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n protoTypeSymbol,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export cosnt Hello$Ref: EnumRef<Hello, Hello> = builder.enumType(\"Hello\", {\n * values: [\n * // ...\n * ],\n * // ...\n * })\n * ```\n */\nexport function createEnumTypeCode(\n type: EnumType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const typeOpts = {\n description: type.description,\n values: code`{${joinCode(\n type.values\n .filter((v) => !v.isIgnored() && !v.isUnespecified())\n .map(\n (ev) =>\n code`${ev.name}: ${literalOf(\n compactForCodegen({\n description: ev.description,\n deprecationReason: ev.deprecationReason,\n value: ev.number,\n extensions: protobufGraphQLExtensions(ev, registry),\n }),\n )},`,\n ),\n )}} as const`,\n extensions: protobufGraphQLExtensions(type, registry),\n };\n\n const protoTypeExpr = protoTypeSymbol(type.proto, opts);\n const enumRefSymbol = createImportSymbol(\"EnumRef\", \"@pothos/core\");\n // EnumRef<Hello, Hello>\n const refTypeExpr = code`${enumRefSymbol}<${protoTypeExpr}, ${protoTypeExpr}>`;\n\n return code`\n export const ${pothosRefPrintable(type)}: ${refTypeExpr} =\n ${pothosBuilderPrintable(opts)}.enumType(${literalOf(\n type.typeName,\n )}, ${literalOf(compactForCodegen(typeOpts))});\n `;\n}\n","import type { ImportSymbol, Printable } from \"./types.js\";\n\nexport const PRINTABLE_ARRAY_MARKER = Symbol.for(\n \"proto-graphql:printable-array\",\n);\n\nexport type PrintableArray = Printable[] & { [PRINTABLE_ARRAY_MARKER]: true };\n\nexport function isPrintableArray(value: unknown): value is PrintableArray {\n return Array.isArray(value) && PRINTABLE_ARRAY_MARKER in value;\n}\n\nexport function markAsPrintableArray(arr: Printable[]): PrintableArray {\n Object.defineProperty(arr, PRINTABLE_ARRAY_MARKER, {\n value: true,\n enumerable: false,\n writable: false,\n configurable: false,\n });\n return arr as PrintableArray;\n}\n\ntype CodeValue =\n | string\n | number\n | ImportSymbol\n | Printable[]\n | null\n | undefined;\n\nexport function code(\n strings: TemplateStringsArray,\n ...values: CodeValue[]\n): PrintableArray {\n const result: Printable[] = [];\n\n for (let i = 0; i < strings.length; i++) {\n if (strings[i] !== \"\") {\n result.push(strings[i]);\n }\n\n if (i < values.length) {\n const value = values[i];\n if (value == null) {\n result.push(String(value));\n } else if (typeof value === \"string\") {\n if (value !== \"\") {\n result.push(value);\n }\n } else if (typeof value === \"number\") {\n result.push(String(value));\n } else if (Array.isArray(value)) {\n result.push(...value);\n } else {\n result.push(value as Printable);\n }\n }\n }\n\n if (result.length === 0) {\n result.push(\"\");\n }\n\n return markAsPrintableArray(result);\n}\n","export type {\n ImportSymbol,\n Printable,\n} from \"@bufbuild/protoplugin\";\n\nexport { createImportSymbol } from \"@bufbuild/protoplugin\";\n\nimport type { ImportSymbol } from \"@bufbuild/protoplugin\";\n\nexport function isImportSymbol(value: unknown): value is ImportSymbol {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"kind\" in value &&\n (value as Record<string, unknown>).kind === \"es_symbol\"\n );\n}\n","import {\n isPrintableArray,\n markAsPrintableArray,\n type PrintableArray,\n} from \"./code-builder.js\";\nimport type { Printable } from \"./types.js\";\nimport { isImportSymbol } from \"./types.js\";\n\nexport function joinCode(\n codes: Printable[][],\n separator?: string,\n): Printable[] {\n if (codes.length === 0) {\n return [];\n }\n\n const result: Printable[] = [];\n for (let i = 0; i < codes.length; i++) {\n result.push(...codes[i]);\n if (separator !== undefined && i < codes.length - 1) {\n result.push(separator);\n }\n }\n return result;\n}\n\nfunction escapeString(str: string): string {\n return str\n .replace(/\\\\/g, \"\\\\\\\\\")\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, \"\\\\n\")\n .replace(/\\r/g, \"\\\\r\")\n .replace(/\\t/g, \"\\\\t\");\n}\n\n/**\n * Remove nullish values recursively, preserving PrintableArrays.\n * This is a variant of compact() from codegen-core that doesn't lose the PrintableArray marker.\n */\nexport function compactForCodegen(v: unknown): unknown {\n if (typeof v !== \"object\") return v;\n if (v == null) return v;\n if (Array.isArray(v)) {\n if (isPrintableArray(v)) {\n return v;\n }\n return v.map(compactForCodegen);\n }\n return compactObjForCodegen(v as Record<string, unknown>);\n}\n\nfunction compactObjForCodegen(\n obj: Record<string, unknown>,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(obj)) {\n const v = obj[key];\n if (v != null) {\n result[key] = compactForCodegen(v);\n }\n }\n return result;\n}\n\nexport function literalOf(value: unknown): PrintableArray {\n if (value === null) {\n return markAsPrintableArray([\"null\"]);\n }\n\n if (value === undefined) {\n return markAsPrintableArray([\"undefined\"]);\n }\n\n if (typeof value === \"string\") {\n return markAsPrintableArray([`\"${escapeString(value)}\"`]);\n }\n\n if (typeof value === \"number\") {\n return markAsPrintableArray([String(value)]);\n }\n\n if (typeof value === \"boolean\") {\n return markAsPrintableArray([String(value)]);\n }\n\n if (Array.isArray(value)) {\n if (isPrintableArray(value)) {\n return value;\n }\n\n if (value.length === 0) {\n return markAsPrintableArray([\"[]\"]);\n }\n\n const elements: Printable[] = [\"[\"];\n for (let i = 0; i < value.length; i++) {\n if (i > 0) {\n elements.push(\", \");\n }\n elements.push(...literalOf(value[i]));\n }\n elements.push(\"]\");\n return markAsPrintableArray(elements);\n }\n\n if (typeof value === \"object\") {\n // ImportSymbol should be returned as-is (wrapped in PrintableArray)\n if (isImportSymbol(value)) {\n return markAsPrintableArray([value]);\n }\n\n const obj = value as Record<string, unknown>;\n const keys = Object.keys(obj);\n\n if (keys.length === 0) {\n return markAsPrintableArray([\"{}\"]);\n }\n\n const elements: Printable[] = [\"{ \"];\n for (let i = 0; i < keys.length; i++) {\n if (i > 0) {\n elements.push(\", \");\n }\n const key = keys[i];\n // Always quote keys to match ts-poet literalOf behavior\n elements.push(`\"${escapeString(key)}\": `);\n elements.push(...literalOf(obj[key]));\n }\n elements.push(\" }\");\n return markAsPrintableArray(elements);\n }\n\n return markAsPrintableArray([String(value)]);\n}\n","import * as path from \"node:path\";\n\nimport type {\n DescEnum,\n DescExtension,\n DescFile,\n DescMessage,\n DescService,\n} from \"@bufbuild/protobuf\";\nimport { nestedTypes } from \"@bufbuild/protobuf/reflect\";\nimport { safeIdentifier } from \"@bufbuild/protoplugin\";\nimport {\n type EnumType,\n filename,\n type InputObjectField,\n type InputObjectType,\n type InterfaceType,\n type ObjectField,\n ObjectOneofField,\n type ObjectType,\n type OneofUnionType,\n type PrinterOptions,\n type SquashedOneofUnionType,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n createImportSymbol,\n type ImportSymbol,\n type Printable,\n} from \"../../codegen/index.js\";\n\nexport type PothosPrinterOptions = Extract<PrinterOptions, { dsl: \"pothos\" }>;\n\nexport function pothosRefName(\n type:\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n | InterfaceType,\n): string {\n return `${type.typeName}$Ref`;\n}\n\nexport function shapeTypeName(type: InputObjectType): string {\n return `${type.typeName}$Shape`;\n}\n\ntype TypeWithFilename =\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n | InterfaceType;\n\nfunction resolveImportOrLocal(\n field: { parent: TypeWithFilename; type: TypeWithFilename },\n opts: PothosPrinterOptions,\n symbolName: string,\n localPrintable: () => Printable[],\n): Printable[] {\n const fromFile = filename(field.parent, opts);\n const toFile = filename(field.type, opts);\n if (fromFile === toFile) return localPrintable();\n\n const importPath = `./${toFile.replace(/\\.ts$/, \"\")}`;\n return code`${createImportSymbol(symbolName, importPath)}`;\n}\n\nexport function fieldTypeRefPrintable(\n field:\n | ObjectField<\n ObjectType | EnumType | InterfaceType | SquashedOneofUnionType\n >\n | InputObjectField<InputObjectType | EnumType>\n | ObjectOneofField,\n opts: PothosPrinterOptions,\n): Printable[] {\n if (field instanceof ObjectOneofField) return pothosRefPrintable(field.type);\n\n return resolveImportOrLocal(field, opts, pothosRefName(field.type), () =>\n pothosRefPrintable(field.type),\n );\n}\n\nexport function shapeTypePrintable(type: InputObjectType): Printable[] {\n return code`${shapeTypeName(type)}`;\n}\n\nexport function fieldTypeShapePrintable(\n field: InputObjectField<InputObjectType>,\n opts: PothosPrinterOptions,\n): Printable[] {\n return resolveImportOrLocal(field, opts, shapeTypeName(field.type), () =>\n shapeTypePrintable(field.type),\n );\n}\n\nexport function toProtoFuncName(type: InputObjectType): string {\n return `${type.typeName}$toProto`;\n}\n\nexport function toProtoFuncPrintable(\n field: InputObjectField<InputObjectType>,\n opts: PothosPrinterOptions,\n): Printable[] {\n return resolveImportOrLocal(\n field,\n opts,\n toProtoFuncName(field.type),\n () => code`${toProtoFuncName(field.type)}`,\n );\n}\n\nexport function pothosRefPrintable(\n type:\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n | InterfaceType,\n): Printable[] {\n return code`${pothosRefName(type)}`;\n}\n\nexport function pothosBuilderPrintable(\n opts: Pick<PothosPrinterOptions, \"pothos\">,\n): Printable[] {\n // protoplugin が自動的に相対パスを計算するため、builderPath をそのまま使用\n return code`${createImportSymbol(\"builder\", opts.pothos.builderPath)}`;\n}\n\nexport function protoTypeSymbol(\n proto: DescMessage | DescEnum,\n opts: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): ImportSymbol {\n const chunks = [proto.name];\n let current: DescMessage | DescEnum = proto;\n while (current.parent != null) {\n current = current.parent;\n chunks.unshift(current.name);\n }\n const symbolName = chunks.join(\"_\");\n const importPath = protoImportPath(proto, opts);\n return createImportSymbol(symbolName, importPath);\n}\n\n/**\n * protobuf-es v2 用: Schema シンボル (例: UserSchema, Parent_ChildSchema) を生成\n *\n * protobuf-es の @bufbuild/protoplugin が行う名前衝突回避ロジックを再実装。\n * 同一ファイル内で shape 名 (型名) と desc 名 (Schema 定数名) が衝突する場合、\n * protobuf-es は salt suffix ($, $1, $2, ...) を付与する。\n *\n * @see {@link https://github.com/bufbuild/protobuf-es/blob/v2.10.2/packages/protoplugin/src/names.ts | @bufbuild/protoplugin names.ts}\n */\nexport function protoSchemaSymbol(\n proto: DescMessage | DescEnum,\n opts: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): ImportSymbol {\n const symbolName = resolveProtobufEsDescName(proto);\n const importPath = protoImportPath(proto, opts);\n return createImportSymbol(symbolName, importPath);\n}\n\nfunction protobufEsSalt(i: number): string {\n if (i === 0) return \"\";\n if (i === 1) return \"$\";\n return `$${i - 1}`;\n}\n\nfunction idealShapeName(desc: DescMessage | DescEnum, i: number): string {\n return safeIdentifier(\n protobufEsIdentifierForNested(desc) + protobufEsSalt(i),\n );\n}\n\ntype NestedDesc = DescMessage | DescEnum | DescExtension | DescService;\n\n/**\n * protobuf-es と同じ identifier 計算。\n * パッケージ名を除去し、ドット (ネスト区切り) をアンダースコアに置換する。\n */\nfunction protobufEsIdentifierForNested(desc: NestedDesc): string {\n const pkg = desc.file.proto.package;\n const offset = pkg.length > 0 ? pkg.length + 1 : 0;\n return desc.typeName.substring(offset).replace(/\\./g, \"_\");\n}\n\nfunction idealDescName(desc: NestedDesc | DescFile, i: number): string {\n const salt = protobufEsSalt(i);\n if (desc.kind === \"file\") {\n const name = `file_${desc.name.replace(/[^a-zA-Z0-9_]+/g, \"_\")}`;\n return safeIdentifier(name + salt);\n }\n if (desc.kind === \"enum\" || desc.kind === \"message\") {\n return safeIdentifier(\n protobufEsIdentifierForNested(desc) + \"Schema\" + salt,\n );\n }\n // extension, service: Schema suffix なし\n return safeIdentifier(protobufEsIdentifierForNested(desc) + salt);\n}\n\n// ファイル単位のキャッシュ: 同一ファイル内の複数の型に対して重複計算を避ける\nconst descNameCache = new WeakMap<\n DescFile,\n Map<DescMessage | DescEnum, string>\n>();\n\n/**\n * @bufbuild/protoplugin の allNames() と同じロジックで desc 名を解決する。\n *\n * 1. Pass 1: 全 message/enum の shape 名を登録\n * 2. Pass 2: file desc + 全 nested types の desc 名を登録 (衝突時は salt suffix を付与)\n */\nfunction resolveProtobufEsDescName(proto: DescMessage | DescEnum): string {\n const file = proto.file;\n\n const cached = descNameCache.get(file);\n if (cached) {\n const name = cached.get(proto);\n if (name !== undefined) return name;\n }\n\n const taken = new Set<string>();\n const descNames = new Map<DescMessage | DescEnum, string>();\n\n // Pass 1: shape 名 (message/enum のみ)\n for (const desc of nestedTypes(file)) {\n if (desc.kind !== \"enum\" && desc.kind !== \"message\") continue;\n let name: string;\n for (let i = 0; ; i++) {\n name = idealShapeName(desc, i);\n if (!taken.has(name)) break;\n }\n taken.add(name);\n }\n\n // Pass 2: desc 名 (file + 全 nested types)\n {\n // file descriptor 自体の desc 名を登録\n let fileName: string;\n for (let i = 0; ; i++) {\n fileName = idealDescName(file, i);\n if (!taken.has(fileName)) break;\n }\n taken.add(fileName);\n }\n\n for (const desc of nestedTypes(file) as Iterable<NestedDesc>) {\n let name: string;\n for (let i = 0; ; i++) {\n name = idealDescName(desc, i);\n if (!taken.has(name)) break;\n }\n taken.add(name);\n if (desc.kind === \"message\" || desc.kind === \"enum\") {\n descNames.set(desc, name);\n }\n }\n\n descNameCache.set(file, descNames);\n\n const result = descNames.get(proto);\n if (result === undefined) {\n throw new Error(\n `Unable to determine protobuf-es desc name for ${proto.toString()}`,\n );\n }\n return result;\n}\n\n/**\n * @bufbuild/protobuf から create 関数を import\n */\nexport function protobufCreateSymbol(): ImportSymbol {\n return createImportSymbol(\"create\", \"@bufbuild/protobuf\");\n}\n\n/**\n * @bufbuild/protobuf から isMessage 関数を import\n */\nexport function protobufIsMessageSymbol(): ImportSymbol {\n return createImportSymbol(\"isMessage\", \"@bufbuild/protobuf\");\n}\n\n/**\n * @bufbuild/protobuf から MessageShape 型を import\n */\nexport function protobufMessageShapeSymbol(): ImportSymbol {\n return createImportSymbol(\"MessageShape\", \"@bufbuild/protobuf\");\n}\n\n/**\n * v2 用: ObjectRef の型パラメータとして使用する型を生成\n * - protobuf-es v2: MessageShape<typeof XxxSchema>\n * - protobuf-es v1: Xxx (クラス)\n * - ts-proto: Xxx (interface)\n */\nexport function protoRefTypePrintable(\n proto: DescMessage,\n opts: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): Printable[] {\n switch (opts.protobuf) {\n case \"ts-proto\":\n case \"protobuf-es-v1\": {\n return code`${protoTypeSymbol(proto, opts)}`;\n }\n case \"protobuf-es\": {\n return code`${protobufMessageShapeSymbol()}<typeof ${protoSchemaSymbol(proto, opts)}>`;\n }\n }\n}\n\nfunction protoImportPath(\n t: DescMessage | DescEnum,\n o: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): string {\n let importPath: string;\n switch (o.protobuf) {\n case \"ts-proto\": {\n importPath = t.file.name;\n break;\n }\n case \"protobuf-es-v1\":\n case \"protobuf-es\": {\n const { dir, name } = path.parse(t.file.name);\n importPath = `${dir}/${name}_pb`;\n break;\n }\n default: {\n o.protobuf satisfies never;\n throw new Error(`unexpected protobuf option: ${o.protobuf}`);\n }\n }\n return `${o.importPrefix ? `${o.importPrefix}/` : \"./\"}${importPath}`.replace(\n /(?<!:)\\/\\//,\n \"/\",\n );\n}\n","import type { Registry } from \"@bufbuild/protobuf\";\nimport {\n EnumType,\n type InputObjectField,\n InputObjectType,\n protobufGraphQLExtensions,\n ScalarType,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n createImportSymbol,\n joinCode,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport { createFieldRefCode, createNoopFieldRefCode } from \"./field.js\";\nimport {\n fieldTypeShapePrintable,\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n protobufCreateSymbol,\n protoSchemaSymbol,\n protoTypeSymbol,\n shapeTypePrintable,\n toProtoFuncName,\n toProtoFuncPrintable,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export type HelloInput$Shape = {\n * // ...\n * }\n * export const HelloInput$Ref: pothos.InputObjectRef<Hello$SHape> = builder.inputRef(\"HelloInput\").implement({\n * description: \"...\",\n * fields: (t) => ({\n * // ...\n * }),\n * })\n *\n * export function HelloInput$toProto () {\n * return {\n * // ...\n * }\n * }\n *\n * ```\n */\nexport function createInputObjectTypeCode(\n type: InputObjectType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const fields = type.fields.filter(\n (f) =>\n !(\n type.options.ignoreNonMessageOneofFields &&\n f.proto.oneof != null &&\n !(f.type instanceof InputObjectType)\n ),\n );\n\n const shapeTypeCode = code`\n export type ${shapeTypePrintable(type)} = {\n ${joinCode(\n fields.map((f) => {\n let typeNode: Printable[];\n if (f.type instanceof InputObjectType) {\n typeNode = fieldTypeShapePrintable(\n f as InputObjectField<InputObjectType>,\n opts,\n );\n if (f.isList()) typeNode = code`Array<${typeNode}>`;\n } else {\n typeNode = code`${protoTypeSymbol(type.proto, opts)}[${literalOf(\n tsFieldName(f.proto, opts).toString(),\n )}]`;\n }\n return f.isNullable()\n ? code`${f.name}?: ${typeNode} | null,`\n : code`${f.name}: ${\n f.type instanceof ScalarType && f.type.isCustomScalar()\n ? code`NonNullable<${typeNode}>`\n : typeNode\n },`;\n }),\n )}\n };\n `;\n\n // In protobuf-es v2, Message types have internal properties like $unknown and $typeName,\n // which can cause type mismatches between Pothos's inferred types and the InputShape type.\n // To work around this, we use a type assertion for protobuf-es v2.\n const needsTypeAssertion = opts.protobuf === \"protobuf-es\";\n const inputObjectRefType = code`${createImportSymbol(\n \"InputObjectRef\",\n \"@pothos/core\",\n )}<${shapeTypePrintable(type)}>`;\n\n const refCode = code`\n export const ${pothosRefPrintable(type)}: ${inputObjectRefType} =\n ${pothosBuilderPrintable(opts)}.inputRef<${shapeTypePrintable(\n type,\n )}>(${literalOf(type.typeName)}).implement(\n ${literalOf(\n compactForCodegen({\n fields: code`t => ({${\n fields.length > 0\n ? joinCode(\n fields.map(\n (f) =>\n code`${f.name}: ${createFieldRefCode(\n f,\n registry,\n opts,\n )}`,\n ),\n \", \",\n )\n : code`_: ${createNoopFieldRefCode({ input: true })}`\n }})`,\n extensions: protobufGraphQLExtensions(type, registry),\n description: type.description,\n }),\n )}\n )${needsTypeAssertion ? code` as ${inputObjectRefType}` : \"\"};\n `;\n\n const codes: Printable[][] = [shapeTypeCode, refCode];\n\n if (opts.protobuf === \"protobuf-es-v1\" || opts.protobuf === \"protobuf-es\") {\n codes.push(createToProtoFuncCode(type, fields, opts));\n }\n\n return joinCode(codes, \"\\n\\n\");\n}\n\nfunction createToProtoFuncCode(\n type: InputObjectType,\n fields: InputObjectField<ScalarType | EnumType | InputObjectType>[],\n opts: PothosPrinterOptions,\n): Printable[] {\n const oneofFields: Record<string, InputObjectField<InputObjectType>[]> = {};\n for (const f of fields) {\n if (f.proto.oneof == null) continue;\n if (!(f.type instanceof InputObjectType)) {\n // Non-message oneof members are ignored in toProto generation.\n // The strict validation path is handled in type construction.\n continue;\n }\n\n oneofFields[f.proto.oneof.name] = [\n ...(oneofFields[f.proto.oneof.name] || []),\n f as InputObjectField<InputObjectType>,\n ];\n }\n\n const protoTypeSym = protoTypeSymbol(type.proto, opts);\n\n const fieldAssignments = joinCode(\n fields\n .filter((f) => f.proto.oneof == null)\n .map((f) => {\n const localName = tsFieldName(f.proto, opts).toString();\n if (f.type instanceof InputObjectType) {\n const toProtoFunc = toProtoFuncPrintable(\n f as InputObjectField<InputObjectType>,\n opts,\n );\n if (f.isList()) {\n return code`${localName}: input?.${f.name}?.map(v => ${toProtoFunc}(v)),`;\n }\n return code`${localName}: input?.${f.name} ? ${toProtoFunc}(input.${f.name}) : undefined,`;\n }\n if (f.type instanceof ScalarType || f.type instanceof EnumType) {\n return code`${localName}: input?.${f.name} ?? undefined,`;\n }\n f.type satisfies never;\n throw new Error(\"unreachable\");\n }),\n \"\\n\",\n );\n\n const oneofAssignments = joinCode(\n Object.values(oneofFields).map((fields) => {\n const oneofName = tsFieldName(\n // biome-ignore lint/style/noNonNullAssertion: we know it's not null\n fields[0]!.proto.oneof!,\n opts,\n ).toString();\n const cases = fields.map((f) => {\n const caseName = tsFieldName(f.proto, opts).toString();\n return code`input?.${f.name} ? { case: \"${caseName}\", value: ${toProtoFuncPrintable(f, opts)}(input.${f.name}) } :`;\n });\n return code`${oneofName}: ${joinCode(cases, \" \")} undefined,`;\n }),\n \"\\n\",\n );\n\n if (opts.protobuf === \"protobuf-es\") {\n const protoSchemaSym = protoSchemaSymbol(type.proto, opts);\n return code`\n export function ${toProtoFuncName(type)} (input: ${shapeTypePrintable(\n type,\n )} | null | undefined): ${protoTypeSym} {\n return ${protobufCreateSymbol()}(${protoSchemaSym}, {\n ${fieldAssignments}\n ${oneofAssignments}\n });\n }\n `;\n }\n\n return code`\n export function ${toProtoFuncName(type)} (input: ${shapeTypePrintable(\n type,\n )} | null | undefined): ${protoTypeSym} {\n return new ${protoTypeSym}({\n ${fieldAssignments}\n ${oneofAssignments}\n });\n }\n `;\n}\n","import type { createRegistry, DescField } from \"@bufbuild/protobuf\";\nimport {\n EnumType,\n InputObjectField,\n ObjectField,\n ObjectOneofField,\n ObjectType,\n protobufGraphQLExtensions,\n ScalarType,\n SquashedOneofUnionType,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport { createEnumResolverCode } from \"./fieldResolver/enumFieldResolver.js\";\nimport { createNonNullResolverCode } from \"./fieldResolver/nonNullResolver.js\";\nimport { createOneofUnionResolverCode } from \"./fieldResolver/oneofUnionResolver.js\";\nimport { fieldTypeRefPrintable, type PothosPrinterOptions } from \"./util.js\";\n\nfunction createGetFieldValueCodePrintable(\n source: string,\n proto: DescField,\n opts: PothosPrinterOptions,\n): Printable[] {\n return code`${source}.${tsFieldName(proto, opts)}`;\n}\n\n/**\n * @example\n * ```ts\n * t.expose(\"name\", {\n * type: \"Boolean\",\n * nullable: true,\n * description: \"...\",\n * })\n * ```\n * ```ts\n * t.field({\n * type: \"Boolean\",\n * nullable: true,\n * description: \"...\",\n * resolve() {\n * return true\n * }\n * })\n * ```\n */\nexport function createFieldRefCode(\n field: ObjectField<any> | ObjectOneofField | InputObjectField<any>,\n registry: ReturnType<typeof createRegistry>,\n opts: PothosPrinterOptions,\n): Printable[] {\n const isInput = field instanceof InputObjectField;\n const baseType =\n field.type instanceof ScalarType\n ? literalOf(field.type.typeName)\n : fieldTypeRefPrintable(field, opts);\n\n const sourceExpr = \"source\";\n let resolverCode: Printable[] | undefined;\n if (!isInput) {\n if (field instanceof ObjectOneofField) {\n resolverCode = createOneofUnionResolverCode(\n code`${sourceExpr}`,\n field,\n opts,\n );\n } else {\n const valueExpr = createGetFieldValueCodePrintable(\n sourceExpr,\n field.proto,\n opts,\n );\n const nullableInProto =\n field.type instanceof ObjectType ||\n (field.type instanceof ScalarType &&\n !field.type.isPrimitive() &&\n !field.type.isWrapperType());\n if (nullableInProto && !field.isNullable()) {\n resolverCode = createNonNullResolverCode(valueExpr);\n }\n if (field.type instanceof EnumType && field instanceof ObjectField) {\n resolverCode = createEnumResolverCode(valueExpr, field, opts);\n }\n if (\n field.type instanceof SquashedOneofUnionType &&\n field instanceof ObjectField\n ) {\n resolverCode = createOneofUnionResolverCode(valueExpr, field, opts);\n }\n if (field.type instanceof ScalarType && field.type.isBytes()) {\n if (field.isList()) {\n resolverCode = code`return ${valueExpr}.map(v => Buffer.from(v));`;\n } else if (field.isNullable()) {\n resolverCode = code`return ${valueExpr} == null ? null : Buffer.from(${valueExpr});`;\n } else {\n resolverCode = code`return Buffer.from(${valueExpr});`;\n }\n }\n }\n }\n\n const nullableValue = isInput !== field.isNullable(); /* Logical XOR */\n const fieldOpts = {\n type: field.isList() ? code`[${baseType}]` : baseType,\n [isInput ? \"required\" : \"nullable\"]: field.isList()\n ? { list: nullableValue, items: isInput /* always non-null */ }\n : nullableValue,\n description: field.description,\n deprecationReason: field.deprecationReason,\n resolve: resolverCode ? code`${sourceExpr} => {${resolverCode}}` : null,\n extensions: protobufGraphQLExtensions(field, registry),\n };\n\n const shouldUseFieldFunc = isInput || resolverCode != null;\n return shouldUseFieldFunc\n ? code`t.field(${literalOf(compactForCodegen(fieldOpts))})`\n : code`t.expose(${literalOf(\n tsFieldName(field.proto as DescField, opts),\n )}, ${literalOf(compactForCodegen(fieldOpts))})`;\n}\n\n/**\n * @example\n * ```ts\n * t.field( {\n * type: \"Boolean\",\n * nullable: true,\n * description: \"noop field\",\n * resolve() {\n * return true\n * }\n * })\n * ```\n */\nexport function createNoopFieldRefCode(opts: { input: boolean }): Printable[] {\n return code`\n t.field({\n type: \"Boolean\",\n ${opts.input ? \"required: false\" : \"nullable: true\"},\n description: \"noop field\",\n ${opts.input ? \"\" : \"resolve: () => true,\"}\n })\n `;\n}\n","import type {\n EnumType,\n EnumTypeValue,\n ObjectField,\n PrinterOptions,\n} from \"@proto-graphql/codegen-core\";\n\nimport { code, joinCode, type Printable } from \"../../../codegen/index.js\";\nimport { protoTypeSymbol } from \"../util.js\";\n\n/**\n * @example nullable\n * ```ts\n * if (!root.myEnum || root.myEnum === _$enums.myEnum.MY_ENUM_UNSPECIFIED) {\n * return null\n * }\n * return root.myEnum\n * ```\n * @example notNull\n * ```ts\n * if (!root.myEnum || root.myEnum === _$enums.myEnum.MY_ENUM_UNSPECIFIED) {\n * throw new Error(\"Message.field is required field. but got null or unspecified.\")\n * }\n * return root.myEnum\n * ```\n */\nexport function createEnumResolverCode(\n valueExpr: Printable[],\n field: ObjectField<EnumType>,\n opts: PrinterOptions,\n): Printable[] {\n const createBlockStmtCodes = (valueExpr: Printable[]): Printable[][] => {\n const chunks: Printable[][] = [];\n\n if (field.type.unspecifiedValue != null) {\n const escapeCode =\n field.isNullable() && !field.isList()\n ? code`return null;`\n : code`throw new Error(\"${field.name} is required field. But got unspecified.\");`;\n chunks.push(code`\n if (${valueExpr} === ${protoTypeSymbol(\n field.type.proto,\n opts,\n )}.${enumValueJsName(field.type, field.type.unspecifiedValue, opts)}) {\n ${escapeCode}\n }\n `);\n }\n for (const ev of field.type.valuesWithIgnored) {\n if (!ev.isIgnored()) continue;\n chunks.push(code`\n if (${valueExpr} === ${protoTypeSymbol(\n field.type.proto,\n opts,\n )}.${enumValueJsName(field.type, ev, opts)}) {\n throw new Error(\"${ev.name} is ignored in GraphQL schema\");\n }\n `);\n }\n\n return chunks;\n };\n\n if (field.isList()) {\n const stmts = createBlockStmtCodes(code`item`);\n if (stmts.length === 0) {\n return code`return ${valueExpr}`;\n }\n return code`return ${valueExpr}.map(item => {\n ${joinCode(stmts)}\n return item;\n })`;\n }\n\n return code`\n ${joinCode(createBlockStmtCodes(valueExpr))}\n return ${valueExpr};\n `;\n}\n\nfunction enumValueJsName(\n _et: EnumType,\n ev: EnumTypeValue,\n opts: PrinterOptions,\n): string {\n switch (opts.protobuf) {\n case \"ts-proto\":\n return ev.proto.name;\n case \"protobuf-es-v1\":\n case \"protobuf-es\":\n return ev.proto.localName;\n }\n}\n","import { code, type Printable } from \"../../../codegen/index.js\";\n\nexport function createNonNullResolverCode(valueExpr: Printable[]): Printable[] {\n return code`\n return ${valueExpr}!;\n `;\n}\n","import {\n ObjectField,\n ObjectOneofField,\n type ObjectType,\n type PrinterOptions,\n type SquashedOneofUnionType,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport { code, joinCode, type Printable } from \"../../../codegen/index.js\";\nimport { protoTypeSymbol } from \"../util.js\";\n\n/**\n * @example nullable\n * ```ts\n * const value = source.v1 ?? source.v2 ?? source.v3;\n * if (value != null) {\n * throw new Error(\"...\");\n * }\n * return value\n * ```\n */\nexport function createOneofUnionResolverCode(\n sourceExpr: Printable[],\n field: ObjectOneofField | ObjectField<SquashedOneofUnionType>,\n opts: PrinterOptions,\n): Printable[] {\n const createBlockStmtCode = (\n sourceExpr: Printable[],\n { nullable, list }: { nullable: boolean; list: boolean },\n ): Printable[] => {\n switch (opts.protobuf) {\n case \"ts-proto\": {\n return createBlockStmtCodeForTsProto(sourceExpr, field, opts, {\n nullable,\n });\n }\n case \"protobuf-es-v1\":\n case \"protobuf-es\": {\n return createBlockStmtCodeForProtobufEs(sourceExpr, field, opts, {\n nullable,\n list,\n });\n }\n }\n };\n\n if (field instanceof ObjectField && field.isList()) {\n return code`\n return ${sourceExpr}.map(item => {\n ${createBlockStmtCode(code`item`, { nullable: false, list: true })}\n })\n `;\n }\n\n return createBlockStmtCode(sourceExpr, {\n nullable: field.isNullable(),\n list: false,\n });\n}\n\nfunction createBlockStmtCodeForTsProto(\n sourceExpr: Printable[],\n field: ObjectOneofField | ObjectField<SquashedOneofUnionType>,\n opts: PrinterOptions,\n { nullable }: { nullable: boolean },\n): Printable[] {\n const createFieldExpr = (memberField: ObjectField<any>): Printable[] => {\n if (field instanceof ObjectOneofField) {\n return code`${sourceExpr}.${tsFieldName(memberField.proto, opts).toString()}`;\n }\n return code`${sourceExpr}?.${tsFieldName(memberField.proto, opts).toString()}`;\n };\n\n return code`\n const value = ${joinCode(field.type.fields.map(createFieldExpr), \" ?? \")};\n if (value == null) {\n ${\n nullable\n ? \"return null\"\n : `throw new Error(\"${field.name} should not be null\")`\n };\n }\n return value;\n `;\n}\n\nfunction createBlockStmtCodeForProtobufEs(\n sourceExpr: Printable[],\n field: ObjectOneofField | ObjectField<SquashedOneofUnionType>,\n opts: PrinterOptions,\n { nullable, list }: { nullable: boolean; list: boolean },\n): Printable[] {\n let valueExpr: Printable[];\n if (field instanceof ObjectOneofField) {\n valueExpr = code`${sourceExpr}.${tsFieldName(field.proto, opts).toString()}.value`;\n } else if (field instanceof ObjectField) {\n valueExpr = code`${sourceExpr}${list ? \"\" : \"?\"}.${tsFieldName(\n field.type.oneofUnionType.proto,\n opts,\n ).toString()}.value`;\n } else {\n field satisfies never;\n throw new Error(\"unreachable\");\n }\n\n // In protobuf-es, accessing .value on a oneof returns a union of all member types.\n // However, some members may be ignored in the GraphQL Union type,\n // so we need to assert to the expected type containing only non-ignored members.\n const memberTypeSymbols = field.type.fields.map((f) =>\n protoTypeSymbol((f.type as ObjectType).proto, opts),\n );\n const typeAssertion =\n memberTypeSymbols.length > 0\n ? code`${joinCode(\n memberTypeSymbols.map((s) => code`${s}`),\n \" | \",\n )} | undefined`\n : code`undefined`;\n\n if (nullable) {\n return code`return (${valueExpr} ?? null) as ${typeAssertion} | null;`;\n }\n return code`\n const value = ${valueExpr} as ${typeAssertion};\n if (value == null) {\n throw new Error(\"${field.name} should not be null\");\n }\n return value;\n `;\n}\n","import type { DescField, Registry } from \"@bufbuild/protobuf\";\nimport {\n InterfaceType,\n type ObjectType,\n protobufGraphQLExtensions,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n joinCode,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport { createFieldRefCode, createNoopFieldRefCode } from \"./field.js\";\nimport {\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n protobufIsMessageSymbol,\n protoRefTypePrintable,\n protoSchemaSymbol,\n protoTypeSymbol,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export const Hello$Ref = builder.objectRef<_$hello$hello_pb.Hello>(\"Hello\")\n * builder.objectType(Hello$Ref, {\n * name: \"Hello\",\n * // ...\n * })\n * ```\n */\nexport function createObjectTypeCode(\n type: ObjectType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const isInterface = type instanceof InterfaceType;\n const typeOpts = {\n name: type.typeName,\n fields: code`t => ({${\n type.fields.length > 0\n ? joinCode(\n type.fields.map(\n (f) => code`${f.name}: ${createFieldRefCode(f, registry, opts)},`,\n ),\n )\n : code`_: ${createNoopFieldRefCode({ input: false })}`\n }})`,\n description: type.description,\n isTypeOf: isInterface\n ? undefined\n : createIsTypeOfFuncCode(type, registry, opts),\n extensions: protobufGraphQLExtensions(type, registry),\n };\n const buildRefFunc = code`${pothosBuilderPrintable(opts)}.${\n isInterface ? \"interface\" : \"object\"\n }Ref`;\n const buildTypeFunc = code`${pothosBuilderPrintable(opts)}.${\n isInterface ? \"interface\" : \"object\"\n }Type`;\n const refFuncTypeArg = isInterface\n ? code`\n Pick<\n ${protoRefTypePrintable(type.proto, opts)},\n ${joinCode(\n type.fields.map((f) =>\n literalOf(tsFieldName(f.proto as DescField, opts)),\n ),\n \"|\",\n )}\n >`\n : protoRefTypePrintable(type.proto, opts);\n\n return code`\n export const ${pothosRefPrintable(\n type,\n )} = ${buildRefFunc}<${refFuncTypeArg}>(${literalOf(type.typeName)});\n ${buildTypeFunc}(${pothosRefPrintable(type)}, ${literalOf(compactForCodegen(typeOpts))});\n `;\n}\n\nfunction createIsTypeOfFuncCode(\n type: ObjectType,\n _registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n switch (opts.protobuf) {\n case \"ts-proto\": {\n return code`\n (source) => {\n return (source as ${protoTypeSymbol(type.proto, opts)} | { $type: string & {} }).$type\n === ${literalOf(type.proto.typeName)};\n }\n `;\n }\n case \"protobuf-es-v1\": {\n return code`\n (source) => {\n return source instanceof ${protoTypeSymbol(type.proto, opts)}\n }\n `;\n }\n case \"protobuf-es\": {\n return code`\n (source) => {\n return ${protobufIsMessageSymbol()}(source, ${protoSchemaSymbol(type.proto, opts)})\n }\n `;\n }\n }\n}\n","import type { Registry } from \"@bufbuild/protobuf\";\nimport {\n type OneofUnionType,\n protobufGraphQLExtensions,\n type SquashedOneofUnionType,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport {\n fieldTypeRefPrintable,\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export cosnt Oneof = builder.unionType(\"Oneof\", {\n * types: [...],\n * // ...\n * })\n * ```\n */\nexport function createOneofUnionTypeCode(\n type: OneofUnionType | SquashedOneofUnionType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const typeOpts = {\n types: type.fields.map((f) => fieldTypeRefPrintable(f, opts)),\n description: type.description,\n extensions: protobufGraphQLExtensions(type, registry),\n };\n return code`\n export const ${pothosRefPrintable(type)} =\n ${pothosBuilderPrintable(opts)}.unionType(${literalOf(\n type.typeName,\n )}, ${literalOf(compactForCodegen(typeOpts))});\n `;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,sBAA0B;;;ACA1B,IAAAC,sBAAuC;AACvC,mCAGO;;;ACFL,cAAW;;;ACFb,yBAAmB;AAEZ,SAASC,WAAWC,OAAY;AACrC,SAAOC,mBAAAA,QAAOC,OAAO,WAAWF,OAAM;IACpCG,WAAW;IACXC,aAAa;IACbC,SAA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C,4CAAuB;EACpDC,MAAM;EACNC,SAAS,IAAIA,OAAAA;EACbC,gBAAYC,gDAAkB;IAC5BC;IACAC,KAAK;EACP,CAAA;EACAC,cAAcC;;EAEdC,WAAW,wBAACC,UAAAA;AACV,WAAOA,MAAMC,IAAI,CAACC,OAAO;MACvB,GAAGA;MACHC,SAASC,WAAWF,EAAEC,OAAO;IAC/B,EAAA;EACF,GALW;AAMb,CAAA;;;IDrBAE,+BAAUC,eAAAA;","names":["import_protoplugin","import_protoplugin","formatCode","code","dprint","format","lineWidth","indentWidth","useTabs","semiColons","quoteStyle","quoteProps","newLineKind","useBraces","bracePosition","singleBodyPosition","nextControlFlowPosition","trailingCommas","operatorPosition","preferHanging","preferSingleLine","import_codegen_core","import_codegen_core","import_codegen_core","PRINTABLE_ARRAY_MARKER","Symbol","for","isPrintableArray","value","Array","isArray","markAsPrintableArray","arr","Object","defineProperty","enumerable","writable","configurable","code","strings","values","result","i","length","push","String","isImportSymbol","value","kind","joinCode","codes","separator","length","result","i","push","undefined","escapeString","str","replace","compactForCodegen","v","Array","isArray","isPrintableArray","map","compactObjForCodegen","obj","key","Object","keys","literalOf","value","markAsPrintableArray","String","elements","isImportSymbol","import_protoplugin","pothosRefName","type","typeName","shapeTypeName","resolveImportOrLocal","field","opts","symbolName","localPrintable","fromFile","filename","parent","toFile","importPath","replace","code","createImportSymbol","fieldTypeRefPrintable","ObjectOneofField","pothosRefPrintable","shapeTypePrintable","fieldTypeShapePrintable","toProtoFuncName","toProtoFuncPrintable","pothosBuilderPrintable","pothos","builderPath","protoTypeSymbol","proto","chunks","name","current","unshift","join","protoImportPath","protoSchemaSymbol","resolveProtobufEsDescName","protobufEsSalt","i","idealShapeName","desc","safeIdentifier","protobufEsIdentifierForNested","pkg","file","package","offset","length","substring","idealDescName","salt","kind","descNameCache","WeakMap","cached","get","undefined","taken","Set","descNames","Map","nestedTypes","has","add","fileName","set","result","Error","toString","protobufCreateSymbol","protobufIsMessageSymbol","protobufMessageShapeSymbol","protoRefTypePrintable","protobuf","t","o","dir","parse","importPrefix","createEnumTypeCode","type","registry","opts","typeOpts","description","values","code","joinCode","filter","v","isIgnored","isUnespecified","map","ev","name","literalOf","compactForCodegen","deprecationReason","value","number","extensions","protobufGraphQLExtensions","protoTypeExpr","protoTypeSymbol","proto","enumRefSymbol","createImportSymbol","refTypeExpr","pothosRefPrintable","pothosBuilderPrintable","typeName","import_codegen_core","import_codegen_core","createEnumResolverCode","valueExpr","field","opts","createBlockStmtCodes","chunks","type","unspecifiedValue","escapeCode","isNullable","isList","code","name","push","protoTypeSymbol","proto","enumValueJsName","ev","valuesWithIgnored","isIgnored","stmts","length","joinCode","_et","protobuf","localName","createNonNullResolverCode","valueExpr","code","import_codegen_core","createOneofUnionResolverCode","sourceExpr","field","opts","createBlockStmtCode","nullable","list","protobuf","createBlockStmtCodeForTsProto","createBlockStmtCodeForProtobufEs","ObjectField","isList","code","isNullable","createFieldExpr","memberField","ObjectOneofField","tsFieldName","proto","toString","joinCode","type","fields","map","name","valueExpr","oneofUnionType","Error","memberTypeSymbols","f","protoTypeSymbol","typeAssertion","length","s","createGetFieldValueCodePrintable","source","proto","opts","code","tsFieldName","createFieldRefCode","field","registry","isInput","InputObjectField","baseType","type","ScalarType","literalOf","typeName","fieldTypeRefPrintable","sourceExpr","resolverCode","ObjectOneofField","createOneofUnionResolverCode","valueExpr","nullableInProto","ObjectType","isPrimitive","isWrapperType","isNullable","createNonNullResolverCode","EnumType","ObjectField","createEnumResolverCode","SquashedOneofUnionType","isBytes","isList","nullableValue","fieldOpts","list","items","description","deprecationReason","resolve","extensions","protobufGraphQLExtensions","shouldUseFieldFunc","compactForCodegen","createNoopFieldRefCode","input","createInputObjectTypeCode","type","registry","opts","fields","filter","f","options","ignoreNonMessageOneofFields","proto","oneof","InputObjectType","shapeTypeCode","code","shapeTypePrintable","joinCode","map","typeNode","fieldTypeShapePrintable","isList","protoTypeSymbol","literalOf","tsFieldName","toString","isNullable","name","ScalarType","isCustomScalar","needsTypeAssertion","protobuf","inputObjectRefType","createImportSymbol","refCode","pothosRefPrintable","pothosBuilderPrintable","typeName","compactForCodegen","length","createFieldRefCode","createNoopFieldRefCode","input","extensions","protobufGraphQLExtensions","description","codes","push","createToProtoFuncCode","oneofFields","protoTypeSym","fieldAssignments","localName","toProtoFunc","toProtoFuncPrintable","EnumType","Error","oneofAssignments","Object","values","oneofName","cases","caseName","protoSchemaSym","protoSchemaSymbol","toProtoFuncName","protobufCreateSymbol","import_codegen_core","createObjectTypeCode","type","registry","opts","isInterface","InterfaceType","typeOpts","name","typeName","fields","code","length","joinCode","map","f","createFieldRefCode","createNoopFieldRefCode","input","description","isTypeOf","undefined","createIsTypeOfFuncCode","extensions","protobufGraphQLExtensions","buildRefFunc","pothosBuilderPrintable","buildTypeFunc","refFuncTypeArg","protoRefTypePrintable","proto","literalOf","tsFieldName","pothosRefPrintable","compactForCodegen","_registry","protobuf","protoTypeSymbol","protobufIsMessageSymbol","protoSchemaSymbol","import_codegen_core","createOneofUnionTypeCode","type","registry","opts","typeOpts","types","fields","map","f","fieldTypeRefPrintable","description","extensions","protobufGraphQLExtensions","code","pothosRefPrintable","pothosBuilderPrintable","literalOf","typeName","compactForCodegen","createTypeDslPrintables","types","registry","opts","flatMap","type","ObjectType","createObjectTypeCode","InputObjectType","createInputObjectTypeCode","EnumType","createEnumTypeCode","OneofUnionType","SquashedOneofUnionType","createOneofUnionTypeCode","_exhaustiveCheck","allowedProtobufs","generateFiles","schema","file","opts","options","includes","printer","protobuf","registry","createRegistryFromSchema","types","collectTypesFromFile","type","allFiles","f","generateFile","filenameFromProtoFile","printables","createTypeDslPrintables","preamble","length","print","p","protocGenPothos","createEcmaScriptPlugin","name","version","generateTs","createTsGenerator","generateFiles","dsl","parseOptions","parsePothosOptions","transpile","files","map","f","content","formatCode","runNodeJs","protocGenPothos"]}
|
|
@@ -9,7 +9,7 @@ import { createEcmaScriptPlugin } from "@bufbuild/protoplugin";
|
|
|
9
9
|
import { createTsGenerator, parsePothosOptions } from "@proto-graphql/protoc-plugin-helpers";
|
|
10
10
|
|
|
11
11
|
// package.json
|
|
12
|
-
var version = "0.7.
|
|
12
|
+
var version = "0.7.1";
|
|
13
13
|
|
|
14
14
|
// src/codegen/stringify.ts
|
|
15
15
|
import dprint from "dprint-node";
|
|
@@ -221,6 +221,8 @@ __name(literalOf, "literalOf");
|
|
|
221
221
|
|
|
222
222
|
// src/dslgen/printers/util.ts
|
|
223
223
|
import * as path from "path";
|
|
224
|
+
import { nestedTypes } from "@bufbuild/protobuf/reflect";
|
|
225
|
+
import { safeIdentifier } from "@bufbuild/protoplugin";
|
|
224
226
|
import { filename, ObjectOneofField } from "@proto-graphql/codegen-core";
|
|
225
227
|
function pothosRefName(type) {
|
|
226
228
|
return `${type.typeName}$Ref`;
|
|
@@ -282,19 +284,85 @@ function protoTypeSymbol(proto, opts) {
|
|
|
282
284
|
}
|
|
283
285
|
__name(protoTypeSymbol, "protoTypeSymbol");
|
|
284
286
|
function protoSchemaSymbol(proto, opts) {
|
|
285
|
-
const
|
|
286
|
-
proto.name
|
|
287
|
-
];
|
|
288
|
-
let current = proto;
|
|
289
|
-
while (current.parent != null) {
|
|
290
|
-
current = current.parent;
|
|
291
|
-
chunks.unshift(current.name);
|
|
292
|
-
}
|
|
293
|
-
const symbolName = `${chunks.join("_")}Schema`;
|
|
287
|
+
const symbolName = resolveProtobufEsDescName(proto);
|
|
294
288
|
const importPath = protoImportPath(proto, opts);
|
|
295
289
|
return createImportSymbol(symbolName, importPath);
|
|
296
290
|
}
|
|
297
291
|
__name(protoSchemaSymbol, "protoSchemaSymbol");
|
|
292
|
+
function protobufEsSalt(i) {
|
|
293
|
+
if (i === 0) return "";
|
|
294
|
+
if (i === 1) return "$";
|
|
295
|
+
return `$${i - 1}`;
|
|
296
|
+
}
|
|
297
|
+
__name(protobufEsSalt, "protobufEsSalt");
|
|
298
|
+
function idealShapeName(desc, i) {
|
|
299
|
+
return safeIdentifier(protobufEsIdentifierForNested(desc) + protobufEsSalt(i));
|
|
300
|
+
}
|
|
301
|
+
__name(idealShapeName, "idealShapeName");
|
|
302
|
+
function protobufEsIdentifierForNested(desc) {
|
|
303
|
+
const pkg = desc.file.proto.package;
|
|
304
|
+
const offset = pkg.length > 0 ? pkg.length + 1 : 0;
|
|
305
|
+
return desc.typeName.substring(offset).replace(/\./g, "_");
|
|
306
|
+
}
|
|
307
|
+
__name(protobufEsIdentifierForNested, "protobufEsIdentifierForNested");
|
|
308
|
+
function idealDescName(desc, i) {
|
|
309
|
+
const salt = protobufEsSalt(i);
|
|
310
|
+
if (desc.kind === "file") {
|
|
311
|
+
const name = `file_${desc.name.replace(/[^a-zA-Z0-9_]+/g, "_")}`;
|
|
312
|
+
return safeIdentifier(name + salt);
|
|
313
|
+
}
|
|
314
|
+
if (desc.kind === "enum" || desc.kind === "message") {
|
|
315
|
+
return safeIdentifier(protobufEsIdentifierForNested(desc) + "Schema" + salt);
|
|
316
|
+
}
|
|
317
|
+
return safeIdentifier(protobufEsIdentifierForNested(desc) + salt);
|
|
318
|
+
}
|
|
319
|
+
__name(idealDescName, "idealDescName");
|
|
320
|
+
var descNameCache = /* @__PURE__ */ new WeakMap();
|
|
321
|
+
function resolveProtobufEsDescName(proto) {
|
|
322
|
+
const file = proto.file;
|
|
323
|
+
const cached = descNameCache.get(file);
|
|
324
|
+
if (cached) {
|
|
325
|
+
const name = cached.get(proto);
|
|
326
|
+
if (name !== void 0) return name;
|
|
327
|
+
}
|
|
328
|
+
const taken = /* @__PURE__ */ new Set();
|
|
329
|
+
const descNames = /* @__PURE__ */ new Map();
|
|
330
|
+
for (const desc of nestedTypes(file)) {
|
|
331
|
+
if (desc.kind !== "enum" && desc.kind !== "message") continue;
|
|
332
|
+
let name;
|
|
333
|
+
for (let i = 0; ; i++) {
|
|
334
|
+
name = idealShapeName(desc, i);
|
|
335
|
+
if (!taken.has(name)) break;
|
|
336
|
+
}
|
|
337
|
+
taken.add(name);
|
|
338
|
+
}
|
|
339
|
+
{
|
|
340
|
+
let fileName;
|
|
341
|
+
for (let i = 0; ; i++) {
|
|
342
|
+
fileName = idealDescName(file, i);
|
|
343
|
+
if (!taken.has(fileName)) break;
|
|
344
|
+
}
|
|
345
|
+
taken.add(fileName);
|
|
346
|
+
}
|
|
347
|
+
for (const desc of nestedTypes(file)) {
|
|
348
|
+
let name;
|
|
349
|
+
for (let i = 0; ; i++) {
|
|
350
|
+
name = idealDescName(desc, i);
|
|
351
|
+
if (!taken.has(name)) break;
|
|
352
|
+
}
|
|
353
|
+
taken.add(name);
|
|
354
|
+
if (desc.kind === "message" || desc.kind === "enum") {
|
|
355
|
+
descNames.set(desc, name);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
descNameCache.set(file, descNames);
|
|
359
|
+
const result = descNames.get(proto);
|
|
360
|
+
if (result === void 0) {
|
|
361
|
+
throw new Error(`Unable to determine protobuf-es desc name for ${proto.toString()}`);
|
|
362
|
+
}
|
|
363
|
+
return result;
|
|
364
|
+
}
|
|
365
|
+
__name(resolveProtobufEsDescName, "resolveProtobufEsDescName");
|
|
298
366
|
function protobufCreateSymbol() {
|
|
299
367
|
return createImportSymbol("create", "@bufbuild/protobuf");
|
|
300
368
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/protoc-gen-pothos.ts","../src/plugin.ts","../package.json","../src/codegen/stringify.ts","../src/printer.ts","../src/dslgen/printers/index.ts","../src/dslgen/printers/enumType.ts","../src/codegen/code-builder.ts","../src/codegen/types.ts","../src/codegen/helpers.ts","../src/dslgen/printers/util.ts","../src/dslgen/printers/inputObjectType.ts","../src/dslgen/printers/field.ts","../src/dslgen/printers/fieldResolver/enumFieldResolver.ts","../src/dslgen/printers/fieldResolver/nonNullResolver.ts","../src/dslgen/printers/fieldResolver/oneofUnionResolver.ts","../src/dslgen/printers/objectType.ts","../src/dslgen/printers/oneofUnionType.ts"],"sourcesContent":["import { runNodeJs } from \"@bufbuild/protoplugin\";\n\nimport { protocGenPothos } from \"./plugin.js\";\n\nrunNodeJs(protocGenPothos);\n","import { createEcmaScriptPlugin } from \"@bufbuild/protoplugin\";\nimport {\n createTsGenerator,\n parsePothosOptions,\n} from \"@proto-graphql/protoc-plugin-helpers\";\n\nimport { version } from \"../package.json\";\nimport { formatCode } from \"./codegen/stringify.js\";\nimport { generateFiles } from \"./printer.js\";\n\nexport const protocGenPothos = createEcmaScriptPlugin({\n name: \"protoc-gen-pothos\",\n version: `v${version}`,\n generateTs: createTsGenerator({\n generateFiles,\n dsl: \"pothos\",\n }),\n parseOptions: parsePothosOptions,\n // NOTE: force `target=ts` and apply formatting\n transpile: (files) => {\n return files.map((f) => ({\n ...f,\n content: formatCode(f.content),\n }));\n },\n});\n","{\n \"name\": \"protoc-gen-pothos\",\n \"version\": \"0.7.0\",\n \"description\": \"Generate DSL for Pothos GraphQL from Protocol Buffers IDL\",\n \"keywords\": [\n \"graphql\",\n \"grpc\",\n \"pothos\",\n \"protobuf\",\n \"typescript\"\n ],\n \"bin\": {\n \"protoc-gen-pothos\": \"./bin/protoc-gen-pothos.cjs\"\n },\n \"repository\": \"git@github.com:proto-graphql/proto-graphql-js.git\",\n \"author\": \"izumin5210 <m@izum.in>\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.cjs\"\n }\n }\n },\n \"files\": [\n \"bin/\",\n \"docs/\",\n \"!docs/development/**\",\n \"src/\",\n \"dist/\",\n \"!src/**/*.test.ts\",\n \"!src/**/__tests__/\"\n ],\n \"sideEffects\": false,\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">= 14.0.0\"\n },\n \"dependencies\": {\n \"@bufbuild/protobuf\": \"catalog:\",\n \"@bufbuild/protoplugin\": \"catalog:\",\n \"@proto-graphql/codegen-core\": \"workspace:*\",\n \"@proto-graphql/protoc-plugin-helpers\": \"workspace:*\",\n \"dprint-node\": \"catalog:\"\n },\n \"devDependencies\": {\n \"@pothos/core\": \"catalog:test\",\n \"@proto-graphql/e2e-testapis-protobuf-es\": \"workspace:*\",\n \"@proto-graphql/e2e-testapis-protobuf-es-v2\": \"workspace:*\",\n \"@proto-graphql/e2e-testapis-ts-proto\": \"workspace:*\",\n \"@proto-graphql/e2e-testapis-ts-proto-with-forcelong-number\": \"workspace:*\",\n \"@proto-graphql/testapis-proto\": \"workspace:*\",\n \"@proto-graphql/tsconfig\": \"workspace:*\",\n \"@vitest/coverage-v8\": \"^4.0.0\",\n \"graphql\": \"catalog:test\",\n \"graphql-scalars\": \"^1.24.0\",\n \"tsx\": \"^4.21.0\"\n },\n \"scripts\": {\n \"build\": \"tsup && cp -r ../../docs/protoc-gen-pothos docs\",\n \"clean\": \"rm -rf dist docs\",\n \"test\": \"vitest run --passWithNoTests\",\n \"test:coverage\": \"vitest run --coverage\"\n }\n}\n","import dprint from \"dprint-node\";\n\nexport function formatCode(code: string): string {\n return dprint.format(\"file.ts\", code, {\n lineWidth: 80,\n indentWidth: 2,\n useTabs: false,\n semiColons: \"always\",\n quoteStyle: \"alwaysDouble\",\n quoteProps: \"asNeeded\",\n newLineKind: \"lf\",\n useBraces: \"whenNotSingleLine\",\n bracePosition: \"sameLineUnlessHanging\",\n singleBodyPosition: \"maintain\",\n nextControlFlowPosition: \"sameLine\",\n trailingCommas: \"onlyMultiLine\",\n operatorPosition: \"nextLine\",\n preferHanging: false,\n preferSingleLine: true,\n \"arrowFunction.useParentheses\": \"force\",\n });\n}\n","import type { DescFile } from \"@bufbuild/protobuf\";\nimport type { Schema } from \"@bufbuild/protoplugin\";\nimport {\n collectTypesFromFile,\n createRegistryFromSchema,\n filenameFromProtoFile,\n} from \"@proto-graphql/codegen-core\";\nimport type { Options } from \"@proto-graphql/protoc-plugin-helpers\";\n\nimport { createTypeDslPrintables } from \"./dslgen/index.js\";\n\nconst allowedProtobufs = [\"ts-proto\", \"protobuf-es-v1\", \"protobuf-es\"];\n\nexport function generateFiles(\n schema: Schema<Options<\"pothos\">>,\n file: DescFile,\n): void {\n const opts = schema.options;\n\n if (!allowedProtobufs.includes(opts.printer.protobuf)) {\n opts.printer.protobuf = \"ts-proto\"; // default\n }\n\n const registry = createRegistryFromSchema(schema);\n const types = collectTypesFromFile(file, opts.type, schema.allFiles);\n\n const f = schema.generateFile(filenameFromProtoFile(file, opts.printer));\n const printables = [\n ...createTypeDslPrintables(types, registry, opts.printer),\n ];\n\n // ヘッダー出力(preamble プロパティに格納される)\n f.preamble(file);\n\n if (printables.length === 0) {\n f.print(\"export {};\");\n return;\n }\n\n // 各型の Printable を直接出力\n for (const p of printables) {\n f.print(...p);\n f.print(); // 空行で区切り\n }\n}\n","import type { createRegistry } from \"@bufbuild/protobuf\";\nimport {\n EnumType,\n InputObjectType,\n ObjectType,\n OneofUnionType,\n SquashedOneofUnionType,\n} from \"@proto-graphql/codegen-core\";\n\nimport type { Printable } from \"../../codegen/index.js\";\nimport { createEnumTypeCode } from \"./enumType.js\";\nimport { createInputObjectTypeCode } from \"./inputObjectType.js\";\nimport { createObjectTypeCode } from \"./objectType.js\";\nimport { createOneofUnionTypeCode } from \"./oneofUnionType.js\";\nimport type { PothosPrinterOptions } from \"./util.js\";\n\nexport function createTypeDslPrintables(\n types: (\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n )[],\n registry: ReturnType<typeof createRegistry>,\n opts: PothosPrinterOptions,\n): Printable[][] {\n return types.flatMap((type) => {\n if (type instanceof ObjectType) {\n return [createObjectTypeCode(type, registry, opts)];\n }\n if (type instanceof InputObjectType) {\n return [createInputObjectTypeCode(type, registry, opts)];\n }\n if (type instanceof EnumType) {\n return [createEnumTypeCode(type, registry, opts)];\n }\n if (\n type instanceof OneofUnionType ||\n type instanceof SquashedOneofUnionType\n ) {\n return [createOneofUnionTypeCode(type, registry, opts)];\n }\n\n const _exhaustiveCheck: never = type;\n throw \"unreachable\";\n });\n}\n","import type { Registry } from \"@bufbuild/protobuf\";\nimport {\n type EnumType,\n protobufGraphQLExtensions,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n createImportSymbol,\n joinCode,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport {\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n protoTypeSymbol,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export cosnt Hello$Ref: EnumRef<Hello, Hello> = builder.enumType(\"Hello\", {\n * values: [\n * // ...\n * ],\n * // ...\n * })\n * ```\n */\nexport function createEnumTypeCode(\n type: EnumType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const typeOpts = {\n description: type.description,\n values: code`{${joinCode(\n type.values\n .filter((v) => !v.isIgnored() && !v.isUnespecified())\n .map(\n (ev) =>\n code`${ev.name}: ${literalOf(\n compactForCodegen({\n description: ev.description,\n deprecationReason: ev.deprecationReason,\n value: ev.number,\n extensions: protobufGraphQLExtensions(ev, registry),\n }),\n )},`,\n ),\n )}} as const`,\n extensions: protobufGraphQLExtensions(type, registry),\n };\n\n const protoTypeExpr = protoTypeSymbol(type.proto, opts);\n const enumRefSymbol = createImportSymbol(\"EnumRef\", \"@pothos/core\");\n // EnumRef<Hello, Hello>\n const refTypeExpr = code`${enumRefSymbol}<${protoTypeExpr}, ${protoTypeExpr}>`;\n\n return code`\n export const ${pothosRefPrintable(type)}: ${refTypeExpr} =\n ${pothosBuilderPrintable(opts)}.enumType(${literalOf(\n type.typeName,\n )}, ${literalOf(compactForCodegen(typeOpts))});\n `;\n}\n","import type { ImportSymbol, Printable } from \"./types.js\";\n\nexport const PRINTABLE_ARRAY_MARKER = Symbol.for(\n \"proto-graphql:printable-array\",\n);\n\nexport type PrintableArray = Printable[] & { [PRINTABLE_ARRAY_MARKER]: true };\n\nexport function isPrintableArray(value: unknown): value is PrintableArray {\n return Array.isArray(value) && PRINTABLE_ARRAY_MARKER in value;\n}\n\nexport function markAsPrintableArray(arr: Printable[]): PrintableArray {\n Object.defineProperty(arr, PRINTABLE_ARRAY_MARKER, {\n value: true,\n enumerable: false,\n writable: false,\n configurable: false,\n });\n return arr as PrintableArray;\n}\n\ntype CodeValue =\n | string\n | number\n | ImportSymbol\n | Printable[]\n | null\n | undefined;\n\nexport function code(\n strings: TemplateStringsArray,\n ...values: CodeValue[]\n): PrintableArray {\n const result: Printable[] = [];\n\n for (let i = 0; i < strings.length; i++) {\n if (strings[i] !== \"\") {\n result.push(strings[i]);\n }\n\n if (i < values.length) {\n const value = values[i];\n if (value == null) {\n result.push(String(value));\n } else if (typeof value === \"string\") {\n if (value !== \"\") {\n result.push(value);\n }\n } else if (typeof value === \"number\") {\n result.push(String(value));\n } else if (Array.isArray(value)) {\n result.push(...value);\n } else {\n result.push(value as Printable);\n }\n }\n }\n\n if (result.length === 0) {\n result.push(\"\");\n }\n\n return markAsPrintableArray(result);\n}\n","export type {\n ImportSymbol,\n Printable,\n} from \"@bufbuild/protoplugin\";\n\nexport { createImportSymbol } from \"@bufbuild/protoplugin\";\n\nimport type { ImportSymbol } from \"@bufbuild/protoplugin\";\n\nexport function isImportSymbol(value: unknown): value is ImportSymbol {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"kind\" in value &&\n (value as Record<string, unknown>).kind === \"es_symbol\"\n );\n}\n","import {\n isPrintableArray,\n markAsPrintableArray,\n type PrintableArray,\n} from \"./code-builder.js\";\nimport type { Printable } from \"./types.js\";\nimport { isImportSymbol } from \"./types.js\";\n\nexport function joinCode(\n codes: Printable[][],\n separator?: string,\n): Printable[] {\n if (codes.length === 0) {\n return [];\n }\n\n const result: Printable[] = [];\n for (let i = 0; i < codes.length; i++) {\n result.push(...codes[i]);\n if (separator !== undefined && i < codes.length - 1) {\n result.push(separator);\n }\n }\n return result;\n}\n\nfunction escapeString(str: string): string {\n return str\n .replace(/\\\\/g, \"\\\\\\\\\")\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, \"\\\\n\")\n .replace(/\\r/g, \"\\\\r\")\n .replace(/\\t/g, \"\\\\t\");\n}\n\n/**\n * Remove nullish values recursively, preserving PrintableArrays.\n * This is a variant of compact() from codegen-core that doesn't lose the PrintableArray marker.\n */\nexport function compactForCodegen(v: unknown): unknown {\n if (typeof v !== \"object\") return v;\n if (v == null) return v;\n if (Array.isArray(v)) {\n if (isPrintableArray(v)) {\n return v;\n }\n return v.map(compactForCodegen);\n }\n return compactObjForCodegen(v as Record<string, unknown>);\n}\n\nfunction compactObjForCodegen(\n obj: Record<string, unknown>,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(obj)) {\n const v = obj[key];\n if (v != null) {\n result[key] = compactForCodegen(v);\n }\n }\n return result;\n}\n\nexport function literalOf(value: unknown): PrintableArray {\n if (value === null) {\n return markAsPrintableArray([\"null\"]);\n }\n\n if (value === undefined) {\n return markAsPrintableArray([\"undefined\"]);\n }\n\n if (typeof value === \"string\") {\n return markAsPrintableArray([`\"${escapeString(value)}\"`]);\n }\n\n if (typeof value === \"number\") {\n return markAsPrintableArray([String(value)]);\n }\n\n if (typeof value === \"boolean\") {\n return markAsPrintableArray([String(value)]);\n }\n\n if (Array.isArray(value)) {\n if (isPrintableArray(value)) {\n return value;\n }\n\n if (value.length === 0) {\n return markAsPrintableArray([\"[]\"]);\n }\n\n const elements: Printable[] = [\"[\"];\n for (let i = 0; i < value.length; i++) {\n if (i > 0) {\n elements.push(\", \");\n }\n elements.push(...literalOf(value[i]));\n }\n elements.push(\"]\");\n return markAsPrintableArray(elements);\n }\n\n if (typeof value === \"object\") {\n // ImportSymbol should be returned as-is (wrapped in PrintableArray)\n if (isImportSymbol(value)) {\n return markAsPrintableArray([value]);\n }\n\n const obj = value as Record<string, unknown>;\n const keys = Object.keys(obj);\n\n if (keys.length === 0) {\n return markAsPrintableArray([\"{}\"]);\n }\n\n const elements: Printable[] = [\"{ \"];\n for (let i = 0; i < keys.length; i++) {\n if (i > 0) {\n elements.push(\", \");\n }\n const key = keys[i];\n // Always quote keys to match ts-poet literalOf behavior\n elements.push(`\"${escapeString(key)}\": `);\n elements.push(...literalOf(obj[key]));\n }\n elements.push(\" }\");\n return markAsPrintableArray(elements);\n }\n\n return markAsPrintableArray([String(value)]);\n}\n","import * as path from \"node:path\";\n\nimport type { DescEnum, DescMessage } from \"@bufbuild/protobuf\";\nimport {\n type EnumType,\n filename,\n type InputObjectField,\n type InputObjectType,\n type InterfaceType,\n type ObjectField,\n ObjectOneofField,\n type ObjectType,\n type OneofUnionType,\n type PrinterOptions,\n type SquashedOneofUnionType,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n createImportSymbol,\n type ImportSymbol,\n type Printable,\n} from \"../../codegen/index.js\";\n\nexport type PothosPrinterOptions = Extract<PrinterOptions, { dsl: \"pothos\" }>;\n\nexport function pothosRefName(\n type:\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n | InterfaceType,\n): string {\n return `${type.typeName}$Ref`;\n}\n\nexport function shapeTypeName(type: InputObjectType): string {\n return `${type.typeName}$Shape`;\n}\n\ntype TypeWithFilename =\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n | InterfaceType;\n\nfunction resolveImportOrLocal(\n field: { parent: TypeWithFilename; type: TypeWithFilename },\n opts: PothosPrinterOptions,\n symbolName: string,\n localPrintable: () => Printable[],\n): Printable[] {\n const fromFile = filename(field.parent, opts);\n const toFile = filename(field.type, opts);\n if (fromFile === toFile) return localPrintable();\n\n const importPath = `./${toFile.replace(/\\.ts$/, \"\")}`;\n return code`${createImportSymbol(symbolName, importPath)}`;\n}\n\nexport function fieldTypeRefPrintable(\n field:\n | ObjectField<\n ObjectType | EnumType | InterfaceType | SquashedOneofUnionType\n >\n | InputObjectField<InputObjectType | EnumType>\n | ObjectOneofField,\n opts: PothosPrinterOptions,\n): Printable[] {\n if (field instanceof ObjectOneofField) return pothosRefPrintable(field.type);\n\n return resolveImportOrLocal(field, opts, pothosRefName(field.type), () =>\n pothosRefPrintable(field.type),\n );\n}\n\nexport function shapeTypePrintable(type: InputObjectType): Printable[] {\n return code`${shapeTypeName(type)}`;\n}\n\nexport function fieldTypeShapePrintable(\n field: InputObjectField<InputObjectType>,\n opts: PothosPrinterOptions,\n): Printable[] {\n return resolveImportOrLocal(field, opts, shapeTypeName(field.type), () =>\n shapeTypePrintable(field.type),\n );\n}\n\nexport function toProtoFuncName(type: InputObjectType): string {\n return `${type.typeName}$toProto`;\n}\n\nexport function toProtoFuncPrintable(\n field: InputObjectField<InputObjectType>,\n opts: PothosPrinterOptions,\n): Printable[] {\n return resolveImportOrLocal(\n field,\n opts,\n toProtoFuncName(field.type),\n () => code`${toProtoFuncName(field.type)}`,\n );\n}\n\nexport function pothosRefPrintable(\n type:\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n | InterfaceType,\n): Printable[] {\n return code`${pothosRefName(type)}`;\n}\n\nexport function pothosBuilderPrintable(\n opts: Pick<PothosPrinterOptions, \"pothos\">,\n): Printable[] {\n // protoplugin が自動的に相対パスを計算するため、builderPath をそのまま使用\n return code`${createImportSymbol(\"builder\", opts.pothos.builderPath)}`;\n}\n\nexport function protoTypeSymbol(\n proto: DescMessage | DescEnum,\n opts: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): ImportSymbol {\n const chunks = [proto.name];\n let current: DescMessage | DescEnum = proto;\n while (current.parent != null) {\n current = current.parent;\n chunks.unshift(current.name);\n }\n const symbolName = chunks.join(\"_\");\n const importPath = protoImportPath(proto, opts);\n return createImportSymbol(symbolName, importPath);\n}\n\n/**\n * protobuf-es v2 用: Schema シンボル (例: UserSchema, Parent_ChildSchema) を生成\n */\nexport function protoSchemaSymbol(\n proto: DescMessage | DescEnum,\n opts: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): ImportSymbol {\n const chunks = [proto.name];\n let current: DescMessage | DescEnum = proto;\n while (current.parent != null) {\n current = current.parent;\n chunks.unshift(current.name);\n }\n const symbolName = `${chunks.join(\"_\")}Schema`;\n const importPath = protoImportPath(proto, opts);\n return createImportSymbol(symbolName, importPath);\n}\n\n/**\n * @bufbuild/protobuf から create 関数を import\n */\nexport function protobufCreateSymbol(): ImportSymbol {\n return createImportSymbol(\"create\", \"@bufbuild/protobuf\");\n}\n\n/**\n * @bufbuild/protobuf から isMessage 関数を import\n */\nexport function protobufIsMessageSymbol(): ImportSymbol {\n return createImportSymbol(\"isMessage\", \"@bufbuild/protobuf\");\n}\n\n/**\n * @bufbuild/protobuf から MessageShape 型を import\n */\nexport function protobufMessageShapeSymbol(): ImportSymbol {\n return createImportSymbol(\"MessageShape\", \"@bufbuild/protobuf\");\n}\n\n/**\n * v2 用: ObjectRef の型パラメータとして使用する型を生成\n * - protobuf-es v2: MessageShape<typeof XxxSchema>\n * - protobuf-es v1: Xxx (クラス)\n * - ts-proto: Xxx (interface)\n */\nexport function protoRefTypePrintable(\n proto: DescMessage,\n opts: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): Printable[] {\n switch (opts.protobuf) {\n case \"ts-proto\":\n case \"protobuf-es-v1\": {\n return code`${protoTypeSymbol(proto, opts)}`;\n }\n case \"protobuf-es\": {\n return code`${protobufMessageShapeSymbol()}<typeof ${protoSchemaSymbol(proto, opts)}>`;\n }\n }\n}\n\nfunction protoImportPath(\n t: DescMessage | DescEnum,\n o: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): string {\n let importPath: string;\n switch (o.protobuf) {\n case \"ts-proto\": {\n importPath = t.file.name;\n break;\n }\n case \"protobuf-es-v1\":\n case \"protobuf-es\": {\n const { dir, name } = path.parse(t.file.name);\n importPath = `${dir}/${name}_pb`;\n break;\n }\n default: {\n o.protobuf satisfies never;\n throw new Error(`unexpected protobuf option: ${o.protobuf}`);\n }\n }\n return `${o.importPrefix ? `${o.importPrefix}/` : \"./\"}${importPath}`.replace(\n /(?<!:)\\/\\//,\n \"/\",\n );\n}\n","import type { Registry } from \"@bufbuild/protobuf\";\nimport {\n EnumType,\n type InputObjectField,\n InputObjectType,\n protobufGraphQLExtensions,\n ScalarType,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n createImportSymbol,\n joinCode,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport { createFieldRefCode, createNoopFieldRefCode } from \"./field.js\";\nimport {\n fieldTypeShapePrintable,\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n protobufCreateSymbol,\n protoSchemaSymbol,\n protoTypeSymbol,\n shapeTypePrintable,\n toProtoFuncName,\n toProtoFuncPrintable,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export type HelloInput$Shape = {\n * // ...\n * }\n * export const HelloInput$Ref: pothos.InputObjectRef<Hello$SHape> = builder.inputRef(\"HelloInput\").implement({\n * description: \"...\",\n * fields: (t) => ({\n * // ...\n * }),\n * })\n *\n * export function HelloInput$toProto () {\n * return {\n * // ...\n * }\n * }\n *\n * ```\n */\nexport function createInputObjectTypeCode(\n type: InputObjectType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const fields = type.fields.filter(\n (f) =>\n !(\n type.options.ignoreNonMessageOneofFields &&\n f.proto.oneof != null &&\n !(f.type instanceof InputObjectType)\n ),\n );\n\n const shapeTypeCode = code`\n export type ${shapeTypePrintable(type)} = {\n ${joinCode(\n fields.map((f) => {\n let typeNode: Printable[];\n if (f.type instanceof InputObjectType) {\n typeNode = fieldTypeShapePrintable(\n f as InputObjectField<InputObjectType>,\n opts,\n );\n if (f.isList()) typeNode = code`Array<${typeNode}>`;\n } else {\n typeNode = code`${protoTypeSymbol(type.proto, opts)}[${literalOf(\n tsFieldName(f.proto, opts).toString(),\n )}]`;\n }\n return f.isNullable()\n ? code`${f.name}?: ${typeNode} | null,`\n : code`${f.name}: ${\n f.type instanceof ScalarType && f.type.isCustomScalar()\n ? code`NonNullable<${typeNode}>`\n : typeNode\n },`;\n }),\n )}\n };\n `;\n\n // In protobuf-es v2, Message types have internal properties like $unknown and $typeName,\n // which can cause type mismatches between Pothos's inferred types and the InputShape type.\n // To work around this, we use a type assertion for protobuf-es v2.\n const needsTypeAssertion = opts.protobuf === \"protobuf-es\";\n const inputObjectRefType = code`${createImportSymbol(\n \"InputObjectRef\",\n \"@pothos/core\",\n )}<${shapeTypePrintable(type)}>`;\n\n const refCode = code`\n export const ${pothosRefPrintable(type)}: ${inputObjectRefType} =\n ${pothosBuilderPrintable(opts)}.inputRef<${shapeTypePrintable(\n type,\n )}>(${literalOf(type.typeName)}).implement(\n ${literalOf(\n compactForCodegen({\n fields: code`t => ({${\n fields.length > 0\n ? joinCode(\n fields.map(\n (f) =>\n code`${f.name}: ${createFieldRefCode(\n f,\n registry,\n opts,\n )}`,\n ),\n \", \",\n )\n : code`_: ${createNoopFieldRefCode({ input: true })}`\n }})`,\n extensions: protobufGraphQLExtensions(type, registry),\n description: type.description,\n }),\n )}\n )${needsTypeAssertion ? code` as ${inputObjectRefType}` : \"\"};\n `;\n\n const codes: Printable[][] = [shapeTypeCode, refCode];\n\n if (opts.protobuf === \"protobuf-es-v1\" || opts.protobuf === \"protobuf-es\") {\n codes.push(createToProtoFuncCode(type, fields, opts));\n }\n\n return joinCode(codes, \"\\n\\n\");\n}\n\nfunction createToProtoFuncCode(\n type: InputObjectType,\n fields: InputObjectField<ScalarType | EnumType | InputObjectType>[],\n opts: PothosPrinterOptions,\n): Printable[] {\n const oneofFields: Record<string, InputObjectField<InputObjectType>[]> = {};\n for (const f of fields) {\n if (f.proto.oneof == null) continue;\n if (!(f.type instanceof InputObjectType)) {\n // Non-message oneof members are ignored in toProto generation.\n // The strict validation path is handled in type construction.\n continue;\n }\n\n oneofFields[f.proto.oneof.name] = [\n ...(oneofFields[f.proto.oneof.name] || []),\n f as InputObjectField<InputObjectType>,\n ];\n }\n\n const protoTypeSym = protoTypeSymbol(type.proto, opts);\n\n const fieldAssignments = joinCode(\n fields\n .filter((f) => f.proto.oneof == null)\n .map((f) => {\n const localName = tsFieldName(f.proto, opts).toString();\n if (f.type instanceof InputObjectType) {\n const toProtoFunc = toProtoFuncPrintable(\n f as InputObjectField<InputObjectType>,\n opts,\n );\n if (f.isList()) {\n return code`${localName}: input?.${f.name}?.map(v => ${toProtoFunc}(v)),`;\n }\n return code`${localName}: input?.${f.name} ? ${toProtoFunc}(input.${f.name}) : undefined,`;\n }\n if (f.type instanceof ScalarType || f.type instanceof EnumType) {\n return code`${localName}: input?.${f.name} ?? undefined,`;\n }\n f.type satisfies never;\n throw new Error(\"unreachable\");\n }),\n \"\\n\",\n );\n\n const oneofAssignments = joinCode(\n Object.values(oneofFields).map((fields) => {\n const oneofName = tsFieldName(\n // biome-ignore lint/style/noNonNullAssertion: we know it's not null\n fields[0]!.proto.oneof!,\n opts,\n ).toString();\n const cases = fields.map((f) => {\n const caseName = tsFieldName(f.proto, opts).toString();\n return code`input?.${f.name} ? { case: \"${caseName}\", value: ${toProtoFuncPrintable(f, opts)}(input.${f.name}) } :`;\n });\n return code`${oneofName}: ${joinCode(cases, \" \")} undefined,`;\n }),\n \"\\n\",\n );\n\n if (opts.protobuf === \"protobuf-es\") {\n const protoSchemaSym = protoSchemaSymbol(type.proto, opts);\n return code`\n export function ${toProtoFuncName(type)} (input: ${shapeTypePrintable(\n type,\n )} | null | undefined): ${protoTypeSym} {\n return ${protobufCreateSymbol()}(${protoSchemaSym}, {\n ${fieldAssignments}\n ${oneofAssignments}\n });\n }\n `;\n }\n\n return code`\n export function ${toProtoFuncName(type)} (input: ${shapeTypePrintable(\n type,\n )} | null | undefined): ${protoTypeSym} {\n return new ${protoTypeSym}({\n ${fieldAssignments}\n ${oneofAssignments}\n });\n }\n `;\n}\n","import type { createRegistry, DescField } from \"@bufbuild/protobuf\";\nimport {\n EnumType,\n InputObjectField,\n ObjectField,\n ObjectOneofField,\n ObjectType,\n protobufGraphQLExtensions,\n ScalarType,\n SquashedOneofUnionType,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport { createEnumResolverCode } from \"./fieldResolver/enumFieldResolver.js\";\nimport { createNonNullResolverCode } from \"./fieldResolver/nonNullResolver.js\";\nimport { createOneofUnionResolverCode } from \"./fieldResolver/oneofUnionResolver.js\";\nimport { fieldTypeRefPrintable, type PothosPrinterOptions } from \"./util.js\";\n\nfunction createGetFieldValueCodePrintable(\n source: string,\n proto: DescField,\n opts: PothosPrinterOptions,\n): Printable[] {\n return code`${source}.${tsFieldName(proto, opts)}`;\n}\n\n/**\n * @example\n * ```ts\n * t.expose(\"name\", {\n * type: \"Boolean\",\n * nullable: true,\n * description: \"...\",\n * })\n * ```\n * ```ts\n * t.field({\n * type: \"Boolean\",\n * nullable: true,\n * description: \"...\",\n * resolve() {\n * return true\n * }\n * })\n * ```\n */\nexport function createFieldRefCode(\n field: ObjectField<any> | ObjectOneofField | InputObjectField<any>,\n registry: ReturnType<typeof createRegistry>,\n opts: PothosPrinterOptions,\n): Printable[] {\n const isInput = field instanceof InputObjectField;\n const baseType =\n field.type instanceof ScalarType\n ? literalOf(field.type.typeName)\n : fieldTypeRefPrintable(field, opts);\n\n const sourceExpr = \"source\";\n let resolverCode: Printable[] | undefined;\n if (!isInput) {\n if (field instanceof ObjectOneofField) {\n resolverCode = createOneofUnionResolverCode(\n code`${sourceExpr}`,\n field,\n opts,\n );\n } else {\n const valueExpr = createGetFieldValueCodePrintable(\n sourceExpr,\n field.proto,\n opts,\n );\n const nullableInProto =\n field.type instanceof ObjectType ||\n (field.type instanceof ScalarType &&\n !field.type.isPrimitive() &&\n !field.type.isWrapperType());\n if (nullableInProto && !field.isNullable()) {\n resolverCode = createNonNullResolverCode(valueExpr);\n }\n if (field.type instanceof EnumType && field instanceof ObjectField) {\n resolverCode = createEnumResolverCode(valueExpr, field, opts);\n }\n if (\n field.type instanceof SquashedOneofUnionType &&\n field instanceof ObjectField\n ) {\n resolverCode = createOneofUnionResolverCode(valueExpr, field, opts);\n }\n if (field.type instanceof ScalarType && field.type.isBytes()) {\n if (field.isList()) {\n resolverCode = code`return ${valueExpr}.map(v => Buffer.from(v));`;\n } else if (field.isNullable()) {\n resolverCode = code`return ${valueExpr} == null ? null : Buffer.from(${valueExpr});`;\n } else {\n resolverCode = code`return Buffer.from(${valueExpr});`;\n }\n }\n }\n }\n\n const nullableValue = isInput !== field.isNullable(); /* Logical XOR */\n const fieldOpts = {\n type: field.isList() ? code`[${baseType}]` : baseType,\n [isInput ? \"required\" : \"nullable\"]: field.isList()\n ? { list: nullableValue, items: isInput /* always non-null */ }\n : nullableValue,\n description: field.description,\n deprecationReason: field.deprecationReason,\n resolve: resolverCode ? code`${sourceExpr} => {${resolverCode}}` : null,\n extensions: protobufGraphQLExtensions(field, registry),\n };\n\n const shouldUseFieldFunc = isInput || resolverCode != null;\n return shouldUseFieldFunc\n ? code`t.field(${literalOf(compactForCodegen(fieldOpts))})`\n : code`t.expose(${literalOf(\n tsFieldName(field.proto as DescField, opts),\n )}, ${literalOf(compactForCodegen(fieldOpts))})`;\n}\n\n/**\n * @example\n * ```ts\n * t.field( {\n * type: \"Boolean\",\n * nullable: true,\n * description: \"noop field\",\n * resolve() {\n * return true\n * }\n * })\n * ```\n */\nexport function createNoopFieldRefCode(opts: { input: boolean }): Printable[] {\n return code`\n t.field({\n type: \"Boolean\",\n ${opts.input ? \"required: false\" : \"nullable: true\"},\n description: \"noop field\",\n ${opts.input ? \"\" : \"resolve: () => true,\"}\n })\n `;\n}\n","import type {\n EnumType,\n EnumTypeValue,\n ObjectField,\n PrinterOptions,\n} from \"@proto-graphql/codegen-core\";\n\nimport { code, joinCode, type Printable } from \"../../../codegen/index.js\";\nimport { protoTypeSymbol } from \"../util.js\";\n\n/**\n * @example nullable\n * ```ts\n * if (!root.myEnum || root.myEnum === _$enums.myEnum.MY_ENUM_UNSPECIFIED) {\n * return null\n * }\n * return root.myEnum\n * ```\n * @example notNull\n * ```ts\n * if (!root.myEnum || root.myEnum === _$enums.myEnum.MY_ENUM_UNSPECIFIED) {\n * throw new Error(\"Message.field is required field. but got null or unspecified.\")\n * }\n * return root.myEnum\n * ```\n */\nexport function createEnumResolverCode(\n valueExpr: Printable[],\n field: ObjectField<EnumType>,\n opts: PrinterOptions,\n): Printable[] {\n const createBlockStmtCodes = (valueExpr: Printable[]): Printable[][] => {\n const chunks: Printable[][] = [];\n\n if (field.type.unspecifiedValue != null) {\n const escapeCode =\n field.isNullable() && !field.isList()\n ? code`return null;`\n : code`throw new Error(\"${field.name} is required field. But got unspecified.\");`;\n chunks.push(code`\n if (${valueExpr} === ${protoTypeSymbol(\n field.type.proto,\n opts,\n )}.${enumValueJsName(field.type, field.type.unspecifiedValue, opts)}) {\n ${escapeCode}\n }\n `);\n }\n for (const ev of field.type.valuesWithIgnored) {\n if (!ev.isIgnored()) continue;\n chunks.push(code`\n if (${valueExpr} === ${protoTypeSymbol(\n field.type.proto,\n opts,\n )}.${enumValueJsName(field.type, ev, opts)}) {\n throw new Error(\"${ev.name} is ignored in GraphQL schema\");\n }\n `);\n }\n\n return chunks;\n };\n\n if (field.isList()) {\n const stmts = createBlockStmtCodes(code`item`);\n if (stmts.length === 0) {\n return code`return ${valueExpr}`;\n }\n return code`return ${valueExpr}.map(item => {\n ${joinCode(stmts)}\n return item;\n })`;\n }\n\n return code`\n ${joinCode(createBlockStmtCodes(valueExpr))}\n return ${valueExpr};\n `;\n}\n\nfunction enumValueJsName(\n _et: EnumType,\n ev: EnumTypeValue,\n opts: PrinterOptions,\n): string {\n switch (opts.protobuf) {\n case \"ts-proto\":\n return ev.proto.name;\n case \"protobuf-es-v1\":\n case \"protobuf-es\":\n return ev.proto.localName;\n }\n}\n","import { code, type Printable } from \"../../../codegen/index.js\";\n\nexport function createNonNullResolverCode(valueExpr: Printable[]): Printable[] {\n return code`\n return ${valueExpr}!;\n `;\n}\n","import {\n ObjectField,\n ObjectOneofField,\n type ObjectType,\n type PrinterOptions,\n type SquashedOneofUnionType,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport { code, joinCode, type Printable } from \"../../../codegen/index.js\";\nimport { protoTypeSymbol } from \"../util.js\";\n\n/**\n * @example nullable\n * ```ts\n * const value = source.v1 ?? source.v2 ?? source.v3;\n * if (value != null) {\n * throw new Error(\"...\");\n * }\n * return value\n * ```\n */\nexport function createOneofUnionResolverCode(\n sourceExpr: Printable[],\n field: ObjectOneofField | ObjectField<SquashedOneofUnionType>,\n opts: PrinterOptions,\n): Printable[] {\n const createBlockStmtCode = (\n sourceExpr: Printable[],\n { nullable, list }: { nullable: boolean; list: boolean },\n ): Printable[] => {\n switch (opts.protobuf) {\n case \"ts-proto\": {\n return createBlockStmtCodeForTsProto(sourceExpr, field, opts, {\n nullable,\n });\n }\n case \"protobuf-es-v1\":\n case \"protobuf-es\": {\n return createBlockStmtCodeForProtobufEs(sourceExpr, field, opts, {\n nullable,\n list,\n });\n }\n }\n };\n\n if (field instanceof ObjectField && field.isList()) {\n return code`\n return ${sourceExpr}.map(item => {\n ${createBlockStmtCode(code`item`, { nullable: false, list: true })}\n })\n `;\n }\n\n return createBlockStmtCode(sourceExpr, {\n nullable: field.isNullable(),\n list: false,\n });\n}\n\nfunction createBlockStmtCodeForTsProto(\n sourceExpr: Printable[],\n field: ObjectOneofField | ObjectField<SquashedOneofUnionType>,\n opts: PrinterOptions,\n { nullable }: { nullable: boolean },\n): Printable[] {\n const createFieldExpr = (memberField: ObjectField<any>): Printable[] => {\n if (field instanceof ObjectOneofField) {\n return code`${sourceExpr}.${tsFieldName(memberField.proto, opts).toString()}`;\n }\n return code`${sourceExpr}?.${tsFieldName(memberField.proto, opts).toString()}`;\n };\n\n return code`\n const value = ${joinCode(field.type.fields.map(createFieldExpr), \" ?? \")};\n if (value == null) {\n ${\n nullable\n ? \"return null\"\n : `throw new Error(\"${field.name} should not be null\")`\n };\n }\n return value;\n `;\n}\n\nfunction createBlockStmtCodeForProtobufEs(\n sourceExpr: Printable[],\n field: ObjectOneofField | ObjectField<SquashedOneofUnionType>,\n opts: PrinterOptions,\n { nullable, list }: { nullable: boolean; list: boolean },\n): Printable[] {\n let valueExpr: Printable[];\n if (field instanceof ObjectOneofField) {\n valueExpr = code`${sourceExpr}.${tsFieldName(field.proto, opts).toString()}.value`;\n } else if (field instanceof ObjectField) {\n valueExpr = code`${sourceExpr}${list ? \"\" : \"?\"}.${tsFieldName(\n field.type.oneofUnionType.proto,\n opts,\n ).toString()}.value`;\n } else {\n field satisfies never;\n throw new Error(\"unreachable\");\n }\n\n // In protobuf-es, accessing .value on a oneof returns a union of all member types.\n // However, some members may be ignored in the GraphQL Union type,\n // so we need to assert to the expected type containing only non-ignored members.\n const memberTypeSymbols = field.type.fields.map((f) =>\n protoTypeSymbol((f.type as ObjectType).proto, opts),\n );\n const typeAssertion =\n memberTypeSymbols.length > 0\n ? code`${joinCode(\n memberTypeSymbols.map((s) => code`${s}`),\n \" | \",\n )} | undefined`\n : code`undefined`;\n\n if (nullable) {\n return code`return (${valueExpr} ?? null) as ${typeAssertion} | null;`;\n }\n return code`\n const value = ${valueExpr} as ${typeAssertion};\n if (value == null) {\n throw new Error(\"${field.name} should not be null\");\n }\n return value;\n `;\n}\n","import type { DescField, Registry } from \"@bufbuild/protobuf\";\nimport {\n InterfaceType,\n type ObjectType,\n protobufGraphQLExtensions,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n joinCode,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport { createFieldRefCode, createNoopFieldRefCode } from \"./field.js\";\nimport {\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n protobufIsMessageSymbol,\n protoRefTypePrintable,\n protoSchemaSymbol,\n protoTypeSymbol,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export const Hello$Ref = builder.objectRef<_$hello$hello_pb.Hello>(\"Hello\")\n * builder.objectType(Hello$Ref, {\n * name: \"Hello\",\n * // ...\n * })\n * ```\n */\nexport function createObjectTypeCode(\n type: ObjectType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const isInterface = type instanceof InterfaceType;\n const typeOpts = {\n name: type.typeName,\n fields: code`t => ({${\n type.fields.length > 0\n ? joinCode(\n type.fields.map(\n (f) => code`${f.name}: ${createFieldRefCode(f, registry, opts)},`,\n ),\n )\n : code`_: ${createNoopFieldRefCode({ input: false })}`\n }})`,\n description: type.description,\n isTypeOf: isInterface\n ? undefined\n : createIsTypeOfFuncCode(type, registry, opts),\n extensions: protobufGraphQLExtensions(type, registry),\n };\n const buildRefFunc = code`${pothosBuilderPrintable(opts)}.${\n isInterface ? \"interface\" : \"object\"\n }Ref`;\n const buildTypeFunc = code`${pothosBuilderPrintable(opts)}.${\n isInterface ? \"interface\" : \"object\"\n }Type`;\n const refFuncTypeArg = isInterface\n ? code`\n Pick<\n ${protoRefTypePrintable(type.proto, opts)},\n ${joinCode(\n type.fields.map((f) =>\n literalOf(tsFieldName(f.proto as DescField, opts)),\n ),\n \"|\",\n )}\n >`\n : protoRefTypePrintable(type.proto, opts);\n\n return code`\n export const ${pothosRefPrintable(\n type,\n )} = ${buildRefFunc}<${refFuncTypeArg}>(${literalOf(type.typeName)});\n ${buildTypeFunc}(${pothosRefPrintable(type)}, ${literalOf(compactForCodegen(typeOpts))});\n `;\n}\n\nfunction createIsTypeOfFuncCode(\n type: ObjectType,\n _registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n switch (opts.protobuf) {\n case \"ts-proto\": {\n return code`\n (source) => {\n return (source as ${protoTypeSymbol(type.proto, opts)} | { $type: string & {} }).$type\n === ${literalOf(type.proto.typeName)};\n }\n `;\n }\n case \"protobuf-es-v1\": {\n return code`\n (source) => {\n return source instanceof ${protoTypeSymbol(type.proto, opts)}\n }\n `;\n }\n case \"protobuf-es\": {\n return code`\n (source) => {\n return ${protobufIsMessageSymbol()}(source, ${protoSchemaSymbol(type.proto, opts)})\n }\n `;\n }\n }\n}\n","import type { Registry } from \"@bufbuild/protobuf\";\nimport {\n type OneofUnionType,\n protobufGraphQLExtensions,\n type SquashedOneofUnionType,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport {\n fieldTypeRefPrintable,\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export cosnt Oneof = builder.unionType(\"Oneof\", {\n * types: [...],\n * // ...\n * })\n * ```\n */\nexport function createOneofUnionTypeCode(\n type: OneofUnionType | SquashedOneofUnionType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const typeOpts = {\n types: type.fields.map((f) => fieldTypeRefPrintable(f, opts)),\n description: type.description,\n extensions: protobufGraphQLExtensions(type, registry),\n };\n return code`\n export const ${pothosRefPrintable(type)} =\n ${pothosBuilderPrintable(opts)}.unionType(${literalOf(\n type.typeName,\n )}, ${literalOf(compactForCodegen(typeOpts))});\n `;\n}\n"],"mappings":";;;;AAAA,SAASA,iBAAiB;;;ACA1B,SAASC,8BAA8B;AACvC,SACEC,mBACAC,0BACK;;;ACFL,cAAW;;;ACFb,OAAOC,YAAY;AAEZ,SAASC,WAAWC,OAAY;AACrC,SAAOC,OAAOC,OAAO,WAAWF,OAAM;IACpCG,WAAW;IACXC,aAAa;IACbC,SAAS;IACTC,YAAY;IACZC,YAAY;IACZC,YAAY;IACZC,aAAa;IACbC,WAAW;IACXC,eAAe;IACfC,oBAAoB;IACpBC,yBAAyB;IACzBC,gBAAgB;IAChBC,kBAAkB;IAClBC,eAAe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,SAAKG,QAAQC,WAAW;EAC1B;AAEA,QAAMC,WAAWC,yBAAyBR,MAAAA;AAC1C,QAAMS,QAAQC,qBAAqBT,MAAMC,KAAKS,MAAMX,OAAOY,QAAQ;AAEnE,QAAMC,IAAIb,OAAOc,aAAaC,sBAAsBd,MAAMC,KAAKG,OAAO,CAAA;AACtE,QAAMW,aAAa;OACdC,wBAAwBR,OAAOF,UAAUL,KAAKG,OAAO;;AAI1DQ,IAAEK,SAASjB,IAAAA;AAEX,MAAIe,WAAWG,WAAW,GAAG;AAC3BN,MAAEO,MAAM,YAAA;AACR;EACF;AAGA,aAAWC,KAAKL,YAAY;AAC1BH,MAAEO,MAAK,GAAIC,CAAAA;AACXR,MAAEO,MAAK;EACT;AACF;AA/BgBrB;;;AHHT,IAAMuB,kBAAkBC,uBAAuB;EACpDC,MAAM;EACNC,SAAS,IAAIA,OAAAA;EACbC,YAAYC,kBAAkB;IAC5BC;IACAC,KAAK;EACP,CAAA;EACAC,cAAcC;;EAEdC,WAAW,wBAACC,UAAAA;AACV,WAAOA,MAAMC,IAAI,CAACC,OAAO;MACvB,GAAGA;MACHC,SAASC,WAAWF,EAAEC,OAAO;IAC/B,EAAA;EACF,GALW;AAMb,CAAA;;;ADrBAE,UAAUC,eAAAA;","names":["runNodeJs","createEcmaScriptPlugin","createTsGenerator","parsePothosOptions","dprint","formatCode","code","dprint","format","lineWidth","indentWidth","useTabs","semiColons","quoteStyle","quoteProps","newLineKind","useBraces","bracePosition","singleBodyPosition","nextControlFlowPosition","trailingCommas","operatorPosition","preferHanging","preferSingleLine","collectTypesFromFile","createRegistryFromSchema","filenameFromProtoFile","EnumType","InputObjectType","ObjectType","OneofUnionType","SquashedOneofUnionType","protobufGraphQLExtensions","PRINTABLE_ARRAY_MARKER","Symbol","for","isPrintableArray","value","Array","isArray","markAsPrintableArray","arr","Object","defineProperty","enumerable","writable","configurable","code","strings","values","result","i","length","push","String","createImportSymbol","isImportSymbol","value","kind","joinCode","codes","separator","length","result","i","push","undefined","escapeString","str","replace","compactForCodegen","v","Array","isArray","isPrintableArray","map","compactObjForCodegen","obj","key","Object","keys","literalOf","value","markAsPrintableArray","String","elements","isImportSymbol","path","filename","ObjectOneofField","pothosRefName","type","typeName","shapeTypeName","resolveImportOrLocal","field","opts","symbolName","localPrintable","fromFile","filename","parent","toFile","importPath","replace","code","createImportSymbol","fieldTypeRefPrintable","ObjectOneofField","pothosRefPrintable","shapeTypePrintable","fieldTypeShapePrintable","toProtoFuncName","toProtoFuncPrintable","pothosBuilderPrintable","pothos","builderPath","protoTypeSymbol","proto","chunks","name","current","unshift","join","protoImportPath","protoSchemaSymbol","protobufCreateSymbol","protobufIsMessageSymbol","protobufMessageShapeSymbol","protoRefTypePrintable","protobuf","t","o","file","dir","parse","Error","importPrefix","createEnumTypeCode","type","registry","opts","typeOpts","description","values","code","joinCode","filter","v","isIgnored","isUnespecified","map","ev","name","literalOf","compactForCodegen","deprecationReason","value","number","extensions","protobufGraphQLExtensions","protoTypeExpr","protoTypeSymbol","proto","enumRefSymbol","createImportSymbol","refTypeExpr","pothosRefPrintable","pothosBuilderPrintable","typeName","EnumType","InputObjectType","protobufGraphQLExtensions","ScalarType","tsFieldName","EnumType","InputObjectField","ObjectField","ObjectOneofField","ObjectType","protobufGraphQLExtensions","ScalarType","SquashedOneofUnionType","tsFieldName","createEnumResolverCode","valueExpr","field","opts","createBlockStmtCodes","chunks","type","unspecifiedValue","escapeCode","isNullable","isList","code","name","push","protoTypeSymbol","proto","enumValueJsName","ev","valuesWithIgnored","isIgnored","stmts","length","joinCode","_et","protobuf","localName","createNonNullResolverCode","valueExpr","code","ObjectField","ObjectOneofField","tsFieldName","createOneofUnionResolverCode","sourceExpr","field","opts","createBlockStmtCode","nullable","list","protobuf","createBlockStmtCodeForTsProto","createBlockStmtCodeForProtobufEs","ObjectField","isList","code","isNullable","createFieldExpr","memberField","ObjectOneofField","tsFieldName","proto","toString","joinCode","type","fields","map","name","valueExpr","oneofUnionType","Error","memberTypeSymbols","f","protoTypeSymbol","typeAssertion","length","s","createGetFieldValueCodePrintable","source","proto","opts","code","tsFieldName","createFieldRefCode","field","registry","isInput","InputObjectField","baseType","type","ScalarType","literalOf","typeName","fieldTypeRefPrintable","sourceExpr","resolverCode","ObjectOneofField","createOneofUnionResolverCode","valueExpr","nullableInProto","ObjectType","isPrimitive","isWrapperType","isNullable","createNonNullResolverCode","EnumType","ObjectField","createEnumResolverCode","SquashedOneofUnionType","isBytes","isList","nullableValue","fieldOpts","list","items","description","deprecationReason","resolve","extensions","protobufGraphQLExtensions","shouldUseFieldFunc","compactForCodegen","createNoopFieldRefCode","input","createInputObjectTypeCode","type","registry","opts","fields","filter","f","options","ignoreNonMessageOneofFields","proto","oneof","InputObjectType","shapeTypeCode","code","shapeTypePrintable","joinCode","map","typeNode","fieldTypeShapePrintable","isList","protoTypeSymbol","literalOf","tsFieldName","toString","isNullable","name","ScalarType","isCustomScalar","needsTypeAssertion","protobuf","inputObjectRefType","createImportSymbol","refCode","pothosRefPrintable","pothosBuilderPrintable","typeName","compactForCodegen","length","createFieldRefCode","createNoopFieldRefCode","input","extensions","protobufGraphQLExtensions","description","codes","push","createToProtoFuncCode","oneofFields","protoTypeSym","fieldAssignments","localName","toProtoFunc","toProtoFuncPrintable","EnumType","Error","oneofAssignments","Object","values","oneofName","cases","caseName","protoSchemaSym","protoSchemaSymbol","toProtoFuncName","protobufCreateSymbol","InterfaceType","protobufGraphQLExtensions","tsFieldName","createObjectTypeCode","type","registry","opts","isInterface","InterfaceType","typeOpts","name","typeName","fields","code","length","joinCode","map","f","createFieldRefCode","createNoopFieldRefCode","input","description","isTypeOf","undefined","createIsTypeOfFuncCode","extensions","protobufGraphQLExtensions","buildRefFunc","pothosBuilderPrintable","buildTypeFunc","refFuncTypeArg","protoRefTypePrintable","proto","literalOf","tsFieldName","pothosRefPrintable","compactForCodegen","_registry","protobuf","protoTypeSymbol","protobufIsMessageSymbol","protoSchemaSymbol","protobufGraphQLExtensions","createOneofUnionTypeCode","type","registry","opts","typeOpts","types","fields","map","f","fieldTypeRefPrintable","description","extensions","protobufGraphQLExtensions","code","pothosRefPrintable","pothosBuilderPrintable","literalOf","typeName","compactForCodegen","createTypeDslPrintables","types","registry","opts","flatMap","type","ObjectType","createObjectTypeCode","InputObjectType","createInputObjectTypeCode","EnumType","createEnumTypeCode","OneofUnionType","SquashedOneofUnionType","createOneofUnionTypeCode","_exhaustiveCheck","allowedProtobufs","generateFiles","schema","file","opts","options","includes","printer","protobuf","registry","createRegistryFromSchema","types","collectTypesFromFile","type","allFiles","f","generateFile","filenameFromProtoFile","printables","createTypeDslPrintables","preamble","length","print","p","protocGenPothos","createEcmaScriptPlugin","name","version","generateTs","createTsGenerator","generateFiles","dsl","parseOptions","parsePothosOptions","transpile","files","map","f","content","formatCode","runNodeJs","protocGenPothos"]}
|
|
1
|
+
{"version":3,"sources":["../src/protoc-gen-pothos.ts","../src/plugin.ts","../package.json","../src/codegen/stringify.ts","../src/printer.ts","../src/dslgen/printers/index.ts","../src/dslgen/printers/enumType.ts","../src/codegen/code-builder.ts","../src/codegen/types.ts","../src/codegen/helpers.ts","../src/dslgen/printers/util.ts","../src/dslgen/printers/inputObjectType.ts","../src/dslgen/printers/field.ts","../src/dslgen/printers/fieldResolver/enumFieldResolver.ts","../src/dslgen/printers/fieldResolver/nonNullResolver.ts","../src/dslgen/printers/fieldResolver/oneofUnionResolver.ts","../src/dslgen/printers/objectType.ts","../src/dslgen/printers/oneofUnionType.ts"],"sourcesContent":["import { runNodeJs } from \"@bufbuild/protoplugin\";\n\nimport { protocGenPothos } from \"./plugin.js\";\n\nrunNodeJs(protocGenPothos);\n","import { createEcmaScriptPlugin } from \"@bufbuild/protoplugin\";\nimport {\n createTsGenerator,\n parsePothosOptions,\n} from \"@proto-graphql/protoc-plugin-helpers\";\n\nimport { version } from \"../package.json\";\nimport { formatCode } from \"./codegen/stringify.js\";\nimport { generateFiles } from \"./printer.js\";\n\nexport const protocGenPothos = createEcmaScriptPlugin({\n name: \"protoc-gen-pothos\",\n version: `v${version}`,\n generateTs: createTsGenerator({\n generateFiles,\n dsl: \"pothos\",\n }),\n parseOptions: parsePothosOptions,\n // NOTE: force `target=ts` and apply formatting\n transpile: (files) => {\n return files.map((f) => ({\n ...f,\n content: formatCode(f.content),\n }));\n },\n});\n","{\n \"name\": \"protoc-gen-pothos\",\n \"version\": \"0.7.1\",\n \"description\": \"Generate DSL for Pothos GraphQL from Protocol Buffers IDL\",\n \"keywords\": [\n \"graphql\",\n \"grpc\",\n \"pothos\",\n \"protobuf\",\n \"typescript\"\n ],\n \"bin\": {\n \"protoc-gen-pothos\": \"./bin/protoc-gen-pothos.cjs\"\n },\n \"repository\": \"git@github.com:proto-graphql/proto-graphql-js.git\",\n \"author\": \"izumin5210 <m@izum.in>\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.cjs\"\n }\n }\n },\n \"files\": [\n \"bin/\",\n \"docs/\",\n \"!docs/development/**\",\n \"src/\",\n \"dist/\",\n \"!src/**/*.test.ts\",\n \"!src/**/__tests__/\"\n ],\n \"sideEffects\": false,\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">= 14.0.0\"\n },\n \"dependencies\": {\n \"@bufbuild/protobuf\": \"catalog:\",\n \"@bufbuild/protoplugin\": \"catalog:\",\n \"@proto-graphql/codegen-core\": \"workspace:*\",\n \"@proto-graphql/protoc-plugin-helpers\": \"workspace:*\",\n \"dprint-node\": \"catalog:\"\n },\n \"devDependencies\": {\n \"@pothos/core\": \"catalog:test\",\n \"@proto-graphql/e2e-testapis-protobuf-es\": \"workspace:*\",\n \"@proto-graphql/e2e-testapis-protobuf-es-v2\": \"workspace:*\",\n \"@proto-graphql/e2e-testapis-ts-proto\": \"workspace:*\",\n \"@proto-graphql/e2e-testapis-ts-proto-with-forcelong-number\": \"workspace:*\",\n \"@proto-graphql/testapis-proto\": \"workspace:*\",\n \"@proto-graphql/tsconfig\": \"workspace:*\",\n \"@vitest/coverage-v8\": \"^4.0.0\",\n \"graphql\": \"catalog:test\",\n \"graphql-scalars\": \"^1.24.0\",\n \"tsx\": \"^4.21.0\"\n },\n \"scripts\": {\n \"build\": \"tsup && cp -r ../../docs/protoc-gen-pothos docs\",\n \"clean\": \"rm -rf dist docs\",\n \"test\": \"vitest run --passWithNoTests\",\n \"test:coverage\": \"vitest run --coverage\"\n }\n}\n","import dprint from \"dprint-node\";\n\nexport function formatCode(code: string): string {\n return dprint.format(\"file.ts\", code, {\n lineWidth: 80,\n indentWidth: 2,\n useTabs: false,\n semiColons: \"always\",\n quoteStyle: \"alwaysDouble\",\n quoteProps: \"asNeeded\",\n newLineKind: \"lf\",\n useBraces: \"whenNotSingleLine\",\n bracePosition: \"sameLineUnlessHanging\",\n singleBodyPosition: \"maintain\",\n nextControlFlowPosition: \"sameLine\",\n trailingCommas: \"onlyMultiLine\",\n operatorPosition: \"nextLine\",\n preferHanging: false,\n preferSingleLine: true,\n \"arrowFunction.useParentheses\": \"force\",\n });\n}\n","import type { DescFile } from \"@bufbuild/protobuf\";\nimport type { Schema } from \"@bufbuild/protoplugin\";\nimport {\n collectTypesFromFile,\n createRegistryFromSchema,\n filenameFromProtoFile,\n} from \"@proto-graphql/codegen-core\";\nimport type { Options } from \"@proto-graphql/protoc-plugin-helpers\";\n\nimport { createTypeDslPrintables } from \"./dslgen/index.js\";\n\nconst allowedProtobufs = [\"ts-proto\", \"protobuf-es-v1\", \"protobuf-es\"];\n\nexport function generateFiles(\n schema: Schema<Options<\"pothos\">>,\n file: DescFile,\n): void {\n const opts = schema.options;\n\n if (!allowedProtobufs.includes(opts.printer.protobuf)) {\n opts.printer.protobuf = \"ts-proto\"; // default\n }\n\n const registry = createRegistryFromSchema(schema);\n const types = collectTypesFromFile(file, opts.type, schema.allFiles);\n\n const f = schema.generateFile(filenameFromProtoFile(file, opts.printer));\n const printables = [\n ...createTypeDslPrintables(types, registry, opts.printer),\n ];\n\n // ヘッダー出力(preamble プロパティに格納される)\n f.preamble(file);\n\n if (printables.length === 0) {\n f.print(\"export {};\");\n return;\n }\n\n // 各型の Printable を直接出力\n for (const p of printables) {\n f.print(...p);\n f.print(); // 空行で区切り\n }\n}\n","import type { createRegistry } from \"@bufbuild/protobuf\";\nimport {\n EnumType,\n InputObjectType,\n ObjectType,\n OneofUnionType,\n SquashedOneofUnionType,\n} from \"@proto-graphql/codegen-core\";\n\nimport type { Printable } from \"../../codegen/index.js\";\nimport { createEnumTypeCode } from \"./enumType.js\";\nimport { createInputObjectTypeCode } from \"./inputObjectType.js\";\nimport { createObjectTypeCode } from \"./objectType.js\";\nimport { createOneofUnionTypeCode } from \"./oneofUnionType.js\";\nimport type { PothosPrinterOptions } from \"./util.js\";\n\nexport function createTypeDslPrintables(\n types: (\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n )[],\n registry: ReturnType<typeof createRegistry>,\n opts: PothosPrinterOptions,\n): Printable[][] {\n return types.flatMap((type) => {\n if (type instanceof ObjectType) {\n return [createObjectTypeCode(type, registry, opts)];\n }\n if (type instanceof InputObjectType) {\n return [createInputObjectTypeCode(type, registry, opts)];\n }\n if (type instanceof EnumType) {\n return [createEnumTypeCode(type, registry, opts)];\n }\n if (\n type instanceof OneofUnionType ||\n type instanceof SquashedOneofUnionType\n ) {\n return [createOneofUnionTypeCode(type, registry, opts)];\n }\n\n const _exhaustiveCheck: never = type;\n throw \"unreachable\";\n });\n}\n","import type { Registry } from \"@bufbuild/protobuf\";\nimport {\n type EnumType,\n protobufGraphQLExtensions,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n createImportSymbol,\n joinCode,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport {\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n protoTypeSymbol,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export cosnt Hello$Ref: EnumRef<Hello, Hello> = builder.enumType(\"Hello\", {\n * values: [\n * // ...\n * ],\n * // ...\n * })\n * ```\n */\nexport function createEnumTypeCode(\n type: EnumType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const typeOpts = {\n description: type.description,\n values: code`{${joinCode(\n type.values\n .filter((v) => !v.isIgnored() && !v.isUnespecified())\n .map(\n (ev) =>\n code`${ev.name}: ${literalOf(\n compactForCodegen({\n description: ev.description,\n deprecationReason: ev.deprecationReason,\n value: ev.number,\n extensions: protobufGraphQLExtensions(ev, registry),\n }),\n )},`,\n ),\n )}} as const`,\n extensions: protobufGraphQLExtensions(type, registry),\n };\n\n const protoTypeExpr = protoTypeSymbol(type.proto, opts);\n const enumRefSymbol = createImportSymbol(\"EnumRef\", \"@pothos/core\");\n // EnumRef<Hello, Hello>\n const refTypeExpr = code`${enumRefSymbol}<${protoTypeExpr}, ${protoTypeExpr}>`;\n\n return code`\n export const ${pothosRefPrintable(type)}: ${refTypeExpr} =\n ${pothosBuilderPrintable(opts)}.enumType(${literalOf(\n type.typeName,\n )}, ${literalOf(compactForCodegen(typeOpts))});\n `;\n}\n","import type { ImportSymbol, Printable } from \"./types.js\";\n\nexport const PRINTABLE_ARRAY_MARKER = Symbol.for(\n \"proto-graphql:printable-array\",\n);\n\nexport type PrintableArray = Printable[] & { [PRINTABLE_ARRAY_MARKER]: true };\n\nexport function isPrintableArray(value: unknown): value is PrintableArray {\n return Array.isArray(value) && PRINTABLE_ARRAY_MARKER in value;\n}\n\nexport function markAsPrintableArray(arr: Printable[]): PrintableArray {\n Object.defineProperty(arr, PRINTABLE_ARRAY_MARKER, {\n value: true,\n enumerable: false,\n writable: false,\n configurable: false,\n });\n return arr as PrintableArray;\n}\n\ntype CodeValue =\n | string\n | number\n | ImportSymbol\n | Printable[]\n | null\n | undefined;\n\nexport function code(\n strings: TemplateStringsArray,\n ...values: CodeValue[]\n): PrintableArray {\n const result: Printable[] = [];\n\n for (let i = 0; i < strings.length; i++) {\n if (strings[i] !== \"\") {\n result.push(strings[i]);\n }\n\n if (i < values.length) {\n const value = values[i];\n if (value == null) {\n result.push(String(value));\n } else if (typeof value === \"string\") {\n if (value !== \"\") {\n result.push(value);\n }\n } else if (typeof value === \"number\") {\n result.push(String(value));\n } else if (Array.isArray(value)) {\n result.push(...value);\n } else {\n result.push(value as Printable);\n }\n }\n }\n\n if (result.length === 0) {\n result.push(\"\");\n }\n\n return markAsPrintableArray(result);\n}\n","export type {\n ImportSymbol,\n Printable,\n} from \"@bufbuild/protoplugin\";\n\nexport { createImportSymbol } from \"@bufbuild/protoplugin\";\n\nimport type { ImportSymbol } from \"@bufbuild/protoplugin\";\n\nexport function isImportSymbol(value: unknown): value is ImportSymbol {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"kind\" in value &&\n (value as Record<string, unknown>).kind === \"es_symbol\"\n );\n}\n","import {\n isPrintableArray,\n markAsPrintableArray,\n type PrintableArray,\n} from \"./code-builder.js\";\nimport type { Printable } from \"./types.js\";\nimport { isImportSymbol } from \"./types.js\";\n\nexport function joinCode(\n codes: Printable[][],\n separator?: string,\n): Printable[] {\n if (codes.length === 0) {\n return [];\n }\n\n const result: Printable[] = [];\n for (let i = 0; i < codes.length; i++) {\n result.push(...codes[i]);\n if (separator !== undefined && i < codes.length - 1) {\n result.push(separator);\n }\n }\n return result;\n}\n\nfunction escapeString(str: string): string {\n return str\n .replace(/\\\\/g, \"\\\\\\\\\")\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, \"\\\\n\")\n .replace(/\\r/g, \"\\\\r\")\n .replace(/\\t/g, \"\\\\t\");\n}\n\n/**\n * Remove nullish values recursively, preserving PrintableArrays.\n * This is a variant of compact() from codegen-core that doesn't lose the PrintableArray marker.\n */\nexport function compactForCodegen(v: unknown): unknown {\n if (typeof v !== \"object\") return v;\n if (v == null) return v;\n if (Array.isArray(v)) {\n if (isPrintableArray(v)) {\n return v;\n }\n return v.map(compactForCodegen);\n }\n return compactObjForCodegen(v as Record<string, unknown>);\n}\n\nfunction compactObjForCodegen(\n obj: Record<string, unknown>,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(obj)) {\n const v = obj[key];\n if (v != null) {\n result[key] = compactForCodegen(v);\n }\n }\n return result;\n}\n\nexport function literalOf(value: unknown): PrintableArray {\n if (value === null) {\n return markAsPrintableArray([\"null\"]);\n }\n\n if (value === undefined) {\n return markAsPrintableArray([\"undefined\"]);\n }\n\n if (typeof value === \"string\") {\n return markAsPrintableArray([`\"${escapeString(value)}\"`]);\n }\n\n if (typeof value === \"number\") {\n return markAsPrintableArray([String(value)]);\n }\n\n if (typeof value === \"boolean\") {\n return markAsPrintableArray([String(value)]);\n }\n\n if (Array.isArray(value)) {\n if (isPrintableArray(value)) {\n return value;\n }\n\n if (value.length === 0) {\n return markAsPrintableArray([\"[]\"]);\n }\n\n const elements: Printable[] = [\"[\"];\n for (let i = 0; i < value.length; i++) {\n if (i > 0) {\n elements.push(\", \");\n }\n elements.push(...literalOf(value[i]));\n }\n elements.push(\"]\");\n return markAsPrintableArray(elements);\n }\n\n if (typeof value === \"object\") {\n // ImportSymbol should be returned as-is (wrapped in PrintableArray)\n if (isImportSymbol(value)) {\n return markAsPrintableArray([value]);\n }\n\n const obj = value as Record<string, unknown>;\n const keys = Object.keys(obj);\n\n if (keys.length === 0) {\n return markAsPrintableArray([\"{}\"]);\n }\n\n const elements: Printable[] = [\"{ \"];\n for (let i = 0; i < keys.length; i++) {\n if (i > 0) {\n elements.push(\", \");\n }\n const key = keys[i];\n // Always quote keys to match ts-poet literalOf behavior\n elements.push(`\"${escapeString(key)}\": `);\n elements.push(...literalOf(obj[key]));\n }\n elements.push(\" }\");\n return markAsPrintableArray(elements);\n }\n\n return markAsPrintableArray([String(value)]);\n}\n","import * as path from \"node:path\";\n\nimport type {\n DescEnum,\n DescExtension,\n DescFile,\n DescMessage,\n DescService,\n} from \"@bufbuild/protobuf\";\nimport { nestedTypes } from \"@bufbuild/protobuf/reflect\";\nimport { safeIdentifier } from \"@bufbuild/protoplugin\";\nimport {\n type EnumType,\n filename,\n type InputObjectField,\n type InputObjectType,\n type InterfaceType,\n type ObjectField,\n ObjectOneofField,\n type ObjectType,\n type OneofUnionType,\n type PrinterOptions,\n type SquashedOneofUnionType,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n createImportSymbol,\n type ImportSymbol,\n type Printable,\n} from \"../../codegen/index.js\";\n\nexport type PothosPrinterOptions = Extract<PrinterOptions, { dsl: \"pothos\" }>;\n\nexport function pothosRefName(\n type:\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n | InterfaceType,\n): string {\n return `${type.typeName}$Ref`;\n}\n\nexport function shapeTypeName(type: InputObjectType): string {\n return `${type.typeName}$Shape`;\n}\n\ntype TypeWithFilename =\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n | InterfaceType;\n\nfunction resolveImportOrLocal(\n field: { parent: TypeWithFilename; type: TypeWithFilename },\n opts: PothosPrinterOptions,\n symbolName: string,\n localPrintable: () => Printable[],\n): Printable[] {\n const fromFile = filename(field.parent, opts);\n const toFile = filename(field.type, opts);\n if (fromFile === toFile) return localPrintable();\n\n const importPath = `./${toFile.replace(/\\.ts$/, \"\")}`;\n return code`${createImportSymbol(symbolName, importPath)}`;\n}\n\nexport function fieldTypeRefPrintable(\n field:\n | ObjectField<\n ObjectType | EnumType | InterfaceType | SquashedOneofUnionType\n >\n | InputObjectField<InputObjectType | EnumType>\n | ObjectOneofField,\n opts: PothosPrinterOptions,\n): Printable[] {\n if (field instanceof ObjectOneofField) return pothosRefPrintable(field.type);\n\n return resolveImportOrLocal(field, opts, pothosRefName(field.type), () =>\n pothosRefPrintable(field.type),\n );\n}\n\nexport function shapeTypePrintable(type: InputObjectType): Printable[] {\n return code`${shapeTypeName(type)}`;\n}\n\nexport function fieldTypeShapePrintable(\n field: InputObjectField<InputObjectType>,\n opts: PothosPrinterOptions,\n): Printable[] {\n return resolveImportOrLocal(field, opts, shapeTypeName(field.type), () =>\n shapeTypePrintable(field.type),\n );\n}\n\nexport function toProtoFuncName(type: InputObjectType): string {\n return `${type.typeName}$toProto`;\n}\n\nexport function toProtoFuncPrintable(\n field: InputObjectField<InputObjectType>,\n opts: PothosPrinterOptions,\n): Printable[] {\n return resolveImportOrLocal(\n field,\n opts,\n toProtoFuncName(field.type),\n () => code`${toProtoFuncName(field.type)}`,\n );\n}\n\nexport function pothosRefPrintable(\n type:\n | ObjectType\n | InputObjectType\n | EnumType\n | OneofUnionType\n | SquashedOneofUnionType\n | InterfaceType,\n): Printable[] {\n return code`${pothosRefName(type)}`;\n}\n\nexport function pothosBuilderPrintable(\n opts: Pick<PothosPrinterOptions, \"pothos\">,\n): Printable[] {\n // protoplugin が自動的に相対パスを計算するため、builderPath をそのまま使用\n return code`${createImportSymbol(\"builder\", opts.pothos.builderPath)}`;\n}\n\nexport function protoTypeSymbol(\n proto: DescMessage | DescEnum,\n opts: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): ImportSymbol {\n const chunks = [proto.name];\n let current: DescMessage | DescEnum = proto;\n while (current.parent != null) {\n current = current.parent;\n chunks.unshift(current.name);\n }\n const symbolName = chunks.join(\"_\");\n const importPath = protoImportPath(proto, opts);\n return createImportSymbol(symbolName, importPath);\n}\n\n/**\n * protobuf-es v2 用: Schema シンボル (例: UserSchema, Parent_ChildSchema) を生成\n *\n * protobuf-es の @bufbuild/protoplugin が行う名前衝突回避ロジックを再実装。\n * 同一ファイル内で shape 名 (型名) と desc 名 (Schema 定数名) が衝突する場合、\n * protobuf-es は salt suffix ($, $1, $2, ...) を付与する。\n *\n * @see {@link https://github.com/bufbuild/protobuf-es/blob/v2.10.2/packages/protoplugin/src/names.ts | @bufbuild/protoplugin names.ts}\n */\nexport function protoSchemaSymbol(\n proto: DescMessage | DescEnum,\n opts: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): ImportSymbol {\n const symbolName = resolveProtobufEsDescName(proto);\n const importPath = protoImportPath(proto, opts);\n return createImportSymbol(symbolName, importPath);\n}\n\nfunction protobufEsSalt(i: number): string {\n if (i === 0) return \"\";\n if (i === 1) return \"$\";\n return `$${i - 1}`;\n}\n\nfunction idealShapeName(desc: DescMessage | DescEnum, i: number): string {\n return safeIdentifier(\n protobufEsIdentifierForNested(desc) + protobufEsSalt(i),\n );\n}\n\ntype NestedDesc = DescMessage | DescEnum | DescExtension | DescService;\n\n/**\n * protobuf-es と同じ identifier 計算。\n * パッケージ名を除去し、ドット (ネスト区切り) をアンダースコアに置換する。\n */\nfunction protobufEsIdentifierForNested(desc: NestedDesc): string {\n const pkg = desc.file.proto.package;\n const offset = pkg.length > 0 ? pkg.length + 1 : 0;\n return desc.typeName.substring(offset).replace(/\\./g, \"_\");\n}\n\nfunction idealDescName(desc: NestedDesc | DescFile, i: number): string {\n const salt = protobufEsSalt(i);\n if (desc.kind === \"file\") {\n const name = `file_${desc.name.replace(/[^a-zA-Z0-9_]+/g, \"_\")}`;\n return safeIdentifier(name + salt);\n }\n if (desc.kind === \"enum\" || desc.kind === \"message\") {\n return safeIdentifier(\n protobufEsIdentifierForNested(desc) + \"Schema\" + salt,\n );\n }\n // extension, service: Schema suffix なし\n return safeIdentifier(protobufEsIdentifierForNested(desc) + salt);\n}\n\n// ファイル単位のキャッシュ: 同一ファイル内の複数の型に対して重複計算を避ける\nconst descNameCache = new WeakMap<\n DescFile,\n Map<DescMessage | DescEnum, string>\n>();\n\n/**\n * @bufbuild/protoplugin の allNames() と同じロジックで desc 名を解決する。\n *\n * 1. Pass 1: 全 message/enum の shape 名を登録\n * 2. Pass 2: file desc + 全 nested types の desc 名を登録 (衝突時は salt suffix を付与)\n */\nfunction resolveProtobufEsDescName(proto: DescMessage | DescEnum): string {\n const file = proto.file;\n\n const cached = descNameCache.get(file);\n if (cached) {\n const name = cached.get(proto);\n if (name !== undefined) return name;\n }\n\n const taken = new Set<string>();\n const descNames = new Map<DescMessage | DescEnum, string>();\n\n // Pass 1: shape 名 (message/enum のみ)\n for (const desc of nestedTypes(file)) {\n if (desc.kind !== \"enum\" && desc.kind !== \"message\") continue;\n let name: string;\n for (let i = 0; ; i++) {\n name = idealShapeName(desc, i);\n if (!taken.has(name)) break;\n }\n taken.add(name);\n }\n\n // Pass 2: desc 名 (file + 全 nested types)\n {\n // file descriptor 自体の desc 名を登録\n let fileName: string;\n for (let i = 0; ; i++) {\n fileName = idealDescName(file, i);\n if (!taken.has(fileName)) break;\n }\n taken.add(fileName);\n }\n\n for (const desc of nestedTypes(file) as Iterable<NestedDesc>) {\n let name: string;\n for (let i = 0; ; i++) {\n name = idealDescName(desc, i);\n if (!taken.has(name)) break;\n }\n taken.add(name);\n if (desc.kind === \"message\" || desc.kind === \"enum\") {\n descNames.set(desc, name);\n }\n }\n\n descNameCache.set(file, descNames);\n\n const result = descNames.get(proto);\n if (result === undefined) {\n throw new Error(\n `Unable to determine protobuf-es desc name for ${proto.toString()}`,\n );\n }\n return result;\n}\n\n/**\n * @bufbuild/protobuf から create 関数を import\n */\nexport function protobufCreateSymbol(): ImportSymbol {\n return createImportSymbol(\"create\", \"@bufbuild/protobuf\");\n}\n\n/**\n * @bufbuild/protobuf から isMessage 関数を import\n */\nexport function protobufIsMessageSymbol(): ImportSymbol {\n return createImportSymbol(\"isMessage\", \"@bufbuild/protobuf\");\n}\n\n/**\n * @bufbuild/protobuf から MessageShape 型を import\n */\nexport function protobufMessageShapeSymbol(): ImportSymbol {\n return createImportSymbol(\"MessageShape\", \"@bufbuild/protobuf\");\n}\n\n/**\n * v2 用: ObjectRef の型パラメータとして使用する型を生成\n * - protobuf-es v2: MessageShape<typeof XxxSchema>\n * - protobuf-es v1: Xxx (クラス)\n * - ts-proto: Xxx (interface)\n */\nexport function protoRefTypePrintable(\n proto: DescMessage,\n opts: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): Printable[] {\n switch (opts.protobuf) {\n case \"ts-proto\":\n case \"protobuf-es-v1\": {\n return code`${protoTypeSymbol(proto, opts)}`;\n }\n case \"protobuf-es\": {\n return code`${protobufMessageShapeSymbol()}<typeof ${protoSchemaSymbol(proto, opts)}>`;\n }\n }\n}\n\nfunction protoImportPath(\n t: DescMessage | DescEnum,\n o: Pick<PrinterOptions, \"protobuf\" | \"importPrefix\">,\n): string {\n let importPath: string;\n switch (o.protobuf) {\n case \"ts-proto\": {\n importPath = t.file.name;\n break;\n }\n case \"protobuf-es-v1\":\n case \"protobuf-es\": {\n const { dir, name } = path.parse(t.file.name);\n importPath = `${dir}/${name}_pb`;\n break;\n }\n default: {\n o.protobuf satisfies never;\n throw new Error(`unexpected protobuf option: ${o.protobuf}`);\n }\n }\n return `${o.importPrefix ? `${o.importPrefix}/` : \"./\"}${importPath}`.replace(\n /(?<!:)\\/\\//,\n \"/\",\n );\n}\n","import type { Registry } from \"@bufbuild/protobuf\";\nimport {\n EnumType,\n type InputObjectField,\n InputObjectType,\n protobufGraphQLExtensions,\n ScalarType,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n createImportSymbol,\n joinCode,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport { createFieldRefCode, createNoopFieldRefCode } from \"./field.js\";\nimport {\n fieldTypeShapePrintable,\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n protobufCreateSymbol,\n protoSchemaSymbol,\n protoTypeSymbol,\n shapeTypePrintable,\n toProtoFuncName,\n toProtoFuncPrintable,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export type HelloInput$Shape = {\n * // ...\n * }\n * export const HelloInput$Ref: pothos.InputObjectRef<Hello$SHape> = builder.inputRef(\"HelloInput\").implement({\n * description: \"...\",\n * fields: (t) => ({\n * // ...\n * }),\n * })\n *\n * export function HelloInput$toProto () {\n * return {\n * // ...\n * }\n * }\n *\n * ```\n */\nexport function createInputObjectTypeCode(\n type: InputObjectType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const fields = type.fields.filter(\n (f) =>\n !(\n type.options.ignoreNonMessageOneofFields &&\n f.proto.oneof != null &&\n !(f.type instanceof InputObjectType)\n ),\n );\n\n const shapeTypeCode = code`\n export type ${shapeTypePrintable(type)} = {\n ${joinCode(\n fields.map((f) => {\n let typeNode: Printable[];\n if (f.type instanceof InputObjectType) {\n typeNode = fieldTypeShapePrintable(\n f as InputObjectField<InputObjectType>,\n opts,\n );\n if (f.isList()) typeNode = code`Array<${typeNode}>`;\n } else {\n typeNode = code`${protoTypeSymbol(type.proto, opts)}[${literalOf(\n tsFieldName(f.proto, opts).toString(),\n )}]`;\n }\n return f.isNullable()\n ? code`${f.name}?: ${typeNode} | null,`\n : code`${f.name}: ${\n f.type instanceof ScalarType && f.type.isCustomScalar()\n ? code`NonNullable<${typeNode}>`\n : typeNode\n },`;\n }),\n )}\n };\n `;\n\n // In protobuf-es v2, Message types have internal properties like $unknown and $typeName,\n // which can cause type mismatches between Pothos's inferred types and the InputShape type.\n // To work around this, we use a type assertion for protobuf-es v2.\n const needsTypeAssertion = opts.protobuf === \"protobuf-es\";\n const inputObjectRefType = code`${createImportSymbol(\n \"InputObjectRef\",\n \"@pothos/core\",\n )}<${shapeTypePrintable(type)}>`;\n\n const refCode = code`\n export const ${pothosRefPrintable(type)}: ${inputObjectRefType} =\n ${pothosBuilderPrintable(opts)}.inputRef<${shapeTypePrintable(\n type,\n )}>(${literalOf(type.typeName)}).implement(\n ${literalOf(\n compactForCodegen({\n fields: code`t => ({${\n fields.length > 0\n ? joinCode(\n fields.map(\n (f) =>\n code`${f.name}: ${createFieldRefCode(\n f,\n registry,\n opts,\n )}`,\n ),\n \", \",\n )\n : code`_: ${createNoopFieldRefCode({ input: true })}`\n }})`,\n extensions: protobufGraphQLExtensions(type, registry),\n description: type.description,\n }),\n )}\n )${needsTypeAssertion ? code` as ${inputObjectRefType}` : \"\"};\n `;\n\n const codes: Printable[][] = [shapeTypeCode, refCode];\n\n if (opts.protobuf === \"protobuf-es-v1\" || opts.protobuf === \"protobuf-es\") {\n codes.push(createToProtoFuncCode(type, fields, opts));\n }\n\n return joinCode(codes, \"\\n\\n\");\n}\n\nfunction createToProtoFuncCode(\n type: InputObjectType,\n fields: InputObjectField<ScalarType | EnumType | InputObjectType>[],\n opts: PothosPrinterOptions,\n): Printable[] {\n const oneofFields: Record<string, InputObjectField<InputObjectType>[]> = {};\n for (const f of fields) {\n if (f.proto.oneof == null) continue;\n if (!(f.type instanceof InputObjectType)) {\n // Non-message oneof members are ignored in toProto generation.\n // The strict validation path is handled in type construction.\n continue;\n }\n\n oneofFields[f.proto.oneof.name] = [\n ...(oneofFields[f.proto.oneof.name] || []),\n f as InputObjectField<InputObjectType>,\n ];\n }\n\n const protoTypeSym = protoTypeSymbol(type.proto, opts);\n\n const fieldAssignments = joinCode(\n fields\n .filter((f) => f.proto.oneof == null)\n .map((f) => {\n const localName = tsFieldName(f.proto, opts).toString();\n if (f.type instanceof InputObjectType) {\n const toProtoFunc = toProtoFuncPrintable(\n f as InputObjectField<InputObjectType>,\n opts,\n );\n if (f.isList()) {\n return code`${localName}: input?.${f.name}?.map(v => ${toProtoFunc}(v)),`;\n }\n return code`${localName}: input?.${f.name} ? ${toProtoFunc}(input.${f.name}) : undefined,`;\n }\n if (f.type instanceof ScalarType || f.type instanceof EnumType) {\n return code`${localName}: input?.${f.name} ?? undefined,`;\n }\n f.type satisfies never;\n throw new Error(\"unreachable\");\n }),\n \"\\n\",\n );\n\n const oneofAssignments = joinCode(\n Object.values(oneofFields).map((fields) => {\n const oneofName = tsFieldName(\n // biome-ignore lint/style/noNonNullAssertion: we know it's not null\n fields[0]!.proto.oneof!,\n opts,\n ).toString();\n const cases = fields.map((f) => {\n const caseName = tsFieldName(f.proto, opts).toString();\n return code`input?.${f.name} ? { case: \"${caseName}\", value: ${toProtoFuncPrintable(f, opts)}(input.${f.name}) } :`;\n });\n return code`${oneofName}: ${joinCode(cases, \" \")} undefined,`;\n }),\n \"\\n\",\n );\n\n if (opts.protobuf === \"protobuf-es\") {\n const protoSchemaSym = protoSchemaSymbol(type.proto, opts);\n return code`\n export function ${toProtoFuncName(type)} (input: ${shapeTypePrintable(\n type,\n )} | null | undefined): ${protoTypeSym} {\n return ${protobufCreateSymbol()}(${protoSchemaSym}, {\n ${fieldAssignments}\n ${oneofAssignments}\n });\n }\n `;\n }\n\n return code`\n export function ${toProtoFuncName(type)} (input: ${shapeTypePrintable(\n type,\n )} | null | undefined): ${protoTypeSym} {\n return new ${protoTypeSym}({\n ${fieldAssignments}\n ${oneofAssignments}\n });\n }\n `;\n}\n","import type { createRegistry, DescField } from \"@bufbuild/protobuf\";\nimport {\n EnumType,\n InputObjectField,\n ObjectField,\n ObjectOneofField,\n ObjectType,\n protobufGraphQLExtensions,\n ScalarType,\n SquashedOneofUnionType,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport { createEnumResolverCode } from \"./fieldResolver/enumFieldResolver.js\";\nimport { createNonNullResolverCode } from \"./fieldResolver/nonNullResolver.js\";\nimport { createOneofUnionResolverCode } from \"./fieldResolver/oneofUnionResolver.js\";\nimport { fieldTypeRefPrintable, type PothosPrinterOptions } from \"./util.js\";\n\nfunction createGetFieldValueCodePrintable(\n source: string,\n proto: DescField,\n opts: PothosPrinterOptions,\n): Printable[] {\n return code`${source}.${tsFieldName(proto, opts)}`;\n}\n\n/**\n * @example\n * ```ts\n * t.expose(\"name\", {\n * type: \"Boolean\",\n * nullable: true,\n * description: \"...\",\n * })\n * ```\n * ```ts\n * t.field({\n * type: \"Boolean\",\n * nullable: true,\n * description: \"...\",\n * resolve() {\n * return true\n * }\n * })\n * ```\n */\nexport function createFieldRefCode(\n field: ObjectField<any> | ObjectOneofField | InputObjectField<any>,\n registry: ReturnType<typeof createRegistry>,\n opts: PothosPrinterOptions,\n): Printable[] {\n const isInput = field instanceof InputObjectField;\n const baseType =\n field.type instanceof ScalarType\n ? literalOf(field.type.typeName)\n : fieldTypeRefPrintable(field, opts);\n\n const sourceExpr = \"source\";\n let resolverCode: Printable[] | undefined;\n if (!isInput) {\n if (field instanceof ObjectOneofField) {\n resolverCode = createOneofUnionResolverCode(\n code`${sourceExpr}`,\n field,\n opts,\n );\n } else {\n const valueExpr = createGetFieldValueCodePrintable(\n sourceExpr,\n field.proto,\n opts,\n );\n const nullableInProto =\n field.type instanceof ObjectType ||\n (field.type instanceof ScalarType &&\n !field.type.isPrimitive() &&\n !field.type.isWrapperType());\n if (nullableInProto && !field.isNullable()) {\n resolverCode = createNonNullResolverCode(valueExpr);\n }\n if (field.type instanceof EnumType && field instanceof ObjectField) {\n resolverCode = createEnumResolverCode(valueExpr, field, opts);\n }\n if (\n field.type instanceof SquashedOneofUnionType &&\n field instanceof ObjectField\n ) {\n resolverCode = createOneofUnionResolverCode(valueExpr, field, opts);\n }\n if (field.type instanceof ScalarType && field.type.isBytes()) {\n if (field.isList()) {\n resolverCode = code`return ${valueExpr}.map(v => Buffer.from(v));`;\n } else if (field.isNullable()) {\n resolverCode = code`return ${valueExpr} == null ? null : Buffer.from(${valueExpr});`;\n } else {\n resolverCode = code`return Buffer.from(${valueExpr});`;\n }\n }\n }\n }\n\n const nullableValue = isInput !== field.isNullable(); /* Logical XOR */\n const fieldOpts = {\n type: field.isList() ? code`[${baseType}]` : baseType,\n [isInput ? \"required\" : \"nullable\"]: field.isList()\n ? { list: nullableValue, items: isInput /* always non-null */ }\n : nullableValue,\n description: field.description,\n deprecationReason: field.deprecationReason,\n resolve: resolverCode ? code`${sourceExpr} => {${resolverCode}}` : null,\n extensions: protobufGraphQLExtensions(field, registry),\n };\n\n const shouldUseFieldFunc = isInput || resolverCode != null;\n return shouldUseFieldFunc\n ? code`t.field(${literalOf(compactForCodegen(fieldOpts))})`\n : code`t.expose(${literalOf(\n tsFieldName(field.proto as DescField, opts),\n )}, ${literalOf(compactForCodegen(fieldOpts))})`;\n}\n\n/**\n * @example\n * ```ts\n * t.field( {\n * type: \"Boolean\",\n * nullable: true,\n * description: \"noop field\",\n * resolve() {\n * return true\n * }\n * })\n * ```\n */\nexport function createNoopFieldRefCode(opts: { input: boolean }): Printable[] {\n return code`\n t.field({\n type: \"Boolean\",\n ${opts.input ? \"required: false\" : \"nullable: true\"},\n description: \"noop field\",\n ${opts.input ? \"\" : \"resolve: () => true,\"}\n })\n `;\n}\n","import type {\n EnumType,\n EnumTypeValue,\n ObjectField,\n PrinterOptions,\n} from \"@proto-graphql/codegen-core\";\n\nimport { code, joinCode, type Printable } from \"../../../codegen/index.js\";\nimport { protoTypeSymbol } from \"../util.js\";\n\n/**\n * @example nullable\n * ```ts\n * if (!root.myEnum || root.myEnum === _$enums.myEnum.MY_ENUM_UNSPECIFIED) {\n * return null\n * }\n * return root.myEnum\n * ```\n * @example notNull\n * ```ts\n * if (!root.myEnum || root.myEnum === _$enums.myEnum.MY_ENUM_UNSPECIFIED) {\n * throw new Error(\"Message.field is required field. but got null or unspecified.\")\n * }\n * return root.myEnum\n * ```\n */\nexport function createEnumResolverCode(\n valueExpr: Printable[],\n field: ObjectField<EnumType>,\n opts: PrinterOptions,\n): Printable[] {\n const createBlockStmtCodes = (valueExpr: Printable[]): Printable[][] => {\n const chunks: Printable[][] = [];\n\n if (field.type.unspecifiedValue != null) {\n const escapeCode =\n field.isNullable() && !field.isList()\n ? code`return null;`\n : code`throw new Error(\"${field.name} is required field. But got unspecified.\");`;\n chunks.push(code`\n if (${valueExpr} === ${protoTypeSymbol(\n field.type.proto,\n opts,\n )}.${enumValueJsName(field.type, field.type.unspecifiedValue, opts)}) {\n ${escapeCode}\n }\n `);\n }\n for (const ev of field.type.valuesWithIgnored) {\n if (!ev.isIgnored()) continue;\n chunks.push(code`\n if (${valueExpr} === ${protoTypeSymbol(\n field.type.proto,\n opts,\n )}.${enumValueJsName(field.type, ev, opts)}) {\n throw new Error(\"${ev.name} is ignored in GraphQL schema\");\n }\n `);\n }\n\n return chunks;\n };\n\n if (field.isList()) {\n const stmts = createBlockStmtCodes(code`item`);\n if (stmts.length === 0) {\n return code`return ${valueExpr}`;\n }\n return code`return ${valueExpr}.map(item => {\n ${joinCode(stmts)}\n return item;\n })`;\n }\n\n return code`\n ${joinCode(createBlockStmtCodes(valueExpr))}\n return ${valueExpr};\n `;\n}\n\nfunction enumValueJsName(\n _et: EnumType,\n ev: EnumTypeValue,\n opts: PrinterOptions,\n): string {\n switch (opts.protobuf) {\n case \"ts-proto\":\n return ev.proto.name;\n case \"protobuf-es-v1\":\n case \"protobuf-es\":\n return ev.proto.localName;\n }\n}\n","import { code, type Printable } from \"../../../codegen/index.js\";\n\nexport function createNonNullResolverCode(valueExpr: Printable[]): Printable[] {\n return code`\n return ${valueExpr}!;\n `;\n}\n","import {\n ObjectField,\n ObjectOneofField,\n type ObjectType,\n type PrinterOptions,\n type SquashedOneofUnionType,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport { code, joinCode, type Printable } from \"../../../codegen/index.js\";\nimport { protoTypeSymbol } from \"../util.js\";\n\n/**\n * @example nullable\n * ```ts\n * const value = source.v1 ?? source.v2 ?? source.v3;\n * if (value != null) {\n * throw new Error(\"...\");\n * }\n * return value\n * ```\n */\nexport function createOneofUnionResolverCode(\n sourceExpr: Printable[],\n field: ObjectOneofField | ObjectField<SquashedOneofUnionType>,\n opts: PrinterOptions,\n): Printable[] {\n const createBlockStmtCode = (\n sourceExpr: Printable[],\n { nullable, list }: { nullable: boolean; list: boolean },\n ): Printable[] => {\n switch (opts.protobuf) {\n case \"ts-proto\": {\n return createBlockStmtCodeForTsProto(sourceExpr, field, opts, {\n nullable,\n });\n }\n case \"protobuf-es-v1\":\n case \"protobuf-es\": {\n return createBlockStmtCodeForProtobufEs(sourceExpr, field, opts, {\n nullable,\n list,\n });\n }\n }\n };\n\n if (field instanceof ObjectField && field.isList()) {\n return code`\n return ${sourceExpr}.map(item => {\n ${createBlockStmtCode(code`item`, { nullable: false, list: true })}\n })\n `;\n }\n\n return createBlockStmtCode(sourceExpr, {\n nullable: field.isNullable(),\n list: false,\n });\n}\n\nfunction createBlockStmtCodeForTsProto(\n sourceExpr: Printable[],\n field: ObjectOneofField | ObjectField<SquashedOneofUnionType>,\n opts: PrinterOptions,\n { nullable }: { nullable: boolean },\n): Printable[] {\n const createFieldExpr = (memberField: ObjectField<any>): Printable[] => {\n if (field instanceof ObjectOneofField) {\n return code`${sourceExpr}.${tsFieldName(memberField.proto, opts).toString()}`;\n }\n return code`${sourceExpr}?.${tsFieldName(memberField.proto, opts).toString()}`;\n };\n\n return code`\n const value = ${joinCode(field.type.fields.map(createFieldExpr), \" ?? \")};\n if (value == null) {\n ${\n nullable\n ? \"return null\"\n : `throw new Error(\"${field.name} should not be null\")`\n };\n }\n return value;\n `;\n}\n\nfunction createBlockStmtCodeForProtobufEs(\n sourceExpr: Printable[],\n field: ObjectOneofField | ObjectField<SquashedOneofUnionType>,\n opts: PrinterOptions,\n { nullable, list }: { nullable: boolean; list: boolean },\n): Printable[] {\n let valueExpr: Printable[];\n if (field instanceof ObjectOneofField) {\n valueExpr = code`${sourceExpr}.${tsFieldName(field.proto, opts).toString()}.value`;\n } else if (field instanceof ObjectField) {\n valueExpr = code`${sourceExpr}${list ? \"\" : \"?\"}.${tsFieldName(\n field.type.oneofUnionType.proto,\n opts,\n ).toString()}.value`;\n } else {\n field satisfies never;\n throw new Error(\"unreachable\");\n }\n\n // In protobuf-es, accessing .value on a oneof returns a union of all member types.\n // However, some members may be ignored in the GraphQL Union type,\n // so we need to assert to the expected type containing only non-ignored members.\n const memberTypeSymbols = field.type.fields.map((f) =>\n protoTypeSymbol((f.type as ObjectType).proto, opts),\n );\n const typeAssertion =\n memberTypeSymbols.length > 0\n ? code`${joinCode(\n memberTypeSymbols.map((s) => code`${s}`),\n \" | \",\n )} | undefined`\n : code`undefined`;\n\n if (nullable) {\n return code`return (${valueExpr} ?? null) as ${typeAssertion} | null;`;\n }\n return code`\n const value = ${valueExpr} as ${typeAssertion};\n if (value == null) {\n throw new Error(\"${field.name} should not be null\");\n }\n return value;\n `;\n}\n","import type { DescField, Registry } from \"@bufbuild/protobuf\";\nimport {\n InterfaceType,\n type ObjectType,\n protobufGraphQLExtensions,\n tsFieldName,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n joinCode,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport { createFieldRefCode, createNoopFieldRefCode } from \"./field.js\";\nimport {\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n protobufIsMessageSymbol,\n protoRefTypePrintable,\n protoSchemaSymbol,\n protoTypeSymbol,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export const Hello$Ref = builder.objectRef<_$hello$hello_pb.Hello>(\"Hello\")\n * builder.objectType(Hello$Ref, {\n * name: \"Hello\",\n * // ...\n * })\n * ```\n */\nexport function createObjectTypeCode(\n type: ObjectType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const isInterface = type instanceof InterfaceType;\n const typeOpts = {\n name: type.typeName,\n fields: code`t => ({${\n type.fields.length > 0\n ? joinCode(\n type.fields.map(\n (f) => code`${f.name}: ${createFieldRefCode(f, registry, opts)},`,\n ),\n )\n : code`_: ${createNoopFieldRefCode({ input: false })}`\n }})`,\n description: type.description,\n isTypeOf: isInterface\n ? undefined\n : createIsTypeOfFuncCode(type, registry, opts),\n extensions: protobufGraphQLExtensions(type, registry),\n };\n const buildRefFunc = code`${pothosBuilderPrintable(opts)}.${\n isInterface ? \"interface\" : \"object\"\n }Ref`;\n const buildTypeFunc = code`${pothosBuilderPrintable(opts)}.${\n isInterface ? \"interface\" : \"object\"\n }Type`;\n const refFuncTypeArg = isInterface\n ? code`\n Pick<\n ${protoRefTypePrintable(type.proto, opts)},\n ${joinCode(\n type.fields.map((f) =>\n literalOf(tsFieldName(f.proto as DescField, opts)),\n ),\n \"|\",\n )}\n >`\n : protoRefTypePrintable(type.proto, opts);\n\n return code`\n export const ${pothosRefPrintable(\n type,\n )} = ${buildRefFunc}<${refFuncTypeArg}>(${literalOf(type.typeName)});\n ${buildTypeFunc}(${pothosRefPrintable(type)}, ${literalOf(compactForCodegen(typeOpts))});\n `;\n}\n\nfunction createIsTypeOfFuncCode(\n type: ObjectType,\n _registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n switch (opts.protobuf) {\n case \"ts-proto\": {\n return code`\n (source) => {\n return (source as ${protoTypeSymbol(type.proto, opts)} | { $type: string & {} }).$type\n === ${literalOf(type.proto.typeName)};\n }\n `;\n }\n case \"protobuf-es-v1\": {\n return code`\n (source) => {\n return source instanceof ${protoTypeSymbol(type.proto, opts)}\n }\n `;\n }\n case \"protobuf-es\": {\n return code`\n (source) => {\n return ${protobufIsMessageSymbol()}(source, ${protoSchemaSymbol(type.proto, opts)})\n }\n `;\n }\n }\n}\n","import type { Registry } from \"@bufbuild/protobuf\";\nimport {\n type OneofUnionType,\n protobufGraphQLExtensions,\n type SquashedOneofUnionType,\n} from \"@proto-graphql/codegen-core\";\n\nimport {\n code,\n compactForCodegen,\n literalOf,\n type Printable,\n} from \"../../codegen/index.js\";\nimport {\n fieldTypeRefPrintable,\n type PothosPrinterOptions,\n pothosBuilderPrintable,\n pothosRefPrintable,\n} from \"./util.js\";\n\n/**\n * @example\n * ```ts\n * export cosnt Oneof = builder.unionType(\"Oneof\", {\n * types: [...],\n * // ...\n * })\n * ```\n */\nexport function createOneofUnionTypeCode(\n type: OneofUnionType | SquashedOneofUnionType,\n registry: Registry,\n opts: PothosPrinterOptions,\n): Printable[] {\n const typeOpts = {\n types: type.fields.map((f) => fieldTypeRefPrintable(f, opts)),\n description: type.description,\n extensions: protobufGraphQLExtensions(type, registry),\n };\n return code`\n export const ${pothosRefPrintable(type)} =\n ${pothosBuilderPrintable(opts)}.unionType(${literalOf(\n type.typeName,\n )}, ${literalOf(compactForCodegen(typeOpts))});\n `;\n}\n"],"mappings":";;;;AAAA,SAASA,iBAAiB;;;ACA1B,SAASC,8BAA8B;AACvC,SACEC,mBACAC,0BACK;;;ACFL,cAAW;;;ACFb,OAAOC,YAAY;AAEZ,SAASC,WAAWC,OAAY;AACrC,SAAOC,OAAOC,OAAO,WAAWF,OAAM;IACpCG,WAAW;IACXC,aAAa;IACbC,SAAS;IACTC,YAAY;IACZC,YAAY;IACZC,YAAY;IACZC,aAAa;IACbC,WAAW;IACXC,eAAe;IACfC,oBAAoB;IACpBC,yBAAyB;IACzBC,gBAAgB;IAChBC,kBAAkB;IAClBC,eAAe;IACfC,kBAAkB;IAClB,gCAAgC;EAClC,CAAA;AACF;AAnBgBlB;;;ACAhB,SACEmB,sBACAC,0BACAC,6BACK;;;ACLP,SACEC,YAAAA,WACAC,mBAAAA,kBACAC,cAAAA,aACAC,gBACAC,0BAAAA,+BACK;;;ACNP,SAEEC,iCACK;;;ACFA,IAAMC,yBAAyBC,uBAAOC,IAC3C,+BAAA;AAKK,SAASC,iBAAiBC,OAAc;AAC7C,SAAOC,MAAMC,QAAQF,KAAAA,KAAUJ,0BAA0BI;AAC3D;AAFgBD;AAIT,SAASI,qBAAqBC,KAAgB;AACnDC,SAAOC,eAAeF,KAAKR,wBAAwB;IACjDI,OAAO;IACPO,YAAY;IACZC,UAAU;IACVC,cAAc;EAChB,CAAA;AACA,SAAOL;AACT;AARgBD;AAkBT,SAASO,KACdC,YACGC,QAAmB;AAEtB,QAAMC,SAAsB,CAAA;AAE5B,WAASC,IAAI,GAAGA,IAAIH,QAAQI,QAAQD,KAAK;AACvC,QAAIH,QAAQG,CAAAA,MAAO,IAAI;AACrBD,aAAOG,KAAKL,QAAQG,CAAAA,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AC;EAAY;EAAkB;;AAEjD,SAASC,cACdC,QACAC,MAAc;AAEd,QAAMC,OAAOF,OAAOG;AAEpB,MAAI,CAACL,iBAAiBM,SAASF,KAAKG,QAAQC,QAAQ,GAAG;AACrDJ,SAAKG,QAAQC,WAAW;EAC1B;AAEA,QAAMC,WAAWC,yBAAyBR,MAAAA;AAC1C,QAAMS,QAAQC,qBAAqBT,MAAMC,KAAKS,MAAMX,OAAOY,QAAQ;AAEnE,QAAMC,IAAIb,OAAOc,aAAaC,sBAAsBd,MAAMC,KAAKG,OAAO,CAAA;AACtE,QAAMW,aAAa;OACdC,wBAAwBR,OAAOF,UAAUL,KAAKG,OAAO;;AAI1DQ,IAAEK,SAASjB,IAAAA;AAEX,MAAIe,WAAWG,WAAW,GAAG;AAC3BN,MAAEO,MAAM,YAAA;AACR;EACF;AAGA,aAAWC,KAAKL,YAAY;AAC1BH,MAAEO,MAAK,GAAIC,CAAAA;AACXR,MAAEO,MAAK;EACT;AACF;AA/BgBrB;;;AHHT,IAAMuB,kBAAkBC,uBAAuB;EACpDC,MAAM;EACNC,SAAS,IAAIA,OAAAA;EACbC,YAAYC,kBAAkB;IAC5BC;IACAC,KAAK;EACP,CAAA;EACAC,cAAcC;;EAEdC,WAAW,wBAACC,UAAAA;AACV,WAAOA,MAAMC,IAAI,CAACC,OAAO;MACvB,GAAGA;MACHC,SAASC,WAAWF,EAAEC,OAAO;IAC/B,EAAA;EACF,GALW;AAMb,CAAA;;;ADrBAE,UAAUC,eAAAA;","names":["runNodeJs","createEcmaScriptPlugin","createTsGenerator","parsePothosOptions","dprint","formatCode","code","dprint","format","lineWidth","indentWidth","useTabs","semiColons","quoteStyle","quoteProps","newLineKind","useBraces","bracePosition","singleBodyPosition","nextControlFlowPosition","trailingCommas","operatorPosition","preferHanging","preferSingleLine","collectTypesFromFile","createRegistryFromSchema","filenameFromProtoFile","EnumType","InputObjectType","ObjectType","OneofUnionType","SquashedOneofUnionType","protobufGraphQLExtensions","PRINTABLE_ARRAY_MARKER","Symbol","for","isPrintableArray","value","Array","isArray","markAsPrintableArray","arr","Object","defineProperty","enumerable","writable","configurable","code","strings","values","result","i","length","push","String","createImportSymbol","isImportSymbol","value","kind","joinCode","codes","separator","length","result","i","push","undefined","escapeString","str","replace","compactForCodegen","v","Array","isArray","isPrintableArray","map","compactObjForCodegen","obj","key","Object","keys","literalOf","value","markAsPrintableArray","String","elements","isImportSymbol","path","nestedTypes","safeIdentifier","filename","ObjectOneofField","pothosRefName","type","typeName","shapeTypeName","resolveImportOrLocal","field","opts","symbolName","localPrintable","fromFile","filename","parent","toFile","importPath","replace","code","createImportSymbol","fieldTypeRefPrintable","ObjectOneofField","pothosRefPrintable","shapeTypePrintable","fieldTypeShapePrintable","toProtoFuncName","toProtoFuncPrintable","pothosBuilderPrintable","pothos","builderPath","protoTypeSymbol","proto","chunks","name","current","unshift","join","protoImportPath","protoSchemaSymbol","resolveProtobufEsDescName","protobufEsSalt","i","idealShapeName","desc","safeIdentifier","protobufEsIdentifierForNested","pkg","file","package","offset","length","substring","idealDescName","salt","kind","descNameCache","WeakMap","cached","get","undefined","taken","Set","descNames","Map","nestedTypes","has","add","fileName","set","result","Error","toString","protobufCreateSymbol","protobufIsMessageSymbol","protobufMessageShapeSymbol","protoRefTypePrintable","protobuf","t","o","dir","parse","importPrefix","createEnumTypeCode","type","registry","opts","typeOpts","description","values","code","joinCode","filter","v","isIgnored","isUnespecified","map","ev","name","literalOf","compactForCodegen","deprecationReason","value","number","extensions","protobufGraphQLExtensions","protoTypeExpr","protoTypeSymbol","proto","enumRefSymbol","createImportSymbol","refTypeExpr","pothosRefPrintable","pothosBuilderPrintable","typeName","EnumType","InputObjectType","protobufGraphQLExtensions","ScalarType","tsFieldName","EnumType","InputObjectField","ObjectField","ObjectOneofField","ObjectType","protobufGraphQLExtensions","ScalarType","SquashedOneofUnionType","tsFieldName","createEnumResolverCode","valueExpr","field","opts","createBlockStmtCodes","chunks","type","unspecifiedValue","escapeCode","isNullable","isList","code","name","push","protoTypeSymbol","proto","enumValueJsName","ev","valuesWithIgnored","isIgnored","stmts","length","joinCode","_et","protobuf","localName","createNonNullResolverCode","valueExpr","code","ObjectField","ObjectOneofField","tsFieldName","createOneofUnionResolverCode","sourceExpr","field","opts","createBlockStmtCode","nullable","list","protobuf","createBlockStmtCodeForTsProto","createBlockStmtCodeForProtobufEs","ObjectField","isList","code","isNullable","createFieldExpr","memberField","ObjectOneofField","tsFieldName","proto","toString","joinCode","type","fields","map","name","valueExpr","oneofUnionType","Error","memberTypeSymbols","f","protoTypeSymbol","typeAssertion","length","s","createGetFieldValueCodePrintable","source","proto","opts","code","tsFieldName","createFieldRefCode","field","registry","isInput","InputObjectField","baseType","type","ScalarType","literalOf","typeName","fieldTypeRefPrintable","sourceExpr","resolverCode","ObjectOneofField","createOneofUnionResolverCode","valueExpr","nullableInProto","ObjectType","isPrimitive","isWrapperType","isNullable","createNonNullResolverCode","EnumType","ObjectField","createEnumResolverCode","SquashedOneofUnionType","isBytes","isList","nullableValue","fieldOpts","list","items","description","deprecationReason","resolve","extensions","protobufGraphQLExtensions","shouldUseFieldFunc","compactForCodegen","createNoopFieldRefCode","input","createInputObjectTypeCode","type","registry","opts","fields","filter","f","options","ignoreNonMessageOneofFields","proto","oneof","InputObjectType","shapeTypeCode","code","shapeTypePrintable","joinCode","map","typeNode","fieldTypeShapePrintable","isList","protoTypeSymbol","literalOf","tsFieldName","toString","isNullable","name","ScalarType","isCustomScalar","needsTypeAssertion","protobuf","inputObjectRefType","createImportSymbol","refCode","pothosRefPrintable","pothosBuilderPrintable","typeName","compactForCodegen","length","createFieldRefCode","createNoopFieldRefCode","input","extensions","protobufGraphQLExtensions","description","codes","push","createToProtoFuncCode","oneofFields","protoTypeSym","fieldAssignments","localName","toProtoFunc","toProtoFuncPrintable","EnumType","Error","oneofAssignments","Object","values","oneofName","cases","caseName","protoSchemaSym","protoSchemaSymbol","toProtoFuncName","protobufCreateSymbol","InterfaceType","protobufGraphQLExtensions","tsFieldName","createObjectTypeCode","type","registry","opts","isInterface","InterfaceType","typeOpts","name","typeName","fields","code","length","joinCode","map","f","createFieldRefCode","createNoopFieldRefCode","input","description","isTypeOf","undefined","createIsTypeOfFuncCode","extensions","protobufGraphQLExtensions","buildRefFunc","pothosBuilderPrintable","buildTypeFunc","refFuncTypeArg","protoRefTypePrintable","proto","literalOf","tsFieldName","pothosRefPrintable","compactForCodegen","_registry","protobuf","protoTypeSymbol","protobufIsMessageSymbol","protoSchemaSymbol","protobufGraphQLExtensions","createOneofUnionTypeCode","type","registry","opts","typeOpts","types","fields","map","f","fieldTypeRefPrintable","description","extensions","protobufGraphQLExtensions","code","pothosRefPrintable","pothosBuilderPrintable","literalOf","typeName","compactForCodegen","createTypeDslPrintables","types","registry","opts","flatMap","type","ObjectType","createObjectTypeCode","InputObjectType","createInputObjectTypeCode","EnumType","createEnumTypeCode","OneofUnionType","SquashedOneofUnionType","createOneofUnionTypeCode","_exhaustiveCheck","allowedProtobufs","generateFiles","schema","file","opts","options","includes","printer","protobuf","registry","createRegistryFromSchema","types","collectTypesFromFile","type","allFiles","f","generateFile","filenameFromProtoFile","printables","createTypeDslPrintables","preamble","length","print","p","protocGenPothos","createEcmaScriptPlugin","name","version","generateTs","createTsGenerator","generateFiles","dsl","parseOptions","parsePothosOptions","transpile","files","map","f","content","formatCode","runNodeJs","protocGenPothos"]}
|
|
@@ -16,6 +16,12 @@ export declare function pothosBuilderPrintable(opts: Pick<PothosPrinterOptions,
|
|
|
16
16
|
export declare function protoTypeSymbol(proto: DescMessage | DescEnum, opts: Pick<PrinterOptions, "protobuf" | "importPrefix">): ImportSymbol;
|
|
17
17
|
/**
|
|
18
18
|
* protobuf-es v2 用: Schema シンボル (例: UserSchema, Parent_ChildSchema) を生成
|
|
19
|
+
*
|
|
20
|
+
* protobuf-es の @bufbuild/protoplugin が行う名前衝突回避ロジックを再実装。
|
|
21
|
+
* 同一ファイル内で shape 名 (型名) と desc 名 (Schema 定数名) が衝突する場合、
|
|
22
|
+
* protobuf-es は salt suffix ($, $1, $2, ...) を付与する。
|
|
23
|
+
*
|
|
24
|
+
* @see {@link https://github.com/bufbuild/protobuf-es/blob/v2.10.2/packages/protoplugin/src/names.ts | @bufbuild/protoplugin names.ts}
|
|
19
25
|
*/
|
|
20
26
|
export declare function protoSchemaSymbol(proto: DescMessage | DescEnum, opts: Pick<PrinterOptions, "protobuf" | "importPrefix">): ImportSymbol;
|
|
21
27
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../src/dslgen/printers/util.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../src/dslgen/printers/util.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,QAAQ,EAGR,WAAW,EAEZ,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,KAAK,QAAQ,EAEb,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC5B,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,cAAc,EAAE;IAAE,GAAG,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC;AAE9E,wBAAgB,aAAa,CAC3B,IAAI,EACA,UAAU,GACV,eAAe,GACf,QAAQ,GACR,cAAc,GACd,sBAAsB,GACtB,aAAa,GAChB,MAAM,CAER;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAE3D;AAwBD,wBAAgB,qBAAqB,CACnC,KAAK,EACD,WAAW,CACT,UAAU,GAAG,QAAQ,GAAG,a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BAAqB,CACnC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE,UAAU,GAAG,cAAc,CAAC,GACtD,SAAS,EAAE,CAUb"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protoc-gen-pothos",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Generate DSL for Pothos GraphQL from Protocol Buffers IDL",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -61,12 +61,12 @@
|
|
|
61
61
|
"graphql": "16.9.0",
|
|
62
62
|
"graphql-scalars": "^1.24.0",
|
|
63
63
|
"tsx": "^4.21.0",
|
|
64
|
-
"@proto-graphql/e2e-testapis-
|
|
64
|
+
"@proto-graphql/e2e-testapis-ts-proto": "0.0.0",
|
|
65
65
|
"@proto-graphql/e2e-testapis-protobuf-es-v2": "0.0.0",
|
|
66
|
-
"@proto-graphql/e2e-testapis-
|
|
66
|
+
"@proto-graphql/e2e-testapis-protobuf-es": "0.0.0",
|
|
67
67
|
"@proto-graphql/testapis-proto": "0.1.1",
|
|
68
68
|
"@proto-graphql/tsconfig": "0.1.1",
|
|
69
|
-
"@proto-graphql/e2e-testapis-ts-proto": "0.0.0"
|
|
69
|
+
"@proto-graphql/e2e-testapis-ts-proto-with-forcelong-number": "0.0.0"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"build": "tsup && cp -r ../../docs/protoc-gen-pothos docs",
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
DescEnum,
|
|
5
|
+
DescExtension,
|
|
6
|
+
DescFile,
|
|
7
|
+
DescMessage,
|
|
8
|
+
DescService,
|
|
9
|
+
} from "@bufbuild/protobuf";
|
|
10
|
+
import { nestedTypes } from "@bufbuild/protobuf/reflect";
|
|
11
|
+
import { safeIdentifier } from "@bufbuild/protoplugin";
|
|
4
12
|
import {
|
|
5
13
|
type EnumType,
|
|
6
14
|
filename,
|
|
@@ -143,22 +151,130 @@ export function protoTypeSymbol(
|
|
|
143
151
|
|
|
144
152
|
/**
|
|
145
153
|
* protobuf-es v2 用: Schema シンボル (例: UserSchema, Parent_ChildSchema) を生成
|
|
154
|
+
*
|
|
155
|
+
* protobuf-es の @bufbuild/protoplugin が行う名前衝突回避ロジックを再実装。
|
|
156
|
+
* 同一ファイル内で shape 名 (型名) と desc 名 (Schema 定数名) が衝突する場合、
|
|
157
|
+
* protobuf-es は salt suffix ($, $1, $2, ...) を付与する。
|
|
158
|
+
*
|
|
159
|
+
* @see {@link https://github.com/bufbuild/protobuf-es/blob/v2.10.2/packages/protoplugin/src/names.ts | @bufbuild/protoplugin names.ts}
|
|
146
160
|
*/
|
|
147
161
|
export function protoSchemaSymbol(
|
|
148
162
|
proto: DescMessage | DescEnum,
|
|
149
163
|
opts: Pick<PrinterOptions, "protobuf" | "importPrefix">,
|
|
150
164
|
): ImportSymbol {
|
|
151
|
-
const
|
|
152
|
-
let current: DescMessage | DescEnum = proto;
|
|
153
|
-
while (current.parent != null) {
|
|
154
|
-
current = current.parent;
|
|
155
|
-
chunks.unshift(current.name);
|
|
156
|
-
}
|
|
157
|
-
const symbolName = `${chunks.join("_")}Schema`;
|
|
165
|
+
const symbolName = resolveProtobufEsDescName(proto);
|
|
158
166
|
const importPath = protoImportPath(proto, opts);
|
|
159
167
|
return createImportSymbol(symbolName, importPath);
|
|
160
168
|
}
|
|
161
169
|
|
|
170
|
+
function protobufEsSalt(i: number): string {
|
|
171
|
+
if (i === 0) return "";
|
|
172
|
+
if (i === 1) return "$";
|
|
173
|
+
return `$${i - 1}`;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function idealShapeName(desc: DescMessage | DescEnum, i: number): string {
|
|
177
|
+
return safeIdentifier(
|
|
178
|
+
protobufEsIdentifierForNested(desc) + protobufEsSalt(i),
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
type NestedDesc = DescMessage | DescEnum | DescExtension | DescService;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* protobuf-es と同じ identifier 計算。
|
|
186
|
+
* パッケージ名を除去し、ドット (ネスト区切り) をアンダースコアに置換する。
|
|
187
|
+
*/
|
|
188
|
+
function protobufEsIdentifierForNested(desc: NestedDesc): string {
|
|
189
|
+
const pkg = desc.file.proto.package;
|
|
190
|
+
const offset = pkg.length > 0 ? pkg.length + 1 : 0;
|
|
191
|
+
return desc.typeName.substring(offset).replace(/\./g, "_");
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function idealDescName(desc: NestedDesc | DescFile, i: number): string {
|
|
195
|
+
const salt = protobufEsSalt(i);
|
|
196
|
+
if (desc.kind === "file") {
|
|
197
|
+
const name = `file_${desc.name.replace(/[^a-zA-Z0-9_]+/g, "_")}`;
|
|
198
|
+
return safeIdentifier(name + salt);
|
|
199
|
+
}
|
|
200
|
+
if (desc.kind === "enum" || desc.kind === "message") {
|
|
201
|
+
return safeIdentifier(
|
|
202
|
+
protobufEsIdentifierForNested(desc) + "Schema" + salt,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
// extension, service: Schema suffix なし
|
|
206
|
+
return safeIdentifier(protobufEsIdentifierForNested(desc) + salt);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ファイル単位のキャッシュ: 同一ファイル内の複数の型に対して重複計算を避ける
|
|
210
|
+
const descNameCache = new WeakMap<
|
|
211
|
+
DescFile,
|
|
212
|
+
Map<DescMessage | DescEnum, string>
|
|
213
|
+
>();
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @bufbuild/protoplugin の allNames() と同じロジックで desc 名を解決する。
|
|
217
|
+
*
|
|
218
|
+
* 1. Pass 1: 全 message/enum の shape 名を登録
|
|
219
|
+
* 2. Pass 2: file desc + 全 nested types の desc 名を登録 (衝突時は salt suffix を付与)
|
|
220
|
+
*/
|
|
221
|
+
function resolveProtobufEsDescName(proto: DescMessage | DescEnum): string {
|
|
222
|
+
const file = proto.file;
|
|
223
|
+
|
|
224
|
+
const cached = descNameCache.get(file);
|
|
225
|
+
if (cached) {
|
|
226
|
+
const name = cached.get(proto);
|
|
227
|
+
if (name !== undefined) return name;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const taken = new Set<string>();
|
|
231
|
+
const descNames = new Map<DescMessage | DescEnum, string>();
|
|
232
|
+
|
|
233
|
+
// Pass 1: shape 名 (message/enum のみ)
|
|
234
|
+
for (const desc of nestedTypes(file)) {
|
|
235
|
+
if (desc.kind !== "enum" && desc.kind !== "message") continue;
|
|
236
|
+
let name: string;
|
|
237
|
+
for (let i = 0; ; i++) {
|
|
238
|
+
name = idealShapeName(desc, i);
|
|
239
|
+
if (!taken.has(name)) break;
|
|
240
|
+
}
|
|
241
|
+
taken.add(name);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Pass 2: desc 名 (file + 全 nested types)
|
|
245
|
+
{
|
|
246
|
+
// file descriptor 自体の desc 名を登録
|
|
247
|
+
let fileName: string;
|
|
248
|
+
for (let i = 0; ; i++) {
|
|
249
|
+
fileName = idealDescName(file, i);
|
|
250
|
+
if (!taken.has(fileName)) break;
|
|
251
|
+
}
|
|
252
|
+
taken.add(fileName);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
for (const desc of nestedTypes(file) as Iterable<NestedDesc>) {
|
|
256
|
+
let name: string;
|
|
257
|
+
for (let i = 0; ; i++) {
|
|
258
|
+
name = idealDescName(desc, i);
|
|
259
|
+
if (!taken.has(name)) break;
|
|
260
|
+
}
|
|
261
|
+
taken.add(name);
|
|
262
|
+
if (desc.kind === "message" || desc.kind === "enum") {
|
|
263
|
+
descNames.set(desc, name);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
descNameCache.set(file, descNames);
|
|
268
|
+
|
|
269
|
+
const result = descNames.get(proto);
|
|
270
|
+
if (result === undefined) {
|
|
271
|
+
throw new Error(
|
|
272
|
+
`Unable to determine protobuf-es desc name for ${proto.toString()}`,
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
|
|
162
278
|
/**
|
|
163
279
|
* @bufbuild/protobuf から create 関数を import
|
|
164
280
|
*/
|