Skip to content

Commit

Permalink
Confirm Immutable Objects & Interfaces (#1042)
Browse files Browse the repository at this point in the history
* Interface instances are immutable just like object instances

* changeset
  • Loading branch information
ericanderson authored Dec 6, 2024
1 parent ca863a1 commit 27f0f77
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-wombats-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osdk/client": patch
---

Interface instances are immutable just like object instances
17 changes: 17 additions & 0 deletions packages/client/src/object/convertWireToOsdkObjects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ describe("convertWireToOsdkObjects", () => {
expect(emptyAttachmentArray).toBeUndefined();
});

it("creates immutable objects", async () => {
const employees = await client(Employee).fetchPage();
expect(employees.data.length).toBeGreaterThanOrEqual(2);
const [a, b] = employees.data;

expect(a).toBeDefined();
expect(() => {
(a as any).somePropertyThatShouldNotExist = 5;
}).toThrow();

const objAsFoo = a.$as(FooInterface);
expect(objAsFoo).toBeDefined();
expect(() => {
(objAsFoo as any).somePropertyThatShouldNotExist = 5;
}).toThrow();
});

it("works even with unknown apiNames - old", async () => {
const clientCtx = createMinimalClient(
{ ontologyRid: $ontologyRid },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ function createInterfaceProxyHandler(
];
},

set() {
return false;
},

get(target, p) {
const underlying = target[UnderlyingOsdkObject];
switch (p) {
Expand Down

0 comments on commit 27f0f77

Please sign in to comment.