Skip to content

Commit

Permalink
feat: toObject returns unpersisted dirty data
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Frank committed Jun 14, 2022
1 parent 37f34d9 commit 0423620
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ticketbridge/hyper-durable",
"version": "0.1.9",
"version": "0.1.10",
"description": "Object-like access to Durable Object properties and methods",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Deletes all data in `storage`, clears `state.dirty` and `state.persisted`, and d

#### `toObject()`

Returns all persisted data as an object.
Returns all persisted and dirty data as an object.

#### `async fetch(request: Request): Promise<Response>`

Expand Down
7 changes: 7 additions & 0 deletions src/HyperDurable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ describe('HyperDurable', () => {
objectLikeProp: []
});
});

test('returns unpersisted dirty data from toObject', async () => {
expect(counter.toObject()).to.deep.equal({
counter: 1,
objectLikeProp: []
});
});
});

describe('fetch', () => {
Expand Down
3 changes: 3 additions & 0 deletions src/HyperDurable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ export class HyperDurable<Env = unknown> implements DurableObject {
for (let key of this.state.persisted) {
output[key] = this[key];
}
for (let key of this.state.dirty) {
output[key] = this[key];
}
return output;
}

Expand Down

0 comments on commit 0423620

Please sign in to comment.