Versions 99 to 318
new file, 64 lines
1+// Issues, asks and news for the open server: one IssueProject Durable Object per project (bound as ISSUES_DO, 2+// named by the project's name), reached through issuesFetch from the Worker's /issues/p/:project/... routes. 3+// The logic is in serve.ts, store.ts and routes.ts, which run under node --test without Cloudflare's runtime. 5+// GET /issues/p/:project/issues[?status=&agent=&parent=&label=&open=1] issues, most recently updated first 6+// GET /issues/p/:project/issue/:n one issue with its comments, edits and asks 7+// GET /issues/p/:project/search?q=[&limit=] full-text search 8+// GET /issues/p/:project/labels | changes | waiting[?of=] | ask/:n | asked?by= | answered?of= 9+// GET /issues/p/:project/a/:agent/waiting | asked | drafts | news[?before=] 10+// POST /issues/p/:project/a/:agent/issue | ask | answer/:n | ack/:n | reply/:n | withdraw/:n 11+// POST /issues/p/:project/a/:agent/issue/:n/comment | edit | drop | reopen | done 12+// POST /issues/p/:project/a/:agent/draft | draft/:n/open | draft/:n/delete | news/read 14+import { DurableObject } from "cloudflare:workers"; 15+import { type IssuesEnv, IssuesObject } from "./serve.ts"; 16+import type { News } from "./store.ts"; 28+/** One project's issues, in its own SQLite. */ 29+export class IssueProject extends DurableObject<IssuesEnv> { 30+ private readonly issues: IssuesObject; 32+ constructor(ctx: DurableObjectState, env: IssuesEnv) { 34+ // The migrations are synchronous SQL, so they finish here, before the object takes any request. 35+ this.issues = new IssuesObject( 36+ { sql: ctx.storage.sql, transactionSync: (action) => ctx.storage.transactionSync(action) }, 41+ async fetch(request: Request): Promise<Response> { 42+ return this.issues.fetch(request); 45+ /** A start note names the issue; `change` is the note's log position. A missing or closed issue is ignored. */ 46+ async claim(agent: string, issue: number, change: number): Promise<void> { 47+ this.issues.store.claim(agent, issue, change); 50+ /** The start note ended without finishing the issue. */ 51+ async unclaim(agent: string, issue: number): Promise<void> { 52+ this.issues.store.unclaim(agent, issue); 55+ /** publish --done finished the issue in `version`: done, and its news for the project to deliver. */ 56+ async done(agent: string, issue: number, version: number): Promise<{ news?: News }> { 57+ return this.issues.store.done(agent, issue, version); 60+ /** How many schema migrations this object has run. */ 61+ async schema(): Promise<{ migrations: number }> { 62+ return { migrations: this.issues.migrations() };