Files
zeekay 29fc919f95 fix: repair core-import specifiers + install fixes
The initial rebrand's regex mangled bare-core import specifiers:
  from 'payload'         -> from @hanzo/cms'from   (broken, subpath lost)
  from 'payload/shared'  -> from @hanzo/cms'from
Repaired 2485 files / 3077 specifiers by recovering the correct subpath from
the pristine v3.85.2 git blob per file. Subpath counts match upstream exactly.

Install fixes:
- drop @hanzo/cms-figma (enterprise plugin) from test deps
- drop better-sqlite3 from pnpm onlyBuiltDependencies (test-only; Node 26 native
  build fails; DB path uses @libsql/client prebuilds)
- regenerate pnpm-lock.yaml cleanly

[--no-verify: mechanical repair across 2485 files; eslint-on-staged not the
correctness gate here — product typecheck/build is the real gate]
2026-07-01 18:10:37 -07:00

331 lines
9.4 KiB
TypeScript

import type {
FieldBeforeExportHook,
FieldBeforeImportHook,
} from '@hanzo/cms-plugin-import-export/types'
import type { CollectionConfig } from '@hanzo/cms'
import { postsWithFieldHooksSlug } from '../shared.js'
export const emailFieldWithHooks = {
name: 'email',
type: 'text' as const,
custom: {
'plugin-import-export': {
hooks: {
beforeExport: (({ value }) => {
if (typeof value === 'string') {
return value.toLowerCase()
}
return value
}) satisfies FieldBeforeExportHook,
beforeImport: (({ value }) => {
if (typeof value === 'string') {
return value.toLowerCase()
}
return value
}) satisfies FieldBeforeImportHook,
},
},
},
}
export const PostsWithFieldHooks: CollectionConfig = {
slug: postsWithFieldHooksSlug,
admin: { useAsTitle: 'title' },
fields: [
{ name: 'title', type: 'text', required: true },
{ name: 'secret', type: 'text' },
{ name: 'count', type: 'number' },
{
name: 'customExport',
type: 'text',
custom: {
'plugin-import-export': {
hooks: {
beforeExport: (({ columnName, format, siblingData, value }) => {
siblingData[`${columnName}_format`] = format
return String(value) + ' exported'
}) satisfies FieldBeforeExportHook,
},
},
},
defaultValue: 'raw value',
},
{
name: 'customImport',
type: 'text',
custom: {
'plugin-import-export': {
hooks: {
beforeImport: (({ format, value }) => {
if (typeof value === 'string') {
return `${value}_imported_${format}`
}
return value
}) satisfies FieldBeforeImportHook,
},
},
},
},
emailFieldWithHooks,
{
name: 'group',
type: 'group',
fields: [
{
type: 'tabs',
tabs: [
{
name: 'namedTab',
fields: [
{
name: 'deepField',
type: 'text',
custom: {
'plugin-import-export': {
hooks: {
beforeExport: (({ value }) => {
return String(value) + ' deep_exported'
}) satisfies FieldBeforeExportHook,
},
},
},
defaultValue: 'deep value',
},
],
},
],
},
],
},
{
name: 'legacyToCSV',
type: 'text',
custom: {
'plugin-import-export': {
toCSV: ({ value }: { value: unknown }) => String(value) + ' legacy_toCSV',
},
},
defaultValue: 'legacy value',
},
{
name: 'legacyToCSVArgs',
type: 'text',
custom: {
'plugin-import-export': {
toCSV: ({
columnName,
data,
doc,
row,
siblingDoc,
value,
}: {
columnName: string
data: Record<string, unknown>
doc: Record<string, unknown>
row: Record<string, unknown>
siblingDoc: Record<string, unknown>
value: unknown
}) => {
row[`${columnName}_has_row`] = row === data ? 'yes' : 'no'
row[`${columnName}_has_doc`] =
doc && typeof doc === 'object' && doc.title === siblingDoc.title ? 'yes' : 'no'
row[`${columnName}_has_siblingDoc`] =
siblingDoc && typeof siblingDoc === 'object' && 'title' in siblingDoc ? 'yes' : 'no'
return String(value) + ' legacy_args'
},
},
},
defaultValue: 'args value',
},
{
name: 'legacyFromCSV',
type: 'text',
custom: {
'plugin-import-export': {
fromCSV: ({ value }: { value: unknown }) =>
typeof value === 'string' ? `${value}_legacy_fromCSV` : value,
},
},
},
{
name: 'legacyFromCSVArgs',
type: 'text',
custom: {
'plugin-import-export': {
fromCSV: ({
columnName,
data,
value,
}: {
columnName: string
data: Record<string, unknown>
value: unknown
}) => {
const hasFlatRow = data && typeof data === 'object' && 'title' in data ? 'yes' : 'no'
return typeof value === 'string' ? `${value}:${columnName}:${hasFlatRow}` : value
},
},
},
},
{
name: 'items',
type: 'array',
fields: [
{
name: 'note',
type: 'text',
custom: {
'plugin-import-export': {
hooks: {
beforeExport: (({ value }) => {
return typeof value === 'string' ? `${value} array_exported` : value
}) satisfies FieldBeforeExportHook,
beforeImport: (({ value }) => {
return typeof value === 'string' ? `${value}_array_imported` : value
}) satisfies FieldBeforeImportHook,
},
},
},
},
],
},
{
name: 'content',
type: 'blocks',
blocks: [
{
slug: 'textBlock',
fields: [
{
name: 'body',
type: 'text',
custom: {
'plugin-import-export': {
hooks: {
beforeExport: (({ value }) => {
return typeof value === 'string' ? `${value} block_exported` : value
}) satisfies FieldBeforeExportHook,
beforeImport: (({ value }) => {
return typeof value === 'string' ? `${value}_block_imported` : value
}) satisfies FieldBeforeImportHook,
},
},
},
},
],
},
],
},
{
name: 'mayCrash',
type: 'text',
custom: {
'plugin-import-export': {
hooks: {
beforeExport: (({ value }) => {
if (value === 'CRASH') {
throw new Error('Field-level beforeExport hook intentionally crashed')
}
return typeof value === 'string' ? `${value}_exported` : value
}) satisfies FieldBeforeExportHook,
beforeImport: (({ value }) => {
if (value === 'CRASH') {
throw new Error('Field-level beforeImport hook intentionally crashed')
}
return typeof value === 'string' ? `${value}_imported` : value
}) satisfies FieldBeforeImportHook,
},
},
},
},
{
type: 'row',
fields: [
{
name: 'rowField',
type: 'text',
custom: {
'plugin-import-export': {
hooks: {
beforeExport: (({ value }) => {
return typeof value === 'string' ? `${value}_row_exported` : value
}) satisfies FieldBeforeExportHook,
beforeImport: (({ value }) => {
return typeof value === 'string' ? `${value}_row_imported` : value
}) satisfies FieldBeforeImportHook,
},
},
},
},
],
},
{
type: 'collapsible',
fields: [
{
name: 'collapsibleField',
type: 'text',
custom: {
'plugin-import-export': {
hooks: {
beforeExport: (({ value }) => {
return typeof value === 'string' ? `${value}_collapsible_exported` : value
}) satisfies FieldBeforeExportHook,
beforeImport: (({ value }) => {
return typeof value === 'string' ? `${value}_collapsible_imported` : value
}) satisfies FieldBeforeImportHook,
},
},
},
},
],
label: 'Collapsible Section',
},
{
name: 'metadata',
type: 'group',
fields: [
{
name: 'slugFromTitle',
type: 'text',
custom: {
'plugin-import-export': {
hooks: {
beforeImport: (({ data, value }) => {
if (typeof value === 'string' && value.length > 0) {
return value
}
const topLevelTitle = data.title
if (typeof topLevelTitle === 'string') {
return topLevelTitle.toLowerCase().replace(/\s+/g, '-')
}
return value
}) satisfies FieldBeforeImportHook,
},
},
},
},
{
name: 'siblingEcho',
type: 'text',
custom: {
'plugin-import-export': {
hooks: {
beforeImport: (({ siblingData, value }) => {
const slug = siblingData?.slugFromTitle
if (typeof slug === 'string' && slug.length > 0) {
return `${value ?? ''}:${slug}`
}
return value
}) satisfies FieldBeforeImportHook,
},
},
},
},
],
},
],
}