ObjectStackObjectStack

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.

Seed Loader Protocol

Defines the schemas for metadata-driven seed data loading with automatic relationship resolution, dependency ordering, and multi-pass insertion.

Architecture Alignment

  • 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

Loading Flow

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

TypeScript Usage

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);

ObjectDependencyGraph

Complete object dependency graph for seed data loading

Properties

PropertyTypeRequiredDescription
nodes{ object: string; dependsOn: string[]; references: object[] }[]✅All objects in the dependency graph
insertOrderstring[]✅Topologically sorted insert order
circularDependenciesstring[][]optional (default: [])Circular dependency chains (e.g., [["a", "b", "a"]])

Nested Shape: ObjectDependencyGraph.nodes[number]

Object node in the seed data dependency graph

PropertyTypeRequiredDescription
objectstring✅Object name (snake_case)
dependsOnstring[]✅Objects this object depends on
references{ field: string; targetObject: string; targetField?: string; fieldType: Enum<'lookup' | 'master_detail' | 'user'>; … }[]✅Field-level reference details

ObjectDependencyNode

Object node in the seed data dependency graph

Properties

PropertyTypeRequiredDescription
objectstring✅Object name (snake_case)
dependsOnstring[]✅Objects this object depends on
references{ field: string; targetObject: string; targetField?: string; fieldType: Enum<'lookup' | 'master_detail' | 'user'>; … }[]✅Field-level reference details

Nested Shape: ObjectDependencyNode.references[number]

Describes how a field reference is resolved during seed loading

PropertyTypeRequiredDescription
fieldstring✅Source field name containing the reference value
targetObjectstring✅Target object name (snake_case)
targetFieldstringoptional (default: "name")Field on target object used for matching
fieldTypeEnum<'lookup' | 'master_detail' | 'user'>✅Relationship field type
multiplebooleanoptionalField stores an array of references (multiple: true)

ReferenceResolution

Describes how a field reference is resolved during seed loading

Properties

PropertyTypeRequiredDescription
fieldstring✅Source field name containing the reference value
targetObjectstring✅Target object name (snake_case)
targetFieldstringoptional (default: "name")Field on target object used for matching
fieldTypeEnum<'lookup' | 'master_detail' | 'user'>✅Relationship field type
multiplebooleanoptionalField stores an array of references (multiple: true)

ReferenceResolutionError

Actionable error for a failed reference resolution

Properties

PropertyTypeRequiredDescription
sourceObjectstring✅Object with the broken reference
fieldstring✅Field name with unresolved reference
targetObjectstring✅Target object searched for the reference
targetFieldstring✅ExternalId field used for matching
attemptedValueany✅Value that failed to resolve
recordIndexinteger✅Index of the record in the dataset
messagestring✅Human-readable error description

SeedIdentity

Identity context for resolving os.user / os.org in seed CEL values

Properties

PropertyTypeRequiredDescription
user{ id: string; role?: string; email?: string }optionalSubject bound to os.user in seed CEL expressions
org{ id: string; tier?: string }optionalOrganization bound to os.org in seed CEL expressions

SeedLoadResult

Result of loading a single dataset

Properties

PropertyTypeRequiredDescription
objectstring✅Object that was loaded
modeEnum<'update' | 'upsert' | 'ignore'>✅Import mode used
insertedinteger✅Records inserted
updatedinteger✅Records updated
skippedinteger✅Records skipped
erroredinteger✅Records with errors
totalinteger✅Total records in dataset
referencesResolvedinteger✅References resolved via externalId
referencesDeferredinteger✅References deferred to second pass
referencesDroppedintegeroptional (default: 0)Reference fields dropped from records that were still written
summariesStaleintegeroptional (default: 0)Roll-up summary values left stale by writes for this dataset
landedIdsstring[]optional (default: [])Ids of the stored rows this dataset landed on: inserted, updated, or matched on replay
insertedIdsstring[]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

Nested Shape: SeedLoadResult.errors[number]

Actionable error for a failed reference resolution

PropertyTypeRequiredDescription
sourceObjectstring✅Object with the broken reference
fieldstring✅Field name with unresolved reference
targetObjectstring✅Target object searched for the reference
targetFieldstring✅ExternalId field used for matching
attemptedValueany✅Value that failed to resolve
recordIndexinteger✅Index of the record in the dataset
messagestring✅Human-readable error description

SeedLoaderConfig

Seed data loader configuration

Properties

PropertyTypeRequiredDescription
dryRunbooleanoptional (default: false)Validate references without writing data
haltOnErrorbooleanoptional (default: false)Stop on first reference resolution error
multiPassbooleanoptional (default: true)Enable multi-pass loading for circular dependencies
defaultModeEnum<'update' | 'upsert' | 'ignore'>optional (default: "ignore")Default conflict resolution strategy: the seed mode default (ignore, create-only)
batchSizeintegeroptional (default: 1000)Maximum records per batch insert/upsert
transactionbooleanoptional (default: false)Wrap entire load in a transaction (all-or-nothing)
envEnum<'prod' | 'dev' | 'test'>optionalOnly load datasets matching this environment
localestringoptionalOnly load datasets scoped to this locale (BCP-47 tag)
organizationIdstringoptionalTarget organization id for per-tenant seed replay
identity{ user?: object; org?: object }optionalIdentity bound to os.user / os.org when resolving CEL seed values

Nested Shape: SeedLoaderConfig.identity

