Skip to Content

Object types

Define object types with defineObject from @osdk/maker, including property types, primary keys, titles, value types, and datasources.

Foundry docsObject types

An object type describes one kind of thing in your ontology, such as an employee or an office: its properties, which property identifies each object, and where its data comes from. Define one with defineObject from @osdk/maker in your .ontology/ontology.mts file.

Define an object type

.ontology/ontology.mts
import { defineObject } from "@osdk/maker";

export const employee = defineObject({
  apiName: "Employee",
  displayName: "Employee",
  pluralDisplayName: "Employees",
  description: "A person employed by the company.",
  icon: { locator: "person", color: "#2D72D2" },
  primaryKeyPropertyApiName: "employeeId",
  titlePropertyApiName: "fullName",
  properties: {
    employeeId: { type: "integer", displayName: "Employee ID" },
    fullName: { type: "string", displayName: "Full name" },
    jobTitle: { type: "string" },
    department: { type: "string" },
    startDate: { type: "date" },
    salary: { type: "double" },
    skills: { type: "string", array: true },
  },
});

defineObject registers the type and returns its definition with the namespaced API name, so employee.apiName is com.example.Employee when you compile with --apiNamespace com.example. Pass the returned value wherever another definition needs the object type, such as a link or an action.

OptionTypeDefaultDescription
apiNamestringRequired. The API name, without the namespace.
displayNamestringRequired. The singular name shown in Foundry.
pluralDisplayNamestringRequired. The plural name shown in Foundry.
primaryKeyPropertyApiNamestringRequired. The property whose value identifies each object.
titlePropertyApiNamestringRequired. The property shown as each object's title.
propertiesRecord<string, PropertyDefinition>The properties, keyed by API name. See Properties.
descriptionstringA description shown in Foundry.
icon{ locator: BlueprintIcon; color: string }A Blueprint icon name and a hex color.
visibility"PROMINENT" | "NORMAL" | "HIDDEN"How prominently Foundry shows the type.
statusObjectTypeStatus"active"See Status.
implementsInterfacesArray<InterfaceImplementation>Interfaces the type implements. See Interfaces.
datasourcesArray<DatasourceDefinition>A datasetWhere property values come from. See Datasources.
editsEnabledbooleanWhether users can edit objects of this type.
editsHistoryConfig{ enabled: boolean; storeAllPreviousProperties?: boolean }Whether to keep a history of edits.
aliasesArray<string>Other names to find the type by in search.
includeEmptyBackingDatasourcebooleanAsk @osdk/maker-experimental to package an empty backing dataset. Only valid when every datasource is dataset or derived. The maker CLI ignores it.
permission"roles" | "publicProject" | { type: "ontologyPackage"; ontologyPackageRid: string }The permission model for the type.

Primary key and title

The primary key and title must both name properties of the object type, and defineObject throws if either is missing.

  • Primary key. Must be a primitive type, such as string or integer, and cannot be editOnly. Every object needs a unique value.
  • Title. Must be a primitive type, or a struct whose mainValue is primitive.

Properties

Each entry in properties maps an API name to a property definition. Only type is required. Property API names start with a letter and contain letters, digits, and _.

