Skip to content

Commit

Permalink
Correctly populate rids (#261) (#264)
Browse files Browse the repository at this point in the history
* correctly populate rids

* add changeset
  • Loading branch information
ssanjay1 authored May 2, 2024
1 parent d588925 commit e690399
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/famous-dolphins-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@osdk/foundry-sdk-generator": patch
"@osdk/legacy-client": patch
---

Fix $rid, $apiName and $primaryKey population
17 changes: 17 additions & 0 deletions packages/foundry-sdk-generator/src/__e2e_tests__/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Office, GetObjectError> = await objectEdit
.fetchOneWithErrors();
const officeImpl2: Office = assertOkOrThrow(officeResult2);
Expand All @@ -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",
);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
});

Expand All @@ -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"
}"
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown> = {};
Expand All @@ -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);
};

Expand Down

0 comments on commit e690399

Please sign in to comment.