diff --git a/.changeset/famous-dolphins-think.md b/.changeset/famous-dolphins-think.md new file mode 100644 index 000000000..76b9f564b --- /dev/null +++ b/.changeset/famous-dolphins-think.md @@ -0,0 +1,6 @@ +--- +"@osdk/foundry-sdk-generator": patch +"@osdk/legacy-client": patch +--- + +Fix $rid, $apiName and $primaryKey population diff --git a/packages/foundry-sdk-generator/src/__e2e_tests__/actions.test.ts b/packages/foundry-sdk-generator/src/__e2e_tests__/actions.test.ts index 1aaa0e49e..0e168e1e0 100644 --- a/packages/foundry-sdk-generator/src/__e2e_tests__/actions.test.ts +++ b/packages/foundry-sdk-generator/src/__e2e_tests__/actions.test.ts @@ -100,6 +100,11 @@ describe("test", () => { expect(officeImpl.__rid).toBe( "ri.phonograph2-objects.main.object.c0c0c0c0-c0c0-c0c0-c0c0-c0c0c0c0c0c0", ); + expect(officeImpl.$apiName).toBe("Office"); + expect(officeImpl.$primaryKey).toBe("NYC"); + expect(officeImpl.$rid).toBe( + "ri.phonograph2-objects.main.object.c0c0c0c0-c0c0-c0c0-c0c0-c0c0c0c0c0c0", + ); const officeResult2: Result = await objectEdit .fetchOneWithErrors(); const officeImpl2: Office = assertOkOrThrow(officeResult2); @@ -109,12 +114,24 @@ describe("test", () => { "ri.phonograph2-objects.main.object.c0c0c0c0-c0c0-c0c0-c0c0-c0c0c0c0c0c0", ); + expect(officeImpl2.$apiName).toBe("Office"); + expect(officeImpl2.$primaryKey).toBe("NYC"); + expect(officeImpl2.$rid).toBe( + "ri.phonograph2-objects.main.object.c0c0c0c0-c0c0-c0c0-c0c0-c0c0c0c0c0c0", + ); + const officeNoErrors: Office = await objectEdit.fetchOne(); expect(officeNoErrors.__apiName).toBe("Office"); expect(officeNoErrors.__primaryKey).toBe("NYC"); expect(officeNoErrors.__rid).toBe( "ri.phonograph2-objects.main.object.c0c0c0c0-c0c0-c0c0-c0c0-c0c0c0c0c0c0", ); + + expect(officeNoErrors.$apiName).toBe("Office"); + expect(officeNoErrors.$primaryKey).toBe("NYC"); + expect(officeNoErrors.$rid).toBe( + "ri.phonograph2-objects.main.object.c0c0c0c0-c0c0-c0c0-c0c0-c0c0c0c0c0c0", + ); } }); diff --git a/packages/legacy-client/src/client/objects/convertWireToOsdkObject.test.ts b/packages/legacy-client/src/client/objects/convertWireToOsdkObject.test.ts index 768677732..225ad71d8 100644 --- a/packages/legacy-client/src/client/objects/convertWireToOsdkObject.test.ts +++ b/packages/legacy-client/src/client/objects/convertWireToOsdkObject.test.ts @@ -126,8 +126,18 @@ describe("convertWireToOsdkObject", () => { MockOntology >(client, wireObject); + const convertedObject = { + id: 1, + __primaryKey: 1, + __apiName: "Task", + __rid: "rid.1", + $primaryKey: 1, + $apiName: "Task", + $rid: "rid.1", + } as const; + expect(object.toString()).toEqual( - JSON.stringify(wireObject, null, 2), + JSON.stringify(convertedObject, null, 2), ); }); @@ -151,7 +161,10 @@ describe("convertWireToOsdkObject", () => { "catch_": 1, "__primaryKey": 1, "__apiName": "ObjectTypeWithReservedNames", - "__rid": "rid.1" + "__rid": "rid.1", + "$primaryKey": 1, + "$apiName": "ObjectTypeWithReservedNames", + "$rid": "rid.1" }" `); }); diff --git a/packages/legacy-client/src/client/objects/convertWireToOsdkObject.ts b/packages/legacy-client/src/client/objects/convertWireToOsdkObject.ts index 6c707e15c..7d73642ca 100644 --- a/packages/legacy-client/src/client/objects/convertWireToOsdkObject.ts +++ b/packages/legacy-client/src/client/objects/convertWireToOsdkObject.ts @@ -51,7 +51,17 @@ function createPrototype< const proto = {}; Object.defineProperty(proto, "__apiName", { get: () => type }); - + Object.defineProperty(proto, "$apiName", { get: () => type }); + Object.defineProperty(proto, "$primaryKey", { + get: function() { + return this["__primaryKey"]; + }, + }); + Object.defineProperty(proto, "$rid", { + get: function() { + return this["__rid"]; + }, + }); // toString that uses the ontology definition to enumerate the props that need to be serialized proto.toString = function() { const obj: Record = {}; @@ -63,6 +73,10 @@ function createPrototype< obj["__primaryKey"] = self.__primaryKey; obj["__apiName"] = type; obj["__rid"] = self.__rid; + + obj["$primaryKey"] = self.__primaryKey; + obj["$apiName"] = type; + obj["$rid"] = self.__rid; return JSON.stringify(obj, undefined, 2); };