From 432bb61992e320260c57fd9d3d8b1618fe81e7db Mon Sep 17 00:00:00 2001 From: Matt Fedderly Date: Tue, 6 Feb 2024 13:10:18 -0500 Subject: [PATCH 01/19] add type: 'object'|'interface'|'action'|'query' into the ontology definition --- .../ontology/actions/actionTakesAllParameterTypes.ts | 1 + .../generatedNoCheck/ontology/actions/createTodo.ts | 1 + .../ontology/interfaces/SimpleInterface.ts | 1 + .../src/generatedNoCheck/ontology/objects/Employee.ts | 1 + .../objects/ObjectTypeWithAllPropertyTypes.ts | 1 + .../src/generatedNoCheck/ontology/objects/Person.ts | 1 + .../sdk/src/generatedNoCheck/ontology/objects/Todo.ts | 1 + .../ontology/objects/WeatherStation.ts | 1 + examples/basic/sdk/src/interfaces/Emailable.ts | 1 + .../ontology/actions/actionTakesAllParameterTypes.ts | 1 + .../generatedNoCheck/ontology/actions/createTodo.ts | 1 + .../objects/ObjectTypeWithAllPropertyTypes.ts | 1 + .../src/generatedNoCheck/ontology/objects/Person.ts | 1 + .../src/generatedNoCheck/ontology/objects/Todo.ts | 1 + .../generatedNoCheck/ontology/queries/getTodoCount.ts | 1 + .../ontology/queries/queryTakesAllParameterTypes.ts | 1 + .../generatedNoCheck/ontology/actions/completeTodo.ts | 1 + .../generatedNoCheck/ontology/actions/createTodo.ts | 1 + .../src/generatedNoCheck/ontology/objects/Todo.ts | 1 + .../ontology/actions/completeTodo.ts | 1 + .../generatedNoCheck2/ontology/actions/createTodo.ts | 1 + .../src/generatedNoCheck2/ontology/objects/Todo.ts | 1 + packages/api/src/ontology/ActionDefinition.ts | 1 + packages/api/src/ontology/InterfaceDefinition.ts | 1 + packages/api/src/ontology/ObjectTypeDefinition.ts | 1 + packages/api/src/ontology/QueryDefinition.ts | 1 + packages/client/src/object/aggregateOrThrow.test.ts | 3 +++ .../src/query/aggregations/AggregationsClause.test.ts | 2 ++ .../query/aggregations/AggregationsResults.test.ts | 2 ++ .../src/query/aggregations/GroupByClause.test.ts | 1 + packages/client/src/util/test/mockOntology.ts | 3 +++ .../UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.ts | 1 + .../shared/wireActionTypeV2ToSdkActionDefinition.ts | 1 + .../shared/wireObjectTypeV2ToSdkObjectDefinition.ts | 1 + .../src/shared/wireQueryTypeV2ToSdkQueryDefinition.ts | 1 + ...reObjectTypeV2ToObjectDefinitionInterfaceString.ts | 1 + .../mock-ontology/ObjectTypeWithAllPropertyTypes.ts | 1 + .../src/mock-ontology/ObjectTypeWithReservedNames.ts | 1 + .../shared.test/src/mock-ontology/mockOntology.ts | 11 +++++++++++ 39 files changed, 55 insertions(+) diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/actions/actionTakesAllParameterTypes.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/actions/actionTakesAllParameterTypes.ts index c438b8d71..a0ef8e8f8 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/actions/actionTakesAllParameterTypes.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/actions/actionTakesAllParameterTypes.ts @@ -1,6 +1,7 @@ import { ActionDefinition } from '@osdk/api'; export const actionTakesAllParameterTypes = { + type: 'action', apiName: 'actionTakesAllParameterTypes', parameters: { objectSet: { diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/actions/createTodo.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/actions/createTodo.ts index 3505481e2..37c996977 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/actions/createTodo.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/actions/createTodo.ts @@ -1,6 +1,7 @@ import { ActionDefinition } from '@osdk/api'; export const createTodo = { + type: 'action', apiName: 'createTodo', parameters: {}, description: 'Creates a new Todo', diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/interfaces/SimpleInterface.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/interfaces/SimpleInterface.ts index c4ea518a2..f6027bf47 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/interfaces/SimpleInterface.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/interfaces/SimpleInterface.ts @@ -1,6 +1,7 @@ import type { InterfaceDefinition } from '@osdk/api'; export const SimpleInterface = { + type: 'interface', apiName: 'SimpleInterface', description: 'Its a todo item.', properties: { diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts index e765632c7..703b6833d 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts @@ -1,6 +1,7 @@ import type { ObjectTypeDefinition } from '@osdk/api'; export const Employee = { + type: 'object', apiName: 'Employee', description: 'An employee', primaryKeyType: 'string', diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts index 54cb8f9d7..82805862d 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts @@ -1,6 +1,7 @@ import type { ObjectTypeDefinition } from '@osdk/api'; export const ObjectTypeWithAllPropertyTypes = { + type: 'object', apiName: 'ObjectTypeWithAllPropertyTypes', description: 'A type with all property types', primaryKeyType: 'integer', diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Person.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Person.ts index 0b1b7ef7f..6f9d3bb8c 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Person.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Person.ts @@ -1,6 +1,7 @@ import type { ObjectTypeDefinition } from '@osdk/api'; export const Person = { + type: 'object', apiName: 'Person', description: 'A person', primaryKeyType: 'string', diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Todo.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Todo.ts index bc2e55651..f205da9d7 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Todo.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Todo.ts @@ -1,6 +1,7 @@ import type { ObjectTypeDefinition } from '@osdk/api'; export const Todo = { + type: 'object', apiName: 'Todo', description: 'Its a todo item.', primaryKeyType: 'integer', diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/WeatherStation.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/WeatherStation.ts index 7d5f39421..67a08254d 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/WeatherStation.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/WeatherStation.ts @@ -1,6 +1,7 @@ import type { ObjectTypeDefinition } from '@osdk/api'; export const WeatherStation = { + type: 'object', apiName: 'WeatherStation', description: 'Weather Station', primaryKeyType: 'string', diff --git a/examples/basic/sdk/src/interfaces/Emailable.ts b/examples/basic/sdk/src/interfaces/Emailable.ts index f650ce984..c3908e6ab 100644 --- a/examples/basic/sdk/src/interfaces/Emailable.ts +++ b/examples/basic/sdk/src/interfaces/Emailable.ts @@ -17,6 +17,7 @@ import type { InterfaceDefinition } from "@osdk/api"; export const Emailable = { + type: "interface", apiName: "Emailable", properties: { diff --git a/examples/one_dot_one/src/generatedNoCheck/ontology/actions/actionTakesAllParameterTypes.ts b/examples/one_dot_one/src/generatedNoCheck/ontology/actions/actionTakesAllParameterTypes.ts index c438b8d71..a0ef8e8f8 100644 --- a/examples/one_dot_one/src/generatedNoCheck/ontology/actions/actionTakesAllParameterTypes.ts +++ b/examples/one_dot_one/src/generatedNoCheck/ontology/actions/actionTakesAllParameterTypes.ts @@ -1,6 +1,7 @@ import { ActionDefinition } from '@osdk/api'; export const actionTakesAllParameterTypes = { + type: 'action', apiName: 'actionTakesAllParameterTypes', parameters: { objectSet: { diff --git a/examples/one_dot_one/src/generatedNoCheck/ontology/actions/createTodo.ts b/examples/one_dot_one/src/generatedNoCheck/ontology/actions/createTodo.ts index 3505481e2..37c996977 100644 --- a/examples/one_dot_one/src/generatedNoCheck/ontology/actions/createTodo.ts +++ b/examples/one_dot_one/src/generatedNoCheck/ontology/actions/createTodo.ts @@ -1,6 +1,7 @@ import { ActionDefinition } from '@osdk/api'; export const createTodo = { + type: 'action', apiName: 'createTodo', parameters: {}, description: 'Creates a new Todo', diff --git a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts index 6b959dfd9..3ce734708 100644 --- a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts +++ b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts @@ -49,6 +49,7 @@ export interface ObjectTypeWithAllPropertyTypes extends OntologyObject { } export const ObjectTypeWithAllPropertyTypes = { + type: 'object', apiName: 'ObjectTypeWithAllPropertyTypes', description: 'A type with all property types', primaryKeyType: 'integer', diff --git a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Person.ts b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Person.ts index f53e1eb34..41a633d92 100644 --- a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Person.ts +++ b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Person.ts @@ -14,6 +14,7 @@ export interface Person extends OntologyObject { } export const Person = { + type: 'object', apiName: 'Person', description: 'A person', primaryKeyType: 'string', diff --git a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Todo.ts b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Todo.ts index 5c5293567..accf7fced 100644 --- a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Todo.ts +++ b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Todo.ts @@ -18,6 +18,7 @@ export interface Todo extends OntologyObject { } export const Todo = { + type: 'object', apiName: 'Todo', description: 'Its a todo item.', primaryKeyType: 'integer', diff --git a/examples/one_dot_one/src/generatedNoCheck/ontology/queries/getTodoCount.ts b/examples/one_dot_one/src/generatedNoCheck/ontology/queries/getTodoCount.ts index c655d19e4..02d824381 100644 --- a/examples/one_dot_one/src/generatedNoCheck/ontology/queries/getTodoCount.ts +++ b/examples/one_dot_one/src/generatedNoCheck/ontology/queries/getTodoCount.ts @@ -1,6 +1,7 @@ import { QueryDefinition } from '@osdk/api'; export const getTodoCount = { + type: 'query', apiName: 'getTodoCount', version: '0.1.2', parameters: {}, diff --git a/examples/one_dot_one/src/generatedNoCheck/ontology/queries/queryTakesAllParameterTypes.ts b/examples/one_dot_one/src/generatedNoCheck/ontology/queries/queryTakesAllParameterTypes.ts index 15ab23800..41487210e 100644 --- a/examples/one_dot_one/src/generatedNoCheck/ontology/queries/queryTakesAllParameterTypes.ts +++ b/examples/one_dot_one/src/generatedNoCheck/ontology/queries/queryTakesAllParameterTypes.ts @@ -1,6 +1,7 @@ import { QueryDefinition } from '@osdk/api'; export const queryTakesAllParameterTypes = { + type: 'query', apiName: 'queryTakesAllParameterTypes', description: 'description of the query that takes all parameter types', displayName: 'qTAPT', diff --git a/examples/todoapp/src/generatedNoCheck/ontology/actions/completeTodo.ts b/examples/todoapp/src/generatedNoCheck/ontology/actions/completeTodo.ts index 5ed7f59a0..ef0ae0e79 100644 --- a/examples/todoapp/src/generatedNoCheck/ontology/actions/completeTodo.ts +++ b/examples/todoapp/src/generatedNoCheck/ontology/actions/completeTodo.ts @@ -1,6 +1,7 @@ import { ActionDefinition } from '@osdk/api'; export const completeTodo = { + type: 'action', apiName: 'completeTodo', parameters: { Todo: { diff --git a/examples/todoapp/src/generatedNoCheck/ontology/actions/createTodo.ts b/examples/todoapp/src/generatedNoCheck/ontology/actions/createTodo.ts index 240431218..3f8c404bc 100644 --- a/examples/todoapp/src/generatedNoCheck/ontology/actions/createTodo.ts +++ b/examples/todoapp/src/generatedNoCheck/ontology/actions/createTodo.ts @@ -1,6 +1,7 @@ import { ActionDefinition } from '@osdk/api'; export const createTodo = { + type: 'action', apiName: 'createTodo', parameters: { Todo: { diff --git a/examples/todoapp/src/generatedNoCheck/ontology/objects/Todo.ts b/examples/todoapp/src/generatedNoCheck/ontology/objects/Todo.ts index 443049265..9672d6a45 100644 --- a/examples/todoapp/src/generatedNoCheck/ontology/objects/Todo.ts +++ b/examples/todoapp/src/generatedNoCheck/ontology/objects/Todo.ts @@ -16,6 +16,7 @@ export interface Todo extends OntologyObject { } export const Todo = { + type: 'object', apiName: 'Todo', description: 'Its a todo item.', primaryKeyType: 'string', diff --git a/examples/todoapp/src/generatedNoCheck2/ontology/actions/completeTodo.ts b/examples/todoapp/src/generatedNoCheck2/ontology/actions/completeTodo.ts index 5ed7f59a0..ef0ae0e79 100644 --- a/examples/todoapp/src/generatedNoCheck2/ontology/actions/completeTodo.ts +++ b/examples/todoapp/src/generatedNoCheck2/ontology/actions/completeTodo.ts @@ -1,6 +1,7 @@ import { ActionDefinition } from '@osdk/api'; export const completeTodo = { + type: 'action', apiName: 'completeTodo', parameters: { Todo: { diff --git a/examples/todoapp/src/generatedNoCheck2/ontology/actions/createTodo.ts b/examples/todoapp/src/generatedNoCheck2/ontology/actions/createTodo.ts index 240431218..3f8c404bc 100644 --- a/examples/todoapp/src/generatedNoCheck2/ontology/actions/createTodo.ts +++ b/examples/todoapp/src/generatedNoCheck2/ontology/actions/createTodo.ts @@ -1,6 +1,7 @@ import { ActionDefinition } from '@osdk/api'; export const createTodo = { + type: 'action', apiName: 'createTodo', parameters: { Todo: { diff --git a/examples/todoapp/src/generatedNoCheck2/ontology/objects/Todo.ts b/examples/todoapp/src/generatedNoCheck2/ontology/objects/Todo.ts index f30912c17..4469266d6 100644 --- a/examples/todoapp/src/generatedNoCheck2/ontology/objects/Todo.ts +++ b/examples/todoapp/src/generatedNoCheck2/ontology/objects/Todo.ts @@ -1,6 +1,7 @@ import type { ObjectTypeDefinition } from '@osdk/api'; export const Todo = { + type: 'object', apiName: 'Todo', description: 'Its a todo item.', primaryKeyType: 'string', diff --git a/packages/api/src/ontology/ActionDefinition.ts b/packages/api/src/ontology/ActionDefinition.ts index e15e0e2a1..97d236ba6 100644 --- a/packages/api/src/ontology/ActionDefinition.ts +++ b/packages/api/src/ontology/ActionDefinition.ts @@ -18,6 +18,7 @@ export interface ActionDefinition< A extends string, K extends string, > { + type: "action"; apiName: A; description?: string; displayName?: string; diff --git a/packages/api/src/ontology/InterfaceDefinition.ts b/packages/api/src/ontology/InterfaceDefinition.ts index 8c58f2517..5e2d94295 100644 --- a/packages/api/src/ontology/InterfaceDefinition.ts +++ b/packages/api/src/ontology/InterfaceDefinition.ts @@ -45,6 +45,7 @@ export interface InterfaceDefinition< K extends string, _L extends string, > { + type: "interface"; apiName: K; description?: string; properties: Record; diff --git a/packages/api/src/ontology/ObjectTypeDefinition.ts b/packages/api/src/ontology/ObjectTypeDefinition.ts index eaddcd581..48834e4bd 100644 --- a/packages/api/src/ontology/ObjectTypeDefinition.ts +++ b/packages/api/src/ontology/ObjectTypeDefinition.ts @@ -45,6 +45,7 @@ export interface ObjectTypeDefinition< K extends string, L extends string, > { + type: "object"; apiName: K; description?: string; primaryKeyType: keyof WirePropertyTypes; diff --git a/packages/api/src/ontology/QueryDefinition.ts b/packages/api/src/ontology/QueryDefinition.ts index f257bec1a..f97196605 100644 --- a/packages/api/src/ontology/QueryDefinition.ts +++ b/packages/api/src/ontology/QueryDefinition.ts @@ -15,6 +15,7 @@ */ export interface QueryDefinition { + type: "query"; apiName: Q; description?: string; displayName?: string; diff --git a/packages/client/src/object/aggregateOrThrow.test.ts b/packages/client/src/object/aggregateOrThrow.test.ts index d7e77d070..f132defeb 100644 --- a/packages/client/src/object/aggregateOrThrow.test.ts +++ b/packages/client/src/object/aggregateOrThrow.test.ts @@ -32,6 +32,7 @@ const mockOntology = { }, objects: { Todo: { + type: "object", apiName: "Todo", links: {}, primaryKeyType: "double", @@ -143,6 +144,7 @@ describe("aggregateOrThrow", () => { metadata: any; objects: { Todo: { + type: "object"; apiName: "Todo"; primaryKeyType: "double"; links: {}; @@ -171,6 +173,7 @@ describe("aggregateOrThrow", () => { metadata: any; objects: { Todo: { + type: "object"; apiName: "Todo"; primaryKeyType: "double"; links: {}; diff --git a/packages/client/src/query/aggregations/AggregationsClause.test.ts b/packages/client/src/query/aggregations/AggregationsClause.test.ts index 90bd3dfca..8609c3ac3 100644 --- a/packages/client/src/query/aggregations/AggregationsClause.test.ts +++ b/packages/client/src/query/aggregations/AggregationsClause.test.ts @@ -23,6 +23,7 @@ export type huh = AggregatableKeys< metadata: any; objects: { Todo: { + type: "object"; apiName: "Todo"; primaryKeyType: "double"; links: {}; @@ -47,6 +48,7 @@ export type Q = AggregationClause< metadata: any; objects: { Todo: { + type: "object"; apiName: "Todo"; primaryKeyType: "double"; links: {}; diff --git a/packages/client/src/query/aggregations/AggregationsResults.test.ts b/packages/client/src/query/aggregations/AggregationsResults.test.ts index b36378148..47b69d628 100644 --- a/packages/client/src/query/aggregations/AggregationsResults.test.ts +++ b/packages/client/src/query/aggregations/AggregationsResults.test.ts @@ -23,6 +23,7 @@ type T_AGG_RESULTS_TEST_1 = AggregationsResults< metadata: any; objects: { Todo: { + type: "object"; apiName: "Todo"; primaryKeyType: "double"; links: {}; @@ -56,6 +57,7 @@ type Q = AggregationResultsWithoutGroups< metadata: any; objects: { Todo: { + type: "object"; apiName: "Todo"; primaryKeyType: "double"; links: {}; diff --git a/packages/client/src/query/aggregations/GroupByClause.test.ts b/packages/client/src/query/aggregations/GroupByClause.test.ts index 7a766e24d..48e81c7d0 100644 --- a/packages/client/src/query/aggregations/GroupByClause.test.ts +++ b/packages/client/src/query/aggregations/GroupByClause.test.ts @@ -22,6 +22,7 @@ export type F = GroupByClause< metadata: any; objects: { Todo: { + type: "object"; apiName: "Todo"; primaryKeyType: "double"; links: {}; diff --git a/packages/client/src/util/test/mockOntology.ts b/packages/client/src/util/test/mockOntology.ts index 84e422e33..276087729 100644 --- a/packages/client/src/util/test/mockOntology.ts +++ b/packages/client/src/util/test/mockOntology.ts @@ -24,6 +24,7 @@ export const MockOntology = { }, objects: { Task: { + type: "object", apiName: "Task", primaryKeyType: "integer", properties: { @@ -42,6 +43,7 @@ export const MockOntology = { }, }, Todo: { + type: "object", apiName: "Todo", primaryKeyType: "integer", properties: { @@ -51,6 +53,7 @@ export const MockOntology = { links: {}, }, Person: { + type: "object", apiName: "Person", primaryKeyType: "integer", properties: { diff --git a/packages/generator/src/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.ts b/packages/generator/src/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.ts index 9cedeac05..ebcc692ad 100644 --- a/packages/generator/src/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.ts +++ b/packages/generator/src/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.ts @@ -41,6 +41,7 @@ function wireInterfaceTypeV2ToSdkObjectDefinition( v2: boolean, ): InterfaceDefinition { return { + type: "interface", apiName: interfaceType.apiName, description: interfaceType.description, properties: Object.fromEntries( diff --git a/packages/generator/src/shared/wireActionTypeV2ToSdkActionDefinition.ts b/packages/generator/src/shared/wireActionTypeV2ToSdkActionDefinition.ts index ece2d28d6..ad2db51a0 100644 --- a/packages/generator/src/shared/wireActionTypeV2ToSdkActionDefinition.ts +++ b/packages/generator/src/shared/wireActionTypeV2ToSdkActionDefinition.ts @@ -31,6 +31,7 @@ export function wireActionTypeV2ToSdkActionDefinition( ): ActionDefinition { const modifiedEntityTypes = getModifiedEntityTypes(input); return { + type: "action", apiName: input.apiName, parameters: Object.fromEntries( Object.entries(input.parameters).map(( diff --git a/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectDefinition.ts b/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectDefinition.ts index b8dd7f4e0..3dc24698e 100644 --- a/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectDefinition.ts +++ b/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectDefinition.ts @@ -32,6 +32,7 @@ export function wireObjectTypeV2ToSdkObjectDefinition( ); } return { + type: "object", apiName: objectTypeWithLink.objectType.apiName, description: objectTypeWithLink.objectType.description, primaryKeyType: wirePropertyV2ToSdkPrimaryKeyTypeDefinition( diff --git a/packages/generator/src/shared/wireQueryTypeV2ToSdkQueryDefinition.ts b/packages/generator/src/shared/wireQueryTypeV2ToSdkQueryDefinition.ts index c023b2d22..3ae825214 100644 --- a/packages/generator/src/shared/wireQueryTypeV2ToSdkQueryDefinition.ts +++ b/packages/generator/src/shared/wireQueryTypeV2ToSdkQueryDefinition.ts @@ -22,6 +22,7 @@ export function wireQueryTypeV2ToSdkQueryDefinition( input: QueryTypeV2, ): QueryDefinition { return { + type: "query", apiName: input.apiName, description: input.description, displayName: input.displayName, diff --git a/packages/generator/src/v2.0/wireObjectTypeV2ToObjectDefinitionInterfaceString.ts b/packages/generator/src/v2.0/wireObjectTypeV2ToObjectDefinitionInterfaceString.ts index 51a97867e..054956941 100644 --- a/packages/generator/src/v2.0/wireObjectTypeV2ToObjectDefinitionInterfaceString.ts +++ b/packages/generator/src/v2.0/wireObjectTypeV2ToObjectDefinitionInterfaceString.ts @@ -21,6 +21,7 @@ export function wireObjectTypeV2ToObjectDefinitionInterfaceString( ) { return ` export interface ${input.apiName} extends ObjectTypeDefinition<"${input.apiName}", "${input.apiName}">{ + type: "interface"; apiName: "${input.apiName}"; properties: { ${ diff --git a/packages/shared.test/src/mock-ontology/ObjectTypeWithAllPropertyTypes.ts b/packages/shared.test/src/mock-ontology/ObjectTypeWithAllPropertyTypes.ts index 4d99e8172..444db1131 100644 --- a/packages/shared.test/src/mock-ontology/ObjectTypeWithAllPropertyTypes.ts +++ b/packages/shared.test/src/mock-ontology/ObjectTypeWithAllPropertyTypes.ts @@ -17,6 +17,7 @@ import type { ObjectTypeDefinition } from "@osdk/api"; export const ObjectTypeWithAllPropertyTypes = { + type: "object", apiName: "ObjectTypeWithAllPropertyTypes", primaryKeyType: "integer", links: {}, diff --git a/packages/shared.test/src/mock-ontology/ObjectTypeWithReservedNames.ts b/packages/shared.test/src/mock-ontology/ObjectTypeWithReservedNames.ts index 3cfe7277b..75afa35b8 100644 --- a/packages/shared.test/src/mock-ontology/ObjectTypeWithReservedNames.ts +++ b/packages/shared.test/src/mock-ontology/ObjectTypeWithReservedNames.ts @@ -17,6 +17,7 @@ import type { ObjectTypeDefinition } from "@osdk/api"; export const ObjectTypeWithReservedNames = { + type: "object", apiName: "ObjectTypeWithReservedNames", primaryKeyType: "integer", links: { diff --git a/packages/shared.test/src/mock-ontology/mockOntology.ts b/packages/shared.test/src/mock-ontology/mockOntology.ts index e219874a7..3953197ce 100644 --- a/packages/shared.test/src/mock-ontology/mockOntology.ts +++ b/packages/shared.test/src/mock-ontology/mockOntology.ts @@ -26,6 +26,7 @@ export const MockOntology = { }, objects: { Task: { + type: "object", apiName: "Task", primaryKeyType: "integer", properties: { @@ -36,6 +37,7 @@ export const MockOntology = { }, }, Todo: { + type: "object", apiName: "Todo", primaryKeyType: "string", description: "A todo object", @@ -60,6 +62,7 @@ export const MockOntology = { }, actions: { createTask: { + type: "action", apiName: "createTask", parameters: { id: { type: "integer", nullable: true }, @@ -69,6 +72,7 @@ export const MockOntology = { }, }, createTodo: { + type: "action", apiName: "createTodo", parameters: {}, modifiedEntities: { @@ -76,6 +80,7 @@ export const MockOntology = { }, }, updateTask: { + type: "action", apiName: "updateTask", parameters: { task: { @@ -106,6 +111,7 @@ export const MockOntology = { }, queries: { queryTakesNoParameters: { + type: "query", apiName: "queryTakesNoParameters", description: "a query that does not require parameters", version: "version", @@ -116,6 +122,7 @@ export const MockOntology = { }, }, queryReturnsAggregation: { + type: "query", apiName: "queryReturnsAggregation", description: "a query that returns an aggregation", version: "version", @@ -130,6 +137,7 @@ export const MockOntology = { }, }, queryTakesAllParameterTypes: { + type: "query", apiName: "queryTakesAllParameterTypes", description: "description of the query that takes all parameter types", displayName: "qTAPT", @@ -230,6 +238,7 @@ export const MockOntology = { }, }, queryTakesNestedObjects: { + type: "query", apiName: "queryTakesNestedObjects", description: "a query that takes nested objects inside other types", version: "version", @@ -258,6 +267,7 @@ export const MockOntology = { }, }, queryWithOnlyOptionalArgs: { + type: "query", apiName: "queryWithOnlyOptionalArgs", description: "a query that only has optional args", version: "version", @@ -270,6 +280,7 @@ export const MockOntology = { }, }, queryWithOnlyRequiredArgs: { + type: "query", apiName: "queryWithOnlyRequiredArgs", description: "a query that only has required args", version: "version", From 269e8039039cc1a2c0578f326a3ad3e2c79ea02c Mon Sep 17 00:00:00 2001 From: Matt Fedderly Date: Fri, 9 Feb 2024 15:17:20 -0500 Subject: [PATCH 02/19] WIP add client(ObjectDefinition) syntax --- .../ontology/objects/Employee.ts | 63 ++++++- .../objects/ObjectTypeWithAllPropertyTypes.ts | 171 +++++++++++++++++- .../ontology/objects/Person.ts | 24 ++- .../generatedNoCheck/ontology/objects/Todo.ts | 45 ++++- .../ontology/objects/WeatherStation.ts | 27 ++- packages/api/src/index.ts | 2 + .../api/src/ontology/ObjectOrInterface.ts | 7 +- .../api/src/ontology/ObjectTypeDefinition.ts | 19 +- .../api/src/ontology/OntologyDefinition.ts | 2 +- packages/client/src/Client.test.ts | 45 +++++ packages/client/src/Client.ts | 13 +- packages/client/src/OsdkObjectFrom.ts | 32 +++- .../src/createCachedOntologyTransform.ts | 2 +- .../src/definitions/LinkDefinitions.test.ts | 2 +- .../client/src/definitions/LinkDefinitions.ts | 36 ++++ .../client/src/object/fetchPageOrThrow.ts | 17 ++ packages/client/src/objectSet/ObjectSet.ts | 27 ++- .../wireObjectTypeV2ToSdkObjectConst.ts | 61 +++++-- .../wireObjectTypeV2ToSdkObjectDefinition.ts | 2 +- .../generatePerObjectInterfaceAndDataFiles.ts | 4 +- .../generateClientSdkVersionTwoPointZero.ts | 4 +- .../src/client/OsdkLegacyObject.test.ts | 5 +- .../createCachedOntologyTransform.ts | 2 +- .../ObjectTypeWithAllPropertyTypes.ts | 1 - .../ObjectTypeWithReservedNames.ts | 1 - .../src/mock-ontology/mockOntology.ts | 10 +- 26 files changed, 564 insertions(+), 60 deletions(-) create mode 100644 packages/client/src/Client.test.ts diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts index 703b6833d..21f9ece83 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts @@ -1,6 +1,61 @@ -import type { ObjectTypeDefinition } from '@osdk/api'; +import type { ObjectTypeDefinition, ObjectTypeLinkDefinition } from '@osdk/api'; -export const Employee = { +export interface EmployeeDef extends ObjectTypeDefinition<'Employee'> { + type: 'object'; + apiName: 'Employee'; + description: 'An employee'; + primaryKeyType: 'string'; + links: { lead: ObjectTypeLinkDefinition; peeps: ObjectTypeLinkDefinition }; + properties: { + adUsername: { + multiplicity: false; + type: 'string'; + nullable: false; + }; + locationName: { + multiplicity: false; + type: 'string'; + nullable: true; + }; + locationCity: { + multiplicity: false; + type: 'string'; + nullable: true; + }; + firstFullTimeStartDate: { + multiplicity: false; + type: 'datetime'; + nullable: true; + }; + businessTitle: { + multiplicity: false; + type: 'string'; + nullable: true; + }; + employeeNumber: { + multiplicity: false; + type: 'double'; + nullable: true; + }; + jobProfile: { + multiplicity: false; + type: 'string'; + nullable: true; + }; + locationType: { + multiplicity: false; + type: 'string'; + nullable: true; + }; + favPlace: { + multiplicity: false; + type: 'geopoint'; + nullable: true; + }; + }; +} + +export const Employee: EmployeeDef = { type: 'object', apiName: 'Employee', description: 'An employee', @@ -14,7 +69,7 @@ export const Employee = { multiplicity: true, targetType: 'Employee', }, - }, + } as const, properties: { adUsername: { multiplicity: false, @@ -62,4 +117,4 @@ export const Employee = { nullable: true, }, }, -} satisfies ObjectTypeDefinition<'Employee', 'Employee'>; +}; diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts index 82805862d..22dfbca1d 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts @@ -1,11 +1,176 @@ import type { ObjectTypeDefinition } from '@osdk/api'; -export const ObjectTypeWithAllPropertyTypes = { +export interface ObjectTypeWithAllPropertyTypesDef extends ObjectTypeDefinition<'ObjectTypeWithAllPropertyTypes'> { + type: 'object'; + apiName: 'ObjectTypeWithAllPropertyTypes'; + description: 'A type with all property types'; + primaryKeyType: 'integer'; + links: {}; + properties: { + id: { + multiplicity: false; + type: 'integer'; + nullable: false; + }; + string: { + multiplicity: false; + type: 'string'; + nullable: true; + }; + boolean: { + multiplicity: false; + type: 'boolean'; + nullable: true; + }; + date: { + multiplicity: false; + type: 'datetime'; + nullable: true; + }; + dateTime: { + multiplicity: false; + type: 'timestamp'; + nullable: true; + }; + decimal: { + multiplicity: false; + type: 'decimal'; + nullable: true; + }; + integer: { + multiplicity: false; + type: 'integer'; + nullable: true; + }; + long: { + multiplicity: false; + type: 'long'; + nullable: true; + }; + short: { + multiplicity: false; + type: 'short'; + nullable: true; + }; + float: { + multiplicity: false; + type: 'float'; + nullable: true; + }; + double: { + multiplicity: false; + type: 'double'; + nullable: true; + }; + byte: { + multiplicity: false; + type: 'byte'; + nullable: true; + }; + attachment: { + multiplicity: false; + type: 'attachment'; + nullable: true; + }; + geoPoint: { + multiplicity: false; + type: 'geopoint'; + nullable: true; + }; + geoShape: { + multiplicity: false; + type: 'geoshape'; + nullable: true; + }; + stringArray: { + multiplicity: true; + type: 'string'; + nullable: true; + }; + booleanArray: { + multiplicity: true; + type: 'boolean'; + nullable: true; + }; + dateArray: { + multiplicity: true; + type: 'datetime'; + nullable: true; + }; + dateTimeArray: { + multiplicity: true; + type: 'timestamp'; + nullable: true; + }; + decimalArray: { + multiplicity: true; + type: 'decimal'; + nullable: true; + }; + integerArray: { + multiplicity: true; + type: 'integer'; + nullable: true; + }; + longArray: { + multiplicity: true; + type: 'long'; + nullable: true; + }; + shortArray: { + multiplicity: true; + type: 'short'; + nullable: true; + }; + floatArray: { + multiplicity: true; + type: 'float'; + nullable: true; + }; + doubleArray: { + multiplicity: true; + type: 'double'; + nullable: true; + }; + byteArray: { + multiplicity: true; + type: 'byte'; + nullable: true; + }; + attachmentArray: { + multiplicity: true; + type: 'attachment'; + nullable: true; + }; + geoPointArray: { + multiplicity: true; + type: 'geopoint'; + nullable: true; + }; + geoShapeArray: { + multiplicity: true; + type: 'geoshape'; + nullable: true; + }; + numericTimeseries: { + multiplicity: false; + type: 'numericTimeseries'; + nullable: true; + }; + stringTimeseries: { + multiplicity: false; + type: 'stringTimeseries'; + nullable: true; + }; + }; +} + +export const ObjectTypeWithAllPropertyTypes: ObjectTypeWithAllPropertyTypesDef = { type: 'object', apiName: 'ObjectTypeWithAllPropertyTypes', description: 'A type with all property types', primaryKeyType: 'integer', - links: {}, + links: {} as const, properties: { id: { multiplicity: false, @@ -163,4 +328,4 @@ export const ObjectTypeWithAllPropertyTypes = { nullable: true, }, }, -} satisfies ObjectTypeDefinition<'ObjectTypeWithAllPropertyTypes', never>; +}; diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Person.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Person.ts index 6f9d3bb8c..6c6d2338b 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Person.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Person.ts @@ -1,6 +1,22 @@ -import type { ObjectTypeDefinition } from '@osdk/api'; +import type { ObjectTypeDefinition, ObjectTypeLinkDefinition } from '@osdk/api'; -export const Person = { +import type { TodoDef } from './Todo.js'; +export interface PersonDef extends ObjectTypeDefinition<'Person'> { + type: 'object'; + apiName: 'Person'; + description: 'A person'; + primaryKeyType: 'string'; + links: { Todos: ObjectTypeLinkDefinition; Friends: ObjectTypeLinkDefinition }; + properties: { + email: { + multiplicity: false; + type: 'string'; + nullable: false; + }; + }; +} + +export const Person: PersonDef = { type: 'object', apiName: 'Person', description: 'A person', @@ -14,7 +30,7 @@ export const Person = { multiplicity: true, targetType: 'Person', }, - }, + } as const, properties: { email: { multiplicity: false, @@ -22,4 +38,4 @@ export const Person = { nullable: false, }, }, -} satisfies ObjectTypeDefinition<'Person', 'Todo' | 'Person'>; +}; diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Todo.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Todo.ts index f205da9d7..3e8d407b9 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Todo.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Todo.ts @@ -1,6 +1,43 @@ -import type { ObjectTypeDefinition } from '@osdk/api'; +import type { ObjectTypeDefinition, ObjectTypeLinkDefinition } from '@osdk/api'; -export const Todo = { +import type { PersonDef } from './Person.js'; +export interface TodoDef extends ObjectTypeDefinition<'Todo'> { + type: 'object'; + apiName: 'Todo'; + description: 'Its a todo item.'; + primaryKeyType: 'integer'; + links: { Assignee: ObjectTypeLinkDefinition }; + properties: { + id: { + multiplicity: false; + type: 'integer'; + nullable: false; + }; + body: { + multiplicity: false; + description: 'The text of the todo'; + type: 'string'; + nullable: true; + }; + text: { + multiplicity: false; + type: 'string'; + nullable: true; + }; + priority: { + multiplicity: false; + type: 'integer'; + nullable: true; + }; + complete: { + multiplicity: false; + type: 'boolean'; + nullable: true; + }; + }; +} + +export const Todo: TodoDef = { type: 'object', apiName: 'Todo', description: 'Its a todo item.', @@ -10,7 +47,7 @@ export const Todo = { multiplicity: false, targetType: 'Person', }, - }, + } as const, properties: { id: { multiplicity: false, @@ -39,4 +76,4 @@ export const Todo = { nullable: true, }, }, -} satisfies ObjectTypeDefinition<'Todo', 'Person'>; +}; diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/WeatherStation.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/WeatherStation.ts index 67a08254d..39a954006 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/WeatherStation.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/WeatherStation.ts @@ -1,11 +1,32 @@ import type { ObjectTypeDefinition } from '@osdk/api'; -export const WeatherStation = { +export interface WeatherStationDef extends ObjectTypeDefinition<'WeatherStation'> { + type: 'object'; + apiName: 'WeatherStation'; + description: 'Weather Station'; + primaryKeyType: 'string'; + links: {}; + properties: { + stationId: { + multiplicity: false; + type: 'string'; + nullable: false; + }; + geohash: { + multiplicity: false; + description: 'geopoint'; + type: 'geopoint'; + nullable: true; + }; + }; +} + +export const WeatherStation: WeatherStationDef = { type: 'object', apiName: 'WeatherStation', description: 'Weather Station', primaryKeyType: 'string', - links: {}, + links: {} as const, properties: { stationId: { multiplicity: false, @@ -19,4 +40,4 @@ export const WeatherStation = { nullable: true, }, }, -} satisfies ObjectTypeDefinition<'WeatherStation', never>; +}; diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index e3b1b63c4..7ab5d583a 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -35,6 +35,7 @@ export type { ObjectOrInterfaceDefinitionFrom, ObjectOrInterfaceKeysFrom, ObjectOrInterfacePropertyKeysFrom, + ObjectOrInterfacePropertyKeysFrom2, } from "./ontology/ObjectOrInterface"; export type { ObjectTypeDefinition, @@ -43,6 +44,7 @@ export type { ObjectTypeLinkDefinition, ObjectTypeLinkDefinitionFrom, ObjectTypeLinkKeysFrom, + ObjectTypeLinkKeysFrom2, ObjectTypeLinkTargetTypeFrom, ObjectTypePropertyDefinition, ObjectTypePropertyDefinitionFrom, diff --git a/packages/api/src/ontology/ObjectOrInterface.ts b/packages/api/src/ontology/ObjectOrInterface.ts index 0c9025f39..a83b0ccc0 100644 --- a/packages/api/src/ontology/ObjectOrInterface.ts +++ b/packages/api/src/ontology/ObjectOrInterface.ts @@ -34,7 +34,7 @@ export type ObjectOrInterfaceKeysFrom> = | InterfaceKeysFrom; export type ObjectOrInterfaceDefinition = - | ObjectTypeDefinition + | ObjectTypeDefinition | InterfaceDefinition; export type ObjectOrInterfacePropertyKeysFrom< @@ -43,6 +43,11 @@ export type ObjectOrInterfacePropertyKeysFrom< > = K extends InterfaceKeysFrom ? InterfacePropertyKeysFrom : ObjectTypePropertyKeysFrom; +export type ObjectOrInterfacePropertyKeysFrom2< + O extends ObjectTypeDefinition, +> = O extends ObjectTypeDefinition ? keyof O["properties"] & string + : never; + export type ObjectOrInterfaceDefinitionFrom< O extends OntologyDefinition, K extends ObjectOrInterfaceKeysFrom, diff --git a/packages/api/src/ontology/ObjectTypeDefinition.ts b/packages/api/src/ontology/ObjectTypeDefinition.ts index 48834e4bd..8e68470d5 100644 --- a/packages/api/src/ontology/ObjectTypeDefinition.ts +++ b/packages/api/src/ontology/ObjectTypeDefinition.ts @@ -43,14 +43,16 @@ export type ObjectTypePropertyDefinitionFrom< export interface ObjectTypeDefinition< K extends string, - L extends string, > { type: "object"; apiName: K; description?: string; primaryKeyType: keyof WirePropertyTypes; properties: Record; - links: Record>; + links: Record< + string, + ObjectTypeLinkDefinition + >; } export type ObjectTypeLinkKeysFrom< @@ -58,9 +60,16 @@ export type ObjectTypeLinkKeysFrom< K extends ObjectTypeKeysFrom, > = keyof ObjectTypeDefinitionFrom["links"]; -export interface ObjectTypeLinkDefinition { - targetType: K; - multiplicity: boolean; +export type ObjectTypeLinkKeysFrom2> = + & keyof O["links"] + & string; + +export interface ObjectTypeLinkDefinition< + O extends ObjectTypeDefinition, + M extends boolean, +> { + targetType: O["apiName"]; + multiplicity: M; } export type ObjectTypeLinkDefinitionFrom< diff --git a/packages/api/src/ontology/OntologyDefinition.ts b/packages/api/src/ontology/OntologyDefinition.ts index e4a82448e..98f5d45d3 100644 --- a/packages/api/src/ontology/OntologyDefinition.ts +++ b/packages/api/src/ontology/OntologyDefinition.ts @@ -28,7 +28,7 @@ export interface OntologyDefinition< > { metadata: OntologyMetadata; objects: { - [KK in K]: ObjectTypeDefinition; + [KK in K]: ObjectTypeDefinition; }; actions: { [AA in A]: ActionDefinition; diff --git a/packages/client/src/Client.test.ts b/packages/client/src/Client.test.ts new file mode 100644 index 000000000..10fb1aa8c --- /dev/null +++ b/packages/client/src/Client.test.ts @@ -0,0 +1,45 @@ +/* + * Copyright 2023 Palantir Technologies, Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, expectTypeOf, it } from "vitest"; +import type { Ontology as MockOntology } from "./generatedNoCheck/index.js"; +import type { Office } from "./generatedNoCheck/ontology/objects.js"; +import { Employee } from "./generatedNoCheck/ontology/objects.js"; +import type { Client } from "./index.js"; +import type { ObjectSet2 } from "./objectSet/ObjectSet.js"; +import type { OsdkObjectFrom2 } from "./OsdkObjectFrom.js"; + +describe("client", () => { + it("can be called with an object definition", async () => { + const client: Client = undefined as any; + const objSet = client(Employee); + expectTypeOf().toEqualTypeOf< + ObjectSet2 + >(); + + const result = await objSet.fetchPageOrThrow(); + expectTypeOf().toEqualTypeOf< + OsdkObjectFrom2< + typeof Employee + > + >(); + + const office = await result.data[0].$link.officeLink.get(); + expectTypeOf().toEqualTypeOf< + OsdkObjectFrom2 + >(); + }); +}); diff --git a/packages/client/src/Client.ts b/packages/client/src/Client.ts index 1237d9a41..4ad4be282 100644 --- a/packages/client/src/Client.ts +++ b/packages/client/src/Client.ts @@ -16,14 +16,21 @@ import type { ObjectOrInterfaceKeysFrom, + ObjectTypeDefinition, ObjectTypeKeysFrom, OntologyDefinition, } from "@osdk/api"; import type { Actions } from "./actions/Actions.js"; -import type { ObjectSet } from "./objectSet/ObjectSet.js"; +import type { ObjectSet, ObjectSet2 } from "./objectSet/ObjectSet.js"; import type { ObjectSetCreator } from "./ObjectSetCreator.js"; -export interface Client> { +export type CallableClient = < + O extends ObjectTypeDefinition, +>( + definition: O, +) => ObjectSet2; + +export type Client> = CallableClient & { objectSet: >( type: K, ) => ObjectSet; @@ -36,4 +43,4 @@ export interface Client> { type: K, rid: string, ): ObjectSet; -} +}; diff --git a/packages/client/src/OsdkObjectFrom.ts b/packages/client/src/OsdkObjectFrom.ts index f3e78cb36..753dbc86f 100644 --- a/packages/client/src/OsdkObjectFrom.ts +++ b/packages/client/src/OsdkObjectFrom.ts @@ -18,6 +18,8 @@ import type { InterfaceKeysFrom, InterfacePropertyDefinitionFrom, InterfacePropertyKeysFrom, + ObjectOrInterfacePropertyKeysFrom2, + ObjectTypeDefinition, ObjectTypeDefinitionFrom, ObjectTypeKeysFrom, ObjectTypePropertyKeysFrom, @@ -25,7 +27,10 @@ import type { WirePropertyTypes, } from "@osdk/api"; import type { OsdkObjectPropertyType } from "./Definitions.js"; -import type { OsdkObjectLinksObject } from "./definitions/LinkDefinitions.js"; +import type { + OsdkObjectLinksObject, + OsdkObjectLinksObject2, +} from "./definitions/LinkDefinitions.js"; export type OsdkObjectPrimaryKeyType< TObjectName, @@ -35,6 +40,31 @@ export type OsdkObjectPrimaryKeyType< ] : never; +export type OsdkObjectPrimaryKeyType2< + O extends ObjectTypeDefinition, +> = WirePropertyTypes[O["primaryKeyType"]]; + +export type OsdkObjectFrom2< + O extends ObjectTypeDefinition, + L extends ObjectOrInterfacePropertyKeysFrom2 = + ObjectOrInterfacePropertyKeysFrom2, +> = + & { + [P in L]: OsdkObjectPropertyType< + O["properties"][P] + >; + } + & { + __apiName: O["apiName"]; + __primaryKey: OsdkObjectPrimaryKeyType2; + /** + * Future versions will require explicitly asking for this field. For now we are marking + * as always optional to avoid breaking changes. + */ + __rid?: string; + $link: OsdkObjectLinksObject2; + }; // TODO + export type OsdkObjectFrom< T_ObjectTypeKey extends ObjectTypeKeysFrom, T_Ontology extends OntologyDefinition, diff --git a/packages/client/src/createCachedOntologyTransform.ts b/packages/client/src/createCachedOntologyTransform.ts index 07a3edcee..4b4f0bd0c 100644 --- a/packages/client/src/createCachedOntologyTransform.ts +++ b/packages/client/src/createCachedOntologyTransform.ts @@ -34,7 +34,7 @@ export function createCachedOntologyTransform< ) { // We can use the ObjectTypeDefinition as the key because it will be a globally unique singleton // Use Map instead of WeakMap here so usage for things like object prototypes do not churn over time - const cache = new Map, T>(); + const cache = new Map, T>(); return (ontology: O, type: K) => { const objectDefinition = ontology.objects[type]; diff --git a/packages/client/src/definitions/LinkDefinitions.test.ts b/packages/client/src/definitions/LinkDefinitions.test.ts index cc8f31bfe..92ad80d28 100644 --- a/packages/client/src/definitions/LinkDefinitions.test.ts +++ b/packages/client/src/definitions/LinkDefinitions.test.ts @@ -90,7 +90,7 @@ describe("LinkDefinitions", () => { >, >( options?: A, - ) => OsdkObjectFrom< + ) => OsdkObjectFrom2< "Person", typeof MockOntology, A["select"] extends readonly string[] ? A["select"][number] diff --git a/packages/client/src/definitions/LinkDefinitions.ts b/packages/client/src/definitions/LinkDefinitions.ts index 81ef46b97..6036b2759 100644 --- a/packages/client/src/definitions/LinkDefinitions.ts +++ b/packages/client/src/definitions/LinkDefinitions.ts @@ -16,17 +16,24 @@ import type { ObjectOrInterfacePropertyKeysFrom, + ObjectOrInterfacePropertyKeysFrom2, + ObjectTypeDefinition, ObjectTypeKeysFrom, + ObjectTypeLinkDefinition, ObjectTypeLinkDefinitionFrom, ObjectTypeLinkKeysFrom, + ObjectTypeLinkKeysFrom2, OntologyDefinition, } from "@osdk/api"; import type { FetchPageOrThrowArgs, SelectArg, + SelectArg2, } from "../object/fetchPageOrThrow.js"; +import type { ObjectSet2 } from "../objectSet/ObjectSet.js"; import type { OsdkObjectFrom, + OsdkObjectFrom2, OsdkObjectPrimaryKeyType, } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; @@ -39,6 +46,12 @@ export type OsdkObjectLinksObject< [L in ObjectTypeLinkKeysFrom]: OsdkObjectLinksEntry; }; +export type OsdkObjectLinksObject2< + O extends ObjectTypeDefinition, +> = ObjectTypeLinkKeysFrom2 extends never ? never : { + [L in ObjectTypeLinkKeysFrom2]: OsdkObjectLinksEntry2; +}; + export type OsdkObjectLinksEntry< K extends ObjectTypeKeysFrom, O extends OntologyDefinition, @@ -96,3 +109,26 @@ export type OsdkObjectLinksEntry< > >; }; + +export type LinkTargetType< + O extends ObjectTypeDefinition, + L extends ObjectTypeLinkKeysFrom2, +> = O["links"][L]["targetType"]; + +export type OsdkObjectLinksEntry2< + O extends ObjectTypeDefinition, + L extends ObjectTypeLinkKeysFrom2, +> = O["links"][L] extends ObjectTypeLinkDefinition ? ( + M extends false ? { + /** Load the linked object */ + get: >( + options?: A, + ) => OsdkObjectFrom2< + T, + A["select"] extends readonly string[] ? A["select"][number] + : ObjectOrInterfacePropertyKeysFrom2 + >; + } + : ObjectSet2 + ) + : never; diff --git a/packages/client/src/object/fetchPageOrThrow.ts b/packages/client/src/object/fetchPageOrThrow.ts index 597d59b9d..6a27d5bc5 100644 --- a/packages/client/src/object/fetchPageOrThrow.ts +++ b/packages/client/src/object/fetchPageOrThrow.ts @@ -17,6 +17,8 @@ import type { ObjectOrInterfaceKeysFrom, ObjectOrInterfacePropertyKeysFrom, + ObjectOrInterfacePropertyKeysFrom2, + ObjectTypeDefinition, OntologyDefinition, } from "@osdk/api"; import { loadObjectSetV2 } from "@osdk/gateway/requests"; @@ -35,6 +37,13 @@ export interface SelectArg< select?: readonly L[]; } +export interface SelectArg2< + O extends ObjectTypeDefinition, + L = ObjectOrInterfacePropertyKeysFrom2, +> { + select?: readonly L[]; +} + export interface FetchPageOrThrowArgs< O extends OntologyDefinition, K extends ObjectOrInterfaceKeysFrom, @@ -44,6 +53,14 @@ export interface FetchPageOrThrowArgs< pageSize?: number; } +export interface FetchPageOrThrowArgs2< + O extends ObjectTypeDefinition, + L = ObjectOrInterfacePropertyKeysFrom2, +> extends SelectArg2 { + nextPageToken?: string; + pageSize?: number; +} + export async function fetchPageOrThrow< O extends OntologyDefinition, T extends ObjectOrInterfaceKeysFrom, diff --git a/packages/client/src/objectSet/ObjectSet.ts b/packages/client/src/objectSet/ObjectSet.ts index 4f7005fe1..9bee5547b 100644 --- a/packages/client/src/objectSet/ObjectSet.ts +++ b/packages/client/src/objectSet/ObjectSet.ts @@ -19,17 +19,40 @@ import type { ObjectOrInterfaceDefinitionFrom, ObjectOrInterfaceKeysFrom, ObjectOrInterfacePropertyKeysFrom, + ObjectOrInterfacePropertyKeysFrom2, + ObjectTypeDefinition, OntologyDefinition, } from "@osdk/api"; import type { ObjectSet as WireObjectSet } from "@osdk/gateway/types"; -import type { FetchPageOrThrowArgs } from "../object/fetchPageOrThrow.js"; -import type { OsdkInterfaceFrom, OsdkObjectFrom } from "../OsdkObjectFrom.js"; +import type { + FetchPageOrThrowArgs, + FetchPageOrThrowArgs2, +} from "../object/fetchPageOrThrow.js"; +import type { + OsdkInterfaceFrom, + OsdkObjectFrom, + OsdkObjectFrom2, +} from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import type { AggregateOpts } from "../query/aggregations/AggregateOpts.js"; import type { AggregationsResults, WhereClause } from "../query/index.js"; import type { LinkTypesFrom } from "./LinkTypesFrom.js"; import type { ObjectSetListener } from "./ObjectSetListener.js"; +export interface ObjectSet2> { + definition: WireObjectSet; + + fetchPageOrThrow: < + S extends ObjectOrInterfacePropertyKeysFrom2, + >( + args?: FetchPageOrThrowArgs2, + ) => Promise< + PageResult< + OsdkObjectFrom2 + > + >; +} + export type ObjectSet< O extends OntologyDefinition, K extends ObjectOrInterfaceKeysFrom, diff --git a/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectConst.ts b/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectConst.ts index 433472d1b..0ddae704a 100644 --- a/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectConst.ts +++ b/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectConst.ts @@ -20,26 +20,55 @@ import { wireObjectTypeV2ToSdkObjectDefinition } from "./wireObjectTypeV2ToSdkOb /** @internal */ export function wireObjectTypeV2ToSdkObjectConst( object: ObjectTypeWithLink, + importExt: string, v2: boolean = false, ) { const uniqueLinkTargetTypes = new Set( object.linkTypes.map(a => a.objectTypeApiName), ); + + const definition = wireObjectTypeV2ToSdkObjectDefinition( + object, + v2, + ); + + const imports = Array.from(uniqueLinkTargetTypes).filter(type => + type != definition.apiName + ).map(type => `import type { ${type}Def } from "./${type}${importExt}";`); + return ` - export const ${object.objectType.apiName} = ${ - JSON.stringify( - wireObjectTypeV2ToSdkObjectDefinition( - object, - v2, - ), - null, - 2, - ) - } satisfies ObjectTypeDefinition<"${object.objectType.apiName}", ${ - uniqueLinkTargetTypes.size > 0 - ? [...uniqueLinkTargetTypes].map(apiName => `"${apiName}"`).join( - "|", - ) - : "never" - }>;`; + ${imports.join("\n")} + export interface ${object.objectType.apiName}Def extends ObjectTypeDefinition<"${object.objectType.apiName}"> { + type: "${definition.type}", + apiName: "${definition.apiName}", + ${ + definition.description != null + ? `description: ${JSON.stringify(definition.description)},` + : "" + } + primaryKeyType: ${JSON.stringify(definition.primaryKeyType)}, + links: {${ + Object.entries(definition.links).map( + ( + [linkApiName, definition], + ) => + `${linkApiName}: ObjectTypeLinkDefinition<${definition.targetType}Def, ${definition.multiplicity}>`, + ).join(",\n") + } + }, + properties: ${JSON.stringify(definition.properties, null, 2)}, + } + + export const ${object.objectType.apiName}: ${object.objectType.apiName}Def = { + type: "${definition.type}", + apiName: "${definition.apiName}", + ${ + definition.description != null + ? `description: ${JSON.stringify(definition.description)},` + : "" + } + primaryKeyType: ${JSON.stringify(definition.primaryKeyType)}, + links: ${JSON.stringify(definition.links, null, 2)} as const, + properties: ${JSON.stringify(definition.properties, null, 2)}, + };`; } diff --git a/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectDefinition.ts b/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectDefinition.ts index 3dc24698e..9974da508 100644 --- a/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectDefinition.ts +++ b/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectDefinition.ts @@ -22,7 +22,7 @@ import { wirePropertyV2ToSdkPropertyDefinition } from "./wirePropertyV2ToSdkProp export function wireObjectTypeV2ToSdkObjectDefinition( objectTypeWithLink: ObjectTypeWithLink, v2: boolean, -): ObjectTypeDefinition { +): ObjectTypeDefinition { if ( objectTypeWithLink.objectType .properties[objectTypeWithLink.objectType.primaryKey] === undefined diff --git a/packages/generator/src/v1.1/generatePerObjectInterfaceAndDataFiles.ts b/packages/generator/src/v1.1/generatePerObjectInterfaceAndDataFiles.ts index c21266f4d..dfd14e324 100644 --- a/packages/generator/src/v1.1/generatePerObjectInterfaceAndDataFiles.ts +++ b/packages/generator/src/v1.1/generatePerObjectInterfaceAndDataFiles.ts @@ -35,7 +35,7 @@ export async function generatePerObjectInterfaceAndDataFiles( await fs.writeFile( path.join(outDir, `${object.objectType.apiName}.ts`), await formatTs(` - import type { ObjectTypeDefinition } from "@osdk/api"; + import type { ObjectTypeDefinition, ObjectTypeLinkDefinition } from "@osdk/api"; ${ wireObjectTypeV2ToObjectInterfaceStringV1( object, @@ -43,7 +43,7 @@ export async function generatePerObjectInterfaceAndDataFiles( ) } - ${wireObjectTypeV2ToSdkObjectConst(object)} + ${wireObjectTypeV2ToSdkObjectConst(object, importExt)} `), ); }), diff --git a/packages/generator/src/v2.0/generateClientSdkVersionTwoPointZero.ts b/packages/generator/src/v2.0/generateClientSdkVersionTwoPointZero.ts index 1e83416d2..bc6012f98 100644 --- a/packages/generator/src/v2.0/generateClientSdkVersionTwoPointZero.ts +++ b/packages/generator/src/v2.0/generateClientSdkVersionTwoPointZero.ts @@ -112,9 +112,9 @@ export async function generateClientSdkVersionTwoPointZero( path.join(outDir, "ontology", `objects`, `${name}.ts`), await formatTs(` - import type { ObjectTypeDefinition } from "@osdk/api"; + import type { ObjectTypeDefinition, ObjectTypeLinkDefinition } from "@osdk/api"; - ${wireObjectTypeV2ToSdkObjectConst(obj, true)} + ${wireObjectTypeV2ToSdkObjectConst(obj, importExt, true)} ${ /* TODO: FIXME diff --git a/packages/legacy-client/src/client/OsdkLegacyObject.test.ts b/packages/legacy-client/src/client/OsdkLegacyObject.test.ts index 9e4e22250..51429f8b9 100644 --- a/packages/legacy-client/src/client/OsdkLegacyObject.test.ts +++ b/packages/legacy-client/src/client/OsdkLegacyObject.test.ts @@ -22,9 +22,12 @@ import type { OsdkLegacyObjectFrom } from "./OsdkLegacyObject"; describe("OsdkLegacyObject", () => { it("compiles", async () => { const x: Todo = {} as Todo; - const y: OsdkLegacyObjectFrom = x; + const y: OsdkLegacyObjectFrom = x; expectTypeOf() .toMatchTypeOf>(); + + expectTypeOf>() + .toMatchTypeOf(); }); }); diff --git a/packages/legacy-client/src/client/objectSets/createCachedOntologyTransform.ts b/packages/legacy-client/src/client/objectSets/createCachedOntologyTransform.ts index 07a3edcee..4b4f0bd0c 100644 --- a/packages/legacy-client/src/client/objectSets/createCachedOntologyTransform.ts +++ b/packages/legacy-client/src/client/objectSets/createCachedOntologyTransform.ts @@ -34,7 +34,7 @@ export function createCachedOntologyTransform< ) { // We can use the ObjectTypeDefinition as the key because it will be a globally unique singleton // Use Map instead of WeakMap here so usage for things like object prototypes do not churn over time - const cache = new Map, T>(); + const cache = new Map, T>(); return (ontology: O, type: K) => { const objectDefinition = ontology.objects[type]; diff --git a/packages/shared.test/src/mock-ontology/ObjectTypeWithAllPropertyTypes.ts b/packages/shared.test/src/mock-ontology/ObjectTypeWithAllPropertyTypes.ts index 444db1131..fb70ff7b1 100644 --- a/packages/shared.test/src/mock-ontology/ObjectTypeWithAllPropertyTypes.ts +++ b/packages/shared.test/src/mock-ontology/ObjectTypeWithAllPropertyTypes.ts @@ -140,6 +140,5 @@ export const ObjectTypeWithAllPropertyTypes = { }, }, } satisfies ObjectTypeDefinition< - "ObjectTypeWithAllPropertyTypes", "ObjectTypeWithAllPropertyTypes" >; diff --git a/packages/shared.test/src/mock-ontology/ObjectTypeWithReservedNames.ts b/packages/shared.test/src/mock-ontology/ObjectTypeWithReservedNames.ts index 75afa35b8..9fbd68197 100644 --- a/packages/shared.test/src/mock-ontology/ObjectTypeWithReservedNames.ts +++ b/packages/shared.test/src/mock-ontology/ObjectTypeWithReservedNames.ts @@ -33,6 +33,5 @@ export const ObjectTypeWithReservedNames = { }, }, } satisfies ObjectTypeDefinition< - "ObjectTypeWithReservedNames", "ObjectTypeWithReservedNames" >; diff --git a/packages/shared.test/src/mock-ontology/mockOntology.ts b/packages/shared.test/src/mock-ontology/mockOntology.ts index 3953197ce..37e0e3e00 100644 --- a/packages/shared.test/src/mock-ontology/mockOntology.ts +++ b/packages/shared.test/src/mock-ontology/mockOntology.ts @@ -33,7 +33,10 @@ export const MockOntology = { id: { type: "integer", nullable: true }, }, links: { - linkedTodos: { multiplicity: true, targetType: "Todo" }, + linkedTodos: { + multiplicity: true, + targetType: "Todo", + }, }, }, Todo: { @@ -54,7 +57,10 @@ export const MockOntology = { points: { type: "integer", nullable: true }, }, links: { - linkedTask: { multiplicity: false, targetType: "Task" }, + linkedTask: { + multiplicity: false, + targetType: "Task", + }, }, }, ObjectTypeWithAllPropertyTypes, From c02498749e747f6cbde9dbded09d1b5fc0d15bdf Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Mon, 12 Feb 2024 17:07:33 -0500 Subject: [PATCH 03/19] Fix types compilation --- .../objects/ObjectTypeWithAllPropertyTypes.ts | 171 +++++++++- .../ontology/objects/Person.ts | 24 +- .../generatedNoCheck/ontology/objects/Todo.ts | 35 +- .../generatedNoCheck/ontology/objects/Todo.ts | 32 +- .../ontology/objects/Todo.ts | 32 +- .../src/definitions/LinkDefinitions.test.ts | 99 ++---- .../client/src/definitions/LinkDefinitions.ts | 22 +- packages/client/src/util/test/mockOntology.ts | 126 ++++--- .../ObjectTypeWithAllPropertyTypes.ts | 318 ++++++++++++------ .../ObjectTypeWithReservedNames.ts | 25 +- .../src/mock-ontology/mockOntology.ts | 112 +++--- turbo.json | 2 +- 12 files changed, 717 insertions(+), 281 deletions(-) diff --git a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts index 3ce734708..062a63f8c 100644 --- a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts +++ b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts @@ -48,12 +48,177 @@ export interface ObjectTypeWithAllPropertyTypes extends OntologyObject { readonly stringTimeseries: TimeSeries | undefined; } -export const ObjectTypeWithAllPropertyTypes = { +export interface ObjectTypeWithAllPropertyTypesDef extends ObjectTypeDefinition<'ObjectTypeWithAllPropertyTypes'> { + type: 'object'; + apiName: 'ObjectTypeWithAllPropertyTypes'; + description: 'A type with all property types'; + primaryKeyType: 'integer'; + links: {}; + properties: { + id: { + multiplicity: false; + type: 'integer'; + nullable: true; + }; + string: { + multiplicity: false; + type: 'string'; + nullable: true; + }; + boolean: { + multiplicity: false; + type: 'boolean'; + nullable: true; + }; + date: { + multiplicity: false; + type: 'datetime'; + nullable: true; + }; + dateTime: { + multiplicity: false; + type: 'timestamp'; + nullable: true; + }; + decimal: { + multiplicity: false; + type: 'decimal'; + nullable: true; + }; + integer: { + multiplicity: false; + type: 'integer'; + nullable: true; + }; + long: { + multiplicity: false; + type: 'long'; + nullable: true; + }; + short: { + multiplicity: false; + type: 'short'; + nullable: true; + }; + float: { + multiplicity: false; + type: 'float'; + nullable: true; + }; + double: { + multiplicity: false; + type: 'double'; + nullable: true; + }; + byte: { + multiplicity: false; + type: 'byte'; + nullable: true; + }; + attachment: { + multiplicity: false; + type: 'attachment'; + nullable: true; + }; + geoPoint: { + multiplicity: false; + type: 'geopoint'; + nullable: true; + }; + geoShape: { + multiplicity: false; + type: 'geoshape'; + nullable: true; + }; + stringArray: { + multiplicity: true; + type: 'string'; + nullable: true; + }; + booleanArray: { + multiplicity: true; + type: 'boolean'; + nullable: true; + }; + dateArray: { + multiplicity: true; + type: 'datetime'; + nullable: true; + }; + dateTimeArray: { + multiplicity: true; + type: 'timestamp'; + nullable: true; + }; + decimalArray: { + multiplicity: true; + type: 'decimal'; + nullable: true; + }; + integerArray: { + multiplicity: true; + type: 'integer'; + nullable: true; + }; + longArray: { + multiplicity: true; + type: 'long'; + nullable: true; + }; + shortArray: { + multiplicity: true; + type: 'short'; + nullable: true; + }; + floatArray: { + multiplicity: true; + type: 'float'; + nullable: true; + }; + doubleArray: { + multiplicity: true; + type: 'double'; + nullable: true; + }; + byteArray: { + multiplicity: true; + type: 'byte'; + nullable: true; + }; + attachmentArray: { + multiplicity: true; + type: 'attachment'; + nullable: true; + }; + geoPointArray: { + multiplicity: true; + type: 'geopoint'; + nullable: true; + }; + geoShapeArray: { + multiplicity: true; + type: 'geoshape'; + nullable: true; + }; + numericTimeseries: { + multiplicity: false; + type: 'numericTimeseries'; + nullable: true; + }; + stringTimeseries: { + multiplicity: false; + type: 'stringTimeseries'; + nullable: true; + }; + }; +} + +export const ObjectTypeWithAllPropertyTypes: ObjectTypeWithAllPropertyTypesDef = { type: 'object', apiName: 'ObjectTypeWithAllPropertyTypes', description: 'A type with all property types', primaryKeyType: 'integer', - links: {}, + links: {} as const, properties: { id: { multiplicity: false, @@ -211,4 +376,4 @@ export const ObjectTypeWithAllPropertyTypes = { nullable: true, }, }, -} satisfies ObjectTypeDefinition<'ObjectTypeWithAllPropertyTypes', never>; +}; diff --git a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Person.ts b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Person.ts index 41a633d92..18efe80fb 100644 --- a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Person.ts +++ b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Person.ts @@ -1,4 +1,4 @@ -import type { ObjectTypeDefinition } from '@osdk/api'; +import type { ObjectTypeDefinition, ObjectTypeLinkDefinition } from '@osdk/api'; import type { MultiLink, OntologyObject } from '@osdk/legacy-client'; import type { Todo } from './Todo'; @@ -13,7 +13,23 @@ export interface Person extends OntologyObject { readonly Friends: MultiLink; } -export const Person = { +import type { TodoDef } from './Todo'; +export interface PersonDef extends ObjectTypeDefinition<'Person'> { + type: 'object'; + apiName: 'Person'; + description: 'A person'; + primaryKeyType: 'string'; + links: { Todos: ObjectTypeLinkDefinition; Friends: ObjectTypeLinkDefinition }; + properties: { + email: { + multiplicity: false; + type: 'string'; + nullable: true; + }; + }; +} + +export const Person: PersonDef = { type: 'object', apiName: 'Person', description: 'A person', @@ -27,7 +43,7 @@ export const Person = { multiplicity: true, targetType: 'Person', }, - }, + } as const, properties: { email: { multiplicity: false, @@ -35,4 +51,4 @@ export const Person = { nullable: true, }, }, -} satisfies ObjectTypeDefinition<'Person', 'Todo' | 'Person'>; +}; diff --git a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Todo.ts b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Todo.ts index accf7fced..e14814ab1 100644 --- a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Todo.ts +++ b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Todo.ts @@ -1,4 +1,4 @@ -import type { ObjectTypeDefinition } from '@osdk/api'; +import type { ObjectTypeDefinition, ObjectTypeLinkDefinition } from '@osdk/api'; import type { OntologyObject, SingleLink } from '@osdk/legacy-client'; import type { Person } from './Person'; @@ -17,7 +17,34 @@ export interface Todo extends OntologyObject { readonly Assignee: SingleLink; } -export const Todo = { +import type { PersonDef } from './Person'; +export interface TodoDef extends ObjectTypeDefinition<'Todo'> { + type: 'object'; + apiName: 'Todo'; + description: 'Its a todo item.'; + primaryKeyType: 'integer'; + links: { Assignee: ObjectTypeLinkDefinition }; + properties: { + id: { + multiplicity: false; + type: 'integer'; + nullable: true; + }; + body: { + multiplicity: false; + description: 'The text of the todo'; + type: 'string'; + nullable: true; + }; + complete: { + multiplicity: false; + type: 'boolean'; + nullable: true; + }; + }; +} + +export const Todo: TodoDef = { type: 'object', apiName: 'Todo', description: 'Its a todo item.', @@ -27,7 +54,7 @@ export const Todo = { multiplicity: false, targetType: 'Person', }, - }, + } as const, properties: { id: { multiplicity: false, @@ -46,4 +73,4 @@ export const Todo = { nullable: true, }, }, -} satisfies ObjectTypeDefinition<'Todo', 'Person'>; +}; diff --git a/examples/todoapp/src/generatedNoCheck/ontology/objects/Todo.ts b/examples/todoapp/src/generatedNoCheck/ontology/objects/Todo.ts index 9672d6a45..5949d4c9c 100644 --- a/examples/todoapp/src/generatedNoCheck/ontology/objects/Todo.ts +++ b/examples/todoapp/src/generatedNoCheck/ontology/objects/Todo.ts @@ -15,12 +15,38 @@ export interface Todo extends OntologyObject { readonly title: string | undefined; } -export const Todo = { +export interface TodoDef extends ObjectTypeDefinition<'Todo'> { + type: 'object'; + apiName: 'Todo'; + description: 'Its a todo item.'; + primaryKeyType: 'string'; + links: {}; + properties: { + id: { + multiplicity: false; + type: 'string'; + nullable: true; + }; + title: { + multiplicity: false; + description: 'The text of the todo'; + type: 'string'; + nullable: true; + }; + isComplete: { + multiplicity: false; + type: 'boolean'; + nullable: true; + }; + }; +} + +export const Todo: TodoDef = { type: 'object', apiName: 'Todo', description: 'Its a todo item.', primaryKeyType: 'string', - links: {}, + links: {} as const, properties: { id: { multiplicity: false, @@ -39,4 +65,4 @@ export const Todo = { nullable: true, }, }, -} satisfies ObjectTypeDefinition<'Todo', never>; +}; diff --git a/examples/todoapp/src/generatedNoCheck2/ontology/objects/Todo.ts b/examples/todoapp/src/generatedNoCheck2/ontology/objects/Todo.ts index 4469266d6..eb262371e 100644 --- a/examples/todoapp/src/generatedNoCheck2/ontology/objects/Todo.ts +++ b/examples/todoapp/src/generatedNoCheck2/ontology/objects/Todo.ts @@ -1,11 +1,37 @@ import type { ObjectTypeDefinition } from '@osdk/api'; -export const Todo = { +export interface TodoDef extends ObjectTypeDefinition<'Todo'> { + type: 'object'; + apiName: 'Todo'; + description: 'Its a todo item.'; + primaryKeyType: 'string'; + links: {}; + properties: { + id: { + multiplicity: false; + type: 'string'; + nullable: false; + }; + title: { + multiplicity: false; + description: 'The text of the todo'; + type: 'string'; + nullable: true; + }; + isComplete: { + multiplicity: false; + type: 'boolean'; + nullable: true; + }; + }; +} + +export const Todo: TodoDef = { type: 'object', apiName: 'Todo', description: 'Its a todo item.', primaryKeyType: 'string', - links: {}, + links: {} as const, properties: { id: { multiplicity: false, @@ -24,4 +50,4 @@ export const Todo = { nullable: true, }, }, -} satisfies ObjectTypeDefinition<'Todo', never>; +}; diff --git a/packages/client/src/definitions/LinkDefinitions.test.ts b/packages/client/src/definitions/LinkDefinitions.test.ts index 92ad80d28..b9364886a 100644 --- a/packages/client/src/definitions/LinkDefinitions.test.ts +++ b/packages/client/src/definitions/LinkDefinitions.test.ts @@ -14,92 +14,43 @@ * limitations under the License. */ -import type { ObjectOrInterfacePropertyKeysFrom } from "@osdk/api"; import { describe, expectTypeOf, it } from "vitest"; -import type { - FetchPageOrThrowArgs, - SelectArg, -} from "../object/fetchPageOrThrow.js"; -import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; -import type { PageResult } from "../PageResult.js"; +import type { ObjectSet2 } from "../objectSet/ObjectSet.js"; import type { MockOntology } from "../util/test/mockOntology.js"; -import type { OsdkObjectLinksObject } from "./LinkDefinitions.js"; +import type { + OsdkObjectLinksObject2, + SingletonLinkAccessor, +} from "./LinkDefinitions.js"; describe("LinkDefinitions", () => { describe("OsdkObjectLinkObject", () => { it("is correctly absent on types with no links", () => { - expectTypeOf>() + expectTypeOf< + OsdkObjectLinksObject2 + >() .toEqualTypeOf(); }); it("populates on types with links", () => { - expectTypeOf>() + type Objects = typeof MockOntology["objects"]; + type TaskDef = Objects["Task"]; + type PersonDef = Objects["Person"]; + type TodoDef = Objects["Todo"]; + + expectTypeOf["Todos"]>() + .toEqualTypeOf>(); + + expectTypeOf["RP"]>() + .toEqualTypeOf>(); + + const q: OsdkObjectLinksObject2 = {} as any; + q.Todos.definition; + + expectTypeOf>() .toEqualTypeOf< { - Todos: { - get: < - A extends SelectArg< - typeof MockOntology, - "Todo", - ObjectOrInterfacePropertyKeysFrom< - typeof MockOntology, - "Todo" - > - >, - >( - primaryKey: number, - options?: A, - ) => OsdkObjectFrom< - "Todo", - typeof MockOntology, - A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom< - typeof MockOntology, - "Todo" - > - >; - fetchPageOrThrow: < - A extends FetchPageOrThrowArgs< - typeof MockOntology, - "Todo", - ObjectOrInterfacePropertyKeysFrom - >, - >(options?: A | undefined) => Promise< - PageResult< - OsdkObjectFrom< - "Todo", - typeof MockOntology, - A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom< - typeof MockOntology, - "Todo" - > - > - > - >; - }; - RP: { - get: < - A extends SelectArg< - typeof MockOntology, - "Person", - ObjectOrInterfacePropertyKeysFrom< - typeof MockOntology, - "Person" - > - >, - >( - options?: A, - ) => OsdkObjectFrom2< - "Person", - typeof MockOntology, - A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom< - typeof MockOntology, - "Person" - > - >; - }; + Todos: ObjectSet2; + RP: SingletonLinkAccessor; } >(); }); diff --git a/packages/client/src/definitions/LinkDefinitions.ts b/packages/client/src/definitions/LinkDefinitions.ts index 6036b2759..a84eccdad 100644 --- a/packages/client/src/definitions/LinkDefinitions.ts +++ b/packages/client/src/definitions/LinkDefinitions.ts @@ -119,16 +119,18 @@ export type OsdkObjectLinksEntry2< O extends ObjectTypeDefinition, L extends ObjectTypeLinkKeysFrom2, > = O["links"][L] extends ObjectTypeLinkDefinition ? ( - M extends false ? { - /** Load the linked object */ - get: >( - options?: A, - ) => OsdkObjectFrom2< - T, - A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom2 - >; - } + M extends false ? SingletonLinkAccessor : ObjectSet2 ) : never; + +// export type Q + +export interface SingletonLinkAccessor> { + /** Load the linked object */ + get: >(options?: A) => OsdkObjectFrom2< + T, + A["select"] extends readonly string[] ? A["select"][number] + : ObjectOrInterfacePropertyKeysFrom2 + >; +} diff --git a/packages/client/src/util/test/mockOntology.ts b/packages/client/src/util/test/mockOntology.ts index 276087729..0a08857fd 100644 --- a/packages/client/src/util/test/mockOntology.ts +++ b/packages/client/src/util/test/mockOntology.ts @@ -14,7 +14,89 @@ * limitations under the License. */ -import type { OntologyDefinition } from "@osdk/api"; +import type { + ObjectTypeDefinition, + ObjectTypeLinkDefinition, + OntologyDefinition, +} from "@osdk/api"; + +const Task: TaskDef = { + type: "object", + apiName: "Task", + primaryKeyType: "integer", + properties: { + id: { type: "integer" }, + name: { type: "string" }, + }, + links: { + "Todos": { + targetType: "Todo", + multiplicity: true, + }, + "RP": { + targetType: "Person", + multiplicity: false, + }, + }, +}; + +interface TaskDef extends ObjectTypeDefinition<"Task"> { + type: "object"; + apiName: "Task"; + primaryKeyType: "integer"; + properties: { + id: { type: "integer" }; + name: { type: "string" }; + }; + links: { + "Todos": ObjectTypeLinkDefinition; + "RP": ObjectTypeLinkDefinition; + }; +} + +const Todo: TodoDef = { + type: "object", + apiName: "Todo", + primaryKeyType: "integer", + properties: { + id: { type: "integer" }, + text: { type: "string" }, + }, + links: {}, +}; + +interface TodoDef extends ObjectTypeDefinition<"Todo"> { + type: "object"; + apiName: "Todo"; + primaryKeyType: "integer"; + properties: { + id: { type: "integer" }; + text: { type: "string" }; + }; + links: {}; +} + +const Person: PersonDef = { + type: "object", + apiName: "Person", + primaryKeyType: "integer", + properties: { + id: { type: "integer" }, + name: { type: "string" }, + }, + links: {}, +}; + +interface PersonDef extends ObjectTypeDefinition<"Person"> { + type: "object"; + apiName: "Person"; + primaryKeyType: "integer"; + properties: { + id: { type: "integer" }; + name: { type: "string" }; + }; + links: {}; +} export const MockOntology = { metadata: { @@ -23,45 +105,9 @@ export const MockOntology = { userAgent: "userAgent", }, objects: { - Task: { - type: "object", - apiName: "Task", - primaryKeyType: "integer", - properties: { - id: { type: "integer" }, - name: { type: "string" }, - }, - links: { - "Todos": { - targetType: "Todo", - multiplicity: true, - }, - "RP": { - targetType: "Person", - multiplicity: false, - }, - }, - }, - Todo: { - type: "object", - apiName: "Todo", - primaryKeyType: "integer", - properties: { - id: { type: "integer" }, - text: { type: "string" }, - }, - links: {}, - }, - Person: { - type: "object", - apiName: "Person", - primaryKeyType: "integer", - properties: { - id: { type: "integer" }, - name: { type: "string" }, - }, - links: {}, - }, + Task, + Todo, + Person, }, actions: {}, queries: {}, diff --git a/packages/shared.test/src/mock-ontology/ObjectTypeWithAllPropertyTypes.ts b/packages/shared.test/src/mock-ontology/ObjectTypeWithAllPropertyTypes.ts index fb70ff7b1..1c703daf4 100644 --- a/packages/shared.test/src/mock-ontology/ObjectTypeWithAllPropertyTypes.ts +++ b/packages/shared.test/src/mock-ontology/ObjectTypeWithAllPropertyTypes.ts @@ -16,129 +16,257 @@ import type { ObjectTypeDefinition } from "@osdk/api"; -export const ObjectTypeWithAllPropertyTypes = { - type: "object", - apiName: "ObjectTypeWithAllPropertyTypes", - primaryKeyType: "integer", - links: {}, +export interface ObjectTypeWithAllPropertyTypesDef + extends ObjectTypeDefinition<"ObjectTypeWithAllPropertyTypes"> +{ + type: "object"; + apiName: "ObjectTypeWithAllPropertyTypes"; + primaryKeyType: "integer"; + links: {}; properties: { id: { - multiplicity: false, - type: "integer", - }, + multiplicity: false; + type: "integer"; + }; string: { - multiplicity: false, - type: "string", - }, + multiplicity: false; + type: "string"; + }; boolean: { - multiplicity: false, - type: "boolean", - }, + multiplicity: false; + type: "boolean"; + }; date: { - multiplicity: false, - type: "datetime", - }, + multiplicity: false; + type: "datetime"; + }; dateTime: { - multiplicity: false, - type: "timestamp", - }, + multiplicity: false; + type: "timestamp"; + }; decimal: { - multiplicity: false, - type: "decimal", - }, + multiplicity: false; + type: "decimal"; + }; integer: { - multiplicity: false, - type: "integer", - }, + multiplicity: false; + type: "integer"; + }; long: { - multiplicity: false, - type: "long", - }, + multiplicity: false; + type: "long"; + }; short: { - multiplicity: false, - type: "short", - }, + multiplicity: false; + type: "short"; + }; float: { - multiplicity: false, - type: "float", - }, + multiplicity: false; + type: "float"; + }; double: { - multiplicity: false, - type: "double", - }, + multiplicity: false; + type: "double"; + }; byte: { - multiplicity: false, - type: "byte", - }, + multiplicity: false; + type: "byte"; + }; attachment: { - multiplicity: false, - type: "attachment", - }, + multiplicity: false; + type: "attachment"; + }; geoPoint: { - multiplicity: false, - type: "geopoint", - }, + multiplicity: false; + type: "geopoint"; + }; geoShape: { - multiplicity: false, - type: "geoshape", - }, + multiplicity: false; + type: "geoshape"; + }; stringArray: { - multiplicity: true, - type: "string", - }, + multiplicity: true; + type: "string"; + }; booleanArray: { - multiplicity: true, - type: "boolean", - }, + multiplicity: true; + type: "boolean"; + }; dateArray: { - multiplicity: true, - type: "datetime", - }, + multiplicity: true; + type: "datetime"; + }; dateTimeArray: { - multiplicity: true, - type: "timestamp", - }, + multiplicity: true; + type: "timestamp"; + }; decimalArray: { - multiplicity: true, - type: "decimal", - }, + multiplicity: true; + type: "decimal"; + }; integerArray: { - multiplicity: true, - type: "integer", - }, + multiplicity: true; + type: "integer"; + }; longArray: { - multiplicity: true, - type: "long", - }, + multiplicity: true; + type: "long"; + }; shortArray: { - multiplicity: true, - type: "short", - }, + multiplicity: true; + type: "short"; + }; floatArray: { - multiplicity: true, - type: "float", - }, + multiplicity: true; + type: "float"; + }; doubleArray: { - multiplicity: true, - type: "double", - }, + multiplicity: true; + type: "double"; + }; byteArray: { - multiplicity: true, - type: "byte", - }, + multiplicity: true; + type: "byte"; + }; attachmentArray: { - multiplicity: true, - type: "attachment", - }, + multiplicity: true; + type: "attachment"; + }; geoPointArray: { - multiplicity: true, - type: "geopoint", - }, + multiplicity: true; + type: "geopoint"; + }; geoShapeArray: { - multiplicity: true, - type: "geoshape", + multiplicity: true; + type: "geoshape"; + }; + }; +} + +export const ObjectTypeWithAllPropertyTypes: ObjectTypeWithAllPropertyTypesDef = + { + type: "object", + apiName: "ObjectTypeWithAllPropertyTypes", + primaryKeyType: "integer", + links: {}, + properties: { + id: { + multiplicity: false, + type: "integer", + }, + string: { + multiplicity: false, + type: "string", + }, + boolean: { + multiplicity: false, + type: "boolean", + }, + date: { + multiplicity: false, + type: "datetime", + }, + dateTime: { + multiplicity: false, + type: "timestamp", + }, + decimal: { + multiplicity: false, + type: "decimal", + }, + integer: { + multiplicity: false, + type: "integer", + }, + long: { + multiplicity: false, + type: "long", + }, + short: { + multiplicity: false, + type: "short", + }, + float: { + multiplicity: false, + type: "float", + }, + double: { + multiplicity: false, + type: "double", + }, + byte: { + multiplicity: false, + type: "byte", + }, + attachment: { + multiplicity: false, + type: "attachment", + }, + geoPoint: { + multiplicity: false, + type: "geopoint", + }, + geoShape: { + multiplicity: false, + type: "geoshape", + }, + stringArray: { + multiplicity: true, + type: "string", + }, + booleanArray: { + multiplicity: true, + type: "boolean", + }, + dateArray: { + multiplicity: true, + type: "datetime", + }, + dateTimeArray: { + multiplicity: true, + type: "timestamp", + }, + decimalArray: { + multiplicity: true, + type: "decimal", + }, + integerArray: { + multiplicity: true, + type: "integer", + }, + longArray: { + multiplicity: true, + type: "long", + }, + shortArray: { + multiplicity: true, + type: "short", + }, + floatArray: { + multiplicity: true, + type: "float", + }, + doubleArray: { + multiplicity: true, + type: "double", + }, + byteArray: { + multiplicity: true, + type: "byte", + }, + attachmentArray: { + multiplicity: true, + type: "attachment", + }, + geoPointArray: { + multiplicity: true, + type: "geopoint", + }, + geoShapeArray: { + multiplicity: true, + type: "geoshape", + }, }, - }, -} satisfies ObjectTypeDefinition< - "ObjectTypeWithAllPropertyTypes" ->; + } satisfies ObjectTypeDefinition< + "ObjectTypeWithAllPropertyTypes" + >; diff --git a/packages/shared.test/src/mock-ontology/ObjectTypeWithReservedNames.ts b/packages/shared.test/src/mock-ontology/ObjectTypeWithReservedNames.ts index 9fbd68197..8ff4a58f1 100644 --- a/packages/shared.test/src/mock-ontology/ObjectTypeWithReservedNames.ts +++ b/packages/shared.test/src/mock-ontology/ObjectTypeWithReservedNames.ts @@ -14,9 +14,26 @@ * limitations under the License. */ -import type { ObjectTypeDefinition } from "@osdk/api"; +import type { ObjectTypeDefinition, ObjectTypeLinkDefinition } from "@osdk/api"; -export const ObjectTypeWithReservedNames = { +export interface ObjectTypeWithReservedNamesDef + extends ObjectTypeDefinition<"ObjectTypeWithReservedNames"> +{ + type: "object"; + apiName: "ObjectTypeWithReservedNames"; + primaryKeyType: "integer"; + links: { + const: ObjectTypeLinkDefinition; + }; + properties: { + catch: { + multiplicity: false; + type: "integer"; + }; + }; +} + +export const ObjectTypeWithReservedNames: ObjectTypeWithReservedNamesDef = { type: "object", apiName: "ObjectTypeWithReservedNames", primaryKeyType: "integer", @@ -32,6 +49,4 @@ export const ObjectTypeWithReservedNames = { type: "integer", }, }, -} satisfies ObjectTypeDefinition< - "ObjectTypeWithReservedNames" ->; +}; diff --git a/packages/shared.test/src/mock-ontology/mockOntology.ts b/packages/shared.test/src/mock-ontology/mockOntology.ts index 37e0e3e00..3577a7ef7 100644 --- a/packages/shared.test/src/mock-ontology/mockOntology.ts +++ b/packages/shared.test/src/mock-ontology/mockOntology.ts @@ -14,10 +14,80 @@ * limitations under the License. */ -import type { OntologyDefinition } from "@osdk/api"; +import type { + ObjectTypeDefinition, + ObjectTypeLinkDefinition, + OntologyDefinition, +} from "@osdk/api"; import { ObjectTypeWithAllPropertyTypes } from "./ObjectTypeWithAllPropertyTypes"; import { ObjectTypeWithReservedNames } from "./ObjectTypeWithReservedNames"; +const Task: TaskDef = { + type: "object", + apiName: "Task", + primaryKeyType: "integer", + properties: { + id: { type: "integer", nullable: true }, + }, + links: { + linkedTodos: { + multiplicity: true, + targetType: "Todo", + }, + }, +}; + +const Todo: TodoDef = { + type: "object", + apiName: "Todo", + primaryKeyType: "string", + description: "A todo object", + properties: { + id: { type: "string", nullable: true, description: "The id" }, + body: { type: "string", nullable: true }, + class: { type: "string", nullable: true }, + complete: { type: "boolean", nullable: true }, + tags: { type: "string", multiplicity: true, nullable: true }, + points: { type: "integer", nullable: true }, + }, + links: { + linkedTask: { + multiplicity: false, + targetType: "Task", + }, + }, +}; + +interface TodoDef extends ObjectTypeDefinition<"Todo"> { + type: "object"; + apiName: "Todo"; + primaryKeyType: "string"; + description: "A todo object"; + properties: { + id: { type: "string"; nullable: true; description: "The id" }; + body: { type: "string"; nullable: true }; + class: { type: "string"; nullable: true }; + complete: { type: "boolean"; nullable: true }; + tags: { type: "string"; multiplicity: true; nullable: true }; + points: { type: "integer"; nullable: true }; + }; + links: { + linkedTask: ObjectTypeLinkDefinition; + }; +} + +interface TaskDef extends ObjectTypeDefinition<"Task"> { + type: "object"; + apiName: "Task"; + primaryKeyType: "integer"; + properties: { + id: { type: "integer"; nullable: true }; + }; + links: { + linkedTodos: ObjectTypeLinkDefinition; + }; +} + export const MockOntology = { metadata: { ontologyRid: "", @@ -25,44 +95,8 @@ export const MockOntology = { userAgent: "typescript-sdk/0.0.0 osdk-cli/0.0.0", }, objects: { - Task: { - type: "object", - apiName: "Task", - primaryKeyType: "integer", - properties: { - id: { type: "integer", nullable: true }, - }, - links: { - linkedTodos: { - multiplicity: true, - targetType: "Todo", - }, - }, - }, - Todo: { - type: "object", - apiName: "Todo", - primaryKeyType: "string", - description: "A todo object", - properties: { - id: { - type: "string", - nullable: true, - description: "The id of the Todo Object", - }, - body: { type: "string", nullable: true }, - class: { type: "string", nullable: true }, - complete: { type: "boolean", nullable: true }, - tags: { type: "string", multiplicity: true, nullable: true }, - points: { type: "integer", nullable: true }, - }, - links: { - linkedTask: { - multiplicity: false, - targetType: "Task", - }, - }, - }, + Task, + Todo, ObjectTypeWithAllPropertyTypes, ObjectTypeWithReservedNames, }, diff --git a/turbo.json b/turbo.json index b4e071c3f..3198c2298 100644 --- a/turbo.json +++ b/turbo.json @@ -77,7 +77,7 @@ "transpile": { "dependsOn": ["mytsup#typecheck", "tsconfig#typecheck", "codegen"], "inputs": ["src/**", "tsup.config.js", "tsconfig.json"], - "outputs": ["dist/**", "lib/**"] + "outputs": ["dist/**", "lib/**", "build/js/**"] }, "test": { From 0f98fe528448739bd2dcc4f7a9d61667ae47840a Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Mon, 12 Feb 2024 17:09:34 -0500 Subject: [PATCH 04/19] Remove unnecessary as const --- .../basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts | 2 +- .../ontology/objects/ObjectTypeWithAllPropertyTypes.ts | 2 +- .../basic/sdk/src/generatedNoCheck/ontology/objects/Person.ts | 2 +- .../basic/sdk/src/generatedNoCheck/ontology/objects/Todo.ts | 2 +- .../sdk/src/generatedNoCheck/ontology/objects/WeatherStation.ts | 2 +- .../ontology/objects/ObjectTypeWithAllPropertyTypes.ts | 2 +- .../one_dot_one/src/generatedNoCheck/ontology/objects/Person.ts | 2 +- .../one_dot_one/src/generatedNoCheck/ontology/objects/Todo.ts | 2 +- examples/todoapp/src/generatedNoCheck/ontology/objects/Todo.ts | 2 +- examples/todoapp/src/generatedNoCheck2/ontology/objects/Todo.ts | 2 +- .../generator/src/shared/wireObjectTypeV2ToSdkObjectConst.ts | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts index 21f9ece83..48532aac1 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Employee.ts @@ -69,7 +69,7 @@ export const Employee: EmployeeDef = { multiplicity: true, targetType: 'Employee', }, - } as const, + }, properties: { adUsername: { multiplicity: false, diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts index 22dfbca1d..caed925be 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts @@ -170,7 +170,7 @@ export const ObjectTypeWithAllPropertyTypes: ObjectTypeWithAllPropertyTypesDef = apiName: 'ObjectTypeWithAllPropertyTypes', description: 'A type with all property types', primaryKeyType: 'integer', - links: {} as const, + links: {}, properties: { id: { multiplicity: false, diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Person.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Person.ts index 6c6d2338b..5914cfff9 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Person.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Person.ts @@ -30,7 +30,7 @@ export const Person: PersonDef = { multiplicity: true, targetType: 'Person', }, - } as const, + }, properties: { email: { multiplicity: false, diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Todo.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Todo.ts index 3e8d407b9..a43e71f61 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Todo.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/Todo.ts @@ -47,7 +47,7 @@ export const Todo: TodoDef = { multiplicity: false, targetType: 'Person', }, - } as const, + }, properties: { id: { multiplicity: false, diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/WeatherStation.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/WeatherStation.ts index 39a954006..c5958dfff 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/objects/WeatherStation.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/objects/WeatherStation.ts @@ -26,7 +26,7 @@ export const WeatherStation: WeatherStationDef = { apiName: 'WeatherStation', description: 'Weather Station', primaryKeyType: 'string', - links: {} as const, + links: {}, properties: { stationId: { multiplicity: false, diff --git a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts index 062a63f8c..163a3cb79 100644 --- a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts +++ b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/ObjectTypeWithAllPropertyTypes.ts @@ -218,7 +218,7 @@ export const ObjectTypeWithAllPropertyTypes: ObjectTypeWithAllPropertyTypesDef = apiName: 'ObjectTypeWithAllPropertyTypes', description: 'A type with all property types', primaryKeyType: 'integer', - links: {} as const, + links: {}, properties: { id: { multiplicity: false, diff --git a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Person.ts b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Person.ts index 18efe80fb..13bdc97e0 100644 --- a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Person.ts +++ b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Person.ts @@ -43,7 +43,7 @@ export const Person: PersonDef = { multiplicity: true, targetType: 'Person', }, - } as const, + }, properties: { email: { multiplicity: false, diff --git a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Todo.ts b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Todo.ts index e14814ab1..e6c96561e 100644 --- a/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Todo.ts +++ b/examples/one_dot_one/src/generatedNoCheck/ontology/objects/Todo.ts @@ -54,7 +54,7 @@ export const Todo: TodoDef = { multiplicity: false, targetType: 'Person', }, - } as const, + }, properties: { id: { multiplicity: false, diff --git a/examples/todoapp/src/generatedNoCheck/ontology/objects/Todo.ts b/examples/todoapp/src/generatedNoCheck/ontology/objects/Todo.ts index 5949d4c9c..1bfe9ad55 100644 --- a/examples/todoapp/src/generatedNoCheck/ontology/objects/Todo.ts +++ b/examples/todoapp/src/generatedNoCheck/ontology/objects/Todo.ts @@ -46,7 +46,7 @@ export const Todo: TodoDef = { apiName: 'Todo', description: 'Its a todo item.', primaryKeyType: 'string', - links: {} as const, + links: {}, properties: { id: { multiplicity: false, diff --git a/examples/todoapp/src/generatedNoCheck2/ontology/objects/Todo.ts b/examples/todoapp/src/generatedNoCheck2/ontology/objects/Todo.ts index eb262371e..b3ae1e1a7 100644 --- a/examples/todoapp/src/generatedNoCheck2/ontology/objects/Todo.ts +++ b/examples/todoapp/src/generatedNoCheck2/ontology/objects/Todo.ts @@ -31,7 +31,7 @@ export const Todo: TodoDef = { apiName: 'Todo', description: 'Its a todo item.', primaryKeyType: 'string', - links: {} as const, + links: {}, properties: { id: { multiplicity: false, diff --git a/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectConst.ts b/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectConst.ts index 0ddae704a..f45288f70 100644 --- a/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectConst.ts +++ b/packages/generator/src/shared/wireObjectTypeV2ToSdkObjectConst.ts @@ -68,7 +68,7 @@ export function wireObjectTypeV2ToSdkObjectConst( : "" } primaryKeyType: ${JSON.stringify(definition.primaryKeyType)}, - links: ${JSON.stringify(definition.links, null, 2)} as const, + links: ${JSON.stringify(definition.links, null, 2)}, properties: ${JSON.stringify(definition.properties, null, 2)}, };`; } From 13a4139f0a0aa17f2182e17643a65f95dfa74075 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Mon, 12 Feb 2024 18:20:20 -0500 Subject: [PATCH 05/19] Fix up types for interfaces --- examples/basic/cli/src/OntologyType.ts | 6 +- examples/basic/cli/src/index.ts | 1 + examples/basic/cli/src/typeChecks.ts | 11 +- packages/api/src/index.ts | 1 + .../api/src/ontology/InterfaceDefinition.ts | 4 + .../api/src/ontology/ObjectOrInterface.ts | 5 +- .../api/src/ontology/ObjectTypeDefinition.ts | 1 + packages/api/src/ontology/index.ts | 1 + packages/client/src/OsdkObjectFrom.ts | 52 +++--- packages/client/src/actions/Actions.ts | 7 +- .../src/definitions/LinkDefinitions.test.ts | 6 +- .../client/src/definitions/LinkDefinitions.ts | 162 ++++++++++-------- packages/client/src/index.ts | 5 +- .../src/object/convertWireToOsdkObjects.ts | 17 +- .../client/src/object/fetchPageOrThrow.ts | 29 +--- .../client/src/object/followLinkOrThrow.ts | 7 +- .../src/object/getLinkedObjectByPkOrThrow.ts | 4 +- .../src/object/getLinkedObjectOrThrow.ts | 8 +- .../src/object/pageLinkedObjectsOrThrow.ts | 32 ++-- packages/client/src/objectSet/ObjectSet.ts | 20 +-- .../client/src/objectSet/ObjectSetListener.ts | 4 +- .../objectSet/ObjectSetListenerWebsocket.ts | 6 +- .../client/src/objectSet/createObjectSet.ts | 7 +- 23 files changed, 197 insertions(+), 199 deletions(-) diff --git a/examples/basic/cli/src/OntologyType.ts b/examples/basic/cli/src/OntologyType.ts index fb9cae701..7a758c27f 100644 --- a/examples/basic/cli/src/OntologyType.ts +++ b/examples/basic/cli/src/OntologyType.ts @@ -18,5 +18,7 @@ import type { OsdkObjectFrom } from "@osdk/client"; import type { Ontology } from "@osdk/examples.basic.sdk"; // Demo for if you want concrete types -export interface Employee extends OsdkObjectFrom<"Employee", Ontology> {} -export interface Todo extends OsdkObjectFrom<"Todo", Ontology> {} +export interface Employee + extends OsdkObjectFrom +{} +export interface Todo extends OsdkObjectFrom {} diff --git a/examples/basic/cli/src/index.ts b/examples/basic/cli/src/index.ts index 26bbb0e6d..ae0af4d2e 100644 --- a/examples/basic/cli/src/index.ts +++ b/examples/basic/cli/src/index.ts @@ -70,6 +70,7 @@ async function runTests() { if (interfaceImplementationComplete) { const interfaceResults = await client.objects.SimpleInterface .fetchPageOrThrow(); + interfaceResults.data[0].body; } diff --git a/examples/basic/cli/src/typeChecks.ts b/examples/basic/cli/src/typeChecks.ts index 640216191..fc313cb39 100644 --- a/examples/basic/cli/src/typeChecks.ts +++ b/examples/basic/cli/src/typeChecks.ts @@ -59,7 +59,9 @@ export async function typeChecks(client: Client) { // lead is an employee const lead = await employee.$link.lead.get(); - expectType>>(true); + expectType< + TypeOf> + >(true); // lead is an employee but we downselect to just their adUsername const leadName = await employee.$link.lead.get({ select: ["adUsername"] }); @@ -76,7 +78,10 @@ export async function typeChecks(client: Client) { TypeOf< typeof peeps, PageResult< - OsdkObjectFrom<"Employee", Ontology, "adUsername" | "employeeNumber"> + OsdkObjectFrom< + Ontology["objects"]["Employee"], + "adUsername" | "employeeNumber" + > > > >(true); @@ -91,7 +96,7 @@ export async function typeChecks(client: Client) { expectType< TypeOf< typeof peepById, - OsdkObjectFrom<"Employee", Ontology, "adUsername"> + OsdkObjectFrom > >( true, diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 7ab5d583a..a958106f1 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -29,6 +29,7 @@ export type { InterfacePropertyDefinitionFrom, InterfacePropertyDefinitionsFrom, InterfacePropertyKeysFrom, + InterfacePropertyKeysFrom2, } from "./ontology/InterfaceDefinition"; export type { ObjectOrInterfaceDefinition, diff --git a/packages/api/src/ontology/InterfaceDefinition.ts b/packages/api/src/ontology/InterfaceDefinition.ts index 5e2d94295..05dfa2a1c 100644 --- a/packages/api/src/ontology/InterfaceDefinition.ts +++ b/packages/api/src/ontology/InterfaceDefinition.ts @@ -30,6 +30,10 @@ export type InterfacePropertyKeysFrom< K extends InterfaceKeysFrom, > = keyof InterfaceDefinitionFrom["properties"] & string; +export type InterfacePropertyKeysFrom2< + I extends InterfaceDefinition, +> = keyof I["properties"] & string; + export type InterfacePropertyDefinitionsFrom< O extends OntologyDefinition, K extends InterfaceKeysFrom, diff --git a/packages/api/src/ontology/ObjectOrInterface.ts b/packages/api/src/ontology/ObjectOrInterface.ts index a83b0ccc0..4b3103174 100644 --- a/packages/api/src/ontology/ObjectOrInterface.ts +++ b/packages/api/src/ontology/ObjectOrInterface.ts @@ -44,9 +44,8 @@ export type ObjectOrInterfacePropertyKeysFrom< : ObjectTypePropertyKeysFrom; export type ObjectOrInterfacePropertyKeysFrom2< - O extends ObjectTypeDefinition, -> = O extends ObjectTypeDefinition ? keyof O["properties"] & string - : never; + O extends ObjectTypeDefinition | InterfaceDefinition, +> = keyof O["properties"] & string; export type ObjectOrInterfaceDefinitionFrom< O extends OntologyDefinition, diff --git a/packages/api/src/ontology/ObjectTypeDefinition.ts b/packages/api/src/ontology/ObjectTypeDefinition.ts index 8e68470d5..40d99f004 100644 --- a/packages/api/src/ontology/ObjectTypeDefinition.ts +++ b/packages/api/src/ontology/ObjectTypeDefinition.ts @@ -68,6 +68,7 @@ export interface ObjectTypeLinkDefinition< O extends ObjectTypeDefinition, M extends boolean, > { + __Mark?: O; targetType: O["apiName"]; multiplicity: M; } diff --git a/packages/api/src/ontology/index.ts b/packages/api/src/ontology/index.ts index d6940ba6d..3c8aa4eb0 100644 --- a/packages/api/src/ontology/index.ts +++ b/packages/api/src/ontology/index.ts @@ -30,6 +30,7 @@ export type { InterfacePropertyDefinitionFrom, InterfacePropertyDefinitionsFrom, InterfacePropertyKeysFrom, + InterfacePropertyKeysFrom2, } from "./InterfaceDefinition"; export type { ObjectOrInterfaceDefinition, diff --git a/packages/client/src/OsdkObjectFrom.ts b/packages/client/src/OsdkObjectFrom.ts index 753dbc86f..8b4b0480f 100644 --- a/packages/client/src/OsdkObjectFrom.ts +++ b/packages/client/src/OsdkObjectFrom.ts @@ -22,15 +22,11 @@ import type { ObjectTypeDefinition, ObjectTypeDefinitionFrom, ObjectTypeKeysFrom, - ObjectTypePropertyKeysFrom, OntologyDefinition, WirePropertyTypes, } from "@osdk/api"; import type { OsdkObjectPropertyType } from "./Definitions.js"; -import type { - OsdkObjectLinksObject, - OsdkObjectLinksObject2, -} from "./definitions/LinkDefinitions.js"; +import type { OsdkObjectLinksObject2 } from "./definitions/LinkDefinitions.js"; export type OsdkObjectPrimaryKeyType< TObjectName, @@ -65,30 +61,30 @@ export type OsdkObjectFrom2< $link: OsdkObjectLinksObject2; }; // TODO -export type OsdkObjectFrom< - T_ObjectTypeKey extends ObjectTypeKeysFrom, - T_Ontology extends OntologyDefinition, - T_PropertyKeys extends ObjectTypePropertyKeysFrom< - T_Ontology, - T_ObjectTypeKey - > = ObjectTypePropertyKeysFrom, -> = - & { - [P in T_PropertyKeys]: OsdkObjectPropertyType< - ObjectTypeDefinitionFrom["properties"][P] - >; - } - & { - __apiName: T_ObjectTypeKey; - __primaryKey: OsdkObjectPrimaryKeyType; - /** - * Future versions will require explicitly asking for this field. For now we are marking - * as always optional to avoid breaking changes. - */ - __rid?: string; +// export type OsdkObjectFrom< +// T_ObjectTypeKey extends ObjectTypeKeysFrom, +// T_Ontology extends OntologyDefinition, +// T_PropertyKeys extends ObjectTypePropertyKeysFrom< +// T_Ontology, +// T_ObjectTypeKey +// > = ObjectTypePropertyKeysFrom, +// > = +// & { +// [P in T_PropertyKeys]: OsdkObjectPropertyType< +// ObjectTypeDefinitionFrom["properties"][P] +// >; +// } +// & { +// __apiName: T_ObjectTypeKey; +// __primaryKey: OsdkObjectPrimaryKeyType; +// /** +// * Future versions will require explicitly asking for this field. For now we are marking +// * as always optional to avoid breaking changes. +// */ +// __rid?: string; - $link: OsdkObjectLinksObject; - }; // TODO +// $link: OsdkObjectLinksObject; +// }; // TODO export type OsdkInterfaceFrom< T_InterfaceKey extends InterfaceKeysFrom, diff --git a/packages/client/src/actions/Actions.ts b/packages/client/src/actions/Actions.ts index 27877edfe..20836d0b4 100644 --- a/packages/client/src/actions/Actions.ts +++ b/packages/client/src/actions/Actions.ts @@ -27,7 +27,7 @@ import type { import type { ObjectSet } from "../index.js"; import type { Attachment } from "../object/Attachment.js"; import type { - OsdkObjectFrom, + OsdkObjectFrom2, OsdkObjectPrimaryKeyType, } from "../OsdkObjectFrom.js"; import type { NOOP } from "../util/NOOP.js"; @@ -72,8 +72,9 @@ type OsdkActionParameterBaseType< K extends ActionKeysFrom, P extends keyof O["actions"][K]["parameters"], > = ActionParameterTypeFrom extends - ObjectActionDataType - ? OsdkObjectFrom | OsdkObjectPrimaryKeyType + ObjectActionDataType ? + | OsdkObjectFrom2 + | OsdkObjectPrimaryKeyType : ActionParameterTypeFrom extends ObjectSetActionDataType ? ObjectSet : ActionParameterTypeFrom extends keyof OverrideWirePropertyTypes diff --git a/packages/client/src/definitions/LinkDefinitions.test.ts b/packages/client/src/definitions/LinkDefinitions.test.ts index b9364886a..b3c9e2ab2 100644 --- a/packages/client/src/definitions/LinkDefinitions.test.ts +++ b/packages/client/src/definitions/LinkDefinitions.test.ts @@ -15,9 +15,9 @@ */ import { describe, expectTypeOf, it } from "vitest"; -import type { ObjectSet2 } from "../objectSet/ObjectSet.js"; import type { MockOntology } from "../util/test/mockOntology.js"; import type { + MultitonLinkAccessor, OsdkObjectLinksObject2, SingletonLinkAccessor, } from "./LinkDefinitions.js"; @@ -38,7 +38,7 @@ describe("LinkDefinitions", () => { type TodoDef = Objects["Todo"]; expectTypeOf["Todos"]>() - .toEqualTypeOf>(); + .toEqualTypeOf>(); expectTypeOf["RP"]>() .toEqualTypeOf>(); @@ -49,7 +49,7 @@ describe("LinkDefinitions", () => { expectTypeOf>() .toEqualTypeOf< { - Todos: ObjectSet2; + Todos: MultitonLinkAccessor; RP: SingletonLinkAccessor; } >(); diff --git a/packages/client/src/definitions/LinkDefinitions.ts b/packages/client/src/definitions/LinkDefinitions.ts index a84eccdad..290c1ce13 100644 --- a/packages/client/src/definitions/LinkDefinitions.ts +++ b/packages/client/src/definitions/LinkDefinitions.ts @@ -15,36 +15,29 @@ */ import type { - ObjectOrInterfacePropertyKeysFrom, ObjectOrInterfacePropertyKeysFrom2, ObjectTypeDefinition, - ObjectTypeKeysFrom, ObjectTypeLinkDefinition, - ObjectTypeLinkDefinitionFrom, - ObjectTypeLinkKeysFrom, ObjectTypeLinkKeysFrom2, - OntologyDefinition, } from "@osdk/api"; import type { - FetchPageOrThrowArgs, - SelectArg, + FetchPageOrThrowArgs2, SelectArg2, } from "../object/fetchPageOrThrow.js"; import type { ObjectSet2 } from "../objectSet/ObjectSet.js"; import type { - OsdkObjectFrom, OsdkObjectFrom2, - OsdkObjectPrimaryKeyType, + OsdkObjectPrimaryKeyType2, } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; /** The $link container to get from one object type to its linked objects */ -export type OsdkObjectLinksObject< - K extends ObjectTypeKeysFrom, - O extends OntologyDefinition, -> = ObjectTypeLinkKeysFrom extends never ? never : { - [L in ObjectTypeLinkKeysFrom]: OsdkObjectLinksEntry; -}; +// export type OsdkObjectLinksObject< +// K extends ObjectTypeKeysFrom, +// O extends OntologyDefinition, +// > = ObjectTypeLinkKeysFrom extends never ? never : { +// [L in ObjectTypeLinkKeysFrom]: OsdkObjectLinksEntry; +// }; export type OsdkObjectLinksObject2< O extends ObjectTypeDefinition, @@ -52,63 +45,63 @@ export type OsdkObjectLinksObject2< [L in ObjectTypeLinkKeysFrom2]: OsdkObjectLinksEntry2; }; -export type OsdkObjectLinksEntry< - K extends ObjectTypeKeysFrom, - O extends OntologyDefinition, - L extends ObjectTypeLinkKeysFrom, - T = ObjectTypeLinkDefinitionFrom["targetType"], -> = ObjectTypeLinkDefinitionFrom extends { multiplicity: false } ? { - /** Load the linked object */ - get: >( - options?: A, - ) => OsdkObjectFrom< - T, - O, - A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom< - O, - T - > - >; - } - : { - /** Loads the linked object for a given primary key */ - get: >( - primaryKey: OsdkObjectPrimaryKeyType< - T, - O - >, - options?: A, - ) => OsdkObjectFrom< - T, - O, - A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom< - O, - T - > - >; +// export type OsdkObjectLinksEntry< +// K extends ObjectTypeKeysFrom, +// O extends OntologyDefinition, +// L extends ObjectTypeLinkKeysFrom, +// T = ObjectTypeLinkDefinitionFrom["targetType"], +// > = ObjectTypeLinkDefinitionFrom extends { multiplicity: false } ? { +// /** Load the linked object */ +// get: >( +// options?: A, +// ) => OsdkObjectFrom< +// T, +// O, +// A["select"] extends readonly string[] ? A["select"][number] +// : ObjectOrInterfacePropertyKeysFrom< +// O, +// T +// > +// >; +// } +// : { +// /** Loads the linked object for a given primary key */ +// get: >( +// primaryKey: OsdkObjectPrimaryKeyType< +// T, +// O +// >, +// options?: A, +// ) => OsdkObjectFrom< +// T, +// O, +// A["select"] extends readonly string[] ? A["select"][number] +// : ObjectOrInterfacePropertyKeysFrom< +// O, +// T +// > +// >; - /** pages through the linked objects */ - fetchPageOrThrow: < - A extends FetchPageOrThrowArgs< - O, - T - >, - >(options?: A) => Promise< - PageResult< - OsdkObjectFrom< - T, - O, - A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom< - O, - T - > - > - > - >; - }; +// /** pages through the linked objects */ +// fetchPageOrThrow: < +// A extends FetchPageOrThrowArgs< +// O, +// T +// >, +// >(options?: A) => Promise< +// PageResult< +// OsdkObjectFrom< +// T, +// O, +// A["select"] extends readonly string[] ? A["select"][number] +// : ObjectOrInterfacePropertyKeysFrom< +// O, +// T +// > +// > +// > +// >; +// }; export type LinkTargetType< O extends ObjectTypeDefinition, @@ -120,7 +113,7 @@ export type OsdkObjectLinksEntry2< L extends ObjectTypeLinkKeysFrom2, > = O["links"][L] extends ObjectTypeLinkDefinition ? ( M extends false ? SingletonLinkAccessor - : ObjectSet2 + : MultitonLinkAccessor ) : never; @@ -134,3 +127,28 @@ export interface SingletonLinkAccessor> { : ObjectOrInterfacePropertyKeysFrom2 >; } + +export interface MultitonLinkAccessor> + extends ObjectSet2 +{ + get: >( + pk: OsdkObjectPrimaryKeyType2, + options?: A, + ) => OsdkObjectFrom2< + T, + A["select"] extends readonly string[] ? A["select"][number] + : ObjectOrInterfacePropertyKeysFrom2 + >; + + fetchPageOrThrow: < + A extends FetchPageOrThrowArgs2, + >(options?: A) => Promise< + PageResult< + OsdkObjectFrom2< + T, + A["select"] extends readonly string[] ? A["select"][number] + : ObjectOrInterfacePropertyKeysFrom2 + > + > + >; +} diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index cc4305000..d699240a2 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -23,7 +23,10 @@ export type { PageResult } from "./PageResult.js"; // FIXME: Should this be Objects or Object? export * as Objects from "./object/index.js"; export type { OsdkObject } from "./OsdkObject.js"; -export type { OsdkInterfaceFrom, OsdkObjectFrom } from "./OsdkObjectFrom.js"; +export type { + OsdkInterfaceFrom, + OsdkObjectFrom2 as OsdkObjectFrom, +} from "./OsdkObjectFrom.js"; export { createClientContext } from "@osdk/shared.net"; export { isOk } from "@osdk/shared.net"; diff --git a/packages/client/src/object/convertWireToOsdkObjects.ts b/packages/client/src/object/convertWireToOsdkObjects.ts index 5f7ad8b5c..fd16c097a 100644 --- a/packages/client/src/object/convertWireToOsdkObjects.ts +++ b/packages/client/src/object/convertWireToOsdkObjects.ts @@ -19,7 +19,7 @@ import type { OntologyObjectV2 } from "@osdk/gateway/types"; import type { ClientContext } from "@osdk/shared.net"; import { createCachedOntologyTransform } from "../createCachedOntologyTransform.js"; import { Attachment } from "./Attachment.js"; -import type { FetchPageOrThrowArgs, SelectArg } from "./fetchPageOrThrow.js"; +import type { FetchPageOrThrowArgs2, SelectArg2 } from "./fetchPageOrThrow.js"; import { getLinkedObjectByPkOrThrow } from "./getLinkedObjectByPkOrThrow.js"; import { getLinkedObjectOrThrow } from "./getLinkedObjectOrThrow.js"; import { pageLinkedObjectsOrThrow } from "./pageLinkedObjectsOrThrow.js"; @@ -58,10 +58,7 @@ function createPrototype< if (!linkDef.multiplicity) { return { get: < - A extends SelectArg< - O, - typeof linkDef.targetType - >, + A extends SelectArg2, >( options?: A, ) => @@ -76,10 +73,7 @@ function createPrototype< } else { return { get: < - A extends SelectArg< - O, - typeof linkDef.targetType - >, + A extends SelectArg2, >(targetPrimaryKey: any, options?: A) => getLinkedObjectByPkOrThrow( client, @@ -90,9 +84,8 @@ function createPrototype< options?.select, ), fetchPageOrThrow: ( - options?: FetchPageOrThrowArgs< - O, - typeof linkDef.targetType + options?: FetchPageOrThrowArgs2< + O["objects"][typeof linkDef.targetType] >, ) => pageLinkedObjectsOrThrow(client, type, primaryKey, p, { diff --git a/packages/client/src/object/fetchPageOrThrow.ts b/packages/client/src/object/fetchPageOrThrow.ts index 6a27d5bc5..c14a0cfa2 100644 --- a/packages/client/src/object/fetchPageOrThrow.ts +++ b/packages/client/src/object/fetchPageOrThrow.ts @@ -15,17 +15,17 @@ */ import type { + ObjectOrInterfaceDefinition, ObjectOrInterfaceKeysFrom, ObjectOrInterfacePropertyKeysFrom, ObjectOrInterfacePropertyKeysFrom2, - ObjectTypeDefinition, OntologyDefinition, } from "@osdk/api"; import { loadObjectSetV2 } from "@osdk/gateway/requests"; import type { LoadObjectSetRequestV2, ObjectSet } from "@osdk/gateway/types"; import { createOpenApiRequest } from "@osdk/shared.net"; import type { ClientContext } from "@osdk/shared.net"; -import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; +import type { OsdkObjectFrom2 } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import { convertWireToOsdkObjects } from "./convertWireToOsdkObjects.js"; @@ -38,23 +38,14 @@ export interface SelectArg< } export interface SelectArg2< - O extends ObjectTypeDefinition, + O extends ObjectOrInterfaceDefinition, L = ObjectOrInterfacePropertyKeysFrom2, > { select?: readonly L[]; } -export interface FetchPageOrThrowArgs< - O extends OntologyDefinition, - K extends ObjectOrInterfaceKeysFrom, - L = ObjectOrInterfacePropertyKeysFrom, -> extends SelectArg { - nextPageToken?: string; - pageSize?: number; -} - export interface FetchPageOrThrowArgs2< - O extends ObjectTypeDefinition, + O extends ObjectOrInterfaceDefinition, L = ObjectOrInterfacePropertyKeysFrom2, > extends SelectArg2 { nextPageToken?: string; @@ -64,10 +55,7 @@ export interface FetchPageOrThrowArgs2< export async function fetchPageOrThrow< O extends OntologyDefinition, T extends ObjectOrInterfaceKeysFrom, - const A extends FetchPageOrThrowArgs< - O, - T - >, + const A extends FetchPageOrThrowArgs2, >( client: ClientContext, objectType: T & string, @@ -78,11 +66,10 @@ export async function fetchPageOrThrow< }, ): Promise< PageResult< - OsdkObjectFrom< - T, - O, + OsdkObjectFrom2< + O["objects"][T], A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom + : ObjectOrInterfacePropertyKeysFrom2 > > > { diff --git a/packages/client/src/object/followLinkOrThrow.ts b/packages/client/src/object/followLinkOrThrow.ts index c6fc6b80f..e96f18149 100644 --- a/packages/client/src/object/followLinkOrThrow.ts +++ b/packages/client/src/object/followLinkOrThrow.ts @@ -22,19 +22,20 @@ import { } from "@osdk/api"; import { listLinkedObjectsV2 } from "@osdk/gateway/requests"; import { type ClientContext, createOpenApiRequest } from "@osdk/shared.net"; -import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; +import type { OsdkObjectFrom2 } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import { convertWireToOsdkObjects } from "./convertWireToOsdkObjects.js"; + export async function followLinkOrThrow< O extends OntologyDefinition, K extends ObjectTypeKeysFrom, L extends ObjectTypeLinkKeysFrom, >( clientCtx: ClientContext, - sourceObject: OsdkObjectFrom, + sourceObject: OsdkObjectFrom2, link: L, ): Promise< - PageResult, O>> + PageResult>> > { const r = await listLinkedObjectsV2( createOpenApiRequest(clientCtx.stack, clientCtx.fetch), diff --git a/packages/client/src/object/getLinkedObjectByPkOrThrow.ts b/packages/client/src/object/getLinkedObjectByPkOrThrow.ts index dd5e892e9..dfeeb70b7 100644 --- a/packages/client/src/object/getLinkedObjectByPkOrThrow.ts +++ b/packages/client/src/object/getLinkedObjectByPkOrThrow.ts @@ -24,7 +24,7 @@ import type { import { getLinkedObjectV2 } from "@osdk/gateway/requests"; import type { ClientContext } from "@osdk/shared.net"; import { createOpenApiRequest } from "@osdk/shared.net"; -import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; +import type { OsdkObjectFrom2 } from "../OsdkObjectFrom.js"; import { convertWireToOsdkObjects } from "./convertWireToOsdkObjects.js"; export async function getLinkedObjectByPkOrThrow< @@ -56,5 +56,5 @@ export async function getLinkedObjectByPkOrThrow< const objects = [object]; convertWireToOsdkObjects(client, objects); - return objects[0] as OsdkObjectFrom; + return objects[0] as OsdkObjectFrom2; } diff --git a/packages/client/src/object/getLinkedObjectOrThrow.ts b/packages/client/src/object/getLinkedObjectOrThrow.ts index 33e9f63f1..0a42858d5 100644 --- a/packages/client/src/object/getLinkedObjectOrThrow.ts +++ b/packages/client/src/object/getLinkedObjectOrThrow.ts @@ -16,18 +16,18 @@ import type { ObjectTypeKeysFrom, - ObjectTypeLinkKeysFrom, + ObjectTypeLinkKeysFrom2, OntologyDefinition, } from "@osdk/api"; import { type ClientContext, PalantirApiError } from "@osdk/shared.net"; -import type { SelectArg } from "./fetchPageOrThrow.js"; +import type { SelectArg2 } from "./fetchPageOrThrow.js"; import { pageLinkedObjectsOrThrow } from "./pageLinkedObjectsOrThrow.js"; export async function getLinkedObjectOrThrow< O extends OntologyDefinition, T extends ObjectTypeKeysFrom & string, - L extends ObjectTypeLinkKeysFrom & string, - S extends SelectArg["select"], + L extends ObjectTypeLinkKeysFrom2 & string, + S extends SelectArg2["select"], >( client: ClientContext, sourceApiName: T, diff --git a/packages/client/src/object/pageLinkedObjectsOrThrow.ts b/packages/client/src/object/pageLinkedObjectsOrThrow.ts index cf9952895..675d1412d 100644 --- a/packages/client/src/object/pageLinkedObjectsOrThrow.ts +++ b/packages/client/src/object/pageLinkedObjectsOrThrow.ts @@ -15,42 +15,36 @@ */ import type { - ObjectOrInterfacePropertyKeysFrom, + ObjectOrInterfacePropertyKeysFrom2, ObjectTypeKeysFrom, - ObjectTypeLinkKeysFrom, - ObjectTypeLinkTargetTypeFrom, + ObjectTypeLinkKeysFrom2, OntologyDefinition, } from "@osdk/api"; import { listLinkedObjectsV2 } from "@osdk/gateway/requests"; import { type ClientContext, createOpenApiRequest } from "@osdk/shared.net"; -import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; +import type { OsdkObjectFrom2 } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import { convertWireToOsdkObjects } from "./convertWireToOsdkObjects.js"; +import type { FetchPageOrThrowArgs2 } from "./fetchPageOrThrow.js"; export async function pageLinkedObjectsOrThrow< O extends OntologyDefinition, T extends ObjectTypeKeysFrom, - L extends ObjectTypeLinkKeysFrom, - S = ReadonlyArray< - ObjectOrInterfacePropertyKeysFrom> - >, + L extends ObjectTypeLinkKeysFrom2, + Q extends O["objects"][T]["links"][L]["__Mark"], + const A extends FetchPageOrThrowArgs2, >( client: ClientContext, sourceApiName: T & string, primaryKey: any, linkTypeApiName: string, - options?: { - nextPageToken?: string; - pageSize?: number; - select?: S; - }, + options: A, ): Promise< PageResult< - OsdkObjectFrom< - T, - O, - S extends readonly string[] ? S[number] - : ObjectOrInterfacePropertyKeysFrom + OsdkObjectFrom2< + Q, + A["select"] extends readonly string[] ? A["select"][number] + : ObjectOrInterfacePropertyKeysFrom2 > > > { @@ -74,6 +68,6 @@ export async function pageLinkedObjectsOrThrow< return { nextPageToken: page.nextPageToken, - data: page.data as OsdkObjectFrom[], + data: page.data as OsdkObjectFrom2[], }; } diff --git a/packages/client/src/objectSet/ObjectSet.ts b/packages/client/src/objectSet/ObjectSet.ts index 9bee5547b..5bf074c18 100644 --- a/packages/client/src/objectSet/ObjectSet.ts +++ b/packages/client/src/objectSet/ObjectSet.ts @@ -18,21 +18,13 @@ import type { InterfaceKeysFrom, ObjectOrInterfaceDefinitionFrom, ObjectOrInterfaceKeysFrom, - ObjectOrInterfacePropertyKeysFrom, ObjectOrInterfacePropertyKeysFrom2, ObjectTypeDefinition, OntologyDefinition, } from "@osdk/api"; import type { ObjectSet as WireObjectSet } from "@osdk/gateway/types"; -import type { - FetchPageOrThrowArgs, - FetchPageOrThrowArgs2, -} from "../object/fetchPageOrThrow.js"; -import type { - OsdkInterfaceFrom, - OsdkObjectFrom, - OsdkObjectFrom2, -} from "../OsdkObjectFrom.js"; +import type { FetchPageOrThrowArgs2 } from "../object/fetchPageOrThrow.js"; +import type { OsdkInterfaceFrom, OsdkObjectFrom2 } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import type { AggregateOpts } from "../query/aggregations/AggregateOpts.js"; import type { AggregationsResults, WhereClause } from "../query/index.js"; @@ -61,17 +53,19 @@ export type ObjectSet< export interface BaseObjectSet< O extends OntologyDefinition, K extends ObjectOrInterfaceKeysFrom, + Q extends ObjectOrInterfaceDefinitionFrom = + ObjectOrInterfaceDefinitionFrom, > { definition: WireObjectSet; fetchPageOrThrow: < - L extends ObjectOrInterfacePropertyKeysFrom, + L extends ObjectOrInterfacePropertyKeysFrom2, >( - args?: FetchPageOrThrowArgs, + args?: FetchPageOrThrowArgs2, ) => Promise< PageResult< K extends InterfaceKeysFrom ? OsdkInterfaceFrom - : OsdkObjectFrom + : OsdkObjectFrom2 > >; diff --git a/packages/client/src/objectSet/ObjectSetListener.ts b/packages/client/src/objectSet/ObjectSetListener.ts index 45a891260..29b9a7fda 100644 --- a/packages/client/src/objectSet/ObjectSetListener.ts +++ b/packages/client/src/objectSet/ObjectSetListener.ts @@ -15,7 +15,7 @@ */ import type { ObjectTypeKeysFrom, OntologyDefinition } from "@osdk/api"; -import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; +import type { OsdkObjectFrom2 } from "../OsdkObjectFrom.js"; export type ObjectSetListener< O extends OntologyDefinition, @@ -25,7 +25,7 @@ export type ObjectSetListener< /** * Specific objects have changed and can be immediately updated */ - onChange: (objects: Array>) => void; + onChange: (objects: Array>) => void; /** * The ObjectSet has become outdated and should be re-fetched in its entirety. diff --git a/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts b/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts index 8f95eb80e..1a413957c 100644 --- a/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts +++ b/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts @@ -42,7 +42,7 @@ import { loadOntologyEntities, } from "../generated/ontology-metadata/api/OntologyMetadataService.js"; import { convertWireToOsdkObjects } from "../object/convertWireToOsdkObjects.js"; -import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; +import type { OsdkObjectFrom2 } from "../OsdkObjectFrom.js"; import type { ObjectSetListener } from "./ObjectSetListener.js"; import { getObjectSetBaseType, @@ -437,7 +437,7 @@ async function convertFoundryToOsdkObjects< client: ClientContext, ctx: ConjureContext, objects: ReadonlyArray, -): Promise>> { +): Promise>> { const osdkObjects: OntologyObjectV2[] = await Promise.all( objects.map(async object => { const propertyMapping = await getOntologyPropertyMappingForRid( @@ -465,7 +465,7 @@ async function convertFoundryToOsdkObjects< convertWireToOsdkObjects(client, osdkObjects); - return osdkObjects as OsdkObjectFrom[]; + return osdkObjects as OsdkObjectFrom2[]; } export type ObjectPropertyMapping = { diff --git a/packages/client/src/objectSet/createObjectSet.ts b/packages/client/src/objectSet/createObjectSet.ts index 28b178223..1f72cb9e1 100644 --- a/packages/client/src/objectSet/createObjectSet.ts +++ b/packages/client/src/objectSet/createObjectSet.ts @@ -18,7 +18,7 @@ import type { ObjectOrInterfaceKeysFrom, OntologyDefinition } from "@osdk/api"; import type { ObjectSet as WireObjectSet } from "@osdk/gateway/types"; import type { ClientContext } from "@osdk/shared.net"; import { modernToLegacyWhereClause } from "../internal/conversions/index.js"; -import type { FetchPageOrThrowArgs } from "../object/fetchPageOrThrow.js"; +import type { FetchPageOrThrowArgs2 } from "../object/fetchPageOrThrow.js"; import { aggregateOrThrow, fetchPageOrThrow } from "../object/index.js"; import type { AggregateOpts } from "../query/aggregations/AggregateOpts.js"; import type { AggregationClause, AggregationsResults } from "../query/index.js"; @@ -63,10 +63,7 @@ export function createObjectSet< // throw "TODO"; // }, fetchPageOrThrow: async ( - args?: FetchPageOrThrowArgs< - O, - K - >, + args?: FetchPageOrThrowArgs2, ) => { return fetchPageOrThrow( clientCtx, From e5d6065a1109e22a902710a0baa9446c08f09c61 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Mon, 12 Feb 2024 18:34:03 -0500 Subject: [PATCH 06/19] Kill some 2s --- packages/client/src/Client.test.ts | 6 +- packages/client/src/OsdkObjectFrom.ts | 62 ++-------- packages/client/src/actions/Actions.ts | 6 +- .../src/definitions/LinkDefinitions.test.ts | 12 +- .../client/src/definitions/LinkDefinitions.ts | 111 ++++-------------- packages/client/src/index.ts | 5 +- .../client/src/object/fetchPageOrThrow.ts | 4 +- .../client/src/object/followLinkOrThrow.ts | 6 +- .../src/object/getLinkedObjectByPkOrThrow.ts | 4 +- .../src/object/pageLinkedObjectsOrThrow.ts | 6 +- packages/client/src/objectSet/ObjectSet.ts | 12 +- .../client/src/objectSet/ObjectSetListener.ts | 4 +- .../objectSet/ObjectSetListenerWebsocket.ts | 6 +- 13 files changed, 68 insertions(+), 176 deletions(-) diff --git a/packages/client/src/Client.test.ts b/packages/client/src/Client.test.ts index 10fb1aa8c..a1e7fcd2c 100644 --- a/packages/client/src/Client.test.ts +++ b/packages/client/src/Client.test.ts @@ -20,7 +20,7 @@ import type { Office } from "./generatedNoCheck/ontology/objects.js"; import { Employee } from "./generatedNoCheck/ontology/objects.js"; import type { Client } from "./index.js"; import type { ObjectSet2 } from "./objectSet/ObjectSet.js"; -import type { OsdkObjectFrom2 } from "./OsdkObjectFrom.js"; +import type { OsdkObjectFrom } from "./OsdkObjectFrom.js"; describe("client", () => { it("can be called with an object definition", async () => { @@ -32,14 +32,14 @@ describe("client", () => { const result = await objSet.fetchPageOrThrow(); expectTypeOf().toEqualTypeOf< - OsdkObjectFrom2< + OsdkObjectFrom< typeof Employee > >(); const office = await result.data[0].$link.officeLink.get(); expectTypeOf().toEqualTypeOf< - OsdkObjectFrom2 + OsdkObjectFrom >(); }); }); diff --git a/packages/client/src/OsdkObjectFrom.ts b/packages/client/src/OsdkObjectFrom.ts index 8b4b0480f..c900c2d42 100644 --- a/packages/client/src/OsdkObjectFrom.ts +++ b/packages/client/src/OsdkObjectFrom.ts @@ -15,32 +15,20 @@ */ import type { - InterfaceKeysFrom, - InterfacePropertyDefinitionFrom, - InterfacePropertyKeysFrom, + InterfaceDefinition, + InterfacePropertyKeysFrom2, ObjectOrInterfacePropertyKeysFrom2, ObjectTypeDefinition, - ObjectTypeDefinitionFrom, - ObjectTypeKeysFrom, - OntologyDefinition, WirePropertyTypes, } from "@osdk/api"; import type { OsdkObjectPropertyType } from "./Definitions.js"; -import type { OsdkObjectLinksObject2 } from "./definitions/LinkDefinitions.js"; +import type { OsdkObjectLinksObject } from "./definitions/LinkDefinitions.js"; export type OsdkObjectPrimaryKeyType< - TObjectName, - O extends OntologyDefinition, -> = TObjectName extends ObjectTypeKeysFrom ? WirePropertyTypes[ - ObjectTypeDefinitionFrom["primaryKeyType"] - ] - : never; - -export type OsdkObjectPrimaryKeyType2< O extends ObjectTypeDefinition, > = WirePropertyTypes[O["primaryKeyType"]]; -export type OsdkObjectFrom2< +export type OsdkObjectFrom< O extends ObjectTypeDefinition, L extends ObjectOrInterfacePropertyKeysFrom2 = ObjectOrInterfacePropertyKeysFrom2, @@ -52,55 +40,27 @@ export type OsdkObjectFrom2< } & { __apiName: O["apiName"]; - __primaryKey: OsdkObjectPrimaryKeyType2; + __primaryKey: OsdkObjectPrimaryKeyType; /** * Future versions will require explicitly asking for this field. For now we are marking * as always optional to avoid breaking changes. */ __rid?: string; - $link: OsdkObjectLinksObject2; + $link: OsdkObjectLinksObject; }; // TODO -// export type OsdkObjectFrom< -// T_ObjectTypeKey extends ObjectTypeKeysFrom, -// T_Ontology extends OntologyDefinition, -// T_PropertyKeys extends ObjectTypePropertyKeysFrom< -// T_Ontology, -// T_ObjectTypeKey -// > = ObjectTypePropertyKeysFrom, -// > = -// & { -// [P in T_PropertyKeys]: OsdkObjectPropertyType< -// ObjectTypeDefinitionFrom["properties"][P] -// >; -// } -// & { -// __apiName: T_ObjectTypeKey; -// __primaryKey: OsdkObjectPrimaryKeyType; -// /** -// * Future versions will require explicitly asking for this field. For now we are marking -// * as always optional to avoid breaking changes. -// */ -// __rid?: string; - -// $link: OsdkObjectLinksObject; -// }; // TODO - export type OsdkInterfaceFrom< - T_InterfaceKey extends InterfaceKeysFrom, - T_Ontology extends OntologyDefinition, - T_PropertyKeys extends InterfacePropertyKeysFrom< - T_Ontology, - T_InterfaceKey - > = InterfacePropertyKeysFrom, + Q extends InterfaceDefinition, + T_PropertyKeys extends InterfacePropertyKeysFrom2 = + InterfacePropertyKeysFrom2, > = & { [P in T_PropertyKeys]: OsdkObjectPropertyType< - InterfacePropertyDefinitionFrom + Q["properties"][P] >; } & { - __apiName: T_InterfaceKey; + __apiName: Q["apiName"]; __primaryKey: unknown; // $uniqueId: string; // will be dynamic /** diff --git a/packages/client/src/actions/Actions.ts b/packages/client/src/actions/Actions.ts index 20836d0b4..cd2f2dc13 100644 --- a/packages/client/src/actions/Actions.ts +++ b/packages/client/src/actions/Actions.ts @@ -27,7 +27,7 @@ import type { import type { ObjectSet } from "../index.js"; import type { Attachment } from "../object/Attachment.js"; import type { - OsdkObjectFrom2, + OsdkObjectFrom, OsdkObjectPrimaryKeyType, } from "../OsdkObjectFrom.js"; import type { NOOP } from "../util/NOOP.js"; @@ -73,8 +73,8 @@ type OsdkActionParameterBaseType< P extends keyof O["actions"][K]["parameters"], > = ActionParameterTypeFrom extends ObjectActionDataType ? - | OsdkObjectFrom2 - | OsdkObjectPrimaryKeyType + | OsdkObjectFrom + | OsdkObjectPrimaryKeyType : ActionParameterTypeFrom extends ObjectSetActionDataType ? ObjectSet : ActionParameterTypeFrom extends keyof OverrideWirePropertyTypes diff --git a/packages/client/src/definitions/LinkDefinitions.test.ts b/packages/client/src/definitions/LinkDefinitions.test.ts index b3c9e2ab2..34b3fda68 100644 --- a/packages/client/src/definitions/LinkDefinitions.test.ts +++ b/packages/client/src/definitions/LinkDefinitions.test.ts @@ -18,7 +18,7 @@ import { describe, expectTypeOf, it } from "vitest"; import type { MockOntology } from "../util/test/mockOntology.js"; import type { MultitonLinkAccessor, - OsdkObjectLinksObject2, + OsdkObjectLinksObject, SingletonLinkAccessor, } from "./LinkDefinitions.js"; @@ -26,7 +26,7 @@ describe("LinkDefinitions", () => { describe("OsdkObjectLinkObject", () => { it("is correctly absent on types with no links", () => { expectTypeOf< - OsdkObjectLinksObject2 + OsdkObjectLinksObject >() .toEqualTypeOf(); }); @@ -37,16 +37,16 @@ describe("LinkDefinitions", () => { type PersonDef = Objects["Person"]; type TodoDef = Objects["Todo"]; - expectTypeOf["Todos"]>() + expectTypeOf["Todos"]>() .toEqualTypeOf>(); - expectTypeOf["RP"]>() + expectTypeOf["RP"]>() .toEqualTypeOf>(); - const q: OsdkObjectLinksObject2 = {} as any; + const q: OsdkObjectLinksObject = {} as any; q.Todos.definition; - expectTypeOf>() + expectTypeOf>() .toEqualTypeOf< { Todos: MultitonLinkAccessor; diff --git a/packages/client/src/definitions/LinkDefinitions.ts b/packages/client/src/definitions/LinkDefinitions.ts index 290c1ce13..d952e54c4 100644 --- a/packages/client/src/definitions/LinkDefinitions.ts +++ b/packages/client/src/definitions/LinkDefinitions.ts @@ -26,102 +26,21 @@ import type { } from "../object/fetchPageOrThrow.js"; import type { ObjectSet2 } from "../objectSet/ObjectSet.js"; import type { - OsdkObjectFrom2, - OsdkObjectPrimaryKeyType2, + OsdkObjectFrom, + OsdkObjectPrimaryKeyType, } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; /** The $link container to get from one object type to its linked objects */ -// export type OsdkObjectLinksObject< -// K extends ObjectTypeKeysFrom, -// O extends OntologyDefinition, -// > = ObjectTypeLinkKeysFrom extends never ? never : { -// [L in ObjectTypeLinkKeysFrom]: OsdkObjectLinksEntry; -// }; - -export type OsdkObjectLinksObject2< +export type OsdkObjectLinksObject< O extends ObjectTypeDefinition, > = ObjectTypeLinkKeysFrom2 extends never ? never : { [L in ObjectTypeLinkKeysFrom2]: OsdkObjectLinksEntry2; }; -// export type OsdkObjectLinksEntry< -// K extends ObjectTypeKeysFrom, -// O extends OntologyDefinition, -// L extends ObjectTypeLinkKeysFrom, -// T = ObjectTypeLinkDefinitionFrom["targetType"], -// > = ObjectTypeLinkDefinitionFrom extends { multiplicity: false } ? { -// /** Load the linked object */ -// get: >( -// options?: A, -// ) => OsdkObjectFrom< -// T, -// O, -// A["select"] extends readonly string[] ? A["select"][number] -// : ObjectOrInterfacePropertyKeysFrom< -// O, -// T -// > -// >; -// } -// : { -// /** Loads the linked object for a given primary key */ -// get: >( -// primaryKey: OsdkObjectPrimaryKeyType< -// T, -// O -// >, -// options?: A, -// ) => OsdkObjectFrom< -// T, -// O, -// A["select"] extends readonly string[] ? A["select"][number] -// : ObjectOrInterfacePropertyKeysFrom< -// O, -// T -// > -// >; - -// /** pages through the linked objects */ -// fetchPageOrThrow: < -// A extends FetchPageOrThrowArgs< -// O, -// T -// >, -// >(options?: A) => Promise< -// PageResult< -// OsdkObjectFrom< -// T, -// O, -// A["select"] extends readonly string[] ? A["select"][number] -// : ObjectOrInterfacePropertyKeysFrom< -// O, -// T -// > -// > -// > -// >; -// }; - -export type LinkTargetType< - O extends ObjectTypeDefinition, - L extends ObjectTypeLinkKeysFrom2, -> = O["links"][L]["targetType"]; - -export type OsdkObjectLinksEntry2< - O extends ObjectTypeDefinition, - L extends ObjectTypeLinkKeysFrom2, -> = O["links"][L] extends ObjectTypeLinkDefinition ? ( - M extends false ? SingletonLinkAccessor - : MultitonLinkAccessor - ) - : never; - -// export type Q - export interface SingletonLinkAccessor> { /** Load the linked object */ - get: >(options?: A) => OsdkObjectFrom2< + get: >(options?: A) => OsdkObjectFrom< T, A["select"] extends readonly string[] ? A["select"][number] : ObjectOrInterfacePropertyKeysFrom2 @@ -132,9 +51,9 @@ export interface MultitonLinkAccessor> extends ObjectSet2 { get: >( - pk: OsdkObjectPrimaryKeyType2, + pk: OsdkObjectPrimaryKeyType, options?: A, - ) => OsdkObjectFrom2< + ) => OsdkObjectFrom< T, A["select"] extends readonly string[] ? A["select"][number] : ObjectOrInterfacePropertyKeysFrom2 @@ -144,7 +63,7 @@ export interface MultitonLinkAccessor> A extends FetchPageOrThrowArgs2, >(options?: A) => Promise< PageResult< - OsdkObjectFrom2< + OsdkObjectFrom< T, A["select"] extends readonly string[] ? A["select"][number] : ObjectOrInterfacePropertyKeysFrom2 @@ -152,3 +71,19 @@ export interface MultitonLinkAccessor> > >; } + +export type LinkTargetType< + O extends ObjectTypeDefinition, + L extends ObjectTypeLinkKeysFrom2, +> = O["links"][L]["targetType"]; + +export type OsdkObjectLinksEntry2< + O extends ObjectTypeDefinition, + L extends ObjectTypeLinkKeysFrom2, +> = O["links"][L] extends ObjectTypeLinkDefinition ? ( + M extends false ? SingletonLinkAccessor + : MultitonLinkAccessor + ) + : never; + +// export type Q diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index d699240a2..cc4305000 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -23,10 +23,7 @@ export type { PageResult } from "./PageResult.js"; // FIXME: Should this be Objects or Object? export * as Objects from "./object/index.js"; export type { OsdkObject } from "./OsdkObject.js"; -export type { - OsdkInterfaceFrom, - OsdkObjectFrom2 as OsdkObjectFrom, -} from "./OsdkObjectFrom.js"; +export type { OsdkInterfaceFrom, OsdkObjectFrom } from "./OsdkObjectFrom.js"; export { createClientContext } from "@osdk/shared.net"; export { isOk } from "@osdk/shared.net"; diff --git a/packages/client/src/object/fetchPageOrThrow.ts b/packages/client/src/object/fetchPageOrThrow.ts index c14a0cfa2..27a397782 100644 --- a/packages/client/src/object/fetchPageOrThrow.ts +++ b/packages/client/src/object/fetchPageOrThrow.ts @@ -25,7 +25,7 @@ import { loadObjectSetV2 } from "@osdk/gateway/requests"; import type { LoadObjectSetRequestV2, ObjectSet } from "@osdk/gateway/types"; import { createOpenApiRequest } from "@osdk/shared.net"; import type { ClientContext } from "@osdk/shared.net"; -import type { OsdkObjectFrom2 } from "../OsdkObjectFrom.js"; +import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import { convertWireToOsdkObjects } from "./convertWireToOsdkObjects.js"; @@ -66,7 +66,7 @@ export async function fetchPageOrThrow< }, ): Promise< PageResult< - OsdkObjectFrom2< + OsdkObjectFrom< O["objects"][T], A["select"] extends readonly string[] ? A["select"][number] : ObjectOrInterfacePropertyKeysFrom2 diff --git a/packages/client/src/object/followLinkOrThrow.ts b/packages/client/src/object/followLinkOrThrow.ts index e96f18149..cbea1941f 100644 --- a/packages/client/src/object/followLinkOrThrow.ts +++ b/packages/client/src/object/followLinkOrThrow.ts @@ -22,7 +22,7 @@ import { } from "@osdk/api"; import { listLinkedObjectsV2 } from "@osdk/gateway/requests"; import { type ClientContext, createOpenApiRequest } from "@osdk/shared.net"; -import type { OsdkObjectFrom2 } from "../OsdkObjectFrom.js"; +import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import { convertWireToOsdkObjects } from "./convertWireToOsdkObjects.js"; @@ -32,10 +32,10 @@ export async function followLinkOrThrow< L extends ObjectTypeLinkKeysFrom, >( clientCtx: ClientContext, - sourceObject: OsdkObjectFrom2, + sourceObject: OsdkObjectFrom, link: L, ): Promise< - PageResult>> + PageResult>> > { const r = await listLinkedObjectsV2( createOpenApiRequest(clientCtx.stack, clientCtx.fetch), diff --git a/packages/client/src/object/getLinkedObjectByPkOrThrow.ts b/packages/client/src/object/getLinkedObjectByPkOrThrow.ts index dfeeb70b7..e42b509a0 100644 --- a/packages/client/src/object/getLinkedObjectByPkOrThrow.ts +++ b/packages/client/src/object/getLinkedObjectByPkOrThrow.ts @@ -24,7 +24,7 @@ import type { import { getLinkedObjectV2 } from "@osdk/gateway/requests"; import type { ClientContext } from "@osdk/shared.net"; import { createOpenApiRequest } from "@osdk/shared.net"; -import type { OsdkObjectFrom2 } from "../OsdkObjectFrom.js"; +import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; import { convertWireToOsdkObjects } from "./convertWireToOsdkObjects.js"; export async function getLinkedObjectByPkOrThrow< @@ -56,5 +56,5 @@ export async function getLinkedObjectByPkOrThrow< const objects = [object]; convertWireToOsdkObjects(client, objects); - return objects[0] as OsdkObjectFrom2; + return objects[0] as OsdkObjectFrom; } diff --git a/packages/client/src/object/pageLinkedObjectsOrThrow.ts b/packages/client/src/object/pageLinkedObjectsOrThrow.ts index 675d1412d..23e215092 100644 --- a/packages/client/src/object/pageLinkedObjectsOrThrow.ts +++ b/packages/client/src/object/pageLinkedObjectsOrThrow.ts @@ -22,7 +22,7 @@ import type { } from "@osdk/api"; import { listLinkedObjectsV2 } from "@osdk/gateway/requests"; import { type ClientContext, createOpenApiRequest } from "@osdk/shared.net"; -import type { OsdkObjectFrom2 } from "../OsdkObjectFrom.js"; +import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import { convertWireToOsdkObjects } from "./convertWireToOsdkObjects.js"; import type { FetchPageOrThrowArgs2 } from "./fetchPageOrThrow.js"; @@ -41,7 +41,7 @@ export async function pageLinkedObjectsOrThrow< options: A, ): Promise< PageResult< - OsdkObjectFrom2< + OsdkObjectFrom< Q, A["select"] extends readonly string[] ? A["select"][number] : ObjectOrInterfacePropertyKeysFrom2 @@ -68,6 +68,6 @@ export async function pageLinkedObjectsOrThrow< return { nextPageToken: page.nextPageToken, - data: page.data as OsdkObjectFrom2[], + data: page.data as OsdkObjectFrom[], }; } diff --git a/packages/client/src/objectSet/ObjectSet.ts b/packages/client/src/objectSet/ObjectSet.ts index 5bf074c18..9e1339509 100644 --- a/packages/client/src/objectSet/ObjectSet.ts +++ b/packages/client/src/objectSet/ObjectSet.ts @@ -15,7 +15,7 @@ */ import type { - InterfaceKeysFrom, + InterfaceDefinition, ObjectOrInterfaceDefinitionFrom, ObjectOrInterfaceKeysFrom, ObjectOrInterfacePropertyKeysFrom2, @@ -24,7 +24,7 @@ import type { } from "@osdk/api"; import type { ObjectSet as WireObjectSet } from "@osdk/gateway/types"; import type { FetchPageOrThrowArgs2 } from "../object/fetchPageOrThrow.js"; -import type { OsdkInterfaceFrom, OsdkObjectFrom2 } from "../OsdkObjectFrom.js"; +import type { OsdkInterfaceFrom, OsdkObjectFrom } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import type { AggregateOpts } from "../query/aggregations/AggregateOpts.js"; import type { AggregationsResults, WhereClause } from "../query/index.js"; @@ -40,7 +40,7 @@ export interface ObjectSet2> { args?: FetchPageOrThrowArgs2, ) => Promise< PageResult< - OsdkObjectFrom2 + OsdkObjectFrom > >; } @@ -61,11 +61,11 @@ export interface BaseObjectSet< fetchPageOrThrow: < L extends ObjectOrInterfacePropertyKeysFrom2, >( - args?: FetchPageOrThrowArgs2, + args?: FetchPageOrThrowArgs2, ) => Promise< PageResult< - K extends InterfaceKeysFrom ? OsdkInterfaceFrom - : OsdkObjectFrom2 + Q extends InterfaceDefinition ? OsdkInterfaceFrom + : OsdkObjectFrom > >; diff --git a/packages/client/src/objectSet/ObjectSetListener.ts b/packages/client/src/objectSet/ObjectSetListener.ts index 29b9a7fda..386dc944a 100644 --- a/packages/client/src/objectSet/ObjectSetListener.ts +++ b/packages/client/src/objectSet/ObjectSetListener.ts @@ -15,7 +15,7 @@ */ import type { ObjectTypeKeysFrom, OntologyDefinition } from "@osdk/api"; -import type { OsdkObjectFrom2 } from "../OsdkObjectFrom.js"; +import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; export type ObjectSetListener< O extends OntologyDefinition, @@ -25,7 +25,7 @@ export type ObjectSetListener< /** * Specific objects have changed and can be immediately updated */ - onChange: (objects: Array>) => void; + onChange: (objects: Array>) => void; /** * The ObjectSet has become outdated and should be re-fetched in its entirety. diff --git a/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts b/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts index 1a413957c..6890fd709 100644 --- a/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts +++ b/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts @@ -42,7 +42,7 @@ import { loadOntologyEntities, } from "../generated/ontology-metadata/api/OntologyMetadataService.js"; import { convertWireToOsdkObjects } from "../object/convertWireToOsdkObjects.js"; -import type { OsdkObjectFrom2 } from "../OsdkObjectFrom.js"; +import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; import type { ObjectSetListener } from "./ObjectSetListener.js"; import { getObjectSetBaseType, @@ -437,7 +437,7 @@ async function convertFoundryToOsdkObjects< client: ClientContext, ctx: ConjureContext, objects: ReadonlyArray, -): Promise>> { +): Promise>> { const osdkObjects: OntologyObjectV2[] = await Promise.all( objects.map(async object => { const propertyMapping = await getOntologyPropertyMappingForRid( @@ -465,7 +465,7 @@ async function convertFoundryToOsdkObjects< convertWireToOsdkObjects(client, osdkObjects); - return osdkObjects as OsdkObjectFrom2[]; + return osdkObjects as OsdkObjectFrom[]; } export type ObjectPropertyMapping = { From 2dc5c8e8774b14875457daf53bdfc81000154e68 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Mon, 12 Feb 2024 18:39:42 -0500 Subject: [PATCH 07/19] Kill selectarg2 --- packages/client/src/definitions/LinkDefinitions.ts | 6 +++--- .../client/src/object/convertWireToOsdkObjects.ts | 6 +++--- packages/client/src/object/fetchPageOrThrow.ts | 11 +---------- packages/client/src/object/getLinkedObjectOrThrow.ts | 4 ++-- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/packages/client/src/definitions/LinkDefinitions.ts b/packages/client/src/definitions/LinkDefinitions.ts index d952e54c4..f837b7d8d 100644 --- a/packages/client/src/definitions/LinkDefinitions.ts +++ b/packages/client/src/definitions/LinkDefinitions.ts @@ -22,7 +22,7 @@ import type { } from "@osdk/api"; import type { FetchPageOrThrowArgs2, - SelectArg2, + SelectArg, } from "../object/fetchPageOrThrow.js"; import type { ObjectSet2 } from "../objectSet/ObjectSet.js"; import type { @@ -40,7 +40,7 @@ export type OsdkObjectLinksObject< export interface SingletonLinkAccessor> { /** Load the linked object */ - get: >(options?: A) => OsdkObjectFrom< + get: >(options?: A) => OsdkObjectFrom< T, A["select"] extends readonly string[] ? A["select"][number] : ObjectOrInterfacePropertyKeysFrom2 @@ -50,7 +50,7 @@ export interface SingletonLinkAccessor> { export interface MultitonLinkAccessor> extends ObjectSet2 { - get: >( + get: >( pk: OsdkObjectPrimaryKeyType, options?: A, ) => OsdkObjectFrom< diff --git a/packages/client/src/object/convertWireToOsdkObjects.ts b/packages/client/src/object/convertWireToOsdkObjects.ts index fd16c097a..7a8f97a66 100644 --- a/packages/client/src/object/convertWireToOsdkObjects.ts +++ b/packages/client/src/object/convertWireToOsdkObjects.ts @@ -19,7 +19,7 @@ import type { OntologyObjectV2 } from "@osdk/gateway/types"; import type { ClientContext } from "@osdk/shared.net"; import { createCachedOntologyTransform } from "../createCachedOntologyTransform.js"; import { Attachment } from "./Attachment.js"; -import type { FetchPageOrThrowArgs2, SelectArg2 } from "./fetchPageOrThrow.js"; +import type { FetchPageOrThrowArgs2, SelectArg } from "./fetchPageOrThrow.js"; import { getLinkedObjectByPkOrThrow } from "./getLinkedObjectByPkOrThrow.js"; import { getLinkedObjectOrThrow } from "./getLinkedObjectOrThrow.js"; import { pageLinkedObjectsOrThrow } from "./pageLinkedObjectsOrThrow.js"; @@ -58,7 +58,7 @@ function createPrototype< if (!linkDef.multiplicity) { return { get: < - A extends SelectArg2, + A extends SelectArg, >( options?: A, ) => @@ -73,7 +73,7 @@ function createPrototype< } else { return { get: < - A extends SelectArg2, + A extends SelectArg, >(targetPrimaryKey: any, options?: A) => getLinkedObjectByPkOrThrow( client, diff --git a/packages/client/src/object/fetchPageOrThrow.ts b/packages/client/src/object/fetchPageOrThrow.ts index 27a397782..598a740a9 100644 --- a/packages/client/src/object/fetchPageOrThrow.ts +++ b/packages/client/src/object/fetchPageOrThrow.ts @@ -17,7 +17,6 @@ import type { ObjectOrInterfaceDefinition, ObjectOrInterfaceKeysFrom, - ObjectOrInterfacePropertyKeysFrom, ObjectOrInterfacePropertyKeysFrom2, OntologyDefinition, } from "@osdk/api"; @@ -30,14 +29,6 @@ import type { PageResult } from "../PageResult.js"; import { convertWireToOsdkObjects } from "./convertWireToOsdkObjects.js"; export interface SelectArg< - O extends OntologyDefinition, - K extends ObjectOrInterfaceKeysFrom, - L = ObjectOrInterfacePropertyKeysFrom, -> { - select?: readonly L[]; -} - -export interface SelectArg2< O extends ObjectOrInterfaceDefinition, L = ObjectOrInterfacePropertyKeysFrom2, > { @@ -47,7 +38,7 @@ export interface SelectArg2< export interface FetchPageOrThrowArgs2< O extends ObjectOrInterfaceDefinition, L = ObjectOrInterfacePropertyKeysFrom2, -> extends SelectArg2 { +> extends SelectArg { nextPageToken?: string; pageSize?: number; } diff --git a/packages/client/src/object/getLinkedObjectOrThrow.ts b/packages/client/src/object/getLinkedObjectOrThrow.ts index 0a42858d5..b8f9f7bf0 100644 --- a/packages/client/src/object/getLinkedObjectOrThrow.ts +++ b/packages/client/src/object/getLinkedObjectOrThrow.ts @@ -20,14 +20,14 @@ import type { OntologyDefinition, } from "@osdk/api"; import { type ClientContext, PalantirApiError } from "@osdk/shared.net"; -import type { SelectArg2 } from "./fetchPageOrThrow.js"; +import type { SelectArg } from "./fetchPageOrThrow.js"; import { pageLinkedObjectsOrThrow } from "./pageLinkedObjectsOrThrow.js"; export async function getLinkedObjectOrThrow< O extends OntologyDefinition, T extends ObjectTypeKeysFrom & string, L extends ObjectTypeLinkKeysFrom2 & string, - S extends SelectArg2["select"], + S extends SelectArg["select"], >( client: ClientContext, sourceApiName: T, From 286270bb01f8421f536ab7dc7876af0edbf2a42c Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 13 Feb 2024 07:56:10 -0500 Subject: [PATCH 08/19] Remove duplicated code --- packages/client/src/OsdkObjectFrom.ts | 38 ++++++++++++--------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/packages/client/src/OsdkObjectFrom.ts b/packages/client/src/OsdkObjectFrom.ts index c900c2d42..6fc4e9c21 100644 --- a/packages/client/src/OsdkObjectFrom.ts +++ b/packages/client/src/OsdkObjectFrom.ts @@ -28,8 +28,8 @@ export type OsdkObjectPrimaryKeyType< O extends ObjectTypeDefinition, > = WirePropertyTypes[O["primaryKeyType"]]; -export type OsdkObjectFrom< - O extends ObjectTypeDefinition, +type OsdkCommonFrom< + O extends ObjectTypeDefinition | InterfaceDefinition, L extends ObjectOrInterfacePropertyKeysFrom2 = ObjectOrInterfacePropertyKeysFrom2, > = @@ -40,32 +40,28 @@ export type OsdkObjectFrom< } & { __apiName: O["apiName"]; - __primaryKey: OsdkObjectPrimaryKeyType; + __primaryKey: O extends ObjectTypeDefinition + ? OsdkObjectPrimaryKeyType + : unknown; + // $uniqueId: string; // will be dynamic + /** * Future versions will require explicitly asking for this field. For now we are marking * as always optional to avoid breaking changes. */ __rid?: string; - $link: OsdkObjectLinksObject; - }; // TODO + }; + +export type OsdkObjectFrom< + O extends ObjectTypeDefinition, + L extends ObjectOrInterfacePropertyKeysFrom2 = + ObjectOrInterfacePropertyKeysFrom2, +> = OsdkCommonFrom & { + $link: OsdkObjectLinksObject; +}; // TODO export type OsdkInterfaceFrom< Q extends InterfaceDefinition, T_PropertyKeys extends InterfacePropertyKeysFrom2 = InterfacePropertyKeysFrom2, -> = - & { - [P in T_PropertyKeys]: OsdkObjectPropertyType< - Q["properties"][P] - >; - } - & { - __apiName: Q["apiName"]; - __primaryKey: unknown; - // $uniqueId: string; // will be dynamic - /** - * Future versions will require explicitly asking for this field. For now we are marking - * as always optional to avoid breaking changes. - */ - __rid?: string; - }; // TODO +> = OsdkCommonFrom; From 603fc2eb54b0b848cbdad093476f241f22e7b4de Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 13 Feb 2024 08:05:04 -0500 Subject: [PATCH 09/19] More cleanup of types --- .../src/definitions/LinkDefinitions.test.ts | 9 ------- .../client/src/definitions/LinkDefinitions.ts | 26 +++++++------------ 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/packages/client/src/definitions/LinkDefinitions.test.ts b/packages/client/src/definitions/LinkDefinitions.test.ts index 34b3fda68..f41d21672 100644 --- a/packages/client/src/definitions/LinkDefinitions.test.ts +++ b/packages/client/src/definitions/LinkDefinitions.test.ts @@ -37,15 +37,6 @@ describe("LinkDefinitions", () => { type PersonDef = Objects["Person"]; type TodoDef = Objects["Todo"]; - expectTypeOf["Todos"]>() - .toEqualTypeOf>(); - - expectTypeOf["RP"]>() - .toEqualTypeOf>(); - - const q: OsdkObjectLinksObject = {} as any; - q.Todos.definition; - expectTypeOf>() .toEqualTypeOf< { diff --git a/packages/client/src/definitions/LinkDefinitions.ts b/packages/client/src/definitions/LinkDefinitions.ts index f837b7d8d..f2c7a681d 100644 --- a/packages/client/src/definitions/LinkDefinitions.ts +++ b/packages/client/src/definitions/LinkDefinitions.ts @@ -35,9 +35,17 @@ import type { PageResult } from "../PageResult.js"; export type OsdkObjectLinksObject< O extends ObjectTypeDefinition, > = ObjectTypeLinkKeysFrom2 extends never ? never : { - [L in ObjectTypeLinkKeysFrom2]: OsdkObjectLinksEntry2; + [L in ObjectTypeLinkKeysFrom2]: OsdkObjectLinksEntry; }; +export type OsdkObjectLinksEntry< + O extends ObjectTypeDefinition, + L extends ObjectTypeLinkKeysFrom2, +> = O["links"][L] extends ObjectTypeLinkDefinition ? ( + M extends false ? SingletonLinkAccessor : MultitonLinkAccessor + ) + : never; + export interface SingletonLinkAccessor> { /** Load the linked object */ get: >(options?: A) => OsdkObjectFrom< @@ -71,19 +79,3 @@ export interface MultitonLinkAccessor> > >; } - -export type LinkTargetType< - O extends ObjectTypeDefinition, - L extends ObjectTypeLinkKeysFrom2, -> = O["links"][L]["targetType"]; - -export type OsdkObjectLinksEntry2< - O extends ObjectTypeDefinition, - L extends ObjectTypeLinkKeysFrom2, -> = O["links"][L] extends ObjectTypeLinkDefinition ? ( - M extends false ? SingletonLinkAccessor - : MultitonLinkAccessor - ) - : never; - -// export type Q From a007167fb67d2eeab6f748e65f3ae64fae65f765 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 13 Feb 2024 08:37:41 -0500 Subject: [PATCH 10/19] More type cleanup --- .../client/src/definitions/LinkDefinitions.ts | 25 ++++++++++--------- .../src/object/convertWireToOsdkObjects.ts | 13 ++++------ .../src/object/pageLinkedObjectsOrThrow.ts | 25 ++++++++----------- 3 files changed, 29 insertions(+), 34 deletions(-) diff --git a/packages/client/src/definitions/LinkDefinitions.ts b/packages/client/src/definitions/LinkDefinitions.ts index f2c7a681d..d3f8037a5 100644 --- a/packages/client/src/definitions/LinkDefinitions.ts +++ b/packages/client/src/definitions/LinkDefinitions.ts @@ -24,7 +24,6 @@ import type { FetchPageOrThrowArgs2, SelectArg, } from "../object/fetchPageOrThrow.js"; -import type { ObjectSet2 } from "../objectSet/ObjectSet.js"; import type { OsdkObjectFrom, OsdkObjectPrimaryKeyType, @@ -48,23 +47,25 @@ export type OsdkObjectLinksEntry< export interface SingletonLinkAccessor> { /** Load the linked object */ - get: >(options?: A) => OsdkObjectFrom< - T, - A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom2 + get: >(options?: A) => Promise< + OsdkObjectFrom< + T, + A["select"] extends readonly string[] ? A["select"][number] + : ObjectOrInterfacePropertyKeysFrom2 + > >; } -export interface MultitonLinkAccessor> - extends ObjectSet2 -{ +export interface MultitonLinkAccessor> { get: >( pk: OsdkObjectPrimaryKeyType, options?: A, - ) => OsdkObjectFrom< - T, - A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom2 + ) => Promise< + OsdkObjectFrom< + T, + A["select"] extends readonly string[] ? A["select"][number] + : ObjectOrInterfacePropertyKeysFrom2 + > >; fetchPageOrThrow: < diff --git a/packages/client/src/object/convertWireToOsdkObjects.ts b/packages/client/src/object/convertWireToOsdkObjects.ts index 7a8f97a66..6ba4e4dc9 100644 --- a/packages/client/src/object/convertWireToOsdkObjects.ts +++ b/packages/client/src/object/convertWireToOsdkObjects.ts @@ -57,11 +57,7 @@ function createPrototype< if (!linkDef.multiplicity) { return { - get: < - A extends SelectArg, - >( - options?: A, - ) => + get: >(options?: A) => getLinkedObjectOrThrow( client, type, @@ -72,9 +68,10 @@ function createPrototype< }; } else { return { - get: < - A extends SelectArg, - >(targetPrimaryKey: any, options?: A) => + get: >( + targetPrimaryKey: any, + options?: A, + ) => getLinkedObjectByPkOrThrow( client, type, diff --git a/packages/client/src/object/pageLinkedObjectsOrThrow.ts b/packages/client/src/object/pageLinkedObjectsOrThrow.ts index 23e215092..c84d4c599 100644 --- a/packages/client/src/object/pageLinkedObjectsOrThrow.ts +++ b/packages/client/src/object/pageLinkedObjectsOrThrow.ts @@ -25,29 +25,26 @@ import { type ClientContext, createOpenApiRequest } from "@osdk/shared.net"; import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import { convertWireToOsdkObjects } from "./convertWireToOsdkObjects.js"; -import type { FetchPageOrThrowArgs2 } from "./fetchPageOrThrow.js"; +import type { FetchPageOrThrowArgs2, SelectArg } from "./fetchPageOrThrow.js"; + +export type SelectArgToKeys> = A["select"] extends + readonly string[] ? A["select"][number] + : A extends SelectArg ? ObjectOrInterfacePropertyKeysFrom2 + : never; export async function pageLinkedObjectsOrThrow< O extends OntologyDefinition, - T extends ObjectTypeKeysFrom, - L extends ObjectTypeLinkKeysFrom2, - Q extends O["objects"][T]["links"][L]["__Mark"], + T_SourceTypeKey extends ObjectTypeKeysFrom, + T_LinkApiName extends ObjectTypeLinkKeysFrom2, + Q extends O["objects"][T_SourceTypeKey]["links"][T_LinkApiName]["__Mark"], const A extends FetchPageOrThrowArgs2, >( client: ClientContext, - sourceApiName: T & string, + sourceApiName: T_SourceTypeKey & string, primaryKey: any, linkTypeApiName: string, options: A, -): Promise< - PageResult< - OsdkObjectFrom< - Q, - A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom2 - > - > -> { +): Promise>>> { const page = await listLinkedObjectsV2( createOpenApiRequest(client.stack, client.fetch), client.ontology.metadata.ontologyApiName, From 95353cf7af96abe17ff87eb09ab7e1c28043e92c Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 13 Feb 2024 08:41:45 -0500 Subject: [PATCH 11/19] more type cleanup --- .../client/src/definitions/LinkDefinitions.ts | 34 +++++-------------- .../src/object/convertWireToOsdkObjects.ts | 4 +-- .../client/src/object/fetchPageOrThrow.ts | 4 +-- .../src/object/pageLinkedObjectsOrThrow.ts | 4 +-- packages/client/src/objectSet/ObjectSet.ts | 6 ++-- .../client/src/objectSet/createObjectSet.ts | 6 ++-- 6 files changed, 19 insertions(+), 39 deletions(-) diff --git a/packages/client/src/definitions/LinkDefinitions.ts b/packages/client/src/definitions/LinkDefinitions.ts index d3f8037a5..f569baebe 100644 --- a/packages/client/src/definitions/LinkDefinitions.ts +++ b/packages/client/src/definitions/LinkDefinitions.ts @@ -15,15 +15,15 @@ */ import type { - ObjectOrInterfacePropertyKeysFrom2, ObjectTypeDefinition, ObjectTypeLinkDefinition, ObjectTypeLinkKeysFrom2, } from "@osdk/api"; import type { - FetchPageOrThrowArgs2, + FetchPageOrThrowArgs, SelectArg, } from "../object/fetchPageOrThrow.js"; +import type { SelectArgToKeys } from "../object/pageLinkedObjectsOrThrow.js"; import type { OsdkObjectFrom, OsdkObjectPrimaryKeyType, @@ -47,36 +47,18 @@ export type OsdkObjectLinksEntry< export interface SingletonLinkAccessor> { /** Load the linked object */ - get: >(options?: A) => Promise< - OsdkObjectFrom< - T, - A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom2 - > - >; + get: >( + options?: A, + ) => Promise>>; } export interface MultitonLinkAccessor> { get: >( pk: OsdkObjectPrimaryKeyType, options?: A, - ) => Promise< - OsdkObjectFrom< - T, - A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom2 - > - >; + ) => Promise>>; fetchPageOrThrow: < - A extends FetchPageOrThrowArgs2, - >(options?: A) => Promise< - PageResult< - OsdkObjectFrom< - T, - A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom2 - > - > - >; + A extends FetchPageOrThrowArgs, + >(options?: A) => Promise>>>; } diff --git a/packages/client/src/object/convertWireToOsdkObjects.ts b/packages/client/src/object/convertWireToOsdkObjects.ts index 6ba4e4dc9..b6bbc056c 100644 --- a/packages/client/src/object/convertWireToOsdkObjects.ts +++ b/packages/client/src/object/convertWireToOsdkObjects.ts @@ -19,7 +19,7 @@ import type { OntologyObjectV2 } from "@osdk/gateway/types"; import type { ClientContext } from "@osdk/shared.net"; import { createCachedOntologyTransform } from "../createCachedOntologyTransform.js"; import { Attachment } from "./Attachment.js"; -import type { FetchPageOrThrowArgs2, SelectArg } from "./fetchPageOrThrow.js"; +import type { FetchPageOrThrowArgs, SelectArg } from "./fetchPageOrThrow.js"; import { getLinkedObjectByPkOrThrow } from "./getLinkedObjectByPkOrThrow.js"; import { getLinkedObjectOrThrow } from "./getLinkedObjectOrThrow.js"; import { pageLinkedObjectsOrThrow } from "./pageLinkedObjectsOrThrow.js"; @@ -81,7 +81,7 @@ function createPrototype< options?.select, ), fetchPageOrThrow: ( - options?: FetchPageOrThrowArgs2< + options?: FetchPageOrThrowArgs< O["objects"][typeof linkDef.targetType] >, ) => diff --git a/packages/client/src/object/fetchPageOrThrow.ts b/packages/client/src/object/fetchPageOrThrow.ts index 598a740a9..e33694cfa 100644 --- a/packages/client/src/object/fetchPageOrThrow.ts +++ b/packages/client/src/object/fetchPageOrThrow.ts @@ -35,7 +35,7 @@ export interface SelectArg< select?: readonly L[]; } -export interface FetchPageOrThrowArgs2< +export interface FetchPageOrThrowArgs< O extends ObjectOrInterfaceDefinition, L = ObjectOrInterfacePropertyKeysFrom2, > extends SelectArg { @@ -46,7 +46,7 @@ export interface FetchPageOrThrowArgs2< export async function fetchPageOrThrow< O extends OntologyDefinition, T extends ObjectOrInterfaceKeysFrom, - const A extends FetchPageOrThrowArgs2, + const A extends FetchPageOrThrowArgs, >( client: ClientContext, objectType: T & string, diff --git a/packages/client/src/object/pageLinkedObjectsOrThrow.ts b/packages/client/src/object/pageLinkedObjectsOrThrow.ts index c84d4c599..7e95b3ab2 100644 --- a/packages/client/src/object/pageLinkedObjectsOrThrow.ts +++ b/packages/client/src/object/pageLinkedObjectsOrThrow.ts @@ -25,7 +25,7 @@ import { type ClientContext, createOpenApiRequest } from "@osdk/shared.net"; import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import { convertWireToOsdkObjects } from "./convertWireToOsdkObjects.js"; -import type { FetchPageOrThrowArgs2, SelectArg } from "./fetchPageOrThrow.js"; +import type { FetchPageOrThrowArgs, SelectArg } from "./fetchPageOrThrow.js"; export type SelectArgToKeys> = A["select"] extends readonly string[] ? A["select"][number] @@ -37,7 +37,7 @@ export async function pageLinkedObjectsOrThrow< T_SourceTypeKey extends ObjectTypeKeysFrom, T_LinkApiName extends ObjectTypeLinkKeysFrom2, Q extends O["objects"][T_SourceTypeKey]["links"][T_LinkApiName]["__Mark"], - const A extends FetchPageOrThrowArgs2, + const A extends FetchPageOrThrowArgs, >( client: ClientContext, sourceApiName: T_SourceTypeKey & string, diff --git a/packages/client/src/objectSet/ObjectSet.ts b/packages/client/src/objectSet/ObjectSet.ts index 9e1339509..74a9db9dc 100644 --- a/packages/client/src/objectSet/ObjectSet.ts +++ b/packages/client/src/objectSet/ObjectSet.ts @@ -23,7 +23,7 @@ import type { OntologyDefinition, } from "@osdk/api"; import type { ObjectSet as WireObjectSet } from "@osdk/gateway/types"; -import type { FetchPageOrThrowArgs2 } from "../object/fetchPageOrThrow.js"; +import type { FetchPageOrThrowArgs } from "../object/fetchPageOrThrow.js"; import type { OsdkInterfaceFrom, OsdkObjectFrom } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import type { AggregateOpts } from "../query/aggregations/AggregateOpts.js"; @@ -37,7 +37,7 @@ export interface ObjectSet2> { fetchPageOrThrow: < S extends ObjectOrInterfacePropertyKeysFrom2, >( - args?: FetchPageOrThrowArgs2, + args?: FetchPageOrThrowArgs, ) => Promise< PageResult< OsdkObjectFrom @@ -61,7 +61,7 @@ export interface BaseObjectSet< fetchPageOrThrow: < L extends ObjectOrInterfacePropertyKeysFrom2, >( - args?: FetchPageOrThrowArgs2, + args?: FetchPageOrThrowArgs, ) => Promise< PageResult< Q extends InterfaceDefinition ? OsdkInterfaceFrom diff --git a/packages/client/src/objectSet/createObjectSet.ts b/packages/client/src/objectSet/createObjectSet.ts index 1f72cb9e1..a358dc509 100644 --- a/packages/client/src/objectSet/createObjectSet.ts +++ b/packages/client/src/objectSet/createObjectSet.ts @@ -18,7 +18,7 @@ import type { ObjectOrInterfaceKeysFrom, OntologyDefinition } from "@osdk/api"; import type { ObjectSet as WireObjectSet } from "@osdk/gateway/types"; import type { ClientContext } from "@osdk/shared.net"; import { modernToLegacyWhereClause } from "../internal/conversions/index.js"; -import type { FetchPageOrThrowArgs2 } from "../object/fetchPageOrThrow.js"; +import type { FetchPageOrThrowArgs } from "../object/fetchPageOrThrow.js"; import { aggregateOrThrow, fetchPageOrThrow } from "../object/index.js"; import type { AggregateOpts } from "../query/aggregations/AggregateOpts.js"; import type { AggregationClause, AggregationsResults } from "../query/index.js"; @@ -62,9 +62,7 @@ export function createObjectSet< // fetchPage: async (args?: { nextPageToken?: string }) => { // throw "TODO"; // }, - fetchPageOrThrow: async ( - args?: FetchPageOrThrowArgs2, - ) => { + fetchPageOrThrow: async (args?: FetchPageOrThrowArgs) => { return fetchPageOrThrow( clientCtx, objectType, From d72646be0fdf0e6e0cc7b16698ade3770fb5fb2b Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 13 Feb 2024 09:02:54 -0500 Subject: [PATCH 12/19] Type fixes and remove code so we can merge this --- packages/client/src/Client.test.ts | 45 ------------------- packages/client/src/Client.ts | 13 ++---- packages/client/src/OsdkObjectFrom.ts | 8 ++++ packages/client/src/objectSet/ObjectSet.ts | 23 +--------- .../client/src/objectSet/ObjectSetListener.ts | 41 ++++++++--------- .../objectSet/ObjectSetListenerWebsocket.ts | 13 +++--- 6 files changed, 39 insertions(+), 104 deletions(-) delete mode 100644 packages/client/src/Client.test.ts diff --git a/packages/client/src/Client.test.ts b/packages/client/src/Client.test.ts deleted file mode 100644 index a1e7fcd2c..000000000 --- a/packages/client/src/Client.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2023 Palantir Technologies, Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, expectTypeOf, it } from "vitest"; -import type { Ontology as MockOntology } from "./generatedNoCheck/index.js"; -import type { Office } from "./generatedNoCheck/ontology/objects.js"; -import { Employee } from "./generatedNoCheck/ontology/objects.js"; -import type { Client } from "./index.js"; -import type { ObjectSet2 } from "./objectSet/ObjectSet.js"; -import type { OsdkObjectFrom } from "./OsdkObjectFrom.js"; - -describe("client", () => { - it("can be called with an object definition", async () => { - const client: Client = undefined as any; - const objSet = client(Employee); - expectTypeOf().toEqualTypeOf< - ObjectSet2 - >(); - - const result = await objSet.fetchPageOrThrow(); - expectTypeOf().toEqualTypeOf< - OsdkObjectFrom< - typeof Employee - > - >(); - - const office = await result.data[0].$link.officeLink.get(); - expectTypeOf().toEqualTypeOf< - OsdkObjectFrom - >(); - }); -}); diff --git a/packages/client/src/Client.ts b/packages/client/src/Client.ts index 4ad4be282..1237d9a41 100644 --- a/packages/client/src/Client.ts +++ b/packages/client/src/Client.ts @@ -16,21 +16,14 @@ import type { ObjectOrInterfaceKeysFrom, - ObjectTypeDefinition, ObjectTypeKeysFrom, OntologyDefinition, } from "@osdk/api"; import type { Actions } from "./actions/Actions.js"; -import type { ObjectSet, ObjectSet2 } from "./objectSet/ObjectSet.js"; +import type { ObjectSet } from "./objectSet/ObjectSet.js"; import type { ObjectSetCreator } from "./ObjectSetCreator.js"; -export type CallableClient = < - O extends ObjectTypeDefinition, ->( - definition: O, -) => ObjectSet2; - -export type Client> = CallableClient & { +export interface Client> { objectSet: >( type: K, ) => ObjectSet; @@ -43,4 +36,4 @@ export type Client> = CallableClient & { type: K, rid: string, ): ObjectSet; -}; +} diff --git a/packages/client/src/OsdkObjectFrom.ts b/packages/client/src/OsdkObjectFrom.ts index 6fc4e9c21..cd1f127e2 100644 --- a/packages/client/src/OsdkObjectFrom.ts +++ b/packages/client/src/OsdkObjectFrom.ts @@ -65,3 +65,11 @@ export type OsdkInterfaceFrom< T_PropertyKeys extends InterfacePropertyKeysFrom2 = InterfacePropertyKeysFrom2, > = OsdkCommonFrom; + +export type OsdkObjectOrInterfaceFrom< + Q extends ObjectTypeDefinition | InterfaceDefinition, + L extends ObjectOrInterfacePropertyKeysFrom2 = + ObjectOrInterfacePropertyKeysFrom2, +> = Q extends InterfaceDefinition ? OsdkInterfaceFrom + : Q extends ObjectTypeDefinition ? OsdkObjectFrom + : never; diff --git a/packages/client/src/objectSet/ObjectSet.ts b/packages/client/src/objectSet/ObjectSet.ts index 74a9db9dc..215ab4615 100644 --- a/packages/client/src/objectSet/ObjectSet.ts +++ b/packages/client/src/objectSet/ObjectSet.ts @@ -15,36 +15,20 @@ */ import type { - InterfaceDefinition, ObjectOrInterfaceDefinitionFrom, ObjectOrInterfaceKeysFrom, ObjectOrInterfacePropertyKeysFrom2, - ObjectTypeDefinition, OntologyDefinition, } from "@osdk/api"; import type { ObjectSet as WireObjectSet } from "@osdk/gateway/types"; import type { FetchPageOrThrowArgs } from "../object/fetchPageOrThrow.js"; -import type { OsdkInterfaceFrom, OsdkObjectFrom } from "../OsdkObjectFrom.js"; +import type { OsdkObjectOrInterfaceFrom } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import type { AggregateOpts } from "../query/aggregations/AggregateOpts.js"; import type { AggregationsResults, WhereClause } from "../query/index.js"; import type { LinkTypesFrom } from "./LinkTypesFrom.js"; import type { ObjectSetListener } from "./ObjectSetListener.js"; -export interface ObjectSet2> { - definition: WireObjectSet; - - fetchPageOrThrow: < - S extends ObjectOrInterfacePropertyKeysFrom2, - >( - args?: FetchPageOrThrowArgs, - ) => Promise< - PageResult< - OsdkObjectFrom - > - >; -} - export type ObjectSet< O extends OntologyDefinition, K extends ObjectOrInterfaceKeysFrom, @@ -63,10 +47,7 @@ export interface BaseObjectSet< >( args?: FetchPageOrThrowArgs, ) => Promise< - PageResult< - Q extends InterfaceDefinition ? OsdkInterfaceFrom - : OsdkObjectFrom - > + PageResult> >; // qq: (foo: Q) => ObjectTypePropertyKeysFrom; diff --git a/packages/client/src/objectSet/ObjectSetListener.ts b/packages/client/src/objectSet/ObjectSetListener.ts index 386dc944a..b4c2cc9b2 100644 --- a/packages/client/src/objectSet/ObjectSetListener.ts +++ b/packages/client/src/objectSet/ObjectSetListener.ts @@ -14,28 +14,25 @@ * limitations under the License. */ -import type { ObjectTypeKeysFrom, OntologyDefinition } from "@osdk/api"; -import type { OsdkObjectFrom } from "../OsdkObjectFrom.js"; +import type { InterfaceDefinition, ObjectTypeDefinition } from "@osdk/api"; +import type { OsdkObjectOrInterfaceFrom } from "../OsdkObjectFrom.js"; -export type ObjectSetListener< - O extends OntologyDefinition, - K extends ObjectTypeKeysFrom, -> = Partial< - { - /** - * Specific objects have changed and can be immediately updated - */ - onChange: (objects: Array>) => void; +export interface ObjectSetListener< + O extends ObjectTypeDefinition | InterfaceDefinition, +> { + /** + * Specific objects have changed and can be immediately updated + */ + onChange?: (objects: Array>) => void; - /** - * The ObjectSet has become outdated and should be re-fetched in its entirety. - * This is also sent when the subscription is first initialized. - */ - onOutOfDate: () => void; + /** + * The ObjectSet has become outdated and should be re-fetched in its entirety. + * This is also sent when the subscription is first initialized. + */ + onOutOfDate?: () => void; - /** - * There was a fatal error with the subscription process - */ - onError: (error: unknown) => void; - } ->; + /** + * There was a fatal error with the subscription process + */ + onError?: (error: unknown) => void; +} diff --git a/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts b/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts index 6890fd709..ca2de9304 100644 --- a/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts +++ b/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts @@ -15,6 +15,7 @@ */ import type { + ObjectOrInterfaceDefinitionFrom, ObjectOrInterfaceKeysFrom, ObjectTypeKeysFrom, OntologyDefinition, @@ -79,7 +80,7 @@ export class ObjectSetListenerWebsocket< #listeners = new Map< string, { - listener: ObjectSetListener; + listener: ObjectSetListener; subscriptionId?: string; objectSet: ObjectSet; expiry: NodeJS.Timeout; @@ -119,7 +120,7 @@ export class ObjectSetListenerWebsocket< subscribe>( objectSet: ObjectSet, - listener: ObjectSetListener, + listener: ObjectSetListener>, ): () => void { const requestId = crypto.randomUUID(); const expiry = setTimeout(() => { @@ -410,18 +411,18 @@ export class ObjectSetListenerWebsocket< } }; - #getCallbackByRequestId>( + #getCallbackByRequestId>( requestId: string, type: T, - ): ObjectSetListener[T] | undefined { + ): ObjectSetListener[T] | undefined { const maybeListener = this.#listeners.get(requestId); return maybeListener?.listener?.[type]; } - #getCallback>( + #getCallback>( subscriptionId: string, type: T, - ): ObjectSetListener[T] | undefined { + ): ObjectSetListener[T] | undefined { const requestId = this.#subscriptionToRequestId.get(subscriptionId); if (requestId) { return this.#getCallbackByRequestId(requestId, type); From e06ef13e8b8ec0a995ed6f3774d31a6154c5ea2e Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 13 Feb 2024 13:47:39 -0500 Subject: [PATCH 13/19] Fix whitespace --- examples/basic/cli/src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/basic/cli/src/index.ts b/examples/basic/cli/src/index.ts index ae0af4d2e..26bbb0e6d 100644 --- a/examples/basic/cli/src/index.ts +++ b/examples/basic/cli/src/index.ts @@ -70,7 +70,6 @@ async function runTests() { if (interfaceImplementationComplete) { const interfaceResults = await client.objects.SimpleInterface .fetchPageOrThrow(); - interfaceResults.data[0].body; } From 625ba05ab14e2e9cf82816af13f1249f0adacedd Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 13 Feb 2024 13:56:57 -0500 Subject: [PATCH 14/19] One more step to objectset --- .../ontology/interfaces/SimpleInterface.ts | 1 + examples/basic/sdk/src/interfaces/Emailable.ts | 1 + packages/api/src/ontology/InterfaceDefinition.ts | 9 ++++++++- packages/client/src/objectSet/ObjectSet.ts | 11 ++++------- .../UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.ts | 1 + 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/basic/sdk/src/generatedNoCheck/ontology/interfaces/SimpleInterface.ts b/examples/basic/sdk/src/generatedNoCheck/ontology/interfaces/SimpleInterface.ts index f6027bf47..96a0b3853 100644 --- a/examples/basic/sdk/src/generatedNoCheck/ontology/interfaces/SimpleInterface.ts +++ b/examples/basic/sdk/src/generatedNoCheck/ontology/interfaces/SimpleInterface.ts @@ -27,4 +27,5 @@ export const SimpleInterface = { nullable: true, }, }, + links: {}, } satisfies InterfaceDefinition<'SimpleInterface', ''>; diff --git a/examples/basic/sdk/src/interfaces/Emailable.ts b/examples/basic/sdk/src/interfaces/Emailable.ts index c3908e6ab..141c3c1ba 100644 --- a/examples/basic/sdk/src/interfaces/Emailable.ts +++ b/examples/basic/sdk/src/interfaces/Emailable.ts @@ -27,4 +27,5 @@ export const Emailable = { nullable: false, }, }, + links: {}, } satisfies InterfaceDefinition<"Emailable", string>; diff --git a/packages/api/src/ontology/InterfaceDefinition.ts b/packages/api/src/ontology/InterfaceDefinition.ts index 05dfa2a1c..22001df2e 100644 --- a/packages/api/src/ontology/InterfaceDefinition.ts +++ b/packages/api/src/ontology/InterfaceDefinition.ts @@ -14,7 +14,10 @@ * limitations under the License. */ -import type { ObjectTypePropertyDefinition } from "./ObjectTypeDefinition"; +import type { + ObjectTypeLinkDefinition, + ObjectTypePropertyDefinition, +} from "./ObjectTypeDefinition"; import type { OntologyDefinition } from "./OntologyDefinition"; export type InterfaceDefinitionFrom< @@ -53,4 +56,8 @@ export interface InterfaceDefinition< apiName: K; description?: string; properties: Record; + links: Record< + string, + ObjectTypeLinkDefinition + >; } diff --git a/packages/client/src/objectSet/ObjectSet.ts b/packages/client/src/objectSet/ObjectSet.ts index 215ab4615..4b1c9b8da 100644 --- a/packages/client/src/objectSet/ObjectSet.ts +++ b/packages/client/src/objectSet/ObjectSet.ts @@ -26,7 +26,6 @@ import type { OsdkObjectOrInterfaceFrom } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import type { AggregateOpts } from "../query/aggregations/AggregateOpts.js"; import type { AggregationsResults, WhereClause } from "../query/index.js"; -import type { LinkTypesFrom } from "./LinkTypesFrom.js"; import type { ObjectSetListener } from "./ObjectSetListener.js"; export type ObjectSet< @@ -77,16 +76,14 @@ export interface BaseObjectSet< // ) => Promise>>; where: ( - clause: WhereClause< - ObjectOrInterfaceDefinitionFrom - >, + clause: WhereClause, ) => ObjectSet; - pivotTo: >( + pivotTo: ( type: T & string, - ) => ObjectSet; + ) => ObjectSet; - subscribe: (listener: ObjectSetListener) => () => void; + subscribe: (listener: ObjectSetListener) => () => void; } export type ObjectSetFactory> = < diff --git a/packages/generator/src/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.ts b/packages/generator/src/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.ts index ebcc692ad..95fa4cf47 100644 --- a/packages/generator/src/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.ts +++ b/packages/generator/src/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.ts @@ -57,5 +57,6 @@ function wireInterfaceTypeV2ToSdkObjectDefinition( ]; }), ), + links: {}, }; } From ae8ee427e0536cf23d5da4602b8f48c3504f873b Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 13 Feb 2024 14:31:29 -0500 Subject: [PATCH 15/19] Prep aggregations --- packages/api/src/index.ts | 1 + .../api/src/ontology/ObjectOrInterface.ts | 5 ++++- .../api/src/ontology/ObjectTypeDefinition.ts | 6 ++++++ .../legacyToModernSingleAggregationResult.ts | 6 +++--- .../modernToLegacyAggregationClause.ts | 5 +---- .../modernToLegacyGroupByClause.ts | 8 +++---- .../src/object/aggregateOrThrow.test.ts | 6 ++---- .../client/src/object/aggregateOrThrow.ts | 21 ++++++++++++------- packages/client/src/objectSet/ObjectSet.ts | 4 ++-- .../client/src/objectSet/createObjectSet.ts | 13 ++++++++---- .../query/aggregations/AggregatableKeys.ts | 20 +++--------------- .../src/query/aggregations/AggregateOpts.ts | 15 +++++-------- .../AggregationResultsWithGroups.ts | 20 +++++++----------- .../AggregationResultsWithoutGroups.ts | 18 ++++++---------- .../aggregations/AggregationsClause.test.ts | 6 ++---- .../query/aggregations/AggregationsClause.ts | 18 +++++----------- .../aggregations/AggregationsResults.test.ts | 6 ++---- .../query/aggregations/AggregationsResults.ts | 13 ++++++------ .../query/aggregations/GroupByClause.test.ts | 3 +-- .../src/query/aggregations/GroupByClause.ts | 21 +++++++------------ 20 files changed, 88 insertions(+), 127 deletions(-) diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index a958106f1..0c3c514c9 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -49,6 +49,7 @@ export type { ObjectTypeLinkTargetTypeFrom, ObjectTypePropertyDefinition, ObjectTypePropertyDefinitionFrom, + ObjectTypePropertyDefinitionFrom2, ObjectTypePropertyDefinitionsFrom, ObjectTypePropertyKeysFrom, } from "./ontology/ObjectTypeDefinition"; diff --git a/packages/api/src/ontology/ObjectOrInterface.ts b/packages/api/src/ontology/ObjectOrInterface.ts index 4b3103174..8ef66f868 100644 --- a/packages/api/src/ontology/ObjectOrInterface.ts +++ b/packages/api/src/ontology/ObjectOrInterface.ts @@ -33,7 +33,10 @@ export type ObjectOrInterfaceKeysFrom> = | ObjectTypeKeysFrom | InterfaceKeysFrom; -export type ObjectOrInterfaceDefinition = +export type ObjectOrInterfaceDefinition< + K extends string = any, + L extends string = any, +> = | ObjectTypeDefinition | InterfaceDefinition; diff --git a/packages/api/src/ontology/ObjectTypeDefinition.ts b/packages/api/src/ontology/ObjectTypeDefinition.ts index 40d99f004..cb60cf7b7 100644 --- a/packages/api/src/ontology/ObjectTypeDefinition.ts +++ b/packages/api/src/ontology/ObjectTypeDefinition.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import type { ObjectOrInterfaceDefinition } from ".."; import type { OntologyDefinition } from "./OntologyDefinition"; import type { WirePropertyTypes } from "./WirePropertyTypes"; @@ -41,6 +42,11 @@ export type ObjectTypePropertyDefinitionFrom< P extends ObjectTypePropertyKeysFrom, > = ObjectTypePropertyDefinitionsFrom[P]; +export type ObjectTypePropertyDefinitionFrom2< + Q extends ObjectOrInterfaceDefinition, + P extends keyof Q["properties"] & string, +> = Q["properties"][P]; + export interface ObjectTypeDefinition< K extends string, > { diff --git a/packages/client/src/internal/conversions/legacyToModernSingleAggregationResult.ts b/packages/client/src/internal/conversions/legacyToModernSingleAggregationResult.ts index 8020a11d4..a6b66f8eb 100644 --- a/packages/client/src/internal/conversions/legacyToModernSingleAggregationResult.ts +++ b/packages/client/src/internal/conversions/legacyToModernSingleAggregationResult.ts @@ -23,10 +23,10 @@ import type { import type { ArrayElement } from "../../util/ArrayElement.js"; export function legacyToModernSingleAggregationResult< - AC extends AggregationClause, + AC extends AggregationClause, >( entry: ArrayElement, -): AggregationResultsWithoutGroups { +): AggregationResultsWithoutGroups { return entry.metrics.reduce( (accumulator, curValue) => { const parts = curValue.name.split("."); @@ -41,6 +41,6 @@ export function legacyToModernSingleAggregationResult< return accumulator; }, - {} as AggregationResultsWithoutGroups, + {} as AggregationResultsWithoutGroups, ); } diff --git a/packages/client/src/internal/conversions/modernToLegacyAggregationClause.ts b/packages/client/src/internal/conversions/modernToLegacyAggregationClause.ts index 64dde9146..52fcf3eef 100644 --- a/packages/client/src/internal/conversions/modernToLegacyAggregationClause.ts +++ b/packages/client/src/internal/conversions/modernToLegacyAggregationClause.ts @@ -14,14 +14,11 @@ * limitations under the License. */ -import type { ObjectTypeKeysFrom, OntologyDefinition } from "@osdk/api"; import type { Aggregation } from "@osdk/gateway/types"; import type { AggregationClause } from "../../query/index.js"; export function modernToLegacyAggregationClause< - T extends OntologyDefinition, - K extends ObjectTypeKeysFrom, - AC extends AggregationClause, + AC extends AggregationClause, >(select: AC) { return Object.entries(select).flatMap(([k, v]) => { if (Array.isArray(v)) { diff --git a/packages/client/src/internal/conversions/modernToLegacyGroupByClause.ts b/packages/client/src/internal/conversions/modernToLegacyGroupByClause.ts index 3bf8c8b23..8893bee62 100644 --- a/packages/client/src/internal/conversions/modernToLegacyGroupByClause.ts +++ b/packages/client/src/internal/conversions/modernToLegacyGroupByClause.ts @@ -14,14 +14,12 @@ * limitations under the License. */ -import type { ObjectTypeKeysFrom, OntologyDefinition } from "@osdk/api"; import type { AggregationGroupByV2 } from "@osdk/gateway/types"; import type { AllGroupByValues, GroupByClause } from "../../query/index.js"; -export function modernToLegacyGroupByClause< - O extends OntologyDefinition, - K extends ObjectTypeKeysFrom, ->(groupByClause: GroupByClause | undefined) { +export function modernToLegacyGroupByClause( + groupByClause: GroupByClause | undefined, +) { if (!groupByClause) return []; return Object.entries( diff --git a/packages/client/src/object/aggregateOrThrow.test.ts b/packages/client/src/object/aggregateOrThrow.test.ts index f132defeb..0f712e248 100644 --- a/packages/client/src/object/aggregateOrThrow.test.ts +++ b/packages/client/src/object/aggregateOrThrow.test.ts @@ -160,8 +160,7 @@ describe("aggregateOrThrow", () => { }; actions: {}; queries: {}; - }, - "Todo", + }["objects"]["Todo"], { locationCity: "approximateDistinct"; text: "approximateDistinct"; @@ -189,8 +188,7 @@ describe("aggregateOrThrow", () => { }; actions: {}; queries: {}; - }, - "Todo", + }["objects"]["Todo"], { locationCity: "approximateDistinct"; text: "approximateDistinct"; diff --git a/packages/client/src/object/aggregateOrThrow.ts b/packages/client/src/object/aggregateOrThrow.ts index e2a269428..77a79f998 100644 --- a/packages/client/src/object/aggregateOrThrow.ts +++ b/packages/client/src/object/aggregateOrThrow.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import type { ObjectTypeKeysFrom, OntologyDefinition } from "@osdk/api"; +import type { + ObjectOrInterfaceDefinitionFrom, + ObjectTypeKeysFrom, + OntologyDefinition, +} from "@osdk/api"; import { aggregateObjectsV2 } from "@osdk/gateway/requests"; import type { AggregateObjectsRequestV2 } from "@osdk/gateway/types"; import { createOpenApiRequest } from "@osdk/shared.net"; @@ -33,16 +37,17 @@ import type { } from "../query/index.js"; export async function aggregateOrThrow< - T extends OntologyDefinition, - K extends ObjectTypeKeysFrom, - const AO extends AggregateOpts, + O extends OntologyDefinition, + K extends ObjectTypeKeysFrom, + Q extends ObjectOrInterfaceDefinitionFrom, + const AO extends AggregateOpts, >( - clientCtx: ClientContext, + clientCtx: ClientContext, objectType: K & string, req: AO, -): Promise> { +): Promise> { const body: AggregateObjectsRequestV2 = { - aggregation: modernToLegacyAggregationClause( + aggregation: modernToLegacyAggregationClause( req.select, ), groupBy: [], @@ -78,7 +83,7 @@ export async function aggregateOrThrow< ) as any; } - const ret: AggregationResultsWithGroups = result.data + const ret: AggregationResultsWithGroups = result.data .map((entry) => { return { group: entry.group as any, diff --git a/packages/client/src/objectSet/ObjectSet.ts b/packages/client/src/objectSet/ObjectSet.ts index 4b1c9b8da..a4e51c8b2 100644 --- a/packages/client/src/objectSet/ObjectSet.ts +++ b/packages/client/src/objectSet/ObjectSet.ts @@ -66,9 +66,9 @@ export interface BaseObjectSet< // OsdkObjectFrom> // >; - aggregateOrThrow: >( + aggregateOrThrow: >( req: AO, - ) => Promise>; + ) => Promise>; // @alpha // aggregate: >( diff --git a/packages/client/src/objectSet/createObjectSet.ts b/packages/client/src/objectSet/createObjectSet.ts index a358dc509..0a1510830 100644 --- a/packages/client/src/objectSet/createObjectSet.ts +++ b/packages/client/src/objectSet/createObjectSet.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import type { ObjectOrInterfaceKeysFrom, OntologyDefinition } from "@osdk/api"; +import type { + ObjectOrInterfaceDefinitionFrom, + ObjectOrInterfaceKeysFrom, + OntologyDefinition, +} from "@osdk/api"; import type { ObjectSet as WireObjectSet } from "@osdk/gateway/types"; import type { ClientContext } from "@osdk/shared.net"; import { modernToLegacyWhereClause } from "../internal/conversions/index.js"; @@ -51,12 +55,13 @@ export function createObjectSet< // throw "TODO"; // }, aggregateOrThrow: async < - AC extends AggregationClause, + AC extends AggregationClause>, // GBC extends GroupByClause, - AO extends AggregateOpts, + AO extends AggregateOpts, AC>, + Q extends ObjectOrInterfaceDefinitionFrom, >( req: AO, - ): Promise> => { + ): Promise> => { return aggregateOrThrow(clientCtx, objectType, req); }, // fetchPage: async (args?: { nextPageToken?: string }) => { diff --git a/packages/client/src/query/aggregations/AggregatableKeys.ts b/packages/client/src/query/aggregations/AggregatableKeys.ts index ae5a300ec..d96370412 100644 --- a/packages/client/src/query/aggregations/AggregatableKeys.ts +++ b/packages/client/src/query/aggregations/AggregatableKeys.ts @@ -14,24 +14,10 @@ * limitations under the License. */ -import type { - ObjectTypeDefinitionFrom, - ObjectTypeKeysFrom, - ObjectTypePropertyKeysFrom, - OntologyDefinition, -} from "@osdk/api"; - -type Q< - O extends OntologyDefinition, - K extends ObjectTypeKeysFrom, - P extends ObjectTypePropertyKeysFrom, -> = ObjectTypeDefinitionFrom["properties"][P]["type"] extends "string" ? K - : ObjectTypeDefinitionFrom["properties"][P]["type"] extends "double" ? K - : never; +import type { ObjectOrInterfaceDefinition } from "@osdk/api"; export type AggregatableKeys< - O extends OntologyDefinition, - K extends ObjectTypeKeysFrom, + Q extends ObjectOrInterfaceDefinition, > = keyof { - [P in ObjectTypePropertyKeysFrom]: any; + [P in keyof Q["properties"]]: any; }; diff --git a/packages/client/src/query/aggregations/AggregateOpts.ts b/packages/client/src/query/aggregations/AggregateOpts.ts index 3d59d88f0..63d94f630 100644 --- a/packages/client/src/query/aggregations/AggregateOpts.ts +++ b/packages/client/src/query/aggregations/AggregateOpts.ts @@ -14,11 +14,7 @@ * limitations under the License. */ -import type { - ObjectTypeDefinitionFrom, - ObjectTypeKeysFrom, - OntologyDefinition, -} from "@osdk/api"; +import type { ObjectOrInterfaceDefinition } from "@osdk/api"; import type { AggregationClause, GroupByClause, @@ -26,11 +22,10 @@ import type { } from "../../query/index.js"; export type AggregateOpts< - T extends OntologyDefinition, - K extends ObjectTypeKeysFrom, - AC extends AggregationClause, + Q extends ObjectOrInterfaceDefinition, + AC extends AggregationClause, > = { select: AC; - where?: WhereClause>; - groupBy?: GroupByClause; + where?: WhereClause; + groupBy?: GroupByClause; }; diff --git a/packages/client/src/query/aggregations/AggregationResultsWithGroups.ts b/packages/client/src/query/aggregations/AggregationResultsWithGroups.ts index 9dbfbd59c..9c29771e5 100644 --- a/packages/client/src/query/aggregations/AggregationResultsWithGroups.ts +++ b/packages/client/src/query/aggregations/AggregationResultsWithGroups.ts @@ -14,27 +14,21 @@ * limitations under the License. */ -import type { - ObjectTypeKeysFrom, - ObjectTypePropertyDefinitionFrom, - ObjectTypePropertyKeysFrom, - OntologyDefinition, -} from "@osdk/api"; +import type { ObjectOrInterfaceDefinition } from "@osdk/api"; import type { OsdkObjectPropertyType } from "../../Definitions.js"; import type { AggregationResultsWithoutGroups } from "./AggregationResultsWithoutGroups.js"; import type { AggregationClause } from "./AggregationsClause.js"; import type { GroupByClause } from "./GroupByClause.js"; export type AggregationResultsWithGroups< - O extends OntologyDefinition, - K extends ObjectTypeKeysFrom, - A extends AggregationClause, - G extends GroupByClause | undefined, + Q extends ObjectOrInterfaceDefinition, + A extends AggregationClause, + G extends GroupByClause | undefined, > = { group: { - [P in keyof G & ObjectTypePropertyKeysFrom]: OsdkObjectPropertyType< - ObjectTypePropertyDefinitionFrom + [P in keyof G & keyof Q["properties"]]: OsdkObjectPropertyType< + Q["properties"][P] >; }; - values: AggregationResultsWithoutGroups; + values: AggregationResultsWithoutGroups; }[]; diff --git a/packages/client/src/query/aggregations/AggregationResultsWithoutGroups.ts b/packages/client/src/query/aggregations/AggregationResultsWithoutGroups.ts index 9906dd35f..b6db7bfb0 100644 --- a/packages/client/src/query/aggregations/AggregationResultsWithoutGroups.ts +++ b/packages/client/src/query/aggregations/AggregationResultsWithoutGroups.ts @@ -14,28 +14,22 @@ * limitations under the License. */ -import type { - ObjectTypeKeysFrom, - ObjectTypePropertyDefinitionFrom, - ObjectTypePropertyKeysFrom, - OntologyDefinition, -} from "@osdk/api"; +import type { ObjectOrInterfaceDefinition } from "@osdk/api"; import type { OsdkObjectPropertyType } from "../../Definitions.js"; import type { StringArrayToUnion } from "../../util/StringArrayToUnion.js"; import type { AggregationClause } from "./AggregationsClause.js"; -type SubselectKeys, P extends keyof AC> = +type SubselectKeys, P extends keyof AC> = AC[P] extends readonly string[] | string ? P : never; export type AggregationResultsWithoutGroups< - O extends OntologyDefinition, - K extends ObjectTypeKeysFrom, - AC extends AggregationClause, + Q extends ObjectOrInterfaceDefinition, + AC extends AggregationClause, > = { - [P in ObjectTypePropertyKeysFrom as SubselectKeys]: AC[P] extends + [P in keyof Q["properties"] as SubselectKeys]: AC[P] extends readonly string[] | string ? { [Z in StringArrayToUnion]: Z extends "approximateDistinct" ? number - : OsdkObjectPropertyType>; + : OsdkObjectPropertyType; } : never; }; diff --git a/packages/client/src/query/aggregations/AggregationsClause.test.ts b/packages/client/src/query/aggregations/AggregationsClause.test.ts index 8609c3ac3..6cf601975 100644 --- a/packages/client/src/query/aggregations/AggregationsClause.test.ts +++ b/packages/client/src/query/aggregations/AggregationsClause.test.ts @@ -39,8 +39,7 @@ export type huh = AggregatableKeys< }; actions: {}; queries: {}; - }, - "Todo" + }["objects"]["Todo"] >; export type Q = AggregationClause< @@ -64,8 +63,7 @@ export type Q = AggregationClause< }; actions: {}; queries: {}; - }, - "Todo" + }["objects"]["Todo"] >; describe("AggregationClause", () => { diff --git a/packages/client/src/query/aggregations/AggregationsClause.ts b/packages/client/src/query/aggregations/AggregationsClause.ts index f8875505a..19383c823 100644 --- a/packages/client/src/query/aggregations/AggregationsClause.ts +++ b/packages/client/src/query/aggregations/AggregationsClause.ts @@ -14,11 +14,7 @@ * limitations under the License. */ -import type { - ObjectTypeKeysFrom, - ObjectTypePropertyDefinitionsFrom, - OntologyDefinition, -} from "@osdk/api"; +import type { ObjectOrInterfaceDefinition } from "@osdk/api"; import type { AggregatableKeys } from "./AggregatableKeys.js"; type StringAggregateOption = "approximateDistinct"; @@ -30,15 +26,11 @@ type NumericAggregateOption = | "approximateDistinct"; export type AggregationClause< - O extends OntologyDefinition, - K extends ObjectTypeKeysFrom, + Q extends ObjectOrInterfaceDefinition, > = { - [P in AggregatableKeys]?: ObjectTypePropertyDefinitionsFrom< - O, - K - >[P]["type"] extends "string" + [P in AggregatableKeys]?: Q["properties"][P]["type"] extends "string" ? StringAggregateOption | StringAggregateOption[] - : ObjectTypePropertyDefinitionsFrom[P]["type"] extends "double" + : Q["properties"][P]["type"] extends "double" ? NumericAggregateOption | NumericAggregateOption[] - : ObjectTypePropertyDefinitionsFrom[P]["type"]; + : Q["properties"][P]["type"]; }; diff --git a/packages/client/src/query/aggregations/AggregationsResults.test.ts b/packages/client/src/query/aggregations/AggregationsResults.test.ts index 47b69d628..9774a03ce 100644 --- a/packages/client/src/query/aggregations/AggregationsResults.test.ts +++ b/packages/client/src/query/aggregations/AggregationsResults.test.ts @@ -39,8 +39,7 @@ type T_AGG_RESULTS_TEST_1 = AggregationsResults< }; actions: {}; queries: {}; - }, - "Todo", + }["objects"]["Todo"], { select: { locationCity: "approximateDistinct"; @@ -73,8 +72,7 @@ type Q = AggregationResultsWithoutGroups< }; actions: {}; queries: {}; - }, - "Todo", + }["objects"]["Todo"], { locationCity: "approximateDistinct"; id: ["max", "sum"]; diff --git a/packages/client/src/query/aggregations/AggregationsResults.ts b/packages/client/src/query/aggregations/AggregationsResults.ts index 30128c21b..0dc8e6092 100644 --- a/packages/client/src/query/aggregations/AggregationsResults.ts +++ b/packages/client/src/query/aggregations/AggregationsResults.ts @@ -14,17 +14,16 @@ * limitations under the License. */ -import type { ObjectTypeKeysFrom, OntologyDefinition } from "@osdk/api"; +import type { ObjectOrInterfaceDefinition } from "@osdk/api"; import type { AggregateOpts } from "./AggregateOpts.js"; import type { AggregationResultsWithGroups } from "./AggregationResultsWithGroups.js"; import type { AggregationResultsWithoutGroups } from "./AggregationResultsWithoutGroups.js"; export type AggregationsResults< - T extends OntologyDefinition, - K extends ObjectTypeKeysFrom, - AO extends AggregateOpts, + Q extends ObjectOrInterfaceDefinition, + AO extends AggregateOpts, > = unknown extends AO["groupBy"] // groupBy is missing - ? AggregationResultsWithoutGroups + ? AggregationResultsWithoutGroups : Exclude extends never // groupBy is explicitly undefined - ? AggregationResultsWithoutGroups - : AggregationResultsWithGroups; + ? AggregationResultsWithoutGroups + : AggregationResultsWithGroups; diff --git a/packages/client/src/query/aggregations/GroupByClause.test.ts b/packages/client/src/query/aggregations/GroupByClause.test.ts index 48e81c7d0..170399859 100644 --- a/packages/client/src/query/aggregations/GroupByClause.test.ts +++ b/packages/client/src/query/aggregations/GroupByClause.test.ts @@ -38,8 +38,7 @@ export type F = GroupByClause< }; actions: {}; queries: {}; - }, - "Todo" + }["objects"]["Todo"] >; describe("GroupByClause", () => { diff --git a/packages/client/src/query/aggregations/GroupByClause.ts b/packages/client/src/query/aggregations/GroupByClause.ts index ab9c084ac..243760632 100644 --- a/packages/client/src/query/aggregations/GroupByClause.ts +++ b/packages/client/src/query/aggregations/GroupByClause.ts @@ -14,29 +14,22 @@ * limitations under the License. */ -import type { - ObjectTypeKeysFrom, - ObjectTypePropertyDefinitionFrom, - OntologyDefinition, -} from "@osdk/api"; +import type { ObjectOrInterfaceDefinition } from "@osdk/api"; import type { AggregatableKeys } from "./AggregatableKeys.js"; import type { GroupByMapper } from "./GroupByMapper.js"; export type GroupByClause< - O extends OntologyDefinition, - K extends ObjectTypeKeysFrom, + Q extends ObjectOrInterfaceDefinition, > = { - [P in AggregatableKeys]?: GroupByEntry; + [P in AggregatableKeys]?: GroupByEntry; }; export type StringGroupByValue = "exact" | { exactWithLimit: number }; type GroupByEntry< - O extends OntologyDefinition, - K extends ObjectTypeKeysFrom, - P extends AggregatableKeys, -> = ObjectTypePropertyDefinitionFrom["type"] extends - keyof GroupByMapper - ? GroupByMapper[ObjectTypePropertyDefinitionFrom["type"]] + Q extends ObjectOrInterfaceDefinition, + P extends AggregatableKeys, +> = Q["properties"][P]["type"] extends keyof GroupByMapper + ? GroupByMapper[Q["properties"][P]["type"]] : never; export type AllGroupByValues = GroupByMapper[keyof GroupByMapper]; From ac4acd3c16b45d55e4193b1fb43032ef9a92e34f Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 13 Feb 2024 15:11:13 -0500 Subject: [PATCH 16/19] Prep is nearly complete --- ...fetchAggregationForEmployeesGroupedThin.ts | 4 +- .../cli/src/examples/fetchEmployeePageThin.ts | 30 +++++--- packages/client/src/Client.ts | 5 +- packages/client/src/ObjectSetCreator.ts | 12 +++- packages/client/src/actions/Actions.ts | 4 +- packages/client/src/createClient.ts | 51 +++++++++----- .../src/object/aggregateOrThrow.test.ts | 69 ++++++++++++------- .../client/src/object/aggregateOrThrow.ts | 16 ++--- .../client/src/object/fetchPageOrThrow.ts | 18 +++-- packages/client/src/objectSet/ObjectSet.ts | 19 ++--- .../objectSet/ObjectSetListenerWebsocket.ts | 9 ++- .../client/src/objectSet/createObjectSet.ts | 22 +++--- packages/client/src/util/toDataValue.ts | 4 +- 13 files changed, 156 insertions(+), 107 deletions(-) diff --git a/examples/basic/cli/src/examples/fetchAggregationForEmployeesGroupedThin.ts b/examples/basic/cli/src/examples/fetchAggregationForEmployeesGroupedThin.ts index 044ca8e4b..c7b97e620 100644 --- a/examples/basic/cli/src/examples/fetchAggregationForEmployeesGroupedThin.ts +++ b/examples/basic/cli/src/examples/fetchAggregationForEmployeesGroupedThin.ts @@ -16,7 +16,7 @@ import type { ClientContext } from "@osdk/client"; import { aggregateOrThrow } from "@osdk/client/objects"; -import type { Ontology } from "@osdk/examples.basic.sdk"; +import { Ontology } from "@osdk/examples.basic.sdk"; import invariant from "tiny-invariant"; import type { TypeOf } from "ts-expect"; import { expectType } from "ts-expect"; @@ -24,7 +24,7 @@ import { expectType } from "ts-expect"; export async function fetchAggregationForEmployeesGroupedThin( clientCtx: ClientContext, ) { - const result = await aggregateOrThrow(clientCtx, "Employee", { + const result = await aggregateOrThrow(clientCtx, Ontology.objects.Employee, { select: { locationCity: "approximateDistinct", locationName: "approximateDistinct", diff --git a/examples/basic/cli/src/examples/fetchEmployeePageThin.ts b/examples/basic/cli/src/examples/fetchEmployeePageThin.ts index b618662b8..3c6214533 100644 --- a/examples/basic/cli/src/examples/fetchEmployeePageThin.ts +++ b/examples/basic/cli/src/examples/fetchEmployeePageThin.ts @@ -18,14 +18,14 @@ import * as OsdkApi from "@osdk/client"; import type { ClientContext } from "@osdk/client"; import { Objects } from "@osdk/client"; import { fetchPageOrThrow } from "@osdk/client/objects"; -import type { Ontology } from "@osdk/examples.basic.sdk"; +import { Ontology } from "@osdk/examples.basic.sdk"; import type { TypeOf } from "ts-expect"; import { expectType } from "ts-expect"; export async function fetchEmployeePageThin( clientCtx: ClientContext, ) { - let result = await fetchPageOrThrow(clientCtx, "Employee", { + let result = await fetchPageOrThrow(clientCtx, Ontology.objects.Employee, { select: ["adUsername", "businessTitle", "employeeNumber"], }); @@ -42,17 +42,29 @@ export async function fetchEmployeePageThin( >(false); // OR - let result2 = await Objects.fetchPageOrThrow(clientCtx, "Employee", { - select: ["adUsername", "businessTitle", "employeeNumber"], - }); + let result2 = await Objects.fetchPageOrThrow( + clientCtx, + Ontology.objects.Employee, + { + select: ["adUsername", "businessTitle", "employeeNumber"], + }, + ); // or - let result3 = await OsdkApi.Objects.fetchPageOrThrow(clientCtx, "Employee", { - select: ["adUsername", "businessTitle", "employeeNumber"], - }); + let result3 = await OsdkApi.Objects.fetchPageOrThrow( + clientCtx, + Ontology.objects.Employee, + { + select: ["adUsername", "businessTitle", "employeeNumber"], + }, + ); // Quick check to make sure we get everything - let result4 = await fetchPageOrThrow(clientCtx, "Employee", {}); + let result4 = await fetchPageOrThrow( + clientCtx, + Ontology.objects.Employee, + {}, + ); console.log("fetchEmployeePageThin(): "); console.table( diff --git a/packages/client/src/Client.ts b/packages/client/src/Client.ts index 1237d9a41..f14d3ab51 100644 --- a/packages/client/src/Client.ts +++ b/packages/client/src/Client.ts @@ -15,6 +15,7 @@ */ import type { + ObjectOrInterfaceDefinitionFrom, ObjectOrInterfaceKeysFrom, ObjectTypeKeysFrom, OntologyDefinition, @@ -26,7 +27,7 @@ import type { ObjectSetCreator } from "./ObjectSetCreator.js"; export interface Client> { objectSet: >( type: K, - ) => ObjectSet; + ) => ObjectSet>; objects: ObjectSetCreator; @@ -35,5 +36,5 @@ export interface Client> { __UNSTABLE_preexistingObjectSet>( type: K, rid: string, - ): ObjectSet; + ): ObjectSet>; } diff --git a/packages/client/src/ObjectSetCreator.ts b/packages/client/src/ObjectSetCreator.ts index c8519d14d..11e7b2bcd 100644 --- a/packages/client/src/ObjectSetCreator.ts +++ b/packages/client/src/ObjectSetCreator.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import type { ObjectOrInterfaceKeysFrom, OntologyDefinition } from "@osdk/api"; +import type { + ObjectOrInterfaceDefinitionFrom, + ObjectOrInterfaceKeysFrom, + OntologyDefinition, +} from "@osdk/api"; import type { ClientContext } from "@osdk/shared.net"; import type { Client } from "./Client.js"; import type { ObjectSet } from "./objectSet/ObjectSet.js"; @@ -22,8 +26,10 @@ import type { ObjectSet } from "./objectSet/ObjectSet.js"; /** * A type that creates an object set for each object in the ontology. */ -export type ObjectSetCreator> = { - [T in ObjectOrInterfaceKeysFrom]: ObjectSet; +export type ObjectSetCreator> = { + [T in ObjectOrInterfaceKeysFrom]: ObjectSet< + ObjectOrInterfaceDefinitionFrom + >; }; /** diff --git a/packages/client/src/actions/Actions.ts b/packages/client/src/actions/Actions.ts index cd2f2dc13..a45b10106 100644 --- a/packages/client/src/actions/Actions.ts +++ b/packages/client/src/actions/Actions.ts @@ -16,6 +16,7 @@ import type { ObjectActionDataType, + ObjectOrInterfaceDefinitionFrom, ObjectSetActionDataType, OntologyDefinition, WirePropertyTypes, @@ -76,7 +77,8 @@ type OsdkActionParameterBaseType< | OsdkObjectFrom | OsdkObjectPrimaryKeyType : ActionParameterTypeFrom extends - ObjectSetActionDataType ? ObjectSet + ObjectSetActionDataType + ? ObjectSet> : ActionParameterTypeFrom extends keyof OverrideWirePropertyTypes ? OverrideWirePropertyTypes[ActionParameterTypeFrom] : never; diff --git a/packages/client/src/createClient.ts b/packages/client/src/createClient.ts index 503e06f87..0a3fbbb08 100644 --- a/packages/client/src/createClient.ts +++ b/packages/client/src/createClient.ts @@ -14,7 +14,12 @@ * limitations under the License. */ -import type { ObjectTypeKeysFrom, OntologyDefinition } from "@osdk/api"; +import type { + ObjectOrInterfaceDefinitionFrom, + ObjectOrInterfaceKeysFrom, + ObjectTypeKeysFrom, + OntologyDefinition, +} from "@osdk/api"; import { createClientContext } from "@osdk/shared.net"; import { createActionInvoker } from "./actions/createActionInvoker.js"; import type { Client } from "./Client.js"; @@ -37,8 +42,17 @@ export function createClient>( fetchFn, ); - const objectSetFactory: ObjectSetFactory = (type) => - createObjectSet(type, clientCtx); + const objectSetFactory: ObjectSetFactory = < + K extends ObjectOrInterfaceKeysFrom, + >(type: K) => + createObjectSet>( + (ontology["objects"][type] + ?? ontology["interfaces"]?.[type]) as ObjectOrInterfaceDefinitionFrom< + O, + K + >, + clientCtx, + ); const client: Client = Object.defineProperties( {} as Client, @@ -54,19 +68,24 @@ export function createClient>( objectType: K, rid: string, ) => { - return createObjectSet(objectType as K & string, clientCtx, { - type: "intersect", - objectSets: [ - { - type: "base", - objectType: objectType as K & string, - }, - { - type: "reference", - reference: rid, - }, - ], - }); + return createObjectSet( + ontology["interfaces"]?.[objectType] + ?? ontology["objects"][objectType], + clientCtx, + { + type: "intersect", + objectSets: [ + { + type: "base", + objectType: objectType as K & string, + }, + { + type: "reference", + reference: rid, + }, + ], + }, + ); }, }, } satisfies Record, PropertyDescriptor>, diff --git a/packages/client/src/object/aggregateOrThrow.test.ts b/packages/client/src/object/aggregateOrThrow.test.ts index 0f712e248..5082c6fc6 100644 --- a/packages/client/src/object/aggregateOrThrow.test.ts +++ b/packages/client/src/object/aggregateOrThrow.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import type { OntologyDefinition } from "@osdk/api"; +import type { ObjectTypeDefinition, OntologyDefinition } from "@osdk/api"; import type { AggregateObjectSetResponseV2 } from "@osdk/gateway/types"; import { createClientContext } from "@osdk/shared.net"; import type { TypeOf } from "ts-expect"; @@ -24,6 +24,48 @@ import type { AggregateOpts } from "../query/aggregations/AggregateOpts.js"; import { USER_AGENT } from "../util/UserAgent.js"; import { aggregateOrThrow } from "./aggregateOrThrow.js"; +interface TodoDef extends ObjectTypeDefinition<"Todo"> { + type: "object"; + apiName: "Todo"; + links: {}; + primaryKeyType: "double"; + properties: { + text: { + type: "string"; + }; + id: { + type: "double"; + }; + priority: { + type: "double"; + }; + other: { + type: "string"; + }; + }; +} + +const Todo: TodoDef = { + type: "object", + apiName: "Todo", + links: {}, + primaryKeyType: "double", + properties: { + text: { + type: "string", + }, + id: { + type: "double", + }, + priority: { + type: "double", + }, + other: { + type: "string", + }, + }, +}; + const mockOntology = { metadata: { ontologyRid: "ri.a.b.c.d", @@ -31,26 +73,7 @@ const mockOntology = { userAgent: "", }, objects: { - Todo: { - type: "object", - apiName: "Todo", - links: {}, - primaryKeyType: "double", - properties: { - text: { - type: "string", - }, - id: { - type: "double", - }, - priority: { - type: "double", - }, - other: { - type: "string", - }, - }, - }, + Todo, }, actions: {}, queries: {}, @@ -104,7 +127,7 @@ describe("aggregateOrThrow", () => { mockFetch, ); - const notGrouped = await aggregateOrThrow(clientCtx, "Todo", { + const notGrouped = await aggregateOrThrow(clientCtx, Todo, { select: { text: "approximateDistinct", priority: "avg", @@ -125,7 +148,7 @@ describe("aggregateOrThrow", () => { > >(false); // subselect should hide unused keys - const grouped = await aggregateOrThrow(clientCtx, "Todo", { + const grouped = await aggregateOrThrow(clientCtx, Todo, { select: { text: "approximateDistinct", }, diff --git a/packages/client/src/object/aggregateOrThrow.ts b/packages/client/src/object/aggregateOrThrow.ts index 77a79f998..638925c59 100644 --- a/packages/client/src/object/aggregateOrThrow.ts +++ b/packages/client/src/object/aggregateOrThrow.ts @@ -14,11 +14,7 @@ * limitations under the License. */ -import type { - ObjectOrInterfaceDefinitionFrom, - ObjectTypeKeysFrom, - OntologyDefinition, -} from "@osdk/api"; +import type { ObjectOrInterfaceDefinition } from "@osdk/api"; import { aggregateObjectsV2 } from "@osdk/gateway/requests"; import type { AggregateObjectsRequestV2 } from "@osdk/gateway/types"; import { createOpenApiRequest } from "@osdk/shared.net"; @@ -37,13 +33,11 @@ import type { } from "../query/index.js"; export async function aggregateOrThrow< - O extends OntologyDefinition, - K extends ObjectTypeKeysFrom, - Q extends ObjectOrInterfaceDefinitionFrom, + Q extends ObjectOrInterfaceDefinition, const AO extends AggregateOpts, >( - clientCtx: ClientContext, - objectType: K & string, + clientCtx: ClientContext, + objectType: Q, req: AO, ): Promise> { const body: AggregateObjectsRequestV2 = { @@ -68,7 +62,7 @@ export async function aggregateOrThrow< clientCtx.fetch, ), clientCtx.ontology.metadata.ontologyApiName, - objectType, + objectType["apiName"], body, ); diff --git a/packages/client/src/object/fetchPageOrThrow.ts b/packages/client/src/object/fetchPageOrThrow.ts index e33694cfa..b115824ca 100644 --- a/packages/client/src/object/fetchPageOrThrow.ts +++ b/packages/client/src/object/fetchPageOrThrow.ts @@ -16,9 +16,8 @@ import type { ObjectOrInterfaceDefinition, - ObjectOrInterfaceKeysFrom, ObjectOrInterfacePropertyKeysFrom2, - OntologyDefinition, + ObjectTypeDefinition, } from "@osdk/api"; import { loadObjectSetV2 } from "@osdk/gateway/requests"; import type { LoadObjectSetRequestV2, ObjectSet } from "@osdk/gateway/types"; @@ -44,23 +43,22 @@ export interface FetchPageOrThrowArgs< } export async function fetchPageOrThrow< - O extends OntologyDefinition, - T extends ObjectOrInterfaceKeysFrom, - const A extends FetchPageOrThrowArgs, + Q extends ObjectOrInterfaceDefinition, + const A extends FetchPageOrThrowArgs, >( - client: ClientContext, - objectType: T & string, + client: ClientContext, + objectType: Q, args: A, objectSet: ObjectSet = { type: "base", - objectType, + objectType: objectType["apiName"] as string, }, ): Promise< PageResult< OsdkObjectFrom< - O["objects"][T], + Q extends ObjectTypeDefinition ? Q : never, A["select"] extends readonly string[] ? A["select"][number] - : ObjectOrInterfacePropertyKeysFrom2 + : ObjectOrInterfacePropertyKeysFrom2 > > > { diff --git a/packages/client/src/objectSet/ObjectSet.ts b/packages/client/src/objectSet/ObjectSet.ts index a4e51c8b2..adde54cf5 100644 --- a/packages/client/src/objectSet/ObjectSet.ts +++ b/packages/client/src/objectSet/ObjectSet.ts @@ -15,6 +15,7 @@ */ import type { + ObjectOrInterfaceDefinition, ObjectOrInterfaceDefinitionFrom, ObjectOrInterfaceKeysFrom, ObjectOrInterfacePropertyKeysFrom2, @@ -29,16 +30,10 @@ import type { AggregationsResults, WhereClause } from "../query/index.js"; import type { ObjectSetListener } from "./ObjectSetListener.js"; export type ObjectSet< - O extends OntologyDefinition, - K extends ObjectOrInterfaceKeysFrom, -> = BaseObjectSet; + Q extends ObjectOrInterfaceDefinition, +> = BaseObjectSet; -export interface BaseObjectSet< - O extends OntologyDefinition, - K extends ObjectOrInterfaceKeysFrom, - Q extends ObjectOrInterfaceDefinitionFrom = - ObjectOrInterfaceDefinitionFrom, -> { +export interface BaseObjectSet { definition: WireObjectSet; fetchPageOrThrow: < @@ -77,11 +72,11 @@ export interface BaseObjectSet< where: ( clause: WhereClause, - ) => ObjectSet; + ) => ObjectSet; pivotTo: ( type: T & string, - ) => ObjectSet; + ) => ObjectSet>; subscribe: (listener: ObjectSetListener) => () => void; } @@ -90,4 +85,4 @@ export type ObjectSetFactory> = < K extends ObjectOrInterfaceKeysFrom, >( type: K & string, -) => ObjectSet; // FIXME +) => ObjectSet>; // FIXME diff --git a/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts b/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts index ca2de9304..06aabc073 100644 --- a/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts +++ b/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts @@ -15,8 +15,7 @@ */ import type { - ObjectOrInterfaceDefinitionFrom, - ObjectOrInterfaceKeysFrom, + ObjectOrInterfaceDefinition, ObjectTypeKeysFrom, OntologyDefinition, } from "@osdk/api"; @@ -74,7 +73,7 @@ export class ObjectSetListenerWebsocket< #ws: WebSocket | undefined; #lastWsConnect = 0; - #client: ClientContext; + #client: ClientContext; /** map of listenerId to listener */ #listeners = new Map< @@ -118,9 +117,9 @@ export class ObjectSetListenerWebsocket< }; } - subscribe>( + subscribe( objectSet: ObjectSet, - listener: ObjectSetListener>, + listener: ObjectSetListener, ): () => void { const requestId = crypto.randomUUID(); const expiry = setTimeout(() => { diff --git a/packages/client/src/objectSet/createObjectSet.ts b/packages/client/src/objectSet/createObjectSet.ts index 0a1510830..4017b1e28 100644 --- a/packages/client/src/objectSet/createObjectSet.ts +++ b/packages/client/src/objectSet/createObjectSet.ts @@ -15,7 +15,7 @@ */ import type { - ObjectOrInterfaceDefinitionFrom, + ObjectOrInterfaceDefinition, ObjectOrInterfaceKeysFrom, OntologyDefinition, } from "@osdk/api"; @@ -34,15 +34,16 @@ const searchAroundPrefix = "searchAround_"; export function createObjectSet< O extends OntologyDefinition, K extends ObjectOrInterfaceKeysFrom, + Q extends ObjectOrInterfaceDefinition, >( - objectType: K & string, - clientCtx: ClientContext, + objectType: Q, + clientCtx: ClientContext, objectSet: WireObjectSet = { type: "base", - objectType, + objectType: objectType["apiName"] as string, }, -): ObjectSet { - const base: BaseObjectSet = { +): ObjectSet { + const base: BaseObjectSet = { definition: objectSet, // aggregate: < // AC extends AggregationClause, @@ -55,10 +56,9 @@ export function createObjectSet< // throw "TODO"; // }, aggregateOrThrow: async < - AC extends AggregationClause>, + AC extends AggregationClause, // GBC extends GroupByClause, - AO extends AggregateOpts, AC>, - Q extends ObjectOrInterfaceDefinitionFrom, + AO extends AggregateOpts, >( req: AO, ): Promise> => { @@ -92,7 +92,7 @@ export function createObjectSet< pivotTo: function>( type: T & string, - ): ObjectSet { + ): ObjectSet { return createSearchAround(type)(); }, @@ -116,7 +116,7 @@ export function createObjectSet< }; } - return new Proxy(base as ObjectSet, { + return new Proxy(base as ObjectSet, { get(target, p, receiver) { if (typeof p === "string" && p.startsWith(searchAroundPrefix)) { return createSearchAround(p.substring(searchAroundPrefix.length)); diff --git a/packages/client/src/util/toDataValue.ts b/packages/client/src/util/toDataValue.ts index 6311feb07..e5f80608a 100644 --- a/packages/client/src/util/toDataValue.ts +++ b/packages/client/src/util/toDataValue.ts @@ -70,7 +70,7 @@ export function toDataValue(value: any): DataValue { return value; } -function isObjectSet(o: any): o is ObjectSet { +function isObjectSet(o: any): o is ObjectSet { return o != null && typeof o === "object" - && isWireObjectSet((o as ObjectSet).definition); + && isWireObjectSet((o as ObjectSet).definition); } From 28d5315f594d33e79b43b723d04c5bf19623324b Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 13 Feb 2024 15:16:47 -0500 Subject: [PATCH 17/19] More legacy types --- packages/client/src/createClient.ts | 2 +- packages/client/src/objectSet/LinkTypesFrom.ts | 7 +++---- packages/client/src/objectSet/ObjectSet.ts | 2 +- packages/client/src/objectSet/createObjectSet.ts | 16 +++++----------- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/packages/client/src/createClient.ts b/packages/client/src/createClient.ts index 0a3fbbb08..f981b2fd7 100644 --- a/packages/client/src/createClient.ts +++ b/packages/client/src/createClient.ts @@ -45,7 +45,7 @@ export function createClient>( const objectSetFactory: ObjectSetFactory = < K extends ObjectOrInterfaceKeysFrom, >(type: K) => - createObjectSet>( + createObjectSet>( (ontology["objects"][type] ?? ontology["interfaces"]?.[type]) as ObjectOrInterfaceDefinitionFrom< O, diff --git a/packages/client/src/objectSet/LinkTypesFrom.ts b/packages/client/src/objectSet/LinkTypesFrom.ts index 2ca56e9cd..752e0d5ec 100644 --- a/packages/client/src/objectSet/LinkTypesFrom.ts +++ b/packages/client/src/objectSet/LinkTypesFrom.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import type { ObjectTypeKeysFrom, OntologyDefinition } from "@osdk/api"; +import type { ObjectOrInterfaceDefinition } from "@osdk/api"; export type LinkTypesFrom< - O extends OntologyDefinition, - K extends ObjectTypeKeysFrom, -> = keyof O["objects"][K]["links"]; + Q extends ObjectOrInterfaceDefinition, +> = keyof Q["links"]; diff --git a/packages/client/src/objectSet/ObjectSet.ts b/packages/client/src/objectSet/ObjectSet.ts index adde54cf5..457cbd6e6 100644 --- a/packages/client/src/objectSet/ObjectSet.ts +++ b/packages/client/src/objectSet/ObjectSet.ts @@ -85,4 +85,4 @@ export type ObjectSetFactory> = < K extends ObjectOrInterfaceKeysFrom, >( type: K & string, -) => ObjectSet>; // FIXME +) => ObjectSet>; diff --git a/packages/client/src/objectSet/createObjectSet.ts b/packages/client/src/objectSet/createObjectSet.ts index 4017b1e28..8270a8cf9 100644 --- a/packages/client/src/objectSet/createObjectSet.ts +++ b/packages/client/src/objectSet/createObjectSet.ts @@ -14,11 +14,7 @@ * limitations under the License. */ -import type { - ObjectOrInterfaceDefinition, - ObjectOrInterfaceKeysFrom, - OntologyDefinition, -} from "@osdk/api"; +import type { ObjectOrInterfaceDefinition } from "@osdk/api"; import type { ObjectSet as WireObjectSet } from "@osdk/gateway/types"; import type { ClientContext } from "@osdk/shared.net"; import { modernToLegacyWhereClause } from "../internal/conversions/index.js"; @@ -32,8 +28,6 @@ import { ObjectSetListenerWebsocket } from "./ObjectSetListenerWebsocket.js"; const searchAroundPrefix = "searchAround_"; export function createObjectSet< - O extends OntologyDefinition, - K extends ObjectOrInterfaceKeysFrom, Q extends ObjectOrInterfaceDefinition, >( objectType: Q, @@ -67,7 +61,7 @@ export function createObjectSet< // fetchPage: async (args?: { nextPageToken?: string }) => { // throw "TODO"; // }, - fetchPageOrThrow: async (args?: FetchPageOrThrowArgs) => { + fetchPageOrThrow: async (args?: FetchPageOrThrowArgs) => { return fetchPageOrThrow( clientCtx, objectType, @@ -90,9 +84,9 @@ export function createObjectSet< // throw ""; // }, - pivotTo: function>( + pivotTo: function>( type: T & string, - ): ObjectSet { + ): ObjectSet { return createSearchAround(type)(); }, @@ -102,7 +96,7 @@ export function createObjectSet< }, }; - function createSearchAround>(link: S & string) { + function createSearchAround>(link: S & string) { return () => { return createObjectSet( objectType, From 2d40fd997b16f84adb9c7afbdd3abf31c616c7f3 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 13 Feb 2024 17:06:54 -0500 Subject: [PATCH 18/19] Fix test --- .../legacy-client/src/client/objectSets/OsdkObjectSet.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/legacy-client/src/client/objectSets/OsdkObjectSet.test.ts b/packages/legacy-client/src/client/objectSets/OsdkObjectSet.test.ts index ad26a9e34..ad4790b31 100644 --- a/packages/legacy-client/src/client/objectSets/OsdkObjectSet.test.ts +++ b/packages/legacy-client/src/client/objectSets/OsdkObjectSet.test.ts @@ -60,9 +60,10 @@ describe("OsdkObjectSet", () => { it("exposes descriptions", () => { const os = createBaseTodoObjectSet(client); + console.log(os); expect(os.description).toEqual("A todo object"); expect(os.properties.id.apiName).toEqual("id"); - expect(os.properties.id.description).toEqual("The id of the Todo Object"); + expect(os.properties.id.description).toEqual("The id"); expect(os.properties.body.apiName).toEqual("body"); expect(os.properties.body.description).toEqual(""); }); From d6c8a0dcac912928329cafa42c1293b0e59d7b9d Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Tue, 13 Feb 2024 22:10:12 +0000 Subject: [PATCH 19/19] Add generated changelog entries --- packages/api/changelog/@unreleased/pr-48.v2.yml | 5 +++++ packages/client/changelog/@unreleased/pr-48.v2.yml | 5 +++++ packages/generator/changelog/@unreleased/pr-48.v2.yml | 5 +++++ packages/legacy-client/changelog/@unreleased/pr-48.v2.yml | 5 +++++ packages/shared.test/changelog/@unreleased/pr-48.v2.yml | 5 +++++ 5 files changed, 25 insertions(+) create mode 100644 packages/api/changelog/@unreleased/pr-48.v2.yml create mode 100644 packages/client/changelog/@unreleased/pr-48.v2.yml create mode 100644 packages/generator/changelog/@unreleased/pr-48.v2.yml create mode 100644 packages/legacy-client/changelog/@unreleased/pr-48.v2.yml create mode 100644 packages/shared.test/changelog/@unreleased/pr-48.v2.yml diff --git a/packages/api/changelog/@unreleased/pr-48.v2.yml b/packages/api/changelog/@unreleased/pr-48.v2.yml new file mode 100644 index 000000000..f66637221 --- /dev/null +++ b/packages/api/changelog/@unreleased/pr-48.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Prep for new client syntax + links: + - https://github.com/palantir/osdk-ts/pull/48 diff --git a/packages/client/changelog/@unreleased/pr-48.v2.yml b/packages/client/changelog/@unreleased/pr-48.v2.yml new file mode 100644 index 000000000..f66637221 --- /dev/null +++ b/packages/client/changelog/@unreleased/pr-48.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Prep for new client syntax + links: + - https://github.com/palantir/osdk-ts/pull/48 diff --git a/packages/generator/changelog/@unreleased/pr-48.v2.yml b/packages/generator/changelog/@unreleased/pr-48.v2.yml new file mode 100644 index 000000000..f66637221 --- /dev/null +++ b/packages/generator/changelog/@unreleased/pr-48.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Prep for new client syntax + links: + - https://github.com/palantir/osdk-ts/pull/48 diff --git a/packages/legacy-client/changelog/@unreleased/pr-48.v2.yml b/packages/legacy-client/changelog/@unreleased/pr-48.v2.yml new file mode 100644 index 000000000..f66637221 --- /dev/null +++ b/packages/legacy-client/changelog/@unreleased/pr-48.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Prep for new client syntax + links: + - https://github.com/palantir/osdk-ts/pull/48 diff --git a/packages/shared.test/changelog/@unreleased/pr-48.v2.yml b/packages/shared.test/changelog/@unreleased/pr-48.v2.yml new file mode 100644 index 000000000..f66637221 --- /dev/null +++ b/packages/shared.test/changelog/@unreleased/pr-48.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Prep for new client syntax + links: + - https://github.com/palantir/osdk-ts/pull/48