Skip to content

Commit

Permalink
Fix action params issue with objects (#458)
Browse files Browse the repository at this point in the history
* fix

* added changeset
  • Loading branch information
ssanjay1 authored Jul 11, 2024
1 parent 4eb05a1 commit 7afa226
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/new-points-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osdk/client": patch
---

Fix action params that take objects to correctly parse out primary key.
22 changes: 22 additions & 0 deletions packages/client/src/util/isOsdkObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2024 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 type { OsdkBase } from "@osdk/client.api";

export function isOsdkBaseObject(o: any): o is OsdkBase<any> {
return o && typeof o === "object" && typeof o.$apiName === "string"
&& o.$primaryKey != null;
}
11 changes: 10 additions & 1 deletion packages/client/src/util/toDataValue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { Ontology } from "@osdk/client.test.ontology";
import { apiServer, MockOntology, stubData } from "@osdk/shared.test";
import type { MockedFunction } from "vitest";
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
Expand All @@ -35,7 +36,7 @@ describe(toDataValue, () => {
apiServer.listen();
client = createClient(
"https://stack.palantir.com",
MockOntology.metadata.ontologyRid,
Ontology.metadata.ontologyRid,
async () => "myAccessToken",
);

Expand Down Expand Up @@ -105,6 +106,14 @@ describe(toDataValue, () => {
);
});

it("maps an ontology object into just its primary key with osdk wrapper", async () => {
const task = await client(Ontology.objects.Employee).fetchOne(50030);
const ontologyConversion = await toDataValue(task, clientCtx);
expect(ontologyConversion).toEqual(
task.$primaryKey,
);
});

it("passes through object set definitions", async () => {
const clientObjectSet = client(MockOntology.objects.Task).where({ id: 0 });
const definition = getWireObjectSet(clientObjectSet);
Expand Down
5 changes: 5 additions & 0 deletions packages/client/src/util/toDataValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { MinimalClient } from "../MinimalClientContext.js";
import { isAttachmentUpload } from "../object/AttachmentUpload.js";
import { getWireObjectSet, isObjectSet } from "../objectSet/createObjectSet.js";
import { isOntologyObjectV2 } from "./isOntologyObjectV2.js";
import { isOsdkBaseObject } from "./isOsdkObject.js";
import { isWireObjectSet } from "./WireObjectSet.js";

/**
Expand Down Expand Up @@ -65,6 +66,10 @@ export async function toDataValue(
return await toDataValue(value.__primaryKey, client);
}

if (isOsdkBaseObject(value)) {
return await toDataValue(value.$primaryKey, client);
}

// object set (the rid as a string (passes through the last return), or the ObjectSet definition directly)
if (isWireObjectSet(value)) {
return value;
Expand Down

0 comments on commit 7afa226

Please sign in to comment.