/** * Palantir Foundry Ontologies API. * Ontologies, Object Types, Objects, Actions, Functions, Queries, Links, * Interface Types, object counts, and full metadata. * * @see https://www.palantir.com/docs/foundry/api/v2/ontologies-v2-resources/ */ import type { PalantirClient } from "./client.js"; import type { Ontology, ObjectType, OntologyObject, ActionType, ApplyActionParams, ApplyActionResponse, FunctionType, ExecuteFunctionParams, QueryType, ListObjectsParams, PageResponse, PageParams, } from "./types.js"; /** An interface type in an ontology. */ export interface InterfaceType { apiName: string; displayName?: string; description?: string; rid: string; sharedPropertyTypes?: unknown[]; objectTypes?: unknown[]; } export class OntologiesNamespace { constructor(private client: PalantirClient) {} // ─── Ontologies ───────────────────────────────────────────────── /** List all ontologies visible to the current user. */ async list(params?: PageParams): Promise> { return this.client.get("/api/v2/ontologies", params); } /** Get a specific ontology by API name or RID. */ async get(ontology: string): Promise { return this.client.get(`/api/v2/ontologies/${ontology}`); } /** * Get full ontology metadata (object types, action types, link types, * interface types, query types, function types) in a single call. */ async getFullMetadata(ontology: string): Promise { return this.client.get(`/api/v2/ontologies/${ontology}/fullMetadata`); } // ─── Object Types ─────────────────────────────────────────────── /** List object types for an ontology. */ async listObjectTypes( ontology: string, params?: PageParams ): Promise> { return this.client.get(`/api/v2/ontologies/${ontology}/objectTypes`, params); } /** Get a specific object type. */ async getObjectType(ontology: string, objectType: string): Promise { return this.client.get(`/api/v2/ontologies/${ontology}/objectTypes/${objectType}`); } // ─── Objects ──────────────────────────────────────────────────── /** List objects for an ontology object type. */ async listObjects( ontology: string, objectType: string, params?: ListObjectsParams ): Promise> { return this.client.get( `/api/v2/ontologies/${ontology}/objects/${objectType}`, params as Record ); } /** Get a single object by primary key. */ async getObject( ontology: string, objectType: string, primaryKey: string | number, params?: { select?: string[]; branch?: string } ): Promise { return this.client.get( `/api/v2/ontologies/${ontology}/objects/${objectType}/${primaryKey}`, params as Record ); } /** Create a new object. */ async createObject( ontology: string, objectType: string, params: { properties: Record; branch?: string; } ): Promise { return this.client.post( `/api/v2/ontologies/${ontology}/objects/${objectType}`, params ); } /** Update object properties. */ async updateObject( ontology: string, objectType: string, primaryKey: string | number, params: { properties: Record; branch?: string; } ): Promise { return this.client.put( `/api/v2/ontologies/${ontology}/objects/${objectType}/${primaryKey}`, params ); } /** Delete an object. */ async deleteObject( ontology: string, objectType: string, primaryKey: string | number, params?: { branch?: string } ): Promise { const qs = params?.branch ? `?branch=${encodeURIComponent(params.branch)}` : ""; return this.client.delete( `/api/v2/ontologies/${ontology}/objects/${objectType}/${primaryKey}${qs}` ); } /** Count objects matching filters. */ async countObjects( ontology: string, objectType: string, params?: { where?: Record; branch?: string; } ): Promise<{ totalCount: number }> { return this.client.post( `/api/v2/ontologies/${ontology}/objects/${objectType}/count`, params ); } /** Aggregate objects. */ async aggregate( ontology: string, objectType: string, params: { aggregation: Record; groupBy?: Record; where?: Record; branch?: string; } ): Promise { return this.client.post( `/api/v2/ontologies/${ontology}/objects/${objectType}/aggregate`, params ); } /** Search objects. */ async search( ontology: string, objectType: string, params: { where?: Record; orderBy?: Record; select?: string[]; pageSize?: number; pageToken?: string; branch?: string; } ): Promise> { return this.client.post( `/api/v2/ontologies/${ontology}/objects/${objectType}/search`, params ); } // ─── Action Types ─────────────────────────────────────────────── /** List action types for an ontology. */ async listActionTypes( ontology: string, params?: PageParams & { branch?: string } ): Promise> { return this.client.get( `/api/v2/ontologies/${ontology}/actionTypes`, params as Record ); } /** Get a specific action type. */ async getActionType(ontology: string, actionType: string, params?: { branch?: string }): Promise { return this.client.get(`/api/v2/ontologies/${ontology}/actionTypes/${actionType}`, params); } /** Validate action parameters without executing. */ async validateAction( ontology: string, actionType: string, params: ApplyActionParams ): Promise> { return this.client.post( `/api/v2/ontologies/${ontology}/actions/${actionType}/validate`, params ); } /** Apply (execute) an action. */ async applyAction( ontology: string, actionType: string, params: ApplyActionParams ): Promise { return this.client.post( `/api/v2/ontologies/${ontology}/actions/${actionType}/apply`, params ); } // ─── Function Types ───────────────────────────────────────────── /** List function types for an ontology. */ async listFunctions( ontology: string, params?: PageParams ): Promise> { return this.client.get( `/api/v2/ontologies/${ontology}/functionTypes`, params ); } /** Get a specific function type. */ async getFunction(ontology: string, functionApiName: string, params?: { branch?: string }): Promise { return this.client.get( `/api/v2/ontologies/${ontology}/functionTypes/${functionApiName}`, params ); } /** Execute a function. */ async executeFunction( ontology: string, functionApiName: string, params: ExecuteFunctionParams ): Promise { return this.client.post( `/api/v2/ontologies/${ontology}/functions/${functionApiName}/execute`, params ); } // ─── Query Types ──────────────────────────────────────────────── /** List query types for an ontology. */ async listQueries( ontology: string, params?: PageParams ): Promise> { return this.client.get( `/api/v2/ontologies/${ontology}/queryTypes`, params ); } /** Execute a query. */ async executeQuery( ontology: string, queryApiName: string, params: Record & { branch?: string } ): Promise { return this.client.post( `/api/v2/ontologies/${ontology}/queries/${queryApiName}/execute`, params ); } // ─── Interface Types ──────────────────────────────────────────── /** List interface types for an ontology. */ async listInterfaceTypes( ontology: string, params?: PageParams ): Promise> { return this.client.get( `/api/v2/ontologies/${ontology}/interfaceTypes`, params ); } /** Get a specific interface type. */ async getInterfaceType(ontology: string, interfaceType: string): Promise { return this.client.get( `/api/v2/ontologies/${ontology}/interfaceTypes/${interfaceType}` ); } // ─── Links ────────────────────────────────────────────────────── /** List linked objects. */ async listLinkedObjects( ontology: string, objectType: string, primaryKey: string | number, linkType: string, params?: PageParams & { branch?: string } ): Promise> { return this.client.get( `/api/v2/ontologies/${ontology}/objects/${objectType}/${primaryKey}/links/${linkType}`, params as Record ); } /** Create a link between objects. */ async createLink( ontology: string, objectType: string, primaryKey: string | number, linkType: string, params: { targetPrimaryKey: string | number; branch?: string } ): Promise { return this.client.post( `/api/v2/ontologies/${ontology}/objects/${objectType}/${primaryKey}/links/${linkType}`, params ); } /** Delete a link between objects. */ async deleteLink( ontology: string, objectType: string, primaryKey: string | number, linkType: string, targetPrimaryKey: string | number, params?: { branch?: string } ): Promise { const qs = params?.branch ? `?branch=${encodeURIComponent(params.branch)}` : ""; return this.client.delete( `/api/v2/ontologies/${ontology}/objects/${objectType}/${primaryKey}/links/${linkType}/${targetPrimaryKey}${qs}` ); } }