Skip to Content

The Ontology and your SDK

How object types, links, actions, functions, interfaces, and object sets map to the generated SDK and to Osdk.Instance values in TypeScript.

Your generated SDK is a typed description of part of a Foundry Ontology. This page explains what each Ontology concept becomes in TypeScript, so you can read the SDK and the values it returns.

Ontology concepts

ConceptWhat it isIn the generated SDKHow you use it
Object typeA schema for real-world entities, such as employees.A definition, Employee, plus the namespace types Employee.Props and Employee.OsdkInstance.client(Employee) returns an object set of every Employee.
PropertyA typed field on an object type.A key in Employee.Props, typed from the property's base type.Read it on an instance: employee.fullName.
Primary keyThe property that uniquely identifies an object.primaryKeyApiName and primaryKeyType on the definition.client(Employee).fetchOne(12345), or employee.$primaryKey.
Link typeA relationship between two object types.Entries in Employee.Links.employee.$link.lead for a single link, employee.$link.reports for many.
Action typeA transaction that edits objects.A definition, modifyEmployee.client(modifyEmployee).applyAction({ ... }).
Function (query)Server-side logic that reads the Ontology and returns a value.A definition, such as getEmployeeMetrics.client(getEmployeeMetrics).executeFunction({ ... }).
InterfaceA shared shape that several object types implement.A definition with its own properties.client(MyInterface).fetchPage(), then instance.$as(Employee).
Object setA lazy, composable query over objects.Employee.ObjectSet.client(Employee).where({ ... }).pivotTo("lead").

The generated package does not contain a client. It exports definitions, which are plain metadata. You pass a definition to a client created with createClient from @osdk/client, and the client does the work:

src/example.ts
import { Employee, getEmployeeMetrics, modifyEmployee } from "@my-app/sdk";
import { client } from "./client";

const page = await client(Employee)
  .where({ department: "Engineering" })
  .fetchPage({ $pageSize: 20 });

const employee = await client(Employee).fetchOne(12345);

await client(modifyEmployee).applyAction({
  employee,
  primary_office_id: "nyc-1",
});

const metrics = await client(getEmployeeMetrics).executeFunction({
  departmentId: "engineering",
});

See Create a client to set up client.

Why client(Employee)

The SDK separates the code that knows your Ontology (the generated package) from the code that talks to Foundry (@osdk/client). That design has practical effects:

  • Smaller bundles. Each definition is a small named export. Bundlers drop the ones you do not import, so the SDK's cost scales with what you use, not with the size of the Ontology.
  • One runtime. Several generated SDKs share the same @osdk/client code instead of each shipping its own.
  • Fixes without regenerating. A bug fix in @osdk/client reaches you through a dependency update. You do not need to regenerate the SDK.

If you want autocomplete across the whole Ontology, import the namespace exports. Tree-shaking still removes what you do not reference:

import { $Objects } from "@my-app/sdk";
import { client } from "./client";

const page = await client($Objects.Employee).fetchPage();

The generated package also exports $Actions, $Queries, and $Interfaces, and $ontologyRid when the SDK was generated for a single Foundry environment.

Object instances

Every object you fetch, from @osdk/client or from @osdk/react hooks, is an Osdk.Instance. The generated alias Employee.OsdkInstance is the same type:

import type { Employee } from "@my-app/sdk";
import type { Osdk } from "@osdk/client";

type A = Employee.OsdkInstance;
type B = Osdk.Instance<Employee>;

Metadata fields

Fields that start with $ describe the object rather than hold Ontology data:

FieldTypeDescription
$apiNamestringAPI name of the type you queried. For an interface query, this is the interface's API name.
$objectTypestringAPI name of the concrete object type, even when you queried an interface.
$primaryKeyPrimary key typeThe object's primary key value. Use it as a React key.
$titlestring | undefinedValue of the object type's title property.
$objectSpecifierObjectSpecifierA string that identifies the object by type and primary key.
$linkLinks objectAccessors for the object's links.
$asFunctionConverts between an interface and an object type that implements it.
$cloneFunctionReturns a copy of the instance with updated properties.
$ridstringThe object's RID. Present only when you request it with $includeRid: true.

