@sixb/core 0.2.0 → 0.2.2

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 (337) hide show
  1. package/dist/actions/index.js +30 -30
  2. package/dist/agents/cancel.d.ts.map +1 -1
  3. package/dist/agents/index.d.ts +5 -3
  4. package/dist/agents/index.d.ts.map +1 -1
  5. package/dist/agents/index.js +39 -33
  6. package/dist/agents/index.js.map +1 -1
  7. package/dist/agents/run-plan.d.ts +15 -1
  8. package/dist/agents/run-plan.d.ts.map +1 -1
  9. package/dist/agents/run-session-http.d.ts.map +1 -1
  10. package/dist/agents/run-session-serve.d.ts.map +1 -1
  11. package/dist/agents/run-session.d.ts +14 -2
  12. package/dist/agents/run-session.d.ts.map +1 -1
  13. package/dist/agents/skills.d.ts +3 -0
  14. package/dist/agents/skills.d.ts.map +1 -1
  15. package/dist/agents/step-limits.d.ts +6 -0
  16. package/dist/agents/step-limits.d.ts.map +1 -1
  17. package/dist/agents/streams/index.js +1 -1
  18. package/dist/agents/streams/internal.js +1 -1
  19. package/dist/agents/streams/protocol.d.ts +8 -2
  20. package/dist/agents/streams/protocol.d.ts.map +1 -1
  21. package/dist/agents/tool-files.d.ts +3 -1
  22. package/dist/agents/tool-files.d.ts.map +1 -1
  23. package/dist/agents/validation.d.ts +1 -1
  24. package/dist/agents/validation.d.ts.map +1 -1
  25. package/dist/agents/web.d.ts +47 -0
  26. package/dist/agents/web.d.ts.map +1 -0
  27. package/dist/artifacts/publish/index.js +17 -17
  28. package/dist/auth/index.js +3 -3
  29. package/dist/authorization/index.js +2 -2
  30. package/dist/authorization/resolve.d.ts +4 -3
  31. package/dist/authorization/resolve.d.ts.map +1 -1
  32. package/dist/authorization/types.d.ts +5 -5
  33. package/dist/authorization/types.d.ts.map +1 -1
  34. package/dist/bootstrap/index.js +38 -38
  35. package/dist/{chunk-neftrg0n.js → chunk-0j3crh1w.js} +2 -2
  36. package/dist/{chunk-8dcfj58k.js → chunk-2ajw5rz0.js} +14 -10
  37. package/dist/chunk-2ajw5rz0.js.map +18 -0
  38. package/dist/{chunk-23s66j86.js → chunk-31kcqmhf.js} +1 -1
  39. package/dist/{chunk-nghc7eq0.js → chunk-3723kgba.js} +1 -1
  40. package/dist/{chunk-fdkpkkpw.js → chunk-3sqqhpr7.js} +5 -5
  41. package/dist/{chunk-m3qe54bb.js → chunk-4bm0caep.js} +1 -1
  42. package/dist/{chunk-ztf5vtmp.js → chunk-4s753g3k.js} +41 -10
  43. package/dist/chunk-4s753g3k.js.map +12 -0
  44. package/dist/{chunk-fntqb7qy.js → chunk-57g0215c.js} +1 -1
  45. package/dist/{chunk-8wsjr52f.js → chunk-5wtnmpze.js} +1 -1
  46. package/dist/{chunk-edx8xcsm.js → chunk-7z5rkf0m.js} +29 -6
  47. package/dist/chunk-7z5rkf0m.js.map +13 -0
  48. package/dist/{chunk-2pk5hjj9.js → chunk-80gym75n.js} +1 -1
  49. package/dist/{chunk-qbrmpgvv.js → chunk-9whfmsfk.js} +1 -1
  50. package/dist/{chunk-qya541bk.js → chunk-a5v4gjdx.js} +31 -28
  51. package/dist/{chunk-qya541bk.js.map → chunk-a5v4gjdx.js.map} +4 -4
  52. package/dist/{chunk-he7g39e5.js → chunk-a7aa0nzj.js} +7 -7
  53. package/dist/{chunk-tvefbgvw.js → chunk-az95tsh3.js} +4 -2
  54. package/dist/chunk-az95tsh3.js.map +11 -0
  55. package/dist/{chunk-7hd2ez3q.js → chunk-c4nrycdy.js} +1 -1
  56. package/dist/{chunk-ekkpzcka.js → chunk-c706qvyc.js} +36 -9
  57. package/dist/chunk-c706qvyc.js.map +11 -0
  58. package/dist/{chunk-n54k068r.js → chunk-c7cfe31p.js} +7 -7
  59. package/dist/{chunk-qsg8rw04.js → chunk-d04g36fw.js} +1 -1
  60. package/dist/{chunk-hjy3dsws.js → chunk-dsv783c3.js} +305 -32
  61. package/dist/{chunk-hjy3dsws.js.map → chunk-dsv783c3.js.map} +12 -10
  62. package/dist/{chunk-peggaard.js → chunk-e6xgz4h4.js} +20 -2
  63. package/dist/{chunk-peggaard.js.map → chunk-e6xgz4h4.js.map} +5 -3
  64. package/dist/{chunk-e99kp9jh.js → chunk-eqgr6nsa.js} +86 -30
  65. package/dist/{chunk-e99kp9jh.js.map → chunk-eqgr6nsa.js.map} +10 -9
  66. package/dist/{chunk-f2w6328x.js → chunk-f1h34y3r.js} +6 -6
  67. package/dist/{chunk-9rh8ncs5.js → chunk-fwsvshr5.js} +1 -1
  68. package/dist/{chunk-c78jjzhy.js → chunk-ga63a3dz.js} +6 -6
  69. package/dist/{chunk-c78jjzhy.js.map → chunk-ga63a3dz.js.map} +2 -2
  70. package/dist/{chunk-cgznz22f.js → chunk-gkv8r794.js} +2 -2
  71. package/dist/{chunk-d3t26vah.js → chunk-j1ny5fwh.js} +35 -11
  72. package/dist/chunk-j1ny5fwh.js.map +15 -0
  73. package/dist/{chunk-8hvfs0fr.js → chunk-j8thxj7w.js} +4 -4
  74. package/dist/{chunk-855n80en.js → chunk-jjmggm9a.js} +1 -1
  75. package/dist/{chunk-31khg3g0.js → chunk-kkjfve0t.js} +73 -2
  76. package/dist/{chunk-31khg3g0.js.map → chunk-kkjfve0t.js.map} +3 -3
  77. package/dist/{chunk-fb3m4sa1.js → chunk-m2vh8gh0.js} +8 -14
  78. package/dist/{chunk-fb3m4sa1.js.map → chunk-m2vh8gh0.js.map} +3 -3
  79. package/dist/{chunk-vkweppkw.js → chunk-mbc5hvnj.js} +3 -3
  80. package/dist/{chunk-jk97v21j.js → chunk-n4zzaf6q.js} +3 -2
  81. package/dist/chunk-n4zzaf6q.js.map +10 -0
  82. package/dist/{chunk-y2x2935j.js → chunk-nh26e7c5.js} +2 -2
  83. package/dist/{chunk-jhbk10wf.js → chunk-q9nkpr8k.js} +1 -1
  84. package/dist/{chunk-47e09r7z.js → chunk-qttqe1ah.js} +86 -6
  85. package/dist/{chunk-47e09r7z.js.map → chunk-qttqe1ah.js.map} +5 -4
  86. package/dist/{chunk-9mab3dvg.js → chunk-s038wa5v.js} +9 -1
  87. package/dist/{chunk-9mab3dvg.js.map → chunk-s038wa5v.js.map} +3 -3
  88. package/dist/{chunk-3x3bebz7.js → chunk-s7j8ewqv.js} +161 -62
  89. package/dist/{chunk-3x3bebz7.js.map → chunk-s7j8ewqv.js.map} +7 -6
  90. package/dist/{chunk-dz7a4t3a.js → chunk-twfreyxr.js} +5 -10
  91. package/dist/{chunk-dz7a4t3a.js.map → chunk-twfreyxr.js.map} +4 -4
  92. package/dist/{chunk-semf1yqn.js → chunk-w1btn96n.js} +51 -26
  93. package/dist/{chunk-semf1yqn.js.map → chunk-w1btn96n.js.map} +6 -6
  94. package/dist/{chunk-fg1db9xx.js → chunk-wkq3kvzd.js} +5 -5
  95. package/dist/chunk-wkq3kvzd.js.map +10 -0
  96. package/dist/{chunk-xj97s5js.js → chunk-wrjx1fqz.js} +6 -6
  97. package/dist/{chunk-agn8d8ys.js → chunk-xtztwpkh.js} +1 -1
  98. package/dist/{chunk-0g5nyx0k.js → chunk-zeykm8my.js} +2 -2
  99. package/dist/connectors/connections/runs.d.ts +7 -0
  100. package/dist/connectors/connections/runs.d.ts.map +1 -1
  101. package/dist/datasets/execution.d.ts.map +1 -1
  102. package/dist/events/index.js +1 -1
  103. package/dist/events/selectors/index.js +1 -1
  104. package/dist/events/selectors/predicate.d.ts.map +1 -1
  105. package/dist/events/types/datasets.d.ts +6 -0
  106. package/dist/events/types/datasets.d.ts.map +1 -1
  107. package/dist/execution/agent.js +30 -30
  108. package/dist/execution/object-reader-security.d.ts.map +1 -1
  109. package/dist/execution/primitive.js +30 -30
  110. package/dist/execution/request.js +31 -31
  111. package/dist/index.d.ts +2 -2
  112. package/dist/index.d.ts.map +1 -1
  113. package/dist/index.js +42 -42
  114. package/dist/lake-storage/in-memory.d.ts.map +1 -1
  115. package/dist/lake-storage/index.d.ts +2 -2
  116. package/dist/lake-storage/index.d.ts.map +1 -1
  117. package/dist/lake-storage/index.js +6 -2
  118. package/dist/lake-storage/index.js.map +1 -1
  119. package/dist/lake-storage/source-ordering.d.ts +7 -0
  120. package/dist/lake-storage/source-ordering.d.ts.map +1 -1
  121. package/dist/lake-storage/types.d.ts +18 -0
  122. package/dist/lake-storage/types.d.ts.map +1 -1
  123. package/dist/lake-storage/version-inputs.d.ts +11 -3
  124. package/dist/lake-storage/version-inputs.d.ts.map +1 -1
  125. package/dist/materializer/index.js +16 -16
  126. package/dist/models/catalog.d.ts +16 -0
  127. package/dist/models/catalog.d.ts.map +1 -1
  128. package/dist/models/definitions.d.ts +1 -1
  129. package/dist/models/definitions.d.ts.map +1 -1
  130. package/dist/models/execution/index.js +18 -18
  131. package/dist/models/execution/model-call-recorder.d.ts +1 -1
  132. package/dist/models/execution/model-call-recorder.d.ts.map +1 -1
  133. package/dist/models/execution/web-search.d.ts +7 -0
  134. package/dist/models/execution/web-search.d.ts.map +1 -0
  135. package/dist/models/index.d.ts +3 -1
  136. package/dist/models/index.d.ts.map +1 -1
  137. package/dist/models/index.js +5 -3
  138. package/dist/models/index.js.map +1 -1
  139. package/dist/models/language-model.d.ts +12 -0
  140. package/dist/models/language-model.d.ts.map +1 -1
  141. package/dist/models/web-search-model.d.ts +66 -0
  142. package/dist/models/web-search-model.d.ts.map +1 -0
  143. package/dist/objects/index.js +30 -30
  144. package/dist/objects/query/executor.d.ts.map +1 -1
  145. package/dist/objects/query/index.d.ts +1 -0
  146. package/dist/objects/query/index.d.ts.map +1 -1
  147. package/dist/objects/query/index.js +19 -16
  148. package/dist/objects/query/index.js.map +1 -1
  149. package/dist/objects/query/sort-ties.d.ts +11 -0
  150. package/dist/objects/query/sort-ties.d.ts.map +1 -0
  151. package/dist/pipelines/index.js +19 -19
  152. package/dist/pipelines/run-dispatch.d.ts +2 -0
  153. package/dist/pipelines/run-dispatch.d.ts.map +1 -1
  154. package/dist/projections/internal.js +16 -16
  155. package/dist/runtime/create.d.ts +1 -1
  156. package/dist/runtime/create.d.ts.map +1 -1
  157. package/dist/runtime/internal.js +22 -22
  158. package/dist/runtime/resolve-definitions.d.ts.map +1 -1
  159. package/dist/schedules/index.js +2 -2
  160. package/dist/security/index.d.ts +1 -0
  161. package/dist/security/index.d.ts.map +1 -1
  162. package/dist/security/registry.d.ts +2 -0
  163. package/dist/security/registry.d.ts.map +1 -1
  164. package/dist/security/view-conditions.d.ts.map +1 -1
  165. package/dist/security/visibility-keys.d.ts +19 -0
  166. package/dist/security/visibility-keys.d.ts.map +1 -0
  167. package/dist/shares/internal.js +16 -16
  168. package/dist/storage/agents/in-memory.d.ts +8 -2
  169. package/dist/storage/agents/in-memory.d.ts.map +1 -1
  170. package/dist/storage/agents/index.d.ts +1 -1
  171. package/dist/storage/agents/index.d.ts.map +1 -1
  172. package/dist/storage/agents/provider.d.ts +8 -2
  173. package/dist/storage/agents/provider.d.ts.map +1 -1
  174. package/dist/storage/agents/provider.js +12 -6
  175. package/dist/storage/agents/provider.js.map +1 -1
  176. package/dist/storage/agents/types.d.ts +42 -2
  177. package/dist/storage/agents/types.d.ts.map +1 -1
  178. package/dist/storage/ai-cost/provider.js +4 -4
  179. package/dist/storage/ai-limits/enforcement.js +3 -3
  180. package/dist/storage/ai-limits/provider.js +2 -2
  181. package/dist/storage/connector-connections/provider.js +3 -3
  182. package/dist/storage/connector-connections/provider.js.map +3 -3
  183. package/dist/storage/file-upload-sessions/provider.js +4 -4
  184. package/dist/storage/index.d.ts +2 -2
  185. package/dist/storage/index.d.ts.map +1 -1
  186. package/dist/storage/index.js +15 -15
  187. package/dist/storage/internal.d.ts +2 -0
  188. package/dist/storage/internal.d.ts.map +1 -1
  189. package/dist/storage/internal.js +8 -4
  190. package/dist/storage/internal.js.map +1 -1
  191. package/dist/storage/migrations/types.d.ts +6 -0
  192. package/dist/storage/migrations/types.d.ts.map +1 -1
  193. package/dist/storage/objects/in-memory/query.d.ts.map +1 -1
  194. package/dist/storage/objects/index.d.ts +1 -1
  195. package/dist/storage/objects/index.d.ts.map +1 -1
  196. package/dist/storage/objects/query-preparation.d.ts +13 -0
  197. package/dist/storage/objects/query-preparation.d.ts.map +1 -1
  198. package/dist/storage/objects/read-scope.d.ts.map +1 -1
  199. package/dist/storage/objects/types.d.ts +52 -0
  200. package/dist/storage/objects/types.d.ts.map +1 -1
  201. package/dist/storage/pipeline-runs/in-memory.d.ts.map +1 -1
  202. package/dist/storage/pipeline-runs/transitions.d.ts +7 -0
  203. package/dist/storage/pipeline-runs/transitions.d.ts.map +1 -0
  204. package/dist/storage/share-grants/provider.js +2 -2
  205. package/dist/storage/sync-runs/in-memory.d.ts.map +1 -1
  206. package/dist/storage/sync-runs/transitions.d.ts +7 -0
  207. package/dist/storage/sync-runs/transitions.d.ts.map +1 -0
  208. package/dist/storage/workflow-runs/provider.js +4 -4
  209. package/dist/syncs/index.js +20 -20
  210. package/dist/syncs/run-dispatch.d.ts +2 -0
  211. package/dist/syncs/run-dispatch.d.ts.map +1 -1
  212. package/dist/testing/agent-storage-contract.d.ts.map +1 -1
  213. package/dist/testing/ai-limit-storage-contract.d.ts.map +1 -1
  214. package/dist/testing/ai-usage-storage-contract.d.ts.map +1 -1
  215. package/dist/testing/connector-connection-storage-contract.d.ts.map +1 -1
  216. package/dist/testing/dataset-sequence-contract.d.ts.map +1 -1
  217. package/dist/testing/index.js +552 -61
  218. package/dist/testing/index.js.map +11 -11
  219. package/dist/testing/lake-changes-contract.d.ts.map +1 -1
  220. package/dist/testing/lake-storage-contract.d.ts.map +1 -1
  221. package/dist/testing/object-conditional-read-scope-contract.d.ts.map +1 -1
  222. package/dist/testing/object-query-contract.d.ts.map +1 -1
  223. package/dist/webhooks/internal.js +16 -16
  224. package/dist/workers/index.d.ts +1 -0
  225. package/dist/workers/index.d.ts.map +1 -1
  226. package/dist/workers/index.js +12 -2
  227. package/dist/workers/index.js.map +5 -4
  228. package/dist/workers/unstarted-run.d.ts +10 -0
  229. package/dist/workers/unstarted-run.d.ts.map +1 -0
  230. package/dist/workflows/index.js +34 -34
  231. package/package.json +1 -1
  232. package/src/agents/README.md +2 -1
  233. package/src/agents/cancel.ts +7 -1
  234. package/src/agents/index.ts +9 -1
  235. package/src/agents/run-plan.ts +31 -0
  236. package/src/agents/run-session-http.ts +15 -12
  237. package/src/agents/run-session-serve.ts +8 -2
  238. package/src/agents/run-session.ts +31 -11
  239. package/src/agents/skills.ts +3 -0
  240. package/src/agents/step-limits.ts +6 -0
  241. package/src/agents/streams/protocol.ts +9 -4
  242. package/src/agents/tool-files.ts +11 -3
  243. package/src/agents/validation.ts +9 -0
  244. package/src/agents/web.ts +218 -0
  245. package/src/authorization/resolve.ts +9 -11
  246. package/src/authorization/types.ts +5 -5
  247. package/src/connectors/connections/runs.ts +42 -5
  248. package/src/datasets/execution.ts +2 -0
  249. package/src/events/selectors/predicate.ts +15 -0
  250. package/src/events/types/datasets.ts +6 -0
  251. package/src/execution/object-reader-security.ts +4 -9
  252. package/src/index.ts +2 -0
  253. package/src/lake-storage/in-memory.ts +30 -20
  254. package/src/lake-storage/index.ts +2 -1
  255. package/src/lake-storage/source-ordering.ts +31 -4
  256. package/src/lake-storage/types.ts +18 -0
  257. package/src/lake-storage/version-inputs.ts +21 -5
  258. package/src/models/catalog.ts +52 -3
  259. package/src/models/definitions.ts +2 -0
  260. package/src/models/execution/README.md +22 -2
  261. package/src/models/execution/model-call-recorder.ts +1 -1
  262. package/src/models/execution/web-search.ts +186 -0
  263. package/src/models/index.ts +12 -0
  264. package/src/models/language-model.ts +12 -0
  265. package/src/models/web-search-model.ts +152 -0
  266. package/src/objects/query/executor.ts +7 -3
  267. package/src/objects/query/index.ts +1 -0
  268. package/src/objects/query/sort-ties.ts +16 -0
  269. package/src/pipelines/run-dispatch.ts +53 -6
  270. package/src/runtime/create.ts +3 -2
  271. package/src/runtime/resolve-definitions.ts +4 -0
  272. package/src/security/index.ts +1 -0
  273. package/src/security/registry.ts +2 -0
  274. package/src/security/view-conditions.ts +4 -3
  275. package/src/security/visibility-keys.ts +144 -0
  276. package/src/storage/agents/in-memory.ts +29 -2
  277. package/src/storage/agents/index.ts +2 -0
  278. package/src/storage/agents/provider.ts +57 -1
  279. package/src/storage/agents/types.ts +45 -2
  280. package/src/storage/connector-connections/in-memory.ts +2 -2
  281. package/src/storage/connector-connections/provider/connections.ts +2 -2
  282. package/src/storage/index.ts +4 -0
  283. package/src/storage/internal.ts +2 -0
  284. package/src/storage/migrations/types.ts +6 -0
  285. package/src/storage/objects/in-memory/query.ts +5 -2
  286. package/src/storage/objects/index.ts +2 -0
  287. package/src/storage/objects/query-preparation.ts +59 -1
  288. package/src/storage/objects/read-scope.ts +108 -2
  289. package/src/storage/objects/types.ts +43 -0
  290. package/src/storage/pipeline-runs/in-memory.ts +2 -5
  291. package/src/storage/pipeline-runs/transitions.ts +14 -0
  292. package/src/storage/sync-runs/in-memory.ts +2 -5
  293. package/src/storage/sync-runs/transitions.ts +11 -0
  294. package/src/syncs/run-dispatch.ts +68 -13
  295. package/src/testing/agent-storage-contract.ts +70 -0
  296. package/src/testing/ai-limit-storage-contract.ts +11 -1
  297. package/src/testing/ai-usage-storage-contract.ts +15 -2
  298. package/src/testing/connector-connection-storage-contract.ts +23 -0
  299. package/src/testing/dataset-sequence-contract.ts +81 -0
  300. package/src/testing/lake-changes-contract.ts +2 -1
  301. package/src/testing/lake-storage-contract.ts +112 -0
  302. package/src/testing/object-conditional-read-scope-contract.ts +267 -5
  303. package/src/testing/object-query-contract.ts +75 -0
  304. package/src/workers/index.ts +1 -0
  305. package/src/workers/unstarted-run.ts +18 -0
  306. package/dist/chunk-8dcfj58k.js.map +0 -18
  307. package/dist/chunk-d3t26vah.js.map +0 -15
  308. package/dist/chunk-edx8xcsm.js.map +0 -13
  309. package/dist/chunk-ekkpzcka.js.map +0 -11
  310. package/dist/chunk-fg1db9xx.js.map +0 -10
  311. package/dist/chunk-jk97v21j.js.map +0 -10
  312. package/dist/chunk-tvefbgvw.js.map +0 -11
  313. package/dist/chunk-ztf5vtmp.js.map +0 -12
  314. /package/dist/{chunk-neftrg0n.js.map → chunk-0j3crh1w.js.map} +0 -0
  315. /package/dist/{chunk-23s66j86.js.map → chunk-31kcqmhf.js.map} +0 -0
  316. /package/dist/{chunk-nghc7eq0.js.map → chunk-3723kgba.js.map} +0 -0
  317. /package/dist/{chunk-fdkpkkpw.js.map → chunk-3sqqhpr7.js.map} +0 -0
  318. /package/dist/{chunk-m3qe54bb.js.map → chunk-4bm0caep.js.map} +0 -0
  319. /package/dist/{chunk-fntqb7qy.js.map → chunk-57g0215c.js.map} +0 -0
  320. /package/dist/{chunk-8wsjr52f.js.map → chunk-5wtnmpze.js.map} +0 -0
  321. /package/dist/{chunk-2pk5hjj9.js.map → chunk-80gym75n.js.map} +0 -0
  322. /package/dist/{chunk-qbrmpgvv.js.map → chunk-9whfmsfk.js.map} +0 -0
  323. /package/dist/{chunk-he7g39e5.js.map → chunk-a7aa0nzj.js.map} +0 -0
  324. /package/dist/{chunk-7hd2ez3q.js.map → chunk-c4nrycdy.js.map} +0 -0
  325. /package/dist/{chunk-n54k068r.js.map → chunk-c7cfe31p.js.map} +0 -0
  326. /package/dist/{chunk-qsg8rw04.js.map → chunk-d04g36fw.js.map} +0 -0
  327. /package/dist/{chunk-f2w6328x.js.map → chunk-f1h34y3r.js.map} +0 -0
  328. /package/dist/{chunk-9rh8ncs5.js.map → chunk-fwsvshr5.js.map} +0 -0
  329. /package/dist/{chunk-cgznz22f.js.map → chunk-gkv8r794.js.map} +0 -0
  330. /package/dist/{chunk-8hvfs0fr.js.map → chunk-j8thxj7w.js.map} +0 -0
  331. /package/dist/{chunk-855n80en.js.map → chunk-jjmggm9a.js.map} +0 -0
  332. /package/dist/{chunk-vkweppkw.js.map → chunk-mbc5hvnj.js.map} +0 -0
  333. /package/dist/{chunk-y2x2935j.js.map → chunk-nh26e7c5.js.map} +0 -0
  334. /package/dist/{chunk-jhbk10wf.js.map → chunk-q9nkpr8k.js.map} +0 -0
  335. /package/dist/{chunk-xj97s5js.js.map → chunk-wrjx1fqz.js.map} +0 -0
  336. /package/dist/{chunk-agn8d8ys.js.map → chunk-xtztwpkh.js.map} +0 -0
  337. /package/dist/{chunk-0g5nyx0k.js.map → chunk-zeykm8my.js.map} +0 -0
