Unkn0wnCat
Unkn0wnCat
CDCloudflare Developers
Created by Unkn0wnCat on 4/17/2024 in #workers-help
DurableObjectStub is missing all methods
Hey, I'm having a little issue. I'm trying my hand at Durable Objects for the first time and I've got some trouble getting them to work. I have this code in my index.ts:
[...]
const episodeStorageStub = env.EPISODE_STORAGE.get(episodeStorageId);

console.log(episodeStorageStub, episodeStorageStub.countQuery)
[...]
[...]
const episodeStorageStub = env.EPISODE_STORAGE.get(episodeStorageId);

console.log(episodeStorageStub, episodeStorageStub.countQuery)
[...]
And this in my durableObject.ts:
import { DurableObject } from "cloudflare:workers";

export class EpisodeStorage extends DurableObject {
async countQuery(): Promise<Number> {
const answers = (await this.ctx.storage.get<Answer[]>("answers", {allowConcurrency: true}))||[];

return answers.length;
}
}
import { DurableObject } from "cloudflare:workers";

export class EpisodeStorage extends DurableObject {
async countQuery(): Promise<Number> {
const answers = (await this.ctx.storage.get<Answer[]>("answers", {allowConcurrency: true}))||[];

return answers.length;
}
}
Yet somehow my countQuery keeps being returned as undefined. Am I overlooking something? I'm basically following this: https://developers.cloudflare.com/durable-objects/examples/build-a-counter/
6 replies