apps 1.0.0-beta.3 → 2.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +10 -48
  2. package/check-publish.mjs +7 -0
  3. package/package.json +27 -56
  4. package/src/Access.ts +37 -0
  5. package/src/Accounts.ts +468 -0
  6. package/src/App.ts +11 -0
  7. package/src/Ask.ts +156 -0
  8. package/src/Changes.ts +13 -0
  9. package/src/Http.ts +30 -0
  10. package/src/Provider.ts +146 -0
  11. package/src/Session.ts +52 -0
  12. package/src/Settings.ts +164 -0
  13. package/src/contract.ts +852 -0
  14. package/src/css-modules.d.ts +2 -0
  15. package/src/desktop/Desktop.ts +192 -0
  16. package/src/desktop/bridge.ts +62 -0
  17. package/src/desktop/errors.ts +88 -0
  18. package/src/desktop/index.ts +15 -0
  19. package/src/entry.ts +48 -0
  20. package/src/index.ts +16 -4
  21. package/src/internal/defects.ts +62 -0
  22. package/src/internal/files.ts +369 -0
  23. package/src/internal/host.ts +17 -0
  24. package/src/internal/query.ts +114 -0
  25. package/src/internal/records.ts +838 -0
  26. package/src/internal/retention.ts +87 -0
  27. package/src/internal/retries.ts +185 -0
  28. package/src/internal/telemetry.ts +167 -0
  29. package/src/migrations.ts +110 -0
  30. package/src/page/Accounts.ts +27 -0
  31. package/src/page/Changes.ts +126 -0
  32. package/src/page/Session.ts +46 -0
  33. package/src/page/client.ts +107 -0
  34. package/src/page/errors.ts +15 -0
  35. package/src/page/http.ts +21 -0
  36. package/src/page/index.ts +18 -0
  37. package/src/page/paths.ts +22 -0
  38. package/src/providers/anthropic.ts +26 -0
  39. package/src/providers/github.ts +49 -0
  40. package/src/providers/google.ts +67 -0
  41. package/src/providers/openai.ts +62 -0
  42. package/src/providers/slack.ts +81 -0
  43. package/src/runtime.ts +1540 -0
  44. package/src/testing.ts +660 -0
  45. package/src/text-modules.d.ts +5 -0
  46. package/src/theme.css +50 -0
  47. package/dist/authoring/index.d.ts +0 -393
  48. package/dist/authoring/index.js +0 -36
  49. package/dist/chunk-4OZFMCTT.js +0 -17
  50. package/dist/chunk-A3H32P2J.js +0 -143
  51. package/dist/chunk-B7NEUIJL.js +0 -14
  52. package/dist/chunk-F7GZYEAC.js +0 -41
  53. package/dist/chunk-MUFMJRXR.js +0 -308
  54. package/dist/chunk-S5KFP4JQ.js +0 -20
  55. package/dist/chunk-Y6LLTN7W.js +0 -99
  56. package/dist/chunk-YUZ4TXOY.js +0 -27
  57. package/dist/http/index.d.ts +0 -9
  58. package/dist/http/index.js +0 -6
  59. package/dist/index.d.ts +0 -4
  60. package/dist/index.js +0 -48
  61. package/dist/manifest/contract.d.ts +0 -63
  62. package/dist/manifest/contract.js +0 -8
  63. package/dist/manifest/index.d.ts +0 -20
  64. package/dist/manifest/index.js +0 -16
  65. package/dist/mcp/client.d.ts +0 -9
  66. package/dist/mcp/index.d.ts +0 -11
  67. package/dist/mcp/index.js +0 -7
  68. package/dist/openapi/index.d.ts +0 -14
  69. package/dist/openapi/index.js +0 -7
  70. package/dist/openapi/mapper.d.ts +0 -7
  71. package/dist/runner/index.d.ts +0 -4
  72. package/dist/runner/index.js +0 -66
  73. package/dist/runner/protocol.d.ts +0 -33
  74. package/dist/runner/protocol.js +0 -8
  75. package/dist/runtime/index.d.ts +0 -83
  76. package/dist/runtime/index.js +0 -12
  77. package/dist/workerd/index.d.ts +0 -7
  78. package/dist/workerd/index.js +0 -10
  79. package/src/authoring/index.ts +0 -658
  80. package/src/http/index.ts +0 -26
  81. package/src/manifest/contract.ts +0 -64
  82. package/src/manifest/index.ts +0 -156
  83. package/src/mcp/client.ts +0 -59
  84. package/src/mcp/index.ts +0 -42
  85. package/src/openapi/index.ts +0 -70
  86. package/src/openapi/mapper.ts +0 -25
  87. package/src/runner/index.ts +0 -80
  88. package/src/runner/protocol.ts +0 -54
  89. package/src/runtime/index.ts +0 -550
  90. package/src/workerd/index.ts +0 -17