@@ -250,6 +250,87 @@ export function runDatasetSequenceContract<TStorage extends LakeStorage>(
250
250
  expect(await rows(storage)).toEqual([])
251
251
  }))
252
252
 
253
+ test("records a merge that only advances source ordering as changing no rows", () =>
254
+ withStorage(async (storage) => {
255
+ // Red check: record `rowsChanged: true` on every merge version the provider creates.
256
+ const changed = (result: DatasetMergeCommitResult) => ({
257
+ outcome: result.outcome,
258
+ rowsChanged: result.version?.rowsChanged,
259
+ lineageChanged: result.version?.lineageChanged,
260
+ })
261
+
262
+ expect(changed(await merge(storage, [upsert(1)]))).toEqual({
263
+ outcome: "created",
264
+ rowsChanged: true,
265
+ lineageChanged: true,
266
+ })
267
+
268
+ // The delete of a key the dataset does not hold only records its sequence.
269
+ const orderingOnly = await merge(storage, [change.delete({ id: "7" }, { sequence: 3 })])
270
+ expect(changed(orderingOnly)).toEqual({
271
+ outcome: "created",
272
+ rowsChanged: false,
273
+ lineageChanged: false,
274
+ })
275
+ expect(
276
+ (await storage.getVersion(dataset.id, orderingOnly.version!.versionId))?.rowsChanged
277
+ ).toBe(false)
278
+
279
+ expect(changed(await merge(storage, [upsert(2, "Ada")]))).toEqual({
280
+ outcome: "created",
281
+ rowsChanged: true,
282
+ lineageChanged: false,
283
+ })
284
+ }))
285
+
286
+ test("keeps a stored row that a newer delivery repeats with only its sequence changed", () =>
287
+ withStorage(async (storage) => {
288
+ // Red check: write every accepted upsert's row (drop `isSequenceOnlyChange` from the
289
+ // provider's merge, or the `sequenceBy` filter from DuckLake's row difference).
290
+ const stored = async () =>
291
+ (await rows(storage))
292
+ .map((row) => ({ id: row.id, revision: String(row.revision), name: row.name }))
293
+ .sort((left, right) => String(left.id).localeCompare(String(right.id)))
294
+ const changed = (result: DatasetMergeCommitResult) => ({
295
+ outcome: result.outcome,
296
+ rowsChanged: result.version?.rowsChanged,
297
+ })
298
+
299
+ await merge(storage, [upsert(10), upsert(1, "Lin", "7")])
300
+
301
+ // A re-read at 12 returns the same content: the row keeps 10, the ordering moves to 12.
302
+ expect(changed(await merge(storage, [upsert(12)]))).toEqual({
303
+ outcome: "created",
304
+ rowsChanged: false,
305
+ })
306
+ expect(await stored()).toEqual([
307
+ { id: "42", revision: "10", name: "Sam" },
308
+ { id: "7", revision: "1", name: "Lin" },
309
+ ])
310
+
311
+ // A late delivery read at 11 stays ignored, and 12 compares with what was delivered at 12.
312
+ expect((await merge(storage, [upsert(11, "Late")])).outcome).toBe("unchanged")
313
+ expect((await merge(storage, [upsert(12)])).outcome).toBe("unchanged")
314
+ await expect(merge(storage, [upsert(12, "Tie")])).rejects.toThrow("conflicting content")
315
+
316
+ // In one batch, only the row whose content changed is rewritten.
317
+ expect(changed(await merge(storage, [upsert(13), upsert(2, "Grace", "7")]))).toEqual({
318
+ outcome: "created",
319
+ rowsChanged: true,
320
+ })
321
+ expect(await stored()).toEqual([
322
+ { id: "42", revision: "10", name: "Sam" },
323
+ { id: "7", revision: "2", name: "Grace" },
324
+ ])
325
+
326
+ // Any other difference rewrites the whole row, its sequence included.
327
+ expect(changed(await merge(storage, [upsert(14, "Ada")]))).toEqual({
328
+ outcome: "created",
329
+ rowsChanged: true,
330
+ })
331
+ expect((await stored())[0]).toEqual({ id: "42", revision: "14", name: "Ada" })
332
+ }))
333
+
253
334
  test("compares canonical content across JSON order and nullable representations", () =>
254
335
  withStorage(async (storage) => {
255
336
  await merge(storage, [
@@ -121,7 +121,8 @@ export function runLakeChangesContractSuite<T extends LakeStorage>(
121
121
  })
122
122
  test("refuses blank identities and invalid column requests", async () => {
123
123
  const first = await write([row(" ", "one")])
124
- expect(await read(first, first)).toBeNull()
124
+ const second = await write([row(" ", "two")])
125
+ expect(await read(first, second)).toBeNull()
125
126
  await expect(read(first, first, [])).rejects.toThrow("distinct columns")
126
127
  await expect(read(first, first, ["missing"])).rejects.toThrow("distinct columns")
127
128
  })
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, test } from "bun:test"
2
+ import { randomUUID } from "node:crypto"
2
3
  import type { FileRef } from "../blob-storage"
3
4
  import { col, type DatasetDefinition, defineDataset } from "../datasets"
4
5
  import { LakeStorageError } from "../lake-storage/errors"
@@ -7,6 +8,7 @@ import type {
7
8
  DatasetColumnRef,
8
9
  DatasetProducer,
9
10
  DatasetRow,
11
+ DatasetVersion,
10
12
  DatasetWriteCommitResult,
11
13
  LakeStorage,
12
14
  } from "../lake-storage/types"
@@ -1178,6 +1180,116 @@ export function runLakeStorageContractSuite<TStorage extends LakeStorage>(
1178
1180
  })
1179
1181
  }))
