Skip to content

Commit

Permalink
Fix proxy handler (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssanjay1 authored Oct 3, 2024
1 parent 8eb2378 commit 9af346e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/smart-garlics-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@osdk/shared.test": patch
"@osdk/client": patch
---

Fixing proxy handlers.
26 changes: 25 additions & 1 deletion packages/client/src/object/convertWireToOsdkObjects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ describe("convertWireToOsdkObjects", () => {
"$apiName",
"$objectType",
"$primaryKey",
"$title",
].sort());

expect(Object.keys(employee.$as)).toEqual([]);
Expand All @@ -78,6 +77,31 @@ describe("convertWireToOsdkObjects", () => {
]);
});

it("stringifies properties on objects and interfaces correctly", async () => {
const { data: [employee] } = await client(Employee).fetchPage();
const { data: [employee2] } = await client(Employee).where({
$and: [{ employeeId: { $gt: 50030 } }, { employeeId: { $lt: 50032 } }],
}).fetchPage();

// Should not have $title
expect(JSON.stringify(employee)).toMatchInlineSnapshot(
`"{"employeeId":50030,"fullName":"John Doe","office":"NYC","class":"Red","startDate":"2019-01-01","employeeStatus":{},"$apiName":"Employee","$objectType":"Employee","$primaryKey":50030}"`,
);

expect(JSON.stringify(employee.$as(FooInterface))).toMatchInlineSnapshot(
`"{"$apiName":"FooInterface","$objectType":"Employee","$primaryKey":50030,"fooSpt":"John Doe"}"`,
);

// Should have $title
expect(JSON.stringify(employee2)).toMatchInlineSnapshot(
`"{"employeeId":50031,"fullName":"Jane Doe","office":"SEA","class":"Blue","startDate":"2012-02-12","employeeStatus":{},"$apiName":"Employee","$objectType":"Employee","$primaryKey":50031,"$title":"Jane Doe"}"`,
);

expect(JSON.stringify(employee2.$as(FooInterface))).toMatchInlineSnapshot(
`"{"$apiName":"FooInterface","$objectType":"Employee","$primaryKey":50031,"$title":"Jane Doe","fooSpt":"Jane Doe"}"`,
);
});

it("reuses the object prototype across objects", async () => {
const employees = await client(Employee).fetchPage();
expect(employees.data.length).toBeGreaterThanOrEqual(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ export function createOsdkObject<
if (p === RawObject) {
return Reflect.getOwnPropertyDescriptor(target, p);
}

if (target[RawObject][p as string] != null) {
return { configurable: true, enumerable: true };
}
return { enumerable: false };
return undefined;
},
});
return osdkObject;
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/object/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ describe("OsdkObject", () => {

// we should get the employee we requested
const employee = result.data[0];
expect(JSON.stringify(employee)).toBeDefined();
expect(employee).toMatchObject({
"$apiName": "Employee",
"$objectType": "Employee",
"$primaryKey": 50030,
"$title": "John Doe",
"class": "Red",
"employeeId": 50030,
"employeeStatus": expect.anything(),
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/objectSet/ObjectSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ describe("ObjectSet", () => {
$apiName: "Employee",
$objectType: "Employee",
$primaryKey: 50030,
$title: "John Doe",
class: "Red",
employeeId: 50030,
employeeStatus: expect.anything(),
Expand Down
1 change: 0 additions & 1 deletion packages/shared.test/src/stubs/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const employee1 = {
"ri.phonograph2-objects.main.object.88a6fccb-f333-46d6-a07e-7725c5f18b61",
__primaryKey: 50030,
__apiName: "Employee",
__title: "John Doe",
employeeId: 50030,
fullName: "John Doe",
office: "NYC",
Expand Down

0 comments on commit 9af346e

Please sign in to comment.