ObjectStackObjectStack

Branded Types

Branded Types protocol schemas

Branded Types for ObjectStack Identifiers

Branded types provide compile-time safety by preventing accidental mixing of different identifier kinds. For example, you cannot pass an ObjectName where a FieldName is expected, even though both are strings at runtime.

@example

import { ObjectNameSchema, FieldNameSchema } from '@objectstack/spec';

const objName = ObjectNameSchema.parse('project_task');   // ObjectName
const fieldName = FieldNameSchema.parse('task_name');     // FieldName

// TypeScript will catch this at compile time:
// const fn: FieldName = objName; // Error!

Source: packages/spec/src/shared/branded-types.zod.ts

TypeScript Usage

import { AppNameSchema, FieldNameSchema, FlowNameSchema, ObjectNameSchema, RoleNameSchema, ViewNameSchema } from '@objectstack/spec/shared';
import type { AppName, FieldName, FlowName, ObjectName, RoleName, ViewName } from '@objectstack/spec/shared';

// Validate data
const result = AppNameSchema.parse(data);

AppName

Branded app name (system identifier)

Type: string


FieldName

Branded field name (snake_case, no dots)

Type: string


FlowName

Branded flow name (system identifier)

Type: string


ObjectName

Branded object name (snake_case, no dots)

Type: string


RoleName

Branded role name (system identifier)

Type: string


ViewName

Branded view name (system identifier)

Type: string


On this page