OptionTypeDefaultDescription
typePropertyTypeTypeRequired. See Property types.
displayNamestringThe API name with its first letter capitalizedThe name shown in Foundry.
descriptionstringA description shown in Foundry.
arraybooleanfalseStore a list of values of type.
reducersArray<{ direction: "ascending" | "descending"; structField?: string }>For arrays, how to reduce the list to one value for display.
valueTypeValueTypeDefinitionVersionA value type from defineValueType. Its constraints apply to the property. See Value types.
sharedPropertyTypeSharedPropertyTypeBack the property with a shared property type. A shared property type can back only one property per object type. See Shared property types.
nullability{ noNulls: boolean; noEmptyCollections: boolean }Disallow nulls or empty lists. Generated actions make the parameter required when noNulls is set.
visibility"PROMINENT" | "NORMAL" | "HIDDEN""NORMAL"How prominently Foundry shows the property.
statusObjectTypeStatusThe property's status. Must match the object's status unless the object is active.
editOnlybooleanThe property has no datasource column and only holds values written by edits.
indexedForSearchbooleantrue, except attachmentWhether the property is searchable.
typeClassesArray<{ kind: string; name: string }>SELECTABLE and SORTABLE render hintsType classes. struct, geoshape, mediaReference, geotimeSeries, attachment, and vector properties cannot have render hints.
baseFormatterOntologyIrBaseFormatterHow Foundry formats values for display.
includeEmptyBackingMediaSetbooleanFor mediaReference properties, ask @osdk/maker-experimental to package an empty media set. The maker CLI ignores it.

Property types

type takes a string for most types and an object for types with options.

TypeValueNotes
Boolean"boolean"
Integers"byte", "short", "integer", "long"
Decimals"float", "double", "decimal"{ type: "decimal", precision?: number, scale?: number } sets precision and scale, which default to 5 and 2.
String"string"{ type: "string", ... } sets search options; see below.
Date and time"date", "timestamp"
Attachment"attachment"
Geospatial"geopoint", "geoshape"
Media"mediaReference"Each mediaReference property gets its own media set datasource.
Time series"geotimeSeries"
Marking{ type: "marking", markingType: "MANDATORY" | "CBAC", markingInputGroupName: string }markingInputGroupName names the marking input chosen when the ontology is installed.
Struct{ type: "struct", structDefinition, mainValue? }See Struct properties.
Vector{ type: "vector", dimension: number, supportsSearchWith, embeddingModel?, quantization? }supportsSearchWith is "COSINE_SIMILARITY", "DOT_PRODUCT", or "EUCLIDEAN_DISTANCE". dimension must be an integer of at least 1, and a vector property cannot be an array.

The object form of string accepts isLongText, supportsEfficientLeadingWildcard, supportsExactMatching, supportsFullTextRegex, supportsPhonetic, enableAsciiFolding, and analyzerOverride:

.ontology/ontology.mts
import { defineObject } from "@osdk/maker";

export const article = defineObject({
  apiName: "Article",
  displayName: "Article",
  pluralDisplayName: "Articles",
  primaryKeyPropertyApiName: "articleId",
  titlePropertyApiName: "headline",
  properties: {
    articleId: { type: "string" },
    headline: { type: "string" },
    body: { type: { type: "string", isLongText: true, supportsPhonetic: true } },
  },
});

Struct properties

A struct property groups named fields into one value. Each field is a type name, or an object with fieldType and displayMetadata. Fields cannot be structs, markings, or vectors. mainValue names the field or fields that represent the struct when it is shown as a single value, such as a title.

.ontology/ontology.mts
import { defineObject } from "@osdk/maker";

export const customer = defineObject({
  apiName: "Customer",
  displayName: "Customer",
  pluralDisplayName: "Customers",
  primaryKeyPropertyApiName: "customerId",
  titlePropertyApiName: "customerId",
  properties: {
    customerId: { type: "string" },
    address: {
      type: {
        type: "struct",
        structDefinition: {
          street: "string",
          city: "string",
          postcode: {
            fieldType: "string",
            displayMetadata: { displayName: "Postcode", description: "Postal code" },
          },
        },
        mainValue: { fields: "street", type: "string" },
      },
    },
  },
});

Value types

A value type is a reusable, versioned type with constraints, such as "a string that looks like an email address". Define it with defineValueType, then reference it from a property with valueType. Value types are written to value-types.json as well as the IR.

.ontology/ontology.mts
import { defineObject, defineValueType } from "@osdk/maker";

