Skip to content

Commit

Permalink
It is possible to pass a Promise<string> for ontologyRid on client cr…
Browse files Browse the repository at this point in the history
…eation (#440)
  • Loading branch information
ericanderson authored Jul 8, 2024
1 parent a8dc51a commit 57b68db
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-kiwis-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osdk/client": patch
---

It is possible to pass a Promise<string> for ontologyRid on client creation
4 changes: 2 additions & 2 deletions packages/client/src/MinimalClientContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { ObjectSetFactory } from "./objectSet/ObjectSetFactory.js";
import type { OntologyProvider } from "./ontology/OntologyProvider.js";

export interface MinimalClient extends SharedClientContext {
ontologyRid: string;
ontologyRid: string | Promise<string>;
ontologyProvider: OntologyProvider;
logger?: Logger;
objectSetFactory: ObjectSetFactory<any, any>;
Expand All @@ -32,5 +32,5 @@ export type MinimalClientParams = {
};

export interface MinimalClientMetadata {
ontologyRid: string;
ontologyRid: string | Promise<string>;
}
4 changes: 2 additions & 2 deletions packages/client/src/__unstable/ConjureSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ export class MetadataClient {
return entities.objectTypes[objectTypeRid];
});

ontologyVersion = strongMemoAsync((_: string) =>
getOntologyVersionForRid(this.#ctx, this.#client.ontologyRid)
ontologyVersion = strongMemoAsync(async (_: string) =>
getOntologyVersionForRid(this.#ctx, await this.#client.ontologyRid)
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/actions/applyAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function applyAction<
if (Array.isArray(parameters)) {
const response = await OntologiesV2.Actions.applyActionBatchV2(
addUserAgent(client, action),
client.ontologyRid,
await client.ontologyRid,
action.apiName,
{
requests: parameters
Expand All @@ -66,7 +66,7 @@ export async function applyAction<
} else {
const response = await OntologiesV2.Actions.applyActionV2(
addUserAgent(client, action),
client.ontologyRid,
await client.ontologyRid,
action.apiName,
{
parameters: await remapActionParams(
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/createClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ActionInvoker<Q extends ActionDefinition<any, any, any>>
export function createClientInternal(
objectSetFactory: ObjectSetFactory<any, any>, // first so i can bind
baseUrl: string,
ontologyRid: string,
ontologyRid: string | Promise<string>,
tokenProvider: () => Promise<string>,
options: { logger?: Logger } | undefined = undefined,
fetchFn: typeof globalThis.fetch = fetch,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/object/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function aggregate<
}
const result = await OntologiesV2.OntologyObjectSets.aggregateObjectSetV2(
addUserAgent(clientCtx, objectType),
clientCtx.ontologyRid,
await clientCtx.ontologyRid,
{
objectSet,
groupBy: body.groupBy,
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/object/fetchPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async function fetchInterfacePage<
): Promise<FetchPageResult<Q, L, R, S>> {
const result = await OntologiesV2.OntologyObjectsV2.searchObjectsForInterface(
addUserAgent(client, interfaceType),
client.ontologyRid,
await client.ontologyRid,
interfaceType.apiName,
applyFetchArgs<SearchObjectsForInterfaceRequest>(args, {
augmentedProperties: args.$augment ?? {},
Expand Down Expand Up @@ -238,7 +238,7 @@ export async function fetchObjectPage<
): Promise<FetchPageResult<Q, L, R, S>> {
const r = await OntologiesV2.OntologyObjectSets.loadObjectSetV2(
addUserAgent(client, objectType),
client.ontologyRid,
await client.ontologyRid,
applyFetchArgs<LoadObjectSetRequestV2>(args, {
objectSet,
// We have to do the following case because LoadObjectSetRequestV2 isnt readonly
Expand Down
10 changes: 7 additions & 3 deletions packages/client/src/objectSet/ObjectSetListenerWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ export class ObjectSetListenerWebsocket {
// in `#createTemporaryObjectSet`. They should be in sync
sub.expiry = setTimeout(() => this.#expire(sub), this.OBJECT_SET_EXPIRY_MS);

const ontologyRid = await this.#client.ontologyRid;

try {
const [temporaryObjectSet] = await Promise.all([
// create a time-bounded object set representation for watching
Expand All @@ -243,7 +245,7 @@ export class ObjectSetListenerWebsocket {
getObjectSetBaseType(sub.objectSet).then(baseType =>
OntologiesV2.ObjectTypesV2.getObjectTypeV2(
this.#client,
this.#client.ontologyRid,
ontologyRid,
baseType,
)
).then(
Expand Down Expand Up @@ -700,16 +702,18 @@ async function getOntologyPropertyMappingForApiName(
);
}

const ontologyRid = await client.ontologyRid;

const wireObjectType = await OntologiesV2.ObjectTypesV2
.getObjectTypeV2(
client,
client.ontologyRid,
ontologyRid,
objectApiName,
);

return getOntologyPropertyMappingForRid(
ctx,
client.ontologyRid,
ontologyRid,
wireObjectType.rid,
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/ontology/loadFullObjectMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function loadFullObjectMetadata(
): Promise<ObjectTypeDefinition<any, any> & { rid: string }> {
const full = await OntologiesV2.OntologyObjectsV2.getObjectTypeFullMetadata(
client,
client.ontologyRid,
await client.ontologyRid,
objtype,
{ preview: true },
);
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/ontology/loadInterfaceDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function loadInterfaceDefinition(
): Promise<InterfaceDefinition<any, any>> {
const r = await OntologiesV2.OntologyObjectsV2.getInterfaceType(
client,
client.ontologyRid,
await client.ontologyRid,
objtype,
{ preview: true },
);
Expand Down

0 comments on commit 57b68db

Please sign in to comment.