Instances are immutable

Instances are frozen, and their properties are readonly. To get a changed copy, call $clone:

const renamed = employee.$clone({ fullName: "Ada Lovelace" });

$clone throws if the update changes the primary key. It does not write anything to Foundry. Use it to build optimistic state for an action, as shown in Optimistic updates. To change data, apply an action.

A single-valued link returns an accessor with fetchOne. A many-valued link returns an object set:

const lead = await employee.$link.lead.fetchOne();
const reports = await employee.$link.reports.fetchPage({ $pageSize: 50 });

In React, use useLinks instead so linked objects share the cache.

Property value types

Most properties are optional on the instance (T | undefined). Only the primary key and properties the Ontology marks as required are always present.

Ontology typeTypeScript valueNotes
stringstring
booleanboolean
integer, short, byte, float, doublenumber
longstringStrings keep 64-bit precision that number cannot hold.
decimalstringStrings keep arbitrary precision.
datestringISO 8601 date, such as "2024-03-15".
timestampstringISO 8601 date and time, such as "2024-03-15T09:30:00Z".
geopointGeoJSON.Point
geoshapeGeoJSON.GeoJSON
attachmentAttachmentHas rid, fetchMetadata(), and fetchContents(), which resolves to a Response.
mediaReferenceMediaHas fetchMetadata(), fetchContents(), and getMediaReference().
cipherTextCipherTextCall decrypt() to get the plaintext.
markingstring
vectornumber[]
Numeric, string, and sensor time seriesTimeSeriesPropertyHas getFirstPoint(), getLastPoint(), and getAllPoints().
geotimeSeriesReferenceGeotimeSeriesProperty

Dates and timestamps

The SDK returns dates and timestamps as ISO 8601 strings instead of Date objects or a date library's types. This keeps a large date library out of your bundle, lets you use the date library you already have, and avoids parsing values you never read.

Parse a value when you need date math:

const startDate =
  employee.startDate != null ? new Date(employee.startDate) : undefined;

To send a date-only value, @osdk/client exports helpers that format a Date as YYYY-MM-DD:

import { extractDateInLocalTime, extractDateInUTC } from "@osdk/client";

extractDateInLocalTime(new Date()); // "2024-03-15" in the user's time zone
extractDateInUTC(new Date()); // "2024-03-15" in UTC

extractDate returns the date part of an ISO 8601 timestamp string.

Object sets

An object set describes which objects you want. Building one does not send a request; only fetching does:

import { Employee } from "@my-app/sdk";
import { client } from "./client";

const engineers = client(Employee).where({ department: "Engineering" });
const theirLeads = engineers.pivotTo("lead");

const page = await theirLeads.fetchPage({ $pageSize: 20 });
MethodReturnsDescription
where(clause)Object setFilters the set.
union(...sets), intersect(...sets), subtract(...sets)Object setCombines sets of the same type.
pivotTo(link)Object setFollows a link to the linked type.
withProperties(...)Object setAdds derived properties computed on the server.
fetchPage(options)Promise of a pageFetches one page: data, nextPageToken, and totalCount.
fetchOne(primaryKey)Promise of an instanceFetches one object. Object types only.
asyncIter()Async iteratorIterates over every object across pages.
aggregate(options)Promise of resultsRuns an aggregation on the server.
subscribe(listener)SubscriptionReceives changes to the set over a WebSocket.

In React, pass the same filters to useOsdkObjects or build a set with useObjectSet.

Interfaces

An interface lets you query several object types through one shape. Instances from an interface query expose the interface's properties. $objectType tells you the concrete type, and $as converts to it:

import { Employee, Worker } from "@my-app/sdk";
import { client } from "./client";

const { data } = await client(Worker).fetchPage();

for (const worker of data) {
  if (worker.$objectType === "Employee") {
    const employee = worker.$as(Employee);
    console.log(employee.fullName);
  }
}

On this page