@yaks/durable-object 0.0.0-stage → 0.2.36

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 (91) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +554 -2
  3. package/_dist/alarm.d.ts +35 -0
  4. package/_dist/alarm.d.ts.map +1 -0
  5. package/_dist/ceiling.d.ts +167 -0
  6. package/_dist/ceiling.d.ts.map +1 -0
  7. package/_dist/compose.d.ts +79 -0
  8. package/_dist/compose.d.ts.map +1 -0
  9. package/_dist/copy.d.ts +67 -0
  10. package/_dist/copy.d.ts.map +1 -0
  11. package/_dist/door.d.ts +172 -0
  12. package/_dist/door.d.ts.map +1 -0
  13. package/_dist/job.d.ts +26 -0
  14. package/_dist/job.d.ts.map +1 -0
  15. package/_dist/keys.d.ts +14 -0
  16. package/_dist/keys.d.ts.map +1 -0
  17. package/_dist/mod.d.ts +65 -0
  18. package/_dist/mod.d.ts.map +1 -0
  19. package/_dist/object.d.ts +75 -0
  20. package/_dist/object.d.ts.map +1 -0
  21. package/_dist/profile.d.ts +32 -0
  22. package/_dist/profile.d.ts.map +1 -0
  23. package/_dist/query-memory.d.ts +27 -0
  24. package/_dist/query-memory.d.ts.map +1 -0
  25. package/_dist/resets.d.ts +208 -0
  26. package/_dist/resets.d.ts.map +1 -0
  27. package/_dist/rewind.d.ts +21 -0
  28. package/_dist/rewind.d.ts.map +1 -0
  29. package/_dist/sockets.d.ts +90 -0
  30. package/_dist/sockets.d.ts.map +1 -0
  31. package/_dist/sql.d.ts +72 -0
  32. package/_dist/sql.d.ts.map +1 -0
  33. package/_dist/store.d.ts +8 -0
  34. package/_dist/store.d.ts.map +1 -0
  35. package/alarm.js +126 -0
  36. package/alarm.js.map +1 -0
  37. package/alarm.ts +188 -0
  38. package/ceiling.js +536 -0
  39. package/ceiling.js.map +1 -0
  40. package/ceiling.ts +681 -0
  41. package/compose.js +201 -0
  42. package/compose.js.map +1 -0
  43. package/compose.ts +249 -0
  44. package/copy.js +394 -0
  45. package/copy.js.map +1 -0
  46. package/copy.ts +413 -0
  47. package/deno.json +1 -0
  48. package/door.js +364 -0
  49. package/door.js.map +1 -0
  50. package/door.ts +542 -0
  51. package/example.ts +108 -0
  52. package/holds.js +85 -0
  53. package/holds.js.map +1 -0
  54. package/holds.ts +72 -0
  55. package/job.js +151 -0
  56. package/job.js.map +1 -0
  57. package/job.ts +166 -0
  58. package/keys.js +59 -0
  59. package/keys.js.map +1 -0
  60. package/keys.ts +85 -0
  61. package/mod.js +65 -0
  62. package/mod.js.map +1 -0
  63. package/mod.ts +167 -0
  64. package/object.js +247 -0
  65. package/object.js.map +1 -0
  66. package/object.ts +385 -0
  67. package/package.json +68 -4
  68. package/profile.js +131 -0
  69. package/profile.js.map +1 -0
  70. package/profile.ts +150 -0
  71. package/query-memory.js +157 -0
  72. package/query-memory.js.map +1 -0
  73. package/query-memory.ts +240 -0
  74. package/resets.js +302 -0
  75. package/resets.js.map +1 -0
  76. package/resets.ts +353 -0
  77. package/rewind.js +68 -0
  78. package/rewind.js.map +1 -0
  79. package/rewind.ts +91 -0
  80. package/sockets.js +749 -0
  81. package/sockets.js.map +1 -0
  82. package/sockets.ts +991 -0
  83. package/sql.js +221 -0
  84. package/sql.js.map +1 -0
  85. package/sql.ts +330 -0
  86. package/store.js +58 -0
  87. package/store.js.map +1 -0
  88. package/store.ts +80 -0
  89. package/watches.js +8 -0
  90. package/watches.js.map +1 -0
  91. package/watches.ts +23 -0