export const emailAddress = defineValueType({
  apiName: "emailAddress",
  displayName: "Email address",
  version: "1.0.0",
  type: {
    type: "string",
    constraints: [
      {
        constraint: {
          type: "regex",
          regex: { regexPattern: "^[^@]+@[^@]+$", usePartialMatch: false },
        },
        failureMessage: { message: "Enter a valid email address." },
      },
    ],
  },
});

export const contact = defineObject({
  apiName: "Contact",
  displayName: "Contact",
  pluralDisplayName: "Contacts",
  primaryKeyPropertyApiName: "contactId",
  titlePropertyApiName: "email",
  properties: {
    contactId: { type: "string" },
    email: { type: "string", valueType: emailAddress },
  },
});
OptionTypeDefaultDescription
apiNamestringRequired. The value type's API name.
displayNamestringRequired. The name shown in Foundry.
versionstringRequired. A semantic version. You can define several versions of the same API name; each version must be unique.
type{ type, constraints? }Required. The base type and its constraints.
descriptionstringA description shown in Foundry.
status"active" | { type: "deprecated"; message: string; deadline: string; replacedBy?: string }"active"Deprecate a version.
namespacePrefixbooleanfalsePrefix the API name with --apiNamespace.

type.type is a type name (boolean, binary, byte, short, integer, long, float, double, decimal, string, date, or timestamp) or an object for a composite type: { type: "array", elementType }, { type: "map", keyType, valueType }, { type: "optional", wrappedType }, or { type: "struct", fields: [{ identifier, baseType }] }. Each entry in constraints has a constraint for that base type and an optional failureMessage. String constraints are regex, oneOf, length, isUuid, and isRid:

.ontology/ontology.mts
import { defineValueType } from "@osdk/maker";

export const seniority = defineValueType({
  apiName: "seniority",
  displayName: "Seniority",
  version: "1.0.0",
  type: {
    type: "string",
    constraints: [
      {
        constraint: {
          type: "oneOf",
          oneOf: { values: ["junior", "senior", "principal"], useIgnoreCase: false },
        },
      },
    ],
  },
});

Status

status is "active", "experimental", "example", or { type: "deprecated", message, deadline }, where deadline is an ISO 8601 date or date-time. An experimental, example, or deprecated object type can only contain properties with the same status, and a link to it must have a matching status. See Link status.

.ontology/ontology.mts
import { defineObject } from "@osdk/maker";

export const legacyBadge = defineObject({
  apiName: "LegacyBadge",
  displayName: "Legacy badge",
  pluralDisplayName: "Legacy badges",
  primaryKeyPropertyApiName: "badgeId",
  titlePropertyApiName: "badgeId",
  properties: { badgeId: { type: "string" } },
  status: {
    type: "deprecated",
    message: "Use BadgeScan instead.",
    deadline: "2027-01-01",
  },
});

Datasources

datasources says where property values come from. Without it, a dataset backs every property. Give an object type one base datasource (dataset, stream, restrictedView, or direct) plus any number of derived datasources; defineObject throws if you list more than one dataset, stream, or restrictedView. Properties not mapped by a derived datasource come from the base datasource.

typeOptionsDescription
"dataset"objectSecurityPolicy?, propertySecurityGroups?A dataset backs the properties.
"stream"retentionPeriod?A stream backs the properties. retentionPeriod is an ISO 8601 duration, such as "P90D".
"restrictedView"A restricted view backs the properties.
"direct"objectSecurityPolicy?, propertySecurityGroups?A direct source backs the properties.
"derived"linkDefinition, propertyMappingProperties computed from linked objects. See Derived properties.
.ontology/ontology.mts
import { defineObject } from "@osdk/maker";

export const badgeScan = defineObject({
  apiName: "BadgeScan",
  displayName: "Badge scan",
  pluralDisplayName: "Badge scans",
  primaryKeyPropertyApiName: "scanId",
  titlePropertyApiName: "scanId",
  properties: {
    scanId: { type: "string" },
    scannedAt: { type: "timestamp" },
  },
  datasources: [{ type: "stream", retentionPeriod: "P90D" }],
});

