Skip to Content

TypeScript SDK overview

Query objects, apply actions, and run functions from any TypeScript runtime with @osdk/client, in Node.js scripts, servers, Vue, or any framework.

Foundry docsTypeScript OSDK

@osdk/client reads and edits your Ontology from any JavaScript runtime with fetch: Node.js scripts and servers, serverless functions, and browser apps in any framework. It has no UI dependency. Your generated SDK supplies typed definitions for your object types, interfaces, actions, and functions, and the client runs them.

Install

Your generated SDK comes from your Foundry npm registry. Set up .npmrc as described in Installation, then:

npm install @osdk/client @osdk/api @osdk/oauth @my-app/sdk@latest

Create one client for your app with createClient, as described in Create a client. Authentication covers the token provider. The samples in this section import that client from ./client.

Example

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

const page = await client(Employee)
  .where({ department: "Engineering", jobTitle: { $isNull: true } })
  .fetchPage({ $select: ["fullName"], $pageSize: 20 });

for (const employee of page.data) {
  await client(modifyEmployee).applyAction({ employee, jobTitle: "Engineer" });
  console.log(`Set title for ${employee.fullName}`);
}

The query runs on the server and returns typed objects. Each applyAction call validates and applies one edit. In real code, wrap it in try/catch, as shown in Actions.

One entry point: client(definition)

Call client with a definition from your SDK. What it returns depends on the definition:

You passYou getMain methods
An object type, such as EmployeeAn object set of every object of that typefetchOne, fetchPage, asyncIter, where, aggregate, pivotTo, withProperties, subscribe
An interface, such as WorkerAn object set over every type that implements itThe same, except fetchOne
An action, such as modifyEmployeeAn action invokerapplyAction, batchApplyAction
A function (query)A function invokerexecuteFunction

Object sets are lazy descriptions. where, pivotTo, union, and withProperties return new object sets without sending a request. A request goes out when you call a method that loads data: fetchOne, fetchPage, asyncIter, aggregate, or subscribe.

client.fetchMetadata(definition) loads the definition from Foundry at runtime, such as an object type's displayName, description, and icon, or an interface's implementedBy.

Relation to @osdk/react

@osdk/react is built on this client. Its hooks accept the same where clauses, derived property definitions, and action parameters, and add a shared cache that keeps components current after actions and live updates. In a React app, use the hooks for data you render and call the client directly for one-off work, such as exports. See Objects in React.

Outside React, framework guides show how to wire the client in Node.js and Vue.

In this section

On this page