@smthrs/journal 0.0.0-stage → 1.0.0-rc.13

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 (257) hide show
  1. package/CHANGELOG.md +149 -0
  2. package/LICENSE +21 -0
  3. package/README.md +208 -2
  4. package/dist/cjs/CallFact.d.ts +129 -0
  5. package/dist/cjs/CallFact.d.ts.map +1 -0
  6. package/dist/cjs/CallFact.js +106 -0
  7. package/dist/cjs/CallFact.js.map +7 -0
  8. package/dist/cjs/Consensus.d.ts +492 -0
  9. package/dist/cjs/Consensus.d.ts.map +1 -0
  10. package/dist/cjs/Consensus.js +314 -0
  11. package/dist/cjs/Consensus.js.map +7 -0
  12. package/dist/cjs/EngineEvent.d.ts +890 -0
  13. package/dist/cjs/EngineEvent.d.ts.map +1 -0
  14. package/dist/cjs/EngineEvent.js +383 -0
  15. package/dist/cjs/EngineEvent.js.map +7 -0
  16. package/dist/cjs/ExecutionFact.d.ts +216 -0
  17. package/dist/cjs/ExecutionFact.d.ts.map +1 -0
  18. package/dist/cjs/ExecutionFact.js +303 -0
  19. package/dist/cjs/ExecutionFact.js.map +7 -0
  20. package/dist/cjs/Journal.d.ts +617 -0
  21. package/dist/cjs/Journal.d.ts.map +1 -0
  22. package/dist/cjs/Journal.js +190 -0
  23. package/dist/cjs/Journal.js.map +7 -0
  24. package/dist/cjs/JournalEvent.d.ts +421 -0
  25. package/dist/cjs/JournalEvent.d.ts.map +1 -0
  26. package/dist/cjs/JournalEvent.js +281 -0
  27. package/dist/cjs/JournalEvent.js.map +7 -0
  28. package/dist/cjs/JournalGeneration.d.ts +34 -0
  29. package/dist/cjs/JournalGeneration.d.ts.map +1 -0
  30. package/dist/cjs/JournalGeneration.js +73 -0
  31. package/dist/cjs/JournalGeneration.js.map +7 -0
  32. package/dist/cjs/JournalMetrics.d.ts +72 -0
  33. package/dist/cjs/JournalMetrics.d.ts.map +1 -0
  34. package/dist/cjs/JournalMetrics.js +55 -0
  35. package/dist/cjs/JournalMetrics.js.map +7 -0
  36. package/dist/cjs/Migrations.d.ts +42 -0
  37. package/dist/cjs/Migrations.d.ts.map +1 -0
  38. package/dist/cjs/Migrations.js +58 -0
  39. package/dist/cjs/Migrations.js.map +7 -0
  40. package/dist/cjs/OwnerId.d.ts +40 -0
  41. package/dist/cjs/OwnerId.d.ts.map +1 -0
  42. package/dist/cjs/OwnerId.js +40 -0
  43. package/dist/cjs/OwnerId.js.map +7 -0
  44. package/dist/cjs/Projection.d.ts +29 -0
  45. package/dist/cjs/Projection.d.ts.map +1 -0
  46. package/dist/cjs/Projection.js +25 -0
  47. package/dist/cjs/Projection.js.map +7 -0
  48. package/dist/cjs/RedactedLogger.d.ts +121 -0
  49. package/dist/cjs/RedactedLogger.d.ts.map +1 -0
  50. package/dist/cjs/RedactedLogger.js +235 -0
  51. package/dist/cjs/RedactedLogger.js.map +7 -0
  52. package/dist/cjs/Redaction.d.ts +350 -0
  53. package/dist/cjs/Redaction.d.ts.map +1 -0
  54. package/dist/cjs/Redaction.js +962 -0
  55. package/dist/cjs/Redaction.js.map +7 -0
  56. package/dist/cjs/SqlConsensus.d.ts +44 -0
  57. package/dist/cjs/SqlConsensus.d.ts.map +1 -0
  58. package/dist/cjs/SqlConsensus.js +273 -0
  59. package/dist/cjs/SqlConsensus.js.map +7 -0
  60. package/dist/cjs/SqlJournal.d.ts +173 -0
  61. package/dist/cjs/SqlJournal.d.ts.map +1 -0
  62. package/dist/cjs/SqlJournal.js +1568 -0
  63. package/dist/cjs/SqlJournal.js.map +7 -0
  64. package/dist/cjs/StepFact.d.ts +66 -0
  65. package/dist/cjs/StepFact.d.ts.map +1 -0
  66. package/dist/cjs/StepFact.js +68 -0
  67. package/dist/cjs/StepFact.js.map +7 -0
  68. package/dist/cjs/index.d.ts +95 -0
  69. package/dist/cjs/index.d.ts.map +1 -0
  70. package/dist/cjs/index.js +63 -0
  71. package/dist/cjs/index.js.map +7 -0
  72. package/dist/cjs/internal/JournalInternalFault.d.ts +37 -0
  73. package/dist/cjs/internal/JournalInternalFault.d.ts.map +1 -0
  74. package/dist/cjs/internal/JournalInternalFault.js +43 -0
  75. package/dist/cjs/internal/JournalInternalFault.js.map +7 -0
  76. package/dist/cjs/migrations/0001_initial.d.ts +15 -0
  77. package/dist/cjs/migrations/0001_initial.d.ts.map +1 -0
  78. package/dist/cjs/migrations/0001_initial.js +54 -0
  79. package/dist/cjs/migrations/0001_initial.js.map +7 -0
  80. package/dist/cjs/migrations/0002_checkpoints.d.ts +27 -0
  81. package/dist/cjs/migrations/0002_checkpoints.d.ts.map +1 -0
  82. package/dist/cjs/migrations/0002_checkpoints.js +48 -0
  83. package/dist/cjs/migrations/0002_checkpoints.js.map +7 -0
  84. package/dist/cjs/migrations/0003_startup_index.d.ts +15 -0
  85. package/dist/cjs/migrations/0003_startup_index.d.ts.map +1 -0
  86. package/dist/cjs/migrations/0003_startup_index.js +40 -0
  87. package/dist/cjs/migrations/0003_startup_index.js.map +7 -0
  88. package/dist/cjs/migrations/0004_dedup.d.ts +15 -0
  89. package/dist/cjs/migrations/0004_dedup.d.ts.map +1 -0
  90. package/dist/cjs/migrations/0004_dedup.js +57 -0
  91. package/dist/cjs/migrations/0004_dedup.js.map +7 -0
  92. package/dist/cjs/migrations/0005_run_event_type.d.ts +15 -0
  93. package/dist/cjs/migrations/0005_run_event_type.d.ts.map +1 -0
  94. package/dist/cjs/migrations/0005_run_event_type.js +40 -0
  95. package/dist/cjs/migrations/0005_run_event_type.js.map +7 -0
  96. package/dist/cjs/migrations/0006_consensus.d.ts +22 -0
  97. package/dist/cjs/migrations/0006_consensus.d.ts.map +1 -0
  98. package/dist/cjs/migrations/0006_consensus.js +84 -0
  99. package/dist/cjs/migrations/0006_consensus.js.map +7 -0
  100. package/dist/cjs/package.json +1 -0
  101. package/dist/cjs/test/Notifying.d.ts +65 -0
  102. package/dist/cjs/test/Notifying.d.ts.map +1 -0
  103. package/dist/cjs/test/Notifying.js +62 -0
  104. package/dist/cjs/test/Notifying.js.map +7 -0
  105. package/dist/cjs/test/TestJournal.d.ts +43 -0
  106. package/dist/cjs/test/TestJournal.d.ts.map +1 -0
  107. package/dist/cjs/test/TestJournal.js +43 -0
  108. package/dist/cjs/test/TestJournal.js.map +7 -0
  109. package/dist/esm/CallFact.d.ts +129 -0
  110. package/dist/esm/CallFact.d.ts.map +1 -0
  111. package/dist/esm/CallFact.js +96 -0
  112. package/dist/esm/CallFact.js.map +1 -0
  113. package/dist/esm/Consensus.d.ts +492 -0
  114. package/dist/esm/Consensus.d.ts.map +1 -0
  115. package/dist/esm/Consensus.js +548 -0
  116. package/dist/esm/Consensus.js.map +1 -0
  117. package/dist/esm/EngineEvent.d.ts +890 -0
  118. package/dist/esm/EngineEvent.d.ts.map +1 -0
  119. package/dist/esm/EngineEvent.js +614 -0
  120. package/dist/esm/EngineEvent.js.map +1 -0
  121. package/dist/esm/ExecutionFact.d.ts +216 -0
  122. package/dist/esm/ExecutionFact.d.ts.map +1 -0
  123. package/dist/esm/ExecutionFact.js +374 -0
  124. package/dist/esm/ExecutionFact.js.map +1 -0
  125. package/dist/esm/Journal.d.ts +617 -0
  126. package/dist/esm/Journal.d.ts.map +1 -0
  127. package/dist/esm/Journal.js +323 -0
  128. package/dist/esm/Journal.js.map +1 -0
  129. package/dist/esm/JournalEvent.d.ts +421 -0
  130. package/dist/esm/JournalEvent.d.ts.map +1 -0
  131. package/dist/esm/JournalEvent.js +517 -0
  132. package/dist/esm/JournalEvent.js.map +1 -0
  133. package/dist/esm/JournalGeneration.d.ts +34 -0
  134. package/dist/esm/JournalGeneration.d.ts.map +1 -0
  135. package/dist/esm/JournalGeneration.js +71 -0
  136. package/dist/esm/JournalGeneration.js.map +1 -0
  137. package/dist/esm/JournalMetrics.d.ts +72 -0
  138. package/dist/esm/JournalMetrics.d.ts.map +1 -0
  139. package/dist/esm/JournalMetrics.js +79 -0
  140. package/dist/esm/JournalMetrics.js.map +1 -0
  141. package/dist/esm/Migrations.d.ts +42 -0
  142. package/dist/esm/Migrations.d.ts.map +1 -0
  143. package/dist/esm/Migrations.js +59 -0
  144. package/dist/esm/Migrations.js.map +1 -0
  145. package/dist/esm/OwnerId.d.ts +40 -0
  146. package/dist/esm/OwnerId.d.ts.map +1 -0
  147. package/dist/esm/OwnerId.js +33 -0
  148. package/dist/esm/OwnerId.js.map +1 -0
  149. package/dist/esm/Projection.d.ts +29 -0
  150. package/dist/esm/Projection.d.ts.map +1 -0
  151. package/dist/esm/Projection.js +13 -0
  152. package/dist/esm/Projection.js.map +1 -0
  153. package/dist/esm/RedactedLogger.d.ts +121 -0
  154. package/dist/esm/RedactedLogger.d.ts.map +1 -0
  155. package/dist/esm/RedactedLogger.js +445 -0
  156. package/dist/esm/RedactedLogger.js.map +1 -0
  157. package/dist/esm/Redaction.d.ts +350 -0
  158. package/dist/esm/Redaction.d.ts.map +1 -0
  159. package/dist/esm/Redaction.js +1628 -0
  160. package/dist/esm/Redaction.js.map +1 -0
  161. package/dist/esm/SqlConsensus.d.ts +44 -0
  162. package/dist/esm/SqlConsensus.d.ts.map +1 -0
  163. package/dist/esm/SqlConsensus.js +273 -0
  164. package/dist/esm/SqlConsensus.js.map +1 -0
  165. package/dist/esm/SqlJournal.d.ts +173 -0
  166. package/dist/esm/SqlJournal.d.ts.map +1 -0
  167. package/dist/esm/SqlJournal.js +1858 -0
  168. package/dist/esm/SqlJournal.js.map +1 -0
  169. package/dist/esm/StepFact.d.ts +66 -0
  170. package/dist/esm/StepFact.d.ts.map +1 -0
  171. package/dist/esm/StepFact.js +50 -0
  172. package/dist/esm/StepFact.js.map +1 -0
  173. package/dist/esm/index.d.ts +95 -0
  174. package/dist/esm/index.d.ts.map +1 -0
  175. package/dist/esm/index.js +95 -0
  176. package/dist/esm/index.js.map +1 -0
  177. package/dist/esm/internal/JournalInternalFault.d.ts +37 -0
  178. package/dist/esm/internal/JournalInternalFault.d.ts.map +1 -0
  179. package/dist/esm/internal/JournalInternalFault.js +28 -0
  180. package/dist/esm/internal/JournalInternalFault.js.map +1 -0
  181. package/dist/esm/migrations/0001_initial.d.ts +15 -0
  182. package/dist/esm/migrations/0001_initial.d.ts.map +1 -0
  183. package/dist/esm/migrations/0001_initial.js +32 -0
  184. package/dist/esm/migrations/0001_initial.js.map +1 -0
  185. package/dist/esm/migrations/0002_checkpoints.d.ts +27 -0
  186. package/dist/esm/migrations/0002_checkpoints.d.ts.map +1 -0
  187. package/dist/esm/migrations/0002_checkpoints.js +38 -0
  188. package/dist/esm/migrations/0002_checkpoints.js.map +1 -0
  189. package/dist/esm/migrations/0003_startup_index.d.ts +15 -0
  190. package/dist/esm/migrations/0003_startup_index.d.ts.map +1 -0
  191. package/dist/esm/migrations/0003_startup_index.js +18 -0
  192. package/dist/esm/migrations/0003_startup_index.js.map +1 -0
  193. package/dist/esm/migrations/0004_dedup.d.ts +15 -0
  194. package/dist/esm/migrations/0004_dedup.d.ts.map +1 -0
  195. package/dist/esm/migrations/0004_dedup.js +38 -0
  196. package/dist/esm/migrations/0004_dedup.js.map +1 -0
  197. package/dist/esm/migrations/0005_run_event_type.d.ts +15 -0
  198. package/dist/esm/migrations/0005_run_event_type.d.ts.map +1 -0
  199. package/dist/esm/migrations/0005_run_event_type.js +18 -0
  200. package/dist/esm/migrations/0005_run_event_type.js.map +1 -0
  201. package/dist/esm/migrations/0006_consensus.d.ts +22 -0
  202. package/dist/esm/migrations/0006_consensus.d.ts.map +1 -0
  203. package/dist/esm/migrations/0006_consensus.js +69 -0
  204. package/dist/esm/migrations/0006_consensus.js.map +1 -0
  205. package/dist/esm/test/Notifying.d.ts +65 -0
  206. package/dist/esm/test/Notifying.d.ts.map +1 -0
  207. package/dist/esm/test/Notifying.js +62 -0
  208. package/dist/esm/test/Notifying.js.map +1 -0
  209. package/dist/esm/test/TestJournal.d.ts +43 -0
  210. package/dist/esm/test/TestJournal.d.ts.map +1 -0
  211. package/dist/esm/test/TestJournal.js +27 -0
  212. package/dist/esm/test/TestJournal.js.map +1 -0
  213. package/docs/README.md +166 -0
  214. package/docs/api.md +650 -0
  215. package/docs/concepts/compaction.md +157 -0
  216. package/docs/concepts/idempotency.md +127 -0
  217. package/docs/concepts/owner-fence.md +128 -0
  218. package/docs/concepts/redaction.md +222 -0
  219. package/docs/concepts/state-event-authority.md +159 -0
  220. package/docs/concepts/two-channels.md +167 -0
  221. package/docs/guides/commit-state-and-entry.md +114 -0
  222. package/docs/guides/compact-a-run.md +134 -0
  223. package/docs/guides/fold-a-projection.md +106 -0
  224. package/docs/guides/read-a-run.md +139 -0
  225. package/docs/guides/redact-log-output.md +94 -0
  226. package/docs/guides/testing.md +124 -0
  227. package/docs/guides/write-lifecycle-events.md +110 -0
  228. package/docs/installation.md +137 -0
  229. package/docs/quickstart.md +146 -0
  230. package/docs/troubleshooting.md +214 -0
  231. package/package.json +263 -3
  232. package/src/CallFact.ts +117 -0
  233. package/src/Consensus.ts +814 -0
  234. package/src/EngineEvent.ts +823 -0
  235. package/src/ExecutionFact.ts +433 -0
  236. package/src/Journal.ts +688 -0
  237. package/src/JournalEvent.ts +654 -0
  238. package/src/JournalGeneration.ts +83 -0
  239. package/src/JournalMetrics.ts +89 -0
  240. package/src/Migrations.ts +62 -0
  241. package/src/OwnerId.ts +42 -0
  242. package/src/Projection.ts +31 -0
  243. package/src/RedactedLogger.ts +483 -0
  244. package/src/Redaction.ts +1828 -0
  245. package/src/SqlConsensus.ts +384 -0
  246. package/src/SqlJournal.ts +2732 -0
  247. package/src/StepFact.ts +69 -0
  248. package/src/index.ts +109 -0
  249. package/src/internal/JournalInternalFault.ts +40 -0
  250. package/src/migrations/0001_initial.ts +41 -0
  251. package/src/migrations/0002_checkpoints.ts +46 -0
  252. package/src/migrations/0003_startup_index.ts +19 -0
  253. package/src/migrations/0004_dedup.ts +43 -0
  254. package/src/migrations/0005_run_event_type.ts +19 -0
  255. package/src/migrations/0006_consensus.ts +83 -0
  256. package/src/test/Notifying.ts +101 -0
  257. package/src/test/TestJournal.ts +52 -0
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Versioned facts for an authorized native cell invocation and its delivered result.
3
+ * @since 1.0.0
4
+ */
5
+ import * as Context from "effect/Context";
6
+ import * as Schema from "effect/Schema";
7
+ /** Stable harness coordinates, independent of physical attempt or publication order.
8
+ * @category schemas
9
+ * @since 1.0.0
10
+ */
11
+ export const Identity = Schema.Struct({
12
+ /** Public logical run identity, not an authentication session credential. */
13
+ runId: Schema.String,
14
+ frame: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
15
+ cell: Schema.String,
16
+ ordinal: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
17
+ declaration: Schema.String,
18
+ layers: Schema.Array(Schema.String)
19
+ });
20
+ /** A call annotation contains data only and never changes an action key.
21
+ * @category schemas
22
+ * @since 1.0.0
23
+ */
24
+ export const Call = Schema.Struct({
25
+ callId: Schema.String.check(Schema.isPattern(/^cell-call-v1:[0-9a-f]{64}$/)),
26
+ identity: Identity,
27
+ flowName: Schema.String,
28
+ input: Schema.Json,
29
+ /**
30
+ * The resolved declaration's display projection, as its owner encoded it.
31
+ *
32
+ * JSON rather than a struct because the vocabulary belongs to
33
+ * `@smthrs/registry` (`Descriptor.FlowActivity`, `Descriptor.CallPresentation`),
34
+ * which sits above this package: `@smthrs/harness` `Cell.displayDescriptor`
35
+ * encodes it from a typed call and the reading card validates each field
36
+ * before it is displayed, so the journal carries it and claims nothing about
37
+ * it. Absent means the declaration claimed nothing.
38
+ */
39
+ descriptor: Schema.optional(Schema.Json)
40
+ });
41
+ /** Native action annotation; only the existing controller record settles a call.
42
+ * @category services
43
+ * @since 1.0.0
44
+ */
45
+ export class Annotation extends Context.Service()("@smthrs/journal/CallFact/Annotation") {
46
+ }
47
+ /** Public result vocabulary. Executable outcomes remain in the protected attempt row.
48
+ * @category schemas
49
+ * @since 1.0.0
50
+ */
51
+ export const Result = Schema.Union([
52
+ Schema.Struct({
53
+ outcome: Schema.Literal("success"),
54
+ value: Schema.Json,
55
+ message: Schema.optional(Schema.String),
56
+ code: Schema.optionalKey(Schema.Never)
57
+ }),
58
+ Schema.Struct({
59
+ outcome: Schema.Literal("failure"),
60
+ value: Schema.Json,
61
+ message: Schema.optional(Schema.String),
62
+ code: Schema.optional(Schema.String)
63
+ })
64
+ ]);
65
+ const coordinates = {
66
+ version: Schema.Literal(1),
67
+ callId: Call.fields.callId,
68
+ identity: Identity,
69
+ flowName: Schema.String
70
+ };
71
+ /** Bounded, redacted event projection; a truncation marker is still JSON.
72
+ * @category schemas
73
+ * @since 1.0.0
74
+ */
75
+ export const Fact = Schema.Union([
76
+ Schema.Struct({
77
+ ...coordinates,
78
+ phase: Schema.Literal("invoked"),
79
+ input: Schema.Json,
80
+ descriptor: Schema.optional(Schema.Json)
81
+ }),
82
+ Schema.Struct({
83
+ ...coordinates,
84
+ phase: Schema.Literal("settled"),
85
+ outcome: Schema.Literals(["success", "failure"]),
86
+ value: Schema.Json,
87
+ message: Schema.optional(Schema.Json),
88
+ code: Schema.optional(Schema.String)
89
+ })
90
+ ]);
91
+ /** The immutable native journal is the durable outbox consumed by the native bridge.
92
+ * @category events
93
+ * @since 1.0.0
94
+ */
95
+ export const eventType = "flows.harness.call-fact.v1";
96
+ //# sourceMappingURL=CallFact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CallFact.js","sourceRoot":"","sources":["../../src/CallFact.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,6EAA6E;IAC7E,KAAK,EAAE,MAAM,CAAC,MAAM;IACpB,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;IACzD,IAAI,EAAE,MAAM,CAAC,MAAM;IACnB,O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,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;KACrC,CAAC;CACH,CAAC,CAAA;AAEF,MAAM,WAAW,GAAG;IAClB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;IAC1B,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,MAAM,CAAC,MAAM;CACxB,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC;IAC/B,MAAM,CAAC,MAAM,CAAC;QACZ,GAAG,WAAW;QACd,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;QAChC,KAAK,EAAE,MAAM,CAAC,IAAI;QAClB,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;KACzC,CAAC;IACF,MAAM,CAAC,MAAM,CAAC;QACZ,GAAG,WAAW;QACd,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;QAChC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAChD,KAAK,EAAE,MAAM,CAAC,IAAI;QAClB,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;QACrC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;KACrC,CAAC;CACH,CAAC,CAAA;AAQF;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,4BAA4B,CAAA","sourcesContent":["/**\n * Versioned facts for an authorized native cell invocation and its delivered result.\n * @since 1.0.0\n */\n\nimport * as Context from \"effect/Context\"\nimport * as Schema from \"effect/Schema\"\n\n/** Stable harness coordinates, independent of physical attempt or publication order.\n * @category schemas\n * @since 1.0.0\n */\nexport const Identity = Schema.Struct({\n /** Public logical run identity, not an authentication session credential. */\n runId: Schema.String,\n frame: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n cell: Schema.String,\n ordinal: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n declaration: Schema.String,\n layers: Schema.Array(Schema.String)\n})\n\n/** A call annotation contains data only and never changes an action key.\n * @category schemas\n * @since 1.0.0\n */\nexport const Call = Schema.Struct({\n callId: Schema.String.check(Schema.isPattern(/^cell-call-v1:[0-9a-f]{64}$/)),\n identity: Identity,\n flowName: Schema.String,\n input: Schema.Json,\n /**\n * The resolved declaration's display projection, as its owner encoded it.\n *\n * JSON rather than a struct because the vocabulary belongs to\n * `@smthrs/registry` (`Descriptor.FlowActivity`, `Descriptor.CallPresentation`),\n * which sits above this package: `@smthrs/harness` `Cell.displayDescriptor`\n * encodes it from a typed call and the reading card validates each field\n * before it is displayed, so the journal carries it and claims nothing about\n * it. Absent means the declaration claimed nothing.\n */\n descriptor: Schema.optional(Schema.Json)\n})\n\n/** Decoded authorized call coordinates.\n * @category models\n * @since 1.0.0\n */\nexport type Call = typeof Call.Type\n\n/** Native action annotation; only the existing controller record settles a call.\n * @category services\n * @since 1.0.0\n */\nexport class Annotation extends Context.Service<Annotation, {\n readonly phase: \"invoked\" | \"settled\"\n readonly call: Call\n}>()(\"@smthrs/journal/CallFact/Annotation\") {}\n\n/** Public result vocabulary. Executable outcomes remain in the protected attempt row.\n * @category schemas\n * @since 1.0.0\n */\nexport const Result = Schema.Union([\n Schema.Struct({\n outcome: Schema.Literal(\"success\"),\n value: Schema.Json,\n message: Schema.optional(Schema.String),\n code: Schema.optionalKey(Schema.Never)\n }),\n Schema.Struct({\n outcome: Schema.Literal(\"failure\"),\n value: Schema.Json,\n message: Schema.optional(Schema.String),\n code: Schema.optional(Schema.String)\n })\n])\n\nconst coordinates = {\n version: Schema.Literal(1),\n callId: Call.fields.callId,\n identity: Identity,\n flowName: Schema.String\n}\n\n/** Bounded, redacted event projection; a truncation marker is still JSON.\n * @category schemas\n * @since 1.0.0\n */\nexport const Fact = Schema.Union([\n Schema.Struct({\n ...coordinates,\n phase: Schema.Literal(\"invoked\"),\n input: Schema.Json,\n descriptor: Schema.optional(Schema.Json)\n }),\n Schema.Struct({\n ...coordinates,\n phase: Schema.Literal(\"settled\"),\n outcome: Schema.Literals([\"success\", \"failure\"]),\n value: Schema.Json,\n message: Schema.optional(Schema.Json),\n code: Schema.optional(Schema.String)\n })\n])\n\n/** Decoded public native call fact.\n * @category models\n * @since 1.0.0\n */\nexport type Fact = typeof Fact.Type\n\n/** The immutable native journal is the durable outbox consumed by the native bridge.\n * @category events\n * @since 1.0.0\n */\nexport const eventType = \"flows.harness.call-fact.v1\"\n"]}
@@ -0,0 +1,492 @@
1
+ /**
2
+ * The injectable consensus strategy arbitrating the journal's ownership rules.
3
+ *
4
+ * The journal owns the consensus rules — single writer per run, fenced and
5
+ * unfenced appends, commit-time admission, the generation fence, and steal
6
+ * only on staleness plus liveness evidence, or on a same-host probe that
7
+ * proves the owner's process gone — and this service is how a deployment chooses *how* those rules are
8
+ * arbitrated: where the lease lives, how liveness is probed, and how the
9
+ * fence is checked at commit time. `Consensus` lives here beside `OwnerId`
10
+ * for the same reason `OwnerId` does: the journal is what it fences.
11
+ * `@smthrs/run-store`'s `Ownership` keeps its public API and rules but
12
+ * delegates arbitration to this strategy.
13
+ *
14
+ * Every operation that reasons about staleness takes the caller's clock
15
+ * reading (`nowMs`) rather than reading a clock itself: staleness (R5) and
16
+ * the monotonic lease stamp are defined against the arbitrating caller's
17
+ * reading, exactly as `RunStore`'s compare-and-swap operations always were,
18
+ * so the recorded lease never differs from the outcome the caller observed.
19
+ *
20
+ * Governing design: `packages/smithers/flows/journal/docs/concepts/owner-fence.md`.
21
+ * Rule constants and their provenance:
22
+ * `packages/smithers/flows/run-store/docs/concepts/leases.md`.
23
+ *
24
+ * Prior art: Effect `EventJournal` (`reference/effect` `unstable/eventlog`)
25
+ * resolves multi-writer by merge with conflict surfacing; driving a run is not
26
+ * mergeable, so this surface deviates to exclusive-writer admission. The
27
+ * fencing and generation semantics follow Temporal's shard `rangeID`
28
+ * (`reference/temporal/service/history/shard/context_impl.go`).
29
+ *
30
+ * @since 1.0.0
31
+ */
32
+ import * as Context from "effect/Context";
33
+ import * as Duration from "effect/Duration";
34
+ import * as Effect from "effect/Effect";
35
+ import * as Layer from "effect/Layer";
36
+ import * as Schema from "effect/Schema";
37
+ import { OwnerId } from "./OwnerId.ts";
38
+ /**
39
+ * How often the supervision loop pulses to renew the owner's lease.
40
+ *
41
+ * @since 1.0.0
42
+ * @category constants
43
+ */
44
+ export declare const heartbeatInterval: Duration.Duration;
45
+ /**
46
+ * How old a persisted heartbeat must be before a peer may steal the run.
47
+ * Every strategy judges R5 staleness against this one definition.
48
+ *
49
+ * @since 1.0.0
50
+ * @category constants
51
+ */
52
+ export declare const heartbeatStaleAfter: Duration.Duration;
53
+ /**
54
+ * How far the owner's wall clock may run behind a peer's before the lease
55
+ * reasoning stops holding.
56
+ *
57
+ * The owner stamps its heartbeat from *its* clock and a would-be stealer
58
+ * compares that stamp against *its own*, so the two hosts' clock offset is
59
+ * subtracted directly from the owner's real safety margin. This constant names
60
+ * that allowance instead of leaving it implicit in a "two ticks" arithmetic
61
+ * accident, and it is a budgeted allowance, not a guarantee: see
62
+ * {@link heartbeatWriteTolerance} for what happens once it is exceeded.
63
+ *
64
+ * @since 1.0.0
65
+ * @category constants
66
+ */
67
+ export declare const heartbeatSkewAllowance: Duration.Duration;
68
+ /**
69
+ * How long heartbeat writes may go unconfirmed before ownership must be reconfirmed.
70
+ *
71
+ * A peer judges staleness by the persisted heartbeat and may steal the run the
72
+ * instant it is {@link heartbeatStaleAfter} old, so an owner that tolerated
73
+ * write failures for exactly that long would still be executing side effects
74
+ * when the steal is admitted. The budget is therefore
75
+ * {@link heartbeatStaleAfter} minus {@link heartbeatSkewAllowance} (the peer's
76
+ * clock may already read that much later than the owner's) minus one
77
+ * {@link heartbeatInterval} (reserved for one bounded compare-and-swap
78
+ * reconfirmation before the owner interrupts).
79
+ *
80
+ * This bounds, but does not eliminate, overlap. Beyond
81
+ * {@link heartbeatSkewAllowance} of clock offset a peer can be admitted while
82
+ * the old owner is still running. *Durable* writes stay safe regardless — they
83
+ * are fenced by the strategy's commit-time admission, so the displaced owner's
84
+ * writes fail rather than corrupt. Non-durable external side effects (an HTTP
85
+ * call, a spawned process) can genuinely overlap. That is inherent to any
86
+ * wall-clock lease and is stated here rather than asserted away; a caller that
87
+ * cannot tolerate any overlap needs an external fencing token at the side
88
+ * effect itself, not a larger timeout.
89
+ *
90
+ * @since 1.0.0
91
+ * @category constants
92
+ */
93
+ export declare const heartbeatWriteTolerance: Duration.Duration;
94
+ /**
95
+ * Evidence that the owner in an exact run snapshot is no longer live.
96
+ *
97
+ * Defined here because R5 — steal requires staleness plus liveness evidence —
98
+ * is a consensus rule every strategy validates. `@smthrs/run-store`'s
99
+ * `Ownership` re-exports it alongside the probes that mint it.
100
+ *
101
+ * Two of the three kinds are collected outside the strategy:
102
+ * `same-host-pid-dead` is a local process probe, and
103
+ * `cross-host-unreachable-stale` is a reachability judgement the deployment
104
+ * makes. `lease-expired` is different — it asserts only that the persisted
105
+ * heartbeat is older than the staleness cutoff, which is the one claim a
106
+ * strategy can check for itself, and `steal` checks it: the takeover refuses
107
+ * any lease whose heartbeat is still inside the window. It is therefore
108
+ * accepted from a claimant on any host, while the other two stay bound to the
109
+ * host relation that makes them meaningful. `same-host-pid-dead` alone also
110
+ * admits a steal inside the window; see {@link provesDeath}. The observation must carry the
111
+ * exact instant supplied to the consuming operation: `checkedAtMs` must equal
112
+ * that operation's `nowMs`. A caller that probes at T and calls at T+1 is
113
+ * refused and must build fresh evidence.
114
+ *
115
+ * @since 1.0.0
116
+ * @category models
117
+ */
118
+ export declare const LivenessEvidence: Schema.Struct<{
119
+ readonly expectedOwner: Schema.Struct<{
120
+ readonly hostId: Schema.String;
121
+ readonly pid: Schema.Int;
122
+ readonly nonce: Schema.String;
123
+ }>;
124
+ readonly checkedAtMs: Schema.Number;
125
+ readonly kind: Schema.Literals<readonly ["same-host-pid-dead", "cross-host-unreachable-stale", "lease-expired"]>;
126
+ }>;
127
+ /**
128
+ * Evidence that the owner in an exact run snapshot is no longer live.
129
+ *
130
+ * @since 1.0.0
131
+ * @category models
132
+ */
133
+ export type LivenessEvidence = typeof LivenessEvidence.Type;
134
+ /**
135
+ * Structural equality on the process identity tuple.
136
+ *
137
+ * @since 1.0.0
138
+ * @category predicates
139
+ */
140
+ export declare const sameOwner: (left: OwnerId, right: OwnerId) => boolean;
141
+ /**
142
+ * Validates liveness evidence against the owner it claims to disprove.
143
+ *
144
+ * The evidence must name the expected owner, carry the observer's current
145
+ * clock reading, and respect the host rule: a `same-host-pid-dead` probe is
146
+ * only meaningful from the same host, a `cross-host-unreachable-stale`
147
+ * observation only from a different one, and `lease-expired` is host-neutral
148
+ * because the strategy verifies the cutoff it names for itself.
149
+ *
150
+ * @since 1.0.0
151
+ * @category predicates
152
+ */
153
+ export declare const matchesEvidence: (expectedOwner: OwnerId, observer: OwnerId, nowMs: number, evidence: LivenessEvidence) => boolean;
154
+ /**
155
+ * Whether evidence proves the owner gone, so a steal need not wait for its
156
+ * lease to go stale.
157
+ *
158
+ * The lease stands in for a question a peer cannot ask directly: is the owner
159
+ * still running? A `same-host-pid-dead` probe asks it. The claimant read its
160
+ * own host's process table and found no process behind the owner's pid, and a
161
+ * process that does not exist renews no lease and writes nothing, so waiting
162
+ * out `heartbeatStaleAfter` adds no safety. A run whose owner was killed with
163
+ * `SIGKILL` is therefore reclaimed by the next process on the same host at
164
+ * once.
165
+ *
166
+ * The evidence must still pass {@link matchesEvidence}, which binds the kind
167
+ * to the same host. One more case is excluded here: an owner recorded with the
168
+ * claimant's own pid names the claimant's process, which is running, so a
169
+ * probe of that pid cannot report it gone. Such evidence keeps the staleness
170
+ * cutoff.
171
+ *
172
+ * The other kinds never waive the cutoff. `cross-host-unreachable-stale` is a
173
+ * judgement about a host this process cannot inspect, and `lease-expired` is
174
+ * the cutoff itself.
175
+ *
176
+ * @since 1.0.0
177
+ * @category predicates
178
+ */
179
+ export declare const provesDeath: (evidence: LivenessEvidence, claimant: OwnerId) => boolean;
180
+ /**
181
+ * Why a strategy refused a claim, steal, or recovery.
182
+ *
183
+ * @since 1.0.0
184
+ * @category models
185
+ */
186
+ export declare const RejectionReason: Schema.Literals<readonly ["already_claimed", "owner_held", "owner_live", "evidence_invalid", "claim_fresh", "claim_changed", "unavailable"]>;
187
+ /**
188
+ * Why a strategy refused a claim, steal, or recovery.
189
+ *
190
+ * @since 1.0.0
191
+ * @category models
192
+ */
193
+ export type RejectionReason = typeof RejectionReason.Type;
194
+ /**
195
+ * A granted claim, carrying the grant timestamp the later activation must
196
+ * present (R4 — the generation fence).
197
+ *
198
+ * @since 1.0.0
199
+ * @category models
200
+ */
201
+ export declare const Claimed: Schema.TaggedStruct<"Claimed", {
202
+ readonly grantedAtMs: Schema.Number;
203
+ }>;
204
+ /**
205
+ * A granted claim.
206
+ *
207
+ * @since 1.0.0
208
+ * @category models
209
+ */
210
+ export type Claimed = typeof Claimed.Type;
211
+ /**
212
+ * A refused claim, steal, or recovery, with the strategy's typed reason.
213
+ *
214
+ * @since 1.0.0
215
+ * @category models
216
+ */
217
+ export declare const Rejected: Schema.TaggedStruct<"Rejected", {
218
+ readonly reason: Schema.Literals<readonly ["already_claimed", "owner_held", "owner_live", "evidence_invalid", "claim_fresh", "claim_changed", "unavailable"]>;
219
+ }>;
220
+ /**
221
+ * A refused claim, steal, or recovery.
222
+ *
223
+ * @since 1.0.0
224
+ * @category models
225
+ */
226
+ export type Rejected = typeof Rejected.Type;
227
+ /**
228
+ * Outcome of `claim` and `steal`.
229
+ *
230
+ * @since 1.0.0
231
+ * @category models
232
+ */
233
+ export declare const ClaimOutcome: Schema.Union<readonly [Schema.TaggedStruct<"Claimed", {
234
+ readonly grantedAtMs: Schema.Number;
235
+ }>, Schema.TaggedStruct<"Rejected", {
236
+ readonly reason: Schema.Literals<readonly ["already_claimed", "owner_held", "owner_live", "evidence_invalid", "claim_fresh", "claim_changed", "unavailable"]>;
237
+ }>]>;
238
+ /**
239
+ * Outcome of `claim` and `steal`.
240
+ *
241
+ * @since 1.0.0
242
+ * @category models
243
+ */
244
+ export type ClaimOutcome = typeof ClaimOutcome.Type;
245
+ /**
246
+ * A claim promoted to ownership.
247
+ *
248
+ * @since 1.0.0
249
+ * @category models
250
+ */
251
+ export declare const Activated: Schema.TaggedStruct<"Activated", {}>;
252
+ /**
253
+ * A claim promoted to ownership.
254
+ *
255
+ * @since 1.0.0
256
+ * @category models
257
+ */
258
+ export type Activated = typeof Activated.Type;
259
+ /**
260
+ * The claim or lease the caller presented no longer exists.
261
+ *
262
+ * @since 1.0.0
263
+ * @category models
264
+ */
265
+ export declare const Lost: Schema.TaggedStruct<"Lost", {}>;
266
+ /**
267
+ * The claim or lease the caller presented no longer exists.
268
+ *
269
+ * @since 1.0.0
270
+ * @category models
271
+ */
272
+ export type Lost = typeof Lost.Type;
273
+ /**
274
+ * Outcome of `activate`.
275
+ *
276
+ * @since 1.0.0
277
+ * @category models
278
+ */
279
+ export declare const ActivateOutcome: Schema.Union<readonly [Schema.TaggedStruct<"Activated", {}>, Schema.TaggedStruct<"Lost", {}>]>;
280
+ /**
281
+ * Outcome of `activate`.
282
+ *
283
+ * @since 1.0.0
284
+ * @category models
285
+ */
286
+ export type ActivateOutcome = typeof ActivateOutcome.Type;
287
+ /**
288
+ * A renewed lease, carrying the monotonic heartbeat stamp the strategy
289
+ * recorded — the maximum of the stored stamp and the caller's reading, so a
290
+ * late pulse never moves the lease backwards.
291
+ *
292
+ * @since 1.0.0
293
+ * @category models
294
+ */
295
+ export declare const Renewed: Schema.TaggedStruct<"Renewed", {
296
+ readonly heartbeatAtMs: Schema.Number;
297
+ }>;
298
+ /**
299
+ * A renewed lease.
300
+ *
301
+ * @since 1.0.0
302
+ * @category models
303
+ */
304
+ export type Renewed = typeof Renewed.Type;
305
+ /**
306
+ * Outcome of `heartbeat` and `reconfirm`.
307
+ *
308
+ * @since 1.0.0
309
+ * @category models
310
+ */
311
+ export declare const HeartbeatOutcome: Schema.Union<readonly [Schema.TaggedStruct<"Renewed", {
312
+ readonly heartbeatAtMs: Schema.Number;
313
+ }>, Schema.TaggedStruct<"Lost", {}>]>;
314
+ /**
315
+ * Outcome of `heartbeat` and `reconfirm`.
316
+ *
317
+ * @since 1.0.0
318
+ * @category models
319
+ */
320
+ export type HeartbeatOutcome = typeof HeartbeatOutcome.Type;
321
+ /**
322
+ * A stale claim cleared after its claimant was proven dead.
323
+ *
324
+ * @since 1.0.0
325
+ * @category models
326
+ */
327
+ export declare const Recovered: Schema.TaggedStruct<"Recovered", {}>;
328
+ /**
329
+ * A stale claim cleared after its claimant was proven dead.
330
+ *
331
+ * @since 1.0.0
332
+ * @category models
333
+ */
334
+ export type Recovered = typeof Recovered.Type;
335
+ /**
336
+ * Outcome of `recover`.
337
+ *
338
+ * @since 1.0.0
339
+ * @category models
340
+ */
341
+ export declare const RecoverOutcome: Schema.Union<readonly [Schema.TaggedStruct<"Recovered", {}>, Schema.TaggedStruct<"Rejected", {
342
+ readonly reason: Schema.Literals<readonly ["already_claimed", "owner_held", "owner_live", "evidence_invalid", "claim_fresh", "claim_changed", "unavailable"]>;
343
+ }>]>;
344
+ /**
345
+ * Outcome of `recover`.
346
+ *
347
+ * @since 1.0.0
348
+ * @category models
349
+ */
350
+ export type RecoverOutcome = typeof RecoverOutcome.Type;
351
+ declare const ConsensusError_base: Schema.Class<ConsensusError, Schema.TaggedStruct<"@smthrs/journal/ConsensusError", {
352
+ readonly code: Schema.Literals<readonly ["fence_lost", "persistence_failed"]>;
353
+ readonly message: Schema.String;
354
+ readonly cause: Schema.optional<Schema.Unknown>;
355
+ }>, import("effect/Cause").YieldableError>;
356
+ /**
357
+ * Failure raised by a consensus strategy.
358
+ *
359
+ * `fence_lost` is `guard`'s refusal: the supplied owner no longer holds the
360
+ * run, so the fenced write it joins must not commit. `persistence_failed`
361
+ * wraps a strategy's storage failure; the original cause is preserved so the
362
+ * durable writer's retry classification still sees a transient conflict
363
+ * through the wrapper.
364
+ *
365
+ * @since 1.0.0
366
+ * @category errors
367
+ */
368
+ export declare class ConsensusError extends ConsensusError_base {
369
+ }
370
+ /**
371
+ * Consensus operations.
372
+ *
373
+ * The rules being arbitrated are strategy-independent; a strategy
374
+ * chooses where the lease lives and how the fence is checked at commit time.
375
+ * The claim lifecycle is two-phase, exactly as `RunStore`'s always was:
376
+ * `claim` (or `steal`, its evidence-gated form) reserves the run and returns
377
+ * the grant timestamp, `activate` presents that grant to take ownership, and
378
+ * `release` clears whichever of the caller's claim or ownership still stands.
379
+ * `recover` clears a *third party's* stale claim after its claimant was proven
380
+ * dead — the relocated `recoverClaim` mechanic. `guard` is the commit-time
381
+ * admission check (R3) `Journal.emitDurable`, `checkpoint`, and `compact`
382
+ * join: it succeeds while the owner holds the run and fails with `fence_lost`
383
+ * otherwise.
384
+ *
385
+ * Heartbeats and lease state are the strategy's private evidence and never
386
+ * enter the journal.
387
+ *
388
+ * @since 1.0.0
389
+ * @category models
390
+ */
391
+ export interface Service {
392
+ /** Holds a named durable resource lease through work, with heartbeat supervision. */
393
+ readonly withPermit: <A, E, R>(key: string, owner: OwnerId, isAlive: (owner: OwnerId, context: {
394
+ readonly claimant: OwnerId;
395
+ readonly heartbeatAtMs: number | null;
396
+ readonly nowMs: number;
397
+ }) => Effect.Effect<boolean>, effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E | ConsensusError, R>;
398
+ readonly claim: (runId: string, claimant: OwnerId, nowMs: number) => Effect.Effect<ClaimOutcome, ConsensusError>;
399
+ readonly activate: (runId: string, owner: OwnerId, grantedAtMs: number, nowMs: number) => Effect.Effect<ActivateOutcome, ConsensusError>;
400
+ readonly heartbeat: (runId: string, owner: OwnerId, nowMs: number) => Effect.Effect<HeartbeatOutcome, ConsensusError>;
401
+ /** Renews only while this owner holds the lease and no takeover claim is pending. */
402
+ readonly reconfirm: (runId: string, owner: OwnerId, nowMs: number) => Effect.Effect<HeartbeatOutcome, ConsensusError>;
403
+ readonly release: (runId: string, owner: OwnerId) => Effect.Effect<void, ConsensusError>;
404
+ readonly steal: (runId: string, claimant: OwnerId, nowMs: number, evidence: LivenessEvidence) => Effect.Effect<ClaimOutcome, ConsensusError>;
405
+ readonly recover: (runId: string, staleClaimant: OwnerId, grantedAtMs: number, observer: OwnerId, nowMs: number, evidence: LivenessEvidence) => Effect.Effect<RecoverOutcome, ConsensusError>;
406
+ readonly guard: (runId: string, owner: OwnerId) => Effect.Effect<void, ConsensusError>;
407
+ }
408
+ declare const Consensus_base: Context.ServiceClass<Consensus, "@smthrs/journal/Consensus", Service>;
409
+ /**
410
+ * Context service for the injected consensus strategy.
411
+ *
412
+ * @since 1.0.0
413
+ * @category services
414
+ */
415
+ export declare class Consensus extends Consensus_base {
416
+ }
417
+ /**
418
+ * Constructs a consensus service from an implementation.
419
+ *
420
+ * @since 1.0.0
421
+ * @category constructors
422
+ */
423
+ export declare const make: (implementation: Service) => Service;
424
+ /**
425
+ * The refusal `guard` raises for an owner that no longer holds the run.
426
+ *
427
+ * @since 1.0.0
428
+ * @category errors
429
+ */
430
+ export declare const fenceLost: (runId: string, owner: OwnerId) => ConsensusError;
431
+ /**
432
+ * Constructs a strategy that arbitrates nothing: claims are refused, leases
433
+ * are never held, and every fenced write is rejected.
434
+ *
435
+ * @since 1.0.0
436
+ * @category constructors
437
+ */
438
+ export declare const makeNoop: (overrides?: Partial<Service>) => Service;
439
+ /**
440
+ * Provides the refusing strategy stub.
441
+ *
442
+ * @since 1.0.0
443
+ * @category layers
444
+ */
445
+ export declare const layerNoop: (overrides?: Partial<Service>) => Layer.Layer<Consensus>;
446
+ interface LocalLease {
447
+ owner: {
448
+ readonly id: OwnerId;
449
+ readonly grantedAtMs: number;
450
+ heartbeatAtMs: number;
451
+ } | undefined;
452
+ claim: {
453
+ readonly id: OwnerId;
454
+ readonly claimedAtMs: number;
455
+ } | undefined;
456
+ }
457
+ /**
458
+ * Constructs the in-memory single-process strategy.
459
+ *
460
+ * @since 1.0.0
461
+ * @category constructors
462
+ */
463
+ export declare const makeLocal: Effect.Effect<Service>;
464
+ /**
465
+ * Provides the in-memory single-process strategy.
466
+ *
467
+ * The lease lives in process memory, so R3 is exact within the process — the
468
+ * strategy's transitions and the serialized append transactions interleave
469
+ * atomically on one event loop — and browser support needs nothing beyond
470
+ * this layer plus the browser-safe journal. State is per layer build: provide
471
+ * one instance to every service that must agree on it, which is what
472
+ * `SqlJournal.layerWith` and `RunStore.layerWith` exist for.
473
+ *
474
+ * The lease is not part of any database transaction: a transition made inside
475
+ * a `Journal.transact` that later rolls back stays applied in memory, so the
476
+ * lease and a rolled-back run row can disagree until the next transition.
477
+ * `SqlConsensus` keeps the two in one transaction; prefer it wherever a
478
+ * database is present.
479
+ *
480
+ * @since 1.0.0
481
+ * @category layers
482
+ */
483
+ export declare const layerLocal: Layer.Layer<Consensus>;
484
+ /**
485
+ * Shares the existing consensus lease lifecycle with named engine resources.
486
+ * The reader is private to the strategy; resource leases never create runs.
487
+ * @since 1.0.0
488
+ * @category constructors
489
+ */
490
+ export declare const resourcePermit: <A, E, R>(strategy: Omit<Service, "withPermit">, read: () => Effect.Effect<LocalLease | undefined, ConsensusError>, key: string, owner: OwnerId, isAlive: Parameters<Service["withPermit"]>[2], effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E | ConsensusError, R>;
491
+ export {};
492
+ //# sourceMappingURL=Consensus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Consensus.d.ts","sourceRoot":"","sources":["../../src/Consensus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cA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