@sixb/core 0.1.12 → 0.1.14

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 (538) hide show
  1. package/dist/actions/index.d.ts +2 -2
  2. package/dist/actions/index.d.ts.map +1 -1
  3. package/dist/actions/index.js +28 -26
  4. package/dist/actions/index.js.map +1 -1
  5. package/dist/actions/read-facade.d.ts +14 -16
  6. package/dist/actions/read-facade.d.ts.map +1 -1
  7. package/dist/actions/request.d.ts.map +1 -1
  8. package/dist/actions/run-dispatch.d.ts +2 -0
  9. package/dist/actions/run-dispatch.d.ts.map +1 -1
  10. package/dist/actions/types/context.d.ts +18 -31
  11. package/dist/actions/types/context.d.ts.map +1 -1
  12. package/dist/actions/types/params.d.ts +2 -1
  13. package/dist/actions/types/params.d.ts.map +1 -1
  14. package/dist/actions/worker.js +1 -1
  15. package/dist/agents/index.js +41 -39
  16. package/dist/agents/index.js.map +1 -1
  17. package/dist/agents/streams/index.js +2 -2
  18. package/dist/agents/streams/internal.js +2 -2
  19. package/dist/assert-never.d.ts +6 -0
  20. package/dist/assert-never.d.ts.map +1 -0
  21. package/dist/auth/client-address.d.ts +3 -0
  22. package/dist/auth/client-address.d.ts.map +1 -0
  23. package/dist/auth/csrf.d.ts +5 -1
  24. package/dist/auth/csrf.d.ts.map +1 -1
  25. package/dist/auth/errors.d.ts +12 -0
  26. package/dist/auth/errors.d.ts.map +1 -1
  27. package/dist/auth/index.d.ts +4 -3
  28. package/dist/auth/index.d.ts.map +1 -1
  29. package/dist/auth/index.js +16 -8
  30. package/dist/auth/index.js.map +1 -1
  31. package/dist/auth/runtime.d.ts +58 -41
  32. package/dist/auth/runtime.d.ts.map +1 -1
  33. package/dist/auth/session-cache.d.ts +10 -3
  34. package/dist/auth/session-cache.d.ts.map +1 -1
  35. package/dist/auth/sessions.d.ts +12 -0
  36. package/dist/auth/sessions.d.ts.map +1 -1
  37. package/dist/auth/strategy.d.ts +2 -0
  38. package/dist/auth/strategy.d.ts.map +1 -1
  39. package/dist/auth/strategy.js +4 -2
  40. package/dist/auth/strategy.js.map +1 -1
  41. package/dist/auth/types.d.ts +16 -15
  42. package/dist/auth/types.d.ts.map +1 -1
  43. package/dist/authorization/index.js +3 -3
  44. package/dist/bootstrap/index.d.ts +1 -1
  45. package/dist/bootstrap/index.d.ts.map +1 -1
  46. package/dist/bootstrap/index.js +45 -43
  47. package/dist/bootstrap/index.js.map +1 -1
  48. package/dist/bootstrap/ontology-type-manifest.d.ts +8 -0
  49. package/dist/bootstrap/ontology-type-manifest.d.ts.map +1 -1
  50. package/dist/{chunk-m7cx05vp.js → chunk-00pfcqh4.js} +126 -59
  51. package/dist/{chunk-m7cx05vp.js.map → chunk-00pfcqh4.js.map} +13 -12
  52. package/dist/{chunk-nzsy3xrp.js → chunk-16jenmzw.js} +69 -44
  53. package/dist/{chunk-nzsy3xrp.js.map → chunk-16jenmzw.js.map} +7 -7
  54. package/dist/{chunk-y3ev53cq.js → chunk-2fv8sajb.js} +2 -2
  55. package/dist/{chunk-q5gz3g2j.js → chunk-2jntasmh.js} +13 -16
  56. package/dist/{chunk-q5gz3g2j.js.map → chunk-2jntasmh.js.map} +3 -3
  57. package/dist/chunk-3a338wrp.js +191 -0
  58. package/dist/chunk-3a338wrp.js.map +11 -0
  59. package/dist/{chunk-ybhz3j9g.js → chunk-3fpgxpsq.js} +104 -148
  60. package/dist/{chunk-ybhz3j9g.js.map → chunk-3fpgxpsq.js.map} +7 -8
  61. package/dist/{chunk-eyjzgav0.js → chunk-3nx8vj5a.js} +6 -4
  62. package/dist/chunk-3nx8vj5a.js.map +12 -0
  63. package/dist/{chunk-5tetw4hn.js → chunk-4tnrzqqh.js} +1 -1
  64. package/dist/{chunk-3ghw2t5q.js → chunk-4ypbe95r.js} +10 -16
  65. package/dist/chunk-4ypbe95r.js.map +10 -0
  66. package/dist/{chunk-2cxv584m.js → chunk-6rzb1g6h.js} +358 -248
  67. package/dist/chunk-6rzb1g6h.js.map +44 -0
  68. package/dist/{chunk-7zgecwy1.js → chunk-6x0pqh32.js} +12 -1
  69. package/dist/{chunk-7zgecwy1.js.map → chunk-6x0pqh32.js.map} +3 -3
  70. package/dist/{chunk-6ma8dvzc.js → chunk-728fp090.js} +49 -42
  71. package/dist/chunk-728fp090.js.map +15 -0
  72. package/dist/chunk-96yw3pwd.js.map +2 -2
  73. package/dist/{chunk-4k53sm9e.js → chunk-a0073121.js} +59 -59
  74. package/dist/{chunk-4k53sm9e.js.map → chunk-a0073121.js.map} +5 -5
  75. package/dist/{chunk-y1ahv8b7.js → chunk-bdhfn0ww.js} +1 -1
  76. package/dist/{chunk-kept9cdd.js → chunk-bxx3ms5t.js} +1 -1
  77. package/dist/{chunk-xtfryrfb.js → chunk-cbn96bve.js} +2 -2
  78. package/dist/{chunk-vsg0g7h9.js → chunk-d8yes9yx.js} +304 -45
  79. package/dist/chunk-d8yes9yx.js.map +20 -0
  80. package/dist/{chunk-vpxss818.js → chunk-drz59ve0.js} +9 -8
  81. package/dist/chunk-drz59ve0.js.map +10 -0
  82. package/dist/{chunk-7c2g3sz9.js → chunk-dsfw1bdr.js} +5 -5
  83. package/dist/{chunk-7c2g3sz9.js.map → chunk-dsfw1bdr.js.map} +1 -1
  84. package/dist/{chunk-qm535afa.js → chunk-dv4ct8mp.js} +66 -24
  85. package/dist/chunk-dv4ct8mp.js.map +15 -0
  86. package/dist/{chunk-t7dzd1tm.js → chunk-e2c5yxfe.js} +2 -2
  87. package/dist/{chunk-p6r1ex7t.js → chunk-ffwvdgk1.js} +5 -13
  88. package/dist/chunk-ffwvdgk1.js.map +10 -0
  89. package/dist/{chunk-tg4g4zh0.js → chunk-gct3m1da.js} +9 -9
  90. package/dist/{chunk-tg4g4zh0.js.map → chunk-gct3m1da.js.map} +3 -3
  91. package/dist/chunk-h89wz928.js +42 -0
  92. package/dist/chunk-h89wz928.js.map +10 -0
  93. package/dist/{chunk-b768c93y.js → chunk-hj0n3c2p.js} +83 -28
  94. package/dist/{chunk-b768c93y.js.map → chunk-hj0n3c2p.js.map} +5 -5
  95. package/dist/{chunk-hkw8rykk.js → chunk-ht4a7mjg.js} +74 -4
  96. package/dist/chunk-ht4a7mjg.js.map +15 -0
  97. package/dist/{chunk-7qnvhtcd.js → chunk-hxgj4kzd.js} +17 -17
  98. package/dist/{chunk-7qnvhtcd.js.map → chunk-hxgj4kzd.js.map} +5 -5
  99. package/dist/{chunk-bg2bs62d.js → chunk-jfdggg1p.js} +5 -5
  100. package/dist/{chunk-f06sf7rr.js → chunk-k4kkp58d.js} +18 -5
  101. package/dist/chunk-k4kkp58d.js.map +11 -0
  102. package/dist/{chunk-e1f1sqba.js → chunk-kxea54yg.js} +3 -3
  103. package/dist/{chunk-2h63nrde.js → chunk-ky7zpbtt.js} +5 -7
  104. package/dist/{chunk-2h63nrde.js.map → chunk-ky7zpbtt.js.map} +3 -4
  105. package/dist/chunk-m4ehq95f.js +9 -0
  106. package/dist/chunk-m4ehq95f.js.map +10 -0
  107. package/dist/{chunk-0mza4xb2.js → chunk-m8zkvep1.js} +2 -2
  108. package/dist/{chunk-xn686q2e.js → chunk-ma1mhh7w.js} +75 -57
  109. package/dist/{chunk-xn686q2e.js.map → chunk-ma1mhh7w.js.map} +3 -3
  110. package/dist/{chunk-yxb4c62x.js → chunk-mr60an99.js} +3 -2
  111. package/dist/{chunk-yxb4c62x.js.map → chunk-mr60an99.js.map} +3 -3
  112. package/dist/{chunk-g50nxqs5.js → chunk-pvgpckm1.js} +63 -20
  113. package/dist/chunk-pvgpckm1.js.map +20 -0
  114. package/dist/{chunk-jjwhy3rs.js → chunk-q2xghyft.js} +5 -5
  115. package/dist/chunk-rdghfsss.js.map +2 -2
  116. package/dist/{chunk-bbaa1fet.js → chunk-rzcjp5m2.js} +7 -3
  117. package/dist/chunk-rzcjp5m2.js.map +25 -0
  118. package/dist/{chunk-hzw7yv5g.js → chunk-rzkr70gr.js} +5 -1
  119. package/dist/{chunk-hzw7yv5g.js.map → chunk-rzkr70gr.js.map} +3 -3
  120. package/dist/{chunk-axndsymr.js → chunk-tw03bsmb.js} +2 -2
  121. package/dist/{chunk-axndsymr.js.map → chunk-tw03bsmb.js.map} +3 -3
  122. package/dist/{chunk-y0v18c2j.js → chunk-vef6qa14.js} +2 -2
  123. package/dist/{chunk-gzt6v1ja.js → chunk-vn3yh259.js} +1 -1
  124. package/dist/{chunk-sfypc7mk.js → chunk-wn7mznxc.js} +4 -4
  125. package/dist/{chunk-r5zythxp.js → chunk-wnxabtn4.js} +7 -7
  126. package/dist/{chunk-4ph94nhd.js → chunk-ww185kt6.js} +2 -2
  127. package/dist/{chunk-3h7ctayx.js → chunk-xgptywp0.js} +4 -3
  128. package/dist/chunk-xgptywp0.js.map +11 -0
  129. package/dist/{chunk-gswwr35f.js → chunk-y487ywrv.js} +4 -4
  130. package/dist/{chunk-bet1rb9h.js → chunk-y6vnvayj.js} +1 -1
  131. package/dist/{chunk-x9tmx3fc.js → chunk-ypj2wqtj.js} +3 -6
  132. package/dist/{chunk-x9tmx3fc.js.map → chunk-ypj2wqtj.js.map} +4 -4
  133. package/dist/{chunk-3bnt2wna.js → chunk-yvf2jqj8.js} +1 -1
  134. package/dist/{chunk-g2gezsg5.js → chunk-z9h698s8.js} +1 -1
  135. package/dist/{chunk-wjffn5m4.js → chunk-zdkcdshk.js} +3 -36
  136. package/dist/{chunk-wjffn5m4.js.map → chunk-zdkcdshk.js.map} +3 -4
  137. package/dist/{chunk-bfjv1adk.js → chunk-znw0zvy4.js} +1 -1
  138. package/dist/edits/types.d.ts +19 -19
  139. package/dist/edits/types.d.ts.map +1 -1
  140. package/dist/error-reporting/internal.js +3 -3
  141. package/dist/errors/catalog.d.ts +4 -0
  142. package/dist/errors/catalog.d.ts.map +1 -1
  143. package/dist/errors/internal.js +1 -1
  144. package/dist/events/envelope.d.ts +0 -12
  145. package/dist/events/envelope.d.ts.map +1 -1
  146. package/dist/events/index.d.ts +1 -1
  147. package/dist/events/index.d.ts.map +1 -1
  148. package/dist/events/index.js +3 -3
  149. package/dist/events/service.d.ts +1 -2
  150. package/dist/events/service.d.ts.map +1 -1
  151. package/dist/events/toStoredEvent.d.ts +1 -2
  152. package/dist/events/toStoredEvent.d.ts.map +1 -1
  153. package/dist/events/types/index.d.ts +2 -1
  154. package/dist/events/types/index.d.ts.map +1 -1
  155. package/dist/execution/agent.d.ts +1 -2
  156. package/dist/execution/agent.d.ts.map +1 -1
  157. package/dist/execution/agent.js +39 -37
  158. package/dist/execution/agent.js.map +1 -1
  159. package/dist/execution/authorized-object-reader.d.ts.map +1 -1
  160. package/dist/execution/primitive.d.ts +1 -2
  161. package/dist/execution/primitive.d.ts.map +1 -1
  162. package/dist/execution/primitive.js +38 -36
  163. package/dist/execution/primitive.js.map +3 -3
  164. package/dist/execution/request.d.ts +1 -2
  165. package/dist/execution/request.d.ts.map +1 -1
  166. package/dist/execution/request.js +39 -37
  167. package/dist/execution/request.js.map +3 -3
  168. package/dist/index.d.ts +6 -6
  169. package/dist/index.d.ts.map +1 -1
  170. package/dist/index.js +56 -50
  171. package/dist/index.js.map +1 -1
  172. package/dist/maintenance/ontology-maintenance.d.ts +11 -1
  173. package/dist/maintenance/ontology-maintenance.d.ts.map +1 -1
  174. package/dist/materialization/errors.d.ts +3 -1
  175. package/dist/materialization/errors.d.ts.map +1 -1
  176. package/dist/materialization/events.d.ts +27 -2
  177. package/dist/materialization/events.d.ts.map +1 -1
  178. package/dist/materializer/edits/commit.d.ts.map +1 -1
  179. package/dist/materializer/edits/operations.d.ts +2 -1
  180. package/dist/materializer/edits/operations.d.ts.map +1 -1
  181. package/dist/materializer/edits/plan.d.ts +2 -2
  182. package/dist/materializer/edits/plan.d.ts.map +1 -1
  183. package/dist/materializer/edits/user-refs.d.ts +30 -0
  184. package/dist/materializer/edits/user-refs.d.ts.map +1 -0
  185. package/dist/materializer/effective/build-events.d.ts +2 -2
  186. package/dist/materializer/effective/build-events.d.ts.map +1 -1
  187. package/dist/materializer/execution/scope.d.ts +11 -3
  188. package/dist/materializer/execution/scope.d.ts.map +1 -1
  189. package/dist/materializer/index.js +23 -21
  190. package/dist/materializer/index.js.map +1 -1
  191. package/dist/materializer/projections/replacement-plan.d.ts +2 -0
  192. package/dist/materializer/projections/replacement-plan.d.ts.map +1 -1
  193. package/dist/materializer/telemetry/plan.d.ts +2 -2
  194. package/dist/materializer/telemetry/plan.d.ts.map +1 -1
  195. package/dist/models/execution/index.js +23 -21
  196. package/dist/models/execution/index.js.map +1 -1
  197. package/dist/models/index.js +1 -1
  198. package/dist/objects/execution.d.ts +21 -27
  199. package/dist/objects/execution.d.ts.map +1 -1
  200. package/dist/objects/index.js +28 -26
  201. package/dist/objects/index.js.map +1 -1
  202. package/dist/objects/query/executor.d.ts.map +1 -1
  203. package/dist/objects/query/index.js +27 -25
  204. package/dist/objects/query/index.js.map +1 -1
  205. package/dist/objects/query/ir.d.ts +8 -1
  206. package/dist/objects/query/ir.d.ts.map +1 -1
  207. package/dist/objects/query/scalar-values.d.ts.map +1 -1
  208. package/dist/objects/query/validate.d.ts.map +1 -1
  209. package/dist/objects/sdk/object-handle.d.ts +1 -2
  210. package/dist/objects/sdk/object-handle.d.ts.map +1 -1
  211. package/dist/objects/sdk/object-set.d.ts +2 -3
  212. package/dist/objects/sdk/object-set.d.ts.map +1 -1
  213. package/dist/objects/sdk/query-builder.d.ts +8 -10
  214. package/dist/objects/sdk/query-builder.d.ts.map +1 -1
  215. package/dist/objects/sdk/telemetry-channel.d.ts +1 -2
  216. package/dist/objects/sdk/telemetry-channel.d.ts.map +1 -1
  217. package/dist/objects/sdk/where.d.ts +2 -3
  218. package/dist/objects/sdk/where.d.ts.map +1 -1
  219. package/dist/ontology/builders.d.ts +11 -10
  220. package/dist/ontology/builders.d.ts.map +1 -1
  221. package/dist/ontology/index.d.ts +4 -2
  222. package/dist/ontology/index.d.ts.map +1 -1
  223. package/dist/ontology/index.js +6 -4
  224. package/dist/ontology/index.js.map +1 -1
  225. package/dist/ontology/inference/index.d.ts +34 -22
  226. package/dist/ontology/inference/index.d.ts.map +1 -1
  227. package/dist/ontology/internal.d.ts +1 -0
  228. package/dist/ontology/internal.d.ts.map +1 -1
  229. package/dist/ontology/internal.js +9 -7
  230. package/dist/ontology/internal.js.map +1 -1
  231. package/dist/ontology/primitives.d.ts +38 -0
  232. package/dist/ontology/primitives.d.ts.map +1 -0
  233. package/dist/ontology/query-capabilities.d.ts +38 -0
  234. package/dist/ontology/query-capabilities.d.ts.map +1 -0
  235. package/dist/ontology/refs.d.ts +23 -2
  236. package/dist/ontology/refs.d.ts.map +1 -1
  237. package/dist/ontology/registered.d.ts +16 -0
  238. package/dist/ontology/registered.d.ts.map +1 -0
  239. package/dist/ontology/registry.d.ts.map +1 -1
  240. package/dist/ontology/tokens.d.ts +35 -1
  241. package/dist/ontology/tokens.d.ts.map +1 -1
  242. package/dist/ontology/types.d.ts +18 -4
  243. package/dist/ontology/types.d.ts.map +1 -1
  244. package/dist/ontology/user-ref.d.ts +35 -0
  245. package/dist/ontology/user-ref.d.ts.map +1 -0
  246. package/dist/ontology/validation/definition.d.ts.map +1 -1
  247. package/dist/ontology/validation/index.d.ts +1 -1
  248. package/dist/ontology/validation/index.d.ts.map +1 -1
  249. package/dist/ontology/validation/normalize.d.ts.map +1 -1
  250. package/dist/ontology/validation/properties.d.ts +6 -1
  251. package/dist/ontology/validation/properties.d.ts.map +1 -1
  252. package/dist/ontology/validation/query.d.ts.map +1 -1
  253. package/dist/ontology/validation/schema.d.ts.map +1 -1
  254. package/dist/pipelines/index.js +26 -24
  255. package/dist/pipelines/index.js.map +1 -1
  256. package/dist/predicates/types.d.ts +53 -3
  257. package/dist/predicates/types.d.ts.map +1 -1
  258. package/dist/projections/builders.d.ts +19 -1
  259. package/dist/projections/builders.d.ts.map +1 -1
  260. package/dist/projections/internal.js +23 -21
  261. package/dist/projections/internal.js.map +1 -1
  262. package/dist/projections/validation.d.ts.map +1 -1
  263. package/dist/query.js +2 -2
  264. package/dist/queues/in-memory.d.ts +1 -1
  265. package/dist/queues/in-memory.d.ts.map +1 -1
  266. package/dist/runtime/create.d.ts +1 -1
  267. package/dist/runtime/create.d.ts.map +1 -1
  268. package/dist/runtime/host.d.ts +5 -5
  269. package/dist/runtime/host.d.ts.map +1 -1
  270. package/dist/runtime/index.d.ts +1 -1
  271. package/dist/runtime/index.d.ts.map +1 -1
  272. package/dist/runtime/internal.js +27 -25
  273. package/dist/runtime/internal.js.map +1 -1
  274. package/dist/runtime/sixb.d.ts +5 -5
  275. package/dist/runtime/sixb.d.ts.map +1 -1
  276. package/dist/runtime/types.d.ts +171 -188
  277. package/dist/runtime/types.d.ts.map +1 -1
  278. package/dist/sandboxes/index.js +5 -5
  279. package/dist/sandboxes/sandbox.d.ts +4 -1
  280. package/dist/sandboxes/sandbox.d.ts.map +1 -1
  281. package/dist/shared/params/types.d.ts +4 -3
  282. package/dist/shared/params/types.d.ts.map +1 -1
  283. package/dist/shared/params/user-refs.d.ts +19 -0
  284. package/dist/shared/params/user-refs.d.ts.map +1 -0
  285. package/dist/shares/compiler.d.ts.map +1 -1
  286. package/dist/shares/internal.js +24 -22
  287. package/dist/shares/internal.js.map +2 -2
  288. package/dist/storage/action-runs/failure.js +2 -2
  289. package/dist/storage/action-runs/types.d.ts +1 -1
  290. package/dist/storage/action-runs/types.d.ts.map +1 -1
  291. package/dist/storage/agents/provider.js +1 -1
  292. package/dist/storage/ai-limits/enforcement.js +2 -2
  293. package/dist/storage/auth/errors.d.ts +1 -1
  294. package/dist/storage/auth/errors.d.ts.map +1 -1
  295. package/dist/storage/auth/in-memory/access-tokens.d.ts.map +1 -1
  296. package/dist/storage/auth/in-memory/auth-storage.d.ts +2 -1
  297. package/dist/storage/auth/in-memory/auth-storage.d.ts.map +1 -1
  298. package/dist/storage/auth/in-memory/device-authorizations.d.ts.map +1 -1
  299. package/dist/storage/auth/in-memory/sessions.d.ts +8 -1
  300. package/dist/storage/auth/in-memory/sessions.d.ts.map +1 -1
  301. package/dist/storage/auth/in-memory/shared.d.ts.map +1 -1
  302. package/dist/storage/auth/index.d.ts +1 -1
  303. package/dist/storage/auth/index.d.ts.map +1 -1
  304. package/dist/storage/auth/types.d.ts +77 -20
  305. package/dist/storage/auth/types.d.ts.map +1 -1
  306. package/dist/storage/connector-connections/provider.js +1 -1
  307. package/dist/storage/executions/provider.js +1 -1
  308. package/dist/storage/file-upload-sessions/in-memory.d.ts +9 -18
  309. package/dist/storage/file-upload-sessions/in-memory.d.ts.map +1 -1
  310. package/dist/storage/file-upload-sessions/index.d.ts +1 -1
  311. package/dist/storage/file-upload-sessions/index.d.ts.map +1 -1
  312. package/dist/storage/file-upload-sessions/provider.d.ts +52 -0
  313. package/dist/storage/file-upload-sessions/provider.d.ts.map +1 -0
  314. package/dist/storage/file-upload-sessions/provider.js +24 -0
  315. package/dist/storage/file-upload-sessions/provider.js.map +9 -0
  316. package/dist/storage/file-upload-sessions/types.d.ts +19 -1
  317. package/dist/storage/file-upload-sessions/types.d.ts.map +1 -1
  318. package/dist/storage/file-upload-sessions/utils.d.ts +8 -2
  319. package/dist/storage/file-upload-sessions/utils.d.ts.map +1 -1
  320. package/dist/storage/index.d.ts +3 -3
  321. package/dist/storage/index.d.ts.map +1 -1
  322. package/dist/storage/index.js +29 -25
  323. package/dist/storage/index.js.map +1 -1
  324. package/dist/storage/internal.js +11 -9
  325. package/dist/storage/internal.js.map +1 -1
  326. package/dist/storage/objects/in-memory/query.d.ts.map +1 -1
  327. package/dist/storage/ontology/commits.d.ts +6 -2
  328. package/dist/storage/ontology/commits.d.ts.map +1 -1
  329. package/dist/storage/ontology/in-memory/materializations.d.ts.map +1 -1
  330. package/dist/storage/ontology/provider-work.d.ts.map +1 -1
  331. package/dist/storage/ontology/provider.d.ts +14 -1
  332. package/dist/storage/ontology/provider.d.ts.map +1 -1
  333. package/dist/storage/ontology/provider.js +8 -2
  334. package/dist/storage/ontology/provider.js.map +1 -1
  335. package/dist/storage/operation-scope.d.ts.map +1 -1
  336. package/dist/storage/operation-scope.js +1 -1
  337. package/dist/storage/projection-runs/provider.js +2 -2
  338. package/dist/storage/types.d.ts +1 -1
  339. package/dist/storage/types.d.ts.map +1 -1
  340. package/dist/storage/workflow-interventions/index.d.ts +1 -1
  341. package/dist/storage/workflow-interventions/index.d.ts.map +1 -1
  342. package/dist/storage/workflow-interventions/types.d.ts +5 -8
  343. package/dist/storage/workflow-interventions/types.d.ts.map +1 -1
  344. package/dist/storage/workflow-runs/provider.js +8 -8
  345. package/dist/syncs/index.js +27 -25
  346. package/dist/syncs/index.js.map +1 -1
  347. package/dist/testing/action-execution.d.ts +4 -0
  348. package/dist/testing/action-execution.d.ts.map +1 -1
  349. package/dist/testing/auth-storage-contract.d.ts.map +1 -1
  350. package/dist/testing/execution.d.ts +1 -2
  351. package/dist/testing/execution.d.ts.map +1 -1
  352. package/dist/testing/file-upload-session-storage-contract.d.ts +12 -0
  353. package/dist/testing/file-upload-session-storage-contract.d.ts.map +1 -0
  354. package/dist/testing/index.d.ts +2 -0
  355. package/dist/testing/index.d.ts.map +1 -1
  356. package/dist/testing/index.js +2035 -1358
  357. package/dist/testing/index.js.map +15 -13
  358. package/dist/testing/materializer-storage-contract.d.ts.map +1 -1
  359. package/dist/testing/object-query-contract.d.ts.map +1 -1
  360. package/dist/testing/ontology-contract-fixture.d.ts +8 -0
  361. package/dist/testing/ontology-contract-fixture.d.ts.map +1 -1
  362. package/dist/testing/ontology-storage-contract.d.ts.map +1 -1
  363. package/dist/testing/sandboxes-contract.d.ts.map +1 -1
  364. package/dist/testing/workflow-intervention-storage-contract.d.ts +8 -0
  365. package/dist/testing/workflow-intervention-storage-contract.d.ts.map +1 -0
  366. package/dist/webhooks/internal.js +24 -22
  367. package/dist/webhooks/internal.js.map +2 -2
  368. package/dist/webhooks/types.d.ts +2 -2
  369. package/dist/webhooks/types.d.ts.map +1 -1
  370. package/dist/workers/index.js +1 -1
  371. package/dist/workflows/index.js +42 -40
  372. package/dist/workflows/index.js.map +1 -1
  373. package/dist/workflows/run-dispatch.d.ts.map +1 -1
  374. package/dist/workflows/types.d.ts +2 -2
  375. package/dist/workflows/types.d.ts.map +1 -1
  376. package/package.json +7 -1
  377. package/src/actions/index.ts +0 -3
  378. package/src/actions/read-facade.ts +102 -62
  379. package/src/actions/request.ts +13 -0
  380. package/src/actions/run-dispatch.ts +3 -0
  381. package/src/actions/types/context.ts +17 -65
  382. package/src/actions/types/params.ts +2 -1
  383. package/src/agents/authority.ts +1 -1
  384. package/src/assert-never.ts +7 -0
  385. package/src/auth/client-address.ts +12 -0
  386. package/src/auth/csrf.ts +14 -5
  387. package/src/auth/errors.ts +23 -0
  388. package/src/auth/index.ts +4 -3
  389. package/src/auth/runtime.ts +353 -297
  390. package/src/auth/session-cache.ts +18 -6
  391. package/src/auth/sessions.ts +30 -0
  392. package/src/auth/strategy.ts +2 -0
  393. package/src/auth/types.ts +15 -17
  394. package/src/bootstrap/index.ts +1 -0
  395. package/src/bootstrap/ontology-type-manifest.ts +112 -60
  396. package/src/edits/types.ts +47 -63
  397. package/src/errors/catalog.ts +4 -0
  398. package/src/events/envelope.ts +0 -13
  399. package/src/events/index.ts +1 -1
  400. package/src/events/service.ts +1 -11
  401. package/src/events/toStoredEvent.ts +1 -3
  402. package/src/events/types/index.ts +1 -1
  403. package/src/execution/agent.ts +1 -2
  404. package/src/execution/authorized-object-reader.ts +5 -7
  405. package/src/execution/primitive.ts +1 -2
  406. package/src/execution/request.ts +1 -2
  407. package/src/index.ts +8 -7
  408. package/src/maintenance/ontology-maintenance.ts +77 -1
  409. package/src/materialization/errors.ts +2 -0
  410. package/src/materialization/events.ts +27 -2
  411. package/src/materializer/README.md +2 -0
  412. package/src/materializer/edits/commit.ts +21 -12
  413. package/src/materializer/edits/operations.ts +32 -4
  414. package/src/materializer/edits/plan.ts +4 -5
  415. package/src/materializer/edits/user-refs.ts +115 -0
  416. package/src/materializer/effective/build-events.ts +4 -5
  417. package/src/materializer/execution/scope.ts +40 -7
  418. package/src/materializer/projections/replace.ts +2 -0
  419. package/src/materializer/projections/replacement-plan.ts +4 -0
  420. package/src/materializer/telemetry/append.ts +4 -12
  421. package/src/materializer/telemetry/plan.ts +4 -5
  422. package/src/objects/execution.ts +33 -62
  423. package/src/objects/query/executor.ts +12 -3
  424. package/src/objects/query/ir.ts +7 -0
  425. package/src/objects/query/planner.ts +1 -0
  426. package/src/objects/query/scalar-values.ts +19 -0
  427. package/src/objects/query/validate.ts +55 -44
  428. package/src/objects/sdk/object-handle.ts +8 -8
  429. package/src/objects/sdk/object-set.ts +8 -15
  430. package/src/objects/sdk/query-builder.ts +59 -71
  431. package/src/objects/sdk/telemetry-channel.ts +6 -7
  432. package/src/objects/sdk/where.ts +6 -13
  433. package/src/ontology/builders.ts +15 -11
  434. package/src/ontology/index.ts +4 -0
  435. package/src/ontology/inference/index.ts +56 -36
  436. package/src/ontology/internal.ts +1 -0
  437. package/src/ontology/json-schema.ts +12 -0
  438. package/src/ontology/primitives.ts +91 -0
  439. package/src/ontology/query-capabilities.ts +136 -0
  440. package/src/ontology/refs.ts +33 -6
  441. package/src/ontology/registered.ts +22 -0
  442. package/src/ontology/registry.ts +6 -3
  443. package/src/ontology/tokens.ts +41 -2
  444. package/src/ontology/types.ts +19 -3
  445. package/src/ontology/user-ref.ts +120 -0
  446. package/src/ontology/validation/definition.ts +2 -13
  447. package/src/ontology/validation/index.ts +1 -0
  448. package/src/ontology/validation/normalize.ts +39 -3
  449. package/src/ontology/validation/properties.ts +95 -19
  450. package/src/ontology/validation/query.ts +11 -42
  451. package/src/ontology/validation/schema.ts +16 -0
  452. package/src/predicates/types.ts +43 -33
  453. package/src/projections/builders.ts +24 -3
  454. package/src/projections/validation.ts +15 -1
  455. package/src/runtime/create.ts +2 -2
  456. package/src/runtime/host.ts +10 -12
  457. package/src/runtime/index.ts +3 -2
  458. package/src/runtime/sixb.ts +13 -23
  459. package/src/runtime/types.ts +277 -479
  460. package/src/sandboxes/sandbox.ts +4 -1
  461. package/src/shared/params/types.ts +4 -3
  462. package/src/shared/params/user-refs.ts +48 -0
  463. package/src/shares/compiler.ts +6 -16
  464. package/src/storage/action-runs/types.ts +1 -0
  465. package/src/storage/auth/errors.ts +0 -1
  466. package/src/storage/auth/in-memory/access-tokens.ts +5 -2
  467. package/src/storage/auth/in-memory/auth-storage.ts +49 -73
  468. package/src/storage/auth/in-memory/device-authorizations.ts +0 -2
  469. package/src/storage/auth/in-memory/sessions.ts +69 -1
  470. package/src/storage/auth/in-memory/shared.ts +13 -7
  471. package/src/storage/auth/index.ts +2 -1
  472. package/src/storage/auth/types.ts +72 -20
  473. package/src/storage/executions/validation.ts +1 -1
  474. package/src/storage/file-upload-sessions/in-memory.ts +64 -113
  475. package/src/storage/file-upload-sessions/index.ts +1 -0
  476. package/src/storage/file-upload-sessions/provider.ts +258 -0
  477. package/src/storage/file-upload-sessions/types.ts +20 -1
  478. package/src/storage/file-upload-sessions/utils.ts +25 -9
  479. package/src/storage/index.ts +3 -2
  480. package/src/storage/objects/in-memory/query.ts +13 -3
  481. package/src/storage/ontology/commits.ts +6 -2
  482. package/src/storage/ontology/in-memory/materializations.ts +6 -34
  483. package/src/storage/ontology/provider-header-validation.ts +57 -0
  484. package/src/storage/ontology/provider-work.ts +15 -3
  485. package/src/storage/ontology/provider.ts +59 -1
  486. package/src/storage/operation-scope.ts +1 -0
  487. package/src/storage/types.ts +0 -1
  488. package/src/storage/workflow-interventions/index.ts +0 -1
  489. package/src/storage/workflow-interventions/types.ts +5 -9
  490. package/src/testing/action-execution.ts +13 -3
  491. package/src/testing/auth-storage-contract.ts +253 -192
  492. package/src/testing/execution-storage-contract.ts +1 -2
  493. package/src/testing/execution.ts +4 -7
  494. package/src/testing/file-upload-session-storage-contract.ts +335 -0
  495. package/src/testing/index.ts +8 -0
  496. package/src/testing/materializer-storage-contract.ts +86 -4
  497. package/src/testing/object-query-contract.ts +121 -2
  498. package/src/testing/ontology-contract-fixture.ts +23 -3
  499. package/src/testing/ontology-storage-contract.ts +58 -0
  500. package/src/testing/sandboxes-contract.ts +27 -0
  501. package/src/testing/workflow-intervention-storage-contract.ts +203 -0
  502. package/src/webhooks/types.ts +2 -2
  503. package/src/workflows/run-dispatch.ts +12 -1
  504. package/src/workflows/snapshot.ts +16 -7
  505. package/src/workflows/types.ts +2 -2
  506. package/dist/chunk-2cxv584m.js.map +0 -43
  507. package/dist/chunk-3ghw2t5q.js.map +0 -10
  508. package/dist/chunk-3h7ctayx.js.map +0 -11
  509. package/dist/chunk-6ma8dvzc.js.map +0 -15
  510. package/dist/chunk-bbaa1fet.js.map +0 -25
  511. package/dist/chunk-eyjzgav0.js.map +0 -12
  512. package/dist/chunk-f06sf7rr.js.map +0 -11
  513. package/dist/chunk-g50nxqs5.js.map +0 -18
  514. package/dist/chunk-hkw8rykk.js.map +0 -15
  515. package/dist/chunk-p6r1ex7t.js.map +0 -10
  516. package/dist/chunk-qm535afa.js.map +0 -15
  517. package/dist/chunk-vpxss818.js.map +0 -10
  518. package/dist/chunk-vsg0g7h9.js.map +0 -17
  519. /package/dist/{chunk-y3ev53cq.js.map → chunk-2fv8sajb.js.map} +0 -0
  520. /package/dist/{chunk-5tetw4hn.js.map → chunk-4tnrzqqh.js.map} +0 -0
  521. /package/dist/{chunk-y1ahv8b7.js.map → chunk-bdhfn0ww.js.map} +0 -0
  522. /package/dist/{chunk-kept9cdd.js.map → chunk-bxx3ms5t.js.map} +0 -0
  523. /package/dist/{chunk-xtfryrfb.js.map → chunk-cbn96bve.js.map} +0 -0
  524. /package/dist/{chunk-t7dzd1tm.js.map → chunk-e2c5yxfe.js.map} +0 -0
  525. /package/dist/{chunk-bg2bs62d.js.map → chunk-jfdggg1p.js.map} +0 -0
  526. /package/dist/{chunk-e1f1sqba.js.map → chunk-kxea54yg.js.map} +0 -0
  527. /package/dist/{chunk-0mza4xb2.js.map → chunk-m8zkvep1.js.map} +0 -0
  528. /package/dist/{chunk-jjwhy3rs.js.map → chunk-q2xghyft.js.map} +0 -0
  529. /package/dist/{chunk-y0v18c2j.js.map → chunk-vef6qa14.js.map} +0 -0
  530. /package/dist/{chunk-gzt6v1ja.js.map → chunk-vn3yh259.js.map} +0 -0
  531. /package/dist/{chunk-sfypc7mk.js.map → chunk-wn7mznxc.js.map} +0 -0
  532. /package/dist/{chunk-r5zythxp.js.map → chunk-wnxabtn4.js.map} +0 -0
  533. /package/dist/{chunk-4ph94nhd.js.map → chunk-ww185kt6.js.map} +0 -0
  534. /package/dist/{chunk-gswwr35f.js.map → chunk-y487ywrv.js.map} +0 -0
  535. /package/dist/{chunk-bet1rb9h.js.map → chunk-y6vnvayj.js.map} +0 -0
  536. /package/dist/{chunk-3bnt2wna.js.map → chunk-yvf2jqj8.js.map} +0 -0
  537. /package/dist/{chunk-g2gezsg5.js.map → chunk-z9h698s8.js.map} +0 -0
  538. /package/dist/{chunk-bfjv1adk.js.map → chunk-znw0zvy4.js.map} +0 -0
