ramosedb 0.0.1 → 0.4.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 (960) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +17 -0
  3. package/README.md +57 -2
  4. package/dist/Auth.d.ts +55 -0
  5. package/dist/Auth.d.ts.map +1 -0
  6. package/dist/Auth.js +50 -0
  7. package/dist/Auth.js.map +1 -0
  8. package/dist/Database.d.ts +40 -0
  9. package/dist/Database.d.ts.map +1 -0
  10. package/dist/Database.js +62 -0
  11. package/dist/Database.js.map +1 -0
  12. package/dist/Providers.d.ts +8 -0
  13. package/dist/Providers.d.ts.map +1 -0
  14. package/dist/Providers.js +9 -0
  15. package/dist/Providers.js.map +1 -0
  16. package/dist/RamoseEnv.d.ts +37 -0
  17. package/dist/RamoseEnv.d.ts.map +1 -0
  18. package/dist/RamoseEnv.js +2 -0
  19. package/dist/RamoseEnv.js.map +1 -0
  20. package/dist/Server.d.ts +100 -0
  21. package/dist/Server.d.ts.map +1 -0
  22. package/dist/Server.js +263 -0
  23. package/dist/Server.js.map +1 -0
  24. package/dist/ServerRuntime.d.ts +10 -0
  25. package/dist/ServerRuntime.d.ts.map +1 -0
  26. package/dist/ServerRuntime.js +11 -0
  27. package/dist/ServerRuntime.js.map +1 -0
  28. package/dist/better-auth/client.d.ts +19 -0
  29. package/dist/better-auth/client.d.ts.map +1 -0
  30. package/dist/better-auth/client.js +110 -0
  31. package/dist/better-auth/client.js.map +1 -0
  32. package/dist/better-auth/index.d.ts +140 -0
  33. package/dist/better-auth/index.d.ts.map +1 -0
  34. package/dist/better-auth/index.js +168 -0
  35. package/dist/better-auth/index.js.map +1 -0
  36. package/dist/client/activation.d.ts +2 -0
  37. package/dist/client/activation.d.ts.map +1 -0
  38. package/dist/client/activation.js +33 -0
  39. package/dist/client/activation.js.map +1 -0
  40. package/dist/client/catalog.d.ts +15 -0
  41. package/dist/client/catalog.d.ts.map +1 -0
  42. package/dist/client/catalog.js +48 -0
  43. package/dist/client/catalog.js.map +1 -0
  44. package/dist/client/changesets.d.ts +85 -0
  45. package/dist/client/changesets.d.ts.map +1 -0
  46. package/dist/client/changesets.js +160 -0
  47. package/dist/client/changesets.js.map +1 -0
  48. package/dist/client/client.d.ts +45 -0
  49. package/dist/client/client.d.ts.map +1 -0
  50. package/dist/client/client.js +425 -0
  51. package/dist/client/client.js.map +1 -0
  52. package/dist/client/database.d.ts +163 -0
  53. package/dist/client/database.d.ts.map +1 -0
  54. package/dist/client/database.js +795 -0
  55. package/dist/client/database.js.map +1 -0
  56. package/dist/client/entity.d.ts +63 -0
  57. package/dist/client/entity.d.ts.map +1 -0
  58. package/dist/client/entity.js +141 -0
  59. package/dist/client/entity.js.map +1 -0
  60. package/dist/client/errors.d.ts +67 -0
  61. package/dist/client/errors.d.ts.map +1 -0
  62. package/dist/client/errors.js +39 -0
  63. package/dist/client/errors.js.map +1 -0
  64. package/dist/client/index.d.ts +13 -0
  65. package/dist/client/index.d.ts.map +1 -0
  66. package/dist/client/index.js +6 -0
  67. package/dist/client/index.js.map +1 -0
  68. package/dist/client/mutation-schema.d.ts +92 -0
  69. package/dist/client/mutation-schema.d.ts.map +1 -0
  70. package/dist/client/mutation-schema.js +2 -0
  71. package/dist/client/mutation-schema.js.map +1 -0
  72. package/dist/client/mutation.d.ts +25 -0
  73. package/dist/client/mutation.d.ts.map +1 -0
  74. package/dist/client/mutation.js +75 -0
  75. package/dist/client/mutation.js.map +1 -0
  76. package/dist/client/operations.d.ts +39 -0
  77. package/dist/client/operations.d.ts.map +1 -0
  78. package/dist/client/operations.js +183 -0
  79. package/dist/client/operations.js.map +1 -0
  80. package/dist/client/query.d.ts +53 -0
  81. package/dist/client/query.d.ts.map +1 -0
  82. package/dist/client/query.js +85 -0
  83. package/dist/client/query.js.map +1 -0
  84. package/dist/client/receipt.d.ts +53 -0
  85. package/dist/client/receipt.d.ts.map +1 -0
  86. package/dist/client/receipt.js +79 -0
  87. package/dist/client/receipt.js.map +1 -0
  88. package/dist/client/submission.d.ts +44 -0
  89. package/dist/client/submission.d.ts.map +1 -0
  90. package/dist/client/submission.js +165 -0
  91. package/dist/client/submission.js.map +1 -0
  92. package/dist/client/subscription.d.ts +18 -0
  93. package/dist/client/subscription.d.ts.map +1 -0
  94. package/dist/client/subscription.js +75 -0
  95. package/dist/client/subscription.js.map +1 -0
  96. package/dist/client/sync.d.ts +32 -0
  97. package/dist/client/sync.d.ts.map +1 -0
  98. package/dist/client/sync.js +34 -0
  99. package/dist/client/sync.js.map +1 -0
  100. package/dist/client/view.d.ts +37 -0
  101. package/dist/client/view.d.ts.map +1 -0
  102. package/dist/client/view.js +112 -0
  103. package/dist/client/view.js.map +1 -0
  104. package/dist/db/Binding.d.ts +79 -0
  105. package/dist/db/Binding.d.ts.map +1 -0
  106. package/dist/db/Binding.js +138 -0
  107. package/dist/db/Binding.js.map +1 -0
  108. package/dist/db/Composer.d.ts +7 -0
  109. package/dist/db/Composer.d.ts.map +1 -0
  110. package/dist/db/Composer.js +6 -0
  111. package/dist/db/Composer.js.map +1 -0
  112. package/dist/db/DatabaseName.d.ts +7 -0
  113. package/dist/db/DatabaseName.d.ts.map +1 -0
  114. package/dist/db/DatabaseName.js +9 -0
  115. package/dist/db/DatabaseName.js.map +1 -0
  116. package/dist/db/Eid.d.ts +19 -0
  117. package/dist/db/Eid.d.ts.map +1 -0
  118. package/dist/db/Eid.js +2 -0
  119. package/dist/db/Eid.js.map +1 -0
  120. package/dist/db/Entity.d.ts +133 -0
  121. package/dist/db/Entity.d.ts.map +1 -0
  122. package/dist/db/Entity.js +104 -0
  123. package/dist/db/Entity.js.map +1 -0
  124. package/dist/db/Errors.d.ts +138 -0
  125. package/dist/db/Errors.d.ts.map +1 -0
  126. package/dist/db/Errors.js +171 -0
  127. package/dist/db/Errors.js.map +1 -0
  128. package/dist/db/Field.d.ts +170 -0
  129. package/dist/db/Field.d.ts.map +1 -0
  130. package/dist/db/Field.js +187 -0
  131. package/dist/db/Field.js.map +1 -0
  132. package/dist/db/IdentName.d.ts +94 -0
  133. package/dist/db/IdentName.d.ts.map +1 -0
  134. package/dist/db/IdentName.js +34 -0
  135. package/dist/db/IdentName.js.map +1 -0
  136. package/dist/db/Operation.d.ts +441 -0
  137. package/dist/db/Operation.d.ts.map +1 -0
  138. package/dist/db/Operation.js +237 -0
  139. package/dist/db/Operation.js.map +1 -0
  140. package/dist/db/Projection.d.ts +97 -0
  141. package/dist/db/Projection.d.ts.map +1 -0
  142. package/dist/db/Projection.js +183 -0
  143. package/dist/db/Projection.js.map +1 -0
  144. package/dist/db/Pull.d.ts +361 -0
  145. package/dist/db/Pull.d.ts.map +1 -0
  146. package/dist/db/Pull.js +547 -0
  147. package/dist/db/Pull.js.map +1 -0
  148. package/dist/db/Schema.d.ts +37 -0
  149. package/dist/db/Schema.d.ts.map +1 -0
  150. package/dist/db/Schema.js +94 -0
  151. package/dist/db/Schema.js.map +1 -0
  152. package/dist/db/Trait.d.ts +129 -0
  153. package/dist/db/Trait.d.ts.map +1 -0
  154. package/dist/db/Trait.js +65 -0
  155. package/dist/db/Trait.js.map +1 -0
  156. package/dist/db/Tx.d.ts +128 -0
  157. package/dist/db/Tx.d.ts.map +1 -0
  158. package/dist/db/Tx.js +248 -0
  159. package/dist/db/Tx.js.map +1 -0
  160. package/dist/db/allocations.d.ts +44 -0
  161. package/dist/db/allocations.d.ts.map +1 -0
  162. package/dist/db/allocations.js +70 -0
  163. package/dist/db/allocations.js.map +1 -0
  164. package/dist/db/attrRef.d.ts +5 -0
  165. package/dist/db/attrRef.d.ts.map +1 -0
  166. package/dist/db/attrRef.js +6 -0
  167. package/dist/db/attrRef.js.map +1 -0
  168. package/dist/db/compose.d.ts +26 -0
  169. package/dist/db/compose.d.ts.map +1 -0
  170. package/dist/db/compose.js +105 -0
  171. package/dist/db/compose.js.map +1 -0
  172. package/dist/db/composition.d.ts +4 -0
  173. package/dist/db/composition.d.ts.map +1 -0
  174. package/dist/db/composition.js +24 -0
  175. package/dist/db/composition.js.map +1 -0
  176. package/dist/db/creation.d.ts +102 -0
  177. package/dist/db/creation.d.ts.map +1 -0
  178. package/dist/db/creation.js +448 -0
  179. package/dist/db/creation.js.map +1 -0
  180. package/dist/db/deployedSchema.d.ts +12 -0
  181. package/dist/db/deployedSchema.d.ts.map +1 -0
  182. package/dist/db/deployedSchema.js +80 -0
  183. package/dist/db/deployedSchema.js.map +1 -0
  184. package/dist/db/documentation.d.ts +4 -0
  185. package/dist/db/documentation.d.ts.map +1 -0
  186. package/dist/db/documentation.js +4 -0
  187. package/dist/db/documentation.js.map +1 -0
  188. package/dist/db/ensure.d.ts +16 -0
  189. package/dist/db/ensure.d.ts.map +1 -0
  190. package/dist/db/ensure.js +48 -0
  191. package/dist/db/ensure.js.map +1 -0
  192. package/dist/db/entityArg.d.ts +15 -0
  193. package/dist/db/entityArg.d.ts.map +1 -0
  194. package/dist/db/entityArg.js +71 -0
  195. package/dist/db/entityArg.js.map +1 -0
  196. package/dist/db/equal.d.ts +4 -0
  197. package/dist/db/equal.d.ts.map +1 -0
  198. package/dist/db/equal.js +2 -0
  199. package/dist/db/equal.js.map +1 -0
  200. package/dist/db/idents.d.ts +90 -0
  201. package/dist/db/idents.d.ts.map +1 -0
  202. package/dist/db/idents.js +2 -0
  203. package/dist/db/idents.js.map +1 -0
  204. package/dist/db/index.d.ts +27 -0
  205. package/dist/db/index.d.ts.map +1 -0
  206. package/dist/db/index.js +20 -0
  207. package/dist/db/index.js.map +1 -0
  208. package/dist/db/internal.d.ts +27 -0
  209. package/dist/db/internal.d.ts.map +1 -0
  210. package/dist/db/internal.js +27 -0
  211. package/dist/db/internal.js.map +1 -0
  212. package/dist/db/query/cursor.d.ts +13 -0
  213. package/dist/db/query/cursor.d.ts.map +1 -0
  214. package/dist/db/query/cursor.js +150 -0
  215. package/dist/db/query/cursor.js.map +1 -0
  216. package/dist/db/query/elemFilter.d.ts +7 -0
  217. package/dist/db/query/elemFilter.d.ts.map +1 -0
  218. package/dist/db/query/elemFilter.js +280 -0
  219. package/dist/db/query/elemFilter.js.map +1 -0
  220. package/dist/db/query/fluent.d.ts +92 -0
  221. package/dist/db/query/fluent.d.ts.map +1 -0
  222. package/dist/db/query/fluent.js +125 -0
  223. package/dist/db/query/fluent.js.map +1 -0
  224. package/dist/db/query/focus.d.ts +42 -0
  225. package/dist/db/query/focus.d.ts.map +1 -0
  226. package/dist/db/query/focus.js +2 -0
  227. package/dist/db/query/focus.js.map +1 -0
  228. package/dist/db/query/index.d.ts +7 -0
  229. package/dist/db/query/index.d.ts.map +1 -0
  230. package/dist/db/query/index.js +6 -0
  231. package/dist/db/query/index.js.map +1 -0
  232. package/dist/db/query/kernel.d.ts +215 -0
  233. package/dist/db/query/kernel.d.ts.map +1 -0
  234. package/dist/db/query/kernel.js +284 -0
  235. package/dist/db/query/kernel.js.map +1 -0
  236. package/dist/db/query/lib.d.ts +168 -0
  237. package/dist/db/query/lib.d.ts.map +1 -0
  238. package/dist/db/query/lib.js +175 -0
  239. package/dist/db/query/lib.js.map +1 -0
  240. package/dist/db/query/query.d.ts +209 -0
  241. package/dist/db/query/query.d.ts.map +1 -0
  242. package/dist/db/query/query.js +1536 -0
  243. package/dist/db/query/query.js.map +1 -0
  244. package/dist/db/query/stdlib/failures.d.ts +91 -0
  245. package/dist/db/query/stdlib/failures.d.ts.map +1 -0
  246. package/dist/db/query/stdlib/failures.js +57 -0
  247. package/dist/db/query/stdlib/failures.js.map +1 -0
  248. package/dist/db/query/stdlib/implementations.d.ts +5 -0
  249. package/dist/db/query/stdlib/implementations.d.ts.map +1 -0
  250. package/dist/db/query/stdlib/implementations.js +208 -0
  251. package/dist/db/query/stdlib/implementations.js.map +1 -0
  252. package/dist/db/query/stdlib/index.d.ts +6 -0
  253. package/dist/db/query/stdlib/index.d.ts.map +1 -0
  254. package/dist/db/query/stdlib/index.js +6 -0
  255. package/dist/db/query/stdlib/index.js.map +1 -0
  256. package/dist/db/query/stdlib/manifest.d.ts +3 -0
  257. package/dist/db/query/stdlib/manifest.d.ts.map +1 -0
  258. package/dist/db/query/stdlib/manifest.js +1067 -0
  259. package/dist/db/query/stdlib/manifest.js.map +1 -0
  260. package/dist/db/query/stdlib/registry.d.ts +22 -0
  261. package/dist/db/query/stdlib/registry.d.ts.map +1 -0
  262. package/dist/db/query/stdlib/registry.js +144 -0
  263. package/dist/db/query/stdlib/registry.js.map +1 -0
  264. package/dist/db/query/stdlib/types.d.ts +50 -0
  265. package/dist/db/query/stdlib/types.d.ts.map +1 -0
  266. package/dist/db/query/stdlib/types.js +17 -0
  267. package/dist/db/query/stdlib/types.js.map +1 -0
  268. package/dist/db/query/stdlib/values.d.ts +17 -0
  269. package/dist/db/query/stdlib/values.d.ts.map +1 -0
  270. package/dist/db/query/stdlib/values.js +200 -0
  271. package/dist/db/query/stdlib/values.js.map +1 -0
  272. package/dist/db/query/surface.d.ts +15 -0
  273. package/dist/db/query/surface.d.ts.map +1 -0
  274. package/dist/db/query/surface.js +14 -0
  275. package/dist/db/query/surface.js.map +1 -0
  276. package/dist/db/reachability.d.ts +40 -0
  277. package/dist/db/reachability.d.ts.map +1 -0
  278. package/dist/db/reachability.js +118 -0
  279. package/dist/db/reachability.js.map +1 -0
  280. package/dist/db/refs.d.ts +46 -0
  281. package/dist/db/refs.d.ts.map +1 -0
  282. package/dist/db/refs.js +69 -0
  283. package/dist/db/refs.js.map +1 -0
  284. package/dist/db/shapes.d.ts +227 -0
  285. package/dist/db/shapes.d.ts.map +1 -0
  286. package/dist/db/shapes.js +246 -0
  287. package/dist/db/shapes.js.map +1 -0
  288. package/dist/db/valueTypes.d.ts +92 -0
  289. package/dist/db/valueTypes.d.ts.map +1 -0
  290. package/dist/db/valueTypes.js +105 -0
  291. package/dist/db/valueTypes.js.map +1 -0
  292. package/dist/errorHttp.d.ts +27 -0
  293. package/dist/errorHttp.d.ts.map +1 -0
  294. package/dist/errorHttp.js +95 -0
  295. package/dist/errorHttp.js.map +1 -0
  296. package/dist/index.d.ts +7 -0
  297. package/dist/index.d.ts.map +1 -0
  298. package/dist/index.js +7 -0
  299. package/dist/index.js.map +1 -0
  300. package/dist/internal/authorization/authoring/compile.d.ts +132 -0
  301. package/dist/internal/authorization/authoring/compile.d.ts.map +1 -0
  302. package/dist/internal/authorization/authoring/compile.js +634 -0
  303. package/dist/internal/authorization/authoring/compile.js.map +1 -0
  304. package/dist/internal/authorization/authoring/expr.d.ts +25 -0
  305. package/dist/internal/authorization/authoring/expr.d.ts.map +1 -0
  306. package/dist/internal/authorization/authoring/expr.js +56 -0
  307. package/dist/internal/authorization/authoring/expr.js.map +1 -0
  308. package/dist/internal/authorization/authoring/index.d.ts +10 -0
  309. package/dist/internal/authorization/authoring/index.d.ts.map +1 -0
  310. package/dist/internal/authorization/authoring/index.js +8 -0
  311. package/dist/internal/authorization/authoring/index.js.map +1 -0
  312. package/dist/internal/authorization/authoring/invoke.d.ts +8 -0
  313. package/dist/internal/authorization/authoring/invoke.d.ts.map +1 -0
  314. package/dist/internal/authorization/authoring/invoke.js +7 -0
  315. package/dist/internal/authorization/authoring/invoke.js.map +1 -0
  316. package/dist/internal/authorization/authoring/operations.d.ts +81 -0
  317. package/dist/internal/authorization/authoring/operations.d.ts.map +1 -0
  318. package/dist/internal/authorization/authoring/operations.js +591 -0
  319. package/dist/internal/authorization/authoring/operations.js.map +1 -0
  320. package/dist/internal/authorization/authoring/path.d.ts +20 -0
  321. package/dist/internal/authorization/authoring/path.d.ts.map +1 -0
  322. package/dist/internal/authorization/authoring/path.js +109 -0
  323. package/dist/internal/authorization/authoring/path.js.map +1 -0
  324. package/dist/internal/authorization/authoring/policy.d.ts +120 -0
  325. package/dist/internal/authorization/authoring/policy.d.ts.map +1 -0
  326. package/dist/internal/authorization/authoring/policy.js +218 -0
  327. package/dist/internal/authorization/authoring/policy.js.map +1 -0
  328. package/dist/internal/authorization/authoring/read.d.ts +13 -0
  329. package/dist/internal/authorization/authoring/read.d.ts.map +1 -0
  330. package/dist/internal/authorization/authoring/read.js +27 -0
  331. package/dist/internal/authorization/authoring/read.js.map +1 -0
  332. package/dist/internal/authorization/authoring/types.d.ts +127 -0
  333. package/dist/internal/authorization/authoring/types.d.ts.map +1 -0
  334. package/dist/internal/authorization/authoring/types.js +43 -0
  335. package/dist/internal/authorization/authoring/types.js.map +1 -0
  336. package/dist/internal/authorization/bind.d.ts +687 -0
  337. package/dist/internal/authorization/bind.d.ts.map +1 -0
  338. package/dist/internal/authorization/bind.js +485 -0
  339. package/dist/internal/authorization/bind.js.map +1 -0
  340. package/dist/internal/authorization/bounds.d.ts +13 -0
  341. package/dist/internal/authorization/bounds.d.ts.map +1 -0
  342. package/dist/internal/authorization/bounds.js +9 -0
  343. package/dist/internal/authorization/bounds.js.map +1 -0
  344. package/dist/internal/authorization/canonical-json.d.ts +6 -0
  345. package/dist/internal/authorization/canonical-json.d.ts.map +1 -0
  346. package/dist/internal/authorization/canonical-json.js +65 -0
  347. package/dist/internal/authorization/canonical-json.js.map +1 -0
  348. package/dist/internal/authorization/catalog-unit.d.ts +1033 -0
  349. package/dist/internal/authorization/catalog-unit.d.ts.map +1 -0
  350. package/dist/internal/authorization/catalog-unit.js +303 -0
  351. package/dist/internal/authorization/catalog-unit.js.map +1 -0
  352. package/dist/internal/authorization/catalog.d.ts +472 -0
  353. package/dist/internal/authorization/catalog.d.ts.map +1 -0
  354. package/dist/internal/authorization/catalog.js +134 -0
  355. package/dist/internal/authorization/catalog.js.map +1 -0
  356. package/dist/internal/authorization/changesets.d.ts +54 -0
  357. package/dist/internal/authorization/changesets.d.ts.map +1 -0
  358. package/dist/internal/authorization/changesets.js +156 -0
  359. package/dist/internal/authorization/changesets.js.map +1 -0
  360. package/dist/internal/authorization/composition.d.ts +10 -0
  361. package/dist/internal/authorization/composition.d.ts.map +1 -0
  362. package/dist/internal/authorization/composition.js +28 -0
  363. package/dist/internal/authorization/composition.js.map +1 -0
  364. package/dist/internal/authorization/database-bindings.d.ts +48 -0
  365. package/dist/internal/authorization/database-bindings.d.ts.map +1 -0
  366. package/dist/internal/authorization/database-bindings.js +101 -0
  367. package/dist/internal/authorization/database-bindings.js.map +1 -0
  368. package/dist/internal/authorization/database-target.d.ts +75 -0
  369. package/dist/internal/authorization/database-target.d.ts.map +1 -0
  370. package/dist/internal/authorization/database-target.js +65 -0
  371. package/dist/internal/authorization/database-target.js.map +1 -0
  372. package/dist/internal/authorization/decode.d.ts +1704 -0
  373. package/dist/internal/authorization/decode.d.ts.map +1 -0
  374. package/dist/internal/authorization/decode.js +294 -0
  375. package/dist/internal/authorization/decode.js.map +1 -0
  376. package/dist/internal/authorization/definitions.d.ts +66 -0
  377. package/dist/internal/authorization/definitions.d.ts.map +1 -0
  378. package/dist/internal/authorization/definitions.js +335 -0
  379. package/dist/internal/authorization/definitions.js.map +1 -0
  380. package/dist/internal/authorization/deployed.d.ts +43 -0
  381. package/dist/internal/authorization/deployed.d.ts.map +1 -0
  382. package/dist/internal/authorization/deployed.js +184 -0
  383. package/dist/internal/authorization/deployed.js.map +1 -0
  384. package/dist/internal/authorization/entity-targets.d.ts +68 -0
  385. package/dist/internal/authorization/entity-targets.d.ts.map +1 -0
  386. package/dist/internal/authorization/entity-targets.js +244 -0
  387. package/dist/internal/authorization/entity-targets.js.map +1 -0
  388. package/dist/internal/authorization/expr.d.ts +259 -0
  389. package/dist/internal/authorization/expr.d.ts.map +1 -0
  390. package/dist/internal/authorization/expr.js +55 -0
  391. package/dist/internal/authorization/expr.js.map +1 -0
  392. package/dist/internal/authorization/failures.d.ts +78 -0
  393. package/dist/internal/authorization/failures.d.ts.map +1 -0
  394. package/dist/internal/authorization/failures.js +22 -0
  395. package/dist/internal/authorization/failures.js.map +1 -0
  396. package/dist/internal/authorization/identities.d.ts +207 -0
  397. package/dist/internal/authorization/identities.d.ts.map +1 -0
  398. package/dist/internal/authorization/identities.js +71 -0
  399. package/dist/internal/authorization/identities.js.map +1 -0
  400. package/dist/internal/authorization/index.d.ts +33 -0
  401. package/dist/internal/authorization/index.d.ts.map +1 -0
  402. package/dist/internal/authorization/index.js +33 -0
  403. package/dist/internal/authorization/index.js.map +1 -0
  404. package/dist/internal/authorization/install/normalize.d.ts +196 -0
  405. package/dist/internal/authorization/install/normalize.d.ts.map +1 -0
  406. package/dist/internal/authorization/install/normalize.js +168 -0
  407. package/dist/internal/authorization/install/normalize.js.map +1 -0
  408. package/dist/internal/authorization/install/plan.d.ts +8 -0
  409. package/dist/internal/authorization/install/plan.d.ts.map +1 -0
  410. package/dist/internal/authorization/install/plan.js +177 -0
  411. package/dist/internal/authorization/install/plan.js.map +1 -0
  412. package/dist/internal/authorization/install.d.ts +404 -0
  413. package/dist/internal/authorization/install.d.ts.map +1 -0
  414. package/dist/internal/authorization/install.js +103 -0
  415. package/dist/internal/authorization/install.js.map +1 -0
  416. package/dist/internal/authorization/invocation-codec.d.ts +10 -0
  417. package/dist/internal/authorization/invocation-codec.d.ts.map +1 -0
  418. package/dist/internal/authorization/invocation-codec.js +36 -0
  419. package/dist/internal/authorization/invocation-codec.js.map +1 -0
  420. package/dist/internal/authorization/invocation-receipts.d.ts +192 -0
  421. package/dist/internal/authorization/invocation-receipts.d.ts.map +1 -0
  422. package/dist/internal/authorization/invocation-receipts.js +546 -0
  423. package/dist/internal/authorization/invocation-receipts.js.map +1 -0
  424. package/dist/internal/authorization/ir.d.ts +1465 -0
  425. package/dist/internal/authorization/ir.d.ts.map +1 -0
  426. package/dist/internal/authorization/ir.js +131 -0
  427. package/dist/internal/authorization/ir.js.map +1 -0
  428. package/dist/internal/authorization/json.d.ts +8 -0
  429. package/dist/internal/authorization/json.d.ts.map +1 -0
  430. package/dist/internal/authorization/json.js +13 -0
  431. package/dist/internal/authorization/json.js.map +1 -0
  432. package/dist/internal/authorization/live.d.ts +38 -0
  433. package/dist/internal/authorization/live.d.ts.map +1 -0
  434. package/dist/internal/authorization/live.js +227 -0
  435. package/dist/internal/authorization/live.js.map +1 -0
  436. package/dist/internal/authorization/operation-grant.d.ts +16 -0
  437. package/dist/internal/authorization/operation-grant.d.ts.map +1 -0
  438. package/dist/internal/authorization/operation-grant.js +79 -0
  439. package/dist/internal/authorization/operation-grant.js.map +1 -0
  440. package/dist/internal/authorization/operation-version.d.ts +28 -0
  441. package/dist/internal/authorization/operation-version.d.ts.map +1 -0
  442. package/dist/internal/authorization/operation-version.js +206 -0
  443. package/dist/internal/authorization/operation-version.js.map +1 -0
  444. package/dist/internal/authorization/operations-runtime.d.ts +78 -0
  445. package/dist/internal/authorization/operations-runtime.d.ts.map +1 -0
  446. package/dist/internal/authorization/operations-runtime.js +1130 -0
  447. package/dist/internal/authorization/operations-runtime.js.map +1 -0
  448. package/dist/internal/authorization/principal.d.ts +95 -0
  449. package/dist/internal/authorization/principal.d.ts.map +1 -0
  450. package/dist/internal/authorization/principal.js +53 -0
  451. package/dist/internal/authorization/principal.js.map +1 -0
  452. package/dist/internal/authorization/query-view.d.ts +7 -0
  453. package/dist/internal/authorization/query-view.d.ts.map +1 -0
  454. package/dist/internal/authorization/query-view.js +17 -0
  455. package/dist/internal/authorization/query-view.js.map +1 -0
  456. package/dist/internal/authorization/read-compatibility.d.ts +185 -0
  457. package/dist/internal/authorization/read-compatibility.d.ts.map +1 -0
  458. package/dist/internal/authorization/read-compatibility.js +176 -0
  459. package/dist/internal/authorization/read-compatibility.js.map +1 -0
  460. package/dist/internal/authorization/read-filter.d.ts +48 -0
  461. package/dist/internal/authorization/read-filter.d.ts.map +1 -0
  462. package/dist/internal/authorization/read-filter.js +496 -0
  463. package/dist/internal/authorization/read-filter.js.map +1 -0
  464. package/dist/internal/authorization/read-tables.d.ts +9 -0
  465. package/dist/internal/authorization/read-tables.d.ts.map +1 -0
  466. package/dist/internal/authorization/read-tables.js +120 -0
  467. package/dist/internal/authorization/read-tables.js.map +1 -0
  468. package/dist/internal/authorization/reads.d.ts +36 -0
  469. package/dist/internal/authorization/reads.d.ts.map +1 -0
  470. package/dist/internal/authorization/reads.js +35 -0
  471. package/dist/internal/authorization/reads.js.map +1 -0
  472. package/dist/internal/authorization/request.d.ts +64 -0
  473. package/dist/internal/authorization/request.d.ts.map +1 -0
  474. package/dist/internal/authorization/request.js +210 -0
  475. package/dist/internal/authorization/request.js.map +1 -0
  476. package/dist/internal/authorization/truth.d.ts +51 -0
  477. package/dist/internal/authorization/truth.d.ts.map +1 -0
  478. package/dist/internal/authorization/truth.js +23 -0
  479. package/dist/internal/authorization/truth.js.map +1 -0
  480. package/dist/internal/authorization/validate.d.ts +3 -0
  481. package/dist/internal/authorization/validate.d.ts.map +1 -0
  482. package/dist/internal/authorization/validate.js +3 -0
  483. package/dist/internal/authorization/validate.js.map +1 -0
  484. package/dist/internal/authorization/validation/catalog.d.ts +32 -0
  485. package/dist/internal/authorization/validation/catalog.d.ts.map +1 -0
  486. package/dist/internal/authorization/validation/catalog.js +417 -0
  487. package/dist/internal/authorization/validation/catalog.js.map +1 -0
  488. package/dist/internal/authorization/validation/common.d.ts +20 -0
  489. package/dist/internal/authorization/validation/common.d.ts.map +1 -0
  490. package/dist/internal/authorization/validation/common.js +36 -0
  491. package/dist/internal/authorization/validation/common.js.map +1 -0
  492. package/dist/internal/authorization/validation/decisions.d.ts +7 -0
  493. package/dist/internal/authorization/validation/decisions.d.ts.map +1 -0
  494. package/dist/internal/authorization/validation/decisions.js +107 -0
  495. package/dist/internal/authorization/validation/decisions.js.map +1 -0
  496. package/dist/internal/authorization/validation/descriptors.d.ts +8 -0
  497. package/dist/internal/authorization/validation/descriptors.d.ts.map +1 -0
  498. package/dist/internal/authorization/validation/descriptors.js +24 -0
  499. package/dist/internal/authorization/validation/descriptors.js.map +1 -0
  500. package/dist/internal/authorization/validation/expression.d.ts +11 -0
  501. package/dist/internal/authorization/validation/expression.d.ts.map +1 -0
  502. package/dist/internal/authorization/validation/expression.js +114 -0
  503. package/dist/internal/authorization/validation/expression.js.map +1 -0
  504. package/dist/internal/authorization/validation/traversal.d.ts +19 -0
  505. package/dist/internal/authorization/validation/traversal.d.ts.map +1 -0
  506. package/dist/internal/authorization/validation/traversal.js +141 -0
  507. package/dist/internal/authorization/validation/traversal.js.map +1 -0
  508. package/dist/internal/authorization/validation/types.d.ts +55 -0
  509. package/dist/internal/authorization/validation/types.d.ts.map +1 -0
  510. package/dist/internal/authorization/validation/types.js +184 -0
  511. package/dist/internal/authorization/validation/types.js.map +1 -0
  512. package/dist/internal/authorization/validation/validate.d.ts +421 -0
  513. package/dist/internal/authorization/validation/validate.d.ts.map +1 -0
  514. package/dist/internal/authorization/validation/validate.js +95 -0
  515. package/dist/internal/authorization/validation/validate.js.map +1 -0
  516. package/dist/internal/authorization/version.d.ts +11 -0
  517. package/dist/internal/authorization/version.d.ts.map +1 -0
  518. package/dist/internal/authorization/version.js +10 -0
  519. package/dist/internal/authorization/version.js.map +1 -0
  520. package/dist/internal/changesets/protocol.d.ts +185 -0
  521. package/dist/internal/changesets/protocol.d.ts.map +1 -0
  522. package/dist/internal/changesets/protocol.js +39 -0
  523. package/dist/internal/changesets/protocol.js.map +1 -0
  524. package/dist/internal/changesets/service.d.ts +69 -0
  525. package/dist/internal/changesets/service.d.ts.map +1 -0
  526. package/dist/internal/changesets/service.js +298 -0
  527. package/dist/internal/changesets/service.js.map +1 -0
  528. package/dist/internal/core/bytes.d.ts +41 -0
  529. package/dist/internal/core/bytes.d.ts.map +1 -0
  530. package/dist/internal/core/bytes.js +215 -0
  531. package/dist/internal/core/bytes.js.map +1 -0
  532. package/dist/internal/core/composition.d.ts +20 -0
  533. package/dist/internal/core/composition.d.ts.map +1 -0
  534. package/dist/internal/core/composition.js +52 -0
  535. package/dist/internal/core/composition.js.map +1 -0
  536. package/dist/internal/core/conn.d.ts +64 -0
  537. package/dist/internal/core/conn.d.ts.map +1 -0
  538. package/dist/internal/core/conn.js +240 -0
  539. package/dist/internal/core/conn.js.map +1 -0
  540. package/dist/internal/core/datom.d.ts +73 -0
  541. package/dist/internal/core/datom.d.ts.map +1 -0
  542. package/dist/internal/core/datom.js +477 -0
  543. package/dist/internal/core/datom.js.map +1 -0
  544. package/dist/internal/core/db.d.ts +65 -0
  545. package/dist/internal/core/db.d.ts.map +1 -0
  546. package/dist/internal/core/db.js +261 -0
  547. package/dist/internal/core/db.js.map +1 -0
  548. package/dist/internal/core/index.d.ts +21 -0
  549. package/dist/internal/core/index.d.ts.map +1 -0
  550. package/dist/internal/core/index.js +21 -0
  551. package/dist/internal/core/index.js.map +1 -0
  552. package/dist/internal/core/json.d.ts +5 -0
  553. package/dist/internal/core/json.d.ts.map +1 -0
  554. package/dist/internal/core/json.js +56 -0
  555. package/dist/internal/core/json.js.map +1 -0
  556. package/dist/internal/core/log.d.ts +68 -0
  557. package/dist/internal/core/log.d.ts.map +1 -0
  558. package/dist/internal/core/log.js +76 -0
  559. package/dist/internal/core/log.js.map +1 -0
  560. package/dist/internal/core/novelty.d.ts +38 -0
  561. package/dist/internal/core/novelty.d.ts.map +1 -0
  562. package/dist/internal/core/novelty.js +300 -0
  563. package/dist/internal/core/novelty.js.map +1 -0
  564. package/dist/internal/core/query/ast.d.ts +174 -0
  565. package/dist/internal/core/query/ast.d.ts.map +1 -0
  566. package/dist/internal/core/query/ast.js +37 -0
  567. package/dist/internal/core/query/ast.js.map +1 -0
  568. package/dist/internal/core/query/builtins.d.ts +19 -0
  569. package/dist/internal/core/query/builtins.d.ts.map +1 -0
  570. package/dist/internal/core/query/builtins.js +242 -0
  571. package/dist/internal/core/query/builtins.js.map +1 -0
  572. package/dist/internal/core/query/edn.d.ts +19 -0
  573. package/dist/internal/core/query/edn.d.ts.map +1 -0
  574. package/dist/internal/core/query/edn.js +248 -0
  575. package/dist/internal/core/query/edn.js.map +1 -0
  576. package/dist/internal/core/query/engine.d.ts +56 -0
  577. package/dist/internal/core/query/engine.d.ts.map +1 -0
  578. package/dist/internal/core/query/engine.js +0 -0
  579. package/dist/internal/core/query/engine.js.map +1 -0
  580. package/dist/internal/core/query/parse.d.ts +8 -0
  581. package/dist/internal/core/query/parse.d.ts.map +1 -0
  582. package/dist/internal/core/query/parse.js +606 -0
  583. package/dist/internal/core/query/parse.js.map +1 -0
  584. package/dist/internal/core/query/pull.d.ts +7 -0
  585. package/dist/internal/core/query/pull.d.ts.map +1 -0
  586. package/dist/internal/core/query/pull.js +304 -0
  587. package/dist/internal/core/query/pull.js.map +1 -0
  588. package/dist/internal/core/query/value.d.ts +10 -0
  589. package/dist/internal/core/query/value.d.ts.map +1 -0
  590. package/dist/internal/core/query/value.js +21 -0
  591. package/dist/internal/core/query/value.js.map +1 -0
  592. package/dist/internal/core/revision.d.ts +19 -0
  593. package/dist/internal/core/revision.d.ts.map +1 -0
  594. package/dist/internal/core/revision.js +13 -0
  595. package/dist/internal/core/revision.js.map +1 -0
  596. package/dist/internal/core/schema.d.ts +63 -0
  597. package/dist/internal/core/schema.d.ts.map +1 -0
  598. package/dist/internal/core/schema.js +228 -0
  599. package/dist/internal/core/schema.js.map +1 -0
  600. package/dist/internal/core/segment.d.ts +16 -0
  601. package/dist/internal/core/segment.d.ts.map +1 -0
  602. package/dist/internal/core/segment.js +149 -0
  603. package/dist/internal/core/segment.js.map +1 -0
  604. package/dist/internal/core/store.d.ts +35 -0
  605. package/dist/internal/core/store.d.ts.map +1 -0
  606. package/dist/internal/core/store.js +88 -0
  607. package/dist/internal/core/store.js.map +1 -0
  608. package/dist/internal/core/telemetry.d.ts +53 -0
  609. package/dist/internal/core/telemetry.d.ts.map +1 -0
  610. package/dist/internal/core/telemetry.js +103 -0
  611. package/dist/internal/core/telemetry.js.map +1 -0
  612. package/dist/internal/core/tree.d.ts +60 -0
  613. package/dist/internal/core/tree.d.ts.map +1 -0
  614. package/dist/internal/core/tree.js +625 -0
  615. package/dist/internal/core/tree.js.map +1 -0
  616. package/dist/internal/core/tx-provenance.d.ts +7 -0
  617. package/dist/internal/core/tx-provenance.d.ts.map +1 -0
  618. package/dist/internal/core/tx-provenance.js +16 -0
  619. package/dist/internal/core/tx-provenance.js.map +1 -0
  620. package/dist/internal/core/tx.d.ts +51 -0
  621. package/dist/internal/core/tx.d.ts.map +1 -0
  622. package/dist/internal/core/tx.js +1029 -0
  623. package/dist/internal/core/tx.js.map +1 -0
  624. package/dist/internal/replica/basis.d.ts +15 -0
  625. package/dist/internal/replica/basis.d.ts.map +1 -0
  626. package/dist/internal/replica/basis.js +32 -0
  627. package/dist/internal/replica/basis.js.map +1 -0
  628. package/dist/internal/replica/errors.d.ts +32 -0
  629. package/dist/internal/replica/errors.d.ts.map +1 -0
  630. package/dist/internal/replica/errors.js +30 -0
  631. package/dist/internal/replica/errors.js.map +1 -0
  632. package/dist/internal/replica/index.d.ts +4 -0
  633. package/dist/internal/replica/index.d.ts.map +1 -0
  634. package/dist/internal/replica/index.js +4 -0
  635. package/dist/internal/replica/index.js.map +1 -0
  636. package/dist/internal/replica/replica-do-testing.d.ts +11 -0
  637. package/dist/internal/replica/replica-do-testing.d.ts.map +1 -0
  638. package/dist/internal/replica/replica-do-testing.js +340 -0
  639. package/dist/internal/replica/replica-do-testing.js.map +1 -0
  640. package/dist/internal/replica/replica-do.d.ts +87 -0
  641. package/dist/internal/replica/replica-do.d.ts.map +1 -0
  642. package/dist/internal/replica/replica-do.js +735 -0
  643. package/dist/internal/replica/replica-do.js.map +1 -0
  644. package/dist/internal/replica/revision-retention.d.ts +29 -0
  645. package/dist/internal/replica/revision-retention.d.ts.map +1 -0
  646. package/dist/internal/replica/revision-retention.js +39 -0
  647. package/dist/internal/replica/revision-retention.js.map +1 -0
  648. package/dist/internal/replication/activation-fence.d.ts +40 -0
  649. package/dist/internal/replication/activation-fence.d.ts.map +1 -0
  650. package/dist/internal/replication/activation-fence.js +85 -0
  651. package/dist/internal/replication/activation-fence.js.map +1 -0
  652. package/dist/internal/replication/digest.d.ts +2 -0
  653. package/dist/internal/replication/digest.d.ts.map +1 -0
  654. package/dist/internal/replication/digest.js +12 -0
  655. package/dist/internal/replication/digest.js.map +1 -0
  656. package/dist/internal/replication/entity-id.d.ts +23 -0
  657. package/dist/internal/replication/entity-id.d.ts.map +1 -0
  658. package/dist/internal/replication/entity-id.js +161 -0
  659. package/dist/internal/replication/entity-id.js.map +1 -0
  660. package/dist/internal/replication/idb.d.ts +9 -0
  661. package/dist/internal/replication/idb.d.ts.map +1 -0
  662. package/dist/internal/replication/idb.js +46 -0
  663. package/dist/internal/replication/idb.js.map +1 -0
  664. package/dist/internal/replication/identity-root.d.ts +11 -0
  665. package/dist/internal/replication/identity-root.d.ts.map +1 -0
  666. package/dist/internal/replication/identity-root.js +48 -0
  667. package/dist/internal/replication/identity-root.js.map +1 -0
  668. package/dist/internal/replication/identity.d.ts +40 -0
  669. package/dist/internal/replication/identity.d.ts.map +1 -0
  670. package/dist/internal/replication/identity.js +95 -0
  671. package/dist/internal/replication/identity.js.map +1 -0
  672. package/dist/internal/replication/index.d.ts +13 -0
  673. package/dist/internal/replication/index.d.ts.map +1 -0
  674. package/dist/internal/replication/index.js +13 -0
  675. package/dist/internal/replication/index.js.map +1 -0
  676. package/dist/internal/replication/indexeddb.d.ts +171 -0
  677. package/dist/internal/replication/indexeddb.d.ts.map +1 -0
  678. package/dist/internal/replication/indexeddb.js +1809 -0
  679. package/dist/internal/replication/indexeddb.js.map +1 -0
  680. package/dist/internal/replication/leadership.d.ts +36 -0
  681. package/dist/internal/replication/leadership.d.ts.map +1 -0
  682. package/dist/internal/replication/leadership.js +108 -0
  683. package/dist/internal/replication/leadership.js.map +1 -0
  684. package/dist/internal/replication/logical.d.ts +40 -0
  685. package/dist/internal/replication/logical.d.ts.map +1 -0
  686. package/dist/internal/replication/logical.js +375 -0
  687. package/dist/internal/replication/logical.js.map +1 -0
  688. package/dist/internal/replication/notices.d.ts +32 -0
  689. package/dist/internal/replication/notices.d.ts.map +1 -0
  690. package/dist/internal/replication/notices.js +92 -0
  691. package/dist/internal/replication/notices.js.map +1 -0
  692. package/dist/internal/replication/outbox-storage.d.ts +98 -0
  693. package/dist/internal/replication/outbox-storage.d.ts.map +1 -0
  694. package/dist/internal/replication/outbox-storage.js +826 -0
  695. package/dist/internal/replication/outbox-storage.js.map +1 -0
  696. package/dist/internal/replication/outbox.d.ts +200 -0
  697. package/dist/internal/replication/outbox.d.ts.map +1 -0
  698. package/dist/internal/replication/outbox.js +744 -0
  699. package/dist/internal/replication/outbox.js.map +1 -0
  700. package/dist/internal/replication/overlay-layers.d.ts +14 -0
  701. package/dist/internal/replication/overlay-layers.d.ts.map +1 -0
  702. package/dist/internal/replication/overlay-layers.js +2 -0
  703. package/dist/internal/replication/overlay-layers.js.map +1 -0
  704. package/dist/internal/replication/overlay-records.d.ts +61 -0
  705. package/dist/internal/replication/overlay-records.d.ts.map +1 -0
  706. package/dist/internal/replication/overlay-records.js +328 -0
  707. package/dist/internal/replication/overlay-records.js.map +1 -0
  708. package/dist/internal/replication/overlay.d.ts +20 -0
  709. package/dist/internal/replication/overlay.d.ts.map +1 -0
  710. package/dist/internal/replication/overlay.js +159 -0
  711. package/dist/internal/replication/overlay.js.map +1 -0
  712. package/dist/internal/replication/projection-binding.d.ts +39 -0
  713. package/dist/internal/replication/projection-binding.d.ts.map +1 -0
  714. package/dist/internal/replication/projection-binding.js +76 -0
  715. package/dist/internal/replication/projection-binding.js.map +1 -0
  716. package/dist/internal/replication/protocol.d.ts +633 -0
  717. package/dist/internal/replication/protocol.d.ts.map +1 -0
  718. package/dist/internal/replication/protocol.js +263 -0
  719. package/dist/internal/replication/protocol.js.map +1 -0
  720. package/dist/internal/replication/reconciliation.d.ts +64 -0
  721. package/dist/internal/replication/reconciliation.d.ts.map +1 -0
  722. package/dist/internal/replication/reconciliation.js +184 -0
  723. package/dist/internal/replication/reconciliation.js.map +1 -0
  724. package/dist/internal/replication/replica-gc.d.ts +42 -0
  725. package/dist/internal/replication/replica-gc.d.ts.map +1 -0
  726. package/dist/internal/replication/replica-gc.js +91 -0
  727. package/dist/internal/replication/replica-gc.js.map +1 -0
  728. package/dist/internal/replication/replica-integrity.d.ts +107 -0
  729. package/dist/internal/replication/replica-integrity.d.ts.map +1 -0
  730. package/dist/internal/replication/replica-integrity.js +418 -0
  731. package/dist/internal/replication/replica-integrity.js.map +1 -0
  732. package/dist/internal/replication/replica-lifecycle.d.ts +72 -0
  733. package/dist/internal/replication/replica-lifecycle.d.ts.map +1 -0
  734. package/dist/internal/replication/replica-lifecycle.js +126 -0
  735. package/dist/internal/replication/replica-lifecycle.js.map +1 -0
  736. package/dist/internal/replication/replica-schema.d.ts +27 -0
  737. package/dist/internal/replication/replica-schema.d.ts.map +1 -0
  738. package/dist/internal/replication/replica-schema.js +130 -0
  739. package/dist/internal/replication/replica-schema.js.map +1 -0
  740. package/dist/internal/replication/route-slot.d.ts +9 -0
  741. package/dist/internal/replication/route-slot.d.ts.map +1 -0
  742. package/dist/internal/replication/route-slot.js +8 -0
  743. package/dist/internal/replication/route-slot.js.map +1 -0
  744. package/dist/internal/replication/server-identity.d.ts +54 -0
  745. package/dist/internal/replication/server-identity.d.ts.map +1 -0
  746. package/dist/internal/replication/server-identity.js +68 -0
  747. package/dist/internal/replication/server-identity.js.map +1 -0
  748. package/dist/internal/replication/session.d.ts +91 -0
  749. package/dist/internal/replication/session.d.ts.map +1 -0
  750. package/dist/internal/replication/session.js +673 -0
  751. package/dist/internal/replication/session.js.map +1 -0
  752. package/dist/internal/replication/state.d.ts +34 -0
  753. package/dist/internal/replication/state.d.ts.map +1 -0
  754. package/dist/internal/replication/state.js +344 -0
  755. package/dist/internal/replication/state.js.map +1 -0
  756. package/dist/internal/replication/submission.d.ts +115 -0
  757. package/dist/internal/replication/submission.d.ts.map +1 -0
  758. package/dist/internal/replication/submission.js +266 -0
  759. package/dist/internal/replication/submission.js.map +1 -0
  760. package/dist/internal/replication/transport.d.ts +34 -0
  761. package/dist/internal/replication/transport.d.ts.map +1 -0
  762. package/dist/internal/replication/transport.js +215 -0
  763. package/dist/internal/replication/transport.js.map +1 -0
  764. package/dist/internal/runtime-boundaries.d.ts +8 -0
  765. package/dist/internal/runtime-boundaries.d.ts.map +1 -0
  766. package/dist/internal/runtime-boundaries.js +7 -0
  767. package/dist/internal/runtime-boundaries.js.map +1 -0
  768. package/dist/internal/storage/index.d.ts +111 -0
  769. package/dist/internal/storage/index.d.ts.map +1 -0
  770. package/dist/internal/storage/index.js +288 -0
  771. package/dist/internal/storage/index.js.map +1 -0
  772. package/dist/internal/storage/memory.d.ts +31 -0
  773. package/dist/internal/storage/memory.d.ts.map +1 -0
  774. package/dist/internal/storage/memory.js +46 -0
  775. package/dist/internal/storage/memory.js.map +1 -0
  776. package/dist/internal/storage/revisions.d.ts +24 -0
  777. package/dist/internal/storage/revisions.d.ts.map +1 -0
  778. package/dist/internal/storage/revisions.js +74 -0
  779. package/dist/internal/storage/revisions.js.map +1 -0
  780. package/dist/internal/test-hooks.d.ts +47 -0
  781. package/dist/internal/test-hooks.d.ts.map +1 -0
  782. package/dist/internal/test-hooks.js +256 -0
  783. package/dist/internal/test-hooks.js.map +1 -0
  784. package/dist/internal/transactor/env.d.ts +3 -0
  785. package/dist/internal/transactor/env.d.ts.map +1 -0
  786. package/dist/internal/transactor/env.js +5 -0
  787. package/dist/internal/transactor/env.js.map +1 -0
  788. package/dist/internal/transactor/errors.d.ts +47 -0
  789. package/dist/internal/transactor/errors.d.ts.map +1 -0
  790. package/dist/internal/transactor/errors.js +66 -0
  791. package/dist/internal/transactor/errors.js.map +1 -0
  792. package/dist/internal/transactor/host.d.ts +37 -0
  793. package/dist/internal/transactor/host.d.ts.map +1 -0
  794. package/dist/internal/transactor/host.js +11 -0
  795. package/dist/internal/transactor/host.js.map +1 -0
  796. package/dist/internal/transactor/index.d.ts +8 -0
  797. package/dist/internal/transactor/index.d.ts.map +1 -0
  798. package/dist/internal/transactor/index.js +8 -0
  799. package/dist/internal/transactor/index.js.map +1 -0
  800. package/dist/internal/transactor/indexer.d.ts +53 -0
  801. package/dist/internal/transactor/indexer.d.ts.map +1 -0
  802. package/dist/internal/transactor/indexer.js +125 -0
  803. package/dist/internal/transactor/indexer.js.map +1 -0
  804. package/dist/internal/transactor/internal.d.ts +8 -0
  805. package/dist/internal/transactor/internal.d.ts.map +1 -0
  806. package/dist/internal/transactor/internal.js +28 -0
  807. package/dist/internal/transactor/internal.js.map +1 -0
  808. package/dist/internal/transactor/observability.d.ts +44 -0
  809. package/dist/internal/transactor/observability.d.ts.map +1 -0
  810. package/dist/internal/transactor/observability.js +39 -0
  811. package/dist/internal/transactor/observability.js.map +1 -0
  812. package/dist/internal/transactor/transactor-do.d.ts +35 -0
  813. package/dist/internal/transactor/transactor-do.d.ts.map +1 -0
  814. package/dist/internal/transactor/transactor-do.js +198 -0
  815. package/dist/internal/transactor/transactor-do.js.map +1 -0
  816. package/dist/internal/transactor/transactor.d.ts +209 -0
  817. package/dist/internal/transactor/transactor.d.ts.map +1 -0
  818. package/dist/internal/transactor/transactor.js +1166 -0
  819. package/dist/internal/transactor/transactor.js.map +1 -0
  820. package/dist/mcp/contract.d.ts +49 -0
  821. package/dist/mcp/contract.d.ts.map +1 -0
  822. package/dist/mcp/contract.js +199 -0
  823. package/dist/mcp/contract.js.map +1 -0
  824. package/dist/mcp/kernel.d.ts +56 -0
  825. package/dist/mcp/kernel.d.ts.map +1 -0
  826. package/dist/mcp/kernel.js +344 -0
  827. package/dist/mcp/kernel.js.map +1 -0
  828. package/dist/mcp/server.d.ts +8 -0
  829. package/dist/mcp/server.d.ts.map +1 -0
  830. package/dist/mcp/server.js +182 -0
  831. package/dist/mcp/server.js.map +1 -0
  832. package/dist/peer.d.ts +175 -0
  833. package/dist/peer.d.ts.map +1 -0
  834. package/dist/peer.js +200 -0
  835. package/dist/peer.js.map +1 -0
  836. package/dist/react/hooks.d.ts +157 -0
  837. package/dist/react/hooks.d.ts.map +1 -0
  838. package/dist/react/hooks.js +130 -0
  839. package/dist/react/hooks.js.map +1 -0
  840. package/dist/react/index.d.ts +4 -0
  841. package/dist/react/index.d.ts.map +1 -0
  842. package/dist/react/index.js +2 -0
  843. package/dist/react/index.js.map +1 -0
  844. package/dist/react/query-state.d.ts +60 -0
  845. package/dist/react/query-state.d.ts.map +1 -0
  846. package/dist/react/query-state.js +48 -0
  847. package/dist/react/query-state.js.map +1 -0
  848. package/dist/react/receipt-state.d.ts +27 -0
  849. package/dist/react/receipt-state.d.ts.map +1 -0
  850. package/dist/react/receipt-state.js +2 -0
  851. package/dist/react/receipt-state.js.map +1 -0
  852. package/dist/react/store.d.ts +30 -0
  853. package/dist/react/store.d.ts.map +1 -0
  854. package/dist/react/store.js +118 -0
  855. package/dist/react/store.js.map +1 -0
  856. package/dist/react/suspense.d.ts +6 -0
  857. package/dist/react/suspense.d.ts.map +1 -0
  858. package/dist/react/suspense.js +111 -0
  859. package/dist/react/suspense.js.map +1 -0
  860. package/dist/worker/admit.d.ts +9 -0
  861. package/dist/worker/admit.d.ts.map +1 -0
  862. package/dist/worker/admit.js +43 -0
  863. package/dist/worker/admit.js.map +1 -0
  864. package/dist/worker/analytics.d.ts +39 -0
  865. package/dist/worker/analytics.d.ts.map +1 -0
  866. package/dist/worker/analytics.js +54 -0
  867. package/dist/worker/analytics.js.map +1 -0
  868. package/dist/worker/auth.d.ts +26 -0
  869. package/dist/worker/auth.d.ts.map +1 -0
  870. package/dist/worker/auth.js +2 -0
  871. package/dist/worker/auth.js.map +1 -0
  872. package/dist/worker/authorized-live.d.ts +15 -0
  873. package/dist/worker/authorized-live.d.ts.map +1 -0
  874. package/dist/worker/authorized-live.js +30 -0
  875. package/dist/worker/authorized-live.js.map +1 -0
  876. package/dist/worker/authorized-operation.d.ts +30 -0
  877. package/dist/worker/authorized-operation.d.ts.map +1 -0
  878. package/dist/worker/authorized-operation.js +304 -0
  879. package/dist/worker/authorized-operation.js.map +1 -0
  880. package/dist/worker/authorized-read.d.ts +32 -0
  881. package/dist/worker/authorized-read.d.ts.map +1 -0
  882. package/dist/worker/authorized-read.js +194 -0
  883. package/dist/worker/authorized-read.js.map +1 -0
  884. package/dist/worker/authorized-replication.d.ts +21 -0
  885. package/dist/worker/authorized-replication.d.ts.map +1 -0
  886. package/dist/worker/authorized-replication.js +593 -0
  887. package/dist/worker/authorized-replication.js.map +1 -0
  888. package/dist/worker/changesets.d.ts +9 -0
  889. package/dist/worker/changesets.d.ts.map +1 -0
  890. package/dist/worker/changesets.js +105 -0
  891. package/dist/worker/changesets.js.map +1 -0
  892. package/dist/worker/demo.d.ts +2 -0
  893. package/dist/worker/demo.d.ts.map +1 -0
  894. package/dist/worker/demo.js +85 -0
  895. package/dist/worker/demo.js.map +1 -0
  896. package/dist/worker/errors.d.ts +53 -0
  897. package/dist/worker/errors.d.ts.map +1 -0
  898. package/dist/worker/errors.js +107 -0
  899. package/dist/worker/errors.js.map +1 -0
  900. package/dist/worker/handle.d.ts +21 -0
  901. package/dist/worker/handle.d.ts.map +1 -0
  902. package/dist/worker/handle.js +386 -0
  903. package/dist/worker/handle.js.map +1 -0
  904. package/dist/worker/index.d.ts +27 -0
  905. package/dist/worker/index.d.ts.map +1 -0
  906. package/dist/worker/index.js +24 -0
  907. package/dist/worker/index.js.map +1 -0
  908. package/dist/worker/jwt.d.ts +23 -0
  909. package/dist/worker/jwt.d.ts.map +1 -0
  910. package/dist/worker/jwt.js +288 -0
  911. package/dist/worker/jwt.js.map +1 -0
  912. package/dist/worker/mcp.d.ts +17 -0
  913. package/dist/worker/mcp.d.ts.map +1 -0
  914. package/dist/worker/mcp.js +151 -0
  915. package/dist/worker/mcp.js.map +1 -0
  916. package/dist/worker/operation-catalogs.d.ts +38 -0
  917. package/dist/worker/operation-catalogs.d.ts.map +1 -0
  918. package/dist/worker/operation-catalogs.js +114 -0
  919. package/dist/worker/operation-catalogs.js.map +1 -0
  920. package/dist/worker/peer.d.ts +70 -0
  921. package/dist/worker/peer.d.ts.map +1 -0
  922. package/dist/worker/peer.js +330 -0
  923. package/dist/worker/peer.js.map +1 -0
  924. package/dist/worker/public-observation.d.ts +15 -0
  925. package/dist/worker/public-observation.d.ts.map +1 -0
  926. package/dist/worker/public-observation.js +111 -0
  927. package/dist/worker/public-observation.js.map +1 -0
  928. package/dist/worker/server-identity.d.ts +2 -0
  929. package/dist/worker/server-identity.d.ts.map +1 -0
  930. package/dist/worker/server-identity.js +2 -0
  931. package/dist/worker/server-identity.js.map +1 -0
  932. package/dist/worker/session-sync.d.ts +27 -0
  933. package/dist/worker/session-sync.d.ts.map +1 -0
  934. package/dist/worker/session-sync.js +4 -0
  935. package/dist/worker/session-sync.js.map +1 -0
  936. package/dist/worker/session.d.ts +144 -0
  937. package/dist/worker/session.d.ts.map +1 -0
  938. package/dist/worker/session.js +408 -0
  939. package/dist/worker/session.js.map +1 -0
  940. package/dist/worker/storage-test-admin.d.ts +3 -0
  941. package/dist/worker/storage-test-admin.d.ts.map +1 -0
  942. package/dist/worker/storage-test-admin.js +277 -0
  943. package/dist/worker/storage-test-admin.js.map +1 -0
  944. package/dist/worker/test-admin.d.ts +11 -0
  945. package/dist/worker/test-admin.d.ts.map +1 -0
  946. package/dist/worker/test-admin.js +432 -0
  947. package/dist/worker/test-admin.js.map +1 -0
  948. package/dist/worker/testing.d.ts +14 -0
  949. package/dist/worker/testing.d.ts.map +1 -0
  950. package/dist/worker/testing.js +71 -0
  951. package/dist/worker/testing.js.map +1 -0
  952. package/dist/workerEntry.d.ts +2 -0
  953. package/dist/workerEntry.d.ts.map +1 -0
  954. package/dist/workerEntry.js +10 -0
  955. package/dist/workerEntry.js.map +1 -0
  956. package/dist/writes.d.ts +8 -0
  957. package/dist/writes.d.ts.map +1 -0
  958. package/dist/writes.js +11 -0
  959. package/dist/writes.js.map +1 -0
  960. package/package.json +102 -4
