payload-live-preview 1.8.0 → 2.0.0-beta.0

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.
Files changed (98) hide show
  1. package/README.md +301 -93
  2. package/dist/adapters/astro/PreviewBoundary.astro +66 -0
  3. package/dist/adapters/astro/RichText.astro +6 -0
  4. package/dist/adapters/astro/index.d.ts +165 -134
  5. package/dist/adapters/astro/index.js +1 -1
  6. package/dist/adapters/astro/index.js.map +1 -1
  7. package/dist/adapters/astro/middleware-entry.d.ts +4 -9
  8. package/dist/adapters/astro/middleware-entry.js +1 -1
  9. package/dist/adapters/astro/middleware-entry.js.map +1 -1
  10. package/dist/adapters/nextjs/index.d.ts +13 -80
  11. package/dist/adapters/nextjs/index.js +1 -1
  12. package/dist/adapters/nextjs/index.js.map +1 -1
  13. package/dist/adapters/nuxt/index.d.ts +46 -106
  14. package/dist/adapters/nuxt/index.js +1 -1
  15. package/dist/adapters/nuxt/index.js.map +1 -1
  16. package/dist/adapters/sveltekit/index.d.ts +10 -75
  17. package/dist/adapters/sveltekit/index.js +1 -1
  18. package/dist/adapters/sveltekit/index.js.map +1 -1
  19. package/dist/client.cjs +2 -0
  20. package/dist/client.cjs.map +1 -0
  21. package/dist/client.d.cts +747 -0
  22. package/dist/client.d.ts +747 -0
  23. package/dist/client.js +2 -0
  24. package/dist/client.js.map +1 -0
  25. package/dist/codegen-astro.d.ts +5 -27
  26. package/dist/codegen-astro.js +1 -1
  27. package/dist/codegen-astro.js.map +1 -1
  28. package/dist/codegen-cli.d.ts +3 -16
  29. package/dist/codegen-cli.js +1 -1
  30. package/dist/codegen-cli.js.map +1 -1
  31. package/dist/codegen.cjs +1 -1
  32. package/dist/codegen.cjs.map +1 -1
  33. package/dist/codegen.d.cts +37 -124
  34. package/dist/codegen.d.ts +37 -124
  35. package/dist/codegen.js +1 -1
  36. package/dist/codegen.js.map +1 -1
  37. package/dist/core.cjs +1 -1
  38. package/dist/core.cjs.map +1 -1
  39. package/dist/core.d.cts +647 -1100
  40. package/dist/core.d.ts +647 -1100
  41. package/dist/core.js +1 -1
  42. package/dist/core.js.map +1 -1
  43. package/dist/doctor-cli.d.ts +3 -28
  44. package/dist/doctor-cli.js +1 -1
  45. package/dist/doctor-cli.js.map +1 -1
  46. package/dist/doctor.d.ts +16 -32
  47. package/dist/doctor.js +1 -1
  48. package/dist/doctor.js.map +1 -1
  49. package/dist/fragment.cjs +2 -0
  50. package/dist/fragment.cjs.map +1 -0
  51. package/dist/fragment.d.cts +333 -0
  52. package/dist/fragment.d.ts +333 -0
  53. package/dist/fragment.js +2 -0
  54. package/dist/fragment.js.map +1 -0
  55. package/dist/index.cjs +1 -1
  56. package/dist/index.cjs.map +1 -1
  57. package/dist/index.d.cts +885 -1531
  58. package/dist/index.d.ts +885 -1531
  59. package/dist/index.js +1 -1
  60. package/dist/index.js.map +1 -1
  61. package/dist/lexical.cjs +2 -0
  62. package/dist/lexical.cjs.map +1 -0
  63. package/dist/lexical.d.cts +90 -0
  64. package/dist/lexical.d.ts +90 -0
  65. package/dist/lexical.js +2 -0
  66. package/dist/lexical.js.map +1 -0
  67. package/dist/middleware-CEPsY1P7.d.ts +40 -0
  68. package/dist/migrate.d.ts +73 -0
  69. package/dist/migrate.js +2 -0
  70. package/dist/migrate.js.map +1 -0
  71. package/dist/options-CEzzfHJu.d.ts +197 -0
  72. package/dist/payload.cjs +1 -1
  73. package/dist/payload.cjs.map +1 -1
  74. package/dist/payload.d.cts +11 -80
  75. package/dist/payload.d.ts +11 -80
  76. package/dist/payload.js +1 -1
  77. package/dist/payload.js.map +1 -1
  78. package/dist/plugins.cjs +2 -0
  79. package/dist/plugins.cjs.map +1 -0
  80. package/dist/plugins.d.cts +509 -0
  81. package/dist/plugins.d.ts +509 -0
  82. package/dist/plugins.js +2 -0
  83. package/dist/plugins.js.map +1 -0
  84. package/dist/{probe-tMHdim5y.d.ts → probe-CYtvj_Lm.d.ts} +43 -77
  85. package/dist/server.cjs +2 -0
  86. package/dist/server.cjs.map +1 -0
  87. package/dist/server.d.cts +435 -0
  88. package/dist/server.d.ts +435 -0
  89. package/dist/server.js +2 -0
  90. package/dist/server.js.map +1 -0
  91. package/dist/structural.cjs +3 -0
  92. package/dist/structural.cjs.map +1 -0
  93. package/dist/structural.d.cts +243 -0
  94. package/dist/structural.d.ts +243 -0
  95. package/dist/structural.js +3 -0
  96. package/dist/structural.js.map +1 -0
  97. package/package.json +86 -7
  98. package/dist/middleware-DD4Hwomt.d.ts +0 -189
