Skip to Content

Osdk.Instance

The type of a loaded object, with its properties plus $-prefixed fields for identity, links, and conversion.

import type { Osdk } from "@osdk/client";

namespace Osdk {
  type Instance<
    Q extends ObjectOrInterfaceDefinition,
    OPTIONS extends never | "$rid" | "$allBaseProperties" | "$propertySecurities" = never,
    P extends PropertyKeys<Q> | ReducedValues<Q> = PropertyKeys<Q>,
    R extends Record<string, SimplePropertyDef> = {},
  >;
}

Every object returned by fetchPage, fetchOne, asyncIter, and the @osdk/react hooks has this type. It holds the properties in P, the derived properties in R, and the fields below. Generated SDKs export a shorthand, such as Employee.OsdkInstance.

Type parameterDescription
QThe object type or interface.
OPTIONSExtra fields: "$rid" adds $rid, "$propertySecurities" adds $propertySecurities, and "$allBaseProperties" marks an interface instance that carries every property of its object type.
PThe loaded properties. Narrowed by $select.
RDerived properties added with withProperties.

Fields

Osdk.Instance is an intersection of mapped and conditional types, so this table is written by hand.

FieldTypeDescription
$apiNameQ["apiName"]The API name of Q. For an interface instance, the interface name.
$objectTypestringThe API name of the underlying object type, also for interface instances.
$primaryKeyPrimaryKeyType<Q>The primary key value.
$titlestring | undefinedThe value of the type's title property.
$objectSpecifierObjectSpecifier<Q>A string that identifies the object across object types.
$link{ [link]: SingleLinkAccessor | ObjectSet }Links of the object. A single link has fetchOne and fetchOneWithErrors; a many link is an ObjectSet.
$as(type) => Osdk.InstanceConverts between an object type and an interface it implements, mapping property names.
$clone(updates?) => Osdk.InstanceReturns a copy with some properties replaced. Use it to build optimistic updates.
$ridstringThe object's RID. Present only when loaded with $includeRid: true.
$propertySecuritiesObjectPropertySecuritiesPer-property marking requirements. Present only when loaded with $loadPropertySecurityMetadata: true.
$scorenumberRelevance score. Present only when ordered by "relevance".

Example

src/describeEmployee.ts
import { Employee, Worker } from "@my-app/sdk";
import type { Client, Osdk } from "@osdk/client";

export async function describeEmployee(client: Client, employeeId: number) {
  const employee: Osdk.Instance<Employee> = await client(Employee).fetchOne(employeeId);

  const lead = await employee.$link.lead.fetchOne();
  const reports = await employee.$link.reports.fetchPage({ $pageSize: 5 });
  const asWorker = employee.$as(Worker);

  return {
    key: `${employee.$objectType}:${employee.$primaryKey}`,
    title: employee.$title,
    lead: lead.fullName,
    reports: reports.data.map((r) => r.fullName),
    workerName: asWorker.name,
  };
}

See also

On this page