ramosedb 0.0.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (960) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +17 -0
  3. package/README.md +57 -2
  4. package/dist/Auth.d.ts +55 -0
  5. package/dist/Auth.d.ts.map +1 -0
  6. package/dist/Auth.js +50 -0
  7. package/dist/Auth.js.map +1 -0
  8. package/dist/Database.d.ts +40 -0
  9. package/dist/Database.d.ts.map +1 -0
  10. package/dist/Database.js +62 -0
  11. package/dist/Database.js.map +1 -0
  12. package/dist/Providers.d.ts +8 -0
  13. package/dist/Providers.d.ts.map +1 -0
  14. package/dist/Providers.js +9 -0
  15. package/dist/Providers.js.map +1 -0
  16. package/dist/RamoseEnv.d.ts +37 -0
  17. package/dist/RamoseEnv.d.ts.map +1 -0
  18. package/dist/RamoseEnv.js +2 -0
  19. package/dist/RamoseEnv.js.map +1 -0
  20. package/dist/Server.d.ts +100 -0
  21. package/dist/Server.d.ts.map +1 -0
  22. package/dist/Server.js +263 -0
  23. package/dist/Server.js.map +1 -0
  24. package/dist/ServerRuntime.d.ts +10 -0
  25. package/dist/ServerRuntime.d.ts.map +1 -0
  26. package/dist/ServerRuntime.js +11 -0
  27. package/dist/ServerRuntime.js.map +1 -0
  28. package/dist/better-auth/client.d.ts +19 -0
  29. package/dist/better-auth/client.d.ts.map +1 -0
  30. package/dist/better-auth/client.js +110 -0
  31. package/dist/better-auth/client.js.map +1 -0
  32. package/dist/better-auth/index.d.ts +140 -0
  33. package/dist/better-auth/index.d.ts.map +1 -0
  34. package/dist/better-auth/index.js +168 -0
  35. package/dist/better-auth/index.js.map +1 -0
  36. package/dist/client/activation.d.ts +2 -0
  37. package/dist/client/activation.d.ts.map +1 -0
  38. package/dist/client/activation.js +33 -0
  39. package/dist/client/activation.js.map +1 -0
  40. package/dist/client/catalog.d.ts +15 -0
  41. package/dist/client/catalog.d.ts.map +1 -0
  42. package/dist/client/catalog.js +48 -0
  43. package/dist/client/catalog.js.map +1 -0
  44. package/dist/client/changesets.d.ts +85 -0
  45. package/dist/client/changesets.d.ts.map +1 -0
  46. package/dist/client/changesets.js +160 -0
  47. package/dist/client/changesets.js.map +1 -0
  48. package/dist/client/client.d.ts +45 -0
  49. package/dist/client/client.d.ts.map +1 -0
  50. package/dist/client/client.js +425 -0
  51. package/dist/client/client.js.map +1 -0
  52. package/dist/client/database.d.ts +163 -0
  53. package/dist/client/database.d.ts.map +1 -0
  54. package/dist/client/database.js +795 -0
  55. package/dist/client/database.js.map +1 -0
  56. package/dist/client/entity.d.ts +63 -0
  57. package/dist/client/entity.d.ts.map +1 -0
  58. package/dist/client/entity.js +141 -0
  59. package/dist/client/entity.js.map +1 -0
  60. package/dist/client/errors.d.ts +67 -0
  61. package/dist/client/errors.d.ts.map +1 -0
  62. package/dist/client/errors.js +39 -0
  63. package/dist/client/errors.js.map +1 -0
  64. package/dist/client/index.d.ts +13 -0
  65. package/dist/client/index.d.ts.map +1 -0
  66. package/dist/client/index.js +6 -0
  67. package/dist/client/index.js.map +1 -0
  68. package/dist/client/mutation-schema.d.ts +92 -0
  69. package/dist/client/mutation-schema.d.ts.map +1 -0
  70. package/dist/client/mutation-schema.js +2 -0
  71. package/dist/client/mutation-schema.js.map +1 -0
  72. package/dist/client/mutation.d.ts +25 -0
  73. package/dist/client/mutation.d.ts.map +1 -0
  74. package/dist/client/mutation.js +75 -0
  75. package/dist/client/mutation.js.map +1 -0
  76. package/dist/client/operations.d.ts +39 -0
  77. package/dist/client/operations.d.ts.map +1 -0
  78. package/dist/client/operations.js +183 -0
  79. package/dist/client/operations.js.map +1 -0
  80. package/dist/client/query.d.ts +53 -0
  81. package/dist/client/query.d.ts.map +1 -0
  82. package/dist/client/query.js +85 -0
  83. package/dist/client/query.js.map +1 -0
  84. package/dist/client/receipt.d.ts +53 -0
  85. package/dist/client/receipt.d.ts.map +1 -0
  86. package/dist/client/receipt.js +79 -0
  87. package/dist/client/receipt.js.map +1 -0
  88. package/dist/client/submission.d.ts +44 -0
  89. package/dist/client/submission.d.ts.map +1 -0
  90. package/dist/client/submission.js +165 -0
  91. package/dist/client/submission.js.map +1 -0
  92. package/dist/client/subscription.d.ts +18 -0
  93. package/dist/client/subscription.d.ts.map +1 -0
  94. package/dist/client/subscription.js +75 -0
  95. package/dist/client/subscription.js.map +1 -0
  96. package/dist/client/sync.d.ts +32 -0
  97. package/dist/client/sync.d.ts.map +1 -0
  98. package/dist/client/sync.js +34 -0
  99. package/dist/client/sync.js.map +1 -0
  100. package/dist/client/view.d.ts +37 -0
  101. package/dist/client/view.d.ts.map +1 -0
  102. package/dist/client/view.js +112 -0
  103. package/dist/client/view.js.map +1 -0
  104. package/dist/db/Binding.d.ts +79 -0
  105. package/dist/db/Binding.d.ts.map +1 -0
  106. package/dist/db/Binding.js +138 -0
  107. package/dist/db/Binding.js.map +1 -0
  108. package/dist/db/Composer.d.ts +7 -0
  109. package/dist/db/Composer.d.ts.map +1 -0
  110. package/dist/db/Composer.js +6 -0
  111. package/dist/db/Composer.js.map +1 -0
  112. package/dist/db/DatabaseName.d.ts +7 -0
  113. package/dist/db/DatabaseName.d.ts.map +1 -0
  114. package/dist/db/DatabaseName.js +9 -0
  115. package/dist/db/DatabaseName.js.map +1 -0
  116. package/dist/db/Eid.d.ts +19 -0
  117. package/dist/db/Eid.d.ts.map +1 -0
  118. package/dist/db/Eid.js +2 -0
  119. package/dist/db/Eid.js.map +1 -0
  120. package/dist/db/Entity.d.ts +133 -0
  121. package/dist/db/Entity.d.ts.map +1 -0
  122. package/dist/db/Entity.js +104 -0
  123. package/dist/db/Entity.js.map +1 -0
  124. package/dist/db/Errors.d.ts +138 -0
  125. package/dist/db/Errors.d.ts.map +1 -0
  126. package/dist/db/Errors.js +171 -0
  127. package/dist/db/Errors.js.map +1 -0
  128. package/dist/db/Field.d.ts +170 -0
  129. package/dist/db/Field.d.ts.map +1 -0
  130. package/dist/db/Field.js +187 -0
  131. package/dist/db/Field.js.map +1 -0
  132. package/dist/db/IdentName.d.ts +94 -0
  133. package/dist/db/IdentName.d.ts.map +1 -0
  134. package/dist/db/IdentName.js +34 -0
  135. package/dist/db/IdentName.js.map +1 -0
  136. package/dist/db/Operation.d.ts +441 -0
  137. package/dist/db/Operation.d.ts.map +1 -0
  138. package/dist/db/Operation.js +237 -0
  139. package/dist/db/Operation.js.map +1 -0
  140. package/dist/db/Projection.d.ts +97 -0
  141. package/dist/db/Projection.d.ts.map +1 -0
  142. package/dist/db/Projection.js +183 -0
  143. package/dist/db/Projection.js.map +1 -0
  144. package/dist/db/Pull.d.ts +361 -0
  145. package/dist/db/Pull.d.ts.map +1 -0
  146. package/dist/db/Pull.js +547 -0
  147. package/dist/db/Pull.js.map +1 -0
  148. package/dist/db/Schema.d.ts +37 -0
  149. package/dist/db/Schema.d.ts.map +1 -0
  150. package/dist/db/Schema.js +94 -0
  151. package/dist/db/Schema.js.map +1 -0
  152. package/dist/db/Trait.d.ts +129 -0
  153. package/dist/db/Trait.d.ts.map +1 -0
  154. package/dist/db/Trait.js +65 -0
  155. package/dist/db/Trait.js.map +1 -0
  156. package/dist/db/Tx.d.ts +128 -0
  157. package/dist/db/Tx.d.ts.map +1 -0
  158. package/dist/db/Tx.js +248 -0
  159. package/dist/db/Tx.js.map +1 -0
  160. package/dist/db/allocations.d.ts +44 -0
  161. package/dist/db/allocations.d.ts.map +1 -0
  162. package/dist/db/allocations.js +70 -0
  163. package/dist/db/allocations.js.map +1 -0
  164. package/dist/db/attrRef.d.ts +5 -0
  165. package/dist/db/attrRef.d.ts.map +1 -0
  166. package/dist/db/attrRef.js +6 -0
  167. package/dist/db/attrRef.js.map +1 -0
  168. package/dist/db/compose.d.ts +26 -0
  169. package/dist/db/compose.d.ts.map +1 -0
  170. package/dist/db/compose.js +105 -0
  171. package/dist/db/compose.js.map +1 -0
  172. package/dist/db/composition.d.ts +4 -0
  173. package/dist/db/composition.d.ts.map +1 -0
  174. package/dist/db/composition.js +24 -0
  175. package/dist/db/composition.js.map +1 -0
  176. package/dist/db/creation.d.ts +102 -0
  177. package/dist/db/creation.d.ts.map +1 -0
  178. package/dist/db/creation.js +448 -0
  179. package/dist/db/creation.js.map +1 -0
  180. package/dist/db/deployedSchema.d.ts +12 -0
  181. package/dist/db/deployedSchema.d.ts.map +1 -0
  182. package/dist/db/deployedSchema.js +80 -0
  183. package/dist/db/deployedSchema.js.map +1 -0
  184. package/dist/db/documentation.d.ts +4 -0
  185. package/dist/db/documentation.d.ts.map +1 -0
  186. package/dist/db/documentation.js +4 -0
  187. package/dist/db/documentation.js.map +1 -0
  188. package/dist/db/ensure.d.ts +16 -0
  189. package/dist/db/ensure.d.ts.map +1 -0
  190. package/dist/db/ensure.js +48 -0
  191. package/dist/db/ensure.js.map +1 -0
  192. package/dist/db/entityArg.d.ts +15 -0
  193. package/dist/db/entityArg.d.ts.map +1 -0
  194. package/dist/db/entityArg.js +71 -0
  195. package/dist/db/entityArg.js.map +1 -0
  196. package/dist/db/equal.d.ts +4 -0
  197. package/dist/db/equal.d.ts.map +1 -0
  198. package/dist/db/equal.js +2 -0
  199. package/dist/db/equal.js.map +1 -0
  200. package/dist/db/idents.d.ts +90 -0
  201. package/dist/db/idents.d.ts.map +1 -0
  202. package/dist/db/idents.js +2 -0
  203. package/dist/db/idents.js.map +1 -0
  204. package/dist/db/index.d.ts +27 -0
  205. package/dist/db/index.d.ts.map +1 -0
  206. package/dist/db/index.js +20 -0
  207. package/dist/db/index.js.map +1 -0
  208. package/dist/db/internal.d.ts +27 -0
  209. package/dist/db/internal.d.ts.map +1 -0
  210. package/dist/db/internal.js +27 -0
  211. package/dist/db/internal.js.map +1 -0
  212. package/dist/db/query/cursor.d.ts +13 -0
  213. package/dist/db/query/cursor.d.ts.map +1 -0
  214. package/dist/db/query/cursor.js +150 -0
  215. package/dist/db/query/cursor.js.map +1 -0
  216. package/dist/db/query/elemFilter.d.ts +7 -0
  217. package/dist/db/query/elemFilter.d.ts.map +1 -0
  218. package/dist/db/query/elemFilter.js +280 -0
  219. package/dist/db/query/elemFilter.js.map +1 -0
  220. package/dist/db/query/fluent.d.ts +92 -0
  221. package/dist/db/query/fluent.d.ts.map +1 -0
  222. package/dist/db/query/fluent.js +125 -0
  223. package/dist/db/query/fluent.js.map +1 -0
  224. package/dist/db/query/focus.d.ts +42 -0
  225. package/dist/db/query/focus.d.ts.map +1 -0
  226. package/dist/db/query/focus.js +2 -0
  227. package/dist/db/query/focus.js.map +1 -0
  228. package/dist/db/query/index.d.ts +7 -0
  229. package/dist/db/query/index.d.ts.map +1 -0
  230. package/dist/db/query/index.js +6 -0
  231. package/dist/db/query/index.js.map +1 -0
  232. package/dist/db/query/kernel.d.ts +215 -0
  233. package/dist/db/query/kernel.d.ts.map +1 -0
  234. package/dist/db/query/kernel.js +284 -0
  235. package/dist/db/query/kernel.js.map +1 -0
  236. package/dist/db/query/lib.d.ts +168 -0
  237. package/dist/db/query/lib.d.ts.map +1 -0
  238. package/dist/db/query/lib.js +175 -0
  239. package/dist/db/query/lib.js.map +1 -0
  240. package/dist/db/query/query.d.ts +209 -0
  241. package/dist/db/query/query.d.ts.map +1 -0
  242. package/dist/db/query/query.js +1536 -0
  243. package/dist/db/query/query.js.map +1 -0
  244. package/dist/db/query/stdlib/failures.d.ts +91 -0
  245. package/dist/db/query/stdlib/failures.d.ts.map +1 -0
  246. package/dist/db/query/stdlib/failures.js +57 -0
  247. package/dist/db/query/stdlib/failures.js.map +1 -0
  248. package/dist/db/query/stdlib/implementations.d.ts +5 -0
  249. package/dist/db/query/stdlib/implementations.d.ts.map +1 -0
  250. package/dist/db/query/stdlib/implementations.js +208 -0
  251. package/dist/db/query/stdlib/implementations.js.map +1 -0
  252. package/dist/db/query/stdlib/index.d.ts +6 -0
  253. package/dist/db/query/stdlib/index.d.ts.map +1 -0
  254. package/dist/db/query/stdlib/index.js +6 -0
  255. package/dist/db/query/stdlib/index.js.map +1 -0
  256. package/dist/db/query/stdlib/manifest.d.ts +3 -0
  257. package/dist/db/query/stdlib/manifest.d.ts.map +1 -0
  258. package/dist/db/query/stdlib/manifest.js +1067 -0
  259. package/dist/db/query/stdlib/manifest.js.map +1 -0
  260. package/dist/db/query/stdlib/registry.d.ts +22 -0
  261. package/dist/db/query/stdlib/registry.d.ts.map +1 -0
  262. package/dist/db/query/stdlib/registry.js +144 -0
  263. package/dist/db/query/stdlib/registry.js.map +1 -0
  264. package/dist/db/query/stdlib/types.d.ts +50 -0
  265. package/dist/db/query/stdlib/types.d.ts.map +1 -0
  266. package/dist/db/query/stdlib/types.js +17 -0
  267. package/dist/db/query/stdlib/types.js.map +1 -0
  268. package/dist/db/query/stdlib/values.d.ts +17 -0
  269. package/dist/db/query/stdlib/values.d.ts.map +1 -0
  270. package/dist/db/query/stdlib/values.js +200 -0
  271. package/dist/db/query/stdlib/values.js.map +1 -0
  272. package/dist/db/query/surface.d.ts +15 -0
  273. package/dist/db/query/surface.d.ts.map +1 -0
  274. package/dist/db/query/surface.js +14 -0
  275. package/dist/db/query/surface.js.map +1 -0
  276. package/dist/db/reachability.d.ts +40 -0
  277. package/dist/db/reachability.d.ts.map +1 -0
  278. package/dist/db/reachability.js +118 -0
  279. package/dist/db/reachability.js.map +1 -0
  280. package/dist/db/refs.d.ts +46 -0
  281. package/dist/db/refs.d.ts.map +1 -0
  282. package/dist/db/refs.js +69 -0
  283. package/dist/db/refs.js.map +1 -0
  284. package/dist/db/shapes.d.ts +227 -0
  285. package/dist/db/shapes.d.ts.map +1 -0
  286. package/dist/db/shapes.js +246 -0
  287. package/dist/db/shapes.js.map +1 -0
  288. package/dist/db/valueTypes.d.ts +92 -0
  289. package/dist/db/valueTypes.d.ts.map +1 -0
  290. package/dist/db/valueTypes.js +105 -0
  291. package/dist/db/valueTypes.js.map +1 -0
  292. package/dist/errorHttp.d.ts +27 -0
  293. package/dist/errorHttp.d.ts.map +1 -0
  294. package/dist/errorHttp.js +95 -0
  295. package/dist/errorHttp.js.map +1 -0
  296. package/dist/index.d.ts +7 -0
  297. package/dist/index.d.ts.map +1 -0
  298. package/dist/index.js +7 -0
  299. package/dist/index.js.map +1 -0
  300. package/dist/internal/authorization/authoring/compile.d.ts +132 -0
  301. package/dist/internal/authorization/authoring/compile.d.ts.map +1 -0
  302. package/dist/internal/authorization/authoring/compile.js +634 -0
  303. package/dist/internal/authorization/authoring/compile.js.map +1 -0
  304. package/dist/internal/authorization/authoring/expr.d.ts +25 -0
  305. package/dist/internal/authorization/authoring/expr.d.ts.map +1 -0
  306. package/dist/internal/authorization/authoring/expr.js +56 -0
  307. package/dist/internal/authorization/authoring/expr.js.map +1 -0
  308. package/dist/internal/authorization/authoring/index.d.ts +10 -0
  309. package/dist/internal/authorization/authoring/index.d.ts.map +1 -0
  310. package/dist/internal/authorization/authoring/index.js +8 -0
  311. package/dist/internal/authorization/authoring/index.js.map +1 -0
  312. package/dist/internal/authorization/authoring/invoke.d.ts +8 -0
  313. package/dist/internal/authorization/authoring/invoke.d.ts.map +1 -0
  314. package/dist/internal/authorization/authoring/invoke.js +7 -0
  315. package/dist/internal/authorization/authoring/invoke.js.map +1 -0
  316. package/dist/internal/authorization/authoring/operations.d.ts +81 -0
  317. package/dist/internal/authorization/authoring/operations.d.ts.map +1 -0
  318. package/dist/internal/authorization/authoring/operations.js +591 -0
  319. package/dist/internal/authorization/authoring/operations.js.map +1 -0
  320. package/dist/internal/authorization/authoring/path.d.ts +20 -0
  321. package/dist/internal/authorization/authoring/path.d.ts.map +1 -0
  322. package/dist/internal/authorization/authoring/path.js +109 -0
  323. package/dist/internal/authorization/authoring/path.js.map +1 -0
  324. package/dist/internal/authorization/authoring/policy.d.ts +120 -0
  325. package/dist/internal/authorization/authoring/policy.d.ts.map +1 -0
  326. package/dist/internal/authorization/authoring/policy.js +218 -0
  327. package/dist/internal/authorization/authoring/policy.js.map +1 -0
  328. package/dist/internal/authorization/authoring/read.d.ts +13 -0
  329. package/dist/internal/authorization/authoring/read.d.ts.map +1 -0
  330. package/dist/internal/authorization/authoring/read.js +27 -0
  331. package/dist/internal/authorization/authoring/read.js.map +1 -0
  332. package/dist/internal/authorization/authoring/types.d.ts +127 -0
  333. package/dist/internal/authorization/authoring/types.d.ts.map +1 -0
  334. package/dist/internal/authorization/authoring/types.js +43 -0
  335. package/dist/internal/authorization/authoring/types.js.map +1 -0
  336. package/dist/internal/authorization/bind.d.ts +687 -0
  337. package/dist/internal/authorization/bind.d.ts.map +1 -0
  338. package/dist/internal/authorization/bind.js +485 -0
  339. package/dist/internal/authorization/bind.js.map +1 -0
  340. package/dist/internal/authorization/bounds.d.ts +13 -0
  341. package/dist/internal/authorization/bounds.d.ts.map +1 -0
  342. package/dist/internal/authorization/bounds.js +9 -0
  343. package/dist/internal/authorization/bounds.js.map +1 -0
  344. package/dist/internal/authorization/canonical-json.d.ts +6 -0
  345. package/dist/internal/authorization/canonical-json.d.ts.map +1 -0
  346. package/dist/internal/authorization/canonical-json.js +65 -0
  347. package/dist/internal/authorization/canonical-json.js.map +1 -0
  348. package/dist/internal/authorization/catalog-unit.d.ts +1033 -0
  349. package/dist/internal/authorization/catalog-unit.d.ts.map +1 -0
  350. package/dist/internal/authorization/catalog-unit.js +303 -0
  351. package/dist/internal/authorization/catalog-unit.js.map +1 -0
  352. package/dist/internal/authorization/catalog.d.ts +472 -0
  353. package/dist/internal/authorization/catalog.d.ts.map +1 -0
  354. package/dist/internal/authorization/catalog.js +134 -0
  355. package/dist/internal/authorization/catalog.js.map +1 -0
  356. package/dist/internal/authorization/changesets.d.ts +54 -0
  357. package/dist/internal/authorization/changesets.d.ts.map +1 -0
  358. package/dist/internal/authorization/changesets.js +156 -0
  359. package/dist/internal/authorization/changesets.js.map +1 -0
  360. package/dist/internal/authorization/composition.d.ts +10 -0
  361. package/dist/internal/authorization/composition.d.ts.map +1 -0
  362. package/dist/internal/authorization/composition.js +28 -0
  363. package/dist/internal/authorization/composition.js.map +1 -0
  364. package/dist/internal/authorization/database-bindings.d.ts +48 -0
  365. package/dist/internal/authorization/database-bindings.d.ts.map +1 -0
  366. package/dist/internal/authorization/database-bindings.js +101 -0
  367. package/dist/internal/authorization/database-bindings.js.map +1 -0
  368. package/dist/internal/authorization/database-target.d.ts +75 -0
  369. package/dist/internal/authorization/database-target.d.ts.map +1 -0
  370. package/dist/internal/authorization/database-target.js +65 -0
  371. package/dist/internal/authorization/database-target.js.map +1 -0
  372. package/dist/internal/authorization/decode.d.ts +1704 -0
  373. package/dist/internal/authorization/decode.d.ts.map +1 -0
  374. package/dist/internal/authorization/decode.js +294 -0
  375. package/dist/internal/authorization/decode.js.map +1 -0
  376. package/dist/internal/authorization/definitions.d.ts +66 -0
  377. package/dist/internal/authorization/definitions.d.ts.map +1 -0
  378. package/dist/internal/authorization/definitions.js +335 -0
  379. package/dist/internal/authorization/definitions.js.map +1 -0
  380. package/dist/internal/authorization/deployed.d.ts +43 -0
  381. package/dist/internal/authorization/deployed.d.ts.map +1 -0
  382. package/dist/internal/authorization/deployed.js +184 -0
  383. package/dist/internal/authorization/deployed.js.map +1 -0
  384. package/dist/internal/authorization/entity-targets.d.ts +68 -0
  385. package/dist/internal/authorization/entity-targets.d.ts.map +1 -0
  386. package/dist/internal/authorization/entity-targets.js +244 -0
  387. package/dist/internal/authorization/entity-targets.js.map +1 -0
  388. package/dist/internal/authorization/expr.d.ts +259 -0
  389. package/dist/internal/authorization/expr.d.ts.map +1 -0
  390. package/dist/internal/authorization/expr.js +55 -0
  391. package/dist/internal/authorization/expr.js.map +1 -0
  392. package/dist/internal/authorization/failures.d.ts +78 -0
  393. package/dist/internal/authorization/failures.d.ts.map +1 -0
  394. package/dist/internal/authorization/failures.js +22 -0
  395. package/dist/internal/authorization/failures.js.map +1 -0
  396. package/dist/internal/authorization/identities.d.ts +207 -0
  397. package/dist/internal/authorization/identities.d.ts.map +1 -0
  398. package/dist/internal/authorization/identities.js +71 -0
  399. package/dist/internal/authorization/identities.js.map +1 -0
  400. package/dist/internal/authorization/index.d.ts +33 -0
  401. package/dist/internal/authorization/index.d.ts.map +1 -0
  402. package/dist/internal/authorization/index.js +33 -0
  403. package/dist/internal/authorization/index.js.map +1 -0
  404. package/dist/internal/authorization/install/normalize.d.ts +196 -0
  405. package/dist/internal/authorization/install/normalize.d.ts.map +1 -0
  406. package/dist/internal/authorization/install/normalize.js +168 -0
  407. package/dist/internal/authorization/install/normalize.js.map +1 -0
  408. package/dist/internal/authorization/install/plan.d.ts +8 -0
  409. package/dist/internal/authorization/install/plan.d.ts.map +1 -0
  410. package/dist/internal/authorization/install/plan.js +177 -0
  411. package/dist/internal/authorization/install/plan.js.map +1 -0
  412. package/dist/internal/authorization/install.d.ts +404 -0
  413. package/dist/internal/authorization/install.d.ts.map +1 -0
  414. package/dist/internal/authorization/install.js +103 -0
  415. package/dist/internal/authorization/install.js.map +1 -0
  416. package/dist/internal/authorization/invocation-codec.d.ts +10 -0
  417. package/dist/internal/authorization/invocation-codec.d.ts.map +1 -0
  418. package/dist/internal/authorization/invocation-codec.js +36 -0
  419. package/dist/internal/authorization/invocation-codec.js.map +1 -0
  420. package/dist/internal/authorization/invocation-receipts.d.ts +192 -0
  421. package/dist/internal/authorization/invocation-receipts.d.ts.map +1 -0
  422. package/dist/internal/authorization/invocation-receipts.js +546 -0
  423. package/dist/internal/authorization/invocation-receipts.js.map +1 -0
  424. package/dist/internal/authorization/ir.d.ts +1465 -0
  425. package/dist/internal/authorization/ir.d.ts.map +1 -0
  426. package/dist/internal/authorization/ir.js +131 -0
  427. package/dist/internal/authorization/ir.js.map +1 -0
  428. package/dist/internal/authorization/json.d.ts +8 -0
  429. package/dist/internal/authorization/json.d.ts.map +1 -0
  430. package/dist/internal/authorization/json.js +13 -0
  431. package/dist/internal/authorization/json.js.map +1 -0
  432. package/dist/internal/authorization/live.d.ts +38 -0
  433. package/dist/internal/authorization/live.d.ts.map +1 -0
  434. package/dist/internal/authorization/live.js +227 -0
  435. package/dist/internal/authorization/live.js.map +1 -0
  436. package/dist/internal/authorization/operation-grant.d.ts +16 -0
  437. package/dist/internal/authorization/operation-grant.d.ts.map +1 -0
  438. package/dist/internal/authorization/operation-grant.js +79 -0
  439. package/dist/internal/authorization/operation-grant.js.map +1 -0
  440. package/dist/internal/authorization/operation-version.d.ts +28 -0
  441. package/dist/internal/authorization/operation-version.d.ts.map +1 -0
  442. package/dist/internal/authorization/operation-version.js +206 -0
  443. package/dist/internal/authorization/operation-version.js.map +1 -0
  444. package/dist/internal/authorization/operations-runtime.d.ts +78 -0
  445. package/dist/internal/authorization/operations-runtime.d.ts.map +1 -0
  446. package/dist/internal/authorization/operations-runtime.js +1130 -0
  447. package/dist/internal/authorization/operations-runtime.js.map +1 -0
  448. package/dist/internal/authorization/principal.d.ts +95 -0
  449. package/dist/internal/authorization/principal.d.ts.map +1 -0
  450. package/dist/internal/authorization/principal.js +53 -0
  451. package/dist/internal/authorization/principal.js.map +1 -0
  452. package/dist/internal/authorization/query-view.d.ts +7 -0
  453. package/dist/internal/authorization/query-view.d.ts.map +1 -0
  454. package/dist/internal/authorization/query-view.js +17 -0
  455. package/dist/internal/authorization/query-view.js.map +1 -0
  456. package/dist/internal/authorization/read-compatibility.d.ts +185 -0
  457. package/dist/internal/authorization/read-compatibility.d.ts.map +1 -0
  458. package/dist/internal/authorization/read-compatibility.js +176 -0
  459. package/dist/internal/authorization/read-compatibility.js.map +1 -0
  460. package/dist/internal/authorization/read-filter.d.ts +48 -0
  461. package/dist/internal/authorization/read-filter.d.ts.map +1 -0
  462. package/dist/internal/authorization/read-filter.js +496 -0
  463. package/dist/internal/authorization/read-filter.js.map +1 -0
  464. package/dist/internal/authorization/read-tables.d.ts +9 -0
  465. package/dist/internal/authorization/read-tables.d.ts.map +1 -0
  466. package/dist/internal/authorization/read-tables.js +120 -0
  467. package/dist/internal/authorization/read-tables.js.map +1 -0
  468. package/dist/internal/authorization/reads.d.ts +36 -0
  469. package/dist/internal/authorization/reads.d.ts.map +1 -0
  470. package/dist/internal/authorization/reads.js +35 -0
  471. package/dist/internal/authorization/reads.js.map +1 -0
  472. package/dist/internal/authorization/request.d.ts +64 -0
  473. package/dist/internal/authorization/request.d.ts.map +1 -0
  474. package/dist/internal/authorization/request.js +210 -0
  475. package/dist/internal/authorization/request.js.map +1 -0
  476. package/dist/internal/authorization/truth.d.ts +51 -0
  477. package/dist/internal/authorization/truth.d.ts.map +1 -0
  478. package/dist/internal/authorization/truth.js +23 -0
  479. package/dist/internal/authorization/truth.js.map +1 -0
  480. package/dist/internal/authorization/validate.d.ts +3 -0
  481. package/dist/internal/authorization/validate.d.ts.map +1 -0
  482. package/dist/internal/authorization/validate.js +3 -0
  483. package/dist/internal/authorization/validate.js.map +1 -0
  484. package/dist/internal/authorization/validation/catalog.d.ts +32 -0
  485. package/dist/internal/authorization/validation/catalog.d.ts.map +1 -0
  486. package/dist/internal/authorization/validation/catalog.js +417 -0
  487. package/dist/internal/authorization/validation/catalog.js.map +1 -0
  488. package/dist/internal/authorization/validation/common.d.ts +20 -0
  489. package/dist/internal/authorization/validation/common.d.ts.map +1 -0
  490. package/dist/internal/authorization/validation/common.js +36 -0
  491. package/dist/internal/authorization/validation/common.js.map +1 -0
  492. package/dist/internal/authorization/validation/decisions.d.ts +7 -0
  493. package/dist/internal/authorization/validation/decisions.d.ts.map +1 -0
  494. package/dist/internal/authorization/validation/decisions.js +107 -0
  495. package/dist/internal/authorization/validation/decisions.js.map +1 -0
  496. package/dist/internal/authorization/validation/descriptors.d.ts +8 -0
  497. package/dist/internal/authorization/validation/descriptors.d.ts.map +1 -0
  498. package/dist/internal/authorization/validation/descriptors.js +24 -0
  499. package/dist/internal/authorization/validation/descriptors.js.map +1 -0
  500. package/dist/internal/authorization/validation/expression.d.ts +11 -0
  501. package/dist/internal/authorization/validation/expression.d.ts.map +1 -0
  502. package/dist/internal/authorization/validation/expression.js +114 -0
  503. package/dist/internal/authorization/validation/expression.js.map +1 -0
  504. package/dist/internal/authorization/validation/traversal.d.ts +19 -0
  505. package/dist/internal/authorization/validation/traversal.d.ts.map +1 -0
  506. package/dist/internal/authorization/validation/traversal.js +141 -0
  507. package/dist/internal/authorization/validation/traversal.js.map +1 -0
  508. package/dist/internal/authorization/validation/types.d.ts +55 -0
  509. package/dist/internal/authorization/validation/types.d.ts.map +1 -0
  510. package/dist/internal/authorization/validation/types.js +184 -0
  511. package/dist/internal/authorization/validation/types.js.map +1 -0
  512. package/dist/internal/authorization/validation/validate.d.ts +421 -0
  513. package/dist/internal/authorization/validation/validate.d.ts.map +1 -0
  514. package/dist/internal/authorization/validation/validate.js +95 -0
  515. package/dist/internal/authorization/validation/validate.js.map +1 -0
  516. package/dist/internal/authorization/version.d.ts +11 -0
  517. package/dist/internal/authorization/version.d.ts.map +1 -0
  518. package/dist/internal/authorization/version.js +10 -0
  519. package/dist/internal/authorization/version.js.map +1 -0
  520. package/dist/internal/changesets/protocol.d.ts +185 -0
  521. package/dist/internal/changesets/protocol.d.ts.map +1 -0
  522. package/dist/internal/changesets/protocol.js +39 -0
  523. package/dist/internal/changesets/protocol.js.map +1 -0
  524. package/dist/internal/changesets/service.d.ts +69 -0
  525. package/dist/internal/changesets/service.d.ts.map +1 -0
  526. package/dist/internal/changesets/service.js +298 -0
  527. package/dist/internal/changesets/service.js.map +1 -0
  528. package/dist/internal/core/bytes.d.ts +41 -0
  529. package/dist/internal/core/bytes.d.ts.map +1 -0
  530. package/dist/internal/core/bytes.js +215 -0
  531. package/dist/internal/core/bytes.js.map +1 -0
  532. package/dist/internal/core/composition.d.ts +20 -0
  533. package/dist/internal/core/composition.d.ts.map +1 -0
  534. package/dist/internal/core/composition.js +52 -0
  535. package/dist/internal/core/composition.js.map +1 -0
  536. package/dist/internal/core/conn.d.ts +64 -0
  537. package/dist/internal/core/conn.d.ts.map +1 -0
  538. package/dist/internal/core/conn.js +240 -0
  539. package/dist/internal/core/conn.js.map +1 -0
  540. package/dist/internal/core/datom.d.ts +73 -0
  541. package/dist/internal/core/datom.d.ts.map +1 -0
  542. package/dist/internal/core/datom.js +477 -0
  543. package/dist/internal/core/datom.js.map +1 -0
  544. package/dist/internal/core/db.d.ts +65 -0
  545. package/dist/internal/core/db.d.ts.map +1 -0
  546. package/dist/internal/core/db.js +261 -0
  547. package/dist/internal/core/db.js.map +1 -0
  548. package/dist/internal/core/index.d.ts +21 -0
  549. package/dist/internal/core/index.d.ts.map +1 -0
  550. package/dist/internal/core/index.js +21 -0
  551. package/dist/internal/core/index.js.map +1 -0
  552. package/dist/internal/core/json.d.ts +5 -0
  553. package/dist/internal/core/json.d.ts.map +1 -0
  554. package/dist/internal/core/json.js +56 -0
  555. package/dist/internal/core/json.js.map +1 -0
  556. package/dist/internal/core/log.d.ts +68 -0
  557. package/dist/internal/core/log.d.ts.map +1 -0
  558. package/dist/internal/core/log.js +76 -0
  559. package/dist/internal/core/log.js.map +1 -0
  560. package/dist/internal/core/novelty.d.ts +38 -0
  561. package/dist/internal/core/novelty.d.ts.map +1 -0
  562. package/dist/internal/core/novelty.js +300 -0
  563. package/dist/internal/core/novelty.js.map +1 -0
  564. package/dist/internal/core/query/ast.d.ts +174 -0
  565. package/dist/internal/core/query/ast.d.ts.map +1 -0
  566. package/dist/internal/core/query/ast.js +37 -0
  567. package/dist/internal/core/query/ast.js.map +1 -0
  568. package/dist/internal/core/query/builtins.d.ts +19 -0
  569. package/dist/internal/core/query/builtins.d.ts.map +1 -0
  570. package/dist/internal/core/query/builtins.js +242 -0
  571. package/dist/internal/core/query/builtins.js.map +1 -0
  572. package/dist/internal/core/query/edn.d.ts +19 -0
  573. package/dist/internal/core/query/edn.d.ts.map +1 -0
  574. package/dist/internal/core/query/edn.js +248 -0
  575. package/dist/internal/core/query/edn.js.map +1 -0
  576. package/dist/internal/core/query/engine.d.ts +56 -0
  577. package/dist/internal/core/query/engine.d.ts.map +1 -0
  578. package/dist/internal/core/query/engine.js +0 -0
  579. package/dist/internal/core/query/engine.js.map +1 -0
  580. package/dist/internal/core/query/parse.d.ts +8 -0
  581. package/dist/internal/core/query/parse.d.ts.map +1 -0
  582. package/dist/internal/core/query/parse.js +606 -0
  583. package/dist/internal/core/query/parse.js.map +1 -0
  584. package/dist/internal/core/query/pull.d.ts +7 -0
  585. package/dist/internal/core/query/pull.d.ts.map +1 -0
  586. package/dist/internal/core/query/pull.js +304 -0
  587. package/dist/internal/core/query/pull.js.map +1 -0
  588. package/dist/internal/core/query/value.d.ts +10 -0
  589. package/dist/internal/core/query/value.d.ts.map +1 -0
  590. package/dist/internal/core/query/value.js +21 -0
  591. package/dist/internal/core/query/value.js.map +1 -0
  592. package/dist/internal/core/revision.d.ts +19 -0
  593. package/dist/internal/core/revision.d.ts.map +1 -0
  594. package/dist/internal/core/revision.js +13 -0
  595. package/dist/internal/core/revision.js.map +1 -0
  596. package/dist/internal/core/schema.d.ts +63 -0
  597. package/dist/internal/core/schema.d.ts.map +1 -0
  598. package/dist/internal/core/schema.js +228 -0
  599. package/dist/internal/core/schema.js.map +1 -0
  600. package/dist/internal/core/segment.d.ts +16 -0
  601. package/dist/internal/core/segment.d.ts.map +1 -0
  602. package/dist/internal/core/segment.js +149 -0
  603. package/dist/internal/core/segment.js.map +1 -0
  604. package/dist/internal/core/store.d.ts +35 -0
  605. package/dist/internal/core/store.d.ts.map +1 -0
  606. package/dist/internal/core/store.js +88 -0
  607. package/dist/internal/core/store.js.map +1 -0
  608. package/dist/internal/core/telemetry.d.ts +53 -0
  609. package/dist/internal/core/telemetry.d.ts.map +1 -0
  610. package/dist/internal/core/telemetry.js +103 -0
  611. package/dist/internal/core/telemetry.js.map +1 -0
  612. package/dist/internal/core/tree.d.ts +60 -0
  613. package/dist/internal/core/tree.d.ts.map +1 -0
  614. package/dist/internal/core/tree.js +625 -0
  615. package/dist/internal/core/tree.js.map +1 -0
  616. package/dist/internal/core/tx-provenance.d.ts +7 -0
  617. package/dist/internal/core/tx-provenance.d.ts.map +1 -0
  618. package/dist/internal/core/tx-provenance.js +16 -0
  619. package/dist/internal/core/tx-provenance.js.map +1 -0
  620. package/dist/internal/core/tx.d.ts +51 -0
  621. package/dist/internal/core/tx.d.ts.map +1 -0
  622. package/dist/internal/core/tx.js +1029 -0
  623. package/dist/internal/core/tx.js.map +1 -0
  624. package/dist/internal/replica/basis.d.ts +15 -0
  625. package/dist/internal/replica/basis.d.ts.map +1 -0
  626. package/dist/internal/replica/basis.js +32 -0
  627. package/dist/internal/replica/basis.js.map +1 -0
  628. package/dist/internal/replica/errors.d.ts +32 -0
  629. package/dist/internal/replica/errors.d.ts.map +1 -0
  630. package/dist/internal/replica/errors.js +30 -0
  631. package/dist/internal/replica/errors.js.map +1 -0
  632. package/dist/internal/replica/index.d.ts +4 -0
  633. package/dist/internal/replica/index.d.ts.map +1 -0
  634. package/dist/internal/replica/index.js +4 -0
  635. package/dist/internal/replica/index.js.map +1 -0
  636. package/dist/internal/replica/replica-do-testing.d.ts +11 -0
  637. package/dist/internal/replica/replica-do-testing.d.ts.map +1 -0
  638. package/dist/internal/replica/replica-do-testing.js +340 -0
  639. package/dist/internal/replica/replica-do-testing.js.map +1 -0
  640. package/dist/internal/replica/replica-do.d.ts +87 -0
  641. package/dist/internal/replica/replica-do.d.ts.map +1 -0
  642. package/dist/internal/replica/replica-do.js +735 -0
  643. package/dist/internal/replica/replica-do.js.map +1 -0
  644. package/dist/internal/replica/revision-retention.d.ts +29 -0
  645. package/dist/internal/replica/revision-retention.d.ts.map +1 -0
  646. package/dist/internal/replica/revision-retention.js +39 -0
  647. package/dist/internal/replica/revision-retention.js.map +1 -0
  648. package/dist/internal/replication/activation-fence.d.ts +40 -0
  649. package/dist/internal/replication/activation-fence.d.ts.map +1 -0
  650. package/dist/internal/replication/activation-fence.js +85 -0
  651. package/dist/internal/replication/activation-fence.js.map +1 -0
  652. package/dist/internal/replication/digest.d.ts +2 -0
  653. package/dist/internal/replication/digest.d.ts.map +1 -0
  654. package/dist/internal/replication/digest.js +12 -0
  655. package/dist/internal/replication/digest.js.map +1 -0
  656. package/dist/internal/replication/entity-id.d.ts +23 -0
  657. package/dist/internal/replication/entity-id.d.ts.map +1 -0
  658. package/dist/internal/replication/entity-id.js +161 -0
  659. package/dist/internal/replication/entity-id.js.map +1 -0
  660. package/dist/internal/replication/idb.d.ts +9 -0
  661. package/dist/internal/replication/idb.d.ts.map +1 -0
  662. package/dist/internal/replication/idb.js +46 -0
  663. package/dist/internal/replication/idb.js.map +1 -0
  664. package/dist/internal/replication/identity-root.d.ts +11 -0
  665. package/dist/internal/replication/identity-root.d.ts.map +1 -0
  666. package/dist/internal/replication/identity-root.js +48 -0
  667. package/dist/internal/replication/identity-root.js.map +1 -0
  668. package/dist/internal/replication/identity.d.ts +40 -0
  669. package/dist/internal/replication/identity.d.ts.map +1 -0
  670. package/dist/internal/replication/identity.js +95 -0
  671. package/dist/internal/replication/identity.js.map +1 -0
  672. package/dist/internal/replication/index.d.ts +13 -0
  673. package/dist/internal/replication/index.d.ts.map +1 -0
  674. package/dist/internal/replication/index.js +13 -0
  675. package/dist/internal/replication/index.js.map +1 -0
  676. package/dist/internal/replication/indexeddb.d.ts +171 -0
  677. package/dist/internal/replication/indexeddb.d.ts.map +1 -0
  678. package/dist/internal/replication/indexeddb.js +1809 -0
  679. package/dist/internal/replication/indexeddb.js.map +1 -0
  680. package/dist/internal/replication/leadership.d.ts +36 -0
  681. package/dist/internal/replication/leadership.d.ts.map +1 -0
  682. package/dist/internal/replication/leadership.js +108 -0
  683. package/dist/internal/replication/leadership.js.map +1 -0
  684. package/dist/internal/replication/logical.d.ts +40 -0
  685. package/dist/internal/replication/logical.d.ts.map +1 -0
  686. package/dist/internal/replication/logical.js +375 -0
  687. package/dist/internal/replication/logical.js.map +1 -0
  688. package/dist/internal/replication/notices.d.ts +32 -0
  689. package/dist/internal/replication/notices.d.ts.map +1 -0
  690. package/dist/internal/replication/notices.js +92 -0
  691. package/dist/internal/replication/notices.js.map +1 -0
  692. package/dist/internal/replication/outbox-storage.d.ts +98 -0
  693. package/dist/internal/replication/outbox-storage.d.ts.map +1 -0
  694. package/dist/internal/replication/outbox-storage.js +826 -0
  695. package/dist/internal/replication/outbox-storage.js.map +1 -0
  696. package/dist/internal/replication/outbox.d.ts +200 -0
  697. package/dist/internal/replication/outbox.d.ts.map +1 -0
  698. package/dist/internal/replication/outbox.js +744 -0
  699. package/dist/internal/replication/outbox.js.map +1 -0
  700. package/dist/internal/replication/overlay-layers.d.ts +14 -0
  701. package/dist/internal/replication/overlay-layers.d.ts.map +1 -0
  702. package/dist/internal/replication/overlay-layers.js +2 -0
  703. package/dist/internal/replication/overlay-layers.js.map +1 -0
  704. package/dist/internal/replication/overlay-records.d.ts +61 -0
  705. package/dist/internal/replication/overlay-records.d.ts.map +1 -0
  706. package/dist/internal/replication/overlay-records.js +328 -0
  707. package/dist/internal/replication/overlay-records.js.map +1 -0
  708. package/dist/internal/replication/overlay.d.ts +20 -0
  709. package/dist/internal/replication/overlay.d.ts.map +1 -0
  710. package/dist/internal/replication/overlay.js +159 -0
  711. package/dist/internal/replication/overlay.js.map +1 -0
  712. package/dist/internal/replication/projection-binding.d.ts +39 -0
  713. package/dist/internal/replication/projection-binding.d.ts.map +1 -0
  714. package/dist/internal/replication/projection-binding.js +76 -0
  715. package/dist/internal/replication/projection-binding.js.map +1 -0
  716. package/dist/internal/replication/protocol.d.ts +633 -0
  717. package/dist/internal/replication/protocol.d.ts.map +1 -0
  718. package/dist/internal/replication/protocol.js +263 -0
  719. package/dist/internal/replication/protocol.js.map +1 -0
  720. package/dist/internal/replication/reconciliation.d.ts +64 -0
  721. package/dist/internal/replication/reconciliation.d.ts.map +1 -0
  722. package/dist/internal/replication/reconciliation.js +184 -0
  723. package/dist/internal/replication/reconciliation.js.map +1 -0
  724. package/dist/internal/replication/replica-gc.d.ts +42 -0
  725. package/dist/internal/replication/replica-gc.d.ts.map +1 -0
  726. package/dist/internal/replication/replica-gc.js +91 -0
  727. package/dist/internal/replication/replica-gc.js.map +1 -0
  728. package/dist/internal/replication/replica-integrity.d.ts +107 -0
  729. package/dist/internal/replication/replica-integrity.d.ts.map +1 -0
  730. package/dist/internal/replication/replica-integrity.js +418 -0
  731. package/dist/internal/replication/replica-integrity.js.map +1 -0
  732. package/dist/internal/replication/replica-lifecycle.d.ts +72 -0
  733. package/dist/internal/replication/replica-lifecycle.d.ts.map +1 -0
  734. package/dist/internal/replication/replica-lifecycle.js +126 -0
  735. package/dist/internal/replication/replica-lifecycle.js.map +1 -0
  736. package/dist/internal/replication/replica-schema.d.ts +27 -0
  737. package/dist/internal/replication/replica-schema.d.ts.map +1 -0
  738. package/dist/internal/replication/replica-schema.js +130 -0
  739. package/dist/internal/replication/replica-schema.js.map +1 -0
  740. package/dist/internal/replication/route-slot.d.ts +9 -0
  741. package/dist/internal/replication/route-slot.d.ts.map +1 -0
  742. package/dist/internal/replication/route-slot.js +8 -0
  743. package/dist/internal/replication/route-slot.js.map +1 -0
  744. package/dist/internal/replication/server-identity.d.ts +54 -0
  745. package/dist/internal/replication/server-identity.d.ts.map +1 -0
  746. package/dist/internal/replication/server-identity.js +68 -0
  747. package/dist/internal/replication/server-identity.js.map +1 -0
  748. package/dist/internal/replication/session.d.ts +91 -0
  749. package/dist/internal/replication/session.d.ts.map +1 -0
  750. package/dist/internal/replication/session.js +673 -0
  751. package/dist/internal/replication/session.js.map +1 -0
  752. package/dist/internal/replication/state.d.ts +34 -0
  753. package/dist/internal/replication/state.d.ts.map +1 -0
  754. package/dist/internal/replication/state.js +344 -0
  755. package/dist/internal/replication/state.js.map +1 -0
  756. package/dist/internal/replication/submission.d.ts +115 -0
  757. package/dist/internal/replication/submission.d.ts.map +1 -0
  758. package/dist/internal/replication/submission.js +266 -0
  759. package/dist/internal/replication/submission.js.map +1 -0
  760. package/dist/internal/replication/transport.d.ts +34 -0
  761. package/dist/internal/replication/transport.d.ts.map +1 -0
  762. package/dist/internal/replication/transport.js +215 -0
  763. package/dist/internal/replication/transport.js.map +1 -0
  764. package/dist/internal/runtime-boundaries.d.ts +8 -0
  765. package/dist/internal/runtime-boundaries.d.ts.map +1 -0
  766. package/dist/internal/runtime-boundaries.js +7 -0
  767. package/dist/internal/runtime-boundaries.js.map +1 -0
  768. package/dist/internal/storage/index.d.ts +111 -0
  769. package/dist/internal/storage/index.d.ts.map +1 -0
  770. package/dist/internal/storage/index.js +288 -0
  771. package/dist/internal/storage/index.js.map +1 -0
  772. package/dist/internal/storage/memory.d.ts +31 -0
  773. package/dist/internal/storage/memory.d.ts.map +1 -0
  774. package/dist/internal/storage/memory.js +46 -0
  775. package/dist/internal/storage/memory.js.map +1 -0
  776. package/dist/internal/storage/revisions.d.ts +24 -0
  777. package/dist/internal/storage/revisions.d.ts.map +1 -0
  778. package/dist/internal/storage/revisions.js +74 -0
  779. package/dist/internal/storage/revisions.js.map +1 -0
  780. package/dist/internal/test-hooks.d.ts +47 -0
  781. package/dist/internal/test-hooks.d.ts.map +1 -0
  782. package/dist/internal/test-hooks.js +256 -0
  783. package/dist/internal/test-hooks.js.map +1 -0
  784. package/dist/internal/transactor/env.d.ts +3 -0
  785. package/dist/internal/transactor/env.d.ts.map +1 -0
  786. package/dist/internal/transactor/env.js +5 -0
  787. package/dist/internal/transactor/env.js.map +1 -0
  788. package/dist/internal/transactor/errors.d.ts +47 -0
  789. package/dist/internal/transactor/errors.d.ts.map +1 -0
  790. package/dist/internal/transactor/errors.js +66 -0
  791. package/dist/internal/transactor/errors.js.map +1 -0
  792. package/dist/internal/transactor/host.d.ts +37 -0
  793. package/dist/internal/transactor/host.d.ts.map +1 -0
  794. package/dist/internal/transactor/host.js +11 -0
  795. package/dist/internal/transactor/host.js.map +1 -0
  796. package/dist/internal/transactor/index.d.ts +8 -0
  797. package/dist/internal/transactor/index.d.ts.map +1 -0
  798. package/dist/internal/transactor/index.js +8 -0
  799. package/dist/internal/transactor/index.js.map +1 -0
  800. package/dist/internal/transactor/indexer.d.ts +53 -0
  801. package/dist/internal/transactor/indexer.d.ts.map +1 -0
  802. package/dist/internal/transactor/indexer.js +125 -0
  803. package/dist/internal/transactor/indexer.js.map +1 -0
  804. package/dist/internal/transactor/internal.d.ts +8 -0
  805. package/dist/internal/transactor/internal.d.ts.map +1 -0
  806. package/dist/internal/transactor/internal.js +28 -0
  807. package/dist/internal/transactor/internal.js.map +1 -0
  808. package/dist/internal/transactor/observability.d.ts +44 -0
  809. package/dist/internal/transactor/observability.d.ts.map +1 -0
  810. package/dist/internal/transactor/observability.js +39 -0
  811. package/dist/internal/transactor/observability.js.map +1 -0
  812. package/dist/internal/transactor/transactor-do.d.ts +35 -0
  813. package/dist/internal/transactor/transactor-do.d.ts.map +1 -0
  814. package/dist/internal/transactor/transactor-do.js +198 -0
  815. package/dist/internal/transactor/transactor-do.js.map +1 -0
  816. package/dist/internal/transactor/transactor.d.ts +209 -0
  817. package/dist/internal/transactor/transactor.d.ts.map +1 -0
  818. package/dist/internal/transactor/transactor.js +1166 -0
  819. package/dist/internal/transactor/transactor.js.map +1 -0
  820. package/dist/mcp/contract.d.ts +49 -0
  821. package/dist/mcp/contract.d.ts.map +1 -0
  822. package/dist/mcp/contract.js +199 -0
  823. package/dist/mcp/contract.js.map +1 -0
  824. package/dist/mcp/kernel.d.ts +56 -0
  825. package/dist/mcp/kernel.d.ts.map +1 -0
  826. package/dist/mcp/kernel.js +344 -0
  827. package/dist/mcp/kernel.js.map +1 -0
  828. package/dist/mcp/server.d.ts +8 -0
  829. package/dist/mcp/server.d.ts.map +1 -0
  830. package/dist/mcp/server.js +182 -0
  831. package/dist/mcp/server.js.map +1 -0
  832. package/dist/peer.d.ts +175 -0
  833. package/dist/peer.d.ts.map +1 -0
  834. package/dist/peer.js +200 -0
  835. package/dist/peer.js.map +1 -0
  836. package/dist/react/hooks.d.ts +157 -0
  837. package/dist/react/hooks.d.ts.map +1 -0
  838. package/dist/react/hooks.js +130 -0
  839. package/dist/react/hooks.js.map +1 -0
  840. package/dist/react/index.d.ts +4 -0
  841. package/dist/react/index.d.ts.map +1 -0
  842. package/dist/react/index.js +2 -0
  843. package/dist/react/index.js.map +1 -0
  844. package/dist/react/query-state.d.ts +60 -0
  845. package/dist/react/query-state.d.ts.map +1 -0
  846. package/dist/react/query-state.js +48 -0
  847. package/dist/react/query-state.js.map +1 -0
  848. package/dist/react/receipt-state.d.ts +27 -0
  849. package/dist/react/receipt-state.d.ts.map +1 -0
  850. package/dist/react/receipt-state.js +2 -0
  851. package/dist/react/receipt-state.js.map +1 -0
  852. package/dist/react/store.d.ts +30 -0
  853. package/dist/react/store.d.ts.map +1 -0
  854. package/dist/react/store.js +118 -0
  855. package/dist/react/store.js.map +1 -0
  856. package/dist/react/suspense.d.ts +6 -0
  857. package/dist/react/suspense.d.ts.map +1 -0
  858. package/dist/react/suspense.js +111 -0
  859. package/dist/react/suspense.js.map +1 -0
  860. package/dist/worker/admit.d.ts +9 -0
  861. package/dist/worker/admit.d.ts.map +1 -0
  862. package/dist/worker/admit.js +43 -0
  863. package/dist/worker/admit.js.map +1 -0
  864. package/dist/worker/analytics.d.ts +39 -0
  865. package/dist/worker/analytics.d.ts.map +1 -0
  866. package/dist/worker/analytics.js +54 -0
  867. package/dist/worker/analytics.js.map +1 -0
  868. package/dist/worker/auth.d.ts +26 -0
  869. package/dist/worker/auth.d.ts.map +1 -0
  870. package/dist/worker/auth.js +2 -0
  871. package/dist/worker/auth.js.map +1 -0
  872. package/dist/worker/authorized-live.d.ts +15 -0
  873. package/dist/worker/authorized-live.d.ts.map +1 -0
  874. package/dist/worker/authorized-live.js +30 -0
  875. package/dist/worker/authorized-live.js.map +1 -0
  876. package/dist/worker/authorized-operation.d.ts +30 -0
  877. package/dist/worker/authorized-operation.d.ts.map +1 -0
  878. package/dist/worker/authorized-operation.js +304 -0
  879. package/dist/worker/authorized-operation.js.map +1 -0
  880. package/dist/worker/authorized-read.d.ts +32 -0
  881. package/dist/worker/authorized-read.d.ts.map +1 -0
  882. package/dist/worker/authorized-read.js +194 -0
  883. package/dist/worker/authorized-read.js.map +1 -0
  884. package/dist/worker/authorized-replication.d.ts +21 -0
  885. package/dist/worker/authorized-replication.d.ts.map +1 -0
  886. package/dist/worker/authorized-replication.js +593 -0
  887. package/dist/worker/authorized-replication.js.map +1 -0
  888. package/dist/worker/changesets.d.ts +9 -0
  889. package/dist/worker/changesets.d.ts.map +1 -0
  890. package/dist/worker/changesets.js +105 -0
  891. package/dist/worker/changesets.js.map +1 -0
  892. package/dist/worker/demo.d.ts +2 -0
  893. package/dist/worker/demo.d.ts.map +1 -0
  894. package/dist/worker/demo.js +85 -0
  895. package/dist/worker/demo.js.map +1 -0
  896. package/dist/worker/errors.d.ts +53 -0
  897. package/dist/worker/errors.d.ts.map +1 -0
  898. package/dist/worker/errors.js +107 -0
  899. package/dist/worker/errors.js.map +1 -0
  900. package/dist/worker/handle.d.ts +21 -0
  901. package/dist/worker/handle.d.ts.map +1 -0
  902. package/dist/worker/handle.js +386 -0
  903. package/dist/worker/handle.js.map +1 -0
  904. package/dist/worker/index.d.ts +27 -0
  905. package/dist/worker/index.d.ts.map +1 -0
  906. package/dist/worker/index.js +24 -0
  907. package/dist/worker/index.js.map +1 -0
  908. package/dist/worker/jwt.d.ts +23 -0
  909. package/dist/worker/jwt.d.ts.map +1 -0
  910. package/dist/worker/jwt.js +288 -0
  911. package/dist/worker/jwt.js.map +1 -0
  912. package/dist/worker/mcp.d.ts +17 -0
  913. package/dist/worker/mcp.d.ts.map +1 -0
  914. package/dist/worker/mcp.js +151 -0
  915. package/dist/worker/mcp.js.map +1 -0
  916. package/dist/worker/operation-catalogs.d.ts +38 -0
  917. package/dist/worker/operation-catalogs.d.ts.map +1 -0
  918. package/dist/worker/operation-catalogs.js +114 -0
  919. package/dist/worker/operation-catalogs.js.map +1 -0
  920. package/dist/worker/peer.d.ts +70 -0
  921. package/dist/worker/peer.d.ts.map +1 -0
  922. package/dist/worker/peer.js +330 -0
  923. package/dist/worker/peer.js.map +1 -0
  924. package/dist/worker/public-observation.d.ts +15 -0
  925. package/dist/worker/public-observation.d.ts.map +1 -0
  926. package/dist/worker/public-observation.js +111 -0
  927. package/dist/worker/public-observation.js.map +1 -0
  928. package/dist/worker/server-identity.d.ts +2 -0
  929. package/dist/worker/server-identity.d.ts.map +1 -0
  930. package/dist/worker/server-identity.js +2 -0
  931. package/dist/worker/server-identity.js.map +1 -0
  932. package/dist/worker/session-sync.d.ts +27 -0
  933. package/dist/worker/session-sync.d.ts.map +1 -0
  934. package/dist/worker/session-sync.js +4 -0
  935. package/dist/worker/session-sync.js.map +1 -0
  936. package/dist/worker/session.d.ts +144 -0
  937. package/dist/worker/session.d.ts.map +1 -0
  938. package/dist/worker/session.js +408 -0
  939. package/dist/worker/session.js.map +1 -0
  940. package/dist/worker/storage-test-admin.d.ts +3 -0
  941. package/dist/worker/storage-test-admin.d.ts.map +1 -0
  942. package/dist/worker/storage-test-admin.js +277 -0
  943. package/dist/worker/storage-test-admin.js.map +1 -0
  944. package/dist/worker/test-admin.d.ts +11 -0
  945. package/dist/worker/test-admin.d.ts.map +1 -0
  946. package/dist/worker/test-admin.js +432 -0
  947. package/dist/worker/test-admin.js.map +1 -0
  948. package/dist/worker/testing.d.ts +14 -0
  949. package/dist/worker/testing.d.ts.map +1 -0
  950. package/dist/worker/testing.js +71 -0
  951. package/dist/worker/testing.js.map +1 -0
  952. package/dist/workerEntry.d.ts +2 -0
  953. package/dist/workerEntry.d.ts.map +1 -0
  954. package/dist/workerEntry.js +10 -0
  955. package/dist/workerEntry.js.map +1 -0
  956. package/dist/writes.d.ts +8 -0
  957. package/dist/writes.d.ts.map +1 -0
  958. package/dist/writes.js +11 -0
  959. package/dist/writes.js.map +1 -0
  960. package/package.json +102 -4
