@ontologie/schema
v0.1.0-preview.4
Published
Schema authoring DSL for DataForge — define, compile, diff, push, and pull ontology schemas
Readme
@ontologie/schema
Schema authoring DSL for Ontologie -- define your ontology in code, compile, diff, push, and pull.
Install
npm install @ontologie/schemaQuick Start
Define your business model in a dataforge.schema.ts file:
import { objectType, string, number, boolean, date, link } from '@ontologie/schema';
export const Company = objectType('Company', {
name: string().required(),
industry: string(),
revenue: number(),
isActive: boolean().default(true),
});
export const Employee = objectType('Employee', {
name: string().required(),
email: string().email(),
salary: number().indexed(),
startDate: date(),
company: link.toOne(() => Company),
});Then use the CLI:
dataforge schema diff # compare local vs remote
dataforge schema push --yes # apply changes
dataforge schema pull # generate from remote
dataforge schema check # verify lockfile integrityAPI
Property Builders
| Builder | Type | Modifiers |
|---------|------|-----------|
| string() | string | .required(), .indexed(), .unique(), .default(v), .description(s), .email(), .enum([...]) |
| number() | number | .required(), .indexed(), .unique(), .default(v), .min(n), .max(n) |
| boolean() | boolean | .required(), .default(v) |
| date() | date | .required(), .indexed(), .datetime() |
| object() | object | .required() |
| array() | array | .required() |
Link Builders
link.toOne(() => TargetType) // N:1 relationship
link.toMany(() => TargetType) // 1:N relationshipModifiers: .inverseName(s), .label(s), .description(s)
Lazy () => Type references support circular dependencies.
Object Type
objectType('ApiName', { ...fields })
.displayName('Human Name')
.description('A description')
.primaryKey('fieldName')Compiler
import { compile } from '@ontologie/schema';
const manifest = compile([Company, Employee]);
// -> OntologyManifest (deterministic IDs, sorted)Diff
import { diff, formatDiff } from '@ontologie/schema';
const result = diff(localManifest, remoteManifest);
console.log(formatDiff(result));
// + ObjectType: Invoice (new)
// ~ ObjectType: Employee
// + property: department (string, required)
// ~ property: salary (indexed: false -> true)Push
import { planPush, executePush } from '@ontologie/schema';
const commands = planPush(diffResult, remoteManifest, { workspaceId });
await executePush({ transport, commands, onProgress: console.log });Pull
import { emitSchema } from '@ontologie/schema';
const source = emitSchema(remoteManifest);
// -> valid TypeScript source using the DSLLockfile
import { generateLockfile, verifyLockfile } from '@ontologie/schema';
const lock = generateLockfile(manifest);
const { drifted } = verifyLockfile(lock, currentManifest);Dependencies
| Package | Role |
|---------|------|
| @ontologie/sdk-types | OntologyManifest, PropertyDescriptor, etc. |
No dependency on @ontologie/sdk-client -- the schema package is standalone. Only the CLI depends on both.
See Also
- SDK README -- Getting started
- CLI README -- CLI commands
- CHANGELOG -- Version history
