Seed Loader schema — Data Protocol reference Defines the schemas for metadata-driven seed data loading with automatic relationship resolution, dependency ordering, and multi-pass insertion.
Defines the schemas for metadata-driven seed data loading with automatic
relationship resolution, dependency ordering, and multi-pass insertion.
Salesforce Data Loader : External ID-based upsert with relationship resolution
ServiceNow : Sys ID and display value mapping during import
Airtable : Linked record resolution via display names
1. Build object dependency graph from field metadata (lookup/master_detail)
2. Topological sort → determine insert order (parents before children)
3. Pass 1: Insert/upsert records, resolve references via externalId
4. Pass 2: Fill deferred references (circular/delayed dependencies)
5. Validate & report unresolved references
6. Return structured result with per-object stats
Source: packages/spec/src/data/seed-loader.zod.ts
import { ObjectDependencyGraphSchema, ObjectDependencyNodeSchema, ReferenceResolutionSchema, ReferenceResolutionErrorSchema, SeedIdentitySchema, SeedLoadResultSchema, SeedLoaderConfigSchema, SeedLoaderRequestSchema, SeedLoaderResultSchema } from '@objectstack/spec/data' ;
import type { ObjectDependencyGraph, ObjectDependencyNode, ReferenceResolution, ReferenceResolutionError, SeedIdentity, SeedLoadResult, SeedLoaderConfig, SeedLoaderRequest, SeedLoaderResult } from '@objectstack/spec/data' ;
// Validate data
const result = ObjectDependencyGraphSchema. parse (data);
Complete object dependency graph for seed data loading
Property Type Required Description nodes { object: string; dependsOn: string[]; references: object[] }[]✅ All objects in the dependency graph insertOrder string[]✅ Topologically sorted insert order circularDependencies string[][]optional (default: []) Circular dependency chains (e.g., [["a", "b", "a"]])
Object node in the seed data dependency graph
Property Type Required Description object string✅ Object name (snake_case) dependsOn string[]✅ Objects this object depends on references { field: string; targetObject: string; targetField?: string; fieldType: Enum<'lookup' | 'master_detail' | 'user'>; … }[]✅ Field-level reference details
Object node in the seed data dependency graph
Property Type Required Description object string✅ Object name (snake_case) dependsOn string[]✅ Objects this object depends on references { field: string; targetObject: string; targetField?: string; fieldType: Enum<'lookup' | 'master_detail' | 'user'>; … }[]✅ Field-level reference details
Describes how a field reference is resolved during seed loading
Property Type Required Description field string✅ Source field name containing the reference value targetObject string✅ Target object name (snake_case) targetField stringoptional (default: "name") Field on target object used for matching fieldType Enum<'lookup' | 'master_detail' | 'user'>✅ Relationship field type multiple booleanoptional Field stores an array of references (multiple: true)
Describes how a field reference is resolved during seed loading
Property Type Required Description field string✅ Source field name containing the reference value targetObject string✅ Target object name (snake_case) targetField stringoptional (default: "name") Field on target object used for matching fieldType Enum<'lookup' | 'master_detail' | 'user'>✅ Relationship field type multiple booleanoptional Field stores an array of references (multiple: true)
Actionable error for a failed reference resolution
Property Type Required Description sourceObject string✅ Object with the broken reference field string✅ Field name with unresolved reference targetObject string✅ Target object searched for the reference targetField string✅ ExternalId field used for matching attemptedValue any✅ Value that failed to resolve recordIndex integer✅ Index of the record in the dataset message string✅ Human-readable error description
Identity context for resolving os.user / os.org in seed CEL values
Property Type Required Description user { id: string; role?: string; email?: string }optional Subject bound to os.user in seed CEL expressions org { id: string; tier?: string }optional Organization bound to os.org in seed CEL expressions
Result of loading a single dataset
Property Type Required Description object string✅ Object that was loaded mode Enum<'update' | 'upsert' | 'ignore'>✅ Import mode used inserted integer✅ Records inserted updated integer✅ Records updated skipped integer✅ Records skipped errored integer✅ Records with errors total integer✅ Total records in dataset referencesResolved integer✅ References resolved via externalId referencesDeferred integer✅ References deferred to second pass referencesDropped integeroptional (default: 0) Reference fields dropped from records that were still written summariesStale integeroptional (default: 0) Roll-up summary values left stale by writes for this dataset landedIds string[]optional (default: []) Ids of the stored rows this dataset landed on: inserted, updated, or matched on replay insertedIds string[]optional (default: []) Ids among landedIds whose row this load created (a successful insert); every other landed id was a pre-existing row a record key matched errors { sourceObject: string; field: string; targetObject: string; targetField: string; … }[]optional (default: []) Reference resolution errors
Actionable error for a failed reference resolution
Property Type Required Description sourceObject string✅ Object with the broken reference field string✅ Field name with unresolved reference targetObject string✅ Target object searched for the reference targetField string✅ ExternalId field used for matching attemptedValue any✅ Value that failed to resolve recordIndex integer✅ Index of the record in the dataset message string✅ Human-readable error description
Seed data loader configuration
Property Type Required Description dryRun booleanoptional (default: false) Validate references without writing data haltOnError booleanoptional (default: false) Stop on first reference resolution error multiPass booleanoptional (default: true) Enable multi-pass loading for circular dependencies defaultMode Enum<'update' | 'upsert' | 'ignore'>optional (default: "ignore") Default conflict resolution strategy: the seed mode default (ignore, create-only) batchSize integeroptional (default: 1000) Maximum records per batch insert/upsert transaction booleanoptional (default: false) Wrap entire load in a transaction (all-or-nothing) env Enum<'prod' | 'dev' | 'test'>optional Only load datasets matching this environment locale stringoptional Only load datasets scoped to this locale (BCP-47 tag) organizationId stringoptional Target organization id for per-tenant seed replay identity { user?: object; org?: object }optional Identity bound to os.user / os.org when resolving CEL seed values
Property Type Required Description user { id: string; role?: string; email?: string }optional Subject bound to os.user in seed CEL expressions org { id: string; tier?: string }optional Organization bound to os.org in seed CEL expressions
Seed loader request with datasets and configuration
Property Type Required Description seeds { object: string; externalId?: string | string[]; mode?: Enum<'update' | 'upsert' | 'ignore'>; columns?: Record<string, object>; … }[]✅ Seeds to load config { dryRun?: boolean; haltOnError?: boolean; multiPass?: boolean; defaultMode?: Enum<'update' | 'upsert' | 'ignore'>; … }optional (has default) Loader configuration
Property Type Required Description object string✅ Target Object Name externalId string | string[]optional (default: "name") Field (or composite list of fields) matched for the uniqueness check mode Enum<'update' | 'upsert' | 'ignore'>optional (default: "ignore") What a load does with a record whose externalId matches an existing row. ignore (default) is create-only: a missing row is inserted and an existing row is left as it is, so a replay (every boot, a package install or upgrade, a publish) never writes a seeded value back over a later edit. upsert also writes every declared column back onto the matched row on each replay; declare it for reference data the package keeps current. update writes matched rows only. Every mode matches on externalId, so a replay finds the row an earlier load wrote instead of inserting it again. On the loads that seed an organization (the boot seed, a seed-replayer replay, the dev hot reload, a package install or upgrade), an ignore or upsert row that landed once and was later deleted is not inserted again; a publish, or a load that names no organization and finds no sole one, keeps no such record, and seed-replayer called with { reseed: true } or the sample-data reseed inserts every missing row. columns Record<string, { applyOn?: Enum<'create' | 'always'> }>optional Per-column write policy, keyed by field name: { status: { applyOn: 'create' } } writes status only when the seed creates the row. Omitted, every column is written on create and update. env Enum<'prod' | 'dev' | 'test'>[]optional (default: ["prod","dev","test"]) Applicable environments locale string[]optional Applicable locales (BCP-47 tags); omitted applies to every locale. The boot seed filters on the app's i18n.defaultLocale; the marketplace install, sample-data reseed, restart heal and per-organization replay filter on the locale resolved for the load (the localization.locale setting when set, then the locale of the installing, reseeding or founding user, then the app's i18n.defaultLocale where the load names one); package apply and draft publish do not filter by locale — they load every dataset and warn. A locale no dataset of the object names gets none of its locale-scoped rows, unless one is marked fallback: true fallback trueoptional Marks this locale-scoped dataset as its object's fallback: it also loads for a resolved locale that no other locale-scoped dataset of the same object lists. Requires locale: a dataset with no locale already loads everywhere, and the pair is refused. At most one dataset per object in a load may be marked; with two different marked datasets of one object, none is used as the fallback and the load reports the object, while each still loads for the locales it lists, as an unmarked dataset would (identical copies count once). A load with no locale loads it like every other dataset. Omitted, the dataset loads only for the locales it lists. dependsOn string[]optional Objects (by name) this dataset loads after, for an order no lookup field gives — e.g. a beforeInsert hook that reads another seeded object. Each name adds an edge to the load's dependency graph. The load is refused, writing nothing, when a name is the dataset's own object, is not seeded by another dataset of the same load, or closes a cycle with the other edges. Omitted, the order comes from lookup fields alone. records Record<string, any>[]✅ Data records files Record<string, { contentType: string; size: integer; sha256: string; data: string }>optional Bytes of the package files the records name with seedFile(path), keyed by path. Written by os build, which reads each path relative to the package root; the loader stores each one as a file the written record owns. _lock Enum<'none' | 'no-overlay' | 'no-delete' | 'full'>optional Item-level lock — controls overlay & delete (ADR-0010). _lockReason stringoptional Human-readable reason shown when a write is refused by _lock. _lockSource Enum<'artifact' | 'package' | 'env-forced'>optional Layer that set _lock (artifact | package | env-forced). _provenance Enum<'package' | 'org' | 'env-forced' | 'platform'>optional Origin of the item (package | org | env-forced | platform). _packageId stringoptional Owning package machine id. _packageVersion stringoptional Owning package version. _lockDocsUrl stringoptional Optional documentation link surfaced next to _lockReason.
Property Type Required Description dryRun booleanoptional (default: false) Validate references without writing data haltOnError booleanoptional (default: false) Stop on first reference resolution error multiPass booleanoptional (default: true) Enable multi-pass loading for circular dependencies defaultMode Enum<'update' | 'upsert' | 'ignore'>optional (default: "ignore") Default conflict resolution strategy: the seed mode default (ignore, create-only) batchSize integeroptional (default: 1000) Maximum records per batch insert/upsert transaction booleanoptional (default: false) Wrap entire load in a transaction (all-or-nothing) env Enum<'prod' | 'dev' | 'test'>optional Only load datasets matching this environment locale stringoptional Only load datasets scoped to this locale (BCP-47 tag) organizationId stringoptional Target organization id for per-tenant seed replay identity { user?: object; org?: object }optional Identity bound to os.user / os.org when resolving CEL seed values
Complete seed loader result
Property Type Required Description success boolean✅ Overall success status dryRun boolean✅ Whether this was a dry-run dependencyGraph { nodes: object[]; insertOrder: string[]; circularDependencies?: string[][] }✅ Object dependency graph results { object: string; mode: Enum<'update' | 'upsert' | 'ignore'>; inserted: integer; updated: integer; … }[]✅ Per-object load results errors { sourceObject: string; field: string; targetObject: string; targetField: string; … }[]✅ All reference resolution errors summary { objectsProcessed: integer; totalRecords: integer; totalInserted: integer; totalUpdated: integer; … }✅ Summary statistics
Property Type Required Description nodes { object: string; dependsOn: string[]; references: object[] }[]✅ All objects in the dependency graph insertOrder string[]✅ Topologically sorted insert order circularDependencies string[][]optional (default: []) Circular dependency chains (e.g., [["a", "b", "a"]])
Result of loading a single dataset
Property Type Required Description object string✅ Object that was loaded mode Enum<'update' | 'upsert' | 'ignore'>✅ Import mode used inserted integer✅ Records inserted updated integer✅ Records updated skipped integer✅ Records skipped errored integer✅ Records with errors total integer✅ Total records in dataset referencesResolved integer✅ References resolved via externalId referencesDeferred integer✅ References deferred to second pass referencesDropped integeroptional (default: 0) Reference fields dropped from records that were still written summariesStale integeroptional (default: 0) Roll-up summary values left stale by writes for this dataset landedIds string[]optional (default: []) Ids of the stored rows this dataset landed on: inserted, updated, or matched on replay insertedIds string[]optional (default: []) Ids among landedIds whose row this load created (a successful insert); every other landed id was a pre-existing row a record key matched errors { sourceObject: string; field: string; targetObject: string; targetField: string; … }[]optional (default: []) Reference resolution errors
Actionable error for a failed reference resolution
Property Type Required Description sourceObject string✅ Object with the broken reference field string✅ Field name with unresolved reference targetObject string✅ Target object searched for the reference targetField string✅ ExternalId field used for matching attemptedValue any✅ Value that failed to resolve recordIndex integer✅ Index of the record in the dataset message string✅ Human-readable error description
Property Type Required Description objectsProcessed integer✅ Total objects processed totalRecords integer✅ Total records across all objects totalInserted integer✅ Total records inserted totalUpdated integer✅ Total records updated totalSkipped integer✅ Total records skipped totalErrored integer✅ Total records with errors totalReferencesResolved integer✅ Total references resolved totalReferencesDeferred integer✅ Total references deferred totalReferencesDropped integeroptional (default: 0) Total reference fields dropped from written records totalSummariesStale integeroptional (default: 0) Total roll-up summary values left stale across the load circularDependencyCount integer✅ Circular dependency chains detected durationMs number✅ Load duration in milliseconds