Skip to content

Latest commit

 

History

History
343 lines (253 loc) · 19.8 KB

seed-loader.mdx

File metadata and controls

343 lines (253 loc) · 19.8 KB
title Seed Loader schema — Data Protocol reference
navTitle Seed Loader
description Defines the schemas for metadata-driven seed data loading with automatic relationship resolution, dependency ordering, and multi-pass insertion.

{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */}

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

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"]])

Nested Shape: ObjectDependencyGraph.nodes[number]

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

ObjectDependencyNode

Object node in the seed data dependency graph

Properties

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

Nested Shape: ObjectDependencyNode.references[number]

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 string optional (default: "name") Field on target object used for matching
fieldType Enum<'lookup' | 'master_detail' | 'user'> ✅ Relationship field type
multiple boolean optional Field stores an array of references (multiple: true)

ReferenceResolution

Describes how a field reference is resolved during seed loading

Properties

Property Type Required Description
field string ✅ Source field name containing the reference value
targetObject string ✅ Target object name (snake_case)
targetField string optional (default: "name") Field on target object used for matching
fieldType Enum<'lookup' | 'master_detail' | 'user'> ✅ Relationship field type
multiple boolean optional Field stores an array of references (multiple: true)

ReferenceResolutionError

Actionable error for a failed reference resolution

Properties

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

SeedIdentity

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

Properties

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

SeedLoadResult

Result of loading a single dataset

Properties

Property Type Required Description
object string ✅ Object that was loaded
mode Enum<'insert' | 'update' | 'upsert' | 'replace' | '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 integer optional (default: 0) Reference fields dropped from records that were still written
summariesStale integer optional (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

Nested Shape: SeedLoadResult.errors[number]

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

SeedLoaderConfig

Seed data loader configuration

Properties

Property Type Required Description
dryRun boolean optional (default: false) Validate references without writing data
haltOnError boolean optional (default: false) Stop on first reference resolution error
multiPass boolean optional (default: true) Enable multi-pass loading for circular dependencies
defaultMode Enum<'insert' | 'update' | 'upsert' | 'replace' | 'ignore'> optional (default: "ignore") Default conflict resolution strategy: the seed mode default (ignore, create-only)
batchSize integer optional (default: 1000) Maximum records per batch insert/upsert
transaction boolean optional (default: false) Wrap entire load in a transaction (all-or-nothing)
env Enum<'prod' | 'dev' | 'test'> optional Only load datasets matching this environment
locale string optional Only load datasets scoped to this locale (BCP-47 tag)
organizationId string optional 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

Nested Shape: SeedLoaderConfig.identity

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

SeedLoaderRequest

Seed loader request with datasets and configuration

Properties

Property Type Required Description
seeds { object: string; externalId?: string | string[]; mode?: Enum<'insert' | 'update' | 'upsert' | 'replace' | 'ignore'>; columns?: Record<string, object>; … }[] ✅ Seeds to load
config { dryRun?: boolean; haltOnError?: boolean; multiPass?: boolean; defaultMode?: Enum<'insert' | 'update' | 'upsert' | 'replace' | 'ignore'>; … } optional (has default) Loader configuration

Nested Shape: SeedLoaderRequest.seeds[number]

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<'insert' | 'update' | 'upsert' | 'replace' | '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, insert inserts every record with no match, so each replay inserts them again, and replace does the same and deletes nothing: it is for a table the caller cleared. 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
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 string optional 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'> optional Origin of the item (package | org | env-forced).
_packageId string optional Owning package machine id.
_packageVersion string optional Owning package version.
_lockDocsUrl string optional Optional documentation link surfaced next to _lockReason.

Nested Shape: SeedLoaderRequest.config

Property Type Required Description
dryRun boolean optional (default: false) Validate references without writing data
haltOnError boolean optional (default: false) Stop on first reference resolution error
multiPass boolean optional (default: true) Enable multi-pass loading for circular dependencies
defaultMode Enum<'insert' | 'update' | 'upsert' | 'replace' | 'ignore'> optional (default: "ignore") Default conflict resolution strategy: the seed mode default (ignore, create-only)
batchSize integer optional (default: 1000) Maximum records per batch insert/upsert
transaction boolean optional (default: false) Wrap entire load in a transaction (all-or-nothing)
env Enum<'prod' | 'dev' | 'test'> optional Only load datasets matching this environment
locale string optional Only load datasets scoped to this locale (BCP-47 tag)
organizationId string optional 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

SeedLoaderResult

Complete seed loader result

Properties

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<'insert' | 'update' | 'upsert' | 'replace' | '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

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"]])

Nested Shape: SeedLoaderResult.results[number]

Result of loading a single dataset

Property Type Required Description
object string ✅ Object that was loaded
mode Enum<'insert' | 'update' | 'upsert' | 'replace' | '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 integer optional (default: 0) Reference fields dropped from records that were still written
summariesStale integer optional (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

Nested Shape: SeedLoaderResult.errors[number]

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

Nested Shape: SeedLoaderResult.summary

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 integer optional (default: 0) Total reference fields dropped from written records
totalSummariesStale integer optional (default: 0) Total roll-up summary values left stale across the load
circularDependencyCount integer ✅ Circular dependency chains detected
durationMs number ✅ Load duration in milliseconds