Skip to content

Commit

Permalink
Merge pull request #94 from palantir/ea/ontology-tweaks
Browse files Browse the repository at this point in the history
Ontology tweaks
  • Loading branch information
ericanderson authored Feb 26, 2024
2 parents f791726 + 720747e commit b1584b3
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/basic/cli/src/examples/fetchEmployeeLead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function fetchEmployeeLead(
{
nextPageToken: string | undefined;
data: {
adUsername: string;
adUsername: string | undefined;
businessTitle: string | undefined;
employeeNumber: number | undefined;
}[];
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/cli/src/examples/fetchEmployeePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function fetchEmployeePage(client: Client<Ontology>) {
expectType<
{
data: {
adUsername: string;
adUsername: string | undefined;
businessTitle: string | undefined;
employeeNumber: number | undefined;
favPlace: { type: "Point"; coordinates: number[] } | undefined;
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/cli/src/examples/fetchEmployeePageThin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function fetchEmployeePageThin(
select: ["adUsername", "businessTitle", "employeeNumber"],
});

expectType<string>(result.data[0].adUsername);
expectType<string | undefined>(result.data[0].adUsername);

// locationCity was not selected. Should not be present
expectType<
Expand Down
81 changes: 80 additions & 1 deletion examples/basic/sdk/ontology.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,36 @@
"objectTypeApiName": "Todo"
}
]
},
"assign-employee-1": {
"apiName": "assign-employee-1",
"description": "Assigns an employee to a venture",
"parameters": {
"employee-1": {
"dataType": {
"type": "object",
"objectApiName": "Employee",
"objectTypeApiName": "Employee"
},
"required": true
},
"venture-1": {
"dataType": {
"type": "object",
"objectApiName": "Venture",
"objectTypeApiName": "Venture"
},
"required": true
}
},
"status": "ACTIVE",
"rid": "ri.a.b.c.d",
"operations": [
{
"type": "modifyObject",
"objectTypeApiName": "Employee"
}
]
}
},
"objectTypes": {
Expand Down Expand Up @@ -222,10 +252,15 @@
"Employee": {
"objectType": {
"apiName": "Employee",
"primaryKey": "adUsername",
"primaryKey": "id",
"displayName": "Employee",
"description": "An employee",
"properties": {
"id": {
"dataType": {
"type": "string"
}
},
"adUsername": {
"dataType": {
"type": "string"
Expand Down Expand Up @@ -292,6 +327,50 @@
"objectTypeApiName": "Employee",
"status": "ACTIVE",
"foreignKeyPropertyApiName": "adUsername"
},
{
"apiName": "ventures",
"cardinality": "MANY",
"displayName": "Ventures",
"objectTypeApiName": "Venture",
"foreignKeyPropertyApiName": "ventureId"
}
]
},
"Venture": {
"objectType": {
"apiName": "Venture",
"primaryKey": "ventureId",
"displayName": "Venture",
"description": "A venture",
"properties": {
"ventureId": {
"dataType": {
"type": "string"
}
},
"ventureName": {
"dataType": {
"type": "string"
}
},
"ventureStart": {
"dataType": {
"type": "date"
}
}
},

"rid": "ridForVenture",
"status": "ACTIVE"
},
"linkTypes": [
{
"apiName": "employees",
"cardinality": "MANY",
"displayName": "Employees",
"objectTypeApiName": "Employee",
"foreignKeyPropertyApiName": "id"
}
]
},
Expand Down
4 changes: 3 additions & 1 deletion examples/basic/sdk/src/generatedNoCheck/Ontology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ const _Ontology = {
Todo: Objects.Todo,
Person: Objects.Person,
Employee: Objects.Employee,
Venture: Objects.Venture,
ObjectTypeWithAllPropertyTypes: Objects.ObjectTypeWithAllPropertyTypes,
},
actions: {
actionTakesAllParameterTypes: Actions.actionTakesAllParameterTypes,
createTodo: Actions.createTodo,
assignEmployee1: Actions.assignEmployee1,
},
queries: {
// TODO
Expand All @@ -25,7 +27,7 @@ const _Ontology = {
SimpleInterface: Interfaces.SimpleInterface,
},
} satisfies OntologyDefinition<
'WeatherStation' | 'BoundariesUsState' | 'Todo' | 'Person' | 'Employee' | 'ObjectTypeWithAllPropertyTypes'
'WeatherStation' | 'BoundariesUsState' | 'Todo' | 'Person' | 'Employee' | 'Venture' | 'ObjectTypeWithAllPropertyTypes'
>;

type _Ontology = typeof _Ontology;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type { ActionDefinition, ObjectActionDataType } from '@osdk/api';
import type { ActionReturnTypeForOptions, ApplyActionOptions, NOOP, OsdkActionParameters } from '@osdk/client';
import type { Employee, Venture } from '../objects.js';

// Represents the definition of the parameters for the action
export type ActionDef$assignEmployee1$Params = {
'employee-1': {
multiplicity: false;
type: ObjectActionDataType<'Employee', Employee>;
nullable: false;
};
'venture-1': {
multiplicity: false;
type: ObjectActionDataType<'Venture', Venture>;
nullable: false;
};
};

// Represents the runtime arguments for the action
export type assignEmployee1$Params = NOOP<OsdkActionParameters<ActionDef$assignEmployee1$Params>>;

// Represents a fqn of the action
export interface assignEmployee1 {
/**
* Assigns an employee to a venture
*/
<OP extends ApplyActionOptions>(args: assignEmployee1$Params, options?: OP): Promise<ActionReturnTypeForOptions<OP>>;
}

// Represents the definition of the action
export interface ActionDef$assignEmployee1
extends ActionDefinition<'assignEmployee1', 'Employee' | 'Venture', assignEmployee1> {
type: 'action';
apiName: 'assignEmployee1';
description: 'Assigns an employee to a venture';
modifiedEntities: { Employee: { created: false; modified: true } };
parameters: ActionDef$assignEmployee1$Params;
}

export const assignEmployee1: ActionDef$assignEmployee1 = {
type: 'action',
apiName: 'assignEmployee1',
parameters: {
'employee-1': {
multiplicity: false,
type: {
type: 'object',
object: 'Employee',
},
nullable: false,
},
'venture-1': {
multiplicity: false,
type: {
type: 'object',
object: 'Venture',
},
nullable: false,
},
},
description: 'Assigns an employee to a venture',
modifiedEntities: {
Employee: {
created: false,
modified: true,
},
},
};
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { actionTakesAllParameterTypes } from './actionTakesAllParameterTypes.js';
export { assignEmployee1 } from './assignEmployee1.js';
export { createTodo } from './createTodo.js';
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from './objects/Employee.js';
export * from './objects/ObjectTypeWithAllPropertyTypes.js';
export * from './objects/Person.js';
export * from './objects/Todo.js';
export * from './objects/Venture.js';
export * from './objects/WeatherStation.js';
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import type { ObjectTypeDefinition, ObjectTypeLinkDefinition, PropertyDef } from '@osdk/api';

import type { Venture } from './Venture.js';

export interface Employee extends ObjectTypeDefinition<'Employee', Employee> {
description: 'An employee';
primaryKeyApiName: 'adUsername';
primaryKeyApiName: 'id';
primaryKeyType: 'string';
links: {
lead: ObjectTypeLinkDefinition<Employee, false>;
peeps: ObjectTypeLinkDefinition<Employee, true>;
ventures: ObjectTypeLinkDefinition<Venture, true>;
};
properties: {
adUsername: PropertyDef<'string', 'non-nullable', 'single'>;
id: PropertyDef<'string', 'non-nullable', 'single'>;
adUsername: PropertyDef<'string', 'nullable', 'single'>;
locationName: PropertyDef<'string', 'nullable', 'single'>;
locationCity: PropertyDef<'string', 'nullable', 'single'>;
firstFullTimeStartDate: PropertyDef<'datetime', 'nullable', 'single'>;
Expand All @@ -25,7 +29,7 @@ export const Employee: Employee = {
type: 'object',
apiName: 'Employee',
description: 'An employee',
primaryKeyApiName: 'adUsername',
primaryKeyApiName: 'id',
primaryKeyType: 'string',
links: {
lead: {
Expand All @@ -36,13 +40,22 @@ export const Employee: Employee = {
multiplicity: true,
targetType: 'Employee',
},
ventures: {
multiplicity: true,
targetType: 'Venture',
},
},
properties: {
adUsername: {
id: {
multiplicity: false,
type: 'string',
nullable: false,
},
adUsername: {
multiplicity: false,
type: 'string',
nullable: true,
},
locationName: {
multiplicity: false,
type: 'string',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { ObjectTypeDefinition, ObjectTypeLinkDefinition, PropertyDef } from '@osdk/api';

import type { Employee } from './Employee.js';

export interface Venture extends ObjectTypeDefinition<'Venture', Venture> {
description: 'A venture';
primaryKeyApiName: 'ventureId';
primaryKeyType: 'string';
links: {
employees: ObjectTypeLinkDefinition<Employee, true>;
};
properties: {
ventureId: PropertyDef<'string', 'non-nullable', 'single'>;
ventureName: PropertyDef<'string', 'nullable', 'single'>;
ventureStart: PropertyDef<'datetime', 'nullable', 'single'>;
};
}

export const Venture: Venture = {
type: 'object',
apiName: 'Venture',
description: 'A venture',
primaryKeyApiName: 'ventureId',
primaryKeyType: 'string',
links: {
employees: {
multiplicity: true,
targetType: 'Employee',
},
},
properties: {
ventureId: {
multiplicity: false,
type: 'string',
nullable: false,
},
ventureName: {
multiplicity: false,
type: 'string',
nullable: true,
},
ventureStart: {
multiplicity: false,
type: 'datetime',
nullable: true,
},
},
};

0 comments on commit b1584b3

Please sign in to comment.