Skip to content

Commit 32d7c64

Browse files
committed
Add dataset schema and import mode enums
Introduces DatasetSchema and DatasetMode using zod for standardized data import strategies and seed data handling. Also exports these from the package spec index for external use.
1 parent ad649aa commit 32d7c64

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { z } from 'zod';
2+
3+
/**
4+
* Data Import Strategy
5+
* Defines how the engine handles existing records.
6+
*/
7+
export const DatasetMode = z.enum([
8+
'insert', // Try to insert, fail on duplicate
9+
'update', // Only update found records, ignore new
10+
'upsert', // Create new or Update existing (Standard)
11+
'replace', // Delete ALL records in object then insert (Dangerous - use for cache tables)
12+
'ignore' // Try to insert, silently skip duplicates
13+
]);
14+
15+
/**
16+
* Dataset Schema (Seed Data / Fixtures)
17+
*
18+
* Standardized format for transporting data.
19+
* Used for:
20+
* 1. System Bootstrapping (Admin accounts, Standard Roles)
21+
* 2. Reference Data (Countries, Currencies)
22+
* 3. Demo/Test Data
23+
*/
24+
export const DatasetSchema = z.object({
25+
/**
26+
* Target Object
27+
* The machine name of the object to populate.
28+
*/
29+
object: z.string().regex(/^[a-z_][a-z0-9_]*$/).describe('Target Object Name'),
30+
31+
/**
32+
* Idempotency Key (The "Upsert" Key)
33+
* The field used to check if a record already exists.
34+
* Best Practice: Use a natural key like 'code', 'slug', 'username' or 'external_id'.
35+
* Standard: '_id' (internal ID) is rarely used for portable seed data.
36+
*/
37+
externalId: z.string().default('name').describe('Field match for uniqueness check'),
38+
39+
/**
40+
* Import Strategy
41+
*/
42+
mode: DatasetMode.default('upsert').describe('Conflict resolution strategy'),
43+
44+
/**
45+
* Environment Scope
46+
* - 'all': Always load
47+
* - 'dev': Only for development/demo
48+
* - 'test': Only for CI/CD tests
49+
*/
50+
env: z.array(z.enum(['prod', 'dev', 'test'])).default(['prod', 'dev', 'test']).describe('Applicable environments'),
51+
52+
/**
53+
* The Payload
54+
* Array of raw JSON objects matching the Object Schema.
55+
*/
56+
records: z.array(z.record(z.any())).describe('Data records'),
57+
});
58+
59+
export type Dataset = z.infer<typeof DatasetSchema>;
60+
export type DatasetImportMode = z.infer<typeof DatasetMode>;

packages/spec/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export * from './data/validation.zod';
1414
export * from './data/permission.zod';
1515
export * from './data/workflow.zod';
1616
export * from './data/flow.zod';
17+
export * from './data/dataset.zod';
1718

1819
// UI Protocol (Layout, Navigation, Interaction)
1920
export * from './ui/app.zod';

0 commit comments

Comments
 (0)