@@ -1,10 +1,11 @@
1
1
  import type { AccessTokenKind, AuthSessionAudience, Principal } from "../../auth"
2
+ import type { AuthorizablePrincipal } from "../../execution/types"
2
3
 
3
4
  export type UserStatus = "active" | "suspended"
4
5
  export type ServiceAccountStatus = "active" | "suspended"
5
6
  export type InvitationStatus = "pending" | "accepted" | "revoked"
6
- export type GroupMembershipSource = "invitation" | "manual" | "agent"
7
- export type AccessTokenSubjectType = "user" | "serviceAccount"
7
+ /** `directory`: owned by the identity provider, and synced to its groups on every sign-in. */
8
+ export type GroupMembershipSource = "invitation" | "manual" | "agent" | "directory"
8
9
  export type DeviceAuthorizationStatus = "pending" | "approved" | "denied" | "consumed"
9
10
  export const MAX_PENDING_DEVICE_AUTHORIZATIONS = 100
10
11
 
@@ -45,7 +46,8 @@ export interface ServiceAccountGroupMembershipRecord {
45
46
  readonly projectId: string
46
47
  readonly serviceAccountId: string
47
48
  readonly groupId: string
48
- readonly source: GroupMembershipSource
49
+ /** Service accounts never sign in, so no identity provider owns their memberships. */
50
+ readonly source: Exclude<GroupMembershipSource, "directory">
49
51
  readonly createdAt: Date
50
52
  }
