Skip to content

Commit

Permalink
fix types and add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
ssanjay1 committed Dec 9, 2024
1 parent 71dcfb2 commit a8be10e
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 54 deletions.
12 changes: 8 additions & 4 deletions etc/api.report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -691,10 +691,11 @@ export type OsdkObjectLinksObject<O extends ObjectTypeDefinition> = ObjectTypeLi
// Warning: (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}'
// Warning: (ae-forgotten-export) The symbol "MaybeArray" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Converted" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "getClientPropertyValueFromWire" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "MaybeNullable" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type OsdkObjectPropertyType<T extends ObjectMetadata.Property, STRICTLY_ENFORCE_NULLABLE extends boolean = true> = STRICTLY_ENFORCE_NULLABLE extends false ? MaybeArray<T, Converted<PropertyValueWireToClient[T["type"]]>> | undefined : MaybeNullable<T, MaybeArray<T, Converted<PropertyValueWireToClient[T["type"]]>>>;
export type OsdkObjectPropertyType<T extends ObjectMetadata.Property, STRICTLY_ENFORCE_NULLABLE extends boolean = true> = STRICTLY_ENFORCE_NULLABLE extends false ? MaybeArray<T, Converted<getClientPropertyValueFromWire<T["type"]>>> | undefined : MaybeNullable<T, MaybeArray<T, Converted<getClientPropertyValueFromWire<T["type"]>>>>;

// @public (undocumented)
export interface PageResult<T> {
Expand Down Expand Up @@ -849,6 +850,9 @@ export interface SelectArg<Q extends ObjectOrInterfaceDefinition, L extends Prop
// @public (undocumented)
export type SelectArgToKeys<Q extends ObjectOrInterfaceDefinition, A extends SelectArg<Q, any, any>> = A extends SelectArg<Q, never> ? PropertyKeys<Q> : A["$select"] extends readonly string[] ? A["$select"][number] : PropertyKeys<Q>;

// @public (undocumented)
export type SimpleWirePropertyTypes = "string" | "datetime" | "double" | "boolean" | "integer" | "timestamp" | "short" | "long" | "float" | "decimal" | "byte" | "marking" | "numericTimeseries" | "stringTimeseries" | "sensorTimeseries" | "attachment" | "geopoint" | "geoshape" | "geotimeSeriesReference";

// @public (undocumented)
export interface SingleLinkAccessor<T extends ObjectTypeDefinition> {
fetchOne: <const A extends SelectArg<T, PropertyKeys<T>, boolean>>(options?: A) => Promise<A extends FetchPageArgs<T, infer L, infer R, any, infer S> ? Osdk.Instance<T, ExtractOptions<R, S>, L> : Osdk.Instance<T>>;
Expand Down Expand Up @@ -942,11 +946,11 @@ export type TimeSeriesQuery = {
export type TwoDimensionalQueryAggregationDefinition = AggregationKeyDataType<"date" | "double" | "timestamp">;

// Warning: (ae-forgotten-export) The symbol "AGG_FOR_TYPE" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "PropertyValueClientToWire" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "getWirePropertyValueFromClient" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type ValidAggregationKeys<Q extends ObjectOrInterfaceDefinition> = keyof ({
[KK in AggregatableKeys<Q> as `${KK & string}:${AGG_FOR_TYPE<PropertyValueClientToWire[CompileTimeMetadata<Q>["properties"][KK]["type"]]>}`]?: any;
[KK in AggregatableKeys<Q> as `${KK & string}:${AGG_FOR_TYPE<getWirePropertyValueFromClient<CompileTimeMetadata<Q>["properties"][KK]["type"]>>}`]?: any;
} & {
$count?: any;
});
Expand All @@ -970,7 +974,7 @@ export type WhereClause<T extends ObjectOrInterfaceDefinition> = OrWhereClause<T
});

