Skip to content

Commit

Permalink
refactor: HyperNamespaceProxy no longer creates DO as ref, instead qu…
Browse files Browse the repository at this point in the history
…eries prototype of class
  • Loading branch information
Travis Frank committed Jun 15, 2022
1 parent 1363739 commit 89af18e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 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.14",
"version": "0.1.15",
"description": "Object-like access to Durable Object properties and methods",
"repository": {
"type": "git",
Expand Down
9 changes: 4 additions & 5 deletions src/HyperNamespaceProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HyperError } from './HyperError';

export class HyperNamespaceProxy<DO extends HyperDurable<any, Env>, Env> implements DurableObjectNamespace {
namespace: DurableObjectNamespace;
ref: DO;
ref: new (state: DurableObjectState, env: Env) => DO;

newUniqueId: (_options?: DurableObjectNamespaceNewUniqueIdOptions) => DurableObjectId;
idFromName: (name: string) => DurableObjectId;
Expand All @@ -14,9 +14,8 @@ export class HyperNamespaceProxy<DO extends HyperDurable<any, Env>, Env> impleme
ref: new (state: DurableObjectState, env: Env) => DO
) {
this.namespace = namespace;
// Create a reference of the DO to check for methods / properties
// @ts-ignore
this.ref = new ref({}, {});
// Reference of the DO to check for methods / properties
this.ref = ref;

this.newUniqueId = namespace.newUniqueId;
this.idFromName = namespace.idFromName;
Expand Down Expand Up @@ -88,7 +87,7 @@ export class HyperNamespaceProxy<DO extends HyperDurable<any, Env>, Env> impleme
// Short circuit for fetch to maintain manual access
if (key === 'fetch') return hyperStub.fetch.bind(hyperStub);

if (typeof this.ref[key] === 'function') {
if (typeof this.ref.prototype[key] === 'function') {
// Anonymous function to pass args
return function (...args: any[]) {
const request = createHyperRequest('call', key, { args });
Expand Down
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type PromisedGetStub<DO extends HyperDurable<any, Env>, Env> = {
}

export type SetStub<DO extends HyperDurable<any, Env>, Env> = {
[Prop in keyof DO as DO[Prop] extends Function ? never : `set${Capitalize<string & Prop>}`]?:
[Prop in keyof DO as DO[Prop] extends Function ? never : `set${Capitalize<string & Prop>}`]:
(newValue: DO[Prop]) => Promise<DO[Prop]>
}

Expand Down

0 comments on commit 89af18e

Please sign in to comment.