@@ -1 +1 @@
1
- {"version":3,"file":"codegen.cjs","names":["SCALAR_TYPE_MAP","text","textarea","email","richText","number","checkbox","date","code","point","ui","radio","extractField","literal","type","readStringProperty","STRUCTURAL_TYPES","Set","name","has","base","required","readBooleanProperty","localized","kind","fields","extractNestedFields","blocks","extractBlocks","flattened","extractNestedFieldsFromStructural","target","readRelationTarget","hasMany","readRelationTargetSingle","options","readSelectOptions","typeRef","fieldsLiteral","readArrayProperty","out","element","getElements","Node","isObjectLiteralExpression","f","push","tabsLiteral","tabElement","tabName","tabFields","blocksLiteral","slug","typeName","toPascalCase","property","getProperty","isPropertyAssignment","initialiser","getInitializer","isStringLiteral","getLiteralValue","isArrayLiteralExpression","filter","map","el","optionsLiteral","value","isNoSubstitutionTemplateLiteral","getKind","SyntaxKind","TrueKeyword","FalseKeyword","node","split","Boolean","part","charAt","toUpperCase","slice","join","extractSchema","project","Project","tsConfigFilePath","skipAddingFilesFromTsConfig","sourceFile","addSourceFileAtPathIfExists","configPath","globals","collections","diagnostics","resolveSourceFileDependencies","configLiteral","findConfigLiteral","extractSlugList","defaultExport","getExportSymbols","find","sym","getName","declarations","getDeclarations","decl","candidate","unwrapToObjectLiteral","call","getDescendantsOfKind","CallExpression","expr","getExpression","isIdentifier","getText","arg","getArguments","isExportAssignment","unwrapExpression","isVariableDeclaration","isCallExpression","isAsExpression","isSatisfiesExpression","resolveIdentifierToObjectLiteral","identifier","getDefinitionNodes","result","key","array","resolveToArrayLiteral","extractEntries","isSpreadElement","expandedArray","resolveToObjectLiteral","extractFieldList","configEntry","fieldsProperty","expanded","inner","field","resolved","__name","DEFAULT_HEADER","emitTypes","schema","lines","header","seenAuxNames","emitSlug","length","g","c","slugAliases","replace","emitAuxiliaries","emitFieldMember","prefix","auxName","nestedTypeName","add","block","blockTypeName","emitBlockInterface","parent","markLocalizedAsDeprecated","optional","renderFieldType","b","Array","isArray","t","o","child","STRUCTURAL_SENTINEL","collect","basePath","path","entry","buildPreviewInventory","checkPreviewBindings","inventory","bindings","byKey","Map","entries","item","set","seen","binding","where","source","paths","get","bound","reportUnbound","async","generateTypes","cwd","process","isAbsolute","resolve","outFile","inventoryFile","mkdir","dirname","recursive","writeFile","JSON","stringify","exports","$","oe","O","L","Fe"],"sources":["../src/codegen/parser/extract-field.ts","../src/codegen/parser/extract-schema.ts","../src/codegen/emit/emit-types.ts","../src/codegen/inventory.ts","../src/codegen/index.ts"],"sourcesContent":["/**\n * Field-level extraction from ts-morph object literals.\n *\n * Payload field definitions are TypeScript object literals like:\n *\n * ```ts\n * { name: 'heroTitle', type: 'text', required: true }\n * ```\n *\n * `extractField()` reads one such literal and produces a normalised\n * `ExtractedField`. It is intentionally tolerant — unknown field types\n * collapse to `unknown`, deeply-conditional fields surface as a\n * diagnostic rather than crashing the parser.\n *\n * @module @codegen/parser/extract-field\n */\n\nimport {\n Node,\n SyntaxKind,\n type ArrayLiteralExpression,\n type ObjectLiteralExpression,\n type PropertyAssignment,\n} from 'ts-morph';\nimport type { ExtractedBlock, ExtractedField, ExtractedScalarField } from './types';\n\nconst SCALAR_TYPE_MAP: Readonly<Record<string, ExtractedScalarField['typeRef']>> = {\n text: 'string',\n textarea: 'string',\n email: 'string',\n richText: 'unknown',\n number: 'number',\n checkbox: 'boolean',\n date: 'string',\n code: 'string',\n point: 'unknown',\n ui: 'unknown',\n radio: 'string',\n};\n\nexport function extractField(literal: ObjectLiteralExpression): ExtractedField | undefined {\n const type = readStringProperty(literal, 'type');\n if (type === undefined) return undefined;\n\n // Most fields carry a `name`. Structural containers (`tabs`,\n // `row`, `collapsible`) do not — they flatten into their parent.\n const STRUCTURAL_TYPES = new Set(['tabs', 'row', 'collapsible']);\n const name = readStringProperty(literal, 'name');\n if (name === undefined && !STRUCTURAL_TYPES.has(type)) return undefined;\n\n const required = readBooleanProperty(literal, 'required') ?? false;\n const localized = readBooleanProperty(literal, 'localized') ?? false;\n const base = { name: name ?? '__structural', required, localized };\n\n switch (type) {\n case 'array':\n return {\n ...base,\n kind: 'array',\n fields: extractNestedFields(literal),\n };\n case 'blocks':\n return {\n ...base,\n kind: 'blocks',\n blocks: extractBlocks(literal),\n };\n case 'group':\n return {\n ...base,\n kind: 'group',\n fields: extractNestedFields(literal),\n };\n case 'tabs':\n case 'row':\n case 'collapsible': {\n // Structural containers — flatten their inner fields up so they\n // appear at the parent's level (Payload does the same at runtime).\n const flattened = extractNestedFieldsFromStructural(literal);\n return {\n ...base,\n kind: 'group',\n fields: flattened,\n };\n }\n case 'relationship':\n return {\n ...base,\n kind: 'relationship',\n target: readRelationTarget(literal),\n hasMany: readBooleanProperty(literal, 'hasMany') ?? false,\n };\n case 'upload':\n return {\n ...base,\n kind: 'upload',\n target: readRelationTargetSingle(literal) ?? 'media',\n };\n case 'json':\n return { ...base, kind: 'json' };\n case 'select':\n return {\n ...base,\n kind: 'select',\n options: readSelectOptions(literal),\n hasMany: readBooleanProperty(literal, 'hasMany') ?? false,\n };\n default: {\n const typeRef = SCALAR_TYPE_MAP[type] ?? 'unknown';\n return { ...base, kind: 'scalar', typeRef };\n }\n }\n}\n\nfunction extractNestedFields(literal: ObjectLiteralExpression): readonly ExtractedField[] {\n const fieldsLiteral = readArrayProperty(literal, 'fields');\n if (!fieldsLiteral) return [];\n const out: ExtractedField[] = [];\n for (const element of fieldsLiteral.getElements()) {\n if (!Node.isObjectLiteralExpression(element)) continue;\n const f = extractField(element);\n if (!f) continue;\n // Structural containers carry the magic `__structural` sentinel\n // name — splat their child fields into the parent instead of\n // surfacing them as a nameless property.\n if (f.kind === 'group' && f.name === '__structural') {\n out.push(...f.fields);\n } else {\n out.push(f);\n }\n }\n return out;\n}\n\nfunction extractNestedFieldsFromStructural(\n literal: ObjectLiteralExpression,\n): readonly ExtractedField[] {\n // `tabs` is the awkward one — its inner shape is `tabs: [{ name, fields }, …]`\n // and each tab can either flatten via `name` or expose itself as a group.\n const tabsLiteral = readArrayProperty(literal, 'tabs');\n if (tabsLiteral) {\n const out: ExtractedField[] = [];\n for (const tabElement of tabsLiteral.getElements()) {\n if (!Node.isObjectLiteralExpression(tabElement)) continue;\n const tabName = readStringProperty(tabElement, 'name');\n const tabFields = extractNestedFields(tabElement);\n if (tabName !== undefined) {\n out.push({\n kind: 'group',\n name: tabName,\n required: false,\n localized: false,\n fields: tabFields,\n });\n } else {\n // Named-less tab — flatten its fields into the parent's surface.\n out.push(...tabFields);\n }\n }\n return out;\n }\n // `row` / `collapsible` — fields array sits directly on the literal.\n return extractNestedFields(literal);\n}\n\nfunction extractBlocks(literal: ObjectLiteralExpression): readonly ExtractedBlock[] {\n const blocksLiteral = readArrayProperty(literal, 'blocks');\n if (!blocksLiteral) return [];\n const out: ExtractedBlock[] = [];\n for (const element of blocksLiteral.getElements()) {\n if (!Node.isObjectLiteralExpression(element)) continue;\n const slug = readStringProperty(element, 'slug');\n if (slug === undefined) continue;\n out.push({\n slug,\n typeName: toPascalCase(slug),\n fields: extractNestedFields(element),\n });\n }\n return out;\n}\n\nfunction readRelationTarget(literal: ObjectLiteralExpression): string | readonly string[] {\n const property = literal.getProperty('relationTo');\n if (!property || !Node.isPropertyAssignment(property)) return 'unknown';\n const initialiser = property.getInitializer();\n if (initialiser && Node.isStringLiteral(initialiser)) return initialiser.getLiteralValue();\n if (initialiser && Node.isArrayLiteralExpression(initialiser)) {\n return initialiser\n .getElements()\n .filter(Node.isStringLiteral)\n .map((el) => el.getLiteralValue());\n }\n return 'unknown';\n}\n\nfunction readRelationTargetSingle(literal: ObjectLiteralExpression): string | undefined {\n const target = readRelationTarget(literal);\n if (typeof target === 'string') return target;\n return target[0];\n}\n\nfunction readSelectOptions(literal: ObjectLiteralExpression): readonly string[] {\n const optionsLiteral = readArrayProperty(literal, 'options');\n if (!optionsLiteral) return [];\n const out: string[] = [];\n for (const element of optionsLiteral.getElements()) {\n if (Node.isStringLiteral(element)) {\n out.push(element.getLiteralValue());\n } else if (Node.isObjectLiteralExpression(element)) {\n const value = readStringProperty(element, 'value');\n if (value !== undefined) out.push(value);\n }\n }\n return out;\n}\n\nfunction readStringProperty(literal: ObjectLiteralExpression, name: string): string | undefined {\n const property = literal.getProperty(name);\n if (!property || !isPropertyAssignment(property)) return undefined;\n const initialiser = property.getInitializer();\n if (initialiser && Node.isStringLiteral(initialiser)) return initialiser.getLiteralValue();\n if (initialiser && Node.isNoSubstitutionTemplateLiteral(initialiser)) {\n return initialiser.getLiteralValue();\n }\n return undefined;\n}\n\nfunction readBooleanProperty(literal: ObjectLiteralExpression, name: string): boolean | undefined {\n const property = literal.getProperty(name);\n if (!property || !isPropertyAssignment(property)) return undefined;\n const initialiser = property.getInitializer();\n if (!initialiser) return undefined;\n if (initialiser.getKind() === SyntaxKind.TrueKeyword) return true;\n if (initialiser.getKind() === SyntaxKind.FalseKeyword) return false;\n return undefined;\n}\n\nfunction readArrayProperty(\n literal: ObjectLiteralExpression,\n name: string,\n): ArrayLiteralExpression | undefined {\n const property = literal.getProperty(name);\n if (!property || !isPropertyAssignment(property)) return undefined;\n const initialiser = property.getInitializer();\n if (initialiser && Node.isArrayLiteralExpression(initialiser)) return initialiser;\n return undefined;\n}\n\nfunction isPropertyAssignment(node: Node): node is PropertyAssignment {\n return Node.isPropertyAssignment(node);\n}\n\nfunction toPascalCase(slug: string): string {\n return slug\n .split(/[-_\\s]+/)\n .filter(Boolean)\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('');\n}\n\nexport { toPascalCase };\n","/**\n * Schema-level extraction: open `payload.config.ts`, find every\n * collection and global definition, walk into them.\n *\n * The extractor is deliberately lenient. Payload configurations are\n * full TypeScript programs — a strict parser would have to model\n * conditional types, factory functions, plugin closures. Instead we\n * recognise the *common* shapes (object literal, identifier\n * referencing an imported literal, default export from a sibling\n * file) and emit a diagnostic for anything we can't unwrap.\n *\n * @module @codegen/parser/extract-schema\n */\n\nimport {\n Node,\n Project,\n SyntaxKind,\n type ArrayLiteralExpression,\n type Identifier,\n type ObjectLiteralExpression,\n type SourceFile,\n} from 'ts-morph';\nimport type { ExtractedField, ExtractedSchema, ExtractedSlug } from './types';\nimport { extractField, toPascalCase } from './extract-field';\n\nexport interface ExtractSchemaOptions {\n /** Absolute or relative path to `payload.config.ts`. */\n readonly configPath: string;\n /** When provided, used instead of constructing a fresh ts-morph project. */\n readonly project?: Project;\n /**\n * Optional path to a `tsconfig.json`. When set, ts-morph loads the\n * project's module-resolution configuration so cross-file imports\n * (Homepage from './globals') can be followed.\n */\n readonly tsConfigFilePath?: string;\n}\n\nexport function extractSchema(options: ExtractSchemaOptions): ExtractedSchema {\n const project =\n options.project ??\n new Project(\n options.tsConfigFilePath !== undefined\n ? { tsConfigFilePath: options.tsConfigFilePath }\n : { skipAddingFilesFromTsConfig: true },\n );\n const sourceFile = project.addSourceFileAtPathIfExists(options.configPath);\n if (!sourceFile) {\n return {\n globals: [],\n collections: [],\n diagnostics: [`Could not open ${options.configPath}`],\n };\n }\n // Pull in every transitively-imported file so cross-file identifier\n // resolution (e.g., `import { Homepage } from './globals'`) can\n // reach the underlying object literal.\n project.resolveSourceFileDependencies();\n const diagnostics: string[] = [];\n\n const configLiteral = findConfigLiteral(sourceFile, diagnostics);\n if (!configLiteral) {\n return {\n globals: [],\n collections: [],\n diagnostics: [\n ...diagnostics,\n 'Could not locate a buildConfig({...}) call or `export default {...}` in the config file.',\n ],\n };\n }\n\n const globals = extractSlugList(configLiteral, 'globals', diagnostics);\n const collections = extractSlugList(configLiteral, 'collections', diagnostics);\n\n return { globals, collections, diagnostics };\n}\n\nfunction findConfigLiteral(\n sourceFile: SourceFile,\n diagnostics: string[],\n): ObjectLiteralExpression | undefined {\n const defaultExport = sourceFile.getExportSymbols().find((sym) => sym.getName() === 'default');\n if (!defaultExport) {\n diagnostics.push('payload.config.ts has no default export.');\n return undefined;\n }\n const declarations = defaultExport.getDeclarations();\n for (const decl of declarations) {\n const candidate = unwrapToObjectLiteral(decl);\n if (candidate) return candidate;\n }\n // Fallback: scan the source file for the first `buildConfig({...})` call.\n for (const call of sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)) {\n const expr = call.getExpression();\n if (Node.isIdentifier(expr) && expr.getText() === 'buildConfig') {\n const arg = call.getArguments()[0];\n if (arg && Node.isObjectLiteralExpression(arg)) return arg;\n }\n }\n return undefined;\n}\n\nfunction unwrapToObjectLiteral(node: Node): ObjectLiteralExpression | undefined {\n if (Node.isExportAssignment(node)) {\n return unwrapExpression(node.getExpression());\n }\n if (Node.isVariableDeclaration(node)) {\n const initialiser = node.getInitializer();\n if (initialiser) return unwrapExpression(initialiser);\n }\n return undefined;\n}\n\nfunction unwrapExpression(node: Node | undefined): ObjectLiteralExpression | undefined {\n if (!node) return undefined;\n if (Node.isObjectLiteralExpression(node)) return node;\n if (Node.isCallExpression(node)) {\n // `buildConfig({...})` or `defineConfig({...})` — first arg.\n const arg = node.getArguments()[0];\n if (arg && Node.isObjectLiteralExpression(arg)) return arg;\n }\n if (Node.isAsExpression(node)) {\n return unwrapExpression(node.getExpression());\n }\n if (Node.isSatisfiesExpression(node)) {\n return unwrapExpression(node.getExpression());\n }\n if (Node.isIdentifier(node)) {\n return resolveIdentifierToObjectLiteral(node);\n }\n return undefined;\n}\n\nfunction resolveIdentifierToObjectLiteral(\n identifier: Identifier,\n): ObjectLiteralExpression | undefined {\n for (const decl of identifier.getDefinitionNodes()) {\n const result = unwrapToObjectLiteral(decl);\n if (result) return result;\n }\n return undefined;\n}\n\nfunction extractSlugList(\n configLiteral: ObjectLiteralExpression,\n key: 'globals' | 'collections',\n diagnostics: string[],\n): readonly ExtractedSlug[] {\n const property = configLiteral.getProperty(key);\n if (!property) return [];\n if (!Node.isPropertyAssignment(property)) return [];\n const initialiser = property.getInitializer();\n if (!initialiser) return [];\n const array = resolveToArrayLiteral(initialiser);\n if (!array) return [];\n return extractEntries(array, diagnostics);\n}\n\nfunction extractEntries(\n array: ArrayLiteralExpression,\n diagnostics: string[],\n): readonly ExtractedSlug[] {\n const out: ExtractedSlug[] = [];\n for (const element of array.getElements()) {\n // Handle `...someArray` spreads — common pattern in real Payload\n // configs that split globals/collections into named buckets.\n if (Node.isSpreadElement(element)) {\n const expandedArray = resolveToArrayLiteral(element.getExpression());\n if (!expandedArray) {\n diagnostics.push(\n `Could not resolve spread \"${element.getText().slice(0, 80)}\" to an array literal.`,\n );\n continue;\n }\n out.push(...extractEntries(expandedArray, diagnostics));\n continue;\n }\n const literal = resolveToObjectLiteral(element);\n if (!literal) {\n diagnostics.push(\n `Could not resolve config entry \"${element.getText().slice(0, 80)}\" to an object literal.`,\n );\n continue;\n }\n const slug = readStringProperty(literal, 'slug');\n if (slug === undefined) {\n diagnostics.push(`Skipping a config entry — no string \\`slug\\` field found.`);\n continue;\n }\n out.push({\n slug,\n typeName: toPascalCase(slug),\n fields: extractFieldList(literal),\n });\n }\n return out;\n}\n\nfunction extractFieldList(configEntry: ObjectLiteralExpression): readonly ExtractedField[] {\n const fieldsProperty = configEntry.getProperty('fields');\n if (!fieldsProperty || !Node.isPropertyAssignment(fieldsProperty)) return [];\n const initialiser = fieldsProperty.getInitializer();\n if (!initialiser || !Node.isArrayLiteralExpression(initialiser)) return [];\n const out: ExtractedField[] = [];\n for (const element of initialiser.getElements()) {\n // Allow spread elements for users who split fields into reusable\n // arrays (e.g., `...commonSeoFields`).\n if (Node.isSpreadElement(element)) {\n const expanded = resolveToArrayLiteral(element.getExpression());\n if (!expanded) continue;\n for (const inner of expanded.getElements()) {\n const literal = resolveToObjectLiteral(inner);\n if (!literal) continue;\n const field = extractField(literal);\n if (!field) continue;\n if (field.kind === 'group' && field.name === '__structural') {\n out.push(...field.fields);\n } else {\n out.push(field);\n }\n }\n continue;\n }\n const literal = resolveToObjectLiteral(element);\n if (!literal) continue;\n const field = extractField(literal);\n if (!field) continue;\n if (field.kind === 'group' && field.name === '__structural') {\n out.push(...field.fields);\n } else {\n out.push(field);\n }\n }\n return out;\n}\n\nfunction resolveToObjectLiteral(node: Node): ObjectLiteralExpression | undefined {\n if (Node.isObjectLiteralExpression(node)) return node;\n if (Node.isIdentifier(node)) return resolveIdentifierToObjectLiteral(node);\n if (Node.isAsExpression(node)) return resolveToObjectLiteral(node.getExpression());\n if (Node.isSatisfiesExpression(node)) return resolveToObjectLiteral(node.getExpression());\n if (Node.isCallExpression(node)) {\n const arg = node.getArguments()[0];\n if (arg) return resolveToObjectLiteral(arg);\n }\n return undefined;\n}\n\nfunction resolveToArrayLiteral(node: Node): ArrayLiteralExpression | undefined {\n if (Node.isArrayLiteralExpression(node)) return node;\n if (Node.isAsExpression(node)) return resolveToArrayLiteral(node.getExpression());\n if (Node.isSatisfiesExpression(node)) return resolveToArrayLiteral(node.getExpression());\n if (Node.isIdentifier(node)) {\n for (const decl of node.getDefinitionNodes()) {\n if (Node.isVariableDeclaration(decl)) {\n const initialiser = decl.getInitializer();\n if (initialiser) {\n const resolved = resolveToArrayLiteral(initialiser);\n if (resolved) return resolved;\n }\n }\n }\n }\n return undefined;\n}\n\nfunction readStringProperty(literal: ObjectLiteralExpression, name: string): string | undefined {\n const property = literal.getProperty(name);\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n const initialiser = property.getInitializer();\n if (initialiser && Node.isStringLiteral(initialiser)) return initialiser.getLiteralValue();\n return undefined;\n}\n","/**\n * Render `ExtractedSchema` to a TypeScript source string.\n *\n * The output is one self-contained `.ts` file that ships:\n *\n * - one `interface` per global and per collection,\n * - nested `interface` declarations for `group`/`array`/`blocks`,\n * - discriminated unions for `blocks` fields (one variant per slug),\n * - `PayloadCollections` / `PayloadGlobals` maps for slug-keyed\n * access (`PayloadCollections['posts']`), and\n * - a `PayloadSlug` alias.\n *\n * Nothing in the runtime depends on this output — consumers import\n * what they need by name.\n *\n * @module @codegen/emit/emit-types\n */\n\nimport type {\n ExtractedBlock,\n ExtractedField,\n ExtractedSchema,\n ExtractedSlug,\n} from '../parser/types';\nimport { toPascalCase } from '../parser/extract-field';\n\nexport interface EmitOptions {\n /** When true, includes a `@deprecated` JSDoc on localized fields. */\n readonly markLocalizedAsDeprecated?: boolean;\n /** Header text injected at the top of the output. Defaults sensibly. */\n readonly header?: string;\n}\n\nconst DEFAULT_HEADER =\n '// Auto-generated by payload-live-preview/codegen.\\n' +\n '// Do not edit by hand — run `pll-codegen` to regenerate.\\n' +\n '/* eslint-disable */';\n\nexport function emitTypes(schema: ExtractedSchema, options: EmitOptions = {}): string {\n const lines: string[] = [];\n lines.push(options.header ?? DEFAULT_HEADER);\n lines.push('');\n lines.push('import type { PayloadMedia, PayloadRelationship } from \"payload-live-preview\";');\n lines.push('');\n\n // Emit slug interfaces (globals + collections), each potentially\n // accompanied by nested interface declarations.\n const seenAuxNames = new Set<string>();\n for (const slug of [...schema.globals, ...schema.collections]) {\n emitSlug(slug, lines, seenAuxNames, options);\n lines.push('');\n }\n\n // Slug → type maps.\n if (schema.globals.length > 0) {\n lines.push('export type PayloadGlobals = {');\n for (const g of schema.globals) {\n lines.push(` '${g.slug}': ${g.typeName};`);\n }\n lines.push('};');\n lines.push('');\n }\n if (schema.collections.length > 0) {\n lines.push('export type PayloadCollections = {');\n for (const c of schema.collections) {\n lines.push(` '${c.slug}': ${c.typeName};`);\n }\n lines.push('};');\n lines.push('');\n }\n const slugAliases: string[] = [];\n if (schema.globals.length > 0) slugAliases.push('keyof PayloadGlobals');\n if (schema.collections.length > 0) slugAliases.push('keyof PayloadCollections');\n if (slugAliases.length > 0) {\n lines.push(`export type PayloadSlug = ${slugAliases.join(' | ')};`);\n lines.push('');\n }\n\n return lines.join('\\n').replace(/\\n{3,}/g, '\\n\\n');\n}\n\nfunction emitSlug(\n slug: ExtractedSlug,\n lines: string[],\n seenAuxNames: Set<string>,\n options: EmitOptions,\n): void {\n emitAuxiliaries(slug.typeName, slug.fields, lines, seenAuxNames, options);\n lines.push(`export interface ${slug.typeName} {`);\n for (const field of slug.fields) {\n emitFieldMember(field, slug.typeName, lines, options);\n }\n lines.push('}');\n}\n\nfunction emitAuxiliaries(\n prefix: string,\n fields: readonly ExtractedField[],\n lines: string[],\n seenAuxNames: Set<string>,\n options: EmitOptions,\n): void {\n for (const field of fields) {\n const auxName = nestedTypeName(prefix, field.name);\n if (field.kind === 'array' || field.kind === 'group') {\n if (seenAuxNames.has(auxName)) continue;\n seenAuxNames.add(auxName);\n emitAuxiliaries(auxName, field.fields, lines, seenAuxNames, options);\n lines.push(`export interface ${auxName} {`);\n for (const inner of field.fields) {\n emitFieldMember(inner, auxName, lines, options);\n }\n lines.push('}');\n lines.push('');\n } else if (field.kind === 'blocks') {\n for (const block of field.blocks) {\n const blockTypeName = nestedTypeName(auxName, block.typeName);\n if (seenAuxNames.has(blockTypeName)) continue;\n seenAuxNames.add(blockTypeName);\n emitAuxiliaries(blockTypeName, block.fields, lines, seenAuxNames, options);\n emitBlockInterface(blockTypeName, block, lines, options);\n }\n }\n }\n}\n\nfunction emitBlockInterface(\n typeName: string,\n block: ExtractedBlock,\n lines: string[],\n options: EmitOptions,\n): void {\n lines.push(`export interface ${typeName} {`);\n lines.push(` blockType: '${block.slug}';`);\n for (const field of block.fields) {\n emitFieldMember(field, typeName, lines, options);\n }\n lines.push('}');\n lines.push('');\n}\n\nfunction emitFieldMember(\n field: ExtractedField,\n parent: string,\n lines: string[],\n options: EmitOptions,\n): void {\n if (options.markLocalizedAsDeprecated && field.localized) {\n lines.push(` /** @localized */`);\n }\n const optional = field.required ? '' : '?';\n lines.push(` ${field.name}${optional}: ${renderFieldType(field, parent)};`);\n}\n\nfunction renderFieldType(field: ExtractedField, parent: string): string {\n switch (field.kind) {\n case 'scalar':\n return field.typeRef;\n case 'array':\n return `${nestedTypeName(parent, field.name)}[]`;\n case 'blocks': {\n if (field.blocks.length === 0) return 'unknown[]';\n const variants = field.blocks\n .map((b) => nestedTypeName(nestedTypeName(parent, field.name), b.typeName))\n .join(' | ');\n return `(${variants})[]`;\n }\n case 'group':\n return nestedTypeName(parent, field.name);\n case 'relationship': {\n const targetExpr: string = Array.isArray(field.target)\n ? field.target.map((t) => `'${t}'`).join(' | ')\n : `'${field.target as string}'`;\n const base = `PayloadRelationship<${targetExpr}>`;\n return field.hasMany ? `${base}[]` : base;\n }\n case 'upload':\n return 'PayloadMedia';\n case 'json':\n return 'unknown';\n case 'select': {\n if (field.options.length === 0) return field.hasMany ? 'string[]' : 'string';\n const literal = field.options.map((o) => `'${o}'`).join(' | ');\n return field.hasMany ? `(${literal})[]` : literal;\n }\n }\n}\n\nfunction nestedTypeName(parent: string, child: string): string {\n return `${parent}${toPascalCase(child)}`;\n}\n","/**\n * Preview inventory — which schema fields a binding can actually address.\n *\n * A live-preview integration has two halves that must agree: the Payload schema\n * and the markup that binds it. Nothing has verified the agreement, so every\n * consumer that cared has built its own inventory and its own scanner, and\n * re-derived a path convention this package already owns.\n *\n * The convention is not obvious, which is the point of publishing it rather\n * than documenting it:\n *\n * - `tabs`, `row` and `collapsible` contribute **no** path segment. The\n * parser marks unnamed ones with a `__structural` sentinel; emitting it\n * would produce `__structural.title` for a field the runtime resolves as\n * `title`.\n * - a `group` contributes its name (`hero.title`),\n * - an `array` addresses its items through `.*` (`slides.*.title`),\n * - a `blocks` field addresses each block through `.*.<slug>`.\n *\n * That is `@schema/walker`'s rule, deliberately: bindings are matched against\n * it at runtime, so an inventory using any other spelling would be wrong in the\n * one place it is supposed to help.\n *\n * @module @codegen/inventory\n */\n\nimport type { ExtractedField, ExtractedSchema, ExtractedSlug } from './parser/types';\n\n/** Sentinel the parser gives an unnamed structural container. */\nconst STRUCTURAL_SENTINEL = '__structural';\n\n/** One addressable field, spelled the way a binding must spell it. */\nexport interface PreviewInventoryField {\n /** Runtime binding path, e.g. `hero.title` or `slides.*.caption`. */\n readonly path: string;\n /** Extracted field kind: `scalar`, `array`, `blocks`, `group`, … */\n readonly kind: ExtractedField['kind'];\n readonly localized: boolean;\n readonly required: boolean;\n}\n\nexport interface PreviewInventoryEntry {\n readonly slug: string;\n readonly typeName: string;\n readonly fields: readonly PreviewInventoryField[];\n}\n\nexport interface PreviewInventory {\n readonly globals: readonly PreviewInventoryEntry[];\n readonly collections: readonly PreviewInventoryEntry[];\n}\n\nfunction collect(\n fields: readonly ExtractedField[],\n basePath: string,\n out: PreviewInventoryField[],\n): void {\n for (const field of fields) {\n // No segment, but its children still belong to the parent's surface.\n if (field.kind === 'group' && field.name === STRUCTURAL_SENTINEL) {\n collect(field.fields, basePath, out);\n continue;\n }\n const path = basePath === '' ? field.name : `${basePath}.${field.name}`;\n out.push({\n path,\n kind: field.kind,\n localized: field.localized,\n required: field.required,\n });\n if (field.kind === 'group') {\n collect(field.fields, path, out);\n } else if (field.kind === 'array') {\n collect(field.fields, `${path}.*`, out);\n } else if (field.kind === 'blocks') {\n for (const block of field.blocks) {\n collect(block.fields, `${path}.*.${block.slug}`, out);\n }\n }\n }\n}\n\nfunction entry(slug: ExtractedSlug): PreviewInventoryEntry {\n const fields: PreviewInventoryField[] = [];\n collect(slug.fields, '', fields);\n return { slug: slug.slug, typeName: slug.typeName, fields };\n}\n\n/** Flatten an extracted schema into every path a binding may address. */\nexport function buildPreviewInventory(schema: ExtractedSchema): PreviewInventory {\n return {\n globals: schema.globals.map(entry),\n collections: schema.collections.map(entry),\n };\n}\n\n/** A binding found in consumer markup, however that consumer found it. */\nexport interface PreviewBindingReference {\n readonly kind: 'global' | 'collection';\n readonly slug: string;\n readonly path: string;\n /** Free-form origin for the diagnostic, e.g. `Hero.astro:42`. */\n readonly source?: string;\n}\n\nexport interface PreviewCoverageOptions {\n /**\n * Report schema fields that no binding addresses. Off by default: a page is\n * allowed to render a subset, and most consumers want the unknown-binding\n * half first.\n */\n readonly reportUnbound?: boolean;\n}\n\n/**\n * Cross-check bindings against the inventory.\n *\n * Extraction stays with the consumer — resolving `bind('x')` in Astro, JSX or\n * Svelte markup is framework work this package cannot do generically. What it\n * can do is own the answer to \"is that a real, addressable field\", which is the\n * half that drifts silently when a schema is renamed.\n */\nexport function checkPreviewBindings(\n inventory: PreviewInventory,\n bindings: readonly PreviewBindingReference[],\n options: PreviewCoverageOptions = {},\n): readonly string[] {\n const diagnostics: string[] = [];\n const byKey = new Map<string, ReadonlySet<string>>();\n for (const [kind, entries] of [\n ['global', inventory.globals],\n ['collection', inventory.collections],\n ] as const) {\n for (const item of entries) {\n byKey.set(`${kind}:${item.slug}`, new Set(item.fields.map((f) => f.path)));\n }\n }\n\n const seen = new Map<string, Set<string>>();\n for (const binding of bindings) {\n const key = `${binding.kind}:${binding.slug}`;\n const where = binding.source === undefined ? '' : ` (${binding.source})`;\n const paths = byKey.get(key);\n if (paths === undefined) {\n diagnostics.push(`unknown ${binding.kind} \"${binding.slug}\"${where}`);\n continue;\n }\n if (!paths.has(binding.path)) {\n diagnostics.push(`${key} has no field \"${binding.path}\"${where}`);\n continue;\n }\n let bound = seen.get(key);\n if (bound === undefined) {\n bound = new Set<string>();\n seen.set(key, bound);\n }\n bound.add(binding.path);\n }\n\n if (options.reportUnbound === true) {\n for (const [key, paths] of byKey) {\n const bound = seen.get(key) ?? new Set<string>();\n for (const path of paths) {\n if (!bound.has(path)) diagnostics.push(`${key} field \"${path}\" is never bound`);\n }\n }\n }\n\n return diagnostics;\n}\n","/**\n * Programmatic codegen API.\n *\n * ```ts\n * import { generateTypes } from 'payload-live-preview/codegen';\n * const { code, diagnostics } = await generateTypes({\n * configPath: 'backend/src/payload.config.ts',\n * outFile: 'frontend/src/payload-types.ts',\n * });\n * ```\n *\n * @module @codegen\n */\n\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, resolve } from 'node:path';\nimport { extractSchema, type ExtractSchemaOptions } from './parser/extract-schema';\nimport { emitTypes, type EmitOptions } from './emit/emit-types';\nimport type { ExtractedSchema } from './parser/types';\n\nimport { buildPreviewInventory, type PreviewInventory } from './inventory';\n\nexport interface GenerateTypesOptions\n extends Pick<ExtractSchemaOptions, 'configPath' | 'project' | 'tsConfigFilePath'>, EmitOptions {\n /**\n * If set, the generated code is written to this absolute or\n * cwd-relative path. The function still returns the rendered string\n * in `code` so callers can verify before writing.\n */\n readonly outFile?: string;\n /** Working directory used to resolve relative paths. Defaults to `process.cwd()`. */\n readonly cwd?: string;\n /**\n * If set, the preview inventory is written to this path as JSON.\n *\n * Every field a binding can address, spelled the way the runtime resolves it.\n * Consumers have had to re-derive that spelling to check their markup against\n * the schema, and re-deriving it is where the two drift apart.\n */\n readonly inventoryFile?: string;\n}\n\nexport interface GenerateTypesResult {\n readonly code: string;\n readonly diagnostics: readonly string[];\n readonly schema: ExtractedSchema;\n readonly outFile?: string;\n /** Always produced; written to disk only when `inventoryFile` is set. */\n readonly inventory: PreviewInventory;\n readonly inventoryFile?: string;\n}\n\nexport async function generateTypes(options: GenerateTypesOptions): Promise<GenerateTypesResult> {\n const cwd = options.cwd ?? process.cwd();\n const configPath = isAbsolute(options.configPath)\n ? options.configPath\n : resolve(cwd, options.configPath);\n const schema = extractSchema({\n configPath,\n ...(options.project !== undefined ? { project: options.project } : {}),\n ...(options.tsConfigFilePath !== undefined\n ? { tsConfigFilePath: options.tsConfigFilePath }\n : {}),\n });\n const code = emitTypes(schema, options);\n const inventory = buildPreviewInventory(schema);\n\n const result: GenerateTypesResult = {\n code,\n diagnostics: schema.diagnostics,\n schema,\n inventory,\n ...(options.outFile !== undefined\n ? { outFile: isAbsolute(options.outFile) ? options.outFile : resolve(cwd, options.outFile) }\n : {}),\n ...(options.inventoryFile !== undefined\n ? {\n inventoryFile: isAbsolute(options.inventoryFile)\n ? options.inventoryFile\n : resolve(cwd, options.inventoryFile),\n }\n : {}),\n };\n\n if (result.outFile) {\n await mkdir(dirname(result.outFile), { recursive: true });\n await writeFile(result.outFile, code, 'utf8');\n }\n if (result.inventoryFile) {\n await mkdir(dirname(result.inventoryFile), { recursive: true });\n // Trailing newline and stable key order so the file is diffable and can be\n // committed as a contract rather than regenerated noise.\n await writeFile(result.inventoryFile, `${JSON.stringify(inventory, null, 2)}\\n`, 'utf8');\n }\n\n return result;\n}\n\nexport { buildPreviewInventory, checkPreviewBindings } from './inventory';\nexport type {\n PreviewBindingReference,\n PreviewCoverageOptions,\n PreviewInventory,\n PreviewInventoryEntry,\n PreviewInventoryField,\n} from './inventory';\nexport { extractSchema } from './parser/extract-schema';\nexport { emitTypes } from './emit/emit-types';\nexport type { ExtractedSchema, ExtractedSlug, ExtractedField } from './parser/types';\n"],"mappings":"yKA0BMA,EAA6E,CACjFC,KAAM,SACNC,SAAU,SACVC,MAAO,SACPC,SAAU,UACVC,OAAQ,SACRC,SAAU,UACVC,KAAM,SACNC,KAAM,SACNC,MAAO,UACPC,GAAI,UACJC,MAAO,UAGF,SAASC,EAAaC,GAC3B,IAAMC,EAAOC,EAAmBF,EAAS,QACzC,QAAa,IAATC,EAAoB,OAIxB,IAAME,EAAmB,IAAIC,IAAI,CAAC,OAAQ,MAAO,gBAC3CC,EAAOH,EAAmBF,EAAS,QACzC,QAAa,IAATK,IAAuBF,EAAiBG,IAAIL,GAAO,OAEvD,IAEMM,EAAO,CAAEF,KAAMA,GAAQ,eAAgBG,SAF5BC,EAAoBT,EAAS,cAAe,EAENU,UADrCD,EAAoBT,EAAS,eAAgB,GAG/D,OAAQC,GACN,IAAK,QACH,MAAO,IACFM,EACHI,KAAM,QACNC,OAAQC,EAAoBb,IAEhC,IAAK,SACH,MAAO,IACFO,EACHI,KAAM,SACNG,OAAQC,EAAcf,IAE1B,IAAK,QACH,MAAO,IACFO,EACHI,KAAM,QACNC,OAAQC,EAAoBb,IAEhC,IAAK,OACL,IAAK,MACL,IAAK,cAAe,CAGlB,IAAMgB,EAAYC,EAAkCjB,GACpD,MAAO,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A9B,qBAAAgC,GAAAF,QAAAlE,UAAAqE,EAAAH,QAAA9H,cAAAkI,EAAAJ,QAAAb,cAAAkB","ignoreList":[]}
1
+ {"version":3,"file":"codegen.cjs","names":["toPascalCase","slug","split","filter","Boolean","map","part","charAt","toUpperCase","slice","join","IDENTIFIER","nestedTypeName","parent","child","emitFieldMember","field","lines","options","markLocalizedAsDeprecated","localized","push","optional","required","name","test","replace","kind","hasMany","typeRef","blocks","length","block","typeName","base","target","literal","option","renderFieldType","emitBlockInterface","fields","emitAuxiliaries","prefix","seen","auxName","has","add","inner","blockTypeName","emitSlug","emitMap","slugs","emitTypes","schema","header","Set","globals","collections","slugAliases","collect","basePath","out","path","entry","buildPreviewInventory","reportSkip","context","node","why","diagnostics","text","getText","snippet","getSourceFile","getBaseName","String","getStartLineNumber","where","unwrap","current","Node","isParenthesizedExpression","isAsExpression","isSatisfiesExpression","isNonNullExpression","isTypeAssertion","getExpression","followAlias","declaration","isImportSpecifier","isImportClause","isNamespaceImport","isExportSpecifier","aliased","getSymbol","getAliasedSymbol","getDeclarations","definitionsOf","identifier","definitions","getDefinitionNodes","flatMap","valueOf","isVariableDeclaration","isPropertyAssignment","getInitializer","isExportAssignment","isShorthandPropertyAssignment","getNameNode","propertyValue","property","getProperty","hasProperty","resolveToObjectLiteral","isObjectLiteralExpression","isCallExpression","getArguments","isIdentifier","resolved","isPropertyAccessExpression","owner","getName","resolveToArrayLiteral","isArrayLiteralExpression","expandElements","array","element","getElements","isSpreadElement","expanded","readStringProperty","value","isStringLiteral","isNoSubstitutionTemplateLiteral","getLiteralValue","readBooleanProperty","isTrueLiteral","isFalseLiteral","readArrayProperty","readRelationTarget","STRUCTURAL_SENTINEL","STRUCTURAL_TYPES","SCALAR_TYPE_MAP","textarea","email","richText","number","checkbox","date","code","point","HAS_MANY_SCALARS","extractFields","extractField","nestedFields","extractTabs","tabs","tab","extractBlocks","readOptions","type","declaredValue","extractSlugList","configLiteral","key","extractSchema","project","Project","tsConfigFilePath","skipAddingFilesFromTsConfig","sourceFile","addSourceFileAtPathIfExists","configPath","resolveSourceFileDependencies","defaultExport","getDefaultExportSymbol","call","getDescendantsOfKind","SyntaxKind","CallExpression","callee","findConfigLiteral","async","writeOut","content","mkdir","dirname","recursive","writeFile","inventory","bindings","byKey","Map","entries","item","set","f","binding","source","paths","get","bound","reportUnbound","cwd","process","absolute","isAbsolute","resolve","outFile","inventoryFile","targets","empty","JSON","stringify"],"sources":["../src/codegen/parser/names.ts","../src/codegen/emit/emit-types.ts","../src/codegen/inventory.ts","../src/codegen/parser/resolve.ts","../src/codegen/parser/extract-field.ts","../src/codegen/parser/extract-schema.ts","../src/codegen/index.ts"],"sourcesContent":["/** Naming shared by the parser and the emitter. */\n\nexport function toPascalCase(slug: string): string {\n return slug\n .split(/[-_\\s]+/u)\n .filter(Boolean)\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('');\n}\n","/**\n * Render an `ExtractedSchema` as one self-contained TypeScript file: an\n * interface per global and collection, nested interfaces for groups, arrays\n * and blocks, and the `PayloadGlobals`/`PayloadCollections`/`PayloadSlug` maps.\n */\nimport { toPascalCase } from '../parser/names';\nimport type {\n ExtractedBlock,\n ExtractedField,\n ExtractedSchema,\n ExtractedSlug,\n} from '../parser/types';\n\nexport interface EmitOptions {\n /** When true, localized fields carry a `@localized` JSDoc marker. */\n readonly markLocalizedAsDeprecated?: boolean;\n /** Header text at the top of the output. */\n readonly header?: string;\n}\n\nconst DEFAULT_HEADER =\n '// Auto-generated by payload-live-preview/codegen.\\n' +\n '// Do not edit by hand — run `pll-codegen` to regenerate.\\n' +\n '/* eslint-disable */';\nconst IDENTIFIER = /^[A-Za-z_$][\\w$]*$/u;\n\nfunction memberName(name: string): string {\n if (IDENTIFIER.test(name)) return name;\n return `'${name.replace(/\\\\/gu, '\\\\\\\\').replace(/'/gu, \"\\\\'\")}'`;\n}\n\nfunction nestedTypeName(parent: string, child: string): string {\n return `${parent}${toPascalCase(child)}`;\n}\n\nfunction renderFieldType(field: ExtractedField, parent: string): string {\n switch (field.kind) {\n case 'scalar':\n return field.hasMany === true ? `${field.typeRef}[]` : field.typeRef;\n case 'array':\n return `${nestedTypeName(parent, field.name)}[]`;\n case 'blocks': {\n if (field.blocks.length === 0) return 'unknown[]';\n const variants = field.blocks\n .map((block) => nestedTypeName(nestedTypeName(parent, field.name), block.typeName))\n .join(' | ');\n return `(${variants})[]`;\n }\n case 'group':\n return nestedTypeName(parent, field.name);\n case 'relationship': {\n const target =\n typeof field.target === 'string'\n ? `'${field.target}'`\n : field.target.map((slug) => `'${slug}'`).join(' | ');\n const base = `PayloadRelationship<${target}>`;\n return field.hasMany ? `${base}[]` : base;\n }\n case 'upload':\n return field.hasMany === true ? 'PayloadMedia[]' : 'PayloadMedia';\n case 'json':\n return 'unknown';\n case 'select': {\n if (field.options.length === 0) return field.hasMany ? 'string[]' : 'string';\n const literal = field.options.map((option) => `'${option}'`).join(' | ');\n return field.hasMany ? `(${literal})[]` : literal;\n }\n }\n}\n\nfunction emitFieldMember(\n field: ExtractedField,\n parent: string,\n lines: string[],\n options: EmitOptions,\n): void {\n if (options.markLocalizedAsDeprecated === true && field.localized) {\n lines.push(' /** @localized */');\n }\n const optional = field.required ? '' : '?';\n lines.push(` ${memberName(field.name)}${optional}: ${renderFieldType(field, parent)};`);\n}\n\nfunction emitBlockInterface(\n typeName: string,\n block: ExtractedBlock,\n lines: string[],\n options: EmitOptions,\n): void {\n lines.push(`export interface ${typeName} {`);\n lines.push(` blockType: '${block.slug}';`);\n for (const field of block.fields) emitFieldMember(field, typeName, lines, options);\n lines.push('}', '');\n}\n\nfunction emitAuxiliaries(\n prefix: string,\n fields: readonly ExtractedField[],\n lines: string[],\n seen: Set<string>,\n options: EmitOptions,\n): void {\n for (const field of fields) {\n const auxName = nestedTypeName(prefix, field.name);\n if (field.kind === 'array' || field.kind === 'group') {\n if (seen.has(auxName)) continue;\n seen.add(auxName);\n emitAuxiliaries(auxName, field.fields, lines, seen, options);\n lines.push(`export interface ${auxName} {`);\n for (const inner of field.fields) emitFieldMember(inner, auxName, lines, options);\n lines.push('}', '');\n } else if (field.kind === 'blocks') {\n for (const block of field.blocks) {\n const blockTypeName = nestedTypeName(auxName, block.typeName);\n if (seen.has(blockTypeName)) continue;\n seen.add(blockTypeName);\n emitAuxiliaries(blockTypeName, block.fields, lines, seen, options);\n emitBlockInterface(blockTypeName, block, lines, options);\n }\n }\n }\n}\n\nfunction emitSlug(\n slug: ExtractedSlug,\n lines: string[],\n seen: Set<string>,\n options: EmitOptions,\n): void {\n emitAuxiliaries(slug.typeName, slug.fields, lines, seen, options);\n lines.push(`export interface ${slug.typeName} {`);\n for (const field of slug.fields) emitFieldMember(field, slug.typeName, lines, options);\n lines.push('}');\n}\n\nfunction emitMap(name: string, slugs: readonly ExtractedSlug[], lines: string[]): void {\n if (slugs.length === 0) return;\n lines.push(`export type ${name} = {`);\n for (const slug of slugs) lines.push(` '${slug.slug}': ${slug.typeName};`);\n lines.push('};', '');\n}\n\nexport function emitTypes(schema: ExtractedSchema, options: EmitOptions = {}): string {\n const lines: string[] = [options.header ?? DEFAULT_HEADER, ''];\n lines.push('import type { PayloadMedia, PayloadRelationship } from \"payload-live-preview\";', '');\n const seen = new Set<string>();\n for (const slug of [...schema.globals, ...schema.collections]) {\n emitSlug(slug, lines, seen, options);\n lines.push('');\n }\n emitMap('PayloadGlobals', schema.globals, lines);\n emitMap('PayloadCollections', schema.collections, lines);\n const slugAliases: string[] = [];\n if (schema.globals.length > 0) slugAliases.push('keyof PayloadGlobals');\n if (schema.collections.length > 0) slugAliases.push('keyof PayloadCollections');\n if (slugAliases.length > 0) {\n lines.push(`export type PayloadSlug = ${slugAliases.join(' | ')};`, '');\n }\n return lines.join('\\n').replace(/\\n{3,}/gu, '\\n\\n');\n}\n","/**\n * Which schema fields a binding can address, spelled the way the runtime\n * resolves them. Paths follow `@schema/walker` exactly — bindings are matched\n * against that rule at runtime, so any other spelling would be wrong here.\n */\n\nimport type { ExtractedField, ExtractedSchema, ExtractedSlug } from './parser/types';\n\n/** Sentinel the parser gives an unnamed structural container. */\nconst STRUCTURAL_SENTINEL = '__structural';\n\n/** One addressable field, spelled the way a binding must spell it. */\nexport interface PreviewInventoryField {\n /** Runtime binding path, e.g. `hero.title` or `slides.*.caption`. */\n readonly path: string;\n /** Extracted field kind: `scalar`, `array`, `blocks`, `group`, … */\n readonly kind: ExtractedField['kind'];\n readonly localized: boolean;\n readonly required: boolean;\n}\n\nexport interface PreviewInventoryEntry {\n readonly slug: string;\n readonly typeName: string;\n readonly fields: readonly PreviewInventoryField[];\n}\n\nexport interface PreviewInventory {\n readonly globals: readonly PreviewInventoryEntry[];\n readonly collections: readonly PreviewInventoryEntry[];\n}\n\nfunction collect(\n fields: readonly ExtractedField[],\n basePath: string,\n out: PreviewInventoryField[],\n): void {\n for (const field of fields) {\n // No segment, but its children still belong to the parent's surface.\n if (field.kind === 'group' && field.name === STRUCTURAL_SENTINEL) {\n collect(field.fields, basePath, out);\n continue;\n }\n const path = basePath === '' ? field.name : `${basePath}.${field.name}`;\n out.push({\n path,\n kind: field.kind,\n localized: field.localized,\n required: field.required,\n });\n if (field.kind === 'group') {\n collect(field.fields, path, out);\n } else if (field.kind === 'array') {\n collect(field.fields, `${path}.*`, out);\n } else if (field.kind === 'blocks') {\n for (const block of field.blocks) {\n collect(block.fields, `${path}.*.${block.slug}`, out);\n }\n }\n }\n}\n\nfunction entry(slug: ExtractedSlug): PreviewInventoryEntry {\n const fields: PreviewInventoryField[] = [];\n collect(slug.fields, '', fields);\n return { slug: slug.slug, typeName: slug.typeName, fields };\n}\n\n/** Flatten an extracted schema into every path a binding may address. */\nexport function buildPreviewInventory(schema: ExtractedSchema): PreviewInventory {\n return {\n globals: schema.globals.map(entry),\n collections: schema.collections.map(entry),\n };\n}\n\n/** A binding found in consumer markup, however that consumer found it. */\nexport interface PreviewBindingReference {\n readonly kind: 'global' | 'collection';\n readonly slug: string;\n readonly path: string;\n /** Free-form origin for the diagnostic, e.g. `Hero.astro:42`. */\n readonly source?: string;\n}\n\nexport interface PreviewCoverageOptions {\n /** Also report schema fields no binding addresses; off, since a page may render a subset. */\n readonly reportUnbound?: boolean;\n}\n\n/** Cross-check bindings the consumer extracted against the inventory. */\nexport function checkPreviewBindings(\n inventory: PreviewInventory,\n bindings: readonly PreviewBindingReference[],\n options: PreviewCoverageOptions = {},\n): readonly string[] {\n const diagnostics: string[] = [];\n const byKey = new Map<string, ReadonlySet<string>>();\n for (const [kind, entries] of [\n ['global', inventory.globals],\n ['collection', inventory.collections],\n ] as const) {\n for (const item of entries) {\n byKey.set(`${kind}:${item.slug}`, new Set(item.fields.map((f) => f.path)));\n }\n }\n\n const seen = new Map<string, Set<string>>();\n for (const binding of bindings) {\n const key = `${binding.kind}:${binding.slug}`;\n const where = binding.source === undefined ? '' : ` (${binding.source})`;\n const paths = byKey.get(key);\n if (paths === undefined) {\n diagnostics.push(`unknown ${binding.kind} \"${binding.slug}\"${where}`);\n continue;\n }\n if (!paths.has(binding.path)) {\n diagnostics.push(`${key} has no field \"${binding.path}\"${where}`);\n continue;\n }\n let bound = seen.get(key);\n if (bound === undefined) {\n bound = new Set<string>();\n seen.set(key, bound);\n }\n bound.add(binding.path);\n }\n\n if (options.reportUnbound === true) {\n for (const [key, paths] of byKey) {\n const bound = seen.get(key) ?? new Set<string>();\n for (const path of paths) {\n if (!bound.has(path)) diagnostics.push(`${key} field \"${path}\" is never bound`);\n }\n }\n }\n\n return diagnostics;\n}\n","/**\n * Resolving the shapes a Payload config takes — literals, identifiers,\n * imports, wrappers, spreads — to the literals the extractors read. Every\n * shape that cannot be resolved becomes a diagnostic, never a silent gap.\n */\nimport {\n Node,\n type ArrayLiteralExpression,\n type Identifier,\n type ObjectLiteralExpression,\n} from 'ts-morph';\n\nexport interface ExtractContext {\n readonly diagnostics: string[];\n}\n\nfunction where(node: Node): string {\n return `${node.getSourceFile().getBaseName()}:${String(node.getStartLineNumber())}`;\n}\n\nfunction snippet(node: Node): string {\n const text = node.getText().replace(/\\s+/gu, ' ');\n return text.length > 60 ? `${text.slice(0, 57)}...` : text;\n}\n\nexport function reportSkip(context: ExtractContext, node: Node, why: string): void {\n context.diagnostics.push(`Skipped \"${snippet(node)}\" at ${where(node)}: ${why}.`);\n}\n\nfunction unwrap(node: Node): Node {\n let current = node;\n while (\n Node.isParenthesizedExpression(current) ||\n Node.isAsExpression(current) ||\n Node.isSatisfiesExpression(current) ||\n Node.isNonNullExpression(current) ||\n Node.isTypeAssertion(current)\n ) {\n current = current.getExpression();\n }\n return current;\n}\n\n/** An import or re-export binds a name but holds no value; the value is in the module it names. */\nfunction followAlias(declaration: Node): readonly Node[] {\n const isAlias =\n Node.isImportSpecifier(declaration) ||\n Node.isImportClause(declaration) ||\n Node.isNamespaceImport(declaration) ||\n Node.isExportSpecifier(declaration);\n if (!isAlias) return [declaration];\n const aliased = declaration.getSymbol()?.getAliasedSymbol();\n return aliased?.getDeclarations() ?? [declaration];\n}\n\n/** Follows imports through the language service; the binder is the fallback for what it cannot see. */\nfunction definitionsOf(identifier: Identifier): readonly Node[] {\n const definitions = identifier.getDefinitionNodes();\n const found =\n definitions.length > 0 ? definitions : (identifier.getSymbol()?.getDeclarations() ?? []);\n return found.flatMap(followAlias);\n}\n\nfunction valueOf(declaration: Node): Node | undefined {\n if (Node.isVariableDeclaration(declaration) || Node.isPropertyAssignment(declaration)) {\n return declaration.getInitializer();\n }\n if (Node.isExportAssignment(declaration)) return declaration.getExpression();\n if (Node.isShorthandPropertyAssignment(declaration)) return declaration.getNameNode();\n return undefined;\n}\n\n/** The value of a property, treating `{ fields }` shorthand as a reference to resolve. */\nexport function propertyValue(literal: ObjectLiteralExpression, name: string): Node | undefined {\n const property = literal.getProperty(name);\n if (property === undefined) return undefined;\n if (Node.isPropertyAssignment(property)) return property.getInitializer();\n if (Node.isShorthandPropertyAssignment(property)) return property.getNameNode();\n return undefined;\n}\n\nexport function hasProperty(literal: ObjectLiteralExpression, name: string): boolean {\n return literal.getProperty(name) !== undefined;\n}\n\nexport function resolveToObjectLiteral(\n node: Node | undefined,\n seen = new Set<Node>(),\n): ObjectLiteralExpression | undefined {\n if (node === undefined || seen.has(node)) return undefined;\n seen.add(node);\n const target = unwrap(node);\n if (Node.isObjectLiteralExpression(target)) return target;\n // `buildConfig({...})`, `defineConfig({...})`: the literal is the first argument.\n if (Node.isCallExpression(target)) return resolveToObjectLiteral(target.getArguments()[0], seen);\n if (Node.isIdentifier(target)) {\n for (const declaration of definitionsOf(target)) {\n const resolved = resolveToObjectLiteral(valueOf(declaration), seen);\n if (resolved !== undefined) return resolved;\n }\n }\n if (Node.isPropertyAccessExpression(target)) {\n const owner = resolveToObjectLiteral(target.getExpression(), seen);\n if (owner !== undefined) {\n return resolveToObjectLiteral(propertyValue(owner, target.getName()), seen);\n }\n }\n return undefined;\n}\n\nexport function resolveToArrayLiteral(\n node: Node | undefined,\n seen = new Set<Node>(),\n): ArrayLiteralExpression | undefined {\n if (node === undefined || seen.has(node)) return undefined;\n seen.add(node);\n const target = unwrap(node);\n if (Node.isArrayLiteralExpression(target)) return target;\n if (Node.isIdentifier(target)) {\n for (const declaration of definitionsOf(target)) {\n const resolved = resolveToArrayLiteral(valueOf(declaration), seen);\n if (resolved !== undefined) return resolved;\n }\n }\n if (Node.isPropertyAccessExpression(target)) {\n const owner = resolveToObjectLiteral(target.getExpression(), seen);\n if (owner !== undefined) {\n return resolveToArrayLiteral(propertyValue(owner, target.getName()), seen);\n }\n }\n return undefined;\n}\n\n/** The elements of an array with every spread expanded; a spread that cannot be resolved is reported and dropped. */\nexport function expandElements(array: ArrayLiteralExpression, context: ExtractContext): Node[] {\n const out: Node[] = [];\n for (const element of array.getElements()) {\n if (!Node.isSpreadElement(element)) {\n out.push(element);\n continue;\n }\n const expanded = resolveToArrayLiteral(element.getExpression());\n if (expanded === undefined) {\n reportSkip(\n context,\n element,\n 'could not resolve the spread to an array literal, so its entries are missing',\n );\n continue;\n }\n out.push(...expandElements(expanded, context));\n }\n return out;\n}\n\nexport function readStringProperty(\n literal: ObjectLiteralExpression,\n name: string,\n): string | undefined {\n const value = propertyValue(literal, name);\n if (value === undefined) return undefined;\n const target = unwrap(value);\n if (Node.isStringLiteral(target) || Node.isNoSubstitutionTemplateLiteral(target)) {\n return target.getLiteralValue();\n }\n return undefined;\n}\n\nexport function readBooleanProperty(\n literal: ObjectLiteralExpression,\n name: string,\n): boolean | undefined {\n const value = propertyValue(literal, name);\n if (value === undefined) return undefined;\n const target = unwrap(value);\n if (Node.isTrueLiteral(target)) return true;\n if (Node.isFalseLiteral(target)) return false;\n return undefined;\n}\n\nexport function readArrayProperty(\n literal: ObjectLiteralExpression,\n name: string,\n): ArrayLiteralExpression | undefined {\n return resolveToArrayLiteral(propertyValue(literal, name));\n}\n\n/** `relationTo`: one slug, several, or `'unknown'` when it is not a literal. */\nexport function readRelationTarget(literal: ObjectLiteralExpression): string | readonly string[] {\n const value = propertyValue(literal, 'relationTo');\n if (value === undefined) return 'unknown';\n const target = unwrap(value);\n if (Node.isStringLiteral(target)) return target.getLiteralValue();\n const array = resolveToArrayLiteral(target);\n if (array === undefined) return 'unknown';\n return array\n .getElements()\n .map(unwrap)\n .filter((element) => Node.isStringLiteral(element))\n .map((element) => element.getLiteralValue());\n}\n","/**\n * Field-level extraction: one Payload field literal → an `ExtractedField`,\n * recursing into groups, arrays, tabs and blocks.\n */\nimport { Node, type ArrayLiteralExpression, type ObjectLiteralExpression } from 'ts-morph';\nimport { toPascalCase } from './names';\nimport {\n expandElements,\n hasProperty,\n readArrayProperty,\n readBooleanProperty,\n readRelationTarget,\n readStringProperty,\n reportSkip,\n resolveToObjectLiteral,\n type ExtractContext,\n} from './resolve';\nimport type { ExtractedBlock, ExtractedField, ExtractedScalarField } from './types';\n\n/** Name of an unnamed structural container; its fields flatten into the parent. */\nexport const STRUCTURAL_SENTINEL = '__structural';\nconst STRUCTURAL_TYPES = new Set(['tabs', 'row', 'collapsible']);\nconst SCALAR_TYPE_MAP: Readonly<Record<string, ExtractedScalarField['typeRef']>> = {\n text: 'string',\n textarea: 'string',\n email: 'string',\n richText: 'unknown',\n number: 'number',\n checkbox: 'boolean',\n date: 'string',\n code: 'string',\n point: '[number, number]',\n};\nconst HAS_MANY_SCALARS = new Set(['text', 'number']);\n\n/** Every field in `array`, spreads expanded and structural containers flattened. */\nexport function extractFields(\n array: ArrayLiteralExpression,\n context: ExtractContext,\n): ExtractedField[] {\n const out: ExtractedField[] = [];\n for (const element of expandElements(array, context)) {\n const literal = resolveToObjectLiteral(element);\n if (literal === undefined) {\n reportSkip(context, element, 'could not resolve the field to an object literal');\n continue;\n }\n const field = extractField(literal, context);\n if (field === undefined) continue;\n if (field.kind === 'group' && field.name === STRUCTURAL_SENTINEL) out.push(...field.fields);\n else out.push(field);\n }\n return out;\n}\n\nfunction nestedFields(literal: ObjectLiteralExpression, context: ExtractContext): ExtractedField[] {\n const array = readArrayProperty(literal, 'fields');\n if (array !== undefined) return extractFields(array, context);\n reportSkip(\n context,\n literal,\n hasProperty(literal, 'fields')\n ? 'its `fields` could not be resolved to an array literal'\n : 'it has no `fields`',\n );\n return [];\n}\n\nfunction extractTabs(literal: ObjectLiteralExpression, context: ExtractContext): ExtractedField[] {\n const tabs = readArrayProperty(literal, 'tabs');\n if (tabs === undefined) {\n reportSkip(context, literal, 'its `tabs` could not be resolved to an array literal');\n return [];\n }\n const out: ExtractedField[] = [];\n for (const element of expandElements(tabs, context)) {\n const tab = resolveToObjectLiteral(element);\n if (tab === undefined) {\n reportSkip(context, element, 'could not resolve the tab to an object literal');\n continue;\n }\n const name = readStringProperty(tab, 'name');\n const fields = nestedFields(tab, context);\n if (name === undefined) out.push(...fields);\n else out.push({ kind: 'group', name, required: false, localized: false, fields });\n }\n return out;\n}\n\nfunction extractBlocks(\n literal: ObjectLiteralExpression,\n context: ExtractContext,\n): ExtractedBlock[] {\n const blocks = readArrayProperty(literal, 'blocks');\n if (blocks === undefined) {\n reportSkip(context, literal, 'its `blocks` could not be resolved to an array literal');\n return [];\n }\n const out: ExtractedBlock[] = [];\n for (const element of expandElements(blocks, context)) {\n const block = resolveToObjectLiteral(element);\n if (block === undefined) {\n reportSkip(context, element, 'could not resolve the block to an object literal');\n continue;\n }\n const slug = readStringProperty(block, 'slug');\n if (slug === undefined) {\n reportSkip(context, element, 'a block needs a string `slug`');\n continue;\n }\n out.push({ slug, typeName: toPascalCase(slug), fields: nestedFields(block, context) });\n }\n return out;\n}\n\nfunction readOptions(literal: ObjectLiteralExpression, context: ExtractContext): string[] {\n const options = readArrayProperty(literal, 'options');\n if (options === undefined) {\n reportSkip(context, literal, 'its `options` could not be resolved to an array literal');\n return [];\n }\n const out: string[] = [];\n for (const element of expandElements(options, context)) {\n if (Node.isStringLiteral(element)) {\n out.push(element.getLiteralValue());\n continue;\n }\n const option = resolveToObjectLiteral(element);\n const value = option === undefined ? undefined : readStringProperty(option, 'value');\n if (value === undefined) reportSkip(context, element, 'an option needs a string or a `value`');\n else out.push(value);\n }\n return out;\n}\n\n/** One field, or `undefined` for a `ui` field (nothing to type) and for shapes reported as skipped. */\nexport function extractField(\n literal: ObjectLiteralExpression,\n context: ExtractContext,\n): ExtractedField | undefined {\n const type = readStringProperty(literal, 'type');\n if (type === undefined) {\n reportSkip(context, literal, 'it has no string `type`');\n return undefined;\n }\n if (type === 'ui') return undefined;\n const name = readStringProperty(literal, 'name');\n if (name === undefined && !STRUCTURAL_TYPES.has(type)) {\n reportSkip(context, literal, `a ${type} field needs a string \\`name\\``);\n return undefined;\n }\n const base = {\n name: name ?? STRUCTURAL_SENTINEL,\n required: readBooleanProperty(literal, 'required') ?? false,\n localized: readBooleanProperty(literal, 'localized') ?? false,\n };\n const hasMany = readBooleanProperty(literal, 'hasMany') ?? false;\n switch (type) {\n case 'array':\n return { ...base, kind: 'array', fields: nestedFields(literal, context) };\n case 'group':\n case 'row':\n case 'collapsible':\n return { ...base, kind: 'group', fields: nestedFields(literal, context) };\n case 'tabs':\n return { ...base, kind: 'group', fields: extractTabs(literal, context) };\n case 'blocks':\n return { ...base, kind: 'blocks', blocks: extractBlocks(literal, context) };\n case 'relationship':\n return { ...base, kind: 'relationship', target: readRelationTarget(literal), hasMany };\n case 'upload': {\n const target = readRelationTarget(literal);\n return {\n ...base,\n kind: 'upload',\n target: (typeof target === 'string' ? target : target[0]) ?? 'media',\n hasMany,\n };\n }\n case 'json':\n return { ...base, kind: 'json' };\n case 'select':\n case 'radio':\n return {\n ...base,\n kind: 'select',\n options: readOptions(literal, context),\n hasMany: type === 'select' && hasMany,\n };\n default:\n return {\n ...base,\n kind: 'scalar',\n typeRef: SCALAR_TYPE_MAP[type] ?? 'unknown',\n hasMany: HAS_MANY_SCALARS.has(type) && hasMany,\n };\n }\n}\n","/**\n * Schema-level extraction: open the config, find every collection and global,\n * walk into them. Lenient by design — a Payload config is a full TypeScript\n * program, so the common shapes are recognised and everything else becomes a\n * diagnostic rather than a silently empty type.\n */\nimport { Node, Project, SyntaxKind, type ObjectLiteralExpression, type SourceFile } from 'ts-morph';\nimport { extractFields } from './extract-field';\nimport { toPascalCase } from './names';\nimport {\n expandElements,\n hasProperty,\n propertyValue,\n readArrayProperty,\n readStringProperty,\n reportSkip,\n resolveToArrayLiteral,\n resolveToObjectLiteral,\n type ExtractContext,\n} from './resolve';\nimport type { ExtractedSchema, ExtractedSlug } from './types';\n\nexport interface ExtractSchemaOptions {\n /** Absolute or relative path to `payload.config.ts`. */\n readonly configPath: string;\n /** When provided, used instead of constructing a fresh ts-morph project. */\n readonly project?: Project;\n /** A `tsconfig.json` whose module resolution lets cross-file imports be followed. */\n readonly tsConfigFilePath?: string;\n}\n\nfunction declaredValue(declaration: Node): Node | undefined {\n if (Node.isExportAssignment(declaration)) return declaration.getExpression();\n if (Node.isVariableDeclaration(declaration)) return declaration.getInitializer();\n return undefined;\n}\n\nfunction findConfigLiteral(\n sourceFile: SourceFile,\n context: ExtractContext,\n): ObjectLiteralExpression | undefined {\n const defaultExport = sourceFile.getDefaultExportSymbol();\n if (defaultExport === undefined) {\n context.diagnostics.push('payload.config.ts has no default export.');\n return undefined;\n }\n for (const declaration of defaultExport.getDeclarations()) {\n const literal = resolveToObjectLiteral(declaredValue(declaration));\n if (literal !== undefined) return literal;\n }\n for (const call of sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)) {\n const callee = call.getExpression();\n if (!Node.isIdentifier(callee) || callee.getText() !== 'buildConfig') continue;\n const literal = resolveToObjectLiteral(call.getArguments()[0]);\n if (literal !== undefined) return literal;\n }\n return undefined;\n}\n\nfunction extractSlugList(\n configLiteral: ObjectLiteralExpression,\n key: 'globals' | 'collections',\n context: ExtractContext,\n): ExtractedSlug[] {\n const value = propertyValue(configLiteral, key);\n if (value === undefined) return [];\n const array = resolveToArrayLiteral(value);\n if (array === undefined) {\n reportSkip(context, value, `could not resolve \\`${key}\\` to an array literal`);\n return [];\n }\n const out: ExtractedSlug[] = [];\n for (const element of expandElements(array, context)) {\n const literal = resolveToObjectLiteral(element);\n if (literal === undefined) {\n reportSkip(context, element, 'could not resolve the config entry to an object literal');\n continue;\n }\n const slug = readStringProperty(literal, 'slug');\n if (slug === undefined) {\n reportSkip(context, element, 'the config entry has no string `slug`');\n continue;\n }\n const fields = readArrayProperty(literal, 'fields');\n if (fields === undefined) {\n reportSkip(\n context,\n literal,\n hasProperty(literal, 'fields')\n ? `the \\`fields\\` of \"${slug}\" could not be resolved to an array literal`\n : `\"${slug}\" has no \\`fields\\``,\n );\n }\n out.push({\n slug,\n typeName: toPascalCase(slug),\n fields: fields === undefined ? [] : extractFields(fields, context),\n });\n }\n return out;\n}\n\nexport function extractSchema(options: ExtractSchemaOptions): ExtractedSchema {\n const project =\n options.project ??\n new Project(\n options.tsConfigFilePath !== undefined\n ? { tsConfigFilePath: options.tsConfigFilePath }\n : { skipAddingFilesFromTsConfig: true },\n );\n const sourceFile = project.addSourceFileAtPathIfExists(options.configPath);\n if (sourceFile === undefined) {\n return { globals: [], collections: [], diagnostics: [`Could not open ${options.configPath}`] };\n }\n project.resolveSourceFileDependencies();\n const context: ExtractContext = { diagnostics: [] };\n const configLiteral = findConfigLiteral(sourceFile, context);\n if (configLiteral === undefined) {\n return {\n globals: [],\n collections: [],\n diagnostics: [\n ...context.diagnostics,\n 'Could not locate a buildConfig({...}) call or `export default {...}` in the config file.',\n ],\n };\n }\n const globals = extractSlugList(configLiteral, 'globals', context);\n const collections = extractSlugList(configLiteral, 'collections', context);\n return { globals, collections, diagnostics: context.diagnostics };\n}\n","/**\n * Programmatic codegen API: `generateTypes({ configPath, outFile })` parses a\n * Payload config and writes the TypeScript types and, optionally, the preview\n * inventory. Requires ts-morph.\n */\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, resolve } from 'node:path';\nimport { emitTypes, type EmitOptions } from './emit/emit-types';\nimport { buildPreviewInventory, type PreviewInventory } from './inventory';\nimport { extractSchema, type ExtractSchemaOptions } from './parser/extract-schema';\nimport type { ExtractedSchema } from './parser/types';\n\nexport interface GenerateTypesOptions\n extends Pick<ExtractSchemaOptions, 'configPath' | 'project' | 'tsConfigFilePath'>, EmitOptions {\n /** Where to write the generated code; `code` is returned either way. */\n readonly outFile?: string;\n /** Resolves relative paths. Defaults to `process.cwd()`. */\n readonly cwd?: string;\n /** Where to write the preview inventory as JSON: every path a binding may address. */\n readonly inventoryFile?: string;\n}\n\nexport interface GenerateTypesResult {\n readonly code: string;\n /** Extraction diagnostics, plus a note when nothing was written. */\n readonly diagnostics: readonly string[];\n readonly schema: ExtractedSchema;\n /** The types file actually written; absent when writing was refused. */\n readonly outFile?: string;\n /** Always produced; written to disk only when `inventoryFile` is set. */\n readonly inventory: PreviewInventory;\n readonly inventoryFile?: string;\n}\n\nasync function writeOut(path: string, content: string): Promise<void> {\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, content, 'utf8');\n}\n\n/** Parse the config and write the types, never writing an empty schema over a consumer's file. */\nexport async function generateTypes(options: GenerateTypesOptions): Promise<GenerateTypesResult> {\n const cwd = options.cwd ?? process.cwd();\n const absolute = (path: string): string => (isAbsolute(path) ? path : resolve(cwd, path));\n const schema = extractSchema({\n configPath: absolute(options.configPath),\n ...(options.project !== undefined ? { project: options.project } : {}),\n ...(options.tsConfigFilePath !== undefined\n ? { tsConfigFilePath: options.tsConfigFilePath }\n : {}),\n });\n const code = emitTypes(schema, options);\n const inventory = buildPreviewInventory(schema);\n const diagnostics = [...schema.diagnostics];\n const outFile = options.outFile === undefined ? undefined : absolute(options.outFile);\n const inventoryFile =\n options.inventoryFile === undefined ? undefined : absolute(options.inventoryFile);\n const targets = [outFile, inventoryFile].filter((path): path is string => path !== undefined);\n const empty = schema.globals.length + schema.collections.length === 0;\n if (empty && targets.length > 0) {\n diagnostics.push(\n `Nothing written: the schema is empty (0 globals, 0 collections), so ${targets.join(' and ')} ` +\n 'were left as they are.',\n );\n } else {\n if (outFile !== undefined) await writeOut(outFile, code);\n // Stable key order and a trailing newline keep the inventory diffable.\n if (inventoryFile !== undefined) {\n await writeOut(inventoryFile, `${JSON.stringify(inventory, null, 2)}\\n`);\n }\n }\n return {\n code,\n diagnostics,\n schema,\n inventory,\n ...(!empty && outFile !== undefined ? { outFile } : {}),\n ...(!empty && inventoryFile !== undefined ? { inventoryFile } : {}),\n };\n}\n\nexport { buildPreviewInventory, checkPreviewBindings } from './inventory';\nexport type {\n PreviewBindingReference,\n PreviewCoverageOptions,\n PreviewInventory,\n PreviewInventoryEntry,\n PreviewInventoryField,\n} from './inventory';\nexport { extractSchema } from './parser/extract-schema';\nexport { emitTypes } from './emit/emit-types';\nexport type { ExtractedSchema, ExtractedSlug, ExtractedField } from './parser/types';\n"],"mappings":"kFAEO,SAASA,EAAaC,GAC3B,OAAOA,EACJC,MAAM,YACNC,OAAOC,SACPC,IAAKC,GAASA,EAAKC,OAAO,GAAGC,cAAgBF,EAAKG,MAAM,IACxDC,KAAK,GACV,CCYA,IAIMC,EAAa,sBAOnB,SAASC,EAAeC,EAAgBC,GACtC,MAAO,GAAGD,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AnB,EAAOjG,EAAUC,EAAQnC,GACzB2K,EAAY7H,EAAsBX,GAClCgB,EAAc,IAAIhB,EAAOgB,aACzB2I,OAA8B,IAApB9L,EAAQ8L,aAAwB,EAAYH,EAAS3L,EAAQ8L,SACvEC,OACsB,IAA1B/L,EAAQ+L,mBAA8B,EAAYJ,EAAS3L,EAAQ+L,eAC/DC,EAAU,CAACF,EAASC,GAAe9M,OAAQ2D,QAAkC,IAATA,GACpEqJ,EAAQ9J,EAAOG,QAAQzB,OAASsB,EAAOI,YAAY1B,SAAW,EAapE,OAZIoL,GAASD,EAAQnL,OAAS,EAC5BsC,EAAYhD,KACV,uEAAuE6L,EAAQxM,KAAK,yCAItE,IAAZsM,SAA6BzB,EAASyB,EAAS3D,QAE7B,IAAlB4D,SACI1B,EAAS0B,EAAe,GAAGG,KAAKC,UAAUxB,EAAW,KAAM,SAG9D,CACLxC,OACAhF,cACAhB,SACAwI,eACKsB,QAAqB,IAAZH,EAAsC,GAAd,CAAEA,cACnCG,QAA2B,IAAlBF,EAAkD,GAApB,CAAEA,iBAElD","ignoreList":[]}
@@ -1,31 +1,21 @@
1
1
  import { Project } from 'ts-morph';
