| 121 | } |
| 122 | |
| 123 | private async post<T>(path: string, body: unknown): Promise<T> { |
| 124 | const base = this.baseUrl.endsWith('/') ? this.baseUrl : this.baseUrl + '/'; |
| 125 | const url = new URL(path.startsWith('/') ? path.slice(1) : path, base); |
| 126 | const res = await fetch(url.toString(), { |
| 127 | method: 'POST', |
| 128 | headers: { 'Content-Type': 'application/json' }, |
| 129 | body: JSON.stringify(body), |
| 130 | }); |
| 131 | if (!res.ok) { |
| 132 | const text = await res.text().catch(() => ''); |
| 133 | throw new Error(`Server error ${res.status}: ${text}`); |
| 134 | } |
| 135 | return res.json() as Promise<T>; |
| 136 | } |
| 137 | |
| 138 | // ---- GraphStore interface ------------------------------------------- |
| 139 | |