PropertyTypeRequiredDescription
user{ id: string; role?: string; email?: string }optionalSubject bound to os.user in seed CEL expressions
org{ id: string; tier?: string }optionalOrganization bound to os.org in seed CEL expressions

SeedLoaderRequest

Seed loader request with datasets and configuration

Properties

PropertyTypeRequiredDescription
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

Nested Shape: SeedLoaderRequest.seeds[number]

PropertyTypeRequiredDescription
objectstring✅Target Object Name
externalIdstring | string[]optional (default: "name")Field (or composite list of fields) matched for the uniqueness check
modeEnum<'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.
columnsRecord<string, { applyOn?: Enum<'create' | 'always'> }>optionalPer-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.
envEnum<'prod' | 'dev' | 'test'>[]optional (default: ["prod","dev","test"])Applicable environments
localestring[]optionalApplicable 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
fallbacktrueoptionalMarks 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.
dependsOnstring[]optionalObjects (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.
recordsRecord<string, any>[]✅Data records
filesRecord<string, { contentType: string; size: integer; sha256: string; data: string }>optionalBytes 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.
_lockEnum<'none' | 'no-overlay' | 'no-delete' | 'full'>optionalItem-level lock — controls overlay & delete (ADR-0010).
_lockReasonstringoptionalHuman-readable reason shown when a write is refused by _lock.
_lockSourceEnum<'artifact' | 'package' | 'env-forced'>optionalLayer that set _lock (artifact | package | env-forced).
_provenanceEnum<'package' | 'org' | 'env-forced' | 'platform'>optionalOrigin of the item (package | org | env-forced | platform).
_packageIdstringoptionalOwning package machine id.
_packageVersionstringoptionalOwning package version.
_lockDocsUrlstringoptionalOptional documentation link surfaced next to _lockReason.

Nested Shape: SeedLoaderRequest.config

PropertyTypeRequiredDescription
dryRunbooleanoptional (default: false)Validate references without writing data
haltOnErrorbooleanoptional (default: false)Stop on first reference resolution error
multiPassbooleanoptional (default: true)Enable multi-pass loading for circular dependencies
defaultModeEnum<'update' | 'upsert' | 'ignore'>optional (default: "ignore")Default conflict resolution strategy: the seed mode default (ignore, create-only)
batchSizeintegeroptional (default: 1000)Maximum records per batch insert/upsert
transactionbooleanoptional (default: false)Wrap entire load in a transaction (all-or-nothing)
envEnum<'prod' | 'dev' | 'test'>optionalOnly load datasets matching this environment
localestringoptionalOnly load datasets scoped to this locale (BCP-47 tag)
organizationIdstringoptionalTarget organization id for per-tenant seed replay
identity{ user?: object; org?: object }optionalIdentity bound to os.user / os.org when resolving CEL seed values

SeedLoaderResult

Complete seed loader result

Properties

PropertyTypeRequiredDescription
successboolean✅Overall success status
dryRunboolean✅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

Nested Shape: SeedLoaderResult.dependencyGraph

PropertyTypeRequiredDescription
nodes{ object: string; dependsOn: string[]; references: object[] }[]✅All objects in the dependency graph
insertOrderstring[]✅Topologically sorted insert order
circularDependenciesstring[][]optional (default: [])Circular dependency chains (e.g., [["a", "b", "a"]])

Nested Shape: SeedLoaderResult.results[number]

Result of loading a single dataset

PropertyTypeRequiredDescription
objectstring✅Object that was loaded
modeEnum<'update' | 'upsert' | 'ignore'>✅Import mode used
insertedinteger✅Records inserted
updatedinteger✅Records updated
skippedinteger✅Records skipped
erroredinteger✅Records with errors
totalinteger✅Total records in dataset
referencesResolvedinteger✅References resolved via externalId
referencesDeferredinteger✅References deferred to second pass
referencesDroppedintegeroptional (default: 0)Reference fields dropped from records that were still written
summariesStaleintegeroptional (default: 0)Roll-up summary values left stale by writes for this dataset
landedIdsstring[]optional (default: [])Ids of the stored rows this dataset landed on: inserted, updated, or matched on replay
insertedIdsstring[]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

Nested Shape: SeedLoaderResult.errors[number]

Actionable error for a failed reference resolution

PropertyTypeRequiredDescription
sourceObjectstring✅Object with the broken reference
fieldstring✅Field name with unresolved reference
targetObjectstring✅Target object searched for the reference
targetFieldstring✅ExternalId field used for matching
attemptedValueany✅Value that failed to resolve
recordIndexinteger✅Index of the record in the dataset
messagestring✅Human-readable error description

Nested Shape: SeedLoaderResult.summary

PropertyTypeRequiredDescription
objectsProcessedinteger✅Total objects processed
totalRecordsinteger✅Total records across all objects
totalInsertedinteger✅Total records inserted
totalUpdatedinteger✅Total records updated
totalSkippedinteger✅Total records skipped
totalErroredinteger✅Total records with errors
totalReferencesResolvedinteger✅Total references resolved
totalReferencesDeferredinteger✅Total references deferred
totalReferencesDroppedintegeroptional (default: 0)Total reference fields dropped from written records
totalSummariesStaleintegeroptional (default: 0)Total roll-up summary values left stale across the load
circularDependencyCountinteger✅Circular dependency chains detected
durationMsnumber✅Load duration in milliseconds

On this page