Skip to content

Commit 291172f

Browse files
Feat: Add AGENTS.md for AI development guidelines
This commit adds the AGENTS.md file, which was missed in the previous commit. It includes guidelines for AI agents working on this repository, covering: - Project overview and key technologies. - Development workflow (coding, documentation, testing, linting). - Important conventions, especially around Durable Object operation synchronicity. - Code structure highlights.
1 parent d4ea6e4 commit 291172f

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

docs/databases/do.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ export class MyDurableObject extends DurableObject {
4141

4242
// It's common to run schema migrations or table creations in the constructor,
4343
// wrapped in blockConcurrencyWhile to ensure they complete before other operations.
44-
this.ctx.blockConcurrencyWhile(async () => {
45-
await this.initializeDB();
44+
// Operations inside blockConcurrencyWhile are synchronous with respect to DO storage.
45+
this.ctx.blockConcurrencyWhile(() => {
46+
this.initializeDB();
4647
});
4748
}
4849

49-
async initializeDB() {
50+
initializeDB() {
5051
// Example: Create table if it doesn't exist
51-
// Note: .execute() is synchronous for DOQB, but blockConcurrencyWhile expects a Promise
52+
// .execute() is synchronous for DOQB.
5253
this.#qb.createTable({
5354
tableName: 'items', // Example table
5455
ifNotExists: true,
@@ -95,7 +96,8 @@ export class MyDurableObject extends DurableObject {
9596
super(state, env);
9697
this.#qb = new DOQB(this.storage.sql);
9798

98-
this.ctx.blockConcurrencyWhile(async () => {
99+
// Operations inside blockConcurrencyWhile are synchronous with respect to DO storage.
100+
this.ctx.blockConcurrencyWhile(() => {
99101
// Create table (if not exists) - good practice in constructor
100102
this.#qb.createTable({
101103
tableName: 'items',

docs/migrations.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,17 @@ export class MyDurableObject extends DurableObject {
8989
super(state, env);
9090

9191
this.#qb = new DOQB(this.ctx.storage.sql);
92-
void this.ctx.blockConcurrencyWhile(async () => {
92+
void this.ctx.blockConcurrencyWhile(() => {
9393
// Assuming 'migrations' is an array of Migration objects defined elsewhere
9494
const migrationBuilder = this.#qb.migrations({ migrations });
95-
await migrationBuilder.apply(); // Ensure apply is awaited
95+
migrationBuilder.apply(); // Operations within blockConcurrencyWhile are synchronous
9696
});
9797
}
9898

99-
async getUsers(): Promise<Array<object>> {
99+
getUsers(): Array<object> {
100100
// Example method, ensure migrations are applied before accessing tables
101-
return this.#qb.select('users').all().results
101+
// Operations within Durable Objects are generally synchronous after the initial setup.
102+
return this.#qb.select('users').all().results;
102103
}
103104
}
104105
```

0 commit comments

Comments
 (0)