51
53
 
@@ -54,6 +56,7 @@ export interface SessionRecord {
54
56
  readonly projectId: string
55
57
  readonly userId: string
56
58
  readonly strategyId: string
59
+ /** The web app a browser session belongs to. A bearer session belongs to none and ignores it. */
57
60
  readonly audience: AuthSessionAudience
58
61
  readonly tokenHash: string
59
62
  readonly createdAt: Date
@@ -65,15 +68,36 @@ export interface SessionRecord {
65
68
  // view. Display only — never used for authorization.
66
69
  readonly userAgent?: string
67
70
  readonly ipAddress?: string
71
+ /** Present when a native client holds the session as bearer tokens instead of a cookie. */
72
+ readonly bearer?: BearerSessionState
73
+ }
74
+
75
+ /**
76
+ * A native client's credentials for its session. `tokenHash` on the session is the current access
77
+ * token's hash; the refresh token rotates on every refresh.
78
+ */
79
+ export interface BearerSessionState {
80
+ /** Self-reported client label, such as "sixb CLI on alex-mbp". Display only. */
81
+ readonly clientName: string
82
+ readonly accessExpiresAt: Date
83
+ readonly refreshTokenHash: string
84
+ /** The refresh token the last rotation replaced, accepted briefly in case its response was lost. */
85
+ readonly previousRefreshTokenHash?: string
86
+ readonly refreshedAt?: Date
68
87
  }
69
88
 
89
+ export type RotateSessionRefreshTokenResult =
90
+ | { readonly status: "rotated"; readonly session: SessionRecord }
91
+ /** A replaced refresh token came back after the grace window; the session is now revoked. */
92
+ | { readonly status: "reused" }
93
+ | { readonly status: "invalid" }
94
+
70
95
  export interface AccessTokenRecord {
71
96
  readonly id: string
72
97
  readonly projectId: string
73
98
  readonly name: string
74
99
  readonly kind: AccessTokenKind
75
- readonly subjectType: AccessTokenSubjectType
76
- readonly subjectId: string
100
+ readonly subject: AuthorizablePrincipal
77
101
  readonly tokenHash: string
78
102
  /**
79
103
  * Optional group constraint. Undefined means "inherit every current group";
@@ -148,8 +172,6 @@ export interface DeviceAuthorizationRecord {
148
172
  readonly deviceCodeHash: string
149
173
  readonly userCode: string
150
174
  readonly clientName: string
151
- readonly tokenName: string
152
- readonly tokenExpiresAt: Date
153
175
  readonly status: DeviceAuthorizationStatus
154
176
  readonly approvedUserId?: string
155
177
  readonly approvedSessionId?: string
@@ -249,7 +271,7 @@ export interface UpsertAuthServiceAccountGroupMembershipInput {
249
271
  readonly projectId: string
250
272
  readonly serviceAccountId: string
251
273
  readonly groupId: string
252
- readonly source: GroupMembershipSource
274
+ readonly source: ServiceAccountGroupMembershipRecord["source"]
253
275
  readonly createdAt?: Date
254
276
  }
255
277
 
@@ -273,6 +295,7 @@ export interface CreateAuthSessionInput {
273
295
  readonly absoluteExpiresAt?: Date
274
296
  readonly userAgent?: string
275
297
  readonly ipAddress?: string
298
+ readonly bearer?: Pick<BearerSessionState, "clientName" | "accessExpiresAt" | "refreshTokenHash">
276
299
  }
277
300
 
278
301
  export interface CreateAuthAccessTokenInput {
@@ -280,8 +303,7 @@ export interface CreateAuthAccessTokenInput {
280
303
  readonly projectId: string
281
304
  readonly name: string
282
305
  readonly kind: AccessTokenKind
283
- readonly subjectType: AccessTokenSubjectType
284
- readonly subjectId: string
306
+ readonly subject: AuthorizablePrincipal
285
307
  readonly tokenHash: string
286
308
  readonly groupIds?: readonly string[]
287
309
  readonly createdByPrincipal?: Principal
@@ -293,8 +315,7 @@ export interface CreateAuthAccessTokenInput {
293
315
  export interface ListAuthAccessTokensInput {
294
316
  readonly projectId: string
295
317
  readonly kind?: AccessTokenKind
296
- readonly subjectType?: AccessTokenSubjectType
297
- readonly subjectId?: string
318
+ readonly subject?: AuthorizablePrincipal
298
319
  readonly includeRevoked?: boolean
299
320
  readonly limit?: number
300
321
  readonly offset?: number
@@ -385,8 +406,6 @@ export interface CreateDeviceAuthorizationInput {
385
406
  readonly deviceCodeHash: string
386
407
  readonly userCode: string
387
408
  readonly clientName: string
388
- readonly tokenName: string
389
- readonly tokenExpiresAt: Date
390
409
  readonly createdAt: Date
391
410
  readonly expiresAt: Date
392
411
  }
@@ -395,13 +414,14 @@ export interface CompleteDeviceAuthorizationInput {
395
414
  readonly projectId: string
396
415
  readonly id: string
397
416
  readonly deviceCodeHash: string
398
- readonly accessToken: CreateAuthAccessTokenInput
417
+ /** The bearer session to start for the approving user. */
418
+ readonly session: CreateAuthSessionInput & { readonly bearer: BearerSessionState }
399
419
  readonly completedAt: Date
400
420
  }
401
421
 
402
422
  export interface CompleteDeviceAuthorizationResult {
403
423
  readonly authorization: DeviceAuthorizationRecord
404
- readonly accessToken: AccessTokenRecord
424
+ readonly session: SessionRecord
405
425
  }
406
426
 
407
427
  export interface CompleteMagicLinkSignInInput {
@@ -413,7 +433,6 @@ export interface CompleteMagicLinkSignInInput {
413
433
  readonly newUserDisplayName?: string
414
434
  readonly newUserAvatarUrl?: string
415
435
  readonly allowUserCreationWithoutInvitation?: boolean
416
- readonly requireNoActiveUsersForUserCreation?: boolean
417
436
  readonly manualGroupIds?: readonly string[]
418
437
  readonly session: CompleteAuthSessionInput
419
438
  }
@@ -424,15 +443,22 @@ export interface CompleteOidcSignInInput {
424
443
  readonly stateHash: string
425
444
  readonly completedAt: Date
426
445
  readonly subject: string
446
+ /**
447
+ * An address the strategy has already decided to trust. Without an identity for `subject`, it
448
+ * links the user who has this email, or claims this email's invitation for a new user.
449
+ */
427
450
  readonly email: string
428
- readonly emailVerified?: boolean
429
451
  readonly displayName?: string
430
452
  readonly avatarUrl?: string
431
453
  readonly claims?: Readonly<Record<string, unknown>>
432
- readonly autoLinkByVerifiedEmail?: boolean
433
454
  readonly allowUserCreationWithoutInvitation?: boolean
434
- readonly requireNoActiveUsersForUserCreation?: boolean
435
455
  readonly manualGroupIds?: readonly string[]
456
+ /**
457
+ * The groups the identity provider grants this user. When present, the user's `directory`
458
+ * memberships become exactly these; memberships from any other source are never touched, and a
459
+ * group the user already has from another source keeps it. Omitted, nothing is synced.
460
+ */
461
+ readonly directoryGroupIds?: readonly string[]
436
462
  readonly newUserId: string
437
463
  readonly session: CompleteAuthSessionInput
438
464
  }
@@ -523,6 +549,7 @@ export interface AuthSessionStore {
523
549
  readonly userId: string
524
550
  readonly now: Date
525
551
  }): Promise<readonly SessionRecord[]>
552
+ /** A live browser (cookie) session whose secret hashes to `tokenHash`. */
526
553
  findValidByTokenHash(params: {
527
554
  readonly projectId: string
528
555
  readonly id: string
@@ -530,6 +557,31 @@ export interface AuthSessionStore {
530
557
  readonly tokenHash: string
531
558
  readonly now: Date
532
559
  }): Promise<SessionRecord | null>
560
+ /** A live bearer session whose current, unexpired access token hashes to `tokenHash`. */
561
+ findValidByAccessTokenHash(params: {
562
+ readonly projectId: string
563
+ readonly id: string
564
+ readonly tokenHash: string
565
+ readonly now: Date
566
+ }): Promise<SessionRecord | null>
567
+ /**
568
+ * Atomically replace a live bearer session's tokens. The current refresh token rotates; the one
569
+ * it replaced also rotates within `reuseGraceMs` of that replacement. Presenting it later revokes
570
+ * the session. `next.expiresAt` extends the idle deadline, never past the absolute one.
571
+ */
572
+ rotateRefreshToken(params: {
573
+ readonly projectId: string
574
+ readonly id: string
575
+ readonly refreshTokenHash: string
576
+ readonly now: Date
577
+ readonly reuseGraceMs: number
578
+ readonly next: {
579
+ readonly tokenHash: string
580
+ readonly accessExpiresAt: Date
581
+ readonly refreshTokenHash: string
582
+ readonly expiresAt: Date
583
+ }
584
+ }): Promise<RotateSessionRefreshTokenResult>
533
585
  renewIfValid(params: {
534
586
  readonly projectId: string
535
587
  readonly id: string
@@ -340,7 +340,7 @@ async function validateCredential(
340
340
  `[Sixb] Authority access token '${credential.id}' does not exist in project '${record.projectId}'.`
341
341
  )
342
342
  }
343
- if (token.subjectType !== principal.type || token.subjectId !== principal.id) {
343
+ if (!principalsEqual(token.subject, principal)) {
344
344
  throw new ExecutionStorageError(
345
345
  "invalid_credential",
346
346
  `[Sixb] Authority access token '${credential.id}' does not belong to principal '${principal.id}'.`
@@ -1,32 +1,37 @@
1
- import type { Principal } from "../../auth"
2
- import type { FileRef, SignedBlobUploadPart } from "../../blob-storage"
3
- import { FileUploadSessionError } from "./errors"
1
+ import {
2
+ DurableFileUploadSessions,
3
+ type FileUploadSessionPersistence,
4
+ type FileUploadSessionPersistenceBackend,
5
+ } from "./provider"
4
6
  import type {
5
7
  CreateFileUploadSessionInput,
6
8
  FileUploadSession,
7
- FileUploadSessionStore,
9
+ ListAbandonedFileUploadSessionsInput,
8
10
  } from "./types"
9
- import {
10
- createFileUploadId,
11
- isFileUploadSessionExpired,
12
- isTerminalFileUploadSessionExpired,
13
- principalKey,
14
- shouldDeleteFileUploadSession,
15
- } from "./utils"
11
+ import { isAbandonedFileUploadSession, shouldDeleteFileUploadSession } from "./utils"
16
12
 
17
13
  export type InMemoryFileUploadSessionsSnapshot = Map<string, FileUploadSession>
18
14
 
19
15
  /**
20
- * In-memory {@link FileUploadSessionStore}.
16
+ * In-memory {@link FileUploadSessionStore}: the shared durable state machine over a Map.
21
17
  *
22
- * Sessions live only in this process's memory: they do not survive a restart and
23
- * are not shared across instances. Staged/direct-put uploads therefore require a
24
- * single-instance deployment for now; a durable (Pg/Sqlite) store is a follow-up.
25
- * Expired sessions are reaped opportunistically on `create` and on demand via
26
- * `cleanupExpired` (there is no background sweeper).
18
+ * Sessions live only in this process's memory: they do not survive a restart and are not
19
+ * shared across instances, so staged uploads need a single instance. `@sixb/pg` and
20
+ * `@sixb/sqlite` provide durable stores. Reapable sessions are also reaped on `create`.
27
21
  */
28
- export class InMemoryFileUploadSessions implements FileUploadSessionStore {
29
- private readonly sessionsById = new Map<string, FileUploadSession>()
22
+ export class InMemoryFileUploadSessions extends DurableFileUploadSessions {
23
+ private readonly sessionsById: Map<string, FileUploadSession>
24
+
25
+ constructor() {
26
+ const sessionsById = new Map<string, FileUploadSession>()
27
+ super(new InMemoryFileUploadSessionBackend(sessionsById))
28
+ this.sessionsById = sessionsById
29
+ }
30
+
31
+ override async create(input: CreateFileUploadSessionInput): Promise<FileUploadSession> {
32
+ await this.cleanupExpired()
33
+ return super.create(input)
34
+ }
30
35
 
31
36
  snapshot(): InMemoryFileUploadSessionsSnapshot {
32
37
  return structuredClone(this.sessionsById)
@@ -38,100 +43,63 @@ export class InMemoryFileUploadSessions implements FileUploadSessionStore {
38
43
  this.sessionsById.set(id, structuredClone(session))
39
44
  }
40
45
  }
46
+ }
41
47
 
42
- async create(input: CreateFileUploadSessionInput): Promise<FileUploadSession> {
43
- await this.cleanupExpired()
48
+ class InMemoryFileUploadSessionBackend implements FileUploadSessionPersistenceBackend {
49
+ private readonly persistence: FileUploadSessionPersistence
50
+ // Every await yields; chaining transactions keeps read-modify-write atomic.
51
+ private tail: Promise<unknown> = Promise.resolve()
44
52
 
45
- const session: FileUploadSession = {
46
- id: input.id ?? createFileUploadId(),
47
- projectId: input.projectId,
48
- principalKey: principalKey(input.principal),
49
- strategy: input.strategy,
50
- status: "pending",
51
- ...(input.fileName === undefined ? {} : { fileName: input.fileName }),
52
- ...(input.mediaType === undefined ? {} : { mediaType: input.mediaType }),
53
- ...(input.logicalPath === undefined ? {} : { logicalPath: input.logicalPath }),
54
- ...(input.expectedSizeBytes === undefined
55
- ? {}
56
- : { expectedSizeBytes: input.expectedSizeBytes }),
57
- ...(input.expectedDigest === undefined ? {} : { expectedDigest: input.expectedDigest }),
58
- ...(input.providerUpload === undefined ? {} : { providerUpload: input.providerUpload }),
59
- signedParts: [],
60
- createdAt: new Date(),
61
- expiresAt: input.expiresAt,
62
- }
53
+ constructor(sessionsById: Map<string, FileUploadSession>) {
54
+ this.persistence = new InMemoryFileUploadSessionPersistence(sessionsById)
55
+ }
63
56
 
64
- this.sessionsById.set(session.id, session)
65
- return session
57
+ read<T>(run: (persistence: FileUploadSessionPersistence) => Promise<T>): Promise<T> {
58
+ return run(this.persistence)
66
59
  }
67
60
 
68
- async getForPrincipal(uploadId: string, principal: Principal): Promise<FileUploadSession> {
69
- const session = this.sessionsById.get(uploadId)
70
- if (!session || session.principalKey !== principalKey(principal)) {
71
- throw new FileUploadSessionError("not_found", "File upload session not found.")
72
- }
61
+ transaction<T>(run: (persistence: FileUploadSessionPersistence) => Promise<T>): Promise<T> {
62
+ const result = this.tail.then(() => run(this.persistence))
63
+ this.tail = result.catch(() => undefined)
64
+ return result
65
+ }
66
+ }
73
67
 
74
- const nowMs = Date.now()
75
- if (isFileUploadSessionExpired(session, nowMs)) {
76
- this.sessionsById.delete(uploadId)
77
- throw new FileUploadSessionError("expired", "File upload session has expired.")
78
- }
68
+ class InMemoryFileUploadSessionPersistence implements FileUploadSessionPersistence {
69
+ constructor(private readonly sessionsById: Map<string, FileUploadSession>) {}
79
70
 
80
- if (isTerminalFileUploadSessionExpired(session, nowMs)) {
81
- this.sessionsById.delete(uploadId)
82
- throw new FileUploadSessionError("not_found", "File upload session not found.")
83
- }
84
-
85
- return session
71
+ async now(): Promise<Date> {
72
+ return new Date()
86
73
  }
87
74
 
88
- async markUploaded(uploadId: string, fileRef: FileRef): Promise<FileUploadSession> {
89
- const session = this.requirePending(uploadId)
90
- const updated = {
91
- ...session,
92
- fileRef,
93
- }
94
- this.sessionsById.set(uploadId, updated)
95
- return updated
75
+ async insert(session: FileUploadSession): Promise<boolean> {
76
+ if (this.sessionsById.has(session.id)) return false
77
+ this.sessionsById.set(session.id, session)
78
+ return true
96
79
  }
97
80
 
98
- async addSignedPart(uploadId: string, part: SignedBlobUploadPart): Promise<FileUploadSession> {
99
- const session = this.requirePending(uploadId)
100
- const updated = {
101
- ...session,
102
- signedParts: [
103
- ...session.signedParts.filter((candidate) => candidate.partNumber !== part.partNumber),
104
- part,
105
- ].sort((left, right) => left.partNumber - right.partNumber),
106
- }
107
- this.sessionsById.set(uploadId, updated)
108
- return updated
81
+ async get(uploadId: string): Promise<FileUploadSession | null> {
82
+ return this.sessionsById.get(uploadId) ?? null
109
83
  }
110
84
 
111
- async complete(uploadId: string, fileRef: FileRef): Promise<FileUploadSession> {
112
- const session = this.requirePending(uploadId)
113
- const updated = {
114
- ...session,
115
- status: "completed" as const,
116
- fileRef,
117
- completedAt: new Date(),
118
- }
119
- this.sessionsById.set(uploadId, updated)
120
- return updated
85
+ async update(session: FileUploadSession): Promise<void> {
86
+ this.sessionsById.set(session.id, session)
121
87
  }
122
88
 
123
- async abort(uploadId: string): Promise<FileUploadSession> {
124
- const session = this.requirePending(uploadId)
125
- const updated = {
126
- ...session,
127
- status: "aborted" as const,
128
- abortedAt: new Date(),
129
- }
130
- this.sessionsById.set(uploadId, updated)
131
- return updated
89
+ async listAbandoned(
90
+ input: ListAbandonedFileUploadSessionsInput
91
+ ): Promise<readonly FileUploadSession[]> {
92
+ return [...this.sessionsById.values()]
93
+ .filter(
94
+ (session) =>
95
+ session.projectId === input.projectId &&
96
+ isAbandonedFileUploadSession(session, input.now.getTime())
97
+ )
98
+ .sort((left, right) => left.expiresAt.getTime() - right.expiresAt.getTime())
99
+ .slice(0, input.limit)
132
100
  }
133
101
 
134
- async cleanupExpired(now = new Date()): Promise<number> {
102
+ async deleteReapable(now: Date): Promise<number> {
135
103
  let deleted = 0
136
104
  for (const [id, session] of this.sessionsById) {
137
105
  if (shouldDeleteFileUploadSession(session, now.getTime())) {
@@ -139,23 +107,6 @@ export class InMemoryFileUploadSessions implements FileUploadSessionStore {
139
107
  deleted += 1
140
108
  }
141
109
  }
142
-
143
110
  return deleted
144
111
  }
145
-
146
- private requirePending(uploadId: string): FileUploadSession {
147
- const session = this.sessionsById.get(uploadId)
148
- if (!session) {
149
- throw new FileUploadSessionError("not_found", "File upload session not found.")
150
- }
151
-
152
- if (session.status !== "pending") {
153
- throw new FileUploadSessionError(
154
- session.status === "completed" ? "already_completed" : "already_aborted",
155
- `File upload session is already ${session.status}.`
156
- )
157
- }
158
-
159
- return session
160
- }
161
112
  }
@@ -7,6 +7,7 @@ export type {
7
7
  FileUploadSessionStore,
8
8
  FileUploadStatus,
9
9
  FileUploadStrategy,
10
+ ListAbandonedFileUploadSessionsInput,
10
11
  } from "./types"
11
12
  export {
12
13
  createFileUploadId,