diff --git a/packages/client/src/object/convertWireToOsdkObjects.test.ts b/packages/client/src/object/convertWireToOsdkObjects.test.ts index 07ee728f4..d512c3f80 100644 --- a/packages/client/src/object/convertWireToOsdkObjects.test.ts +++ b/packages/client/src/object/convertWireToOsdkObjects.test.ts @@ -14,12 +14,14 @@ * limitations under the License. */ +import { createClientContext } from "@osdk/shared.net"; import { apiServer } from "@osdk/shared.test"; import { afterAll, beforeAll, describe, expect, it } from "vitest"; import type { Client } from "../Client.js"; import { createClient } from "../createClient.js"; import { Ontology as MockOntology } from "../generatedNoCheck/index.js"; import { Attachment } from "./Attachment.js"; +import { convertWireToOsdkObjects } from "./convertWireToOsdkObjects.js"; describe("convertWireToOsdkObjects", () => { let client: Client; @@ -65,4 +67,23 @@ describe("convertWireToOsdkObjects", () => { expect(emptyAttachment).toBeUndefined(); expect(emptyAttachmentArray).toBeUndefined(); }); + + it("works even with unknown apiNames", () => { + const clientCtx = createClientContext( + MockOntology, + "https://stack.palantir.com", + () => "myAccessToken", + "userAgent", + ); + + const object = { + __apiName: "unknown", + __primaryKey: 0, + } as const; + const prototypeBefore = Object.getPrototypeOf(object); + convertWireToOsdkObjects(clientCtx, [object]); + const prototypeAfter = Object.getPrototypeOf(object); + + expect(prototypeBefore).not.toBe(prototypeAfter); + }); }); diff --git a/packages/client/src/object/convertWireToOsdkObjects.ts b/packages/client/src/object/convertWireToOsdkObjects.ts index 3b0e7ff10..5f7ad8b5c 100644 --- a/packages/client/src/object/convertWireToOsdkObjects.ts +++ b/packages/client/src/object/convertWireToOsdkObjects.ts @@ -39,6 +39,10 @@ function createPrototype< const objDef = ontology.objects[type]; const proto = {}; + if (!objDef) { + return proto; + } + Object.defineProperty(proto, "$link", { get: function() { const client = this[OriginClient] as ClientContext; @@ -116,10 +120,15 @@ function createConverter< ontology: O, type: T, ) { + const objDef = ontology.objects[type]; + if (!objDef) { + return false as const; + } + const steps: Array<(o: Record) => void> = []; for ( - const [key, value] of Object.entries(ontology.objects[type].properties) + const [key, value] of Object.entries(objDef.properties) ) { // attachments need a wrapper to provide functionality and to identify them at serialization time if (value.type === "attachment") {