From 720747e261ddbec71aad135e90e856ff72266791 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Fri, 23 Feb 2024 11:59:37 -0500 Subject: [PATCH] Ontology tweaks --- .../cli/src/examples/fetchEmployeeLead.ts | 2 +- .../cli/src/examples/fetchEmployeePage.ts | 2 +- .../cli/src/examples/fetchEmployeePageThin.ts | 2 +- examples/basic/sdk/ontology.json | 81 ++++++++++++++++++- .../sdk/src/generatedNoCheck/Ontology.ts | 4 +- .../ontology/actions/assignEmployee1.ts | 68 ++++++++++++++++ .../ontology/actions/index.ts | 1 + .../src/generatedNoCheck/ontology/objects.ts | 1 + .../ontology/objects/Employee.ts | 21 ++++- .../ontology/objects/Venture.ts | 48 +++++++++++ 10 files changed, 221 insertions(+), 9 deletions(-) create mode 100644 examples/basic/sdk/src/generatedNoCheck/ontology/actions/assignEmployee1.ts create mode 100644 examples/basic/sdk/src/generatedNoCheck/ontology/objects/Venture.ts diff --git a/examples/basic/cli/src/examples/fetchEmployeeLead.ts b/examples/basic/cli/src/examples/fetchEmployeeLead.ts index b4af95fc9..d6f4fdeea 100644 --- a/examples/basic/cli/src/examples/fetchEmployeeLead.ts +++ b/examples/basic/cli/src/examples/fetchEmployeeLead.ts @@ -54,7 +54,7 @@ export async function fetchEmployeeLead( { nextPageToken: string | undefined; data: { - adUsername: string; + adUsername: string | undefined; businessTitle: string | undefined; employeeNumber: number | undefined; }[]; diff --git a/examples/basic/cli/src/examples/fetchEmployeePage.ts b/examples/basic/cli/src/examples/fetchEmployeePage.ts index 1b9fc1f09..cd9b346ee 100644 --- a/examples/basic/cli/src/examples/fetchEmployeePage.ts +++ b/examples/basic/cli/src/examples/fetchEmployeePage.ts @@ -29,7 +29,7 @@ export async function fetchEmployeePage(client: Client) { expectType< { data: { - adUsername: string; + adUsername: string | undefined; businessTitle: string | undefined; employeeNumber: number | undefined; favPlace: { type: "Point"; coordinates: number[] } | undefined; diff --git a/examples/basic/cli/src/examples/fetchEmployeePageThin.ts b/examples/basic/cli/src/examples/fetchEmployeePageThin.ts index 2f8522af9..f8fd3ecee 100644 --- a/examples/basic/cli/src/examples/fetchEmployeePageThin.ts +++ b/examples/basic/cli/src/examples/fetchEmployeePageThin.ts @@ -30,7 +30,7 @@ export async function fetchEmployeePageThin( select: ["adUsername", "businessTitle", "employeeNumber"], }); - expectType(result.data[0].adUsername); + expectType(result.data[0].adUsername); // locationCity was not selected. Should not be present expectType< diff --git a/examples/basic/sdk/ontology.json b/examples/basic/sdk/ontology.json index be9e8c6a9..7318dcc27 100644 --- a/examples/basic/sdk/ontology.json +++ b/examples/basic/sdk/ontology.json @@ -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": { @@ -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" @@ -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" } ] }, diff --git a/examples/basic/sdk/src/generatedNoCheck/Ontology.ts b/examples/basic/sdk/src/generatedNoCheck/Ontology.ts index d9aa1c67a..f49994b86 100644 --- a/examples/basic/sdk/src/generatedNoCheck/Ontology.ts +++ b/examples/basic/sdk/src/generatedNoCheck/Ontology.ts @@ -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 @@ -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; diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/actions/assignEmployee1.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/actions/assignEmployee1.ts new file mode 100644 index 000000000..4fa8118f0 --- /dev/null +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/actions/assignEmployee1.ts @@ -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>; + +// Represents a fqn of the action +export interface assignEmployee1 { + /** + * Assigns an employee to a venture + */ + (args: assignEmployee1$Params, options?: OP): Promise>; +} + +// 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, + }, + }, +}; diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/actions/index.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/actions/index.ts index 9ead94069..ba1c50c8d 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/actions/index.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/actions/index.ts @@ -1,2 +1,3 @@ export { actionTakesAllParameterTypes } from './actionTakesAllParameterTypes.js'; +export { assignEmployee1 } from './assignEmployee1.js'; export { createTodo } from './createTodo.js'; diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects.ts index e9f32340d..68b68d8f3 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects.ts @@ -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'; diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts index 1e9e3018f..99bf35a0a 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts @@ -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; peeps: ObjectTypeLinkDefinition; + ventures: ObjectTypeLinkDefinition; }; 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'>; @@ -25,7 +29,7 @@ export const Employee: Employee = { type: 'object', apiName: 'Employee', description: 'An employee', - primaryKeyApiName: 'adUsername', + primaryKeyApiName: 'id', primaryKeyType: 'string', links: { lead: { @@ -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', diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Venture.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Venture.ts new file mode 100644 index 000000000..25d017176 --- /dev/null +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Venture.ts @@ -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; + }; + 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, + }, + }, +};