// @public (undocumented)
export type WirePropertyTypes = "string" | "datetime" | "double" | "boolean" | "integer" | "timestamp" | "short" | "long" | "float" | "decimal" | "byte" | "marking" | "numericTimeseries" | "stringTimeseries" | "sensorTimeseries" | "attachment" | "geopoint" | "geoshape" | "geotimeSeriesReference";
export type WirePropertyTypes = SimpleWirePropertyTypes | Record<string, SimpleWirePropertyTypes>;

// Warnings were encountered during analysis:
//
Expand Down
38 changes: 28 additions & 10 deletions packages/client/src/objectSet/ObjectSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,28 +215,46 @@ describe("ObjectSet", () => {
expectTypeOf<typeof player>().toMatchTypeOf<
Osdk<BgaoNflPlayer, PropertyKeys<BgaoNflPlayer>>
>;
expectTypeOf<typeof player.address>().toMatchTypeOf<
{
addressLine1: string | undefined;
addressLine2: string | undefined;
city: string | undefined;
state: string | undefined;
zipCode: number | undefined;
} | undefined
>;

expectTypeOf<typeof player.address.addressLine1>().toMatchTypeOf<
const address1 = player.address!.addressLine1;
expectTypeOf<typeof address1>().toMatchTypeOf<
string | undefined
>;
expect(player.address.addressLine1).toEqual("15 Muppets Lane");
expectTypeOf<typeof player.address.addressLine2>().toMatchTypeOf<
expect(address1).toEqual("15 Muppets Lane");

const address2 = player.address?.addressLine2;
expectTypeOf<typeof address2>().toMatchTypeOf<
string | undefined
>;
expect(player.address.addressLine2).toEqual("Resort No 4");
expect(address2).toEqual("Resort No 4");

expectTypeOf<typeof player.address.city>().toMatchTypeOf<
const city = player.address?.city;
expectTypeOf<typeof city>().toMatchTypeOf<
string | undefined
>;
expect(player.address.city).toEqual("Memphis");
expectTypeOf<typeof player.address.state>().toMatchTypeOf<
expect(city).toEqual("Memphis");

const state = player.address?.state;
expectTypeOf<typeof state>().toMatchTypeOf<
string | undefined
>;
expect(player.address.state).toEqual("TN");
expectTypeOf<typeof player.address.zipCode>().toMatchTypeOf<
expect(state).toEqual("TN");

const zipCode = player.address?.zipCode;
expectTypeOf<typeof zipCode>().toMatchTypeOf<
number | undefined
>;
expect(player.address.zipCode).toEqual(11100);
expect(zipCode).toEqual(11100);

expect(player.$primaryKey).toEqual(stubData.travisPlayer.__primaryKey);
expect(player.address).toEqual(stubData.travisPlayer.address);
});
Expand Down
70 changes: 70 additions & 0 deletions packages/e2e.generated.catchall/ontology.json
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,76 @@
},
"linkTypes": []
},
"McAirportStruct": {
"objectType": {
"apiName": "McAirportStruct",
"primaryKey": "airportName",
"displayName": "McAirportStruct",
"description": "McAirportStruct",
"properties": {
"airportName": {
"displayName": "Airport Name",
"dataType": {
"type": "string"
}
},
"city": {
"displayName": "City",
"dataType": {
"type": "string"
}
},
"airportStruct": {
"displayName": "Airport Struct",
"dataType": {
"type": "struct",
"structFieldTypes": [
{
"apiName": "code",
"dataType": {
"type": "string"
}
},
{
"apiName": "geoHash",
"dataType": {
"type": "string"
}
},
{
"apiName": "timestamp",
"dataType": {
"type": "string"
}
}
]
}
},
"state": {
"displayName": "State",
"dataType": {
"type": "string"
}
},
"originDate": {
"displayName": "Origin Date",
"dataType": {
"type": "timestamp"
}
}
},
"status": "ACTIVE",
"rid": "rid.a.b.c.d",
"icon": {
"type": "blueprint",
"name": "mcAirportStruct",
"color": "color"
},
"titleProperty": "airportName",
"pluralDisplayName": "McAirportStructs"
},
"linkTypes": []
},
"BuilderDeploymentState": {
"objectType": {
"apiName": "BuilderDeploymentState",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export {
Employee,
FintrafficAis,
GtfsTripTrackObject,
McAirportStruct,
MtaBus,
ObjectTypeWithAllPropertyTypes,
OsdkTestObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { DherlihyComplexObject } from './objects/DherlihyComplexObject.js';
export { Employee } from './objects/Employee.js';
export { FintrafficAis } from './objects/FintrafficAis.js';
export { GtfsTripTrackObject } from './objects/GtfsTripTrackObject.js';
export { McAirportStruct } from './objects/McAirportStruct.js';
export { MtaBus } from './objects/MtaBus.js';
export { ObjectTypeWithAllPropertyTypes } from './objects/ObjectTypeWithAllPropertyTypes.js';
export { OsdkTestObject } from './objects/OsdkTestObject.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ export namespace BgaoNflPlayer {
export type Links = {};

export interface Props {
readonly address: {
addressLine1: $PropType['string'] | undefined;
addressLine2: $PropType['string'] | undefined;
city: $PropType['string'] | undefined;
state: $PropType['string'] | undefined;
zipCode: $PropType['integer'] | undefined;
};
readonly address:
| {
addressLine1: $PropType['string'] | undefined;
addressLine2: $PropType['string'] | undefined;
city: $PropType['string'] | undefined;
state: $PropType['string'] | undefined;
zipCode: $PropType['integer'] | undefined;
}
| undefined;
readonly gamesPlayed: $PropType['integer'] | undefined;
readonly id: $PropType['string'];
readonly name: $PropType['string'] | undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import type { PropertyDef as $PropertyDef } from '@osdk/client';
import { $osdkMetadata } from '../../OntologyMetadata.js';
import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
import type {
PropertyKeys as $PropertyKeys,
ObjectTypeDefinition as $ObjectTypeDefinition,
ObjectMetadata as $ObjectMetadata,
} from '@osdk/client';
import type {
ObjectSet as $ObjectSet,
Osdk as $Osdk,
OsdkObject as $OsdkObject,
PropertyValueWireToClient as $PropType,
SingleLinkAccessor as $SingleLinkAccessor,
} from '@osdk/client';

export namespace McAirportStruct {
export type PropertyKeys = 'airportName' | 'city' | 'airportStruct' | 'state' | 'originDate';

export type Links = {};

export interface Props {
readonly airportName: $PropType['string'];
readonly airportStruct:
| {
code: $PropType['string'] | undefined;
geoHash: $PropType['string'] | undefined;
timestamp: $PropType['string'] | undefined;
}
| undefined;
readonly city: $PropType['string'] | undefined;
readonly originDate: $PropType['timestamp'] | undefined;
readonly state: $PropType['string'] | undefined;
}
export type StrictProps = Props;

export interface ObjectSet extends $ObjectSet<McAirportStruct, McAirportStruct.ObjectSet> {}

export type OsdkInstance<
OPTIONS extends never | '$rid' = never,
K extends keyof McAirportStruct.Props = keyof McAirportStruct.Props,
> = $Osdk.Instance<McAirportStruct, OPTIONS, K>;

/** @deprecated use OsdkInstance */
export type OsdkObject<
OPTIONS extends never | '$rid' = never,
K extends keyof McAirportStruct.Props = keyof McAirportStruct.Props,
> = OsdkInstance<OPTIONS, K>;
}

export interface McAirportStruct extends $ObjectTypeDefinition {
osdkMetadata: typeof $osdkMetadata;
type: 'object';
apiName: 'McAirportStruct';
__DefinitionMetadata?: {
objectSet: McAirportStruct.ObjectSet;
props: McAirportStruct.Props;
linksType: McAirportStruct.Links;
strictProps: McAirportStruct.StrictProps;
apiName: 'McAirportStruct';
description: 'McAirportStruct';
displayName: 'McAirportStruct';
icon: {
type: 'blueprint';
name: 'mcAirportStruct';
color: 'color';
};
interfaceMap: {};
inverseInterfaceMap: {};
links: {};
pluralDisplayName: 'McAirportStructs';
primaryKeyApiName: 'airportName';
primaryKeyType: 'string';
properties: {
/**
* display name: 'Airport Name'
*/
airportName: $PropertyDef<'string', 'non-nullable', 'single'>;
/**
* display name: 'Airport Struct'
*/
airportStruct: $PropertyDef<{ code: 'string'; geoHash: 'string'; timestamp: 'string' }, 'nullable', 'single'>;
/**
* display name: 'City'
*/
city: $PropertyDef<'string', 'nullable', 'single'>;
/**
* display name: 'Origin Date'
*/
originDate: $PropertyDef<'timestamp', 'nullable', 'single'>;
/**
* display name: 'State'
*/
state: $PropertyDef<'string', 'nullable', 'single'>;
};
rid: 'rid.a.b.c.d';
status: 'ACTIVE';
titleProperty: 'airportName';
type: 'object';
};
}

export const McAirportStruct: McAirportStruct = {
type: 'object',
apiName: 'McAirportStruct',
osdkMetadata: $osdkMetadata,
};
47 changes: 25 additions & 22 deletions packages/e2e.sandbox.catchall/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { runGeotimeSeriesReferenceTests } from "./runGeotimeSeriesTest.js";
import { runInterfacesTest } from "./runInterfacesTest.js";
import { runLegacyExamples } from "./runLegacyExamples.js";
import { runQueriesTest } from "./runQueriesTest.js";
import { runStructsTest } from "./runStructsTest.js";
import { runSubscriptionsTest } from "./runSubscriptionsTest.js";
import { runTimeseriesTest } from "./runTimeseriesTest.js";
import { typeChecks } from "./typeChecks.js";
Expand All @@ -34,40 +35,42 @@ const testSubscriptions = false;

async function runTests() {
try {
await checkUnstableBulkLinks();
// await checkUnstableBulkLinks();

if (runOld) {
await runLegacyExamples();
}
if (testSubscriptions) {
runSubscriptionsTest();
// if (runOld) {
// await runLegacyExamples();
// }
// if (testSubscriptions) {
// runSubscriptionsTest();

// we don't need the console flooded with additional things
return;
}
// // we don't need the console flooded with additional things
// return;
// }

const datasetRid =
"ri.foundry.main.dataset.58070dbb-dd3b-4c82-b012-9c2f8a13dd83";
await runFoundrySdkClientVerificationTest(datasetRid);
// const datasetRid =
// "ri.foundry.main.dataset.58070dbb-dd3b-4c82-b012-9c2f8a13dd83";
// await runFoundrySdkClientVerificationTest(datasetRid);

await runInterfacesTest();
// await runInterfacesTest();

// only works in default ontology
await runGeoQueriesTest();
// // only works in default ontology
// await runGeoQueriesTest();

await runAssignEmployeeToVentureTest();
// await runAssignEmployeeToVentureTest();

await runAggregationsTest();
// await runAggregationsTest();

await runAggregationGroupByDatesTest();
// await runAggregationGroupByDatesTest();

await runQueriesTest();
// await runQueriesTest();

if (runOld) await typeChecks(client);
// if (runOld) await typeChecks(client);

await runTimeseriesTest();
// await runTimeseriesTest();

await runGeotimeSeriesReferenceTests();
// await runGeotimeSeriesReferenceTests();

await runStructsTest();
} catch (e) {
console.error(`Caught an error we did not expect, type: ${typeof e}`);
console.error(e);
Expand Down
Loading

0 comments on commit a8be10e

Please sign in to comment.