@@ -0,0 +1,1166 @@
1
+ import { ChangesetService, decodeChangesetCommand } from "../changesets/service.js";
2
+ import { changesetConflict, changesetSubject } from "../authorization/changesets.js";
3
+ import { Connection, TxError, bootstrapDatoms, decodeLogChunk, emptyRoots, encodeLogChunk, fromJson, gzipCodec, toJson, txFrame, FIRST_USER_EID, Histogram, RateMeter, componentLogger, toWireDatom, VALUE_TYPE_IDENTS, } from "../core/index.js";
4
+ import { InvalidRequest, OperationRejected, TxRejected, Unauthorized, } from "../../db/Errors.js";
5
+ import { R2NodeStore, readCurrentRoot, recordToRoots, rootsToRecord } from "../storage/index.js";
6
+ import * as Effect from "effect/Effect";
7
+ import { BadRequest, NotFound, TransactorDeadError, Unavailable, errorResponse, toHttpError } from "./errors.js";
8
+ import {} from "./host.js";
9
+ import { Indexer } from "./indexer.js";
10
+ import { TxMetrics } from "./observability.js";
11
+ import { inertRuntimeBoundaries, } from "../runtime-boundaries.js";
12
+ import { allocationMappingsResolvable, authorizeCatalogOperation, authorizeCatalogOperationGrant, authorizeCatalogOperationReplay, catalogProvisioningAttributes, decideEpoch, decideInvocationReceipt, deployedOperationInputWireShape, deployedOperationOutputWireShape, deployedOperationVersion, executeCatalogOperation, inputEntityRefHandles, invocationReceiptOutcome, isLegacyInvocationReceiptRow, OperationRuntimeFault, opaqueOperationDenial, outputEntityRefPaths, parseEntityIdScope, parseInvocationAllocations, parseStoredInvocationReceipt, prepareInvocationReceipt, requireSuppliedOperationVersion, resolveOperationCatalog, resolveSealedInputRefs, resolveSealedTarget, transitionInvocationReceipt, } from "../authorization/index.js";
13
+ export { TransactorDeadError };
14
+ function asPrincipal(x) {
15
+ if (typeof x !== "object" || x === null || Array.isArray(x))
16
+ return undefined;
17
+ const o = x;
18
+ if (o.kind !== "user" || typeof o.class !== "string")
19
+ return undefined;
20
+ const claims = typeof o.claims === "object" && o.claims !== null
21
+ ? o.claims
22
+ : {};
23
+ const classes = Array.isArray(o.classes)
24
+ ? o.classes.filter((c) => typeof c === "string")
25
+ : undefined;
26
+ return {
27
+ kind: "user",
28
+ class: o.class,
29
+ claims,
30
+ ...(typeof o.sub === "string" ? { sub: o.sub } : {}),
31
+ ...(typeof o.eid === "number" ? { eid: o.eid } : {}),
32
+ ...(classes !== undefined && classes.length > 0 ? { classes } : {}),
33
+ };
34
+ }
35
+ const RECENT_CLIENT_TX_LIMIT = 256;
36
+ export function clientTxReplayKey(principal, id) {
37
+ if (!principal)
38
+ return `\0:${id}`;
39
+ const who = principal.sub ?? (principal.eid !== undefined ? `#${principal.eid}` : principal.class);
40
+ return `${principal.kind}\0${who}\0${id}`;
41
+ }
42
+ const yieldToEventLoop = () => new Promise((r) => setTimeout(r, 0));
43
+ const round = (x) => Math.round(x * 100) / 100;
44
+ const safeName = (host) => {
45
+ try {
46
+ return host.dbName;
47
+ }
48
+ catch {
49
+ return undefined;
50
+ }
51
+ };
52
+ const json = (body, status = 200, headers = {}) => new Response(JSON.stringify(toJson(body)), { status, headers: { "content-type": "application/json", ...headers } });
53
+ export class Transactor {
54
+ host;
55
+ operationRuntime;
56
+ boundaries;
57
+ ready;
58
+ conn;
59
+ store;
60
+ rootRecord;
61
+ logWatermark = 0;
62
+ queue = [];
63
+ committing = false;
64
+ indexer;
65
+ txSinceIndex = 0;
66
+ dead;
67
+ recentAcks = new Map();
68
+ stats = { txs: 0, batches: 0, maxBatch: 0, rejected: 0, indexRuns: 0, broadcasts: 0, commitMs: 0, resolveMs: 0, loopMs: 0, fenceMs: 0 };
69
+ txRate = new RateMeter(10_000);
70
+ batchSizes = new Histogram([1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]);
71
+ commitLatency = new Histogram();
72
+ resolveLatency = new Histogram();
73
+ loopLatency = new Histogram();
74
+ fenceLatency = new Histogram();
75
+ metrics;
76
+ log;
77
+ deployedComposition;
78
+ constructor(host, operationRuntime, boundaries = inertRuntimeBoundaries) {
79
+ this.host = host;
80
+ this.operationRuntime = operationRuntime;
81
+ this.boundaries = boundaries;
82
+ this.log = componentLogger("transactor", () => ({ db: safeName(host) }));
83
+ this.metrics = new TxMetrics(host.analytics);
84
+ }
85
+ bindComposition(unitHash, index) {
86
+ const current = this.deployedComposition;
87
+ if (current !== undefined) {
88
+ if (current.unitHash !== unitHash) {
89
+ throw new TxError("cannot change deployed catalog composition", "tx/system");
90
+ }
91
+ return;
92
+ }
93
+ this.deployedComposition = { unitHash, index };
94
+ if (this.conn !== undefined)
95
+ this.conn.bindComposition(index);
96
+ }
97
+ init() {
98
+ if (!this.ready)
99
+ this.ready = this.boot();
100
+ return this.ready;
101
+ }
102
+ async boot() {
103
+ const sql = this.host.sql;
104
+ this.proposalService.initialize();
105
+ sql.exec(`CREATE TABLE IF NOT EXISTS log (t INTEGER PRIMARY KEY, tx_instant INTEGER NOT NULL, datoms BLOB NOT NULL)`);
106
+ sql.exec(`CREATE TABLE IF NOT EXISTS meta (k TEXT PRIMARY KEY, v TEXT NOT NULL)`);
107
+ sql.exec(`CREATE TABLE IF NOT EXISTS operation_receipts (
108
+ principal_id TEXT NOT NULL,
109
+ invocation_id TEXT NOT NULL,
110
+ status TEXT NOT NULL,
111
+ receipt TEXT NOT NULL,
112
+ PRIMARY KEY (principal_id, invocation_id)
113
+ )`);
114
+ this.store = new R2NodeStore(this.host.bucket, { codec: gzipCodec, maxNodes: 4096 });
115
+ let rec = this.getMeta("root") ?? (await readCurrentRoot(this.host.bucket));
116
+ if (!rec) {
117
+ const roots = await emptyRoots(this.store);
118
+ const fresh = rootsToRecord(roots, { log_watermark: 0, next_eid: FIRST_USER_EID, codec: gzipCodec.name });
119
+ const boot = bootstrapDatoms();
120
+ this.host.transactionSync(() => {
121
+ this.appendLogRow({ t: 1, txInstant: this.host.now(), datoms: boot });
122
+ this.setMeta("root", fresh);
123
+ this.setMeta("next_eid", FIRST_USER_EID);
124
+ });
125
+ rec = fresh;
126
+ }
127
+ this.rootRecord = rec;
128
+ this.logWatermark = rec.log_watermark;
129
+ const roots = recordToRoots(rec);
130
+ const nextEid = this.getMeta("next_eid") ?? rec.next_eid;
131
+ const logDatoms = this.readLogDatoms(roots.t);
132
+ this.conn = await Connection.restore(this.store, roots, logDatoms, nextEid, {
133
+ now: () => this.host.now(),
134
+ ...(this.deployedComposition === undefined
135
+ ? {}
136
+ : { composition: this.deployedComposition.index }),
137
+ });
138
+ if (this.deployedComposition !== undefined) {
139
+ this.conn.bindComposition(this.deployedComposition.index);
140
+ }
141
+ this.txSinceIndex = Math.max(0, this.conn.t - roots.t);
142
+ const c = this.host.config;
143
+ this.indexer = new Indexer(this, {
144
+ intervalMs: c.indexIntervalMs,
145
+ txThreshold: c.indexTxThreshold,
146
+ maxTxsPerRun: c.indexMaxTxsPerRun,
147
+ logKeepTxs: c.logKeepTxs,
148
+ gcEveryN: c.gcEveryNIndexes,
149
+ retainRoots: c.retainRoots,
150
+ }, this.boundaries);
151
+ if (this.conn.t > roots.t)
152
+ await this.indexer.schedule();
153
+ await this.proposalService.schedule();
154
+ this.log.info("boot", { t: this.conn.t, rootT: roots.t, novelty: this.conn.noveltyCount, nextEid: this.conn.nextEntityId, fresh: !this.getMeta("root") });
155
+ }
156
+ getMeta(k) {
157
+ const row = this.host.sql.exec(`SELECT v FROM meta WHERE k = ?`, k).toArray()[0];
158
+ return row ? JSON.parse(row.v) : undefined;
159
+ }
160
+ setMeta(k, v) {
161
+ this.host.sql.exec(`INSERT OR REPLACE INTO meta (k, v) VALUES (?, ?)`, k, JSON.stringify(v));
162
+ }
163
+ appendLogRow(e) {
164
+ const body = encodeLogChunk([e]);
165
+ const buf = body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength);
166
+ this.host.sql.exec(`INSERT INTO log (t, tx_instant, datoms) VALUES (?, ?, ?)`, e.t, e.txInstant, buf);
167
+ }
168
+ readInvocationReceipt(principalId, invocationId) {
169
+ const row = this.host.sql.exec(`SELECT status, receipt FROM operation_receipts
170
+ WHERE principal_id = ? AND invocation_id = ?`, principalId, invocationId).toArray()[0];
171
+ if (row === undefined)
172
+ return undefined;
173
+ const receipt = parseStoredInvocationReceipt(JSON.parse(row.receipt));
174
+ if (isLegacyInvocationReceiptRow(receipt))
175
+ return receipt;
176
+ if (row.status !== receipt.status) {
177
+ throw new TypeError("durable invocation receipt status mismatch");
178
+ }
179
+ return receipt;
180
+ }
181
+ insertInvocationReceipt(receipt) {
182
+ this.host.sql.exec(`INSERT INTO operation_receipts
183
+ (principal_id, invocation_id, status, receipt) VALUES (?, ?, ?, ?)`, receipt.principalId, receipt.invocationId, receipt.status, JSON.stringify(receipt));
184
+ }
185
+ replaceInvocationReceipt(receipt) {
186
+ this.host.sql.exec(`UPDATE operation_receipts SET status = ?, receipt = ?
187
+ WHERE principal_id = ? AND invocation_id = ?`, receipt.status, JSON.stringify(receipt), receipt.principalId, receipt.invocationId);
188
+ }
189
+ claimInvocationReceipt(prepared) {
190
+ return this.host.transactionSync(() => {
191
+ const stored = this.readInvocationReceipt(prepared.principalId, prepared.invocationId);
192
+ const decision = decideInvocationReceipt(stored, prepared);
193
+ if (decision._tag === "Claim") {
194
+ this.insertInvocationReceipt(decision.receipt);
195
+ }
196
+ else if (decision._tag === "Recover") {
197
+ this.replaceInvocationReceipt(decision.receipt);
198
+ }
199
+ return decision;
200
+ });
201
+ }
202
+ inspectInvocationReceipt(prepared) {
203
+ const stored = this.readInvocationReceipt(prepared.principalId, prepared.invocationId);
204
+ return decideInvocationReceipt(stored, prepared);
205
+ }
206
+ recoverInvocationReceipt(prepared) {
207
+ return this.host.transactionSync(() => {
208
+ const stored = this.readInvocationReceipt(prepared.principalId, prepared.invocationId);
209
+ const decision = decideInvocationReceipt(stored, prepared);
210
+ if (decision._tag === "Recover") {
211
+ this.replaceInvocationReceipt(decision.receipt);
212
+ }
213
+ return decision;
214
+ });
215
+ }
216
+ assertClaimIdentity(stored, claim) {
217
+ if (stored === undefined || isLegacyInvocationReceiptRow(stored) ||
218
+ stored.status !== "claimed" || stored.version !== claim.version ||
219
+ stored.principalId !== claim.principalId ||
220
+ stored.invocationId !== claim.invocationId ||
221
+ stored.scopeDigest !== claim.scopeDigest ||
222
+ stored.operationVersion !== claim.operationVersion ||
223
+ stored.invocationDigest !== claim.invocationDigest) {
224
+ throw new Error("durable invocation claim changed before completion");
225
+ }
226
+ }
227
+ finishInvocationReceipt(claim, event, insideTransaction = false) {
228
+ const finish = () => {
229
+ const stored = this.readInvocationReceipt(claim.principalId, claim.invocationId);
230
+ this.assertClaimIdentity(stored, claim);
231
+ const terminal = transitionInvocationReceipt(stored, event);
232
+ this.replaceInvocationReceipt(terminal);
233
+ return terminal;
234
+ };
235
+ return insideTransaction ? finish() : this.host.transactionSync(finish);
236
+ }
237
+ readLogEntries(from, to = Number.MAX_SAFE_INTEGER, limit = 100_000) {
238
+ const rows = this.host.sql.exec(`SELECT t, tx_instant, datoms FROM log WHERE t > ? AND t <= ? ORDER BY t LIMIT ?`, from, to, limit).toArray();
239
+ const out = [];
240
+ for (const r of rows) {
241
+ const raw = r.datoms;
242
+ const buf = raw instanceof Uint8Array ? raw : new Uint8Array(raw);
243
+ const [entry] = decodeLogChunk(buf);
244
+ out.push(entry);
245
+ }
246
+ return out;
247
+ }
248
+ readLogDatoms(afterT) {
249
+ const out = [];
250
+ for (const e of this.readLogEntries(afterT))
251
+ for (const d of e.datoms)
252
+ out.push(d);
253
+ return out;
254
+ }
255
+ earliestLogT() {
256
+ const row = this.host.sql.exec(`SELECT MIN(t) AS t FROM log`).toArray()[0];
257
+ return row?.t ?? 0;
258
+ }
259
+ pruneLog(throughT) {
260
+ const before = this.host.sql.exec(`SELECT COUNT(*) AS n FROM log WHERE t <= ?`, throughT).toArray()[0].n;
261
+ this.host.sql.exec(`DELETE FROM log WHERE t <= ?`, throughT);
262
+ return before;
263
+ }
264
+ get connection() {
265
+ return this.conn;
266
+ }
267
+ get nodeStore() {
268
+ return this.store;
269
+ }
270
+ get bucket() {
271
+ return this.host.bucket;
272
+ }
273
+ get currentRootRecord() {
274
+ return this.rootRecord;
275
+ }
276
+ get watermark() {
277
+ return this.logWatermark;
278
+ }
279
+ get t() {
280
+ return this.conn.t;
281
+ }
282
+ get txsSinceIndex() {
283
+ return this.txSinceIndex;
284
+ }
285
+ get isDead() {
286
+ return this.dead !== undefined;
287
+ }
288
+ adoptRoot(rec) {
289
+ this.rootRecord = rec;
290
+ this.logWatermark = rec.log_watermark;
291
+ this.setMeta("root", rec);
292
+ this.txSinceIndex = Math.max(0, this.conn.t - rec.t);
293
+ this.stats.indexRuns++;
294
+ this.broadcast({ v: 1, kind: "root", root: rec });
295
+ }
296
+ transact(tx, principal, clientTxId, extras) {
297
+ if (this.dead !== undefined)
298
+ return Promise.reject(new TransactorDeadError(this.dead));
299
+ if (clientTxId !== undefined) {
300
+ const key = clientTxReplayKey(principal, clientTxId);
301
+ const hit = this.recentAcks.get(key);
302
+ if (hit)
303
+ return Promise.resolve(hit);
304
+ }
305
+ return new Promise((resolve, reject) => {
306
+ this.queue.push({
307
+ tx,
308
+ principal,
309
+ clientTxId,
310
+ system: extras?.system || undefined,
311
+ resolve: resolve,
312
+ reject,
313
+ });
314
+ if (!this.committing) {
315
+ this.committing = true;
316
+ void this.commitLoop();
317
+ }
318
+ });
319
+ }
320
+ replayableMappings(receipt, context) {
321
+ if (receipt.status !== "completed" || receipt.allocations === undefined) {
322
+ return true;
323
+ }
324
+ if (context === undefined)
325
+ return false;
326
+ return allocationMappingsResolvable(receipt.allocations, {
327
+ keyId: context.sealing.keyId,
328
+ scope: context.scope,
329
+ });
330
+ }
331
+ decideInvocationEpoch(p, inputHandles) {
332
+ const operation = p.operation;
333
+ if (!this.usesOpaqueHandles(operation, inputHandles)) {
334
+ return { _tag: "Agreed", context: undefined };
335
+ }
336
+ const scope = operation.entityIdScope;
337
+ const keyId = operation.entityIdKeyId;
338
+ if (p.sealing === undefined || scope === undefined || keyId === undefined) {
339
+ throw opaqueOperationDenial();
340
+ }
341
+ const decision = decideEpoch({ keyId, scope }, p.sealing);
342
+ if (decision._tag === "UpdateRequired")
343
+ return decision;
344
+ return {
345
+ _tag: "Agreed",
346
+ context: { sealing: decision.sealing, scope: decision.scope },
347
+ };
348
+ }
349
+ usesOpaqueHandles(invocation, inputHandles) {
350
+ return invocation.sealedTarget !== undefined ||
351
+ (invocation.allocations !== undefined && invocation.allocations.length > 0) ||
352
+ inputHandles.length > 0;
353
+ }
354
+ needsSealingKey(invocation) {
355
+ return invocation.sealedTarget !== undefined ||
356
+ (invocation.allocations !== undefined && invocation.allocations.length > 0) ||
357
+ invocation.entityIdScope !== undefined;
358
+ }
359
+ async resolveInvocationTarget(p, context) {
360
+ const invocation = p.operation;
361
+ if (invocation.sealedTarget === undefined)
362
+ return invocation;
363
+ if (invocation.target !== undefined)
364
+ throw opaqueOperationDenial();
365
+ if (context === undefined)
366
+ throw opaqueOperationDenial();
367
+ const resolution = await resolveSealedTarget(context.sealing, context.scope, invocation.sealedTarget);
368
+ if (resolution._tag === "UpdateRequired")
369
+ return undefined;
370
+ if (resolution._tag === "Denied")
371
+ throw opaqueOperationDenial();
372
+ return Object.freeze({ ...invocation, target: resolution.eid });
373
+ }
374
+ async resolveInvocationInput(invocation, context, inputHandles) {
375
+ if (inputHandles.length === 0)
376
+ return invocation;
377
+ if (context === undefined)
378
+ throw opaqueOperationDenial();
379
+ const resolution = await resolveSealedInputRefs(context.sealing, context.scope, invocation.input, inputHandles);
380
+ if (resolution._tag === "UpdateRequired")
381
+ return undefined;
382
+ if (resolution._tag === "Denied")
383
+ throw opaqueOperationDenial();
384
+ return Object.freeze({ ...invocation, input: resolution.input });
385
+ }
386
+ async invoke(invocation) {
387
+ if (this.dead !== undefined)
388
+ throw new TransactorDeadError(this.dead);
389
+ const runtime = this.operationRuntime;
390
+ if (runtime === undefined)
391
+ throw opaqueOperationDenial();
392
+ let sealing;
393
+ if (this.needsSealingKey(invocation)) {
394
+ if (runtime.sealing === undefined || invocation.entityIdScope === undefined) {
395
+ throw opaqueOperationDenial();
396
+ }
397
+ try {
398
+ sealing = await runtime.sealing();
399
+ }
400
+ catch (cause) {
401
+ const message = cause instanceof Error ? cause.message : String(cause);
402
+ this.log.error("operation.sealing-root-unavailable", { error: message });
403
+ throw new Unavailable({
404
+ message: "the server sealing root is momentarily unavailable",
405
+ retryAfterMs: 1_000,
406
+ });
407
+ }
408
+ }
409
+ return new Promise((resolve, reject) => {
410
+ this.queue.push({
411
+ tx: [],
412
+ operation: invocation,
413
+ ...(sealing === undefined ? {} : { sealing }),
414
+ resolve: resolve,
415
+ reject,
416
+ });
417
+ if (!this.committing) {
418
+ this.committing = true;
419
+ void this.commitLoop();
420
+ }
421
+ });
422
+ }
423
+ serialized(run) {
424
+ if (this.dead !== undefined)
425
+ return Promise.reject(new TransactorDeadError(this.dead));
426
+ return new Promise((resolve, reject) => {
427
+ this.queue.push({ reject, task: async () => {
428
+ try {
429
+ resolve(await run());
430
+ }
431
+ catch (cause) {
432
+ reject(cause);
433
+ }
434
+ } });
435
+ if (!this.committing) {
436
+ this.committing = true;
437
+ void this.commitLoop();
438
+ }
439
+ });
440
+ }
441
+ proposalHandler;
442
+ get proposalService() {
443
+ if (this.proposalHandler !== undefined)
444
+ return this.proposalHandler;
445
+ const owner = this;
446
+ return this.proposalHandler = new ChangesetService({
447
+ get sql() { return owner.host.sql; },
448
+ get database() { return safeName(owner.host) ?? ""; },
449
+ schedule: (deadline) => this.scheduleAlarm(deadline),
450
+ serialized: (run) => this.serialized(run),
451
+ current: () => this.conn,
452
+ checkpoint: () => this.boundaries.checkpoint("changeset.prepare"),
453
+ transactionSync: (run) => this.host.transactionSync(run),
454
+ reserve: (next) => this.setMeta("next_eid", next),
455
+ resolve: (operations, caller) => this.resolveChangesetOperations(operations, caller),
456
+ commit: async (entry, caller, persist) => {
457
+ const next = this.conn.fork();
458
+ next.applyDatoms(entry.datoms);
459
+ await this.boundaries.checkpoint("changeset.commit");
460
+ changesetSubject(caller, this.operationRuntime.now());
461
+ this.host.transactionSync(() => {
462
+ this.boundaries.checkpointSync("changeset.commit.write");
463
+ this.appendLogRow(entry);
464
+ this.setMeta("next_eid", next.nextEntityId);
465
+ persist();
466
+ });
467
+ this.conn.applyDatoms(entry.datoms);
468
+ this.txSinceIndex++;
469
+ this.stats.txs++;
470
+ this.broadcast(txFrame(entry));
471
+ await this.indexer.maybeSchedule();
472
+ },
473
+ });
474
+ }
475
+ async resolveChangesetOperations(rawOperations, caller) {
476
+ const runtime = this.operationRuntime;
477
+ const operations = [];
478
+ for (const raw of rawOperations) {
479
+ const invocation = { ...raw, caller };
480
+ if (invocation.database !== safeName(this.host))
481
+ throw opaqueOperationDenial();
482
+ const resolved = await Effect.runPromise(resolveOperationCatalog(runtime, invocation));
483
+ this.bindComposition(resolved.deployed.definition.unitHash, resolved.deployed.definition.composition);
484
+ const inputShape = deployedOperationInputWireShape(resolved, invocation.owner, invocation.localName);
485
+ if (inputShape === undefined)
486
+ throw opaqueOperationDenial();
487
+ const paths = inputEntityRefHandles(inputShape, invocation.input);
488
+ const sealing = this.needsSealingKey(invocation) ? await runtime.sealing?.() : undefined;
489
+ const pending = { operation: invocation, sealing };
490
+ const epoch = this.decideInvocationEpoch(pending, paths);
491
+ if (epoch._tag !== "Agreed")
492
+ throw changesetConflict("invocation_update_required");
493
+ const target = await this.resolveInvocationTarget(pending, epoch.context);
494
+ if (target === undefined)
495
+ throw changesetConflict("invocation_update_required");
496
+ const operation = await this.resolveInvocationInput(target, epoch.context, paths);
497
+ if (operation === undefined)
498
+ throw changesetConflict("invocation_update_required");
499
+ operations.push(operation);
500
+ }
501
+ return operations;
502
+ }
503
+ retainedRevisionRoots() { return this.proposalService.revisions.roots(); }
504
+ async changeset(command) {
505
+ const runtime = this.operationRuntime;
506
+ if (runtime === undefined)
507
+ throw opaqueOperationDenial();
508
+ if (command.action === "watch" || command.action === "list")
509
+ return this.proposalService.execute(this.conn, runtime, command);
510
+ if (command.action === "inspect" || command.action === "query" || command.action === "read") {
511
+ const snapshot = await this.serialized(async () => {
512
+ const stored = this.proposalService.load(command.id);
513
+ const release = stored?.baseRevision === undefined ? () => { } : this.proposalService.revisions.retain(stored.baseRevision);
514
+ return { connection: this.conn.fork(), stored, release };
515
+ });
516
+ try {
517
+ await this.boundaries.checkpoint("changeset.read");
518
+ return await this.proposalService.execute(snapshot.connection, runtime, command, snapshot);
519
+ }
520
+ finally {
521
+ snapshot.release();
522
+ }
523
+ }
524
+ if (command.action === "prepare" || command.action === "append")
525
+ return this.proposalService.execute(this.conn.fork(), runtime, command);
526
+ return this.serialized(() => this.proposalService.execute(this.conn, runtime, command));
527
+ }
528
+ async provisionCatalog(definition) {
529
+ await this.init();
530
+ this.bindComposition(definition.unitHash, definition.composition);
531
+ const attributes = catalogProvisioningAttributes(definition);
532
+ let missing = false;
533
+ for (const expected of attributes) {
534
+ const existing = this.conn.db().attr(expected[":db/ident"]);
535
+ if (existing === undefined) {
536
+ missing = true;
537
+ continue;
538
+ }
539
+ const expectedValueType = VALUE_TYPE_IDENTS[expected[":db/valueType"]];
540
+ const expectedUnique = expected[":db/unique"] === undefined
541
+ ? undefined
542
+ : expected[":db/unique"] === ":db.unique/identity"
543
+ ? "identity"
544
+ : "value";
545
+ const expectedCardinality = expected[":db/cardinality"] ===
546
+ ":db.cardinality/many"
547
+ ? "many"
548
+ : "one";
549
+ if (existing.valueType !== expectedValueType ||
550
+ existing.cardinality !== expectedCardinality ||
551
+ existing.unique !== expectedUnique ||
552
+ existing.index !== (expected[":db/index"] === true) ||
553
+ existing.isComponent !== (expected[":db/isComponent"] === true) ||
554
+ (existing.optional === true) !== (expected[":db/optional"] === true)) {
555
+ throw new TxError(`cannot provision incompatible deployed field ${expected[":db/ident"]}`, "tx/system");
556
+ }
557
+ }
558
+ if (!missing)
559
+ return this.conn.t;
560
+ const ack = await this.transact([...attributes], undefined, undefined, { system: true });
561
+ return ack.t;
562
+ }
563
+ async provision(principal) {
564
+ await this.init();
565
+ if (!principal)
566
+ return { eid: null, class: "" };
567
+ return { eid: principal.eid ?? null, class: principal.class };
568
+ }
569
+ rememberAck(id, ack) {
570
+ this.recentAcks.set(id, ack);
571
+ while (this.recentAcks.size > RECENT_CLIENT_TX_LIMIT) {
572
+ const first = this.recentAcks.keys().next().value;
573
+ if (first === undefined)
574
+ break;
575
+ this.recentAcks.delete(first);
576
+ }
577
+ }
578
+ invocationFailureEvent(error) {
579
+ let rejection;
580
+ if (error instanceof Unauthorized) {
581
+ rejection = { kind: "unauthorized" };
582
+ }
583
+ else if (error instanceof InvalidRequest) {
584
+ rejection = { kind: "invalid_request" };
585
+ }
586
+ else if (error instanceof OperationRejected) {
587
+ rejection = {
588
+ kind: "operation_rejected",
589
+ message: error.message,
590
+ operation: error.operation,
591
+ ...(error.step === undefined ? {} : { step: error.step }),
592
+ ...(error.reason === undefined ? {} : { reason: error.reason }),
593
+ };
594
+ }
595
+ else if (error instanceof TxRejected || error instanceof TxError) {
596
+ rejection = { kind: "request_rejected" };
597
+ }
598
+ return rejection === undefined
599
+ ? { _tag: "Fail" }
600
+ : { _tag: "Reject", rejection };
601
+ }
602
+ takeBatch() {
603
+ const batch = [];
604
+ const max = this.host.config.maxBatch;
605
+ while (this.queue.length > 0 && (max <= 0 || batch.length < max)) {
606
+ const next = this.queue[0];
607
+ if ("task" in next || (next.operation !== undefined && batch.length > 0))
608
+ break;
609
+ this.queue.shift();
610
+ batch.push(next);
611
+ if (next.operation !== undefined)
612
+ break;
613
+ }
614
+ return batch;
615
+ }
616
+ async commitLoop() {
617
+ try {
618
+ await this.init();
619
+ const fences = this.host.config.timingYields;
620
+ while (this.queue.length > 0 && this.dead === undefined) {
621
+ await yieldToEventLoop();
622
+ const next = this.queue[0];
623
+ if (next !== undefined && "task" in next) {
624
+ this.queue.shift();
625
+ await next.task();
626
+ continue;
627
+ }
628
+ let fenceMs = 0;
629
+ if (fences) {
630
+ const tFence = performance.now();
631
+ await yieldToEventLoop();
632
+ fenceMs = performance.now() - tFence;
633
+ this.stats.fenceMs += fenceMs;
634
+ this.fenceLatency.observe(fenceMs);
635
+ }
636
+ const queueDepth = this.queue.length;
637
+ const tLoop = performance.now();
638
+ const batch = this.takeBatch();
639
+ const entries = [];
640
+ const acks = [];
641
+ const batchAcks = new Map();
642
+ const tResolve = performance.now();
643
+ for (const p of batch) {
644
+ if (p.operation !== undefined) {
645
+ let claim;
646
+ try {
647
+ if (this.operationRuntime === undefined) {
648
+ throw opaqueOperationDenial();
649
+ }
650
+ const supplied = requireSuppliedOperationVersion(p.operation.operationVersion);
651
+ const resolved = await Effect.runPromise(resolveOperationCatalog(this.operationRuntime, p.operation));
652
+ this.bindComposition(resolved.deployed.definition.unitHash, resolved.deployed.definition.composition);
653
+ const operationVersion = deployedOperationVersion(resolved, p.operation.owner, p.operation.localName);
654
+ if (operationVersion === undefined)
655
+ throw opaqueOperationDenial();
656
+ const inputWireShape = deployedOperationInputWireShape(resolved, p.operation.owner, p.operation.localName);
657
+ if (inputWireShape === undefined)
658
+ throw opaqueOperationDenial();
659
+ const inputHandles = inputEntityRefHandles(inputWireShape, p.operation.input);
660
+ const outputWireShape = deployedOperationOutputWireShape(resolved, p.operation.owner, p.operation.localName);
661
+ const outcomeOf = (receipt) => {
662
+ const outcome = invocationReceiptOutcome(receipt);
663
+ if (outcome._tag !== "Completed" || outputWireShape === undefined) {
664
+ return outcome;
665
+ }
666
+ const outputRefPaths = outputEntityRefPaths(outputWireShape, outcome.output);
667
+ return outputRefPaths.length === 0
668
+ ? outcome
669
+ : { ...outcome, outputRefPaths };
670
+ };
671
+ const operationRuntime = this.operationRuntime;
672
+ const resolveCompatibility = async (tag) => {
673
+ await authorizeCatalogOperationGrant(this.conn, operationRuntime, p.operation, resolved);
674
+ this.stats.rejected++;
675
+ p.resolve({ _tag: tag });
676
+ };
677
+ if (supplied !== undefined && supplied !== operationVersion) {
678
+ await resolveCompatibility("OperationChanged");
679
+ continue;
680
+ }
681
+ const epoch = this.decideInvocationEpoch(p, inputHandles);
682
+ if (epoch._tag === "UpdateRequired") {
683
+ await resolveCompatibility("UpdateRequired");
684
+ continue;
685
+ }
686
+ const sealingContext = epoch.context;
687
+ const targeted = await this.resolveInvocationTarget(p, sealingContext);
688
+ if (targeted === undefined) {
689
+ await resolveCompatibility("UpdateRequired");
690
+ continue;
691
+ }
692
+ const operation = await this.resolveInvocationInput(targeted, sealingContext, inputHandles);
693
+ if (operation === undefined) {
694
+ await resolveCompatibility("UpdateRequired");
695
+ continue;
696
+ }
697
+ const prepared = await Effect.runPromise(prepareInvocationReceipt(operation, operationVersion));
698
+ const inspected = this.inspectInvocationReceipt(prepared);
699
+ if (inspected._tag === "OperationChanged" ||
700
+ inspected._tag === "UpdateRequired") {
701
+ await resolveCompatibility(inspected._tag);
702
+ continue;
703
+ }
704
+ if (inspected._tag === "Conflict") {
705
+ this.stats.rejected++;
706
+ p.resolve({ _tag: "Conflict" });
707
+ continue;
708
+ }
709
+ if (inspected._tag === "Recover") {
710
+ const recovered = this.recoverInvocationReceipt(prepared);
711
+ if (recovered._tag === "OperationChanged" ||
712
+ recovered._tag === "UpdateRequired") {
713
+ await resolveCompatibility(recovered._tag);
714
+ continue;
715
+ }
716
+ if (recovered._tag === "Conflict") {
717
+ this.stats.rejected++;
718
+ p.resolve({ _tag: "Conflict" });
719
+ continue;
720
+ }
721
+ if (recovered._tag === "Replay" || recovered._tag === "Recover") {
722
+ if (!this.replayableMappings(recovered.receipt, sealingContext)) {
723
+ await resolveCompatibility("UpdateRequired");
724
+ continue;
725
+ }
726
+ p.resolve(outcomeOf(recovered.receipt));
727
+ continue;
728
+ }
729
+ }
730
+ if (inspected._tag === "Replay") {
731
+ if (!this.replayableMappings(inspected.receipt, sealingContext)) {
732
+ await resolveCompatibility("UpdateRequired");
733
+ continue;
734
+ }
735
+ if (inspected.receipt.status === "completed") {
736
+ await authorizeCatalogOperationReplay(this.conn, this.operationRuntime, operation, inspected.receipt.replayFence, resolved);
737
+ }
738
+ else {
739
+ await authorizeCatalogOperation(this.conn, this.operationRuntime, operation, resolved);
740
+ }
741
+ p.resolve(outcomeOf(inspected.receipt));
742
+ continue;
743
+ }
744
+ const admission = await authorizeCatalogOperation(this.conn, this.operationRuntime, operation, resolved);
745
+ const decision = this.claimInvocationReceipt(prepared);
746
+ if (decision._tag === "Conflict" ||
747
+ decision._tag === "OperationChanged" ||
748
+ decision._tag === "UpdateRequired") {
749
+ this.stats.rejected++;
750
+ p.resolve({ _tag: decision._tag });
751
+ continue;
752
+ }
753
+ if (decision._tag === "Replay" || decision._tag === "Recover") {
754
+ if (!this.replayableMappings(decision.receipt, sealingContext)) {
755
+ await resolveCompatibility("UpdateRequired");
756
+ continue;
757
+ }
758
+ if (decision.receipt.status === "completed") {
759
+ await authorizeCatalogOperationReplay(this.conn, this.operationRuntime, operation, decision.receipt.replayFence, resolved);
760
+ }
761
+ p.resolve(outcomeOf(decision.receipt));
762
+ continue;
763
+ }
764
+ claim = decision.receipt;
765
+ await this.boundaries.checkpoint("operation.claimed");
766
+ const executed = await executeCatalogOperation(this.conn, this.operationRuntime, operation, resolved, admission, sealingContext?.sealing);
767
+ const rep = executed.report;
768
+ const event = {
769
+ _tag: "Complete",
770
+ committedT: rep.t,
771
+ output: executed.output,
772
+ replayFence: executed.replayFence,
773
+ ...(sealingContext === undefined ||
774
+ executed.allocations.length === 0
775
+ ? {}
776
+ : {
777
+ allocations: {
778
+ version: 1,
779
+ keyId: sealingContext.sealing.keyId,
780
+ scope: { ...sealingContext.scope },
781
+ entries: executed.allocations,
782
+ },
783
+ }),
784
+ };
785
+ const terminal = transitionInvocationReceipt(claim, event);
786
+ const txInstant = rep.txData[0]?.v;
787
+ entries.push({ t: rep.t, txInstant, datoms: rep.txData });
788
+ acks.push({
789
+ p,
790
+ ack: outcomeOf(terminal),
791
+ assertFresh: executed.assertFresh,
792
+ receiptCompletion: { claim, event },
793
+ });
794
+ }
795
+ catch (err) {
796
+ if (err instanceof OperationRuntimeFault) {
797
+ this.log.error("operation.failed", {
798
+ stage: err.stage,
799
+ error: err.detail instanceof Error
800
+ ? err.detail.message
801
+ : String(err.detail),
802
+ });
803
+ }
804
+ if (claim !== undefined) {
805
+ try {
806
+ const terminal = this.finishInvocationReceipt(claim, this.invocationFailureEvent(err));
807
+ this.stats.rejected++;
808
+ this.log.warn("operation.rejected", {
809
+ status: terminal.status,
810
+ });
811
+ p.resolve(invocationReceiptOutcome(terminal));
812
+ }
813
+ catch (storageError) {
814
+ this.die(`receipt write failed: ${storageError instanceof Error ? storageError.message : String(storageError)}`, storageError, [p]);
815
+ return;
816
+ }
817
+ }
818
+ else {
819
+ const e = this.scrub(err, p);
820
+ this.stats.rejected++;
821
+ this.log.warn("tx.rejected", {
822
+ code: e?.code,
823
+ error: e instanceof Error ? e.message : String(e),
824
+ });
825
+ p.reject(e);
826
+ }
827
+ }
828
+ continue;
829
+ }
830
+ if (p.clientTxId !== undefined) {
831
+ const key = clientTxReplayKey(p.principal, p.clientTxId);
832
+ const hit = this.recentAcks.get(key) ?? batchAcks.get(key);
833
+ if (hit) {
834
+ p.resolve(hit);
835
+ continue;
836
+ }
837
+ }
838
+ try {
839
+ if (!p.system)
840
+ await this.applyProvision(p, entries);
841
+ const tx = await this.authorize(p);
842
+ const rep = await this.conn.transact(tx);
843
+ const ack = {
844
+ t: rep.t,
845
+ txEid: rep.txEid,
846
+ tempids: rep.tempids,
847
+ datoms: await this.ackDatoms(rep.txData, p.principal),
848
+ ...(p.clientTxId !== undefined ? { clientTxId: p.clientTxId } : {}),
849
+ };
850
+ const txInstant = rep.txData[0]?.v;
851
+ entries.push({ t: rep.t, txInstant, datoms: rep.txData });
852
+ if (p.clientTxId !== undefined) {
853
+ batchAcks.set(clientTxReplayKey(p.principal, p.clientTxId), ack);
854
+ }
855
+ acks.push({ p, ack });
856
+ }
857
+ catch (err) {
858
+ if (err instanceof OperationRuntimeFault) {
859
+ this.log.error("operation.failed", {
860
+ stage: err.stage,
861
+ error: err.detail instanceof Error ? err.detail.message : String(err.detail),
862
+ });
863
+ }
864
+ const e = this.scrub(err, p);
865
+ this.stats.rejected++;
866
+ this.log.warn("tx.rejected", { code: e?.code, error: e instanceof Error ? e.message : String(e) });
867
+ p.reject(e);
868
+ }
869
+ }
870
+ if (fences)
871
+ await yieldToEventLoop();
872
+ const resolveMs = performance.now() - tResolve;
873
+ this.stats.resolveMs += resolveMs;
874
+ if (entries.length === 0)
875
+ continue;
876
+ const tWrite = performance.now();
877
+ try {
878
+ await this.boundaries.checkpoint("transactor.commit");
879
+ for (const pending of acks)
880
+ pending.assertFresh?.();
881
+ this.host.transactionSync(() => {
882
+ this.boundaries.checkpointSync("transactor.commit.write");
883
+ for (const e of entries)
884
+ this.appendLogRow(e);
885
+ this.setMeta("next_eid", this.conn.nextEntityId);
886
+ for (const pending of acks) {
887
+ if (pending.receiptCompletion !== undefined) {
888
+ this.finishInvocationReceipt(pending.receiptCompletion.claim, pending.receiptCompletion.event, true);
889
+ }
890
+ }
891
+ });
892
+ }
893
+ catch (err) {
894
+ this.die(`log write failed: ${err instanceof Error ? err.message : String(err)}`, err, acks.map((a) => a.p));
895
+ return;
896
+ }
897
+ if (fences)
898
+ await yieldToEventLoop();
899
+ const writeMs = performance.now() - tWrite;
900
+ this.stats.commitMs += writeMs;
901
+ this.stats.txs += entries.length;
902
+ this.stats.batches++;
903
+ if (entries.length > this.stats.maxBatch)
904
+ this.stats.maxBatch = entries.length;
905
+ this.txSinceIndex += entries.length;
906
+ this.txRate.mark(entries.length, this.host.now());
907
+ this.batchSizes.observe(entries.length);
908
+ this.commitLatency.observe(writeMs);
909
+ this.resolveLatency.observe(resolveMs);
910
+ this.log.debug("tx.commit", { t: this.conn.t, batch: entries.length, datoms: entries.reduce((n, e) => n + e.datoms.length, 0), writeMs: round(writeMs), queued: this.queue.length, txsSinceIndex: this.txSinceIndex });
911
+ for (const [id, ack] of batchAcks)
912
+ this.rememberAck(id, ack);
913
+ for (const a of acks) {
914
+ try {
915
+ a.assertFresh?.();
916
+ a.p.resolve(a.ack);
917
+ }
918
+ catch (err) {
919
+ this.stats.rejected++;
920
+ a.p.reject(err);
921
+ }
922
+ }
923
+ const loopMs = performance.now() - tLoop;
924
+ this.stats.loopMs += loopMs;
925
+ this.loopLatency.observe(loopMs);
926
+ this.metrics.batch({
927
+ db: safeName(this.host) ?? "unknown",
928
+ resolveMs,
929
+ commitMs: writeMs,
930
+ batchSize: entries.length,
931
+ queueDepth,
932
+ noveltyDatoms: this.conn.noveltyCount,
933
+ fenceMs,
934
+ txOk: entries.length,
935
+ txErr: batch.length - entries.length,
936
+ });
937
+ for (const e of entries)
938
+ this.broadcast(txFrame(e));
939
+ await this.indexer.maybeSchedule();
940
+ }
941
+ }
942
+ catch (err) {
943
+ this.die(`commit loop failed: ${err instanceof Error ? err.message : String(err)}`, err, []);
944
+ }
945
+ finally {
946
+ this.committing = false;
947
+ if (this.queue.length > 0 && this.dead === undefined) {
948
+ this.committing = true;
949
+ void this.commitLoop();
950
+ }
951
+ }
952
+ }
953
+ async applyProvision(_p, _entries) {
954
+ return;
955
+ }
956
+ async authorize(p) {
957
+ return p.tx;
958
+ }
959
+ async ackDatoms(datoms, _principal) {
960
+ return datoms.map(toWireDatom);
961
+ }
962
+ scrub(err, _p) {
963
+ return err;
964
+ }
965
+ die(reason, cause, inflight) {
966
+ if (this.dead !== undefined)
967
+ return;
968
+ this.dead = reason;
969
+ this.log.error("tx.aborted", { reason, inflight: inflight.length, queued: this.queue.length, t: this.conn?.t });
970
+ const err = cause instanceof Error ? cause : new TransactorDeadError(reason);
971
+ for (const p of inflight)
972
+ p.reject(err);
973
+ for (const p of this.queue)
974
+ p.reject(new TransactorDeadError(reason));
975
+ this.queue = [];
976
+ this.host.abort(reason);
977
+ }
978
+ broadcast(frame) {
979
+ this.proposalHandler?.notify();
980
+ const msg = JSON.stringify(frame);
981
+ this.stats.broadcasts++;
982
+ for (const ws of this.host.sockets()) {
983
+ try {
984
+ ws.send(msg);
985
+ }
986
+ catch {
987
+ }
988
+ }
989
+ }
990
+ onSubscribe(ws, from) {
991
+ ws.send(JSON.stringify({ v: 1, kind: "hello", t: this.conn.t, root: this.rootRecord }));
992
+ this.sendCatchUp(ws, Number.isFinite(from) ? from : 0);
993
+ this.log.info("subscriber.connect", { from, t: this.conn.t, subscribers: this.host.sockets().length });
994
+ }
995
+ onSocketMessage(ws, message) {
996
+ if (typeof message !== "string")
997
+ return;
998
+ let msg;
999
+ try {
1000
+ msg = JSON.parse(message);
1001
+ }
1002
+ catch {
1003
+ return;
1004
+ }
1005
+ if (msg?.kind === "resume" && typeof msg.from === "number")
1006
+ this.sendCatchUp(ws, msg.from);
1007
+ else if (msg?.kind === "ping")
1008
+ ws.send(JSON.stringify({ v: 1, kind: "pong", t: this.conn.t }));
1009
+ }
1010
+ sendCatchUp(ws, from) {
1011
+ const t = this.conn.t;
1012
+ if (from >= t)
1013
+ return;
1014
+ const earliest = this.earliestLogT();
1015
+ if (earliest === 0 || earliest > from + 1) {
1016
+ ws.send(JSON.stringify({ v: 1, kind: "gap", from: Math.max(from, earliest - 1) }));
1017
+ this.log.warn("subscriber.gap", { from, earliestLogT: earliest, t });
1018
+ from = Math.max(from, earliest - 1);
1019
+ }
1020
+ for (const e of this.readLogEntries(from, t))
1021
+ ws.send(JSON.stringify(txFrame(e)));
1022
+ }
1023
+ alarmQueue = Promise.resolve();
1024
+ scheduleAlarm(deadline) {
1025
+ const next = this.alarmQueue.then(async () => {
1026
+ const existing = await this.host.getAlarm();
1027
+ if (existing === null || deadline < existing)
1028
+ await this.host.setAlarm(deadline);
1029
+ });
1030
+ this.alarmQueue = next.catch(() => { });
1031
+ return next;
1032
+ }
1033
+ async onAlarm() {
1034
+ await this.init();
1035
+ await this.serialized(async () => this.proposalService.expire(this.host.now()));
1036
+ await this.indexer.onAlarm();
1037
+ await this.proposalService.schedule();
1038
+ }
1039
+ info() {
1040
+ return {
1041
+ t: this.conn.t,
1042
+ root: this.rootRecord,
1043
+ novelty: this.conn.noveltyCount,
1044
+ txsSinceIndex: this.txSinceIndex,
1045
+ logWatermark: this.logWatermark,
1046
+ earliestLogT: this.earliestLogT(),
1047
+ nextEid: this.conn.nextEntityId,
1048
+ subscribers: this.host.sockets().length,
1049
+ opts: { timingYields: this.host.config.timingYields, maxBatch: this.host.config.maxBatch },
1050
+ stats: this.stats,
1051
+ metrics: {
1052
+ txPerSec: round(this.txRate.rate(this.host.now())),
1053
+ batchSize: this.batchSizes.snapshot(),
1054
+ commitMs: this.commitLatency.snapshot(),
1055
+ avgBatch: this.stats.batches ? round(this.stats.txs / this.stats.batches) : 0,
1056
+ resolveMs: round(this.stats.resolveMs),
1057
+ loopMs: round(this.stats.loopMs),
1058
+ batchResolveMs: this.resolveLatency.snapshot(),
1059
+ batchCommitMs: this.commitLatency.snapshot(),
1060
+ batchLoopMs: this.loopLatency.snapshot(),
1061
+ fenceMs: this.fenceLatency.snapshot(),
1062
+ noveltyDatoms: this.conn.noveltyCount,
1063
+ queueDepth: this.queue.length,
1064
+ ...this.metrics.snapshot(),
1065
+ },
1066
+ store: this.store.stats,
1067
+ indexer: this.indexer.status(),
1068
+ };
1069
+ }
1070
+ operationReceiptCount() {
1071
+ const row = this.host.sql.exec(`SELECT COUNT(*) AS count FROM operation_receipts`).toArray()[0];
1072
+ return Number(row?.count ?? 0);
1073
+ }
1074
+ async handleRequest(request) {
1075
+ await this.init();
1076
+ this.metrics.observeColo(request.cf?.colo ?? request.headers.get("x-ramose-colo") ?? undefined);
1077
+ const url = new URL(request.url);
1078
+ return Effect.runPromise(Effect.tryPromise({ try: () => this.route(request, url), catch: toHttpError }).pipe(Effect.catchTags({
1079
+ TxRejected: (e) => Effect.sync(() => errorResponse(e)),
1080
+ Unauthorized: (e) => Effect.sync(() => errorResponse(e)),
1081
+ OperationRejected: (e) => Effect.sync(() => errorResponse(e)),
1082
+ TransactorDead: (e) => Effect.sync(() => errorResponse(e)),
1083
+ Unavailable: (e) => Effect.sync(() => errorResponse(e)),
1084
+ BadRequest: (e) => Effect.sync(() => errorResponse(e)),
1085
+ NotFound: (e) => Effect.sync(() => errorResponse(e)),
1086
+ Internal: (e) => Effect.sync(() => errorResponse(e)),
1087
+ })));
1088
+ }
1089
+ async route(request, url) {
1090
+ const path = url.pathname;
1091
+ if (path === "/changesets" && request.method === "POST") {
1092
+ let command;
1093
+ try {
1094
+ command = decodeChangesetCommand(await request.json());
1095
+ }
1096
+ catch {
1097
+ throw new BadRequest({ message: "invalid changeset command" });
1098
+ }
1099
+ return json(await this.changeset(command));
1100
+ }
1101
+ if (path === "/invoke" && request.method === "POST") {
1102
+ const body = await request.json();
1103
+ const raw = body?.invocation;
1104
+ const invocation = typeof raw === "object" && raw !== null && !Array.isArray(raw)
1105
+ ? {
1106
+ ...raw,
1107
+ ...(Object.hasOwn(raw, "target")
1108
+ ? { target: fromJson(raw.target) }
1109
+ : {}),
1110
+ }
1111
+ : undefined;
1112
+ if (invocation === undefined || invocation.database !== safeName(this.host)) {
1113
+ throw new BadRequest({ message: "invalid deployed operation invocation" });
1114
+ }
1115
+ const entityIdScope = parseEntityIdScope(invocation.entityIdScope);
1116
+ const allocations = parseInvocationAllocations(invocation.allocations);
1117
+ if (allocations === undefined ||
1118
+ (invocation.sealedTarget !== undefined &&
1119
+ (typeof invocation.sealedTarget !== "string" ||
1120
+ entityIdScope === undefined)) ||
1121
+ (allocations.length > 0 && entityIdScope === undefined)) {
1122
+ throw new BadRequest({ message: "invalid deployed operation invocation" });
1123
+ }
1124
+ if (entityIdScope !== undefined &&
1125
+ (typeof invocation.entityIdKeyId !== "string" ||
1126
+ invocation.entityIdKeyId.length === 0)) {
1127
+ throw new BadRequest({ message: "invalid deployed operation invocation" });
1128
+ }
1129
+ const resolved = {
1130
+ ...invocation,
1131
+ ...(entityIdScope === undefined ? {} : { entityIdScope }),
1132
+ ...(allocations.length === 0 ? {} : { allocations }),
1133
+ };
1134
+ return new Response(JSON.stringify(await this.invoke(resolved)), {
1135
+ headers: { "content-type": "application/json" },
1136
+ });
1137
+ }
1138
+ if (path === "/transact" && request.method === "POST") {
1139
+ const body = fromJson(await request.json());
1140
+ if (!body || !Array.isArray(body.tx))
1141
+ throw new BadRequest({ message: "body must be { tx: [...] }" });
1142
+ const clientTxId = typeof body.clientTxId === "string" && body.clientTxId.length > 0 ? body.clientTxId : undefined;
1143
+ const ack = await this.transact(body.tx, asPrincipal(body.principal), clientTxId);
1144
+ return json(ack);
1145
+ }
1146
+ if (path === "/provision" && request.method === "POST") {
1147
+ const body = fromJson(await request.json());
1148
+ return json(await this.provision(asPrincipal(body?.principal)));
1149
+ }
1150
+ if (path === "/info")
1151
+ return json(this.info());
1152
+ if (path === "/log") {
1153
+ const from = Number(url.searchParams.get("from") ?? "0");
1154
+ const to = Number(url.searchParams.get("to") ?? String(Number.MAX_SAFE_INTEGER));
1155
+ const entries = this.readLogEntries(from, to, 10_000);
1156
+ const frames = entries.map(txFrame);
1157
+ return json({ from, to, earliestLogT: this.earliestLogT(), t: this.conn.t, entries: frames });
1158
+ }
1159
+ if (path === "/admin/index" && request.method === "POST")
1160
+ return json(await this.indexer.runNow());
1161
+ if (path === "/admin/gc" && request.method === "POST")
1162
+ return json(await this.indexer.gcNow());
1163
+ throw new NotFound({ message: "not found" });
1164
+ }
1165
+ }
1166
+ //# sourceMappingURL=transactor.js.map