1180
1182
  })
1183
+
1184
+ describe("what a version changed", () => {
1185
+ const changed = (version: DatasetVersion | null | undefined) => ({
1186
+ rowsChanged: version?.rowsChanged,
1187
+ lineageChanged: version?.lineageChanged,
1188
+ })
1189
+
1190
+ test("records whether a version changed rows or lineage, across reopening", async () => {
1191
+ // Red check: store `rowsChanged: true` on every version the provider creates.
1192
+ let storage = await options.createStorage()
1193
+ try {
1194
+ await storage.createDataset(writeDataset)
1195
+ await storage.createDataset(definitionDataset)
1196
+
1197
+ const inputVersion = async () => {
1198
+ const session = await storage.beginWrite({ dataset: definitionDataset })
1199
+ await session.writeRows([{ orderId: randomUUID(), customerName: "Input" }])
1200
+ const version = await session.commit()
1201
+ return { datasetId: definitionDataset.id, versionId: version.versionId }
1202
+ }
1203
+
1204
+ const rows = [{ orderId: "ord_1", customerName: "Ada" }]
1205
+ const commit = async (
1206
+ input: Pick<BeginDatasetWriteInput, "producer" | "lineage" | "mode" | "inputs">,
1207
+ written: readonly DatasetRow[] = rows
1208
+ ) => {
1209
+ const session = await storage.beginWrite({ dataset: writeDataset, ...input })
1210
+ await session.writeRows(written)
1211
+ const version = await session.commit()
1212
+ expect(version.outcome).toBe("created")
1213
+ return version
1214
+ }
1215
+
1216
+ const first = await commit({ inputs: [await inputVersion()] })
1217
+ expect(changed(first)).toEqual({ rowsChanged: true, lineageChanged: true })
1218
+
1219
+ // Identical rows computed from a new input version.
1220
+ const provenanceOnly = await commit({ inputs: [await inputVersion()] })
1221
+ expect(changed(provenanceOnly)).toEqual({ rowsChanged: false, lineageChanged: false })
1222
+
1223
+ // Identical rows that come from other columns.
1224
+ const lineageOnly = await commit({ producer: pipeline, lineage: copied })
1225
+ expect(changed(lineageOnly)).toEqual({ rowsChanged: false, lineageChanged: true })
1226
+
1227
+ const rowsOnly = await commit({ producer: pipeline, lineage: copied }, [
1228
+ { orderId: "ord_2", customerName: "Grace" },
1229
+ ])
1230
+ expect(changed(rowsOnly)).toEqual({ rowsChanged: true, lineageChanged: false })
1231
+
1232
+ // An append of no rows from a new input version.
1233
+ const emptyAppend = await commit(
1234
+ { producer: pipeline, lineage: copied, mode: "append", inputs: [await inputVersion()] },
1235
+ []
1236
+ )
1237
+ expect(changed(emptyAppend)).toEqual({ rowsChanged: false, lineageChanged: false })
1238
+
1239
+ const append = await commit({ producer: pipeline, lineage: copied, mode: "append" }, [
1240
+ { orderId: "ord_3", customerName: "Lin" },
1241
+ ])
1242
+ expect(changed(append)).toEqual({ rowsChanged: true, lineageChanged: false })
1243
+
1244
+ if (options.reopen) storage = await options.reopen(storage)
1245
+
1246
+ const committed = [first, provenanceOnly, lineageOnly, rowsOnly, emptyAppend, append]
1247
+ const expected = Object.fromEntries(committed.map((v) => [v.versionId, changed(v)]))
1248
+ const listed = await storage.listVersions(writeDataset.id)
1249
+ expect(Object.fromEntries(listed.map((v) => [v.versionId, changed(v)]))).toEqual(expected)
1250
+
1251
+ for (const version of committed) {
1252
+ expect(changed(await storage.getVersion(writeDataset.id, version.versionId))).toEqual(
1253
+ changed(version)
1254
+ )
1255
+ }
1256
+ expect(changed(await storage.getLatestVersion(writeDataset.id))).toEqual(changed(append))
1257
+ } finally {
1258
+ await options.teardown?.(storage)
1259
+ }
1260
+ })
1261
+
1262
+ test("a dataset's first version changes rows, even empty", () =>
1263
+ withStorage(async (storage) => {
1264
+ await storage.createDataset(writeDataset)
1265
+ const session = await storage.beginWrite({ dataset: writeDataset })
1266
+ const first = await session.commit()
1267
+
1268
+ expect(changed(first)).toEqual({ rowsChanged: true, lineageChanged: true })
1269
+ }))
1270
+
1271
+ test("a schema change changes rows", () =>
1272
+ withStorage(async (storage) => {
1273
+ if (schemaEvolution === "strict") return
1274
+
1275
+ const initial = defineDataset("contract.changes.schema_evolution", {
1276
+ schema: [col("invoiceId", "string")],
1277
+ })
1278
+ const widened = defineDataset("contract.changes.schema_evolution", {
1279
+ schema: [col("invoiceId", "string"), col("currency", "string", { nullable: true })],
1280
+ })
1281
+
1282
+ await storage.createDataset(initial)
1283
+ const session = await storage.beginWrite({ dataset: initial })
1284
+ await session.writeRows([{ invoiceId: "inv_1" }])
1285
+ await session.commit()
1286
+
1287
+ await storage.createDataset(widened)
1288
+ const [schemaVersion] = await storage.listVersions(initial.id, 1)
1289
+ expect(schemaVersion?.mode).toBe("schema")
1290
+ expect(changed(schemaVersion)).toEqual({ rowsChanged: true, lineageChanged: true })
1291
+ }))
1292
+ })
1181
1293
  })