@@ -0,0 +1,369 @@
1
+ /**
2
+ * Effect's `FileSystem`, over the host's `files` capability. The same limited
3
+ * set on every host: read, write, stream, sink, stat, list, copy, rename,
4
+ * remove, and temporary directories (under `/.tmp`). Calls that make no sense
5
+ * for object storage fail with a clear error.
6
+ *
7
+ * `stream` and `sink` never hold a whole file: bytes pass to and from the host
8
+ * as a `ReadableStream`. `readFile` reads through the same stream, and a
9
+ * `writeFile` larger than {@link STREAMED_WRITE_BYTES} is sent as one, because
10
+ * workerd refuses an RPC value over 32 MiB. They are what Effect's multipart parser
11
+ * (`makeTempDirectoryScoped`, `sink`) and `HttpServerResponse.file` (`stat`,
12
+ * `stream`) call, so uploads and downloads stream.
13
+ */
14
+ import {
15
+ ByteSize,
16
+ Deferred,
17
+ Effect,
18
+ FileSystem,
19
+ Layer,
20
+ Option,
21
+ Path,
22
+ PlatformError,
23
+ Sink,
24
+ Stream,
25
+ } from "effect";
26
+ import { Etag, HttpPlatform } from "effect/http";
27
+ import type { ContractError, FileInfo, HostFiles, Result } from "../contract.ts";
28
+
29
+ const module = "FileSystem";
30
+ /** A `writeFile` larger than this goes to the host as a stream of {@link SLICE_BYTES} slices. */
31
+ const STREAMED_WRITE_BYTES = 4 * 1024 * 1024;
32
+ const SLICE_BYTES = 1024 * 1024;
33
+
34
+ const slices = (data: Uint8Array) => {
35
+ let at = 0;
36
+ return new ReadableStream<Uint8Array>({
37
+ pull(controller) {
38
+ if (at >= data.length) return controller.close();
39
+ controller.enqueue(data.subarray(at, at + SLICE_BYTES));
40
+ at += SLICE_BYTES;
41
+ },
42
+ });
43
+ };
44
+
45
+ const collect = async (stream: ReadableStream<Uint8Array>) => {
46
+ const chunks: Array<Uint8Array> = [];
47
+ let size = 0;
48
+ const reader = stream.getReader();
49
+ for (;;) {
50
+ const { done, value } = await reader.read();
51
+ if (done) break;
52
+ chunks.push(value);
53
+ size += value.length;
54
+ }
55
+ const out = new Uint8Array(size);
56
+ let at = 0;
57
+ for (const chunk of chunks) {
58
+ out.set(chunk, at);
59
+ at += chunk.length;
60
+ }
61
+ return out;
62
+ };
63
+ const TEMP = "/.tmp";
64
+
65
+ const unsupported = (method: string) =>
66
+ Effect.fail(
67
+ PlatformError.badArgument({
68
+ module,
69
+ method,
70
+ description: `${method} is not supported by Executor's file system`,
71
+ }),
72
+ );
73
+
74
+ const toError = (method: string, path: string, error: ContractError) =>
75
+ error.reason === "Unsupported" || error.reason === "TooLarge"
76
+ ? PlatformError.badArgument({ module, method, description: error.message })
77
+ : PlatformError.systemError({
78
+ _tag:
79
+ (["NotFound", "AlreadyExists", "BadResource", "PermissionDenied", "Busy"] as const).find(
80
+ (tag) => tag === error.reason,
81
+ ) ?? "Unknown",
82
+ module,
83
+ method,
84
+ description: error.message,
85
+ pathOrDescriptor: path,
86
+ });
87
+
88
+ const info = (value: FileInfo): FileSystem.File.Info => ({
89
+ type: value.type,
90
+ mtime: value.mtime === null ? Option.none() : Option.some(new Date(value.mtime)),
91
+ atime: Option.none(),
92
+ birthtime: Option.none(),
93
+ dev: 0n,
94
+ ino: Option.none(),
95
+ mode: value.type === "Directory" ? 0o755 : 0o644,
96
+ nlink: Option.none(),
97
+ uid: Option.none(),
98
+ gid: Option.none(),
99
+ rdev: Option.none(),
100
+ size: ByteSize.bytes(value.size),
101
+ blksize: Option.none(),
102
+ blocks: Option.none(),
103
+ });
104
+
105
+ const resolve = (path: string) => {
106
+ const parts: Array<string> = [];
107
+ for (const part of path.split("/")) {
108
+ if (part === "" || part === ".") continue;
109
+ if (part === "..") parts.pop();
110
+ else parts.push(part);
111
+ }
112
+ return "/" + parts.join("/");
113
+ };
114
+
115
+ export const make = (files: HostFiles | undefined): FileSystem.FileSystem => {
116
+ const call = <A>(method: string, path: string, f: (files: HostFiles) => Promise<Result<A>>) =>
117
+ files === undefined
118
+ ? Effect.fail(
119
+ PlatformError.badArgument({ module, method, description: "Not running under Executor" }),
120
+ )
121
+ : Effect.flatMap(
122
+ Effect.tryPromise({
123
+ try: () => f(files),
124
+ catch: (cause) =>
125
+ PlatformError.systemError({
126
+ _tag: "Unknown",
127
+ module,
128
+ method,
129
+ description: String(cause),
130
+ pathOrDescriptor: path,
131
+ }),
132
+ }),
133
+ (result) =>
134
+ result.ok
135
+ ? Effect.succeed(result.value)
136
+ : Effect.fail(toError(method, path, result.error)),
137
+ );
138
+
139
+ const stat = (path: string) =>
140
+ Effect.map(
141
+ call("stat", path, (f) => f.stat(resolve(path))),
142
+ info,
143
+ );
144
+ const list = (path: string) => call("readDirectory", path, (f) => f.list(resolve(path)));
145
+ const readDirectory = (
146
+ path: string,
147
+ options?: { readonly recursive?: boolean | undefined },
148
+ ): Effect.Effect<Array<string>, PlatformError.PlatformError> =>
149
+ Effect.flatMap(list(path), (names) =>
150
+ options?.recursive !== true
151
+ ? Effect.succeed([...names])
152
+ : Effect.map(
153
+ Effect.forEach(names, (name) =>
154
+ Effect.flatMap(stat(`${path}/${name}`), (s) =>
155
+ s.type === "Directory"
156
+ ? Effect.map(readDirectory(`${path}/${name}`, options), (inner) => [
157
+ name,
158
+ ...inner.map((n) => `${name}/${n}`),
159
+ ])
160
+ : Effect.succeed([name]),
161
+ ),
162
+ ),
163
+ (nested) => nested.flat(),
164
+ ),
165
+ );
166
+ const writeFile = (
167
+ path: string,
168
+ data: Uint8Array,
169
+ options?: { readonly flag?: FileSystem.OpenFlag | undefined },
170
+ ) =>
171
+ call("writeFile", path, (f) =>
172
+ f.write(resolve(path), data.length > STREAMED_WRITE_BYTES ? slices(data) : data, {
173
+ append: options?.flag?.startsWith("a") === true,
174
+ exclusive: options?.flag?.includes("x") === true,
175
+ }),
176
+ );
177
+
178
+ const readFile = (path: string) =>
179
+ call("readFile", path, async (f): Promise<Result<Uint8Array>> => {
180
+ const opened = await f.stream(resolve(path));
181
+ return opened.ok ? { ok: true, value: await collect(opened.value) } : opened;
182
+ });
183
+
184
+ const tempDirectory = (options?: {
185
+ readonly directory?: string | undefined;
186
+ readonly prefix?: string | undefined;
187
+ }) => {
188
+ const path = resolve(
189
+ `${options?.directory ?? TEMP}/${options?.prefix ?? ""}${crypto.randomUUID()}`,
190
+ );
191
+ return Effect.as(
192
+ call("makeTempDirectory", path, (f) => f.makeDirectory(path, { recursive: true })),
193
+ path,
194
+ );
195
+ };
196
+ const sink = (
197
+ path: string,
198
+ options?: { readonly flag?: FileSystem.OpenFlag | undefined },
199
+ ): Sink.Sink<void, Uint8Array, never, PlatformError.PlatformError> =>
200
+ Sink.unwrap(
201
+ Effect.gen(function* () {
202
+ const pipe = new TransformStream<Uint8Array, Uint8Array>();
203
+ const writer = pipe.writable.getWriter();
204
+ const ended = yield* Deferred.make<null, PlatformError.PlatformError>();
205
+ yield* call("sink", path, (f) =>
206
+ f.write(resolve(path), pipe.readable, {
207
+ append: options?.flag?.startsWith("a") === true,
208
+ exclusive: options?.flag?.includes("x") === true,
209
+ }),
210
+ ).pipe(Deferred.into(ended), Effect.forkScoped);
211
+ yield* Effect.addFinalizer(() =>
212
+ Effect.promise(() => writer.abort("the write was abandoned").catch(() => undefined)),
213
+ );
214
+ const stopped = Effect.flatMap(Deferred.await(ended), () =>
215
+ Effect.fail(
216
+ PlatformError.systemError({
217
+ _tag: "Unknown",
218
+ module,
219
+ method: "sink",
220
+ description: "The host stopped reading before the end of the file",
221
+ pathOrDescriptor: path,
222
+ }),
223
+ ),
224
+ );
225
+ const io = (method: string, f: () => Promise<void>) =>
226
+ Effect.tryPromise({
227
+ try: f,
228
+ catch: (cause) =>
229
+ PlatformError.systemError({
230
+ _tag: "Unknown",
231
+ module,
232
+ method,
233
+ description: String(cause),
234
+ pathOrDescriptor: path,
235
+ }),
236
+ });
237
+ return Sink.forEach((chunk: Uint8Array) =>
238
+ Effect.raceFirst(
239
+ io("sink", () => writer.write(chunk)),
240
+ stopped,
241
+ ),
242
+ ).pipe(
243
+ Sink.mapEffect(() =>
244
+ Effect.andThen(
245
+ io("sink", () => writer.close()),
246
+ Effect.asVoid(Deferred.await(ended)),
247
+ ),
248
+ ),
249
+ );
250
+ }),
251
+ );
252
+
253
+ const fs = FileSystem.make({
254
+ access: (path) => Effect.asVoid(stat(path)),
255
+ copy: (from, to, options) =>
256
+ call("copy", from, (f) =>
257
+ f.copy(resolve(from), resolve(to), { overwrite: options?.overwrite === true }),
258
+ ),
259
+ copyFile: (from, to) =>
260
+ call("copyFile", from, (f) => f.copy(resolve(from), resolve(to), { overwrite: true })),
261
+ chmod: () => unsupported("chmod"),
262
+ chown: () => unsupported("chown"),
263
+ link: () => unsupported("link"),
264
+ lstat: stat,
265
+ makeDirectory: (path, options) =>
266
+ call("makeDirectory", path, (f) =>
267
+ f.makeDirectory(resolve(path), { recursive: options?.recursive === true }),
268
+ ),
269
+ makeTempDirectory: tempDirectory,
270
+ makeTempDirectoryScoped: (options) =>
271
+ Effect.acquireRelease(tempDirectory(options), (path) =>
272
+ Effect.ignore(call("remove", path, (f) => f.remove(path, { recursive: true }))),
273
+ ),
274
+ makeTempFile: () => unsupported("makeTempFile"),
275
+ makeTempFileScoped: () => unsupported("makeTempFileScoped"),
276
+ open: () => unsupported("open"),
277
+ readDirectory,
278
+ readDirectoryEntries: (path) =>
279
+ Effect.flatMap(list(path), (names) =>
280
+ Effect.forEach(names, (name) =>
281
+ Effect.map(stat(`${path}/${name}`), (s) => ({ name, type: s.type })),
282
+ ),
283
+ ),
284
+ readFile: (path) => readFile(path),
285
+ readLink: () => unsupported("readLink"),
286
+ realPath: (path) => Effect.as(stat(path), resolve(path)),
287
+ remove: (path, options) =>
288
+ call("remove", path, (f) =>
289
+ f.remove(resolve(path), { recursive: options?.recursive === true }),
290
+ ).pipe(
291
+ Effect.catchIf(
292
+ (error) => options?.force === true && error.reason._tag === "NotFound",
293
+ () => Effect.succeed(null),
294
+ ),
295
+ Effect.asVoid,
296
+ ),
297
+ rename: (from, to) => call("rename", from, (f) => f.rename(resolve(from), resolve(to))),
298
+ stat,
299
+ symlink: () => unsupported("symlink"),
300
+ truncate: () => unsupported("truncate"),
301
+ utimes: () => unsupported("utimes"),
302
+ watch: () =>
303
+ Stream.fail(
304
+ PlatformError.badArgument({
305
+ module,
306
+ method: "watch",
307
+ description: "watch is not supported by Executor's file system",
308
+ }),
309
+ ),
310
+ writeFile,
311
+ });
312
+
313
+ return {
314
+ ...fs,
315
+ readFile: (path) => readFile(path),
316
+ stream: (path, options) =>
317
+ Stream.unwrap(
318
+ Effect.map(
319
+ call("stream", path, (f) =>
320
+ f.stream(resolve(path), {
321
+ ...(options?.offset === undefined
322
+ ? {}
323
+ : {
324
+ offset: Number(
325
+ Option.match(ByteSize.fromInput(options.offset), {
326
+ onNone: () => 0n,
327
+ onSome: ByteSize.toBigInt,
328
+ }),
329
+ ),
330
+ }),
331
+ ...(options?.bytesToRead === undefined
332
+ ? {}
333
+ : {
334
+ length: Number(
335
+ Option.match(ByteSize.fromInput(options.bytesToRead), {
336
+ onNone: () => 0n,
337
+ onSome: ByteSize.toBigInt,
338
+ }),
339
+ ),
340
+ }),
341
+ }),
342
+ ),
343
+ (body) =>
344
+ Stream.fromReadableStream({
345
+ evaluate: () => body,
346
+ onError: (cause) =>
347
+ PlatformError.systemError({
348
+ _tag: "Unknown",
349
+ module,
350
+ method: "stream",
351
+ description: String(cause),
352
+ pathOrDescriptor: path,
353
+ }),
354
+ }),
355
+ ),
356
+ ),
357
+ sink,
358
+ writeFile,
359
+ };
360
+ };
361
+
362
+ /**
363
+ * `FileSystem`, and what Effect's HTTP modules need beside it to read uploads
364
+ * (`Path`) and send files (`HttpPlatform`, with weak ETags from file info).
365
+ */
366
+ export const layer = (files: HostFiles | undefined) => {
367
+ const fs = Layer.succeed(FileSystem.FileSystem, make(files));
368
+ return Layer.mergeAll(fs, Path.layer, Etag.layerWeak, HttpPlatform.layer.pipe(Layer.provide(fs)));
369
+ };
@@ -0,0 +1,17 @@
1
+ import { Context } from "effect";
2
+ import type { HostCapabilities } from "../contract.ts";
3
+
4
+ /**
5
+ * The loaded app's link to its host. A `Context.Reference`, so author code
6
+ * that reads it (the app's address, accounts) carries no extra requirement.
7
+ * Outside Executor (a plain test), `capabilities` is undefined.
8
+ */
9
+ export interface HostContext {
10
+ readonly capabilities: HostCapabilities | undefined;
11
+ readonly appId: string;
12
+ readonly appUrl: string;
13
+ }
14
+
15
+ export const Host = Context.Reference<HostContext>("apps/internal/Host", {
16
+ defaultValue: () => ({ capabilities: undefined, appId: "local", appUrl: "http://localhost" }),
17
+ });
@@ -0,0 +1,114 @@
1
+ import type { QueryRequest, QueryResult, Result } from "../contract.ts";
2
+
3
+ export interface QueryStorage {
4
+ readonly sql: { exec(query: string, ...bindings: Array<unknown>): SqlCursorLike };
5
+ transactionSync<T>(closure: () => T): T;
6
+ }
7
+
8
+ interface SqlCursorLike extends Iterable<Record<string, unknown>> {
9
+ readonly columnNames: ReadonlyArray<string>;
10
+ readonly rowsRead: number;
11
+ readonly rowsWritten: number;
12
+ raw(): Iterable<ReadonlyArray<unknown>>;
13
+ }
14
+
15
+ class Rollback extends Error {}
16
+
17
+ const failure = (reason: string, message: string): Result<never> => ({
18
+ ok: false,
19
+ error: { reason, message },
20
+ });
21
+
22
+ export const hasSecondStatement = (sql: string): boolean => {
23
+ let ended = false;
24
+ for (let i = 0; i < sql.length; i++) {
25
+ const c = sql[i]!;
26
+ if (c === "-" && sql[i + 1] === "-") {
27
+ const end = sql.indexOf("\n", i);
28
+ i = end === -1 ? sql.length : end;
29
+ continue;
30
+ }
31
+ if (c === "/" && sql[i + 1] === "*") {
32
+ const end = sql.indexOf("*/", i + 2);
33
+ i = end === -1 ? sql.length : end + 1;
34
+ continue;
35
+ }
36
+ if (/\s/u.test(c)) continue;
37
+ if (ended) return true;
38
+ if (c === ";") {
39
+ ended = true;
40
+ continue;
41
+ }
42
+ const close = c === "'" ? "'" : c === '"' ? '"' : c === "`" ? "`" : c === "[" ? "]" : undefined;
43
+ if (close !== undefined) {
44
+ const end = sql.indexOf(close, i + 1);
45
+ i = end === -1 ? sql.length : end;
46
+ }
47
+ }
48
+ return false;
49
+ };
50
+
51
+ const cell = (value: unknown, maxChars: number): unknown => {
52
+ if (typeof value === "string")
53
+ return value.length > maxChars ? `${value.slice(0, maxChars)}…` : value;
54
+ if (value instanceof ArrayBuffer) return { bytes: value.byteLength };
55
+ if (ArrayBuffer.isView(value)) return { bytes: value.byteLength };
56
+ return value;
57
+ };
58
+
59
+ export const readOnlyQuery = (
60
+ storage: QueryStorage,
61
+ request: QueryRequest,
62
+ ): Result<QueryResult> => {
63
+ const sql = request.sql.trim();
64
+ if (sql.length === 0) return failure("QueryRefused", "The query is empty.");
65
+ // external: storage.sql.exec runs every statement it is given and returns only the last one's rows.
66
+ if (hasSecondStatement(sql)) {
67
+ return failure(
68
+ "QueryRefused",
69
+ "Only one SQL statement may be run at a time. Remove everything after the first `;`.",
70
+ );
71
+ }
72
+ let result: QueryResult | undefined;
73
+ let wrote = false;
74
+ try {
75
+ // external: measured on workerd 1.20261125.1 in a host object and in a facet: a throw out of
76
+ // transactionSync undoes INSERT, DELETE and DROP TABLE; COMMIT, ROLLBACK and SAVEPOINT are refused
77
+ // inside it; ATTACH, writing PRAGMAs and load_extension fail with SQLITE_AUTH.
78
+ storage.transactionSync(() => {
79
+ const cursor = storage.sql.exec(sql, ...(request.params ?? []));
80
+ const columns = [...cursor.columnNames];
81
+ const rows: Array<ReadonlyArray<unknown>> = [];
82
+ let bytes = 0;
83
+ let truncated = false;
84
+ for (const raw of cursor.raw()) {
85
+ if (rows.length >= request.maxRows) {
86
+ truncated = true;
87
+ break;
88
+ }
89
+ const row = raw.map((value) => cell(value, request.maxCellChars));
90
+ bytes += JSON.stringify(row).length;
91
+ if (bytes > request.maxBytes && rows.length > 0) {
92
+ truncated = true;
93
+ break;
94
+ }
95
+ rows.push(row);
96
+ }
97
+ wrote = cursor.rowsWritten > 0;
98
+ result = { columns, rows, truncated, rowsRead: cursor.rowsRead };
99
+ throw new Rollback();
100
+ });
101
+ } catch (cause) {
102
+ if (!(cause instanceof Rollback)) {
103
+ const message = cause instanceof Error ? cause.message : String(cause);
104
+ return failure("QueryFailed", message.slice(0, 1_000));
105
+ }
106
+ }
107
+ if (wrote)
108
+ return failure(
109
+ "QueryRefused",
110
+ "The query wrote to the database. Queries are read-only; what it wrote was rolled back.",
111
+ );
112
+ if (result === undefined) return failure("QueryFailed", "The query returned nothing.");
113
+ return { ok: true, value: result };
114
+ };