Seed helper: @intecion/ipal-kit/seed (createSeeder + building blocks)

createSeeder(payload, { dryRun, update, force, guard, editCheck, context, ... })
returns upsertBySlug, upsertBy, fillGlobal and summary(); building blocks
isLocalDatabase, writeLocales, seedHash, projectOnto, editedSinceSeed.
Behaviour follows docs/seeding.md: create-only by default, natural keys,
never deletes, globals get empty fields only, every locale written with
fallbackLocale: false onto the same row ids, records edited since seeding
skipped, update refused on production / non-local DB unless
IPAL_SEED_ALLOW_PROD_UPDATE=1, context.ipalSkipIndexNow on every write.

Both seed templates now use the helper. Node-only entry (no 'server-only',
which throws under `payload run`). SQLite integration tests cover the
production guard, the edited-record skip, the hash field, row ids and
the IndexNow skip. Agent guide (AGENT.md, ipal-reference, ipal-site,
ipal-form) and seeding.md updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-22 18:33:34 +02:00
co-authored by Claude Opus 5.5
parent b61b753ec2
commit cff76c2a69
16 changed files with 1155 additions and 521 deletions
+39
View File
@@ -0,0 +1,39 @@
/**
* Entry point: @intecion/ipal-kit/seed
*
* Seed helper for the project's seed scripts (docs/seeding.md):
*
* // scripts/seed-content.ts — pnpm payload run scripts/seed-content.ts
* import config from '@payload-config'
* import { getPayload } from 'payload'
* import { createSeeder } from '@intecion/ipal-kit/seed'
*
* const seed = createSeeder(await getPayload({ config }))
* await seed.upsertBySlug('pages', [{ title: { pl: 'Kontakt', en: 'Contact' }, slug: { pl: 'kontakt', en: 'contact' } }])
* await seed.fillGlobal('header', { links: [] })
* process.exit(seed.summary().errors ? 1 : 0)
*
* Server only: Node built-ins and the Local API. Never import it from client
* code, the Payload config or a route. It does not import 'server-only' — that
* package throws in plain Node, and `payload run` is plain Node.
*/
export {
createSeeder,
editedSinceSeed,
isLocalDatabase,
projectOnto,
seedHash,
writeLocales,
} from '../modules/seed/index.js'
export type {
EditedSinceSeedArgs,
Seeder,
SeederOptions,
SeedResult,
SeedStatus,
SeedSummary,
SeedTarget,
SeedValue,
UpsertOptions,
WriteLocalesOptions,
} from '../modules/seed/index.js'