@@ -0,0 +1,1536 @@
1
+ import { PREDICATES, vkey } from "../../internal/core/query/builtins.js";
2
+ import { RAMOSE_TYPE_IDENT, TX_BASE } from "../../internal/core/schema.js";
3
+ import { makeEid } from "../Eid.js";
4
+ import { InvalidRequest, NotOne } from "../Errors.js";
5
+ import { isMutationRef } from "../refs.js";
6
+ import { lowerOrderPath, requiredClauses, resetGensym, shapeToPullMap, cardsOf, pathOf, revsOf, } from "../shapes.js";
7
+ import { inspectPullField, isAgain, isAllShape, lowerPullPattern, mapPullEntityIds, pullReshapeIdentity, reshapePullResult, } from "../Pull.js";
8
+ import { Q, isFocusSentinel, isPullSpec, isRowsSpec, isAggSpec, isValueSpec, isDistinctSpec, isVar, isBlank, collectBody, mkVar, runBody, } from "./kernel.js";
9
+ export const isCursor = (x) => typeof x === "object" &&
10
+ x !== null &&
11
+ x._tag === "Cursor" &&
12
+ Array.isArray(x.keys);
13
+ export const isPipeline = (x) => typeof x === "object" && x !== null && x._tag === "Pipeline";
14
+ const isIdsSpec = (x) => typeof x === "object" && x !== null && x._tag === "idsSpec";
15
+ export const isQueryObject = (x) => typeof x === "object" && x !== null && x._tag === "Query";
16
+ const groupKeyId = (path, revs) => path.map((ident, i) => `${revs[i] ? "~" : ""}${ident}`).join("\0");
17
+ const isGen = (x) => typeof x === "object" && x !== null && typeof x.next === "function";
18
+ const runInto = (qv, ctx, stripCursor) => {
19
+ const out = qv.body();
20
+ if (isPipeline(out))
21
+ return assemblePipeline(out, ctx, stripCursor);
22
+ if (isGen(out)) {
23
+ const raw = runBody(out, ctx);
24
+ let distinct = false;
25
+ let proj = raw;
26
+ while (isDistinctSpec(proj)) {
27
+ distinct = true;
28
+ proj = proj.inner;
29
+ }
30
+ return {
31
+ clauses: ctx.clauses,
32
+ proj: normalizeProj(proj),
33
+ focus: focusOf(proj),
34
+ order: [],
35
+ limit: undefined,
36
+ offset: undefined,
37
+ groupKeys: new Map(),
38
+ distinct,
39
+ };
40
+ }
41
+ throw new Error("ramose/query: a Query.build body is a generator of clauses returning the projection, or a function returning a pipeline");
42
+ };
43
+ const normalizeProj = (proj) => {
44
+ if (isVar(proj))
45
+ return { _tag: "idsSpec", v: proj };
46
+ if (isDistinctSpec(proj)) {
47
+ throw new Error("ramose/query: Q.distinct(...) wraps the whole projection, not one cell");
48
+ }
49
+ if (isPullSpec(proj) || isRowsSpec(proj) || isValueSpec(proj))
50
+ return proj;
51
+ if (typeof proj === "object" && proj !== null && !Array.isArray(proj)) {
52
+ const cells = proj;
53
+ if (Object.keys(cells).length === 0) {
54
+ throw new Error("ramose/query: the body returned an empty projection — name at least one cell");
55
+ }
56
+ return cells;
57
+ }
58
+ throw new Error("ramose/query: the body must return its projection — Q.pull(focus, shape), Q.rows({ … }), Q.value(...), Q.distinct({ … }), a record of bound handles, or a focus var for bare ids");
59
+ };
60
+ const focusOf = (proj) => {
61
+ if (isVar(proj))
62
+ return proj;
63
+ if (isPullSpec(proj))
64
+ return proj.focus;
65
+ return undefined;
66
+ };
67
+ const assemblePipeline = (pipe, ctx, stripCursor) => {
68
+ const root = mkVar("entity", pipe.ns.ns);
69
+ ctx.clauses.push({ _tag: "memberOf", ns: pipe.ns, v: root });
70
+ let focus = root;
71
+ let select;
72
+ let extraCells;
73
+ let selectFocus = root;
74
+ let projectIds = false;
75
+ const order = [];
76
+ let limit;
77
+ let offset;
78
+ const groupKeys = new Map();
79
+ for (const st of pipe.stages) {
80
+ switch (st.kind) {
81
+ case "frag": {
82
+ if (select !== undefined) {
83
+ throw new Error("ramose/query: a filter after select(...) — clauses close before the projection; move the stage before select");
84
+ }
85
+ const r = runBody(st.frag(focus), ctx);
86
+ if (isVar(r))
87
+ focus = r;
88
+ break;
89
+ }
90
+ case "select":
91
+ select = st.shape;
92
+ selectFocus = focus;
93
+ extraCells =
94
+ st.extra === undefined
95
+ ? undefined
96
+ : rewriteExtra(typeof st.extra === "function" ? st.extra(focus) : st.extra, focus);
97
+ projectIds = false;
98
+ break;
99
+ case "ids":
100
+ projectIds = true;
101
+ break;
102
+ case "orderBy":
103
+ order.push(resolveOrderKey(st, select, extraCells));
104
+ break;
105
+ case "limit":
106
+ limit = st.n;
107
+ break;
108
+ case "offset":
109
+ offset = st.n;
110
+ break;
111
+ }
112
+ }
113
+ if (stripCursor) {
114
+ order.length = 0;
115
+ limit = undefined;
116
+ offset = undefined;
117
+ }
118
+ let proj;
119
+ let shapeCells;
120
+ if (select !== undefined && !projectIds && extraCells !== undefined) {
121
+ shapeCells = expandShapeToCells(selectFocus, select, ctx, groupKeys);
122
+ proj = { ...shapeCells, ...extraCells };
123
+ }
124
+ else if (select !== undefined && !projectIds) {
125
+ proj = { _tag: "pullSpec", focus: selectFocus, shape: select };
126
+ }
127
+ else {
128
+ proj = { _tag: "idsSpec", v: focus };
129
+ }
130
+ return {
131
+ clauses: ctx.clauses,
132
+ proj,
133
+ focus: select !== undefined && !projectIds ? selectFocus : focus,
134
+ order: finalizePendingOrders(order, select, projectIds, shapeCells),
135
+ limit,
136
+ offset,
137
+ groupKeys,
138
+ distinct: false,
139
+ };
140
+ };
141
+ const finalizePendingOrders = (order, select, projectIds, shapeCells) => {
142
+ const out = [];
143
+ for (const o of order) {
144
+ if (o.kind !== "shapeKey") {
145
+ out.push(o);
146
+ continue;
147
+ }
148
+ if (shapeCells !== undefined) {
149
+ const cell = shapeCells[o.key];
150
+ if (!isVar(cell)) {
151
+ throw new Error(`ramose/query: orderBy("${o.key}") — a sort key is a direct attribute column`);
152
+ }
153
+ out.push({ kind: "cell", cell, dir: o.dir, empty: o.empty });
154
+ continue;
155
+ }
156
+ if (select !== undefined && !projectIds) {
157
+ out.push(orderKeyFromSelectColumn(o.key, select, o.dir, o.empty));
158
+ continue;
159
+ }
160
+ throw new Error(`ramose/query: orderBy("${o.key}") — the projection has no column "${o.key}"`);
161
+ }
162
+ return out;
163
+ };
164
+ const orderKeyFromSelectColumn = (key, select, dir, empty) => {
165
+ let field = select[key];
166
+ if (field === undefined) {
167
+ throw new Error(`ramose/query: orderBy("${key}") — the select shape has no column "${key}"`);
168
+ }
169
+ while (typeof field === "object" &&
170
+ field !== null &&
171
+ (field._tag === "optional" ||
172
+ field._tag === "default") &&
173
+ "field" in field) {
174
+ field = field.field;
175
+ }
176
+ if (typeof field !== "object" || field === null || typeof field.ident !== "string") {
177
+ throw new Error(`ramose/query: orderBy("${key}") — a sort key is a direct attribute column`);
178
+ }
179
+ const carrier = field;
180
+ const path = pathOf(carrier);
181
+ if (cardsOf(carrier).includes("many")) {
182
+ throw new Error(`ramose/query: orderBy(${path.join(" → ")}) crosses a cardinality-many attribute — the sort key would be a set, not a value`);
183
+ }
184
+ return { kind: "path", path, revs: revsOf(carrier), ref: isRefCarrier(carrier), dir, empty };
185
+ };
186
+ const resolveOrderKey = (st, select, extra) => {
187
+ if (typeof st.key === "string" && extra !== undefined && extra[st.key] !== undefined) {
188
+ return { kind: "cell", cell: extra[st.key], dir: st.dir, empty: st.empty };
189
+ }
190
+ if (typeof st.key === "string") {
191
+ if (select === undefined) {
192
+ throw new Error(`ramose/query: orderBy("${st.key}") names a selected column — select(...) first, or pass the attribute itself`);
193
+ }
194
+ if (select[st.key] === undefined) {
195
+ throw new Error(`ramose/query: orderBy("${st.key}") — the select shape has no column "${st.key}"`);
196
+ }
197
+ if (extra !== undefined) {
198
+ return { kind: "shapeKey", key: st.key, dir: st.dir, empty: st.empty };
199
+ }
200
+ return orderKeyFromSelectColumn(st.key, select, st.dir, st.empty);
201
+ }
202
+ const carrier = st.key;
203
+ const path = pathOf(carrier);
204
+ if (cardsOf(carrier).includes("many")) {
205
+ throw new Error(`ramose/query: orderBy(${path.join(" → ")}) crosses a cardinality-many attribute — the sort key would be a set, not a value`);
206
+ }
207
+ return {
208
+ kind: "path",
209
+ path,
210
+ revs: revsOf(carrier),
211
+ ref: isRefCarrier(carrier),
212
+ dir: st.dir,
213
+ empty: st.empty,
214
+ };
215
+ };
216
+ const isPathCarrier = (x) => typeof x === "object" && x !== null && typeof x.ident === "string";
217
+ const isRefCarrier = (carrier) => carrier.valueType === "ref";
218
+ const expandShapeToCells = (focus, shape, ctx, groupKeys, prefix = {
219
+ path: [],
220
+ revs: [],
221
+ }) => {
222
+ const cells = {};
223
+ for (const [key, field] of Object.entries(shape)) {
224
+ const info = inspectPullField(field);
225
+ const attr = info.attr;
226
+ if (attr === undefined || typeof attr.ident !== "string") {
227
+ throw new Error(`ramose/query: select(..., aggregates) field "${key}" is not an attribute`);
228
+ }
229
+ if (info.many) {
230
+ throw new Error(`ramose/query: select(..., aggregates) cannot group by a cardinality-many field ("${key}")`);
231
+ }
232
+ if (isAgain(info.nestedPattern) || isAllShape(info.nestedPattern)) {
233
+ throw new Error(`ramose/query: select(..., aggregates) cannot group by all(...) or again(...) ("${key}")`);
234
+ }
235
+ const path = [...prefix.path, ...pathOf(attr)];
236
+ const revs = [...prefix.revs, ...revsOf(attr)];
237
+ if (info.nestedPattern !== undefined && typeof info.nestedPattern === "object") {
238
+ if (info.optional || info.hasDefault) {
239
+ throw new Error(`ramose/query: select(..., aggregates) cannot group by an optional or defaulted nested shape ("${key}")`);
240
+ }
241
+ const target = mkVar("entity");
242
+ const cmd = info.reverse ? Q.fact(target, attr, focus) : Q.fact(focus, attr, target);
243
+ ctx.clauses.push(cmd);
244
+ cells[key] = expandShapeToCells(target, info.nestedPattern, ctx, groupKeys, {
245
+ path,
246
+ revs,
247
+ });
248
+ continue;
249
+ }
250
+ const v = bindGroupKey(focus, attr, info, ctx);
251
+ groupKeys.set(groupKeyId(path, revs), v);
252
+ cells[key] = v;
253
+ }
254
+ return cells;
255
+ };
256
+ const bindGroupKey = (focus, attr, info, ctx) => {
257
+ if (attr.ident === ":db/id") {
258
+ const id = mkVar("id");
259
+ ctx.clauses.push(Q.fact(focus, attr, id));
260
+ return id;
261
+ }
262
+ const isRef = attr.valueType === "ref";
263
+ const v = isRef ? mkVar("entity") : mkVar("value");
264
+ if (info.optional || info.hasDefault) {
265
+ const fallback = info.hasDefault ? info.defaultValue : null;
266
+ const present = info.reverse
267
+ ? function* () {
268
+ yield* Q.fact(v, attr, focus);
269
+ }
270
+ : function* () {
271
+ yield* Q.fact(focus, attr, v);
272
+ };
273
+ const missing = info.reverse
274
+ ? function* () {
275
+ yield* Q.fact(Q._, attr, focus);
276
+ }
277
+ : function* () {
278
+ yield* Q.fact(focus, attr);
279
+ };
280
+ ctx.clauses.push({
281
+ _tag: "orGroup",
282
+ branches: [
283
+ collectBody(present),
284
+ collectBody(function* () {
285
+ yield* Q.not(missing);
286
+ yield* Q.in(v, [fallback]);
287
+ }),
288
+ ],
289
+ });
290
+ return v;
291
+ }
292
+ if (info.reverse) {
293
+ ctx.clauses.push(Q.fact(v, attr, focus));
294
+ return v;
295
+ }
296
+ const cmd = Q.fact(focus, attr);
297
+ ctx.clauses.push(cmd);
298
+ return cmd.handle.v;
299
+ };
300
+ const extendPath = (parent, leaf) => ({
301
+ ident: leaf.ident,
302
+ cardinality: leaf.cardinality,
303
+ __path: [...pathOf(parent), ...pathOf(leaf)],
304
+ __cards: [...cardsOf(parent), ...cardsOf(leaf)],
305
+ __revs: [...revsOf(parent), ...revsOf(leaf)],
306
+ });
307
+ const rewriteExtra = (extra, focus) => {
308
+ const out = {};
309
+ for (const [key, cell] of Object.entries(extra)) {
310
+ if (isAggSpec(cell)) {
311
+ out[key] = isFocusSentinel(cell.v) ? { ...cell, v: focus } : cell;
312
+ continue;
313
+ }
314
+ if (cell !== null && typeof cell === "object" && !isVar(cell) && !isPullSpec(cell) && !isValueSpec(cell)) {
315
+ out[key] = rewriteExtra(cell, focus);
316
+ continue;
317
+ }
318
+ throw new Error(`ramose/query: select(..., extras) cells are aggregates — "${key}" is not Q.count / Q.sum / …`);
319
+ }
320
+ return out;
321
+ };
322
+ const pullShapeCells = (shape, parent) => {
323
+ const out = {};
324
+ for (const [key, field] of Object.entries(shape)) {
325
+ const info = inspectPullField(field);
326
+ const attr = info.attr;
327
+ const fromFocus = parent !== undefined && attr !== undefined && typeof attr.ident === "string"
328
+ ? extendPath(parent, attr)
329
+ : attr;
330
+ if (info.nestedPattern !== undefined &&
331
+ typeof info.nestedPattern === "object" &&
332
+ !isAgain(info.nestedPattern) &&
333
+ !isAllShape(info.nestedPattern)) {
334
+ const nextParent = fromFocus !== undefined && typeof fromFocus.ident === "string" ? fromFocus : parent;
335
+ out[key] = pullShapeCells(info.nestedPattern, nextParent);
336
+ }
337
+ else {
338
+ out[key] = fromFocus ?? info.attr;
339
+ }
340
+ }
341
+ return out;
342
+ };
343
+ const projectionCells = (proj) => {
344
+ if (isValueSpec(proj))
345
+ return proj.cell;
346
+ if (isIdsSpec(proj))
347
+ return { id: proj.v };
348
+ if (isPullSpec(proj))
349
+ return pullShapeCells(proj.shape);
350
+ return isRowsSpec(proj) ? proj.cells : proj;
351
+ };
352
+ export const makeQueryObject = (body, stripCursor, take, seek, orders = [], limitN, offsetN) => {
353
+ const self = {
354
+ _tag: "Query",
355
+ body,
356
+ stripCursor,
357
+ take,
358
+ seek,
359
+ orders,
360
+ limitN,
361
+ offsetN,
362
+ open: (() => openCommand(self)),
363
+ logic: () => makeQueryObject(body, true),
364
+ orderBy: (key, dir = "asc", opts) => makeQueryObject(body, stripCursor, take, seek, [
365
+ ...orders,
366
+ { key, dir, empty: opts?.empty ?? "last" },
367
+ ], limitN, offsetN),
368
+ limit: (n) => makeQueryObject(body, stripCursor, take, seek, orders, n, offsetN),
369
+ offset: (n) => makeQueryObject(body, stripCursor, take, seek, orders, limitN, n),
370
+ one: () => {
371
+ if (seek !== undefined) {
372
+ throw new Error("ramose/query: one() unwraps a single row, and after(...) pages many — a paged query keeps its rows");
373
+ }
374
+ return makeQueryObject(body, stripCursor, "one", undefined, orders, limitN, offsetN);
375
+ },
376
+ oneOrFail: () => {
377
+ if (seek !== undefined) {
378
+ throw new Error("ramose/query: oneOrFail() unwraps a single row, and after(...) pages many — a paged query keeps its rows");
379
+ }
380
+ return makeQueryObject(body, stripCursor, "oneOrFail", undefined, orders, limitN, offsetN);
381
+ },
382
+ after: (cursor) => {
383
+ if (take !== undefined) {
384
+ throw new Error("ramose/query: one() / oneOrFail() answer a single row — there is no next page to cursor to");
385
+ }
386
+ if (cursor !== null && !isCursor(cursor)) {
387
+ throw new Error("ramose/query: after(...) takes the previous page's cursor, or null for the first page");
388
+ }
389
+ return makeQueryObject(body, stripCursor, undefined, cursor, orders, limitN, offsetN);
390
+ },
391
+ };
392
+ return self;
393
+ };
394
+ /**
395
+ * Build a query. The body returns the projection; both the pipe and
396
+ * generator spellings denote the same value. Put changing values in the
397
+ * body as literals — `Query.build` takes one argument.
398
+ */
399
+ export function q(body) {
400
+ if (typeof body !== "function") {
401
+ throw new Error("ramose/query: Query.build(body) takes a generator or a function returning a pipeline");
402
+ }
403
+ return makeQueryObject(body, false);
404
+ }
405
+ export const isRuleValue = (x) => typeof x === "function" && x._tag === "QueryRule";
406
+ const RULE_NAME = /^[A-Za-z][A-Za-z0-9_./-]*$/;
407
+ /**
408
+ * `Query.rule(name, body)` — the named form of the head/body constructor.
409
+ * The body's parameters are the bound head vars; a returned var joins the
410
+ * head as the free position (promotion: an instantiated fragment becomes a
411
+ * named engine rule in exactly this one mechanical call).
412
+ */
413
+ export function rule(name, body) {
414
+ if (!RULE_NAME.test(name)) {
415
+ throw new Error(`ramose/query: "${name}" is not a rule name — use letters, digits, '_', '.', '/', '-', starting with a letter`);
416
+ }
417
+ let built;
418
+ const ensureBuilt = () => {
419
+ if (built)
420
+ return built;
421
+ const headVars = Array.from({ length: body.length }, () => mkVar("value"));
422
+ const ctx = { clauses: [] };
423
+ const ret = runBody(body(...headVars), ctx);
424
+ let retVar;
425
+ if (isVar(ret)) {
426
+ if (headVars.includes(ret)) {
427
+ throw new Error(`ramose/query: rule "${name}" returns one of its own arguments — a head var appears once; return a var the body binds`);
428
+ }
429
+ retVar = ret;
430
+ }
431
+ else if (ret !== undefined) {
432
+ throw new Error(`ramose/query: rule "${name}" must return a bound var (its free head position) or nothing`);
433
+ }
434
+ built = { headVars, retVar, clauses: ctx.clauses };
435
+ return built;
436
+ };
437
+ const apply = (...args) => {
438
+ if (args.length !== body.length) {
439
+ throw new Error(`ramose/query: rule "${name}" takes ${body.length} argument${body.length === 1 ? "" : "s"}, got ${args.length}`);
440
+ }
441
+ const ret = mkVar("value");
442
+ const cmd = {
443
+ _tag: "splice",
444
+ splice: (ctx) => {
445
+ const call = { _tag: "ruleCall", rule: self, args, ret };
446
+ ctx.clauses.push(call);
447
+ return ret;
448
+ },
449
+ [Symbol.iterator]() {
450
+ let state = 0;
451
+ return {
452
+ next: (v) => state === 0
453
+ ? ((state = 1), { done: false, value: cmd })
454
+ : { done: true, value: v },
455
+ };
456
+ },
457
+ };
458
+ return cmd;
459
+ };
460
+ const self = Object.assign(apply, { _tag: "QueryRule", ruleName: name, ensureBuilt });
461
+ return self;
462
+ }
463
+ const openCommand = (qv) => {
464
+ const cmd = {
465
+ _tag: "splice",
466
+ splice: (ctx) => {
467
+ const built = runInto(qv, ctx, qv.stripCursor);
468
+ const hasCursor = built.order.length > 0 ||
469
+ built.limit !== undefined ||
470
+ built.offset !== undefined ||
471
+ qv.take !== undefined ||
472
+ qv.seek !== undefined ||
473
+ (!qv.stripCursor &&
474
+ (qv.orders.length > 0 || qv.limitN !== undefined || qv.offsetN !== undefined));
475
+ if (hasCursor) {
476
+ throw new Error("ramose/query: a query with a cursor (orderBy/limit/offset/one/after) does not delegate — the cursor is post-processing for the outermost query; extend then order, or strip it explicitly with q.logic()");
477
+ }
478
+ const cols = isIdsSpec(built.proj) ? { id: built.proj.v } : built.proj;
479
+ const focus = built.focus ?? (isPullSpec(built.proj) ? built.proj.focus : undefined);
480
+ if (focus === undefined) {
481
+ throw new Error("ramose/query: q.open(...) needs the opened query's focus — a multi-root projection has none to hand back; open its parts instead");
482
+ }
483
+ return { focus, cols };
484
+ },
485
+ [Symbol.iterator]() {
486
+ let state = 0;
487
+ const self = cmd;
488
+ return {
489
+ next: (v) => state === 0
490
+ ? ((state = 1), { done: false, value: self })
491
+ : { done: true, value: v },
492
+ };
493
+ },
494
+ };
495
+ return cmd;
496
+ };
497
+ /**
498
+ * Lift an enricher generator into a query transformer: the query-level
499
+ * generics live here, never in user code. The enricher sees the opened
500
+ * query's focus and returns extra cells for the row.
501
+ */
502
+ export const enrich = (body) => (qv) => makeQueryObject(function* () {
503
+ const { focus, cols } = (yield* openCommand(qv));
504
+ const extra = yield* body(focus);
505
+ return Q.row(cols, extra);
506
+ }, false);
507
+ /** Shape-preserving sibling of {@link enrich}: extra constraints, same row. */
508
+ export const refine = (frag) => (qv) => makeQueryObject(function* () {
509
+ const { focus, cols } = (yield* openCommand(qv));
510
+ yield* frag(focus);
511
+ return cols;
512
+ }, false);
513
+ export const symbolicIdentityLowering = () => {
514
+ const identities = [];
515
+ return {
516
+ lowering: { resolveEntity: (id) => -identities.push(id) },
517
+ identities,
518
+ };
519
+ };
520
+ const EMPTY_AGG = {
521
+ count: 0,
522
+ "count-distinct": 0,
523
+ sum: 0,
524
+ avg: null,
525
+ min: null,
526
+ max: null,
527
+ };
528
+ const unwrapEidLike = (v) => typeof v === "object" &&
529
+ v !== null &&
530
+ typeof v.id === "number" &&
531
+ Object.keys(v).length === 1
532
+ ? v.id
533
+ : v;
534
+ const namedEntity = (v) => {
535
+ if (typeof v !== "object" || v === null)
536
+ return v;
537
+ const id = v.id;
538
+ return typeof id === "string" || typeof id === "number" ? id : v;
539
+ };
540
+ const isRefAttr = (attr) => attr !== undefined && attr.valueType === "ref";
541
+ const UNRESOLVED = Symbol("ramose/query/unplaceable-entity");
542
+ const regexSource = (re) => {
543
+ if (typeof re === "string")
544
+ return re;
545
+ if (re.flags !== "") {
546
+ throw new Error(`ramose/query: matches(/${re.source}/${re.flags}) — the peer compiles the pattern with no flags; express it in the pattern instead`);
547
+ }
548
+ return re.source;
549
+ };
550
+ export const lowerQueryAst = (qv) => lowerQueryObject(qv).query;
551
+ export const tryLowerQueryObject = (qv, lowering) => {
552
+ try {
553
+ return lowerQueryObject(qv, lowering);
554
+ }
555
+ catch (e) {
556
+ if (e instanceof InvalidRequest)
557
+ throw e;
558
+ throw new InvalidRequest({
559
+ message: e instanceof Error ? e.message : String(e),
560
+ });
561
+ }
562
+ };
563
+ export const lowerQueryObject = (qv, lowering) => {
564
+ const entityId = lowering?.entity ?? ((eid) => makeEid(eid));
565
+ let bindsEntities = false;
566
+ resetGensym();
567
+ const ctx = { clauses: [] };
568
+ const built = runInto(qv, ctx, qv.stripCursor);
569
+ const names = new Map();
570
+ const kinds = new Map();
571
+ let seq = 0;
572
+ const nameOf = (v) => {
573
+ let n = names.get(v.id);
574
+ if (n === undefined) {
575
+ n = `?q${seq++}`;
576
+ names.set(v.id, n);
577
+ kinds.set(n, v.kind);
578
+ }
579
+ return n;
580
+ };
581
+ let blanks = 0;
582
+ const freshName = (prefix) => `?q${prefix}${blanks++}`;
583
+ const byRule = new Map();
584
+ const byNs = new Map();
585
+ const takenNames = new Map();
586
+ const ruleDefs = [];
587
+ const claimName = (name, source) => {
588
+ const holder = takenNames.get(name);
589
+ if (holder !== undefined && holder !== source) {
590
+ throw new Error(`ramose/query: two different rules named "${name}" reached one query — rule names are identities`);
591
+ }
592
+ takenNames.set(name, source);
593
+ };
594
+ const registerRule = (r) => {
595
+ const seen = byRule.get(r);
596
+ if (seen)
597
+ return seen;
598
+ const b = r.ensureBuilt();
599
+ const entry = { wireName: r.ruleName, hasRet: b.retVar !== undefined };
600
+ claimName(r.ruleName, r);
601
+ byRule.set(r, entry);
602
+ const headVars = b.retVar === undefined ? b.headVars : [...b.headVars, b.retVar];
603
+ const head = [r.ruleName, ...headVars.map(nameOf)];
604
+ const clauses = lowerClauses(b.clauses, varSet(headVars));
605
+ ruleDefs.push([head, ...clauses]);
606
+ return entry;
607
+ };
608
+ const registerMembership = (ns) => {
609
+ const seen = byNs.get(ns);
610
+ if (seen)
611
+ return seen;
612
+ const wireName = `is${ns.ns.charAt(0).toUpperCase()}${ns.ns.slice(1)}`.replace(/[^A-Za-z0-9_]/g, "_");
613
+ claimName(wireName, ns);
614
+ const entry = { wireName, hasRet: false };
615
+ byNs.set(ns, entry);
616
+ const e = freshName("m");
617
+ if (ns._tag === "Trait") {
618
+ const type = freshName("type");
619
+ ruleDefs.push([
620
+ [wireName, e],
621
+ [e, RAMOSE_TYPE_IDENT, type],
622
+ [["ramose-trait?", e, type, `:${ns.ns}`]],
623
+ ]);
624
+ }
625
+ else {
626
+ ruleDefs.push([[wireName, e], [e, RAMOSE_TYPE_IDENT, `:${ns.ns}`]]);
627
+ }
628
+ return entry;
629
+ };
630
+ const varSet = (vs) => new Set(vs.map((v) => v.id));
631
+ const factVars = (c, into) => {
632
+ const e = c.eVar ?? c.e0;
633
+ if (isVar(e))
634
+ into.add(e.id);
635
+ const v = c.vVar ?? c.v0;
636
+ if (isVar(v))
637
+ into.add(v.id);
638
+ if (c.txVar)
639
+ into.add(c.txVar.id);
640
+ if (c.opVar)
641
+ into.add(c.opVar.id);
642
+ };
643
+ const clauseListVars = (list, into = new Set()) => {
644
+ for (const c of list) {
645
+ switch (c._tag) {
646
+ case "fact":
647
+ factVars(c, into);
648
+ break;
649
+ case "cmp":
650
+ for (const a of c.args)
651
+ if (isVar(a))
652
+ into.add(a.id);
653
+ break;
654
+ case "fnBind":
655
+ for (const a of c.args)
656
+ if (isVar(a))
657
+ into.add(a.id);
658
+ into.add(c.ret.id);
659
+ break;
660
+ case "memberOf":
661
+ into.add(c.v.id);
662
+ break;
663
+ case "ruleCall":
664
+ for (const a of c.args)
665
+ if (isVar(a))
666
+ into.add(a.id);
667
+ into.add(c.ret.id);
668
+ break;
669
+ case "orGroup":
670
+ c.branches.forEach((b) => clauseListVars(b, into));
671
+ break;
672
+ case "notGroup":
673
+ clauseListVars(c.clauses, into);
674
+ break;
675
+ }
676
+ }
677
+ return into;
678
+ };
679
+ const resolveIdentity = lowering?.resolveEntity;
680
+ const lowerEntityConst = (v, use) => {
681
+ const named = namedEntity(v);
682
+ if (typeof named !== "string") {
683
+ if (typeof named === "object" && named !== null && !Array.isArray(named)) {
684
+ throw new InvalidRequest({
685
+ message: `ramose/query: ${use} takes an entity — an entity id, or the row cell that carries one`,
686
+ });
687
+ }
688
+ return unwrapEidLike(named);
689
+ }
690
+ bindsEntities = true;
691
+ if (resolveIdentity === undefined) {
692
+ throw new InvalidRequest({
693
+ message: `ramose/query: ${use} names an entity by its opaque identity, and an identity is only meaningful against the replica it was issued to — ask this question through a client's own query`,
694
+ });
695
+ }
696
+ const eid = resolveIdentity(named);
697
+ return eid === undefined ? UNRESOLVED : eid;
698
+ };
699
+ const refuseIdentity = (v, use) => {
700
+ if (!isMutationRef(v))
701
+ return;
702
+ throw new InvalidRequest({
703
+ message: `ramose/query: an entity identity is not a value for ${use} — only a reference holds an entity; compare the reference itself`,
704
+ });
705
+ };
706
+ const lowerConst = (v, use, entity = false) => {
707
+ if (entity)
708
+ return lowerEntityConst(v, use);
709
+ refuseIdentity(v, use);
710
+ return unwrapEidLike(v);
711
+ };
712
+ const lowerPos = (v, use, entity = false) => {
713
+ if (v === undefined || isBlank(v))
714
+ return "_";
715
+ if (isVar(v))
716
+ return nameOf(v);
717
+ if (isAggSpec(v)) {
718
+ throw new Error(`ramose/query: an aggregate cell is not a value for ${use} — an aggregate exists only after grouping, as a projected cell or a top-level comparison operand`);
719
+ }
720
+ return lowerConst(v, use, entity);
721
+ };
722
+ const groundNothing = (name) => [["ground", []], [name, "..."]];
723
+ const neverClause = () => groundNothing(freshName("n"));
724
+ const lowerClauses = (list, outer) => {
725
+ const out = [];
726
+ for (const c of list) {
727
+ switch (c._tag) {
728
+ case "fact": {
729
+ const clauses = lowerFact(c);
730
+ if (clauses !== undefined)
731
+ out.push(...clauses);
732
+ break;
733
+ }
734
+ case "cmp":
735
+ out.push(...lowerCmp(c));
736
+ break;
737
+ case "fnBind":
738
+ out.push([
739
+ [c.fn, ...c.args.map((a) => lowerPos(a, `Q.call("${c.fn}")`))],
740
+ nameOf(c.ret),
741
+ ]);
742
+ break;
743
+ case "memberOf": {
744
+ const prefix = `:${c.ns.ns}/`;
745
+ const entailed = list.some((s) => s !== c &&
746
+ s._tag === "fact" &&
747
+ s.attr !== undefined &&
748
+ s.attr.ident.startsWith(prefix) &&
749
+ (s.eVar ?? s.e0) === c.v);
750
+ if (!entailed) {
751
+ const entry = registerMembership(c.ns);
752
+ out.push([entry.wireName, nameOf(c.v)]);
753
+ }
754
+ break;
755
+ }
756
+ case "ruleCall": {
757
+ const entry = registerRule(c.rule);
758
+ const args = c.args.map((a) => lowerPos(a, `rule ${entry.wireName}`));
759
+ if (entry.hasRet) {
760
+ out.push([entry.wireName, ...args, nameOf(c.ret)]);
761
+ }
762
+ else {
763
+ const usedElsewhere = (() => {
764
+ const rest = new Set();
765
+ clauseListVars(list.filter((s) => s !== c), rest);
766
+ return rest.has(c.ret.id) || outer.has(c.ret.id);
767
+ })();
768
+ if (usedElsewhere) {
769
+ throw new Error(`ramose/query: rule "${entry.wireName}" binds nothing — its application has no value to use`);
770
+ }
771
+ out.push([entry.wireName, ...args]);
772
+ }
773
+ break;
774
+ }
775
+ case "orGroup": {
776
+ if (c.branches.length === 0) {
777
+ out.push(neverClause());
778
+ break;
779
+ }
780
+ const inner = new Set();
781
+ c.branches.forEach((b) => clauseListVars(b, inner));
782
+ const rest = clauseListVars(list.filter((s) => s !== c));
783
+ const join = [...inner].filter((id) => rest.has(id) || outer.has(id));
784
+ const scope = new Set([...outer, ...rest]);
785
+ out.push([
786
+ "or-join",
787
+ join.map((id) => names.get(id) ?? nameOf(findVar(c, id))),
788
+ ...c.branches.map((b) => ["and", ...lowerClauses(b, scope)]),
789
+ ]);
790
+ break;
791
+ }
792
+ case "notGroup": {
793
+ const inner = clauseListVars(c.clauses);
794
+ const rest = clauseListVars(list.filter((s) => s !== c));
795
+ const join = [...inner].filter((id) => rest.has(id) || outer.has(id));
796
+ const scope = new Set([...outer, ...rest]);
797
+ const lowered = lowerClauses(c.clauses, scope);
798
+ if (lowered.length === 0) {
799
+ out.push(neverClause());
800
+ break;
801
+ }
802
+ out.push(["not-join", join.map((id) => names.get(id) ?? nameOf(findVar(c, id))), ...lowered]);
803
+ break;
804
+ }
805
+ }
806
+ }
807
+ return out;
808
+ };
809
+ const findVar = (group, id) => {
810
+ let found;
811
+ const scan = (list) => {
812
+ for (const c of list) {
813
+ if (found)
814
+ return;
815
+ switch (c._tag) {
816
+ case "fact": {
817
+ const e = c.eVar ?? c.e0;
818
+ if (isVar(e) && e.id === id)
819
+ found = e;
820
+ const v = c.vVar ?? c.v0;
821
+ if (isVar(v) && v.id === id)
822
+ found = v;
823
+ if (c.txVar?.id === id)
824
+ found = c.txVar;
825
+ if (c.opVar?.id === id)
826
+ found = c.opVar;
827
+ break;
828
+ }
829
+ case "cmp":
830
+ for (const a of c.args)
831
+ if (isVar(a) && a.id === id)
832
+ found = a;
833
+ break;
834
+ case "fnBind":
835
+ for (const a of c.args)
836
+ if (isVar(a) && a.id === id)
837
+ found = a;
838
+ if (c.ret.id === id)
839
+ found = c.ret;
840
+ break;
841
+ case "memberOf":
842
+ if (c.v.id === id)
843
+ found = c.v;
844
+ break;
845
+ case "ruleCall":
846
+ for (const a of c.args)
847
+ if (isVar(a) && a.id === id)
848
+ found = a;
849
+ if (c.ret.id === id)
850
+ found = c.ret;
851
+ break;
852
+ case "orGroup":
853
+ c.branches.forEach(scan);
854
+ break;
855
+ case "notGroup":
856
+ scan(c.clauses);
857
+ break;
858
+ }
859
+ }
860
+ };
861
+ scan([group]);
862
+ if (!found)
863
+ throw new Error("ramose/query: internal — join var not found in its group");
864
+ return found;
865
+ };
866
+ const isWireVar = (x) => typeof x === "string" && x.startsWith("?");
867
+ const lowerIdFact = (c) => {
868
+ if (c.txVar !== undefined || c.opVar !== undefined) {
869
+ throw new Error("ramose/query: :db/id is the entity's identity, not a datom — it has no tx or op position");
870
+ }
871
+ const ePos = c.eVar ?? c.e0;
872
+ const vPos = c.vVar ?? c.v0;
873
+ if (isVar(ePos) && isVar(vPos)) {
874
+ const eName = names.get(ePos.id);
875
+ const vName = names.get(vPos.id);
876
+ if (eName !== undefined && vName !== undefined) {
877
+ return eName === vName ? undefined : [[["identity", eName], vName]];
878
+ }
879
+ const n = eName ?? vName ?? nameOf(ePos);
880
+ names.set(ePos.id, n);
881
+ names.set(vPos.id, n);
882
+ return undefined;
883
+ }
884
+ const e = lowerPos(ePos, "an entity position", true);
885
+ const v = lowerPos(vPos, ":db/id's value", true);
886
+ if (e === UNRESOLVED || v === UNRESOLVED) {
887
+ const bound = [e, v].find(isWireVar);
888
+ return [bound === undefined ? neverClause() : groundNothing(bound)];
889
+ }
890
+ if (e === v || e === "_" || v === "_")
891
+ return undefined;
892
+ if (isWireVar(e) && !isWireVar(v))
893
+ return [[["ground", v], e]];
894
+ if (isWireVar(v) && !isWireVar(e))
895
+ return [[["ground", e], v]];
896
+ return [neverClause()];
897
+ };
898
+ const lowerFact = (c) => {
899
+ if (c.attr?.ident === ":db/id")
900
+ return lowerIdFact(c);
901
+ const e = lowerPos(c.eVar ?? c.e0, "an entity position", true);
902
+ const attr = c.attr?.ident ?? "_";
903
+ const v = lowerPos(c.vVar ?? c.v0, attr === "_" ? "a value position" : `${attr}'s value`, isRefAttr(c.attr));
904
+ const unplaced = e === UNRESOLVED || v === UNRESOLVED;
905
+ const clause = [
906
+ e === UNRESOLVED ? freshName("u") : e,
907
+ attr,
908
+ v === UNRESOLVED ? freshName("u") : v,
909
+ ];
910
+ if (c.txVar !== undefined || c.opVar !== undefined) {
911
+ clause.push(c.txVar !== undefined ? nameOf(c.txVar) : "_");
912
+ }
913
+ if (c.opVar !== undefined)
914
+ clause.push(nameOf(c.opVar));
915
+ return unplaced ? [clause, neverClause()] : [clause];
916
+ };
917
+ const lowerCmp = (c) => {
918
+ const { op, args, ignoreCase } = c;
919
+ const tSided = args.some((a) => isVar(a) && a.kind === "t");
920
+ const entitySided = args.some((a) => isVar(a) && (a.kind === "entity" || a.kind === "id"));
921
+ const use = `the comparison "${op}"`;
922
+ const operand = (a) => {
923
+ if (isAggSpec(a)) {
924
+ throw new Error("ramose/query: a comparison over an aggregate cell cannot appear inside Q.or / Q.not or a rule body — :having filters whole groups, and there is no group where those lower; write it at the query's top level");
925
+ }
926
+ if (isVar(a))
927
+ return nameOf(a);
928
+ let v = a;
929
+ if (op === "re-find?")
930
+ return regexSource(v);
931
+ if (op === "in") {
932
+ if (!Array.isArray(v))
933
+ throw new Error(`ramose/query: Q.in takes an array of values, got ${String(v)}`);
934
+ return v.map((member) => lowerConst(member, use, entitySided));
935
+ }
936
+ v = lowerConst(v, use, entitySided);
937
+ if (tSided && typeof v === "number")
938
+ return TX_BASE + v;
939
+ return v;
940
+ };
941
+ if (op === "in") {
942
+ const [subject, list] = args;
943
+ if (!isVar(subject)) {
944
+ throw new Error("ramose/query: Q.in's first argument is a bound var");
945
+ }
946
+ const values = operand(list).filter((value) => value !== UNRESOLVED);
947
+ return [[["ground", values], [nameOf(subject), "..."]]];
948
+ }
949
+ if (ignoreCase) {
950
+ if (args.some(isAggSpec)) {
951
+ throw new Error("ramose/query: ignoreCase cannot wrap an aggregate comparison — :having does not bind functions; write the comparison at the query's top level without ignoreCase, or fold through Q.call(\"lower-case\") before aggregating");
952
+ }
953
+ const extras = [];
954
+ const folded = args.map((a) => {
955
+ if (isVar(a)) {
956
+ const out = freshName("l");
957
+ extras.push([["lower-case", nameOf(a)], out]);
958
+ return out;
959
+ }
960
+ if (isBlank(a) || a === undefined) {
961
+ throw new Error("ramose/query: ignoreCase needs a bound var or a string on each side");
962
+ }
963
+ const v = lowerConst(a, use);
964
+ if (typeof v !== "string") {
965
+ throw new Error("ramose/query: ignoreCase applies to strings");
966
+ }
967
+ return v.toLowerCase();
968
+ });
969
+ return [...extras, [[op, ...folded]]];
970
+ }
971
+ const operands = args.map(operand);
972
+ if (operands.includes(UNRESOLVED))
973
+ return [neverClause()];
974
+ return [[[op, ...operands]]];
975
+ };
976
+ const clauses = built.clauses;
977
+ const havingCmps = [];
978
+ const rowClauses = [];
979
+ for (const c of clauses) {
980
+ if (c._tag === "cmp" && c.args.some(isAggSpec)) {
981
+ if (c.ignoreCase) {
982
+ throw new Error("ramose/query: ignoreCase cannot wrap an aggregate comparison — :having does not bind functions");
983
+ }
984
+ havingCmps.push(c);
985
+ }
986
+ else
987
+ rowClauses.push(c);
988
+ }
989
+ const nameCells = havingCmps.length > 0;
990
+ const aggKey = (a) => {
991
+ const id = isFocusSentinel(a.v) && built.focus !== undefined ? built.focus.id : a.v.id;
992
+ return `${a.fn}:${id}`;
993
+ };
994
+ const aggAlias = new Map();
995
+ const emptyCells = new Map();
996
+ const plainCellVars = new Set();
997
+ const where = [];
998
+ const flats = [];
999
+ const find = [];
1000
+ const readVar = (v) => {
1001
+ switch (v.kind) {
1002
+ case "entity":
1003
+ case "tx":
1004
+ return (cell) => typeof cell === "number"
1005
+ ? { id: v.kind === "entity" ? entityId(cell) : makeEid(cell) }
1006
+ : cell;
1007
+ case "id":
1008
+ return (cell) => (typeof cell === "number" ? entityId(cell) : cell);
1009
+ case "t":
1010
+ return (cell) => (typeof cell === "number" ? cell - TX_BASE : cell);
1011
+ default:
1012
+ return (cell) => cell;
1013
+ }
1014
+ };
1015
+ const readAgg = (fn, v) => {
1016
+ if (fn !== "min" && fn !== "max")
1017
+ return (cell) => cell;
1018
+ switch (v.kind) {
1019
+ case "entity":
1020
+ case "id":
1021
+ return (cell) => (typeof cell === "number" ? entityId(cell) : cell);
1022
+ case "t":
1023
+ return (cell) => (typeof cell === "number" ? cell - TX_BASE : cell);
1024
+ default:
1025
+ return (cell) => cell;
1026
+ }
1027
+ };
1028
+ const flattenCell = (path, cell) => {
1029
+ if (isVar(cell)) {
1030
+ plainCellVars.add(cell.id);
1031
+ flats.push({ path, elem: nameOf(cell), read: readVar(cell) });
1032
+ return;
1033
+ }
1034
+ if (isAggSpec(cell)) {
1035
+ const v = isFocusSentinel(cell.v)
1036
+ ? built.focus ??
1037
+ (() => {
1038
+ throw new Error("ramose/query: Q.focus needs a select focus — use it in .select(shape, extras) or Q.pull");
1039
+ })()
1040
+ : cell.v;
1041
+ const read = readAgg(cell.fn, v);
1042
+ let elem = [cell.fn, nameOf(v)];
1043
+ if (nameCells) {
1044
+ const alias = aggAlias.get(aggKey(cell)) ?? freshName("h");
1045
+ aggAlias.set(aggKey(cell), alias);
1046
+ emptyCells.set(alias, EMPTY_AGG[cell.fn]);
1047
+ elem = ["as", elem, alias];
1048
+ }
1049
+ flats.push({ path, elem, read, agg: cell.fn });
1050
+ return;
1051
+ }
1052
+ if (isPullSpec(cell)) {
1053
+ if (nameCells) {
1054
+ throw new Error("ramose/query: an aggregate-cell comparison and Q.pull cannot share a projection — the server's :having names find cells and a pull is not one; project bound vars beside the aggregate instead");
1055
+ }
1056
+ const map = shapeToPullMap(cell.shape);
1057
+ const focus = nameOf(cell.focus);
1058
+ where.push(...requiredClauses(focus, map));
1059
+ flats.push({
1060
+ path,
1061
+ elem: ["pull", focus, lowerPullPattern(map)],
1062
+ read: (c) => mapPullEntityIds(map, reshapePullResult(map, c), entityId),
1063
+ plan: pullReshapeIdentity(map),
1064
+ });
1065
+ return;
1066
+ }
1067
+ if (isDistinctSpec(cell)) {
1068
+ throw new Error("ramose/query: Q.distinct(...) wraps the whole projection, not one cell");
1069
+ }
1070
+ if (typeof cell === "object" && cell !== null) {
1071
+ for (const [k, sub] of Object.entries(cell)) {
1072
+ flattenCell([...path, k], sub);
1073
+ }
1074
+ return;
1075
+ }
1076
+ throw new Error(`ramose/query: projection cell at ${path.join(".") || "<root>"} is not a bound handle, Q.pull, or an aggregate`);
1077
+ };
1078
+ let finalizeRows;
1079
+ let scalar = false;
1080
+ let projection = "rows";
1081
+ let rootPlan = null;
1082
+ const proj = built.proj;
1083
+ if (isValueSpec(proj)) {
1084
+ projection = "value";
1085
+ flattenCell(["$"], proj.cell);
1086
+ find.push(flats[0].elem, ".");
1087
+ scalar = true;
1088
+ const aggFn = flats[0].agg;
1089
+ finalizeRows = (raw) => {
1090
+ const empty = aggFn !== undefined ? EMPTY_AGG[aggFn] : null;
1091
+ if (raw.length === 0)
1092
+ return aggFn !== undefined && emptyRowPasses() ? [empty] : [];
1093
+ return raw;
1094
+ };
1095
+ }
1096
+ else if (isIdsSpec(proj)) {
1097
+ projection = "ids";
1098
+ find.push(nameOf(proj.v));
1099
+ finalizeRows = (tuples) => tuples.map((t) => typeof t[0] === "number" ? { id: entityId(t[0]) } : t[0]);
1100
+ }
1101
+ else if (isPullSpec(proj)) {
1102
+ projection = "pull";
1103
+ const map = shapeToPullMap(proj.shape);
1104
+ rootPlan = pullReshapeIdentity(map);
1105
+ const focus = nameOf(proj.focus);
1106
+ where.push(...requiredClauses(focus, map));
1107
+ find.push(["pull", focus, lowerPullPattern(map)]);
1108
+ finalizeRows = (tuples) => tuples.map((t) => mapPullEntityIds(map, reshapePullResult(map, t[0]), entityId));
1109
+ }
1110
+ else {
1111
+ const cells = isRowsSpec(proj) ? proj.cells : proj;
1112
+ for (const [k, cell] of Object.entries(cells))
1113
+ flattenCell([k], cell);
1114
+ find.push(...flats.map((f) => f.elem));
1115
+ const aggOnly = flats.length > 0 && flats.every((f) => f.agg !== undefined);
1116
+ finalizeRows = (raw) => (raw.length === 0 && aggOnly && emptyRowPasses() ? [flats.map((f) => EMPTY_AGG[f.agg])] : raw).map((t) => {
1117
+ const row = {};
1118
+ flats.forEach((f, i) => {
1119
+ const value = f.read(t[i]);
1120
+ let at = row;
1121
+ for (let d = 0; d < f.path.length - 1; d++) {
1122
+ const k = f.path[d];
1123
+ at = (at[k] ??= {});
1124
+ }
1125
+ const leaf = f.path[f.path.length - 1];
1126
+ if (leaf === "…") {
1127
+ Object.assign(at, value);
1128
+ }
1129
+ else {
1130
+ at[leaf] = value;
1131
+ }
1132
+ });
1133
+ return row;
1134
+ });
1135
+ }
1136
+ const projVars = new Set();
1137
+ const provenanceVars = new Set();
1138
+ const addProvenance = (v) => {
1139
+ if (v.kind !== "entity" && v.kind !== "tx")
1140
+ provenanceVars.add(v.id);
1141
+ };
1142
+ const collectProjVars = (cell) => {
1143
+ if (isVar(cell)) {
1144
+ projVars.add(cell.id);
1145
+ if (!built.distinct)
1146
+ addProvenance(cell);
1147
+ }
1148
+ else if (isAggSpec(cell)) {
1149
+ const v = isFocusSentinel(cell.v) ? (built.focus ?? cell.v) : cell.v;
1150
+ projVars.add(v.id);
1151
+ addProvenance(v);
1152
+ }
1153
+ else if (isPullSpec(cell))
1154
+ projVars.add(cell.focus.id);
1155
+ else if (isDistinctSpec(cell)) {
1156
+ throw new Error("ramose/query: Q.distinct(...) wraps the whole projection, not one cell");
1157
+ }
1158
+ else if (typeof cell === "object" && cell !== null) {
1159
+ for (const sub of Object.values(cell))
1160
+ collectProjVars(sub);
1161
+ }
1162
+ };
1163
+ if (isIdsSpec(proj))
1164
+ projVars.add(proj.v.id);
1165
+ else if (isPullSpec(proj))
1166
+ projVars.add(proj.focus.id);
1167
+ else if (isValueSpec(proj))
1168
+ collectProjVars(proj.cell);
1169
+ else
1170
+ collectProjVars(isRowsSpec(proj) ? proj.cells : proj);
1171
+ where.unshift(...lowerClauses(rowClauses, projVars));
1172
+ const havingCellName = (a) => {
1173
+ const alias = aggAlias.get(aggKey(a));
1174
+ if (alias === undefined) {
1175
+ throw new Error(`ramose/query: Q.${a.fn === "count-distinct" ? "countDistinct" : a.fn}(...) is compared but never projected — a post-group filter names an aggregate cell of the row, so the same cell value must reach the projection`);
1176
+ }
1177
+ return alias;
1178
+ };
1179
+ const lowerHavingCmp = (c) => {
1180
+ const tSided = c.args.some((a) => (isVar(a) && a.kind === "t") ||
1181
+ (isAggSpec(a) && a.v.kind === "t" && (a.fn === "min" || a.fn === "max")));
1182
+ const operand = (a) => {
1183
+ if (isAggSpec(a))
1184
+ return havingCellName(a);
1185
+ if (isVar(a)) {
1186
+ if (!plainCellVars.has(a.id)) {
1187
+ throw new Error("ramose/query: a post-group comparison sees the group's row, so a var beside the aggregate cell must be a projected cell of it — project the var, or compare against a literal");
1188
+ }
1189
+ return nameOf(a);
1190
+ }
1191
+ let v = a;
1192
+ const use = `the post-group comparison "${c.op}"`;
1193
+ if (c.op === "re-find?")
1194
+ return regexSource(v);
1195
+ if (c.op === "in") {
1196
+ if (!Array.isArray(v))
1197
+ throw new Error(`ramose/query: Q.in takes an array of values, got ${String(v)}`);
1198
+ return v.map((member) => lowerConst(member, use));
1199
+ }
1200
+ v = lowerConst(v, use);
1201
+ if (tSided && typeof v === "number")
1202
+ return TX_BASE + v;
1203
+ return v;
1204
+ };
1205
+ return [[c.op, ...c.args.map(operand)]];
1206
+ };
1207
+ const having = havingCmps.map(lowerHavingCmp);
1208
+ const emptyRowPasses = () => having.every((clause) => {
1209
+ const [op, ...args] = clause[0];
1210
+ const vals = args.map((a) => (typeof a === "string" && emptyCells.has(a) ? emptyCells.get(a) : a));
1211
+ if (op === "in") {
1212
+ const [v, list] = vals;
1213
+ return Array.isArray(list) && list.some((x) => vkey(x) === vkey(v));
1214
+ }
1215
+ const f = PREDICATES[op];
1216
+ return f !== undefined && Boolean(f(...vals));
1217
+ });
1218
+ const withVars = [];
1219
+ if (provenanceVars.size > 0) {
1220
+ const walkGroups = (list, visit) => {
1221
+ for (const c of list) {
1222
+ visit(c);
1223
+ if (c._tag === "orGroup")
1224
+ c.branches.forEach((b) => walkGroups(b, visit));
1225
+ }
1226
+ };
1227
+ const fnBindArgs = new Map();
1228
+ walkGroups(clauses, (c) => {
1229
+ if (c._tag === "fnBind")
1230
+ fnBindArgs.set(c.ret.id, c.args);
1231
+ });
1232
+ const rideableDirect = [];
1233
+ const queue = [...provenanceVars];
1234
+ for (let i = 0; i < queue.length; i++) {
1235
+ const args = fnBindArgs.get(queue[i]);
1236
+ if (args === undefined)
1237
+ continue;
1238
+ for (const a of args) {
1239
+ if (!isVar(a))
1240
+ continue;
1241
+ if (a.kind === "entity" || a.kind === "tx") {
1242
+ rideableDirect.push(a);
1243
+ continue;
1244
+ }
1245
+ if (!provenanceVars.has(a.id)) {
1246
+ provenanceVars.add(a.id);
1247
+ queue.push(a.id);
1248
+ }
1249
+ }
1250
+ }
1251
+ const topLevelBound = new Set();
1252
+ for (const c of clauses) {
1253
+ switch (c._tag) {
1254
+ case "fact":
1255
+ factVars(c, topLevelBound);
1256
+ break;
1257
+ case "fnBind":
1258
+ for (const a of c.args)
1259
+ if (isVar(a))
1260
+ topLevelBound.add(a.id);
1261
+ topLevelBound.add(c.ret.id);
1262
+ break;
1263
+ case "memberOf":
1264
+ topLevelBound.add(c.v.id);
1265
+ break;
1266
+ case "ruleCall":
1267
+ for (const a of c.args)
1268
+ if (isVar(a))
1269
+ topLevelBound.add(a.id);
1270
+ topLevelBound.add(c.ret.id);
1271
+ break;
1272
+ case "orGroup": {
1273
+ const inner = new Set();
1274
+ c.branches.forEach((b) => clauseListVars(b, inner));
1275
+ const rest = clauseListVars(clauses.filter((s) => s !== c));
1276
+ for (const id of inner) {
1277
+ if (rest.has(id) || projVars.has(id) || topLevelBound.has(id)) {
1278
+ topLevelBound.add(id);
1279
+ }
1280
+ }
1281
+ break;
1282
+ }
1283
+ }
1284
+ }
1285
+ const seen = new Set();
1286
+ const ride = (e, requireBound) => {
1287
+ if (!isVar(e) || projVars.has(e.id) || seen.has(e.id))
1288
+ return;
1289
+ if (requireBound && !topLevelBound.has(e.id))
1290
+ return;
1291
+ seen.add(e.id);
1292
+ withVars.push(nameOf(e));
1293
+ };
1294
+ for (const v of rideableDirect)
1295
+ ride(v, true);
1296
+ const walkFacts = (list, nested) => {
1297
+ for (const c of list) {
1298
+ if (c._tag === "fact") {
1299
+ const v = c.vVar ?? c.v0;
1300
+ const bindsValue = (isVar(v) && provenanceVars.has(v.id)) ||
1301
+ (c.txVar !== undefined && provenanceVars.has(c.txVar.id)) ||
1302
+ (c.opVar !== undefined && provenanceVars.has(c.opVar.id));
1303
+ if (!bindsValue)
1304
+ continue;
1305
+ ride(c.eVar ?? c.e0, nested);
1306
+ }
1307
+ else if (c._tag === "orGroup") {
1308
+ c.branches.forEach((b) => walkFacts(b, true));
1309
+ }
1310
+ }
1311
+ };
1312
+ walkFacts(clauses, false);
1313
+ }
1314
+ const order = [];
1315
+ const queryAggregates = flats.some((f) => f.agg !== undefined);
1316
+ const bindOrderPath = (path, revs, ref, dir, empty) => {
1317
+ const group = built.groupKeys.get(groupKeyId(path, revs));
1318
+ if (group !== undefined) {
1319
+ order.push({ var: nameOf(group), dir, empty });
1320
+ return;
1321
+ }
1322
+ if (queryAggregates) {
1323
+ throw new Error(`ramose/query: orderBy(${path.join(" → ")}) is not a group key of this select — an aggregate query orders only by a projected cell`);
1324
+ }
1325
+ if (built.focus === undefined) {
1326
+ throw new Error("ramose/query: orderBy(attribute) needs a select focus — order a multi-root projection by a projected cell or bound var");
1327
+ }
1328
+ const bound = lowerOrderPath(nameOf(built.focus), path, revs);
1329
+ if (!kinds.has(bound.var))
1330
+ kinds.set(bound.var, ref ? "entity" : "value");
1331
+ where.push(...bound.clauses);
1332
+ order.push({ var: bound.var, dir, empty });
1333
+ };
1334
+ const orderFromPicked = (picked, label, dir, empty) => {
1335
+ if (isVar(picked)) {
1336
+ const v = isFocusSentinel(picked)
1337
+ ? built.focus ??
1338
+ (() => {
1339
+ throw new Error("ramose/query: Q.focus needs a select focus — order a projected cell instead");
1340
+ })()
1341
+ : picked;
1342
+ order.push({ var: nameOf(v), dir, empty });
1343
+ return;
1344
+ }
1345
+ if (isAggSpec(picked)) {
1346
+ const v = isFocusSentinel(picked.v)
1347
+ ? built.focus ??
1348
+ (() => {
1349
+ throw new Error("ramose/query: Q.focus needs a select focus — order a projected cell instead");
1350
+ })()
1351
+ : picked.v;
1352
+ order.push({ var: nameOf(v), dir, empty });
1353
+ return;
1354
+ }
1355
+ if (isPathCarrier(picked)) {
1356
+ if (cardsOf(picked).includes("many")) {
1357
+ throw new Error(`ramose/query: orderBy(${pathOf(picked).join(" → ")}) crosses a cardinality-many attribute — the sort key would be a set, not a value`);
1358
+ }
1359
+ bindOrderPath(pathOf(picked), revsOf(picked), isRefCarrier(picked), dir, empty);
1360
+ return;
1361
+ }
1362
+ throw new Error(`ramose/query: ${label} did not pick a bound var, projected cell, or attribute`);
1363
+ };
1364
+ const lookupCell = (tree, key) => {
1365
+ if (tree !== null && typeof tree === "object" && !Array.isArray(tree)) {
1366
+ return tree[key];
1367
+ }
1368
+ return undefined;
1369
+ };
1370
+ if (built.order.length > 0) {
1371
+ for (const o of built.order) {
1372
+ if (o.kind === "cell") {
1373
+ orderFromPicked(o.cell, "orderBy", o.dir, o.empty);
1374
+ }
1375
+ else if (o.kind === "path") {
1376
+ bindOrderPath(o.path, o.revs, o.ref, o.dir, o.empty);
1377
+ }
1378
+ else {
1379
+ throw new Error("ramose/query: orderBy leftover is not a projected cell or attribute path");
1380
+ }
1381
+ }
1382
+ }
1383
+ if (!qv.stripCursor) {
1384
+ const cells = projectionCells(proj);
1385
+ for (const o of qv.orders) {
1386
+ let picked = o.key;
1387
+ if (typeof o.key === "function") {
1388
+ picked = o.key(cells);
1389
+ }
1390
+ else if (typeof o.key === "string") {
1391
+ picked = lookupCell(cells, o.key);
1392
+ if (picked === undefined) {
1393
+ throw new Error(`ramose/query: orderBy("${o.key}") — the projection has no column "${o.key}"`);
1394
+ }
1395
+ }
1396
+ orderFromPicked(picked, "orderBy", o.dir, o.empty);
1397
+ }
1398
+ }
1399
+ if (isValueSpec(proj) && (order.length > 0 || qv.limitN !== undefined || qv.offsetN !== undefined || qv.seek !== undefined)) {
1400
+ throw new Error("ramose/query: Q.value is a single value — orderBy / limit / offset / after page rows");
1401
+ }
1402
+ const boundCount = (n, what) => {
1403
+ if (n === undefined)
1404
+ return undefined;
1405
+ if (!Number.isInteger(n) || n < 0) {
1406
+ throw new Error(`ramose/query: ${what} takes a non-negative integer, got ${String(n)}`);
1407
+ }
1408
+ return n;
1409
+ };
1410
+ const take = qv.stripCursor ? undefined : qv.take;
1411
+ const seek = qv.stripCursor ? undefined : qv.seek;
1412
+ const limit = take === "one"
1413
+ ? 1
1414
+ : take === "oneOrFail"
1415
+ ? 2
1416
+ : boundCount(qv.stripCursor ? undefined : (qv.limitN ?? built.limit), "limit");
1417
+ const offset = boundCount(qv.stripCursor ? undefined : (qv.offsetN ?? built.offset), "offset");
1418
+ const pagedVars = [];
1419
+ const pagedEntities = [];
1420
+ if (seek !== undefined) {
1421
+ if (offset !== undefined) {
1422
+ throw new Error("ramose/query: after(...) and offset both say where the page starts — a cursor already is the offset");
1423
+ }
1424
+ if (order.length === 0) {
1425
+ throw new Error("ramose/query: after(...) pages a sorted query — add an orderBy for the cursor to be a position in");
1426
+ }
1427
+ if (built.focus === undefined) {
1428
+ throw new Error("ramose/query: after(...) pages by a root entity's id as tie-breaker — a multi-root projection has no paging root");
1429
+ }
1430
+ const root = nameOf(built.focus);
1431
+ if (!order.some((o) => o.var === root)) {
1432
+ order.push({ var: root, dir: "asc", empty: "last" });
1433
+ }
1434
+ pagedVars.push(...order.map((o) => o.var));
1435
+ pagedEntities.push(...order.map((o) => kinds.get(o.var) === "entity" || kinds.get(o.var) === "id"));
1436
+ if (seek !== null && seek.keys.length !== order.length) {
1437
+ throw new Error(`ramose/query: this cursor does not fit — it carries ${seek.keys.length} sort-key values and the query orders by ${order.length}; a cursor only continues the query that minted it`);
1438
+ }
1439
+ find.push(...pagedVars);
1440
+ }
1441
+ const baseLen = find.length - pagedVars.length;
1442
+ const resolveCursorCell = (key, index) => {
1443
+ if (pagedEntities[index] !== true)
1444
+ return key;
1445
+ const resolve = lowering?.resolveEntity;
1446
+ if (resolve === undefined)
1447
+ return key;
1448
+ bindsEntities = true;
1449
+ const eid = resolve(key);
1450
+ if (eid === undefined) {
1451
+ throw new InvalidRequest({
1452
+ message: "ramose/query: this cursor names an entity this client cannot resolve — a cursor only continues the page that minted it, on the replica that minted it",
1453
+ });
1454
+ }
1455
+ return eid;
1456
+ };
1457
+ const query = {
1458
+ find,
1459
+ where,
1460
+ ...(withVars.length > 0 ? { with: withVars } : {}),
1461
+ ...(having.length > 0 ? { having } : {}),
1462
+ ...(ruleDefs.length > 0 ? { rules: ruleDefs } : {}),
1463
+ ...(order.length > 0 ? { order } : {}),
1464
+ ...(seek !== undefined && seek !== null
1465
+ ? { after: seek.keys.map((key, index) => resolveCursorCell(key, index)) }
1466
+ : {}),
1467
+ ...(limit !== undefined ? { limit } : {}),
1468
+ ...(offset !== undefined ? { offset } : {}),
1469
+ };
1470
+ const rowShape = JSON.stringify({
1471
+ projection,
1472
+ root: rootPlan,
1473
+ cells: flats.map((cell) => [cell.path, cell.agg ?? null, cell.plan ?? null]),
1474
+ scalar,
1475
+ });
1476
+ return {
1477
+ query,
1478
+ bindsEntities,
1479
+ result: seek !== undefined ? "page" : take !== undefined ? "row" : "rows",
1480
+ rowShape,
1481
+ shape: JSON.stringify({
1482
+ row: rowShape,
1483
+ take: take ?? null,
1484
+ paged: seek !== undefined,
1485
+ }),
1486
+ finalize: (result) => {
1487
+ if (scalar) {
1488
+ const cell = flats[0];
1489
+ const empty = cell.agg !== undefined ? EMPTY_AGG[cell.agg] : null;
1490
+ if (result === null || result === undefined) {
1491
+ return cell.agg !== undefined && emptyRowPasses() ? cell.read(empty) : null;
1492
+ }
1493
+ if (Array.isArray(result)) {
1494
+ const first = result[0];
1495
+ const raw = Array.isArray(first) ? first[0] : first;
1496
+ if (raw === undefined) {
1497
+ return cell.agg !== undefined && emptyRowPasses() ? cell.read(empty) : null;
1498
+ }
1499
+ return cell.read(raw);
1500
+ }
1501
+ return cell.read(result);
1502
+ }
1503
+ const tuples = Array.isArray(result) ? result : [];
1504
+ const rows = finalizeRows(tuples);
1505
+ if (seek !== undefined) {
1506
+ const last = tuples[tuples.length - 1];
1507
+ return {
1508
+ rows,
1509
+ cursor: !Array.isArray(last) ||
1510
+ (typeof limit === "number" && tuples.length < limit)
1511
+ ? null
1512
+ : {
1513
+ _tag: "Cursor",
1514
+ keys: last.slice(baseLen).map((key, index) => pagedEntities[index] === true && typeof key === "number"
1515
+ ? entityId(key)
1516
+ : key),
1517
+ },
1518
+ };
1519
+ }
1520
+ if (take !== undefined) {
1521
+ if (take === "one")
1522
+ return rows[0] ?? null;
1523
+ if (rows.length === 1)
1524
+ return rows[0];
1525
+ return new NotOne({
1526
+ message: rows.length === 0
1527
+ ? "ramose/query: expected exactly one row, found none"
1528
+ : "ramose/query: expected exactly one row, found 2",
1529
+ found: rows.length === 0 ? 0 : 2,
1530
+ });
1531
+ }
1532
+ return rows;
1533
+ },
1534
+ };
1535
+ };
1536
+ //# sourceMappingURL=query.js.map