2
2
 
3
3
  /**
4
- * Internal schema representation used by the codegen pipeline.
5
- *
6
- * Decoupled from `PayloadFieldSchema` (the runtime shape that arrives
7
- * via postMessage) because:
8
- *
9
- * 1. Static analysis sees richer information — block definitions,
10
- * relationship targets, hasMany — that the runtime shape may not
11
- * always carry.
12
- * 2. The emit phase wants ergonomic structures (TypeScript-like
13
- * type references) that the runtime never needs.
14
- *
15
- * @module @codegen/parser/types
4
+ * The schema as static analysis sees it: richer than the runtime's
5
+ * `PayloadFieldSchema` (block definitions, relationship targets, hasMany) and
6
+ * shaped for the emitter.
16
7
  */
17
8
  interface ExtractedSchema {
18
9
  readonly globals: readonly ExtractedSlug[];
19
10
  readonly collections: readonly ExtractedSlug[];
20
- /** Diagnostics produced during extraction. Soft warnings only. */
11
+ /** What the extractor could not resolve. Every entry is a gap in the output. */
21
12
  readonly diagnostics: readonly string[];
22
13
  }
23
14
  interface ExtractedSlug {
24
15
  /** The Payload slug (`'homepage'`, `'posts'`, …). */
25
16
  readonly slug: string;
26
- /** PascalCase type name (`'Homepage'`, `'Post'`, …). */
17
+ /** PascalCase type name (`'Homepage'`, `'Posts'`, …). */
27
18
  readonly typeName: string;
28
- /** Fully-resolved field tree. */
29
19
  readonly fields: readonly ExtractedField[];
30
20
  }
