Skip to content

Commit

Permalink
Merge pull request #48 from palantir/mf/callable-client
Browse files Browse the repository at this point in the history
Prep for client(Foo) syntax
  • Loading branch information
ericanderson authored Feb 14, 2024
2 parents f7f4441 + d6c8a0d commit 28b5f8c
Show file tree
Hide file tree
Showing 90 changed files with 1,555 additions and 761 deletions.
6 changes: 4 additions & 2 deletions examples/basic/cli/src/OntologyType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ontology["objects"]["Employee"]>
{}
export interface Todo extends OsdkObjectFrom<Ontology["objects"]["Todo"]> {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

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";

export async function fetchAggregationForEmployeesGroupedThin(
clientCtx: ClientContext<Ontology>,
) {
const result = await aggregateOrThrow(clientCtx, "Employee", {
const result = await aggregateOrThrow(clientCtx, Ontology.objects.Employee, {
select: {
locationCity: "approximateDistinct",
locationName: "approximateDistinct",
Expand Down
30 changes: 21 additions & 9 deletions examples/basic/cli/src/examples/fetchEmployeePageThin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ontology>,
) {
let result = await fetchPageOrThrow(clientCtx, "Employee", {
let result = await fetchPageOrThrow(clientCtx, Ontology.objects.Employee, {
select: ["adUsername", "businessTitle", "employeeNumber"],
});

Expand All @@ -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(
Expand Down
11 changes: 8 additions & 3 deletions examples/basic/cli/src/typeChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export async function typeChecks(client: Client<Ontology>) {

// lead is an employee
const lead = await employee.$link.lead.get();
expectType<TypeOf<typeof lead, OsdkObjectFrom<"Employee", Ontology>>>(true);
expectType<
TypeOf<typeof lead, OsdkObjectFrom<Ontology["objects"]["Employee"]>>
>(true);

// lead is an employee but we downselect to just their adUsername
const leadName = await employee.$link.lead.get({ select: ["adUsername"] });
Expand All @@ -97,7 +99,10 @@ export async function typeChecks(client: Client<Ontology>) {
TypeOf<
typeof peeps,
PageResult<
OsdkObjectFrom<"Employee", Ontology, "adUsername" | "employeeNumber">
OsdkObjectFrom<
Ontology["objects"]["Employee"],
"adUsername" | "employeeNumber"
>
>
>
>(true);
Expand All @@ -112,7 +117,7 @@ export async function typeChecks(client: Client<Ontology>) {
expectType<
TypeOf<
typeof peepById,
OsdkObjectFrom<"Employee", Ontology, "adUsername">
OsdkObjectFrom<Ontology["objects"]["Employee"], "adUsername">
>
>(
true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ActionDefinition } from '@osdk/api';

export const actionTakesAllParameterTypes = {
type: 'action',
apiName: 'actionTakesAllParameterTypes',
parameters: {
objectSet: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ActionDefinition } from '@osdk/api';

export const createTodo = {
type: 'action',
apiName: 'createTodo',
parameters: {},
description: 'Creates a new Todo',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { InterfaceDefinition } from '@osdk/api';

export const SimpleInterface = {
type: 'interface',
apiName: 'SimpleInterface',
description: 'Its a todo item.',
properties: {
Expand All @@ -26,4 +27,5 @@ export const SimpleInterface = {
nullable: true,
},
},
links: {},
} satisfies InterfaceDefinition<'SimpleInterface', ''>;
Original file line number Diff line number Diff line change
@@ -1,6 +1,62 @@
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<EmployeeDef, false>; peeps: ObjectTypeLinkDefinition<EmployeeDef, true> };
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',
primaryKeyType: 'string',
Expand Down Expand Up @@ -61,4 +117,4 @@ export const Employee = {
nullable: true,
},
},
} satisfies ObjectTypeDefinition<'Employee', 'Employee'>;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,172 @@
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',
Expand Down Expand Up @@ -162,4 +328,4 @@ export const ObjectTypeWithAllPropertyTypes = {
nullable: true,
},
},
} satisfies ObjectTypeDefinition<'ObjectTypeWithAllPropertyTypes', never>;
};
Loading

0 comments on commit 28b5f8c

Please sign in to comment.