Property security

On dataset and direct datasources, propertySecurityGroups restricts who can read a set of properties, and objectSecurityPolicy restricts who can read the objects. Each takes a name, an optional granularPolicy condition, and optional appliedMarkings and assumedMarkings maps from a marking input name to "CBAC" or "MANDATORY".

A granularPolicy condition is one of:

ConditionPasses when
{ type: "group", name }The user is in the group chosen for the input name when the ontology is installed.
{ type: "groupProperty", property }The user is in a group listed in property.
{ type: "markingProperty", property }The user satisfies the markings in the marking property property.
{ type: "and" | "or", conditions }All or any of conditions pass.
.ontology/ontology.mts
import { defineObject } from "@osdk/maker";

export const caseFile = defineObject({
  apiName: "CaseFile",
  displayName: "Case file",
  pluralDisplayName: "Case files",
  primaryKeyPropertyApiName: "caseId",
  titlePropertyApiName: "caseId",
  properties: {
    caseId: { type: "string" },
    summary: { type: "string" },
    classification: {
      type: { type: "marking", markingType: "MANDATORY", markingInputGroupName: "caseMarkings" },
    },
  },
  datasources: [
    {
      type: "dataset",
      propertySecurityGroups: [
        {
          name: "restrictedSummary",
          properties: ["summary"],
          granularPolicy: {
            type: "and",
            conditions: [
              { type: "markingProperty", property: "classification" },
              { type: "group", name: "investigators" },
            ],
          },
        },
      ],
    },
  ],
});

Derived properties

A derived datasource computes properties from objects reached through one or more links. linkDefinition lists the links to follow in order, and propertyMapping maps each derived property to either a property on the linked object or an aggregation.

AggregationDerived property must beDescription
{ type: "count" }AnyThe number of linked objects.
{ type: "sum" | "avg", property }NumericThe sum or average of property.
{ type: "min" | "max", property }PrimitiveThe smallest or largest value of property.
{ type: "approximateCardinality" | "exactCardinality", property }PrimitiveThe number of distinct values of property.
{ type: "collectList" | "collectSet", property, limit }An arrayUp to limit values of property, at most 100.

Aggregations skip linked objects where the property is null. Generated create, modify, and create-or-modify actions leave derived properties out of their parameters.

The link must be defined before the object that uses it. When the object is not defined yet, refer to it from the link by its API name:

.ontology/ontology.mts
import { defineLink, defineObject } from "@osdk/maker";

export const employee = defineObject({
  apiName: "Employee",
  displayName: "Employee",
  pluralDisplayName: "Employees",
  primaryKeyPropertyApiName: "employeeId",
  titlePropertyApiName: "fullName",
  properties: {
    employeeId: { type: "integer" },
    fullName: { type: "string" },
    officeId: { type: "string" },
  },
});

export const officeOccupants = defineLink({
  apiName: "office-occupants",
  one: { object: "Office", metadata: { apiName: "occupants" } },
  toMany: { object: employee, metadata: { apiName: "office" } },
  manyForeignKeyProperty: "officeId",
});

export const office = defineObject({
  apiName: "Office",
  displayName: "Office",
  pluralDisplayName: "Offices",
  primaryKeyPropertyApiName: "officeId",
  titlePropertyApiName: "name",
  properties: {
    officeId: { type: "string" },
    name: { type: "string" },
    headcount: { type: "integer" },
    occupantNames: { type: "string", array: true },
  },
  datasources: [
    { type: "dataset" },
    {
      type: "derived",
      linkDefinition: [{ linkType: officeOccupants }],
      propertyMapping: {
        headcount: { type: "count" },
        occupantNames: { type: "collectList", property: "fullName", limit: 100 },
      },
    },
  ],
});

When you compile with --apiNamespace, the string reference must include the namespace, such as "com.example.Office".

On this page