31
21
  type ExtractedField = ExtractedScalarField | ExtractedArrayField | ExtractedBlocksField | ExtractedGroupField | ExtractedRelationshipField | ExtractedUploadField | ExtractedJsonField | ExtractedSelectField;
@@ -36,7 +26,9 @@ interface ExtractedFieldBase {
36
26
  }
37
27
  interface ExtractedScalarField extends ExtractedFieldBase {
38
28
  readonly kind: 'scalar';
39
- readonly typeRef: 'string' | 'number' | 'boolean' | 'Date' | 'unknown';
29
+ readonly typeRef: 'string' | 'number' | 'boolean' | 'Date' | '[number, number]' | 'unknown';
30
+ /** `text` and `number` fields may hold several values. */
31
+ readonly hasMany?: boolean;
40
32
  }
41
33
  interface ExtractedArrayField extends ExtractedFieldBase {
42
34
  readonly kind: 'array';
@@ -63,94 +55,30 @@ interface ExtractedRelationshipField extends ExtractedFieldBase {
63
55
  interface ExtractedUploadField extends ExtractedFieldBase {
64
56
  readonly kind: 'upload';
65
57
  readonly target: string;
58
+ readonly hasMany?: boolean;
66
59
  }
67
60
  interface ExtractedJsonField extends ExtractedFieldBase {
68
61
  readonly kind: 'json';
69
62
  }
63
+ /** `select` and `radio`; a radio never has many. */
70
64
  interface ExtractedSelectField extends ExtractedFieldBase {
71
65
  readonly kind: 'select';
72
66
  readonly options: readonly string[];
73
67
  readonly hasMany: boolean;
74
68
  }
75
69
 
76
- /**
77
- * Schema-level extraction: open `payload.config.ts`, find every
78
- * collection and global definition, walk into them.
79
- *
80
- * The extractor is deliberately lenient. Payload configurations are
81
- * full TypeScript programs — a strict parser would have to model
82
- * conditional types, factory functions, plugin closures. Instead we
83
- * recognise the *common* shapes (object literal, identifier
84
- * referencing an imported literal, default export from a sibling
85
- * file) and emit a diagnostic for anything we can't unwrap.
86
- *
87
- * @module @codegen/parser/extract-schema
88
- */
89
-
90
- interface ExtractSchemaOptions {
91
- /** Absolute or relative path to `payload.config.ts`. */
92
- readonly configPath: string;
93
- /** When provided, used instead of constructing a fresh ts-morph project. */
94
- readonly project?: Project;
95
- /**
96
- * Optional path to a `tsconfig.json`. When set, ts-morph loads the
97
- * project's module-resolution configuration so cross-file imports
98
- * (Homepage from './globals') can be followed.
99
- */
100
- readonly tsConfigFilePath?: string;
101
- }
102
- declare function extractSchema(options: ExtractSchemaOptions): ExtractedSchema;
103
-
104
- /**
105
- * Render `ExtractedSchema` to a TypeScript source string.
106
- *
107
- * The output is one self-contained `.ts` file that ships:
108
- *
109
- * - one `interface` per global and per collection,
110
- * - nested `interface` declarations for `group`/`array`/`blocks`,
111
- * - discriminated unions for `blocks` fields (one variant per slug),
112
- * - `PayloadCollections` / `PayloadGlobals` maps for slug-keyed
113
- * access (`PayloadCollections['posts']`), and
114
- * - a `PayloadSlug` alias.
115
- *
116
- * Nothing in the runtime depends on this output — consumers import
117
- * what they need by name.
118
- *
119
- * @module @codegen/emit/emit-types
120
- */
121
-
122
70
  interface EmitOptions {
123
- /** When true, includes a `@deprecated` JSDoc on localized fields. */
71
+ /** When true, localized fields carry a `@localized` JSDoc marker. */
124
72
  readonly markLocalizedAsDeprecated?: boolean;
125
- /** Header text injected at the top of the output. Defaults sensibly. */
73
+ /** Header text at the top of the output. */
126
74
  readonly header?: string;
127
75
  }
128
76
  declare function emitTypes(schema: ExtractedSchema, options?: EmitOptions): string;
129
77
 
130
78
  /**
131
- * Preview inventory — which schema fields a binding can actually address.
132
- *
133
- * A live-preview integration has two halves that must agree: the Payload schema
134
- * and the markup that binds it. Nothing has verified the agreement, so every
135
- * consumer that cared has built its own inventory and its own scanner, and
136
- * re-derived a path convention this package already owns.
137
- *
138
- * The convention is not obvious, which is the point of publishing it rather
139
- * than documenting it:
140
- *
141
- * - `tabs`, `row` and `collapsible` contribute **no** path segment. The
142
- * parser marks unnamed ones with a `__structural` sentinel; emitting it
143
- * would produce `__structural.title` for a field the runtime resolves as
144
- * `title`.
145
- * - a `group` contributes its name (`hero.title`),
146
- * - an `array` addresses its items through `.*` (`slides.*.title`),
147
- * - a `blocks` field addresses each block through `.*.<slug>`.
148
- *
149
- * That is `@schema/walker`'s rule, deliberately: bindings are matched against
150
- * it at runtime, so an inventory using any other spelling would be wrong in the
151
- * one place it is supposed to help.
152
- *
153
- * @module @codegen/inventory
79
+ * Which schema fields a binding can address, spelled the way the runtime
80
+ * resolves them. Paths follow `@schema/walker` exactly — bindings are matched
81
+ * against that rule at runtime, so any other spelling would be wrong here.
154
82
  */
155
83
 
156
84
  /** One addressable field, spelled the way a binding must spell it. */
@@ -182,64 +110,49 @@ interface PreviewBindingReference {
182
110
  readonly source?: string;
183
111
  }
184
112
  interface PreviewCoverageOptions {
185
- /**
186
- * Report schema fields that no binding addresses. Off by default: a page is
187
- * allowed to render a subset, and most consumers want the unknown-binding
188
- * half first.
189
- */
113
+ /** Also report schema fields no binding addresses; off, since a page may render a subset. */
190
114
  readonly reportUnbound?: boolean;
191
115
  }
192
- /**
193
- * Cross-check bindings against the inventory.
194
- *
195
- * Extraction stays with the consumer — resolving `bind('x')` in Astro, JSX or
196
- * Svelte markup is framework work this package cannot do generically. What it
197
- * can do is own the answer to "is that a real, addressable field", which is the
198
- * half that drifts silently when a schema is renamed.
199
- */
116
+ /** Cross-check bindings the consumer extracted against the inventory. */
200
117
  declare function checkPreviewBindings(inventory: PreviewInventory, bindings: readonly PreviewBindingReference[], options?: PreviewCoverageOptions): readonly string[];
201
118
 
202
119
  /**
203
- * Programmatic codegen API.
204
- *
205
- * ```ts
206
- * import { generateTypes } from 'payload-live-preview/codegen';
207
- * const { code, diagnostics } = await generateTypes({
208
- * configPath: 'backend/src/payload.config.ts',
209
- * outFile: 'frontend/src/payload-types.ts',
210
- * });
211
- * ```
212
- *
213
- * @module @codegen
120
+ * Schema-level extraction: open the config, find every collection and global,
121
+ * walk into them. Lenient by design — a Payload config is a full TypeScript
122
+ * program, so the common shapes are recognised and everything else becomes a
123
+ * diagnostic rather than a silently empty type.
214
124
  */
215
125
 
126
+ interface ExtractSchemaOptions {
127
+ /** Absolute or relative path to `payload.config.ts`. */
128
+ readonly configPath: string;
129
+ /** When provided, used instead of constructing a fresh ts-morph project. */
130
+ readonly project?: Project;
131
+ /** A `tsconfig.json` whose module resolution lets cross-file imports be followed. */
132
+ readonly tsConfigFilePath?: string;
133
+ }
134
+ declare function extractSchema(options: ExtractSchemaOptions): ExtractedSchema;
135
+
216
136
  interface GenerateTypesOptions extends Pick<ExtractSchemaOptions, 'configPath' | 'project' | 'tsConfigFilePath'>, EmitOptions {
217
- /**
218
- * If set, the generated code is written to this absolute or
219
- * cwd-relative path. The function still returns the rendered string
220
- * in `code` so callers can verify before writing.
221
- */
137
+ /** Where to write the generated code; `code` is returned either way. */
222
138
  readonly outFile?: string;
223
- /** Working directory used to resolve relative paths. Defaults to `process.cwd()`. */
139
+ /** Resolves relative paths. Defaults to `process.cwd()`. */
224
140
  readonly cwd?: string;
225
- /**
226
- * If set, the preview inventory is written to this path as JSON.
227
- *
228
- * Every field a binding can address, spelled the way the runtime resolves it.
229
- * Consumers have had to re-derive that spelling to check their markup against
230
- * the schema, and re-deriving it is where the two drift apart.
231
- */
141
+ /** Where to write the preview inventory as JSON: every path a binding may address. */
232
142
  readonly inventoryFile?: string;
233
143
  }
234
144
  interface GenerateTypesResult {
235
145
  readonly code: string;
146
+ /** Extraction diagnostics, plus a note when nothing was written. */
236
147
  readonly diagnostics: readonly string[];
237
148
  readonly schema: ExtractedSchema;
149
+ /** The types file actually written; absent when writing was refused. */
238
150
  readonly outFile?: string;
239
151
  /** Always produced; written to disk only when `inventoryFile` is set. */
240
152
  readonly inventory: PreviewInventory;
241
153
  readonly inventoryFile?: string;
242
154
  }
155
+ /** Parse the config and write the types, never writing an empty schema over a consumer's file. */
243
156
  declare function generateTypes(options: GenerateTypesOptions): Promise<GenerateTypesResult>;
244
157
 
245
158
  export { type ExtractedField, type ExtractedSchema, type ExtractedSlug, type GenerateTypesOptions, type GenerateTypesResult, type PreviewBindingReference, type PreviewCoverageOptions, type PreviewInventory, type PreviewInventoryEntry, type PreviewInventoryField, buildPreviewInventory, checkPreviewBindings, emitTypes, extractSchema, generateTypes };