@@ -0,0 +1,75 @@
1
+ import type { RecoverableListening } from "@yaks/api";
2
+ import { type Alarms, type Clock, type Options as Timing, type Work } from "./alarm.js";
3
+ import { type Ceiling, type Kv, type Options as Limits } from "./ceiling.js";
4
+ import { type Keys } from "./keys.js";
5
+ import type { Hibernation, Sockets, Wire } from "./sockets.js";
6
+ import type { DurableStorage } from "./sql.js";
7
+ /** The slice of `DurableObjectState` the class uses. */ export type State = Hibernation & {
8
+ id?: {
9
+ name?: string;
10
+ };
11
+ storage: DurableStorage & Alarms & {
12
+ kv?: Kv;
13
+ };
14
+ };
15
+ /** What an object opened: its door, its subscriptions and its works. */ export type Opened = {
16
+ /** Every request the object is sent. A socket is accepted here, through
17
+ * the object's {@link Durable.accept}, after whatever the door checks. An
18
+ * object with no door, called only through its own entries, answers every
19
+ * request 404. */ serve?(request: Request): Response | Promise<Response>;
20
+ /** The subscriptions its sockets serve; without them it takes none. */ subs?: RecoverableListening;
21
+ /** What its alarm works, in order (`./alarm.ts`). */ works?: Record<string, Work>;
22
+ /** Whether the object takes a socket's frame or close now. One it does
23
+ * not is let go unanswered, before anything is asked of its sockets, a
24
+ * clock probe included. */ admit?(ws: Wire): boolean | Promise<boolean>;
25
+ /** The sockets serving `ws` now, where the object makes its own over
26
+ * subscriptions it remakes (`subs` makes them once), or keeps several sets
27
+ * of them, asked once a frame or close is admitted and a clock probe
28
+ * answered. None hangs a frame's socket up: the page must open another. */ live?(ws: Wire): Sockets | undefined | Promise<Sockets | undefined>;
29
+ /** A frame from one of its sockets, given `take`, the sockets' own reading
30
+ * of it, which answers whether they took it: the object reads frames
31
+ * itself, or around them. */ frame?(ws: Wire, data: string | ArrayBuffer, take: () => Promise<boolean>): unknown;
32
+ /** One of its sockets went away, once its sockets let it go. */ closed?(ws: Wire): unknown;
33
+ };
34
+ /** What makes one kind of object. */ export type Spec = {
35
+ /** Compose what the object holds, once an instance, given the object: its
36
+ * state, its clock and its ceiling; nothing by default. */ open?(object: Durable): Promise<Opened>;
37
+ /** A failure the object caught, by the entry it was caught in. */ report(error: unknown, entry: string): unknown;
38
+ /** The row ceiling's options, refusing by default. Without them the
39
+ * object counts against the ceiling its storage already has: the one named
40
+ * first, or one that reports and refuses nothing. */ ceiling?: Limits;
41
+ /** The alarm's timing (`./alarm.ts`). */ alarm?: Pick<Timing, 'slice' | 'backstop' | 'retry' | 'keep' | 'now' | 'around'>;
42
+ /** The deploy the object runs, whose first entry arms the alarm. */ version?: string;
43
+ /** Each entry's work, run inside what the object measures it by. */ around?<T>(entry: string, work: () => Promise<T>): Promise<T>;
44
+ };
45
+ /** One Durable Object, of the kind its spec makes. */ export declare class Durable {
46
+ /** The object's own state: its storage and its sockets. */ readonly ctx: State;
47
+ /** Without a `spec`, the object asks its `specify()` for one. */ constructor(ctx: State, spec?: Spec);
48
+ /** What makes this kind of object, asked once, at the object's first
49
+ * entry or its ceiling: a subclass whose spec names its own members
50
+ * answers it here. */ protected specify(): Spec;
51
+ /** What makes this object. */ get spec(): Spec;
52
+ /** The object's row ceiling, made at its first statement through the
53
+ * object. A subclass that opens a driver of its own before (`open` is the
54
+ * object's) names its ceiling first, with `this.ceiling` at the end of its
55
+ * constructor: every driver counts against the ceiling made first. */ get ceiling(): Ceiling;
56
+ /** The object's async key-value storage, each call counted against its
57
+ * ceiling as a statement is (`./keys.ts`). */ get keys(): Keys;
58
+ /** The object's alarm: a write that owes work arms it. */ get clock(): Clock;
59
+ /** The object's sockets, once it has opened subscriptions. */ get live(): Sockets | undefined;
60
+ /** What the object holds, opened once an instance; its sockets woken. */ open(): Promise<Opened>;
61
+ /** A socket for this object's subscriptions: the door's to call. */ accept(...args: Parameters<Sockets['accept']>): Response;
62
+ /** A request: the door's answer, `Stopped`'s with how long to wait, or a
63
+ * 503 for a failure the door did not answer, which is reported. */ fetch(request: Request): Promise<Response>;
64
+ /** An entry of the subclass's own, such as an RPC method: `work`, given
65
+ * what the object opened, inside `around` as `entry`. What it throws is
66
+ * thrown on to its caller, and a failure other than the ceiling's
67
+ * `Stopped` is reported by `entry` first, as a request's is. */ protected enter<T>(entry: string, work: (opened: Opened) => T | Promise<T>): Promise<T>;
68
+ /** The runtime's clock going off: one slice of every work. */ alarm(): Promise<void>;
69
+ /** A frame from one of the object's sockets. A clock probe is answered
70
+ * once the frame is admitted, before the sockets are asked; each frame
71
+ * they read runs inside `around`, as `ws <kind>`. */ webSocketMessage(ws: Wire, data: string | ArrayBuffer): void | Promise<void>;
72
+ /** One of its sockets went away. */ webSocketClose(ws: Wire): void | Promise<void>;
73
+ /** One of its sockets failed, which is it going away. */ webSocketError(ws: Wire, _error: unknown): void | Promise<void>;
74
+ }
75
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.d.ts","sources":["../object.ts"],"names":[],"mappings":"AA+CA,cAAc,oBAAoB,yBAA8B;AAChE,SACE,KAAK,MAAM,EACX,KAAK,KAAK,EAEV,KAAK,WAAW,MAAM,EACtB,KAAK,IAAI,qBACQ;AACnB,SAEE,KAAK,OAAO,EACZ,KAAK,EAAE,EACP,KAAK,WAAW,MAAM,uBAEH;AACrB,SAAS,KAAK,IAAI,oBAAyB;AAC3C,cAAc,WAAW,EAAE,OAAO,EAAE,IAAI,uBAAsB;AAC9D,cAAc,cAAc,mBAAkB;AAE9C,sDAAsD,GACtD,YAAY,QAAQ;EAClB;IAAO,OAAO,MAAM;;EACpB,SAAS,iBAAiB;IAAW,KAAK;;;AAG5C,sEAAsE,GACtE,YAAY;EACV;;;kBAGgB,GAChB,OAAO,SAAS,UAAU,WAAW,QAAQ;EAC7C,qEAAqE,GACrE,OAAO;EACP,mDAAmD,GACnD,QAAQ,OAAO,MAAM,EAAE;EACvB;;2BAEyB,GACzB,OAAO,IAAI,OAAO,OAAO,GAAG,QAAQ,OAAO;EAC3C;;;2EAGyE,GACzE,MAAM,IAAI,OAAO,UAAU,SAAS,GAAG,QAAQ,UAAU,SAAS;EAClE;;6BAE2B,GAC3B,OACE,IAAI,MACJ,MAAM,MAAM,GAAG,aACf,YAAY,QAAQ,OAAO,IAC1B,OAAO;EACV,8DAA8D,GAC9D,QAAQ,IAAI,OAAO,OAAO;;AAG5B,mCAAmC,GACnC,YAAY;EACV;2DACyD,GACzD,MAAM,QAAQ,UAAU,QAAQ;EAChC,gEAAgE,GAChE,OAAO,OAAO,OAAO,EAAE,OAAO,MAAM,GAAG,OAAO;EAC9C;;qDAEmD,GACnD,UAAU;EACV,uCAAuC,GACvC,QAAQ,KACN,QACA,UAAU,aAAa,UAAU,SAAS,QAAQ;EAEpD,kEAAkE,GAClE,UAAU,MAAM;EAChB,kEAAkE,GAClE,QAAQ,GAAG,OAAO,MAAM,EAAE,YAAY,QAAQ,KAAK,QAAQ;;AAM7D,oDAAoD,GACpD,OAAO,cAAM;EACX,yDAAyD,GACzD,SAAS,KAAK,MAAK;EAUnB,+DAA+D,GAC/D,YAAY,KAAK,KAAK,EAAE,OAAO,IAAI;EAKnC;;sBAEoB,GACpB,UAAU,WAAW;EAIrB,4BAA4B,GAC5B,IAAI,QAAQ;EAIZ;;;sEAGoE,GACpE,IAAI,WAAW;EAOf;8CAC4C,GAC5C,IAAI,QAAQ;EAOZ,wDAAwD,GACxD,IAAI,SAAS;EAYb,4DAA4D,GAC5D,IAAI,QAAQ,UAAU,SAAS;EAI/B,uEAAuE,GACvE,AAAM,QAAQ,QAAQ;EAqCtB,kEAAkE,GAClE,OAAO,GAAG,MAAM,WAAW,QAAQ,UAAU,GAAG;EAKhD;mEACiE,GACjE,AAAM,MAAM,SAAS,OAAO,GAAG,QAAQ;EAgBvC;;;gEAG8D,GAC9D,UAAU,MAAM,GACd,OAAO,MAAM,EACb,OAAO,QAAQ,WAAW,IAAI,QAAQ,EAAE,GACvC,QAAQ;EAyBX,4DAA4D,GAC5D,SAAS,QAAQ,IAAI;EAmCrB;;qDAEmD,GACnD,iBAAiB,IAAI,IAAI,EAAE,MAAM,MAAM,GAAG,WAAW,GAAG,IAAI,GAAG,QAAQ,IAAI;EA0B3E,kCAAkC,GAClC,eAAe,IAAI,IAAI,GAAG,IAAI,GAAG,QAAQ,IAAI;EAa7C,uDAAuD,GACvD,eAAe,IAAI,IAAI,EAAE,QAAQ,OAAO,GAAG,IAAI,GAAG,QAAQ,IAAI;AAGhE"}
@@ -0,0 +1,32 @@
1
+ import type { Observe } from "./sql.js";
2
+ export type Cost = {
3
+ calls: number;
4
+ rowsRead: number;
5
+ rowsWritten: number;
6
+ };
7
+ export type Entry = Cost & {
8
+ id: string;
9
+ shape: string;
10
+ };
11
+ export type Operation = {
12
+ kind: string;
13
+ total: Cost;
14
+ statements: Entry[];
15
+ other: Cost;
16
+ };
17
+ export type Summary = {
18
+ ms: number;
19
+ total: Cost;
20
+ statements: Entry[];
21
+ other: Cost;
22
+ operations: Operation[];
23
+ };
24
+ /** Report the first nonempty window at once, then at most once per minute
25
+ * while this object stays awake. Shape and invocation buckets have fixed caps;
26
+ * `other` sums anything beyond them. `run` keeps a label across awaits, even
27
+ * when another request runs on the same object before the first resumes. */ export declare let profile: (emit: (summary: Summary) => void) => {
28
+ observe: Observe;
29
+ run: <T>(kind: string, work: () => T) => T;
30
+ flush: (now?: number) => void;
31
+ };
32
+ //# sourceMappingURL=profile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.d.ts","sources":["../profile.ts"],"names":[],"mappings":"AAKA,cAAc,OAAO,mBAA0B;AAE/C,YAAY;EACV,OAAO,MAAM;EACb,UAAU,MAAM;EAChB,aAAa,MAAM;;AAGrB,YAAY,QAAQ;EAAS,IAAI,MAAM;EAAE,OAAO,MAAM;;AAEtD,YAAY;EACV,MAAM,MAAM;EACZ,OAAO;EACP,YAAY;EACZ,OAAO;;AAGT,YAAY;EACV,IAAI,MAAM;EACV,OAAO;EACP,YAAY;EACZ,OAAO;EACP,YAAY;;AA4Ed;;;0EAG0E,GAC1E,OAAO,YAAI,UACT,OAAO,SAAS,YAAY,IAAI;EAGhC,SAAS;EACT,MAAM,GAAG,MAAM,MAAM,EAAE,YAAY,MAAM;EACzC,QAAQ,MAAM,MAAM,KAAK,IAAI;EAoC9B"}
@@ -0,0 +1,27 @@
1
+ import { Refused } from "@yaks/graph/errors";
2
+ type Spend = (bytes: number, limit?: number) => void;
3
+ /** Read a member's response under the enclosing Store's query allowance. */ export declare let queryJson: (answer: Response) => Promise<unknown>;
4
+ export declare class QueryPage extends Refused {
5
+ readonly budgetBytes: number;
6
+ readonly attemptedBytes: number;
7
+ readonly limit?: number;
8
+ constructor(budgetBytes: number, attemptedBytes: number, limit?: number, shared?: boolean);
9
+ }
10
+ type Read<T> = (spend: Spend) => T | Promise<T>;
11
+ type ReadOpts = {
12
+ signal?: AbortSignal;
13
+ admission?: 'page' | 'wide' | number;
14
+ };
15
+ type QueryMemory = {
16
+ (read: Read<Response>, opts?: ReadOpts) : Promise<Response>;
17
+ value<T>(read: Read<T>, opts: ReadOpts): Promise<T>;
18
+ };
19
+ type Sizes = {
20
+ /** The most one read may hold. */ page?: number;
21
+ /** The most every read in flight holds together. */ store?: number;
22
+ /** The wait for room, as its owner names and times its waits. */ admitting?: (wait: () => Promise<() => void>) => Promise<() => void>;
23
+ };
24
+ /** The shared memory allowance for one Store's query pages, including pages
25
+ * still being sent. A read can charge bytes it assembles outside the SQL
26
+ * cursor. `hold` releases a page when its body ends or is cancelled. */ export declare let queryMemory: (connection: () => object, hold: (answer: Response, release: () => void) => Response, _dts_1: never) => QueryMemory;
27
+ //# sourceMappingURL=query-memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-memory.d.ts","sources":["../query-memory.ts"],"names":[],"mappings":"AAEA,SAAS,OAAO,kCAAuC;KAGlD,SAAS,OAAO,MAAM,EAAE,QAAQ,MAAM,KAAK,IAAI;AAkCpD,0EAA0E,GAC1E,OAAO,YAAI,YAAmB,QAAQ,aAAW,QAAQ,OAAO,EAmB/D;AAED,OAAO,cAAM,kBAAkB;WAElB,aAAa,MAAM;WACnB,gBAAgB,MAAM;WACtB,QAAQ,MAAM;EAHzB,YACE,AAAS,aAAa,MAAM,EAC5B,AAAS,gBAAgB,MAAM,EAC/B,AAAS,QAAQ,MAAM,EACvB,gBAAc;AAwBlB;KAEK,KAAK,MAAM,OAAO,UAAU,IAAI,QAAQ;KAIxC;EAAa,SAAS;EAAa,YAAY,SAAS,SAAS,MAAM;;KAEvE;GACF,MAAM,KAAK,WAAW,OAAO,YAAW,QAAQ;EACjD,MAAM,GAAG,MAAM,KAAK,IAAI,MAAM,WAAW,QAAQ;;KAgD9C;EACH,gCAAgC,GAChC,OAAO,MAAM;EACb,kDAAkD,GAClD,QAAQ,MAAM;EACd,+DAA+D,GAC/D,aAAa,YAAY,cAAc,IAAI,MAAM,cAAc,IAAI;;AAGrE;;sEAEsE,GACtE,OAAO,YAAI,cACT,kBAAkB,MAAM,EACxB,OAAO,QAAQ,UAAU,eAAe,IAAI,KAAK,UACjD,kBAKC,YAuEF"}
@@ -0,0 +1,208 @@
1
+ import { type Clock } from "@yaks/fp";
2
+ /**
3
+ * The runtime moved this object to a new instance, and the work is run again
4
+ * by whoever owns it.
5
+ *
6
+ * ```ts
7
+ * import { assertEquals } from '@std/assert'
8
+ * let gone = new Error('Connection closed: this Durable Object instance is ' +
9
+ * 'no longer active. Reconnect or retry the request.')
10
+ * assertEquals(moved(gone), true)
11
+ * assertEquals(moved(new Error('Durable Object reset because its code was updated.')), true)
12
+ * assertEquals(moved(new Error('Internal error in Durable Object storage ' +
13
+ * 'caused object to be reset; reference = 48q6hau1fptrm6g69pk2lqqh')), true)
14
+ * assertEquals(moved(new Error('Internal error while starting up Durable ' +
15
+ * 'Object storage caused object to be reset; reference = k6485n9h')), true)
16
+ * assertEquals(moved(new Error('Network connection lost.')), true)
17
+ * assertEquals(moved(new Error('Durable Object storage operation exceeded ' +
18
+ * 'timeout which caused object to be reset.')), false)
19
+ * assertEquals(moved(null), false)
20
+ * ```
21
+ */ export declare let moved: (e: unknown) => boolean;
22
+ /** The slice of an object's storage that `replaced` asks. */ export type Own = {
23
+ sql: {
24
+ exec(query: string): unknown;
25
+ };
26
+ transactionSync<T>(body: () => T): T;
27
+ };
28
+ /**
29
+ * Whether the runtime has moved the object off the instance this storage
30
+ * belongs to. A moved instance refuses its own storage in the words `moved`
31
+ * knows, a lost connection among them, but not all of it: one reset for a
32
+ * deploy still answers a read and refuses every write (workerd's
33
+ * `ActorSqlite::requireNotBroken`). A transaction counts as a write even when
34
+ * its body only reads, so it asks both; the live instance answers. An
35
+ * instance the runtime killed for its CPU or memory limit is replaced too:
36
+ * its transactions say the kill (`killed`), which whoever met it first
37
+ * reports, and its reads go on failing as a lost connection.
38
+ *
39
+ * ```ts
40
+ * import { assertEquals } from '@std/assert'
41
+ * let reset = () => {
42
+ * throw new Error('Durable Object reset because its code was updated.')
43
+ * }
44
+ * let sql = { exec: () => [] }
45
+ * let live = { sql, transactionSync: <T>(body: () => T) => body() }
46
+ * assertEquals(replaced(live), false)
47
+ * assertEquals(replaced({ sql, transactionSync: reset }), true)
48
+ * assertEquals(replaced({ ...live, sql: { exec: reset } }), true)
49
+ * let cut = () => {
50
+ * throw new Error('Network connection lost.')
51
+ * }
52
+ * assertEquals(replaced({ ...live, sql: { exec: cut } }), true)
53
+ * let kill = () => {
54
+ * throw new Error("Durable Object's isolate exceeded its memory limit and was reset.")
55
+ * }
56
+ * assertEquals(replaced({ sql, transactionSync: kill }), true)
57
+ * ```
58
+ */ export declare let replaced: (storage: Own) => boolean;
59
+ /** How often `vacating` asks whether the instance was replaced. */ export declare let LOOK: number;
60
+ /**
61
+ * `run`'s answer, or the runtime's words once it moves the object off this
62
+ * instance while `run` has not answered. An instance reset under a request
63
+ * still runs it, and what the request waits on can stay unsettled after the
64
+ * reset, so the request never answers (T-160126). Failed in the words
65
+ * `evicted` knows, it is sent again by its caller to the instance that took
66
+ * its place, and the work left behind here can write nothing. While `run`
67
+ * waits, `replaced` is asked every `every` ms on `clock`.
68
+ *
69
+ * ```ts
70
+ * import { assertEquals, assertRejects } from '@std/assert'
71
+ * import { clock } from '@yaks/testing'
72
+ * let reset = false
73
+ * let storage = {
74
+ * sql: { exec: () => [] },
75
+ * transactionSync: <T>(body: () => T) => {
76
+ * if (reset) throw new Error('Durable Object reset because its code was updated.')
77
+ * return body()
78
+ * },
79
+ * }
80
+ * let time = clock()
81
+ * assertEquals(await vacating(() => Promise.resolve('ok'), storage, time), 'ok')
82
+ * let stuck = vacating(() => new Promise<never>(() => {}), storage, time)
83
+ * await time.advance(LOOK)
84
+ * reset = true
85
+ * await time.advance(LOOK)
86
+ * await assertRejects(() => stuck, Error, 'reset because its code was updated')
87
+ * ```
88
+ */ export declare let vacating: <T>(run: () => T, storage: Own, clock?: Clock, signal?: AbortSignal) => T;
89
+ /**
90
+ * The object was reset under a request, and the runtime's guidance is to fetch
91
+ * again: its own `retryable` flag on the error, or, on an older runtime, its
92
+ * words.
93
+ *
94
+ * ```ts
95
+ * import { assertEquals } from '@std/assert'
96
+ * assertEquals(evicted(Object.assign(new Error('reset'), { retryable: true })), true)
97
+ * assertEquals(evicted(new Error('Durable Object storage operation exceeded ' +
98
+ * 'timeout which caused object to be reset.')), true)
99
+ * assertEquals(evicted(new Error('boot failed')), false)
100
+ * assertEquals(evicted(null), false)
101
+ * ```
102
+ */ export declare let evicted: (e: unknown) => boolean;
103
+ /** A request dropped by an overloaded object before it could serve it. */ export declare let overloaded: (e: unknown) => e is Error;
104
+ /**
105
+ * The runtime reset the object under the call (`evicted`), or dropped the call
106
+ * from its queue (`overloaded`), in its flags or its words. A read, or a call
107
+ * carrying one idempotency key the object spends (door.ts `resending`), is
108
+ * sent again on it; a write with no key only on `untouched`. `retried` paces
109
+ * an overloaded object's resends apart (`backoff.crowded`).
110
+ *
111
+ * ```ts
112
+ * import { assertEquals } from '@std/assert'
113
+ * assertEquals(unserved(new Error('Network connection lost.')), true)
114
+ * assertEquals(unserved(Object.assign(new Error('x'), { overloaded: true })), true)
115
+ * assertEquals(unserved(new Error('boot failed')), false)
116
+ * ```
117
+ */ export declare let unserved: (e: unknown) => boolean;
118
+ /**
119
+ * The runtime itself says the object never ran the call: its own `overloaded`
120
+ * or `retryable` flag, on an error the object's code did not throw. The words
121
+ * show nothing, and neither does a flag on an error marked `remote`: an
122
+ * object that met an overloaded or reset object it called, and rethrew what
123
+ * it met, ran the call up to there, and may have written. The runtime gives
124
+ * an object's own uncaught error to its caller with the message intact and
125
+ * `remote` set. So this, never `unserved`, is what sends a write with no
126
+ * idempotency key again.
127
+ *
128
+ * ```ts
129
+ * import { assertEquals } from '@std/assert'
130
+ * let words = 'Durable Object is overloaded. Requests queued for too long.'
131
+ * assertEquals(untouched(Object.assign(new Error(words), { overloaded: true })), true)
132
+ * assertEquals(untouched(Object.assign(new Error('reset'), { retryable: true })), true)
133
+ * assertEquals(untouched(new Error(words)), false)
134
+ * assertEquals(untouched(Object.assign(new Error(words), { overloaded: true, remote: true })), false)
135
+ * assertEquals(untouched(new Error('Network connection lost.')), false)
136
+ * ```
137
+ */ export declare let untouched: (e: unknown) => boolean;
138
+ /**
139
+ * The runtime killed the object for its limits. Its own code never sees the
140
+ * kill, and the retry may well answer, so whoever sees these words reports
141
+ * them before anything retries, or nothing ever would (M-37965).
142
+ *
143
+ * ```ts
144
+ * import { assertEquals } from '@std/assert'
145
+ * assertEquals(killed(new Error('Durable Object exceeded its CPU time limit and was reset.')), true)
146
+ * assertEquals(killed(new Error('boot failed')), false)
147
+ * ```
148
+ */ export declare let killed: (e: unknown) => boolean;
149
+ /**
150
+ * The object's SQLite refused a statement for memory. The engine also says
151
+ * this when a statement's program passes its step limit, which no wait cures,
152
+ * so it is reported and never sent again.
153
+ *
154
+ * ```ts
155
+ * import { assertEquals } from '@std/assert'
156
+ * assertEquals(starved(new Error('out of memory: SQLITE_NOMEM')), true)
157
+ * assertEquals(starved(new Error('boot failed')), false)
158
+ * ```
159
+ */ export declare let starved: (e: unknown) => boolean;
160
+ /**
161
+ * The runtime failed inside itself and names no cause, only a reference for
162
+ * Cloudflare to look up. The work is tried again; a failure that persists
163
+ * through the retries is reported.
164
+ *
165
+ * ```ts
166
+ * import { assertEquals } from '@std/assert'
167
+ * assertEquals(opaque(new Error('internal error; reference = h1h5n5h0ltksfc1hb4h8qkit')), true)
168
+ * assertEquals(opaque(new Error('get: internal error; reference = abc')), false)
169
+ * assertEquals(opaque('internal error; reference = abc'), false)
170
+ * ```
171
+ */ export declare let opaque: (e: unknown) => e is Error;
172
+ export declare let backoff: {
173
+ pauses: number[];
174
+ crowded: number[];
175
+ };
176
+ /** How `retried` waits out a pause: half of it or more, so calls that failed
177
+ * together do not return together, on `clock` (the runtime's by default). */ export declare let jittered: (clock?: Clock) => any;
178
+ /**
179
+ * Send one replayable call again while it fails in words `retry` knows,
180
+ * pausing before each resend, once per `backoff` pause (`crowded` after an
181
+ * `overloaded` refusal), as `wait` waits one
182
+ * (`jittered` on the runtime's clock by default; a test hands its own). The
183
+ * last failure propagates unchanged.
184
+ *
185
+ * ```ts
186
+ * import { assertEquals } from '@std/assert'
187
+ * let sends = 0
188
+ * let send = () => {
189
+ * if (++sends < 3) throw new Error('Network connection lost.')
190
+ * return 'answered'
191
+ * }
192
+ * let paused: number[] = []
193
+ * let wait = (ms: number) => Promise.resolve(void paused.push(ms))
194
+ * assertEquals(await retried(send, true, evicted, wait), 'answered')
195
+ * assertEquals(paused, [100, 500])
196
+ * assertEquals(sends, 3)
197
+ * let crowded = Object.assign(new Error('queued too long'), { overloaded: true })
198
+ * let refused = 0
199
+ * let busy = () => {
200
+ * if (++refused < 3) throw crowded
201
+ * return 'answered'
202
+ * }
203
+ * paused = []
204
+ * assertEquals(await retried(busy, true, unserved, wait), 'answered')
205
+ * assertEquals(paused, [1000, 3000])
206
+ * ```
207
+ */ export declare let retried: <T>(send: () => T | Promise<T>, replayable?: boolean, retry?: (error: unknown) => boolean, wait?: (ms: number) => Promise<void>) => Promise<T>;
208
+ //# sourceMappingURL=resets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resets.d.ts","sources":["../resets.ts"],"names":[],"mappings":"AAaA,SAAS,KAAK,KAAK,wBAA4C;AAwB/D;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,YAAI,QAAS,GAAG,OAAO,KAAG,OAAO,CAAkB;AAE1D,2DAA2D,GAC3D,YAAY;EACV;IAAO,KAAK,OAAO,MAAM,GAAG,OAAO;;EACnC,gBAAgB,GAAG,YAAY,IAAI;;AAGrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BC,GACD,OAAO,YAAI,WAAY,SAAS,QAAM,OAAO,CAA4B;AAazE,iEAAiE,GACjE,OAAO,YAAI,aAAY;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BC,GACD,OAAO,YAAI,WAAY,GACrB,WAAW,GACX,SAAS,KACT,QAAO,OAEP,SAAS,gBACR,EAoBF;AAED;;;;;;;;;;;;;CAaC,GACD,OAAO,YAAI,UAAW,GAAG,OAAO,KAAG,OAAO,CAEuB;AAEjE,wEAAwE,GACxE,OAAO,YAAI,aAAc,GAAG,OAAO,KAAG,KAAK,MAKrC;AAEN;;;;;;;;;;;;;CAaC,GACD,OAAO,YAAI,WAAY,GAAG,OAAO,KAAG,OAAO,CAA+B;AAK1E;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,YAAI,YAAa,GAAG,OAAO,KAAG,OAAO,CAEK;AAEjD;;;;;;;;;;CAUC,GACD,OAAO,YAAI,SAAU,GAAG,OAAO,KAAG,OAAO,CACK;AAE9C;;;;;;;;;;CAUC,GACD,OAAO,YAAI,UAAW,GAAG,OAAO,KAAG,OAAO,CACK;AAE/C;;;;;;;;;;;CAWC,GACD,OAAO,YAAI,SAAU,GAAG,OAAO,KAAG,KAAK,MACO;AAkB9C,OAAO,YAAI;EAAW,QAAQ,MAAM;EAAI,SAAS,MAAM;EAGtD;AAED;2EAC2E,GAC3E,OAAO,YAAI,WAAY,QAAO,cAC4B;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BC,GACD,OAAO,YAAI,UAAiB,GAC1B,YAAY,IAAI,QAAQ,IACxB,sBACA,SAAQ,OAAO,OAAO,KAAK,OAAO,EAClC,QAAO,IAAI,MAAM,KAAK,QAAQ,IAAI,MACjC,QAAQ,GAUV"}
@@ -0,0 +1,21 @@
1
+ import { type Bucket } from "@yaks/blob/object";
2
+ /** The handoff lives outside the SQLite file that is about to move. A pointer
3
+ * without a count names an incomplete capture. Keep a completed capture
4
+ * until replay has committed. */ export type Handoff = {
5
+ id: string;
6
+ pages: number;
7
+ count?: number;
8
+ };
9
+ type BucketDoor = Pick<Bucket, 'get' | 'put' | 'delete' | 'list'>;
10
+ /** The persisted pages and the pointer used to find them after a restart. */ export type Rewind = {
11
+ read: () => Promise<Handoff | null>;
12
+ clear: (held: Handoff) => Promise<void>;
13
+ save: <T>(id: string, source: AsyncIterable<{
14
+ rows: T[];
15
+ count: number;
16
+ }>) => Promise<Handoff>;
17
+ replay: <T>(held: Handoff, apply: (rows: T[]) => Promise<void>) => Promise<void>;
18
+ };
19
+ /** Durable pages for one store's rewind. The caller serializes prepare and
20
+ * replay with the store's normal writers. */ export declare let handoff: (bucket: BucketDoor, name: string) => Rewind;
21
+ //# sourceMappingURL=rewind.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rewind.d.ts","sources":["../rewind.ts"],"names":[],"mappings":"AAAA,SAAS,KAAK,MAAM,iCAAwD;AAE5E;;+BAE+B,GAC/B,YAAY;EAAY,IAAI,MAAM;EAAE,OAAO,MAAM;EAAE,QAAQ,MAAM;;KAC5D,aAAa,KAAK,QAAQ,QAAQ,QAAQ,WAAW;AAE1D,2EAA2E,GAC3E,YAAY;EACV,YAAY,QAAQ,UAAU,IAAI;EAClC,QAAQ,MAAM,YAAY,QAAQ,IAAI;EACtC,OAAO,GACL,IAAI,MAAM,EACV,QAAQ;IAAgB,MAAM;IAAK,OAAO,MAAM;SAC7C,QAAQ;EACb,SAAS,GACP,MAAM,SACN,QAAQ,MAAM,QAAQ,QAAQ,IAAI,MAC/B,QAAQ,IAAI;;AAGnB;2CAC2C,GAC3C,OAAO,YAAI,UAAW,QAAQ,YAAY,MAAM,MAAM,KAAG,OAkExD"}
@@ -0,0 +1,90 @@
1
+ import { type PeerWriter, type RecoverableListening } from "@yaks/api";
2
+ import type { ReadOpts } from "@yaks/graph";
3
+ import type { DurableStorage } from "./sql.js";
4
+ /**
5
+ * The part of a hibernatable WebSocket this package uses: a frame out, and the
6
+ * attachment that is the socket's only durable memory. A Cloudflare Worker's
7
+ * server-side `WebSocket` satisfies it.
8
+ */ export type Wire = {
9
+ /** only an open socket can receive a frame; closing sockets may still be
10
+ * returned by `getWebSockets()` */ readyState: number;
11
+ /** send one frame, already serialized */ send(data: string): void;
12
+ /** close a connection whose messages keep exceeding its relay allowance */ close?(code?: number, reason?: string): void;
13
+ /** bytes waiting inside the socket transport */ bufferedAmount?: number;
14
+ /** hold a value on the socket itself — it survives hibernation (2KB cap) */ serializeAttachment(value: unknown): void;
15
+ /** read that value back, `null` when nothing was held */ deserializeAttachment(): unknown;
16
+ };
17
+ /**
18
+ * The part of a `DurableObjectState` this package uses: accepting a socket for
19
+ * hibernation, and finding the ones a woken object inherited.
20
+ */ export type Hibernation = {
21
+ /** hand a socket to the runtime, so it outlives this object's memory */ acceptWebSocket(ws: Wire, tags?: string[]): void;
22
+ /** every socket this object is serving, hibernated or not */ getWebSockets(): Wire[];
23
+ /** the object's storage, used when watches or delivery state exceed 2 KB */ storage: DurableStorage;
24
+ /** Keep an asynchronous transport delivery alive after its entry answers. */ waitUntil?(work: Promise<unknown>): void;
25
+ };
26
+ /** The plumbing an object wires its handlers to. */ export type Sockets = {
27
+ /** answer a `/ws` request: accept the socket for hibernation, return the 101 */ accept(request: Request, opts?: ReadOpts, writer?: PeerWriter, socket?: {
28
+ tags: string[];
29
+ opened: (ws: Wire) => void;
30
+ }): Response;
31
+ /** a frame arrived — the object's `webSocketMessage` */ message(ws: Wire, data: unknown, scope?: (kind: SocketKind, work: () => void | Promise<void>) => void | Promise<void>): void | Promise<void>;
32
+ /** a socket went away — the object's `webSocketClose` */ close(ws: Wire): void | Promise<void>;
33
+ /** re-open the subscriptions of every socket this object inherited; call it
34
+ * at the top of `fetch`, so a batch applied on a woken object still pushes.
35
+ * Cold peer-only recovery may omit proven static snapshots, not interests. */ wake(deferStatic?: boolean): void | Promise<void>;
36
+ };
37
+ type Renewals = {
38
+ at: (at: number, read: () => Promise<void>) => () => void;
39
+ run: () => Promise<number | null>;
40
+ };
41
+ type LiveSockets = Sockets & {
42
+ /** Refresh timed watches from the object's alarm and return the next due time. */ renew(): Promise<number | null>;
43
+ /** Each open socket's read as `update` makes it, kept on the socket, then
44
+ * checked again (`authorize`): a host told that a caller's standing moved
45
+ * (a seat taken away) says so here, rather than reading it on each frame.
46
+ * A socket refused closes. */ restand(update: (read: ReadOpts | undefined) => ReadOpts | undefined): Promise<void>;
47
+ };
48
+ /** Schedule subscription reads on the object's existing alarm. On a cold
49
+ * alarm, the adapter restores the socket's watches and reads their current
50
+ * answers, which supply fresh deadlines. The runtime holds no timer between
51
+ * reads. */ export declare let socketRenewals: (arm: (at: number) => Promise<void>, _dts_1: never) => Renewals;
52
+ /** The finite protocol label a host may use for aggregate socket costs.
53
+ * Frame ids, queries, relay values and malformed input never become labels. */ export type SocketKind = 'ack' | 'subscribe' | 'unsubscribe' | 'relay' | 'other';
54
+ /**
55
+ * Wire a Durable Object's sockets to a subscription registry. The object keeps
56
+ * one of these and calls it from its three handlers:
57
+ *
58
+ * ```ts
59
+ * // fetch(request) → live.wake(); live.accept(request)
60
+ * // webSocketMessage(ws, data) → live.message(ws, data)
61
+ * // webSocketClose(ws) → live.close(ws)
62
+ * ```
63
+ *
64
+ * Frames go straight to the socket; no durable write crosses it (a batch is
65
+ * applied with `POST /apply`, and the socket is how everyone hears about it).
66
+ * The one exception is a `sync: peers` relay, which crosses here because its
67
+ * lifetime is this socket's — see @yaks/api's `receive`.
68
+ */ export declare let sockets: (subs: RecoverableListening, ctx: Hibernation, report?: (error: Error) => void, opts?: {
69
+ /** On peer-only recovery, register static durable watch interests without
70
+ * repeating the snapshot already held by the page. Unknown queries open. */ deferStatic?: boolean;
71
+ /** Restore caller read context from the authenticated socket writer. */ read?: (read: ReadOpts | undefined, writer: PeerWriter | undefined) => ReadOpts;
72
+ /** A host whose authenticated standing expires on wake can require a
73
+ * new handshake before this writer relays again. */ writer?: (writer: PeerWriter) => boolean | Promise<boolean>;
74
+ /** Current read/delivery authority. Denial or failure retires the socket.
75
+ * Checked on recovery, input, and at transport delivery (including ACKs).
76
+ * `held` is the read the socket holds, as accepted or last `restand`. */ authorize?: (read: ReadOpts | undefined, writer: PeerWriter | undefined, held: ReadOpts | undefined) => boolean | Promise<boolean>;
77
+ /** Told each refusal a socket is sent, as the client reads it: an
78
+ * object on older code than its caller restarts on one, as it does on a
79
+ * refused request, since a socket's refusals come after its handshake was
80
+ * answered. */ refused?: (refusal: {
81
+ error: string;
82
+ message: string;
83
+ }) => void;
84
+ /** The subprotocol the host selected for this upgrade, if it uses one. */ protocol?: (request: Request) => string | undefined;
85
+ /** The alarm-backed scheduler used by this registry's timed watches. */ renewals?: Renewals;
86
+ /** How a burst of watch changes is put off until its stored map is
87
+ * written once (default: a timer of {@link SETTLE} ms, which also keeps
88
+ * the object from hibernating before the write is made). */ defer?: (write: () => void) => void;
89
+ }) => LiveSockets;
90
+ //# sourceMappingURL=sockets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sockets.d.ts","sources":["../sockets.ts"],"names":[],"mappings":"AAmBA,SAQE,KAAK,UAAU,EAGf,KAAK,oBAAoB,yBAIE;AAC7B,cAAc,QAAQ,2BAAgC;AAItD,cAAc,cAAc,mBAAkB;AAI9C;;;;CAIC,GACD,YAAY;EACV;mCACiC,GACjC,YAAY,MAAM;EAClB,uCAAuC,GACvC,KAAK,MAAM,MAAM,GAAG,IAAI;EACxB,yEAAyE,GACzE,OAAO,OAAO,MAAM,EAAE,SAAS,MAAM,GAAG,IAAI;EAC5C,8CAA8C,GAC9C,iBAAiB,MAAM;EACvB,0EAA0E,GAC1E,oBAAoB,OAAO,OAAO,GAAG,IAAI;EACzC,uDAAuD,GACvD,yBAAyB,OAAO;;AAGlC;;;CAGC,GACD,YAAY;EACV,sEAAsE,GACtE,gBAAgB,IAAI,MAAM,OAAO,MAAM,KAAK,IAAI;EAChD,2DAA2D,GAC3D,iBAAiB;EACjB,0EAA0E,GAC1E,SAAS;EACT,2EAA2E,GAC3E,WAAW,MAAM,QAAQ,OAAO,IAAI,IAAI;;AAG1C,kDAAkD,GAClD,YAAY;EACV,8EAA8E,GAC9E,OACE,SAAS,SACT,OAAO,UACP,SAAS,YACT;IAAW,MAAM,MAAM;IAAI,SAAS,IAAI,SAAS,IAAI;MACpD;EACH,sDAAsD,GACtD,QACE,IAAI,MACJ,MAAM,OAAO,EACb,SACE,MAAM,YACN,YAAY,IAAI,GAAG,QAAQ,IAAI,MAC5B,IAAI,GAAG,QAAQ,IAAI,IACvB,IAAI,GAAG,QAAQ,IAAI;EACtB,uDAAuD,GACvD,MAAM,IAAI,OAAO,IAAI,GAAG,QAAQ,IAAI;EACpC;;8EAE4E,GAC5E,KAAK,cAAc,OAAO,GAAG,IAAI,GAAG,QAAQ,IAAI;;KAG7C;EACH,KAAK,IAAI,MAAM,EAAE,YAAY,QAAQ,IAAI,YAAY,IAAI;EACzD,WAAW,QAAQ,MAAM,GAAG,IAAI;;KAG7B,cAAc;EACjB,gFAAgF,GAChF,SAAS,QAAQ,MAAM,GAAG,IAAI;EAC9B;;;8BAG4B,GAC5B,QACE,SAAS,MAAM,WAAW,SAAS,KAAK,WAAW,SAAS,GAC3D,QAAQ,IAAI;;AAGjB;;;UAGU,GACV,OAAO,YAAI,iBACT,MAAM,IAAI,MAAM,KAAK,QAAQ,IAAI,GACjC,kBAIC,SA4BF;AA4HD;6EAC6E,GAC7E,YAAY,aAAa,QAAQ,cAAc,gBAAgB,UAAU;AA+BzE;;;;;;;;;;;;;;CAcC,GACD,OAAO,YAAI,UACT,MAAM,sBACN,KAAK,aACL,UAAU,OAAO,UAAU,IAAI,EAC/B;EACE;8EAC0E,GAC1E,cAAc,OAAO;EACrB,sEAAsE,GACtE,QACE,MAAM,WAAW,SAAS,EAC1B,QAAQ,aAAa,SAAS,KAC3B;EACL;sDACkD,GAClD,UAAU,QAAQ,eAAe,OAAO,GAAG,QAAQ,OAAO;EAC1D;;2EAEuE,GACvE,aACE,MAAM,WAAW,SAAS,EAC1B,QAAQ,aAAa,SAAS,EAC9B,MAAM,WAAW,SAAS,KACvB,OAAO,GAAG,QAAQ,OAAO;EAC9B;;;iBAGa,GACb,WAAW;IAAW,OAAO,MAAM;IAAE,SAAS,MAAM;QAAO,IAAI;EAC/D,wEAAwE,GACxE,YAAY,SAAS,YAAY,MAAM,GAAG,SAAS;EACnD,sEAAsE,GACtE,WAAW;EACX;;8DAE0D,GAC1D,SAAS,aAAa,IAAI,KAAK,IAAI;MAEpC,YA4mBF"}
package/_dist/sql.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { type Driver, type Row } from "@yaks/sql";
2
+ /** A value the engine will bind: everything else is converted first. */ export type SqlValue = ArrayBuffer | string | number | null;
3
+ /**
4
+ * A table Cloudflare owns inside the object's SQLite. `_cf_KV` is the one
5
+ * behind `ctx.storage.kv` — the docs spell it `__cf_kv` and the engine reports
6
+ * it as `_cf_KV`, so neither the case nor the number of underscores is worth
7
+ * trusting — and `_cf_METADATA` is its neighbour.
8
+ *
9
+ * These are not merely uninteresting: workerd's SQL authorizer refuses them to
10
+ * the object's own statements — `access to _cf_KV.key is prohibited:
11
+ * SQLITE_AUTH` — while still listing them in `sqlite_master`. So anything that
12
+ * enumerates tables and then reads them must skip these or throw (T-34019).
13
+ */ export declare let prohibited: (name: string) => boolean;
14
+ /**
15
+ * Every table the object does not own: {@link prohibited} plus SQLite's own
16
+ * catalogue, which is readable but is nobody's data.
17
+ */ export declare let reserved: (name: string) => boolean;
18
+ /** What `exec` hands back — the rows, drained with `toArray()`. */ export type SqlCursor<T> = Iterable<T> & {
19
+ /** every remaining row, read at once */ toArray(): T[];
20
+ /** The runtime's metered rows, available after the cursor is drained. */ rowsRead?: number;
21
+ rowsWritten?: number;
22
+ };
23
+ export type Sample = {
24
+ shape: string;
25
+ rowsRead: number;
26
+ rowsWritten: number;
27
+ };
28
+ export type Observe = (sample: Sample) => void;
29
+ export type Measure = (rowsRead?: number, rowsWritten?: number, shape?: () => string) => void;
30
+ /**
31
+ * The synchronous SQLite handle of a Durable Object — the shape of
32
+ * `ctx.storage.sql`, reduced to the one method this package calls. Naming just
33
+ * this keeps the adapter free of any Cloudflare dependency; a `SqlStorage`
34
+ * satisfies it.
35
+ */ export type DurableSql = {
36
+ /** The runtime's stored-byte count, without a SQL statement. */ readonly databaseSize?: number;
37
+ /** run a statement with its bindings and hand back the rows */ exec(query: string, ...bindings: SqlValue[]): SqlCursor<Row>;
38
+ };
39
+ /**
40
+ * The object's storage — the shape of `ctx.storage`: its SQLite handle, and
41
+ * the transaction the runtime insists on. `transactionSync` nests, commits
42
+ * when the body returns, and rolls back when it throws.
43
+ */ export type DurableStorage = {
44
+ /** the embedded SQLite engine */ sql: DurableSql;
45
+ /** run a body as one all-or-nothing unit of work */ transactionSync<T>(body: () => T): T;
46
+ };
47
+ /** Erase the database and release its connection. Open new drivers to use the
48
+ * empty storage so none of the old database's schema or rows stay cached. */ export declare let clearStorage: (durable: DurableStorage & {
49
+ deleteAll(): Promise<void>;
50
+ }) => Promise<void>;
51
+ /**
52
+ * A {@link https://jsr.io/@yaks/sql | @yaks/sql} `Driver` over a Durable
53
+ * Object's storage. It converts the values the engine will not take, hands the
54
+ * transaction back to `transactionSync`, and turns foreign keys on — the
55
+ * enforcement the schema's references are written for, which workerd leaves off
56
+ * per connection.
57
+ *
58
+ * ```ts
59
+ * // let store = storage(ctx.storage, vocab) // …which is this, bound
60
+ * ```
61
+ */ export declare let driver: (durable: DurableStorage, observe?: Observe, measure?: Measure) => Driver;
62
+ /**
63
+ * A {@link driver} whose statements are counted against the object's ceiling
64
+ * (./ceiling.ts) and never refused, its transactions included: for work that
65
+ * must not stop half way, such as a copy of the whole object an admin
66
+ * started. What it costs is still told as it runs.
67
+ *
68
+ * ```ts
69
+ * // let sql = freely(ctx.storage)
70
+ * ```
71
+ */ export declare let freely: (durable: DurableStorage, observe?: Observe, measure?: Measure) => Driver;
72
+ //# sourceMappingURL=sql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql.d.ts","sources":["../sql.ts"],"names":[],"mappings":"AAkBA,SAKE,KAAK,MAAM,EAMX,KAAK,GAAG,yBAQmB;AAM7B,sEAAsE,GACtE,YAAY,WAAW,cAAc,MAAM,GAAG,MAAM,GAAG,IAAI;AAE3D;;;;;;;;;;CAUC,GACD,OAAO,YAAI,aAAc,MAAM,MAAM,KAAG,OAAO,CAAwB;AAEvE;;;CAGC,GACD,OAAO,YAAI,WAAY,MAAM,MAAM,KAAG,OAAO,CACD;AAE5C,iEAAiE,GACjE,YAAY,UAAU,KAAK,SAAS;EAClC,sCAAsC,GACtC,WAAW;EACX,uEAAuE,GACvE,WAAW,MAAM;EACjB,cAAc,MAAM;;AAGtB,YAAY;EACV,OAAO,MAAM;EACb,UAAU,MAAM;EAChB,aAAa,MAAM;;AAGrB,YAAY,WAAW,QAAQ,WAAW,IAAI;AAC9C,YAAY,WACV,WAAW,MAAM,EACjB,cAAc,MAAM,EACpB,cAAc,MAAM,KACjB,IAAI;AAET;;;;;CAKC,GACD,YAAY;EACV,8DAA8D,YACrD,eAAe,MAAM;EAC9B,6DAA6D,GAC7D,KAAK,OAAO,MAAM,EAAE,GAAG,UAAU,aAAa,UAAU;;AAG1D;;;;CAIC,GACD,YAAY;EACV,+BAA+B,GAC/B,KAAK;EACL,kDAAkD,GAClD,gBAAgB,GAAG,YAAY,IAAI;;AA6CrC;2EAC2E,GAC3E,OAAO,YAAI,eACT,SAAS;EAAmB,aAAa,QAAQ,IAAI;MACpD,QAAQ,IAAI,EAGd;AAaD;;;;;;;;;;CAUC,GACD,OAAO,YAAI,SACT,SAAS,gBACT,UAAU,SACV,UAAU,YACT,OAkHF;AAED;;;;;;;;;CASC,GACD,OAAO,YAAI,SACT,SAAS,gBACT,UAAU,SACV,UAAU,YACT,OASF"}
@@ -0,0 +1,8 @@
1
+ import type { Opts, Store } from "@yaks/sqlite";
2
+ import type { Vocab } from "@yaks/vocab";
3
+ import { type DurableStorage, type Measure, type Observe } from "./sql.js";
4
+ export type { Opts, Store };
5
+ export declare let storage: (durable: DurableStorage, vocab: Vocab, base?: Opts, observe?: Observe, measure?: Measure) => Store & {
6
+ upkeep: (run?: boolean) => number | null;
7
+ };
8
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sources":["../store.ts"],"names":[],"mappings":"AAOA,cAAc,IAAI,EAAE,KAAK,4BAAiC;AAG1D,cAAc,KAAK,2BAAgC;AACnD,SAEE,KAAK,cAAc,EACnB,KAAK,OAAO,EACZ,KAAK,OAAO,mBACG;AAEjB,cAAc,IAAI,EAAE,KAAK,GAAE;AAuB3B,OAAO,YAAI,UACT,SAAS,gBACT,OAAO,OACP,OAAM,MACN,UAAU,SACV,UAAU,YACT;EAAU,SAAS,MAAM,OAAO,KAAK,MAAM,GAAG,IAAI;EAgCpD"}