@autumnsgrove/lyra 0.0.0-stage → 0.1.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 (178) hide show
  1. package/dist/adapters/cloudflare/index.d.ts +11 -0
  2. package/dist/adapters/cloudflare/index.d.ts.map +1 -0
  3. package/dist/adapters/cloudflare/index.js +11 -0
  4. package/dist/adapters/cloudflare/index.js.map +1 -0
  5. package/dist/adapters/cloudflare/secrets.d.ts +15 -0
  6. package/dist/adapters/cloudflare/secrets.d.ts.map +1 -0
  7. package/dist/adapters/cloudflare/secrets.js +24 -0
  8. package/dist/adapters/cloudflare/secrets.js.map +1 -0
  9. package/dist/adapters/cloudflare/storage.d.ts +43 -0
  10. package/dist/adapters/cloudflare/storage.d.ts.map +1 -0
  11. package/dist/adapters/cloudflare/storage.js +89 -0
  12. package/dist/adapters/cloudflare/storage.js.map +1 -0
  13. package/dist/adapters/cloudflare/waking.d.ts +34 -0
  14. package/dist/adapters/cloudflare/waking.d.ts.map +1 -0
  15. package/dist/adapters/cloudflare/waking.js +63 -0
  16. package/dist/adapters/cloudflare/waking.js.map +1 -0
  17. package/dist/adapters/memory/ids.d.ts +12 -0
  18. package/dist/adapters/memory/ids.d.ts.map +1 -0
  19. package/dist/adapters/memory/ids.js +20 -0
  20. package/dist/adapters/memory/ids.js.map +1 -0
  21. package/dist/adapters/memory/index.d.ts +13 -0
  22. package/dist/adapters/memory/index.d.ts.map +1 -0
  23. package/dist/adapters/memory/index.js +13 -0
  24. package/dist/adapters/memory/index.js.map +1 -0
  25. package/dist/adapters/memory/secrets.d.ts +14 -0
  26. package/dist/adapters/memory/secrets.d.ts.map +1 -0
  27. package/dist/adapters/memory/secrets.js +19 -0
  28. package/dist/adapters/memory/secrets.js.map +1 -0
  29. package/dist/adapters/memory/storage.d.ts +24 -0
  30. package/dist/adapters/memory/storage.d.ts.map +1 -0
  31. package/dist/adapters/memory/storage.js +40 -0
  32. package/dist/adapters/memory/storage.js.map +1 -0
  33. package/dist/adapters/memory/waking.d.ts +21 -0
  34. package/dist/adapters/memory/waking.d.ts.map +1 -0
  35. package/dist/adapters/memory/waking.js +29 -0
  36. package/dist/adapters/memory/waking.js.map +1 -0
  37. package/dist/core/clock.d.ts +22 -0
  38. package/dist/core/clock.d.ts.map +1 -0
  39. package/dist/core/clock.js +10 -0
  40. package/dist/core/clock.js.map +1 -0
  41. package/dist/core/conversation.d.ts +28 -0
  42. package/dist/core/conversation.d.ts.map +1 -0
  43. package/dist/core/conversation.js +9 -0
  44. package/dist/core/conversation.js.map +1 -0
  45. package/dist/core/decode-reply.d.ts +28 -0
  46. package/dist/core/decode-reply.d.ts.map +1 -0
  47. package/dist/core/decode-reply.js +158 -0
  48. package/dist/core/decode-reply.js.map +1 -0
  49. package/dist/core/define-recipe.d.ts +54 -0
  50. package/dist/core/define-recipe.d.ts.map +1 -0
  51. package/dist/core/define-recipe.js +96 -0
  52. package/dist/core/define-recipe.js.map +1 -0
  53. package/dist/core/events.d.ts +98 -0
  54. package/dist/core/events.d.ts.map +1 -0
  55. package/dist/core/events.js +14 -0
  56. package/dist/core/events.js.map +1 -0
  57. package/dist/core/execute-tools.d.ts +61 -0
  58. package/dist/core/execute-tools.d.ts.map +1 -0
  59. package/dist/core/execute-tools.js +147 -0
  60. package/dist/core/execute-tools.js.map +1 -0
  61. package/dist/core/finish.d.ts +53 -0
  62. package/dist/core/finish.d.ts.map +1 -0
  63. package/dist/core/finish.js +106 -0
  64. package/dist/core/finish.js.map +1 -0
  65. package/dist/core/handles.d.ts +34 -0
  66. package/dist/core/handles.d.ts.map +1 -0
  67. package/dist/core/handles.js +81 -0
  68. package/dist/core/handles.js.map +1 -0
  69. package/dist/core/json.d.ts +19 -0
  70. package/dist/core/json.d.ts.map +1 -0
  71. package/dist/core/json.js +41 -0
  72. package/dist/core/json.js.map +1 -0
  73. package/dist/core/limits.d.ts +53 -0
  74. package/dist/core/limits.d.ts.map +1 -0
  75. package/dist/core/limits.js +81 -0
  76. package/dist/core/limits.js.map +1 -0
  77. package/dist/core/model.d.ts +66 -0
  78. package/dist/core/model.d.ts.map +1 -0
  79. package/dist/core/model.js +10 -0
  80. package/dist/core/model.js.map +1 -0
  81. package/dist/core/recipe.d.ts +45 -0
  82. package/dist/core/recipe.d.ts.map +1 -0
  83. package/dist/core/recipe.js +102 -0
  84. package/dist/core/recipe.js.map +1 -0
  85. package/dist/core/result.d.ts +38 -0
  86. package/dist/core/result.d.ts.map +1 -0
  87. package/dist/core/result.js +35 -0
  88. package/dist/core/result.js.map +1 -0
  89. package/dist/core/resume.d.ts +71 -0
  90. package/dist/core/resume.d.ts.map +1 -0
  91. package/dist/core/resume.js +133 -0
  92. package/dist/core/resume.js.map +1 -0
  93. package/dist/core/run-handle.d.ts +39 -0
  94. package/dist/core/run-handle.d.ts.map +1 -0
  95. package/dist/core/run-handle.js +101 -0
  96. package/dist/core/run-handle.js.map +1 -0
  97. package/dist/core/run.d.ts +136 -0
  98. package/dist/core/run.d.ts.map +1 -0
  99. package/dist/core/run.js +1095 -0
  100. package/dist/core/run.js.map +1 -0
  101. package/dist/core/runtime.d.ts +81 -0
  102. package/dist/core/runtime.d.ts.map +1 -0
  103. package/dist/core/runtime.js +201 -0
  104. package/dist/core/runtime.js.map +1 -0
  105. package/dist/core/schema.d.ts +119 -0
  106. package/dist/core/schema.d.ts.map +1 -0
  107. package/dist/core/schema.js +469 -0
  108. package/dist/core/schema.js.map +1 -0
  109. package/dist/core/slots.d.ts +32 -0
  110. package/dist/core/slots.d.ts.map +1 -0
  111. package/dist/core/slots.js +10 -0
  112. package/dist/core/slots.js.map +1 -0
  113. package/dist/core/state.d.ts +18 -0
  114. package/dist/core/state.d.ts.map +1 -0
  115. package/dist/core/state.js +53 -0
  116. package/dist/core/state.js.map +1 -0
  117. package/dist/core/system-clock.d.ts +17 -0
  118. package/dist/core/system-clock.d.ts.map +1 -0
  119. package/dist/core/system-clock.js +59 -0
  120. package/dist/core/system-clock.js.map +1 -0
  121. package/dist/core/tool.d.ts +74 -0
  122. package/dist/core/tool.d.ts.map +1 -0
  123. package/dist/core/tool.js +48 -0
  124. package/dist/core/tool.js.map +1 -0
  125. package/dist/index.d.ts +35 -0
  126. package/dist/index.d.ts.map +1 -0
  127. package/dist/index.js +35 -0
  128. package/dist/index.js.map +1 -0
  129. package/dist/record/entries.d.ts +152 -0
  130. package/dist/record/entries.d.ts.map +1 -0
  131. package/dist/record/entries.js +497 -0
  132. package/dist/record/entries.js.map +1 -0
  133. package/dist/record/load.d.ts +29 -0
  134. package/dist/record/load.d.ts.map +1 -0
  135. package/dist/record/load.js +106 -0
  136. package/dist/record/load.js.map +1 -0
  137. package/dist/record/replay.d.ts +16 -0
  138. package/dist/record/replay.d.ts.map +1 -0
  139. package/dist/record/replay.js +63 -0
  140. package/dist/record/replay.js.map +1 -0
  141. package/dist/record/truncate.d.ts +25 -0
  142. package/dist/record/truncate.d.ts.map +1 -0
  143. package/dist/record/truncate.js +167 -0
  144. package/dist/record/truncate.js.map +1 -0
  145. package/dist/testkit/clock.d.ts +19 -0
  146. package/dist/testkit/clock.d.ts.map +1 -0
  147. package/dist/testkit/clock.js +77 -0
  148. package/dist/testkit/clock.js.map +1 -0
  149. package/dist/testkit/crashing-storage.d.ts +23 -0
  150. package/dist/testkit/crashing-storage.d.ts.map +1 -0
  151. package/dist/testkit/crashing-storage.js +39 -0
  152. package/dist/testkit/crashing-storage.js.map +1 -0
  153. package/dist/testkit/index.d.ts +15 -0
  154. package/dist/testkit/index.d.ts.map +1 -0
  155. package/dist/testkit/index.js +15 -0
  156. package/dist/testkit/index.js.map +1 -0
  157. package/dist/testkit/model.d.ts +53 -0
  158. package/dist/testkit/model.d.ts.map +1 -0
  159. package/dist/testkit/model.js +80 -0
  160. package/dist/testkit/model.js.map +1 -0
  161. package/dist/testkit/scenario.d.ts +55 -0
  162. package/dist/testkit/scenario.d.ts.map +1 -0
  163. package/dist/testkit/scenario.js +505 -0
  164. package/dist/testkit/scenario.js.map +1 -0
  165. package/dist/testkit/storage.d.ts +18 -0
  166. package/dist/testkit/storage.d.ts.map +1 -0
  167. package/dist/testkit/storage.js +27 -0
  168. package/dist/testkit/storage.js.map +1 -0
  169. package/dist/testkit/timeline-recipe.d.ts +59 -0
  170. package/dist/testkit/timeline-recipe.d.ts.map +1 -0
  171. package/dist/testkit/timeline-recipe.js +322 -0
  172. package/dist/testkit/timeline-recipe.js.map +1 -0
  173. package/dist/testkit/tools.d.ts +47 -0
  174. package/dist/testkit/tools.d.ts.map +1 -0
  175. package/dist/testkit/tools.js +82 -0
  176. package/dist/testkit/tools.js.map +1 -0
  177. package/package.json +42 -5
  178. package/README.md +0 -3
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The Cloudflare entry point (decision 12, step 4).
3
+ *
4
+ * Three slots over plain Durable Objects (decision 72): the record in SQLite, the
5
+ * wake as the object's one alarm, and secrets as Worker bindings. The core never
6
+ * imports this, and this imports the core and nothing else.
7
+ */
8
+ export * from "./secrets.js";
9
+ export * from "./storage.js";
10
+ export * from "./waking.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/cloudflare/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The Cloudflare entry point (decision 12, step 4).
3
+ *
4
+ * Three slots over plain Durable Objects (decision 72): the record in SQLite, the
5
+ * wake as the object's one alarm, and secrets as Worker bindings. The core never
6
+ * imports this, and this imports the core and nothing else.
7
+ */
8
+ export * from "./secrets.js";
9
+ export * from "./storage.js";
10
+ export * from "./waking.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/cloudflare/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Secrets over Worker bindings (docs/adapters.md, CFL19 to CFL21).
3
+ *
4
+ * A tool asks for a key by name and gets a string, or nothing. That is the whole
5
+ * adapter: bindings are the host's, a non-string binding is not a secret (a KV
6
+ * namespace or a Durable Object namespace is not text), and a name the object does
7
+ * not own — including `__proto__` and `constructor` — is simply not held.
8
+ *
9
+ * The value never reaches a log, an error message or the record. A tool that needs
10
+ * a missing secret gets `undefined` and says so by name; what a name maps to stays
11
+ * in the host.
12
+ */
13
+ import type { SecretsSlot } from "../../core/slots.js";
14
+ export declare function bindingSecrets(env: object): SecretsSlot;
15
+ //# sourceMappingURL=secrets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../../src/adapters/cloudflare/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAUvD"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Secrets over Worker bindings (docs/adapters.md, CFL19 to CFL21).
3
+ *
4
+ * A tool asks for a key by name and gets a string, or nothing. That is the whole
5
+ * adapter: bindings are the host's, a non-string binding is not a secret (a KV
6
+ * namespace or a Durable Object namespace is not text), and a name the object does
7
+ * not own — including `__proto__` and `constructor` — is simply not held.
8
+ *
9
+ * The value never reaches a log, an error message or the record. A tool that needs
10
+ * a missing secret gets `undefined` and says so by name; what a name maps to stays
11
+ * in the host.
12
+ */
13
+ export function bindingSecrets(env) {
14
+ return {
15
+ async get(name) {
16
+ // An own property only, so a prototype name is a miss rather than a function,
17
+ // and a descriptor so a non-string binding (a namespace, an object) is not a
18
+ // secret rather than a surprise.
19
+ const value = Object.getOwnPropertyDescriptor(env, name)?.value;
20
+ return typeof value === "string" ? value : undefined;
21
+ },
22
+ };
23
+ }
24
+ //# sourceMappingURL=secrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../../src/adapters/cloudflare/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,MAAM,UAAU,cAAc,CAAC,GAAW;IACzC,OAAO;QACN,KAAK,CAAC,GAAG,CAAC,IAAY;YACrB,8EAA8E;YAC9E,6EAA6E;YAC7E,iCAAiC;YACjC,MAAM,KAAK,GAAG,MAAM,CAAC,wBAAwB,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC;YAChE,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;QACtD,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * A run's record in a Durable Object's SQLite storage (docs/adapters.md, STO01 to
3
+ * STO04 and CFL01 to CFL06; decisions 72 and 102).
4
+ *
5
+ * One row per line, in a fixed table, with `seq` as the primary key and the line
6
+ * exactly as the core encoded it. The table is created on first use rather than at
7
+ * construction, so a storage that is already broken comes back as a failed result
8
+ * instead of a throwing factory.
9
+ *
10
+ * The types are structural and local on purpose. `DurableObjectStorage` is a
11
+ * Workers global, and the core builds with no platform types at all; an adapter
12
+ * that needs one global would drag it into the program that checks everything
13
+ * else. The fixture passes the real `ctx.storage`, which satisfies this shape.
14
+ *
15
+ * `append` runs inside `transactionSync`, whose callback is synchronous, so two
16
+ * appends can never interleave: the next `seq` is read and the row written before
17
+ * the transaction ends (STO04). A transaction that throws rolls back, so a failed
18
+ * append leaves no gap.
19
+ */
20
+ import type { StorageSlot } from "../../core/slots.js";
21
+ /** One statement's rows, as the driver hands them over. */
22
+ export interface SqlCursorLike {
23
+ toArray(): Record<string, unknown>[];
24
+ }
25
+ /** The synchronous SQLite surface a Durable Object's storage exposes. */
26
+ export interface SqlStorageLike {
27
+ exec(query: string, ...bindings: unknown[]): SqlCursorLike;
28
+ }
29
+ /** What this adapter needs from `DurableObjectStorage`, and nothing else. */
30
+ export interface DurableObjectSqlStorage {
31
+ readonly sql: SqlStorageLike;
32
+ transactionSync<T>(callback: () => T): T;
33
+ }
34
+ export interface CloudflareStorageOptions {
35
+ /**
36
+ * The largest line this adapter accepts, in bytes. It defaults to the record's
37
+ * own 1 MiB cap, which sits well under Cloudflare's 2 MB row limit, and a larger
38
+ * line is refused before SQLite sees it (decision 102).
39
+ */
40
+ maxEntryBytes?: number;
41
+ }
42
+ export declare function durableObjectStorage(storage: DurableObjectSqlStorage, options?: CloudflareStorageOptions): StorageSlot;
43
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/adapters/cloudflare/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,2DAA2D;AAC3D,MAAM,WAAW,aAAa;IAC7B,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;CACrC;AAED,yEAAyE;AACzE,MAAM,WAAW,cAAc;IAC9B,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC;CAC3D;AAED,6EAA6E;AAC7E,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC;IAC7B,eAAe,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,wBAAwB;IACxC;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAYD,wBAAgB,oBAAoB,CACnC,OAAO,EAAE,uBAAuB,EAChC,OAAO,GAAE,wBAA6B,GACpC,WAAW,CAkEb"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * A run's record in a Durable Object's SQLite storage (docs/adapters.md, STO01 to
3
+ * STO04 and CFL01 to CFL06; decisions 72 and 102).
4
+ *
5
+ * One row per line, in a fixed table, with `seq` as the primary key and the line
6
+ * exactly as the core encoded it. The table is created on first use rather than at
7
+ * construction, so a storage that is already broken comes back as a failed result
8
+ * instead of a throwing factory.
9
+ *
10
+ * The types are structural and local on purpose. `DurableObjectStorage` is a
11
+ * Workers global, and the core builds with no platform types at all; an adapter
12
+ * that needs one global would drag it into the program that checks everything
13
+ * else. The fixture passes the real `ctx.storage`, which satisfies this shape.
14
+ *
15
+ * `append` runs inside `transactionSync`, whose callback is synchronous, so two
16
+ * appends can never interleave: the next `seq` is read and the row written before
17
+ * the transaction ends (STO04). A transaction that throws rolls back, so a failed
18
+ * append leaves no gap.
19
+ */
20
+ import { fail, ok } from "../../core/result.js";
21
+ import { DEFAULT_ENTRY_CAP_BYTES } from "../../core/run.js";
22
+ const encoder = new TextEncoder();
23
+ /** UTF-8 bytes, which is what a storage limit is measured in. */
24
+ function byteLength(text) {
25
+ return encoder.encode(text).length;
26
+ }
27
+ const CREATE = "CREATE TABLE IF NOT EXISTS lyra_entries (seq INTEGER PRIMARY KEY, line TEXT NOT NULL)";
28
+ export function durableObjectStorage(storage, options = {}) {
29
+ const limit = options.maxEntryBytes ?? DEFAULT_ENTRY_CAP_BYTES;
30
+ let ready = false;
31
+ /** Create the table once. The caller decides whether it is inside a transaction. */
32
+ const ensureTable = () => {
33
+ if (ready) {
34
+ return;
35
+ }
36
+ storage.sql.exec(CREATE);
37
+ ready = true;
38
+ };
39
+ const slot = {
40
+ maxEntryBytes: limit,
41
+ async append(line) {
42
+ const bytes = byteLength(line);
43
+ if (bytes > limit) {
44
+ return fail("bad_request", `the line is ${bytes} bytes, over this adapter's limit of ${limit}`);
45
+ }
46
+ try {
47
+ const seq = storage.transactionSync(() => {
48
+ ensureTable();
49
+ const rows = storage.sql
50
+ .exec("SELECT COALESCE(MAX(seq), -1) AS last FROM lyra_entries")
51
+ .toArray();
52
+ const last = rows[0]?.["last"];
53
+ const next = (typeof last === "number" ? last : -1) + 1;
54
+ storage.sql.exec("INSERT INTO lyra_entries (seq, line) VALUES (?, ?)", next, line);
55
+ return next;
56
+ });
57
+ return ok({ seq });
58
+ }
59
+ catch (error) {
60
+ return fail("internal", `the record could not be saved: ${messageOf(error)}`);
61
+ }
62
+ },
63
+ async read() {
64
+ try {
65
+ ensureTable();
66
+ const rows = storage.sql
67
+ .exec("SELECT line FROM lyra_entries ORDER BY seq ASC")
68
+ .toArray();
69
+ const lines = [];
70
+ for (const row of rows) {
71
+ const line = row["line"];
72
+ if (typeof line !== "string") {
73
+ return fail("internal", "a saved line is not text");
74
+ }
75
+ lines.push(line);
76
+ }
77
+ return ok(lines);
78
+ }
79
+ catch (error) {
80
+ return fail("internal", `the record could not be read: ${messageOf(error)}`);
81
+ }
82
+ },
83
+ };
84
+ return slot;
85
+ }
86
+ function messageOf(error) {
87
+ return (error instanceof Error ? error.message : String(error)).slice(0, 200);
88
+ }
89
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/adapters/cloudflare/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,IAAI,EAAE,EAAE,EAAe,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AA4B5D,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,iEAAiE;AACjE,SAAS,UAAU,CAAC,IAAY;IAC/B,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;AACpC,CAAC;AAED,MAAM,MAAM,GACX,uFAAuF,CAAC;AAEzF,MAAM,UA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and one run active per session, so one row is enough: which
6
+ * run to wake, and when. `schedule` replaces the row and the alarm (Cloudflare keeps
7
+ * one alarm and `setAlarm` replaces it), and `cancel` removes both. The host's
8
+ * `alarm()` reads the row and calls `runtime.wake`, whose own registry is what makes
9
+ * a late, duplicated or concurrent alarm harmless.
10
+ *
11
+ * An alarm is delivered at least once and retried if the handler throws, so the
12
+ * host's handler must catch everything: a domain failure is a reason not to wake a
13
+ * run, not a reason to have Cloudflare try again forever.
14
+ *
15
+ * The types are structural and local, like the storage adapter's, so the core's
16
+ * program never learns a Workers global.
17
+ */
18
+ import type { WakingSlot } from "../../core/slots.js";
19
+ import type { DurableObjectSqlStorage } from "./storage.js";
20
+ /** What this adapter needs from `DurableObjectStorage`'s alarm surface. */
21
+ export interface DurableObjectAlarmStorage extends DurableObjectSqlStorage {
22
+ getAlarm(): Promise<number | null>;
23
+ setAlarm(scheduledTime: number | Date): Promise<void>;
24
+ deleteAlarm(): Promise<void>;
25
+ }
26
+ /** The one row: which run, and when it was due. */
27
+ export interface ScheduledWake {
28
+ runId: string;
29
+ atMs: number;
30
+ }
31
+ /** The wake this object holds, or nothing when it holds none. */
32
+ export declare function scheduledWake(storage: DurableObjectSqlStorage): Promise<ScheduledWake | undefined>;
33
+ export declare function alarmWaking(storage: DurableObjectAlarmStorage): WakingSlot;
34
+ //# sourceMappingURL=waking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"waking.d.ts","sourceRoot":"","sources":["../../../src/adapters/cloudflare/waking.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAE5D,2EAA2E;AAC3E,MAAM,WAAW,yBAA0B,SAAQ,uBAAuB;IACzE,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACnC,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED,mDAAmD;AACnD,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACb;AASD,iEAAiE;AACjE,wBAAsB,aAAa,CAClC,OAAO,EAAE,uBAAuB,GAC9B,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAapC;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,yBAAyB,GAAG,UAAU,CA8B1E"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * A run's wake as a Durable Object alarm (docs/adapters.md, CFL07 to CFL13; decisions
3
+ * 72 and 101).
4
+ *
5
+ * One alarm per object and one run active per session, so one row is enough: which
6
+ * run to wake, and when. `schedule` replaces the row and the alarm (Cloudflare keeps
7
+ * one alarm and `setAlarm` replaces it), and `cancel` removes both. The host's
8
+ * `alarm()` reads the row and calls `runtime.wake`, whose own registry is what makes
9
+ * a late, duplicated or concurrent alarm harmless.
10
+ *
11
+ * An alarm is delivered at least once and retried if the handler throws, so the
12
+ * host's handler must catch everything: a domain failure is a reason not to wake a
13
+ * run, not a reason to have Cloudflare try again forever.
14
+ *
15
+ * The types are structural and local, like the storage adapter's, so the core's
16
+ * program never learns a Workers global.
17
+ */
18
+ const CREATE = "CREATE TABLE IF NOT EXISTS lyra_wake (id INTEGER PRIMARY KEY CHECK (id = 0), run_id TEXT NOT NULL, at_ms INTEGER NOT NULL)";
19
+ function ensureTable(storage) {
20
+ storage.sql.exec(CREATE);
21
+ }
22
+ /** The wake this object holds, or nothing when it holds none. */
23
+ export async function scheduledWake(storage) {
24
+ ensureTable(storage);
25
+ const rows = storage.sql.exec("SELECT run_id, at_ms FROM lyra_wake WHERE id = 0").toArray();
26
+ const row = rows[0];
27
+ if (row === undefined) {
28
+ return undefined;
29
+ }
30
+ const runId = row["run_id"];
31
+ const atMs = row["at_ms"];
32
+ if (typeof runId !== "string" || typeof atMs !== "number") {
33
+ return undefined;
34
+ }
35
+ return { runId, atMs };
36
+ }
37
+ export function alarmWaking(storage) {
38
+ return {
39
+ async schedule(runId, atMs) {
40
+ storage.transactionSync(() => {
41
+ ensureTable(storage);
42
+ storage.sql.exec("DELETE FROM lyra_wake");
43
+ storage.sql.exec("INSERT INTO lyra_wake (id, run_id, at_ms) VALUES (0, ?, ?)", runId, atMs);
44
+ });
45
+ // The row is the truth; the alarm is when it will be read. Set it after the
46
+ // row so an alarm that fires immediately finds something to wake.
47
+ await storage.setAlarm(atMs);
48
+ },
49
+ async cancel(runId) {
50
+ // One run per session, so the row can only be this run's; the parameter is
51
+ // part of the slot's shape rather than something to match on. A cancel for
52
+ // a run the object no longer holds still clears the alarm, which is the
53
+ // harmless direction.
54
+ void runId;
55
+ storage.transactionSync(() => {
56
+ ensureTable(storage);
57
+ storage.sql.exec("DELETE FROM lyra_wake");
58
+ });
59
+ await storage.deleteAlarm();
60
+ },
61
+ };
62
+ }
63
+ //# sourceMappingURL=waking.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"waking.js","sourceRoot":"","sources":["../../../src/adapters/cloudflare/waking.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAkBH,MAAM,MAAM,GACX,4HAA4H,CAAC;AAE9H,SAAS,WAAW,CAAC,OAAgC;IACpD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC1B,CAAC;AAED,iEAAiE;AACjE,MAAM,CAAC,KAAK,UAAU,aAAa,CAClC,OAAgC;IAEhC,WAAW,CAAC,OAAO,CAAC,CAAC;IACrB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC,OAAO,EAAE,CAAC;IAC5F,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,G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`docs/core-loop.md`, "Time and identity are injected").
4
+ *
5
+ * This is not for a host that can be reached by anyone: an id that counts is
6
+ * guessable, and decision 85 wants an unguessable one for an approval. A host
7
+ * uses `systemIds`; a test uses these, because a record it can predict is a
8
+ * record it can compare byte for byte.
9
+ */
10
+ import type { Ids } from "../../core/clock.js";
11
+ export declare function counterIds(): Ids;
12
+ //# sourceMappingURL=ids.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../../src/adapters/memory/ids.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAE/C,wBAAgB,UAAU,IAAI,GAAG,CAShC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Ids as counters, so the same script writes the same record twice
3
+ * (`docs/core-loop.md`, "Time and identity are injected").
4
+ *
5
+ * This is not for a host that can be reached by anyone: an id that counts is
6
+ * guessable, and decision 85 wants an unguessable one for an approval. A host
7
+ * uses `systemIds`; a test uses these, because a record it can predict is a
8
+ * record it can compare byte for byte.
9
+ */
10
+ export function counterIds() {
11
+ const counters = new Map();
12
+ return {
13
+ next(prefix) {
14
+ const count = (counters.get(prefix) ?? 0) + 1;
15
+ counters.set(prefix, count);
16
+ return `${prefix}${count}`;
17
+ },
18
+ };
19
+ }
20
+ //# sourceMappingURL=ids.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ids.js","sourceRoot":"","sources":["../../../src/adapters/memory/ids.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,MAAM,UAAU,UAAU;IACzB,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC3C,OAAO;QACN,IAAI,CAAC,MAAM;YACV,MAAM,KAAK,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YAC9C,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAC5B,OAAO,GAAG,MAAM,GAAG,KAAK,EAAE,CAAC;QAC5B,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The in-memory adapter: a host for tests, a dev script, and anywhere a run does
3
+ * not need to outlive the process.
4
+ *
5
+ * It fills four of the five slots (there is no shell yet): storage, secrets,
6
+ * waking and ids. Everything here is deterministic, because a test that cannot
7
+ * predict the record cannot compare it (docs/adapters.md, decision 12).
8
+ */
9
+ export { counterIds } from "./ids.js";
10
+ export { memorySecrets, type MemorySecrets } from "./secrets.js";
11
+ export { memoryStorage, DEFAULT_MAX_LINE_BYTES, type MemoryStorage, type MemoryStorageOptions, } from "./storage.js";
12
+ export { memoryWaking, type MemoryWaking, type ScheduledWake } from "./waking.js";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/memory/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EACN,aAAa,EACb,sBAAsB,EACtB,KAAK,aAAa,EAClB,KAAK,oBAAoB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The in-memory adapter: a host for tests, a dev script, and anywhere a run does
3
+ * not need to outlive the process.
4
+ *
5
+ * It fills four of the five slots (there is no shell yet): storage, secrets,
6
+ * waking and ids. Everything here is deterministic, because a test that cannot
7
+ * predict the record cannot compare it (docs/adapters.md, decision 12).
8
+ */
9
+ export { counterIds } from "./ids.js";
10
+ export { memorySecrets } from "./secrets.js";
11
+ export { memoryStorage, DEFAULT_MAX_LINE_BYTES, } from "./storage.js";
12
+ export { memoryWaking } from "./waking.js";
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/memory/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AACjE,OAAO,EACN,aAAa,EACb,sBAAsB,GAGtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAyC,MAAM,aAAa,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Secrets in memory, for tests and for a host that has none to offer.
3
+ *
4
+ * A tool asks by name and gets a value or nothing; it never learns what else is
5
+ * held (decision 12). Nothing here is logged, and nothing is written down, which
6
+ * is what makes it safe for a test to hold a made-up key.
7
+ */
8
+ import type { SecretsSlot } from "../../core/slots.js";
9
+ export interface MemorySecrets extends SecretsSlot {
10
+ /** Put a value in place, so a test can change one between calls. */
11
+ set(name: string, value: string): void;
12
+ }
13
+ export declare function memorySecrets(initial?: Record<string, string>): MemorySecrets;
14
+ //# sourceMappingURL=secrets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../../src/adapters/memory/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,oEAAoE;IACpE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,aAAa,CAUjF"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Secrets in memory, for tests and for a host that has none to offer.
3
+ *
4
+ * A tool asks by name and gets a value or nothing; it never learns what else is
5
+ * held (decision 12). Nothing here is logged, and nothing is written down, which
6
+ * is what makes it safe for a test to hold a made-up key.
7
+ */
8
+ export function memorySecrets(initial = {}) {
9
+ const held = new Map(Object.entries(initial));
10
+ return {
11
+ async get(name) {
12
+ return held.get(name);
13
+ },
14
+ set(name, value) {
15
+ held.set(name, value);
16
+ },
17
+ };
18
+ }
19
+ //# sourceMappingURL=secrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../../src/adapters/memory/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,MAAM,UAAU,aAAa,CAAC,OAAO,GAA2B,EAAE;IACjE,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9C,OAAO;QACN,KAAK,CAAC,GAAG,CAAC,IAAI;YACb,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QACD,GAAG,CAAC,IAAI,EAAE,KAAK;YACd,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACvB,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Storage in memory (docs/adapters.md, "Spec rows: storage").
3
+ *
4
+ * A plain array of the lines as they were saved, which is enough for the loop,
5
+ * the testkit and the scenarios in-process. It keeps the same promise the
6
+ * Cloudflare adapter will: `seq` counts up from zero, a read is a copy, and a
7
+ * line over the adapter's limit is refused without being stored.
8
+ */
9
+ import type { StorageSlot } from "../../core/slots.js";
10
+ /**
11
+ * The record caps an entry at 1 MiB (decision 90), and this adapter's own limit
12
+ * defaults to the same number: a line this small always saves, and a line bigger
13
+ * than the record allows is not something the core will ask for.
14
+ */
15
+ export declare const DEFAULT_MAX_LINE_BYTES = 1048576;
16
+ export interface MemoryStorageOptions {
17
+ maxLineBytes?: number;
18
+ }
19
+ export interface MemoryStorage extends StorageSlot {
20
+ /** The lines saved so far, as a copy, for a test that wants to look directly. */
21
+ saved(): string[];
22
+ }
23
+ export declare function memoryStorage(options?: MemoryStorageOptions): MemoryStorage;
24
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/adapters/memory/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,UAAY,CAAC;AAEhD,MAAM,WAAW,oBAAoB;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,iFAAiF;IACjF,KAAK,IAAI,MAAM,EAAE,CAAC;CAClB;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa,CA6B/E"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Storage in memory (docs/adapters.md, "Spec rows: storage").
3
+ *
4
+ * A plain array of the lines as they were saved, which is enough for the loop,
5
+ * the testkit and the scenarios in-process. It keeps the same promise the
6
+ * Cloudflare adapter will: `seq` counts up from zero, a read is a copy, and a
7
+ * line over the adapter's limit is refused without being stored.
8
+ */
9
+ import { fail, ok } from "../../core/result.js";
10
+ /**
11
+ * The record caps an entry at 1 MiB (decision 90), and this adapter's own limit
12
+ * defaults to the same number: a line this small always saves, and a line bigger
13
+ * than the record allows is not something the core will ask for.
14
+ */
15
+ export const DEFAULT_MAX_LINE_BYTES = 1_048_576;
16
+ export function memoryStorage(options = {}) {
17
+ const limit = options.maxLineBytes ?? DEFAULT_MAX_LINE_BYTES;
18
+ const encoder = new TextEncoder();
19
+ const lines = [];
20
+ return {
21
+ // The core lowers its own cap to this when it is smaller, so nothing it saves
22
+ // can be refused here for size.
23
+ maxEntryBytes: limit,
24
+ saved: () => [...lines],
25
+ async append(line) {
26
+ const bytes = encoder.encode(line).length;
27
+ if (bytes > limit) {
28
+ return fail("bad_request", `the line is ${bytes} bytes, over this storage's limit of ${limit}`);
29
+ }
30
+ // The position is taken here, synchronously, so two appends issued without
31
+ // waiting for the first cannot take the same `seq`.
32
+ lines.push(line);
33
+ return ok({ seq: lines.length - 1 });
34
+ },
35
+ async read() {
36
+ return ok([...lines]);
37
+ },
38
+ };
39
+ }
40
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/adapters/memory/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAGhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,SAAS,CAAC;AAWhD,MAAM,UAAU,aAAa,CAAC,OAAO,GAAyB,EAAE;IAC/D,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY,IAAI,sBAAsB,CAAC;IAC7D,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,OAAO;QACN,8EAA8E;QAC9E,gCAAgC;QAChC,aAAa,EAAE,KAAK;QACpB,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC;QAEvB,KAAK,CAAC,MAAM,CAAC,IAAI;YAChB,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;YAC1C,IAAI,KAAK,GAAG,KAAK,EAAE,CAAC;gBACnB,OAAO,IAAI,CACV,aAAa,EACb,eAAe,KAAK,wCAAwC,KAAK,EAAE,CACnE,CAAC;YACH,CAAC;YACD,2EAA2E;YAC3E,oDAAoD;YACpD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjB,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC;QACtC,CAAC;QAED,KAAK,CAAC,IAAI;YACT,OAAO,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;QACvB,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Waking, recorded instead of scheduled.
3
+ *
4
+ * A real host wakes a run by itself, after a wait or an interruption. A test
5
+ * cannot wait, so this adapter keeps what would have been scheduled and lets the
6
+ * test fire it, which is how a resumed run is exercised without time passing.
7
+ */
8
+ import type { WakingSlot } from "../../core/slots.js";
9
+ export interface ScheduledWake {
10
+ runId: string;
11
+ atMs: number;
12
+ }
13
+ export interface MemoryWaking {
14
+ slot: WakingSlot;
15
+ /** What is waiting to fire, in the order it was scheduled. */
16
+ scheduled(): ScheduledWake[];
17
+ /** Take what is waiting, in order, and leave nothing behind. */
18
+ fire(): ScheduledWake[];
19
+ }
20
+ export declare function memoryWaking(): MemoryWaking;
21
+ //# sourceMappingURL=waking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"waking.d.ts","sourceRoot":"","sources":["../../../src/adapters/memory/waking.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,8DAA8D;IAC9D,SAAS,IAAI,aAAa,EAAE,CAAC;IAC7B,gEAAgE;IAChE,IAAI,IAAI,aAAa,EAAE,CAAC;CACxB;AAED,wBAAgB,YAAY,IAAI,YAAY,CAqB3C"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Waking, recorded instead of scheduled.
3
+ *
4
+ * A real host wakes a run by itself, after a wait or an interruption. A test
5
+ * cannot wait, so this adapter keeps what would have been scheduled and lets the
6
+ * test fire it, which is how a resumed run is exercised without time passing.
7
+ */
8
+ export function memoryWaking() {
9
+ const waiting = new Map();
10
+ return {
11
+ slot: {
12
+ async schedule(runId, atMs) {
13
+ // One wake per run: scheduling again moves it, which is what a run that
14
+ // parks twice expects.
15
+ waiting.set(runId, atMs);
16
+ },
17
+ async cancel(runId) {
18
+ waiting.delete(runId);
19
+ },
20
+ },
21
+ scheduled: () => [...waiting].map(([runId, atMs]) => ({ runId, atMs })),
22
+ fire() {
23
+ const due = [...waiting].map(([runId, atMs]) => ({ runId, atMs }));
24
+ waiting.clear();
25
+ return due;
26
+ },
27
+ };
28
+ }
29
+ //# sourceMappingURL=waking.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"waking.js","sourceRoot":"","sources":["../../../src/adapters/memory/waking.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiBH,MAAM,UAAU,YAAY;IAC3B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE1C,OAAO;QACN,IAAI,EAAE;YACL,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI;gBACzB,wEAAwE;gBACxE,uBAAuB;gBACvB,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAC1B,CAAC;YACD,KAAK,CAAC,MAAM,CAAC,KAAK;gBACjB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;SACD;QACD,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACvE,IAAI;YACH,MAAM,GAAG,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACnE,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,OAAO,GAAG,CAAC;QACZ,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Time and identity, injected (docs/implementation/README.md, calls made in advance, 5).
3
+ *
4
+ * The core never reads the real clock and never draws its own randomness, so a
5
+ * test can advance time by hand and the same script produces the same record
6
+ * byte for byte. `core/system-clock.ts` is the one place that wraps the real
7
+ * things, and it is only used by a host that has no better answer.
8
+ */
9
+ export interface Clock {
10
+ /** Milliseconds since the epoch. */
11
+ now(): number;
12
+ /**
13
+ * Wait, without blocking. Rejects if `signal` aborts first, so a stopped run
14
+ * does not finish its wait, and a test can move time instead of waiting.
15
+ */
16
+ sleep(ms: number, signal?: AbortSignal): Promise<void>;
17
+ }
18
+ export interface Ids {
19
+ /** A fresh identifier that begins with `prefix`, such as `c1` or `e_9f2a`. */
20
+ next(prefix: string): string;
21
+ }
22
+ //# sourceMappingURL=clock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../../src/core/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,KAAK;IACrB,oCAAoC;IACpC,GAAG,IAAI,MAAM,CAAC;IACd;;;OAGG;IACH,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,GAAG;IACnB,8EAA8E;IAC9E,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Time and identity, injected (docs/implementation/README.md, calls made in advance, 5).
3
+ *
4
+ * The core never reads the real clock and never draws its own randomness, so a
5
+ * test can advance time by hand and the same script produces the same record
6
+ * byte for byte. `core/system-clock.ts` is the one place that wraps the real
7
+ * things, and it is only used by a host that has no better answer.
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=clock.js.map