1182
1294
  }
1183
1295
 
@@ -6,10 +6,14 @@ import {
6
6
  type ObjectQueryPredicate,
7
7
  validateObjectQuery,
8
8
  } from "../objects/query"
9
- import { defineObjectType, link, OntologyRegistry, prop } from "../ontology"
9
+ import { bindCurrentUserPredicate } from "../objects/query/current-user"
10
+ import { defineObjectType, link, OntologyRegistry, prop, ref } from "../ontology"
11
+ import type { UserRef } from "../ontology/user-ref"
12
+ import { viewConditionReadCondition } from "../security/visibility-keys"
10
13
  import { migrateStorage } from "../storage/migrations"
11
14
  import {
12
15
  compileConditionalObjectReadScope,
16
+ type ExpandedLinkValue,
13
17
  linkBatchKey,
14
18
  type ObjectReadCondition,
15
19
  type ObjectReadScopeFactory,
@@ -57,10 +61,30 @@ const Customer = defineObjectType({
57
61
  id: "ConditionCustomer",
58
62
  name: "Condition Customer",
59
63
  properties: [prop("id", "string", { required: true, primary: true }), prop("name", "string")],
60
- links: [link("invoices", Invoice)],
64
+ links: [link("invoices", Invoice), link("primaryInvoice", Invoice, { cardinality: "one" })],
61
65
  })
62
66
 
63
- const ontology = new OntologyRegistry({ sources: [Invoice, CreditNote, Customer] })
67
+ /** Who sees a ticket depends on its reader: the conditions compare `currentUser()`. */
68
+ const Ticket = defineObjectType({
69
+ id: "ConditionTicket",
70
+ name: "Condition Ticket",
71
+ properties: [
72
+ prop("id", "string", {
73
+ required: true,
74
+ primary: true,
75
+ query: { searchable: true, sortable: true },
76
+ }),
77
+ prop("status", "string", { query: { searchable: true, filterable: true } }),
78
+ prop("owner", ref.user(), { nullable: true, query: { searchable: true, filterable: true } }),
79
+ prop(
80
+ "watchers",
81
+ { type: "array", items: ref.user() },
82
+ { nullable: true, query: { searchable: true, filterable: true } }
83
+ ),
84
+ ],
85
+ })
86
+
87
+ const ontology = new OntologyRegistry({ sources: [Invoice, CreditNote, Customer, Ticket] })
64
88
 
65
89
  /**
66
90
  * Portable conditional-read contract shared by every storage provider.
@@ -393,6 +417,134 @@ export function runConditionalObjectReadScopeContractSuite<TStorage extends Stor
393
417
  })
394
418
  })
395
419
 
420
+ test("never expands through a hidden object", async () => {
421
+ await withHarness(async ({ harness }) => {
422
+ // Without conditions every edge is reached, so each expectation of the conditioned reader
423
+ // can only hold if the hidden draft and the links touching it stay out.
424
+ const unconditioned = createReader(harness.objectReadScopeFactory, [])
425
+ const conditioned = createReader(harness.objectReadScopeFactory, [noDrafts(Invoice.id)])
426
+
427
+ const customers = async (reader: ObjectReadStorage) => {
428
+ const [customer] = await queryRows(reader, {
429
+ kind: "expand",
430
+ input: {
431
+ kind: "limit",
432
+ limit: 10,
433
+ input: { kind: "start", objectTypeId: Customer.id },
434
+ },
435
+ expansions: [
436
+ { linkId: "primaryInvoice", direction: "outgoing" },
437
+ {
438
+ linkId: "invoices",
439
+ direction: "outgoing",
440
+ expand: [{ linkId: "related", direction: "outgoing" }],
441
+ },
442
+ ],
443
+ })
444
+
445
+ return {
446
+ primaryInvoice: linkedIds(customer?.links?.primaryInvoice),
447
+ invoices: Object.fromEntries(
448
+ linkedRows(customer?.links?.invoices).map((row) => [
449
+ row.primaryId,
450
+ linkedIds(row.links?.related),
451
+ ])
452
+ ),
453
+ }
454
+ }
455
+
456
+ expect(await customers(unconditioned)).toEqual({
457
+ primaryInvoice: ["inv-2"],
458
+ invoices: { "inv-1": ["inv-2", "inv-3"], "inv-2": ["inv-1"], "inv-3": [] },
459
+ })
460
+ // The hidden draft is neither a neighbour nor the middle of a nested expansion.
461
+ expect(await customers(conditioned)).toEqual({
462
+ primaryInvoice: [],
463
+ invoices: { "inv-1": ["inv-3"], "inv-3": [] },
464
+ })
465
+
466
+ const relatedFrom = async (reader: ObjectReadStorage) => {
467
+ const invoices = await queryRows(reader, {
468
+ kind: "expand",
469
+ input: {
470
+ kind: "limit",
471
+ limit: 10,
472
+ input: sorted({ kind: "start", objectTypeId: Invoice.id }, "amount"),
473
+ },
474
+ expansions: [
475
+ { linkId: "related", direction: "incoming", sourceObjectTypeId: Invoice.id },
476
+ ],
477
+ })
478
+
479
+ return invoices.map((row) => linkedIds(row.links?.related))
480
+ }
481
+
482
+ expect(await relatedFrom(unconditioned)).toEqual([["inv-2"], ["inv-1"], ["inv-1"]])
483
+ expect(await relatedFrom(conditioned)).toEqual([[], ["inv-1"]])
484
+ })
485
+ })
486
+
487
+ test("never traverses through a hidden object", async () => {
488
+ await withHarness(async ({ harness }) => {
489
+ // As above, the unconditioned reader shows what each traversal reaches through the draft.
490
+ const unconditioned = createReader(harness.objectReadScopeFactory, [])
491
+ const conditioned = createReader(harness.objectReadScopeFactory, [noDrafts(Invoice.id)])
492
+
493
+ const reached = async (reader: ObjectReadStorage, query: ObjectQuery) => {
494
+ const rows = await queryRows(reader, query)
495
+ return rows.map((row) => row.primaryId).sort()
496
+ }
497
+ const relatedOf = (input: ObjectQuery): ObjectQuery => ({
498
+ kind: "traverse",
499
+ direction: "outgoing",
500
+ linkId: "related",
501
+ input,
502
+ })
503
+ const refs = (...primaryIds: string[]): ObjectQuery => ({
504
+ kind: "refs",
505
+ refs: primaryIds.map((primaryId) => ({ objectTypeId: Invoice.id, primaryId })),
506
+ })
507
+
508
+ const twoHops = relatedOf({
509
+ kind: "traverse",
510
+ direction: "outgoing",
511
+ linkId: "invoices",
512
+ input: { kind: "start", objectTypeId: Customer.id },
513
+ })
514
+ expect(await reached(unconditioned, twoHops)).toEqual(["inv-1", "inv-2", "inv-3"])
515
+ expect(await reached(conditioned, twoHops)).toEqual(["inv-3"])
516
+
517
+ const fromRefs = relatedOf(refs("inv-1", "inv-2"))
518
+ expect(await reached(unconditioned, fromRefs)).toEqual(["inv-1", "inv-2", "inv-3"])
519
+ expect(await reached(conditioned, fromRefs)).toEqual(["inv-3"])
520
+
521
+ const fromSet = relatedOf({
522
+ kind: "set",
523
+ op: "union",
524
+ inputs: [refs("inv-2"), refs("inv-3")],
525
+ })
526
+ expect(await reached(unconditioned, fromSet)).toEqual(["inv-1"])
527
+ expect(await reached(conditioned, fromSet)).toEqual([])
528
+
529
+ // From the target side, the hidden draft is the source of a link to a visible invoice.
530
+ const sourcesOf: ObjectQuery = {
531
+ kind: "traverse",
532
+ direction: "incoming",
533
+ linkId: "related",
534
+ sourceObjectTypeId: Invoice.id,
535
+ input: refs("inv-1", "inv-3"),
536
+ }
537
+ expect(await reached(unconditioned, sourcesOf)).toEqual(["inv-1", "inv-2"])
538
+ expect(await reached(conditioned, sourcesOf)).toEqual(["inv-1"])
539
+ expect(await unconditioned.countObjects?.({ projectId, query: sourcesOf })).toEqual({
540
+ count: 2,
541
+ })
542
+ expect(await conditioned.countObjects?.({ projectId, query: sourcesOf })).toEqual({
543
+ count: 1,
544
+ })
545
+ })
546
+ })
547
+
396
548
  test("applies a condition to its concrete type only", async () => {
397
549
  await withHarness(async ({ harness }) => {
398
550
  const invoicesOnly = createReader(harness.objectReadScopeFactory, [noDrafts(Invoice.id)])
@@ -445,6 +597,84 @@ export function runConditionalObjectReadScopeContractSuite<TStorage extends Stor
445
597
  })
446
598
  })
447
599
 
600
+ // A provider may filter a member's reads on the keys of its conditions instead of their
601
+ // predicate. Both must show each reader the same objects, whatever its user's id.
602
+ test("shows a reader through its conditions' keys exactly what their predicate shows", async () => {
603
+ await withHarness(async ({ harness, fixture }) => {
604
+ const ids = ["usr_1", 'a"b', "a\\b", 'a", "b', "*", "u:usr_1"]
605
+ const users = ids.map((id): UserRef => ({ type: "user", id }))
606
+
607
+ const auth = harness.storage.auth
608
+ if (!auth) throw new Error("The conditional read contract requires auth storage.")
609
+ for (const [index, id] of ids.entries()) {
610
+ await auth.users.create({ projectId, id, email: `reader-${index}@example.com` })
611
+ }
612
+
613
+ await fixture.seed({
614
+ objects: users.flatMap((user, index) => [
615
+ object(Ticket.id, `t-${index}-owned`, {
616
+ id: `t-${index}-owned`,
617
+ status: "open",
618
+ owner: user,
619
+ }),
620
+ object(Ticket.id, `t-${index}-watched`, {
621
+ id: `t-${index}-watched`,
622
+ status: index % 2 === 0 ? "open" : "closed",
623
+ owner: users[(index + 1) % users.length]!,
624
+ watchers: [user, users[(index + 2) % users.length]!],
625
+ }),
626
+ ]),
627
+ links: [],
628
+ })
629
+
630
+ const me = { type: "currentUser" }
631
+ const conditions: ObjectQueryPredicate[] = [
632
+ { op: "eq", propertyId: "owner", value: me },
633
+ { op: "contains", propertyId: "watchers", value: me },
634
+ {
635
+ op: "or",
636
+ items: [
637
+ { op: "eq", propertyId: "status", value: "closed" },
638
+ { op: "in", propertyId: "owner", values: [me, users[0]!] },
639
+ ],
640
+ },
641
+ {
642
+ op: "and",
643
+ items: [
644
+ { op: "eq", propertyId: "status", value: "open" },
645
+ { op: "contains", propertyId: "watchers", value: me },
646
+ ],
647
+ },
648
+ // No keys: read through its predicate beside the keys of the others.
649
+ { op: "neq", propertyId: "owner", value: me },
650
+ ]
651
+
652
+ const visible = async (condition: ObjectReadCondition) => {
653
+ const reader = createReader(harness.objectReadScopeFactory, [condition])
654
+ const rows = await queryRows(reader, {
655
+ kind: "limit",
656
+ limit: 100,
657
+ input: sorted({ kind: "start", objectTypeId: Ticket.id }, "id"),
658
+ })
659
+ return rows.map((row) => row.primaryId)
660
+ }
661
+
662
+ for (const [index, condition] of conditions.entries()) {
663
+ const predicates = [ticketCondition(condition), ticketCondition(conditions[0]!)]
664
+ for (const user of [undefined, ...users]) {
665
+ const keyed = viewConditionReadCondition(Ticket.id, predicates, user)
666
+ const bound = bindCurrentUserPredicate({ op: "or", items: predicates }, user)
667
+
668
+ expect({ index, user, ids: await visible(keyed) }).toEqual({
669
+ index,
670
+ user,
671
+ ids: await visible({ objectTypeId: Ticket.id, predicate: bound }),
672
+ })
673
+ }
674
+ }
675
+ })
676
+ })
677
+
448
678
  test("never reads another project's objects or links", async () => {
449
679
  await withHarness(async ({ harness }) => {
450
680
  await migrateStorage(harness.storage, { projectId: otherProjectId, ontology })
@@ -555,7 +785,10 @@ function createReader(
555
785
  })
556
786
  }
557
787
 
558
- /** `status neq "draft"`, validated like a grant's condition so `scalarKind` is resolved. */
788
+ /**
789
+ * `status neq "draft"`, validated like a grant's condition so `scalarKind` is resolved, and read the
790
+ * way a member reads it: with its keys, which a provider may filter on instead of the predicate.
791
+ */
559
792
  function noDrafts(objectTypeId: string): ObjectReadCondition {
560
793
  const predicate: ObjectQueryPredicate = { op: "neq", propertyId: "status", value: "draft" }
561
794
  const { query } = validateObjectQuery(
@@ -564,7 +797,35 @@ function noDrafts(objectTypeId: string): ObjectReadCondition {
564
797
  )
565
798
  if (query.kind !== "filter") throw new Error("expected a validated filter")
566
799
 
567
- return { objectTypeId, predicate: query.predicate }
800
+ return viewConditionReadCondition(objectTypeId, [query.predicate], undefined)
801
+ }
802
+
803
+ /** A ticket condition as a grant's validation returns it, `currentUser()` left unbound. */
804
+ function ticketCondition(predicate: ObjectQueryPredicate): ObjectQueryPredicate {
805
+ const { query } = validateObjectQuery(
806
+ { kind: "filter", input: { kind: "start", objectTypeId: Ticket.id }, predicate },
807
+ { ontology }
808
+ )
809
+ if (query.kind !== "filter") throw new Error("expected a validated filter")
810
+ return query.predicate
811
+ }
812
+
813
+ /** Run a query as the executor does, so a provider pushes down what it can. */
814
+ async function queryRows(reader: ObjectReadStorage, query: ObjectQuery) {
815
+ const result = await executeObjectQuery({ projectId, query }, { ontology, storage: reader })
816
+ return result.objects
817
+ }
818
+
819
+ /** An expanded link's neighbours, whatever its cardinality. */
820
+ function linkedRows(value: ExpandedLinkValue | undefined) {
821
+ if (Array.isArray(value)) return value
822
+ return value ? [value] : []
823
+ }
824
+
825
+ function linkedIds(value: ExpandedLinkValue | undefined): string[] {
826
+ return linkedRows(value)
827
+ .map((row) => row.primaryId)
828
+ .sort()
568
829
  }
569
830
 
570
831
  function sorted(
@@ -595,6 +856,7 @@ async function seed(fixture: MaterializerTestFixture): Promise<void> {
595
856
  linkRow(Customer.id, "cust-1", "invoices", Invoice.id, "inv-1"),
596
857
  linkRow(Customer.id, "cust-1", "invoices", Invoice.id, "inv-2"),
597
858
  linkRow(Customer.id, "cust-1", "invoices", Invoice.id, "inv-3"),
859
+ linkRow(Customer.id, "cust-1", "primaryInvoice", Invoice.id, "inv-2"),
598
860
  linkRow(Invoice.id, "inv-1", "related", Invoice.id, "inv-2"),
599
861
  linkRow(Invoice.id, "inv-2", "related", Invoice.id, "inv-1"),
600
862
  linkRow(Invoice.id, "inv-1", "related", Invoice.id, "inv-3"),
@@ -689,6 +689,81 @@ export function runObjectQueryProviderContractSuite<TStorage extends Storage>(
689
689
  })
690
690
  })
691
691
 
692
+ // A guard on the tie order: break ties in identity order whatever the direction, and each
693
+ // descending list below stops being the ascending one backwards.
694
+ test("lists a descending sort as the ascending one backwards, ties included", async () => {
695
+ await withStorage(async ({ objects: storage, fixture }) => {
696
+ const labelCodes = ["b", null, "a", "b", "a", null, "b"]
697
+ const deviceNames = ["dimmer", "sensor", "dimmer", "sensor"]
698
+ await fixture.seed({
699
+ objects: [
700
+ ...labelCodes.map((code, index) =>
701
+ objectSeed(Label.id, `tie-${index}`, { id: `tie-${index}`, code })
702
+ ),
703
+ objectSeed(Room.id, "room-ties", { id: "room-ties" }),
704
+ ...deviceNames.map((name, index) =>
705
+ objectSeed(Device.id, `device-tie-${index}`, { id: `device-tie-${index}`, name })
706
+ ),
707
+ ],
708
+ links: deviceNames.map((_, index) =>
709
+ linkSeed(Room.id, "room-ties", "hasDevice", Device.id, `device-tie-${index}`)
710
+ ),
711
+ })
712
+
713
+ const run = (query: ObjectQuery) =>
714
+ executeObjectQuery(
715
+ { projectId, query },
716
+ { ontology: objectQueryContractOntology, storage }
717
+ )
718
+ const byCode = (direction: "asc" | "desc"): ObjectQuery => ({
719
+ kind: "sort",
720
+ fields: [{ kind: "property", propertyId: "code", direction }],
721
+ input: { kind: "start", objectTypeId: Label.id },
722
+ })
723
+
724
+ const ascending = ids(await run(byCode("asc")))
725
+ const descending = ids(await run(byCode("desc")))
726
+
727
+ // Null values sort last in both directions, so each part is reversed on its own.
728
+ const valued = ascending.slice(0, 5)
729
+ const nulls = ascending.slice(5)
730
+ expect(descending).toEqual([...valued.reverse(), ...nulls.reverse()])
731
+
732
+ const paged: string[] = []
733
+ let pageToken: string | undefined
734
+ do {
735
+ const page = await run({ kind: "page", pageSize: 2, pageToken, input: byCode("desc") })
736
+ paged.push(...ids(page))
737
+ pageToken = page.nextPageToken
738
+ } while (pageToken)
739
+
740
+ expect(paged).toEqual(descending)
741
+
742
+ // A parent's linked objects tie the same way.
743
+ const devices = async (direction: "asc" | "desc") => {
744
+ const result = await run({
745
+ kind: "expand",
746
+ expansions: [
747
+ {
748
+ linkId: "hasDevice",
749
+ direction: "outgoing",
750
+ limit: deviceNames.length,
751
+ orderBy: [{ kind: "property", propertyId: "name", direction }],
752
+ },
753
+ ],
754
+ input: { kind: "limit", limit: 10, input: { kind: "start", objectTypeId: Room.id } },
755
+ })
756
+ const room = result.objects.find((row) => row.primaryId === "room-ties")
757
+ const linked = room?.links?.hasDevice
758
+ return Array.isArray(linked) ? linked.map((row) => row.primaryId) : []
759
+ }
760
+
761
+ const ascendingDevices = await devices("asc")
762
+ expect(ascendingDevices).toHaveLength(deviceNames.length)
763
+ expect(await devices("desc")).toEqual([...ascendingDevices].reverse())
764
+ })
765
+ })
766
+
692
767
  test("keeps page tokens stable when projection hides sorted cursor fields", async () => {
693
768
  await withStorage(async ({ objects: storage, fixture }) => {
694
769
  await seedObjectQueryContractData(fixture)
@@ -3,4 +3,5 @@ export type { QueueDelivery, QueueDeliveryState, QueueSettlementResult } from ".
3
3
  export { QueueDeliveryLeaseLostError } from "./queue-delivery"
4
4
  export type { QueueWorkerConfig, QueueWorkerFailureDecision } from "./queue-worker"
5
5
  export { isAbortError, QueueWorker } from "./queue-worker"
6
+ export { retryUnstartedRun } from "./unstarted-run"
6
7
  export { Worker } from "./worker"
@@ -0,0 +1,18 @@
1
+ import type { QueueWorkerFailureDecision } from "./queue-worker"
2
+
3
+ const UNSTARTED_RUN_ATTEMPTS = 3
4
+ const UNSTARTED_RUN_RETRY_INITIAL_DELAY_MS = 250
5
+
6
+ /**
7
+ * A run that has not started has committed nothing, so a job that fails before starting it is
8
+ * retried with a short doubling backoff. Returns `undefined` once its attempts are spent: the
9
+ * worker then fails the run, so that later triggers stop joining it.
10
+ */
11
+ export function retryUnstartedRun(
12
+ attempt: number
13
+ ): Extract<QueueWorkerFailureDecision, { readonly kind: "retry" }> | undefined {
14
+ if (attempt >= UNSTARTED_RUN_ATTEMPTS) return undefined
15
+
16
+ const delayMs = UNSTARTED_RUN_RETRY_INITIAL_DELAY_MS * 2 ** (Math.max(attempt, 1) - 1)
17
+ return { kind: "retry", availableAt: new Date(Date.now() + delayMs).toISOString() }
18
+ }