@xtandard/permissions 0.0.0-stage → 0.1.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 (375) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +362 -2
  3. package/bin/xtandard-permissions.mjs +3 -0
  4. package/dist/better-auth-Bp9YVyQa.d.cts +56 -0
  5. package/dist/better-auth-DHyW5-yt.cjs +91 -0
  6. package/dist/better-auth-DHyW5-yt.cjs.map +1 -0
  7. package/dist/better-auth-NO40ZqSM.mjs +74 -0
  8. package/dist/better-auth-NO40ZqSM.mjs.map +1 -0
  9. package/dist/better-auth-NSXgt6ZU.d.mts +56 -0
  10. package/dist/catalog-DA_d1SdC.d.cts +153 -0
  11. package/dist/catalog-DJcJ3ycq.d.mts +153 -0
  12. package/dist/catalog.cjs +198 -0
  13. package/dist/catalog.cjs.map +1 -0
  14. package/dist/catalog.d.cts +3 -0
  15. package/dist/catalog.d.mts +3 -0
  16. package/dist/catalog.mjs +141 -0
  17. package/dist/catalog.mjs.map +1 -0
  18. package/dist/chunk-DakpK96I.cjs +43 -0
  19. package/dist/cli.cjs +548 -0
  20. package/dist/cli.cjs.map +1 -0
  21. package/dist/cli.d.cts +28 -0
  22. package/dist/cli.d.mts +28 -0
  23. package/dist/cli.mjs +544 -0
  24. package/dist/cli.mjs.map +1 -0
  25. package/dist/contract-BMiOmg2f.d.cts +50 -0
  26. package/dist/contract-Bpy8yPrS.cjs +70 -0
  27. package/dist/contract-Bpy8yPrS.cjs.map +1 -0
  28. package/dist/contract-CNgMXr2u.d.cts +46 -0
  29. package/dist/contract-CNgMXr2u.d.mts +46 -0
  30. package/dist/contract-CPmJVoRx.cjs +70 -0
  31. package/dist/contract-CPmJVoRx.cjs.map +1 -0
  32. package/dist/contract-D32H1t0u.d.mts +50 -0
  33. package/dist/contract-DTdTXZtJ.mjs +47 -0
  34. package/dist/contract-DTdTXZtJ.mjs.map +1 -0
  35. package/dist/contract-DUzgB-He.d.mts +375 -0
  36. package/dist/contract-Dk6d2ylD.d.cts +375 -0
  37. package/dist/contract-RMkmERhT.d.cts +2 -0
  38. package/dist/contract-RMkmERhT.d.mts +2 -0
  39. package/dist/contract-Yc5AZuvv.mjs +47 -0
  40. package/dist/contract-Yc5AZuvv.mjs.map +1 -0
  41. package/dist/create-fetch-handler-BHDU4chu.d.mts +77 -0
  42. package/dist/create-fetch-handler-BtX64_rS.d.cts +77 -0
  43. package/dist/create-fetch-handler-C-WyaRCR.cjs +653 -0
  44. package/dist/create-fetch-handler-C-WyaRCR.cjs.map +1 -0
  45. package/dist/create-fetch-handler-ojjpk1Iw.mjs +636 -0
  46. package/dist/create-fetch-handler-ojjpk1Iw.mjs.map +1 -0
  47. package/dist/elysia-shared-BM6cPoCU.mjs +78 -0
  48. package/dist/elysia-shared-BM6cPoCU.mjs.map +1 -0
  49. package/dist/elysia-shared-BUTFTeal.cjs +101 -0
  50. package/dist/elysia-shared-BUTFTeal.cjs.map +1 -0
  51. package/dist/elysia-shared-DtKViycb.d.cts +58 -0
  52. package/dist/elysia-shared-g8zsb_pU.d.mts +58 -0
  53. package/dist/engine-Bufv0TbD.mjs +574 -0
  54. package/dist/engine-Bufv0TbD.mjs.map +1 -0
  55. package/dist/engine-CGGVDCqi.d.cts +296 -0
  56. package/dist/engine-DpFIcbgh.d.mts +296 -0
  57. package/dist/engine-bMoz3iW-.cjs +587 -0
  58. package/dist/engine-bMoz3iW-.cjs.map +1 -0
  59. package/dist/entry-auth-basic.cjs +40 -0
  60. package/dist/entry-auth-basic.cjs.map +1 -0
  61. package/dist/entry-auth-basic.d.cts +24 -0
  62. package/dist/entry-auth-basic.d.mts +24 -0
  63. package/dist/entry-auth-basic.mjs +26 -0
  64. package/dist/entry-auth-basic.mjs.map +1 -0
  65. package/dist/entry-auth-better-auth.cjs +12 -0
  66. package/dist/entry-auth-better-auth.d.cts +5 -0
  67. package/dist/entry-auth-better-auth.d.mts +5 -0
  68. package/dist/entry-auth-better-auth.mjs +4 -0
  69. package/dist/entry-auth-delegated.cjs +8 -0
  70. package/dist/entry-auth-delegated.d.cts +2 -0
  71. package/dist/entry-auth-delegated.d.mts +2 -0
  72. package/dist/entry-auth-delegated.mjs +2 -0
  73. package/dist/entry-auth-jwt.cjs +116 -0
  74. package/dist/entry-auth-jwt.cjs.map +1 -0
  75. package/dist/entry-auth-jwt.d.cts +65 -0
  76. package/dist/entry-auth-jwt.d.mts +65 -0
  77. package/dist/entry-auth-jwt.mjs +108 -0
  78. package/dist/entry-auth-jwt.mjs.map +1 -0
  79. package/dist/entry-auth-none.cjs +14 -0
  80. package/dist/entry-auth-none.d.cts +2 -0
  81. package/dist/entry-auth-none.d.mts +2 -0
  82. package/dist/entry-auth-none.mjs +2 -0
  83. package/dist/entry-auth-session.cjs +82 -0
  84. package/dist/entry-auth-session.cjs.map +1 -0
  85. package/dist/entry-auth-session.d.cts +20 -0
  86. package/dist/entry-auth-session.d.mts +20 -0
  87. package/dist/entry-auth-session.mjs +75 -0
  88. package/dist/entry-auth-session.mjs.map +1 -0
  89. package/dist/entry-authorization-delegated.cjs +31 -0
  90. package/dist/entry-authorization-delegated.cjs.map +1 -0
  91. package/dist/entry-authorization-delegated.d.cts +27 -0
  92. package/dist/entry-authorization-delegated.d.mts +27 -0
  93. package/dist/entry-authorization-delegated.mjs +30 -0
  94. package/dist/entry-authorization-delegated.mjs.map +1 -0
  95. package/dist/entry-authorization-none.cjs +29 -0
  96. package/dist/entry-authorization-none.cjs.map +1 -0
  97. package/dist/entry-authorization-none.d.cts +17 -0
  98. package/dist/entry-authorization-none.d.mts +17 -0
  99. package/dist/entry-authorization-none.mjs +28 -0
  100. package/dist/entry-authorization-none.mjs.map +1 -0
  101. package/dist/entry-authorization-permissions.cjs +4 -0
  102. package/dist/entry-authorization-permissions.d.cts +49 -0
  103. package/dist/entry-authorization-permissions.d.mts +49 -0
  104. package/dist/entry-authorization-permissions.mjs +2 -0
  105. package/dist/entry-authorization-roles.cjs +9 -0
  106. package/dist/entry-authorization-roles.d.cts +37 -0
  107. package/dist/entry-authorization-roles.d.mts +37 -0
  108. package/dist/entry-authorization-roles.mjs +3 -0
  109. package/dist/entry-better-auth-client.cjs +31 -0
  110. package/dist/entry-better-auth-client.cjs.map +1 -0
  111. package/dist/entry-better-auth-client.d.cts +63 -0
  112. package/dist/entry-better-auth-client.d.mts +63 -0
  113. package/dist/entry-better-auth-client.mjs +29 -0
  114. package/dist/entry-better-auth-client.mjs.map +1 -0
  115. package/dist/entry-better-auth.cjs +289 -0
  116. package/dist/entry-better-auth.cjs.map +1 -0
  117. package/dist/entry-better-auth.d.cts +3 -0
  118. package/dist/entry-better-auth.d.mts +3 -0
  119. package/dist/entry-better-auth.mjs +284 -0
  120. package/dist/entry-better-auth.mjs.map +1 -0
  121. package/dist/entry-bridges-audit.cjs +106 -0
  122. package/dist/entry-bridges-audit.cjs.map +1 -0
  123. package/dist/entry-bridges-audit.d.cts +58 -0
  124. package/dist/entry-bridges-audit.d.mts +58 -0
  125. package/dist/entry-bridges-audit.mjs +105 -0
  126. package/dist/entry-bridges-audit.mjs.map +1 -0
  127. package/dist/entry-bridges-webhooks.cjs +90 -0
  128. package/dist/entry-bridges-webhooks.cjs.map +1 -0
  129. package/dist/entry-bridges-webhooks.d.cts +46 -0
  130. package/dist/entry-bridges-webhooks.d.mts +46 -0
  131. package/dist/entry-bridges-webhooks.mjs +88 -0
  132. package/dist/entry-bridges-webhooks.mjs.map +1 -0
  133. package/dist/entry-bun.cjs +33 -0
  134. package/dist/entry-bun.cjs.map +1 -0
  135. package/dist/entry-bun.d.cts +31 -0
  136. package/dist/entry-bun.d.mts +31 -0
  137. package/dist/entry-bun.mjs +30 -0
  138. package/dist/entry-bun.mjs.map +1 -0
  139. package/dist/entry-drizzle-mysql.cjs +34 -0
  140. package/dist/entry-drizzle-mysql.cjs.map +1 -0
  141. package/dist/entry-drizzle-mysql.d.cts +20 -0
  142. package/dist/entry-drizzle-mysql.d.mts +20 -0
  143. package/dist/entry-drizzle-mysql.mjs +33 -0
  144. package/dist/entry-drizzle-mysql.mjs.map +1 -0
  145. package/dist/entry-drizzle-pg.cjs +44 -0
  146. package/dist/entry-drizzle-pg.cjs.map +1 -0
  147. package/dist/entry-drizzle-pg.d.cts +20 -0
  148. package/dist/entry-drizzle-pg.d.mts +20 -0
  149. package/dist/entry-drizzle-pg.mjs +43 -0
  150. package/dist/entry-drizzle-pg.mjs.map +1 -0
  151. package/dist/entry-drizzle-sqlite.cjs +34 -0
  152. package/dist/entry-drizzle-sqlite.cjs.map +1 -0
  153. package/dist/entry-drizzle-sqlite.d.cts +15 -0
  154. package/dist/entry-drizzle-sqlite.d.mts +15 -0
  155. package/dist/entry-drizzle-sqlite.mjs +33 -0
  156. package/dist/entry-drizzle-sqlite.mjs.map +1 -0
  157. package/dist/entry-elysia.cjs +117 -0
  158. package/dist/entry-elysia.cjs.map +1 -0
  159. package/dist/entry-elysia.d.cts +446 -0
  160. package/dist/entry-elysia.d.mts +446 -0
  161. package/dist/entry-elysia.mjs +113 -0
  162. package/dist/entry-elysia.mjs.map +1 -0
  163. package/dist/entry-elysia2.cjs +117 -0
  164. package/dist/entry-elysia2.cjs.map +1 -0
  165. package/dist/entry-elysia2.d.cts +571 -0
  166. package/dist/entry-elysia2.d.mts +571 -0
  167. package/dist/entry-elysia2.mjs +113 -0
  168. package/dist/entry-elysia2.mjs.map +1 -0
  169. package/dist/entry-express.cjs +101 -0
  170. package/dist/entry-express.cjs.map +1 -0
  171. package/dist/entry-express.d.cts +36 -0
  172. package/dist/entry-express.d.mts +36 -0
  173. package/dist/entry-express.mjs +97 -0
  174. package/dist/entry-express.mjs.map +1 -0
  175. package/dist/entry-hono.cjs +63 -0
  176. package/dist/entry-hono.cjs.map +1 -0
  177. package/dist/entry-hono.d.cts +40 -0
  178. package/dist/entry-hono.d.mts +40 -0
  179. package/dist/entry-hono.mjs +60 -0
  180. package/dist/entry-hono.mjs.map +1 -0
  181. package/dist/entry-hooks-log.cjs +39 -0
  182. package/dist/entry-hooks-log.cjs.map +1 -0
  183. package/dist/entry-hooks-log.d.cts +19 -0
  184. package/dist/entry-hooks-log.d.mts +19 -0
  185. package/dist/entry-hooks-log.mjs +36 -0
  186. package/dist/entry-hooks-log.mjs.map +1 -0
  187. package/dist/entry-next.cjs +67 -0
  188. package/dist/entry-next.cjs.map +1 -0
  189. package/dist/entry-next.d.cts +60 -0
  190. package/dist/entry-next.d.mts +60 -0
  191. package/dist/entry-next.mjs +57 -0
  192. package/dist/entry-next.mjs.map +1 -0
  193. package/dist/entry-react.cjs +401 -0
  194. package/dist/entry-react.cjs.map +1 -0
  195. package/dist/entry-react.d.cts +206 -0
  196. package/dist/entry-react.d.mts +206 -0
  197. package/dist/entry-react.mjs +388 -0
  198. package/dist/entry-react.mjs.map +1 -0
  199. package/dist/entry-storage-cloudflare-kv.cjs +8 -0
  200. package/dist/entry-storage-cloudflare-kv.d.cts +2 -0
  201. package/dist/entry-storage-cloudflare-kv.d.mts +2 -0
  202. package/dist/entry-storage-cloudflare-kv.mjs +2 -0
  203. package/dist/entry-storage-drizzle.cjs +71 -0
  204. package/dist/entry-storage-drizzle.cjs.map +1 -0
  205. package/dist/entry-storage-drizzle.d.cts +27 -0
  206. package/dist/entry-storage-drizzle.d.mts +27 -0
  207. package/dist/entry-storage-drizzle.mjs +68 -0
  208. package/dist/entry-storage-drizzle.mjs.map +1 -0
  209. package/dist/entry-storage-file.cjs +54 -0
  210. package/dist/entry-storage-file.cjs.map +1 -0
  211. package/dist/entry-storage-file.d.cts +24 -0
  212. package/dist/entry-storage-file.d.mts +24 -0
  213. package/dist/entry-storage-file.mjs +46 -0
  214. package/dist/entry-storage-file.mjs.map +1 -0
  215. package/dist/entry-storage-libsql.cjs +64 -0
  216. package/dist/entry-storage-libsql.cjs.map +1 -0
  217. package/dist/entry-storage-libsql.d.cts +28 -0
  218. package/dist/entry-storage-libsql.d.mts +28 -0
  219. package/dist/entry-storage-libsql.mjs +61 -0
  220. package/dist/entry-storage-libsql.mjs.map +1 -0
  221. package/dist/entry-storage-memory.cjs +3 -0
  222. package/dist/entry-storage-memory.d.cts +25 -0
  223. package/dist/entry-storage-memory.d.mts +25 -0
  224. package/dist/entry-storage-memory.mjs +2 -0
  225. package/dist/entry-storage-mongodb.cjs +61 -0
  226. package/dist/entry-storage-mongodb.cjs.map +1 -0
  227. package/dist/entry-storage-mongodb.d.cts +25 -0
  228. package/dist/entry-storage-mongodb.d.mts +25 -0
  229. package/dist/entry-storage-mongodb.mjs +58 -0
  230. package/dist/entry-storage-mongodb.mjs.map +1 -0
  231. package/dist/entry-storage-postgres.cjs +62 -0
  232. package/dist/entry-storage-postgres.cjs.map +1 -0
  233. package/dist/entry-storage-postgres.d.cts +29 -0
  234. package/dist/entry-storage-postgres.d.mts +29 -0
  235. package/dist/entry-storage-postgres.mjs +58 -0
  236. package/dist/entry-storage-postgres.mjs.map +1 -0
  237. package/dist/entry-storage-redis.cjs +76 -0
  238. package/dist/entry-storage-redis.cjs.map +1 -0
  239. package/dist/entry-storage-redis.d.cts +29 -0
  240. package/dist/entry-storage-redis.d.mts +29 -0
  241. package/dist/entry-storage-redis.mjs +72 -0
  242. package/dist/entry-storage-redis.mjs.map +1 -0
  243. package/dist/entry-storage-sqlite.cjs +46 -0
  244. package/dist/entry-storage-sqlite.cjs.map +1 -0
  245. package/dist/entry-storage-sqlite.d.cts +22 -0
  246. package/dist/entry-storage-sqlite.d.mts +22 -0
  247. package/dist/entry-storage-sqlite.mjs +43 -0
  248. package/dist/entry-storage-sqlite.mjs.map +1 -0
  249. package/dist/entry-storage-unstorage.cjs +8 -0
  250. package/dist/entry-storage-unstorage.d.cts +2 -0
  251. package/dist/entry-storage-unstorage.d.mts +2 -0
  252. package/dist/entry-storage-unstorage.mjs +2 -0
  253. package/dist/error-codes-9MRMSSMQ.cjs +49 -0
  254. package/dist/error-codes-9MRMSSMQ.cjs.map +1 -0
  255. package/dist/error-codes-CCKuDDu7.mjs +44 -0
  256. package/dist/error-codes-CCKuDDu7.mjs.map +1 -0
  257. package/dist/errors-bL3XQLfE.mjs +54 -0
  258. package/dist/errors-bL3XQLfE.mjs.map +1 -0
  259. package/dist/errors-vVYic8gz.cjs +89 -0
  260. package/dist/errors-vVYic8gz.cjs.map +1 -0
  261. package/dist/events-AE4Ytqmz.d.cts +6 -0
  262. package/dist/events-AE4Ytqmz.d.mts +6 -0
  263. package/dist/events-DYZShrYB.mjs +15 -0
  264. package/dist/events-DYZShrYB.mjs.map +1 -0
  265. package/dist/events-FJ2K0wly.cjs +26 -0
  266. package/dist/events-FJ2K0wly.cjs.map +1 -0
  267. package/dist/guard-BOx5cnMP.mjs +141 -0
  268. package/dist/guard-BOx5cnMP.mjs.map +1 -0
  269. package/dist/guard-C3o7V14m.d.cts +62 -0
  270. package/dist/guard-DCbTnqPz.d.mts +62 -0
  271. package/dist/guard-nwdOYe90.cjs +188 -0
  272. package/dist/guard-nwdOYe90.cjs.map +1 -0
  273. package/dist/index-BVVgDSdq.d.cts +1 -0
  274. package/dist/index-BVVgDSdq.d.mts +1 -0
  275. package/dist/index.cjs +240 -0
  276. package/dist/index.cjs.map +1 -0
  277. package/dist/index.d.cts +195 -0
  278. package/dist/index.d.mts +195 -0
  279. package/dist/index.mjs +60 -0
  280. package/dist/index.mjs.map +1 -0
  281. package/dist/kit-C7tepDB2.cjs +76 -0
  282. package/dist/kit-C7tepDB2.cjs.map +1 -0
  283. package/dist/kit-DMVBLBI9.d.mts +57 -0
  284. package/dist/kit-fzXHYb1l.mjs +65 -0
  285. package/dist/kit-fzXHYb1l.mjs.map +1 -0
  286. package/dist/kit-qAROuhOI.d.cts +57 -0
  287. package/dist/memory-BbBbbY8-.mjs +32 -0
  288. package/dist/memory-BbBbbY8-.mjs.map +1 -0
  289. package/dist/memory-knijqKw_.cjs +39 -0
  290. package/dist/memory-knijqKw_.cjs.map +1 -0
  291. package/dist/permissions-C9PjftY6.mjs +59 -0
  292. package/dist/permissions-C9PjftY6.mjs.map +1 -0
  293. package/dist/permissions-Cxri_P_k.cjs +70 -0
  294. package/dist/permissions-Cxri_P_k.cjs.map +1 -0
  295. package/dist/policy-BQmlo2lu.mjs +3 -0
  296. package/dist/policy-CGA6QD0a.d.mts +4 -0
  297. package/dist/policy-DFq_SYR3.d.cts +4 -0
  298. package/dist/react-embed.js +18710 -0
  299. package/dist/react.css +1 -0
  300. package/dist/relationships-BLYEJ9tc.cjs +907 -0
  301. package/dist/relationships-BLYEJ9tc.cjs.map +1 -0
  302. package/dist/relationships-BfLonEMI.mjs +756 -0
  303. package/dist/relationships-BfLonEMI.mjs.map +1 -0
  304. package/dist/roles-DBk4i8b5.mjs +69 -0
  305. package/dist/roles-DBk4i8b5.mjs.map +1 -0
  306. package/dist/roles-a8B5uZ35.cjs +104 -0
  307. package/dist/roles-a8B5uZ35.cjs.map +1 -0
  308. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  309. package/dist/routes-DtRb3EO0.mjs +1001 -0
  310. package/dist/routes-DtRb3EO0.mjs.map +1 -0
  311. package/dist/routes-irNuuZqo.cjs +1049 -0
  312. package/dist/routes-irNuuZqo.cjs.map +1 -0
  313. package/dist/server-C2F4H6bR.d.cts +886 -0
  314. package/dist/server-CJ7AIJpO.d.mts +886 -0
  315. package/dist/table-DA98mVVT.d.cts +2 -0
  316. package/dist/table-DA98mVVT.d.mts +2 -0
  317. package/dist/testing.cjs +59 -0
  318. package/dist/testing.cjs.map +1 -0
  319. package/dist/testing.d.cts +37 -0
  320. package/dist/testing.d.mts +37 -0
  321. package/dist/testing.mjs +57 -0
  322. package/dist/testing.mjs.map +1 -0
  323. package/dist/types-elysia2/adapters/elysia-shared.d.ts +71 -0
  324. package/dist/types-elysia2/adapters/elysia2.d.ts +432 -0
  325. package/dist/types-elysia2/adapters/guard.d.ts +140 -0
  326. package/dist/types-elysia2/auth/contract.d.ts +9 -0
  327. package/dist/types-elysia2/auth-provider/contract.d.ts +57 -0
  328. package/dist/types-elysia2/auth-provider/kit.d.ts +57 -0
  329. package/dist/types-elysia2/authorization/contract.d.ts +53 -0
  330. package/dist/types-elysia2/authorization/permissions.d.ts +54 -0
  331. package/dist/types-elysia2/catalog.d.ts +197 -0
  332. package/dist/types-elysia2/engine.d.ts +192 -0
  333. package/dist/types-elysia2/entry-elysia2.d.ts +9 -0
  334. package/dist/types-elysia2/errors.d.ts +47 -0
  335. package/dist/types-elysia2/hooks/contract.d.ts +100 -0
  336. package/dist/types-elysia2/keys.d.ts +78 -0
  337. package/dist/types-elysia2/policy.d.ts +13 -0
  338. package/dist/types-elysia2/relationships.d.ts +162 -0
  339. package/dist/types-elysia2/schema.d.ts +299 -0
  340. package/dist/types-elysia2/server/cors.d.ts +8 -0
  341. package/dist/types-elysia2/server/create-fetch-handler.d.ts +87 -0
  342. package/dist/types-elysia2/server/openapi.d.ts +29 -0
  343. package/dist/types-elysia2/server/routes.d.ts +132 -0
  344. package/dist/types-elysia2/server/validation.d.ts +205 -0
  345. package/dist/types-elysia2/storage/contract.d.ts +18 -0
  346. package/dist/types-react/catalog.d.ts +197 -0
  347. package/dist/types-react/engine.d.ts +192 -0
  348. package/dist/types-react/entry-react-embed.d.ts +20 -0
  349. package/dist/types-react/errors.d.ts +47 -0
  350. package/dist/types-react/hooks/contract.d.ts +100 -0
  351. package/dist/types-react/keys.d.ts +78 -0
  352. package/dist/types-react/policy.d.ts +13 -0
  353. package/dist/types-react/react-embed.d.ts +37 -0
  354. package/dist/types-react/relationships.d.ts +162 -0
  355. package/dist/types-react/schema.d.ts +299 -0
  356. package/dist/types-react/storage/contract.d.ts +18 -0
  357. package/dist/types-react/ui/App.d.ts +23 -0
  358. package/dist/types-react/ui/api.d.ts +73 -0
  359. package/dist/types-react/ui/components/perm-bits.d.ts +64 -0
  360. package/dist/types-react/ui/lib/queries.d.ts +46 -0
  361. package/dist/types-react/ui/theme.d.ts +10 -0
  362. package/dist/types-react/ui/types.d.ts +109 -0
  363. package/dist/types-react/ui/views/CatalogView.d.ts +3 -0
  364. package/dist/types-react/ui/views/HistoryView.d.ts +6 -0
  365. package/dist/types-react/ui/views/PlaygroundView.d.ts +14 -0
  366. package/dist/types-react/ui/views/RelationshipsView.d.ts +6 -0
  367. package/dist/types-react/ui/views/SubjectDetailView.d.ts +7 -0
  368. package/dist/types-react/ui/views/SubjectsView.d.ts +6 -0
  369. package/dist/ui/apple-touch-icon.png +0 -0
  370. package/dist/ui/assets/index-DCPZRo-Z.css +1 -0
  371. package/dist/ui/assets/index-uXGOtyuj.js +104 -0
  372. package/dist/ui/favicon.ico +0 -0
  373. package/dist/ui/favicon.svg +15 -0
  374. package/dist/ui/index.html +20 -0
  375. package/package.json +587 -4
@@ -0,0 +1,907 @@
1
+ const require_chunk = require("./chunk-DakpK96I.cjs");
2
+ let valibot = require("valibot");
3
+ valibot = require_chunk.__toESM(valibot, 1);
4
+ let _xtandard_kit_util = require("@xtandard/kit/util");
5
+ let _xtandard_kit_hooks = require("@xtandard/kit/hooks");
6
+ let _xtandard_lib_policy_rebac = require("@xtandard/lib/policy/rebac");
7
+ let _xtandard_kit_storage = require("@xtandard/kit/storage");
8
+ //#region src/schema.ts
9
+ const nonEmpty = valibot.pipe(valibot.string(), valibot.minLength(1, "must not be empty"));
10
+ /** Who performs a write: an actor id, an {@link Actor}, or `null` (system). */
11
+ const actorSchema = valibot.nullable(valibot.union([nonEmpty, valibot.object({
12
+ id: nonEmpty,
13
+ type: valibot.optional(valibot.string()),
14
+ name: valibot.optional(valibot.string()),
15
+ email: valibot.optional(valibot.string())
16
+ })]));
17
+ const reasonSchema = valibot.pipe(valibot.string(), valibot.maxLength(1e3, "must be at most 1000 characters"));
18
+ const instantSchema = valibot.union([
19
+ valibot.pipe(valibot.string(), valibot.check((s) => !Number.isNaN(Date.parse(s)), "must be an ISO-8601 date")),
20
+ valibot.pipe(valibot.date(), valibot.check((date) => !Number.isNaN(date.getTime()), "must be a valid date")),
21
+ valibot.pipe(valibot.number(), valibot.finite())
22
+ ]);
23
+ /** Input of `grant()`. */
24
+ const grantInputSchema = valibot.object({
25
+ subject: nonEmpty,
26
+ permission: nonEmpty,
27
+ actor: valibot.optional(actorSchema),
28
+ reason: valibot.optional(reasonSchema),
29
+ /** ISO string, `Date` or unix ms; `null` = never. */
30
+ expiresAt: valibot.optional(valibot.nullable(instantSchema))
31
+ });
32
+ /** Input of `revoke()`. */
33
+ const revokeInputSchema = valibot.object({
34
+ subject: nonEmpty,
35
+ permission: nonEmpty,
36
+ actor: valibot.optional(actorSchema),
37
+ reason: valibot.optional(reasonSchema)
38
+ });
39
+ /** Input of `setRole()`; `role: null` clears the stored assignment. */
40
+ const setRoleInputSchema = valibot.object({
41
+ subject: nonEmpty,
42
+ role: valibot.nullable(nonEmpty),
43
+ actor: valibot.optional(actorSchema),
44
+ reason: valibot.optional(reasonSchema)
45
+ });
46
+ /** Input of `upsertSubject()`. `null` clears a field. */
47
+ const upsertSubjectInputSchema = valibot.object({
48
+ id: nonEmpty,
49
+ name: valibot.optional(valibot.nullable(valibot.pipe(valibot.string(), valibot.maxLength(500)))),
50
+ email: valibot.optional(valibot.nullable(valibot.pipe(valibot.string(), valibot.maxLength(500))))
51
+ });
52
+ /** Query of `list()`. */
53
+ const listQuerySchema = valibot.object({
54
+ subject: valibot.optional(nonEmpty),
55
+ permission: valibot.optional(nonEmpty),
56
+ includeExpired: valibot.optional(valibot.boolean())
57
+ });
58
+ const refPart = "[^:#]+";
59
+ /** `type:id` (the id may hold `:`, `/`, `%`, non-ASCII, but not `#`, which starts a userset). */
60
+ const objectRefSchema = valibot.pipe(valibot.string(), valibot.maxLength(512, "must be at most 512 characters"), valibot.regex(new RegExp(`^${refPart}:[^#]+$`), "must be \"type:id\" (no \"#\" in the id)"));
61
+ /** `type:id`, `type:id#relation` or `type:*`. */
62
+ const subjectRefSchema = valibot.pipe(valibot.string(), valibot.maxLength(512, "must be at most 512 characters"), valibot.regex(new RegExp(`^${refPart}:[^#]+(#${refPart})?$`), "must be \"type:id\", \"type:id#relation\" or \"type:*\""));
63
+ /** Input of `writeRelationship()` / `deleteRelationship()`. */
64
+ const relationshipInputSchema = valibot.object({
65
+ object: objectRefSchema,
66
+ relation: nonEmpty,
67
+ subject: subjectRefSchema,
68
+ actor: valibot.optional(actorSchema),
69
+ reason: valibot.optional(reasonSchema)
70
+ });
71
+ /** Query of `readRelationships()`. */
72
+ const relationshipQuerySchema = valibot.object({
73
+ /** `type:id`, or just `type` for every object of a type. */
74
+ object: valibot.optional(valibot.pipe(valibot.string(), valibot.minLength(1, "must not be empty"))),
75
+ relation: valibot.optional(nonEmpty),
76
+ subject: valibot.optional(subjectRefSchema),
77
+ limit: valibot.optional(valibot.pipe(valibot.number(), valibot.integer(), valibot.minValue(1), valibot.maxValue(1e3))),
78
+ cursor: valibot.optional(valibot.string())
79
+ });
80
+ /** Input of `checkRelation()`. */
81
+ const relationCheckSchema = valibot.object({
82
+ subject: subjectRefSchema,
83
+ relation: nonEmpty,
84
+ object: objectRefSchema
85
+ });
86
+ /** Query of `listObjects()`. */
87
+ const listObjectsQuerySchema = valibot.object({
88
+ subject: subjectRefSchema,
89
+ relation: nonEmpty,
90
+ type: nonEmpty
91
+ });
92
+ /** Query of `listRelationSubjects()`. */
93
+ const listRelationSubjectsQuerySchema = valibot.object({
94
+ object: objectRefSchema,
95
+ relation: nonEmpty,
96
+ /** Only subjects of this type. */
97
+ type: valibot.optional(nonEmpty)
98
+ });
99
+ /** Query of `history()`. */
100
+ const historyQuerySchema = valibot.object({
101
+ subject: valibot.optional(nonEmpty),
102
+ limit: valibot.optional(valibot.pipe(valibot.number(), valibot.integer(), valibot.minValue(1), valibot.maxValue(1e3))),
103
+ cursor: valibot.optional(valibot.string())
104
+ });
105
+ //#endregion
106
+ //#region src/hooks/contract.ts
107
+ /**
108
+ * Control-plane hooks fired around grant, revoke, role and relationship writes (mirrors the
109
+ * family's hooks contract, `@xtandard/kit/hooks`).
110
+ *
111
+ * - `before` runs sequentially before the write commits. **Throw to deny**
112
+ * (e.g. {@link HookDeniedError}); the error propagates to the caller.
113
+ * - `after` runs once committed, for side effects (audit, webhooks, cache
114
+ * busting). Errors are isolated and reported via `onHookError`.
115
+ *
116
+ * A re-grant of an existing grant, a revoke of nothing, a role set to the
117
+ * role already stored, a re-write of a stored relationship and a delete of a
118
+ * missing one are no-ops: they fire neither `before` nor `after`.
119
+ * Checks never go through hooks.
120
+ *
121
+ * @module
122
+ */
123
+ /** Default `after`-hook error reporter: warn with the `[@xtandard/permissions]` prefix, never throw. */
124
+ const defaultHookErrorReporter = (0, _xtandard_kit_hooks.createHookErrorReporter)("@xtandard/permissions");
125
+ //#endregion
126
+ //#region src/keys.ts
127
+ /**
128
+ * Key layout (ADR 0003). Pure string helpers; every id segment is
129
+ * `encodeURIComponent`-ed, so any subject id or permission name is safe in a
130
+ * key and can't contain the `/` separator.
131
+ *
132
+ * ```txt
133
+ * perm/grants/{subject}/{permission} -> Grant one key per pair: unique on every driver
134
+ * perm/subjects/{subject} -> SubjectRecord optional role assignment + display fields
135
+ * perm/history/{subject}/{at}-{id} -> HistoryEntry append-only; sortable by the last segment
136
+ *
137
+ * perm/rel/{objectType}/{objectId}/{relation}/{subject} -> Relationship
138
+ * perm/relrev/{subjectType}/{subjectId}/{subjectRel}/{objectType}/{objectId}/{relation}
139
+ * -> RelationshipRef
140
+ * ```
141
+ *
142
+ * Relationships (ADR 0013): one forward key per tuple (unique on every driver, so writes are
143
+ * idempotent), read by `(object, relation)` with one prefix scan; the reverse key serves
144
+ * `listObjects` (every tuple naming a subject, plain or as a userset). `{subject}` is the whole
145
+ * subject reference (`user:ana`, `group:eng#member`, `user:*`) as one segment; `{subjectRel}` is
146
+ * `_` for a plain subject or a wildcard and `#{relation}` (encoded `%23…`) for a userset, so it
147
+ * can't collide with a relation named `_`.
148
+ *
149
+ * @module
150
+ */
151
+ /** Root namespace of every key. */
152
+ const ROOT = "perm";
153
+ const e = encodeURIComponent;
154
+ const d = decodeURIComponent;
155
+ /** Prefix of every grant. */
156
+ const grantsPrefix = () => `${ROOT}/grants/`;
157
+ /** Prefix of one subject's grants. */
158
+ const subjectGrantsPrefix = (subject) => `${grantsPrefix()}${e(subject)}/`;
159
+ /** One grant. */
160
+ const grantKey = (subject, permission) => `${subjectGrantsPrefix(subject)}${e(permission)}`;
161
+ /** Prefix of every subject record. */
162
+ const subjectsPrefix = () => `${ROOT}/subjects/`;
163
+ /** One subject record. */
164
+ const subjectKey = (subject) => `${subjectsPrefix()}${e(subject)}`;
165
+ /** Prefix of the whole history log. */
166
+ const historyPrefix = () => `${ROOT}/history/`;
167
+ /** Prefix of one subject's history. */
168
+ const subjectHistoryPrefix = (subject) => `${historyPrefix()}${e(subject)}/`;
169
+ /** One history entry: the last segment (`{at}-{id}`) sorts by time. */
170
+ const historyKey = (subject, at, id) => `${subjectHistoryPrefix(subject)}${e(`${at}-${id}`)}`;
171
+ /** Split `type:id` (first colon). */
172
+ function splitRef(ref) {
173
+ const colon = ref.indexOf(":");
174
+ return [ref.slice(0, colon), ref.slice(colon + 1)];
175
+ }
176
+ /** Split a subject `type:id` / `type:id#relation` into object ref and relation (first `#`). */
177
+ function splitSubject(subject) {
178
+ const hash = subject.indexOf("#");
179
+ return hash === -1 ? [subject, void 0] : [subject.slice(0, hash), subject.slice(hash + 1)];
180
+ }
181
+ /** The `{subjectRel}` segment of a reverse key. */
182
+ const subjectRelSegment = (relation) => relation === void 0 ? "_" : e(`#${relation}`);
183
+ /** Prefix of every relationship (forward keys). */
184
+ const relationshipsPrefix = () => `${ROOT}/rel/`;
185
+ /** Prefix of one object type's relationships. */
186
+ const relationshipTypePrefix = (type) => `${relationshipsPrefix()}${e(type)}/`;
187
+ /** Prefix of one object's relationships (`doc:1`). */
188
+ const objectRelationshipsPrefix = (object) => {
189
+ const [type, id] = splitRef(object);
190
+ return `${relationshipTypePrefix(type)}${e(id)}/`;
191
+ };
192
+ /** Prefix of the subjects stored on `(object, relation)`: what a tuple reader scans. */
193
+ const relationSubjectsPrefix = (object, relation) => `${objectRelationshipsPrefix(object)}${e(relation)}/`;
194
+ /** One relationship's forward key. */
195
+ const relationshipKey = (object, relation, subject) => `${relationSubjectsPrefix(object, relation)}${e(subject)}`;
196
+ /** Prefix of every reverse key. */
197
+ const reverseRelationshipsPrefix = () => `${ROOT}/relrev/`;
198
+ /** Prefix of the reverse keys of one subject object (`user:ana`), plain and as any userset. */
199
+ const subjectObjectReversePrefix = (object) => {
200
+ const [type, id] = splitRef(object);
201
+ return `${reverseRelationshipsPrefix()}${e(type)}/${e(id)}/`;
202
+ };
203
+ /** Prefix of the reverse keys of exactly `subject` (`user:ana`, `user:*`, `group:eng#member`). */
204
+ const subjectReversePrefix = (subject) => {
205
+ const [object, relation] = splitSubject(subject);
206
+ return `${subjectObjectReversePrefix(object)}${subjectRelSegment(relation)}/`;
207
+ };
208
+ /** One relationship's reverse key. */
209
+ const reverseRelationshipKey = (object, relation, subject) => {
210
+ const [type, id] = splitRef(object);
211
+ return `${subjectReversePrefix(subject)}${e(type)}/${e(id)}/${e(relation)}`;
212
+ };
213
+ /** A forward key back to its tuple; `null` when it is not one. */
214
+ function parseRelationshipKey(key) {
215
+ const parts = key.split("/");
216
+ if (parts.length !== 6 || parts[0] !== "perm" || parts[1] !== "rel") return null;
217
+ try {
218
+ const [type, id, relation, subject] = parts.slice(2).map(d);
219
+ return {
220
+ object: `${type}:${id}`,
221
+ relation,
222
+ subject
223
+ };
224
+ } catch {
225
+ return null;
226
+ }
227
+ }
228
+ /** A reverse key back to its tuple; `null` when it is not one. */
229
+ function parseReverseRelationshipKey(key) {
230
+ const parts = key.split("/");
231
+ if (parts.length !== 8 || parts[0] !== "perm" || parts[1] !== "relrev") return null;
232
+ try {
233
+ const [subjectType, subjectId, subjectRel, type, id, relation] = parts.slice(2).map(d);
234
+ if (subjectRel !== "_" && !subjectRel.startsWith("#")) return null;
235
+ const subject = `${subjectType}:${subjectId}${subjectRel === "_" ? "" : subjectRel}`;
236
+ return {
237
+ object: `${type}:${id}`,
238
+ relation,
239
+ subject
240
+ };
241
+ } catch {
242
+ return null;
243
+ }
244
+ }
245
+ /** The decoded segments after the root's area (`grants`, `subjects`, `history`). */
246
+ function parseKey(key) {
247
+ const parts = key.split("/");
248
+ if (parts[0] !== "perm" || parts.length < 3) return null;
249
+ const area = parts[1];
250
+ if (area !== "grants" && area !== "subjects" && area !== "history") return null;
251
+ try {
252
+ const subject = d(parts[2]);
253
+ const rest = parts.length > 3 ? d(parts.slice(3).join("/")) : void 0;
254
+ return rest === void 0 ? {
255
+ area,
256
+ subject
257
+ } : {
258
+ area,
259
+ subject,
260
+ rest
261
+ };
262
+ } catch {
263
+ return null;
264
+ }
265
+ }
266
+ //#endregion
267
+ //#region src/relationships.ts
268
+ /**
269
+ * Relationships (ReBAC, ADR 0013): the tuple store, the tuple reader the lib's checker plugs into,
270
+ * `checkRelation`, `listObjects`, `listRelationSubjects` and the synchronous preload for rules.
271
+ * **The lib evaluates** (`@xtandard/lib/policy/rebac`: schema, `check`, `explain`, reverse edges);
272
+ * this module stores, indexes and lists. The engine (`createPermissions`) mixes these methods in.
273
+ *
274
+ * Storage: one forward key per tuple, `perm/rel/{objectType}/{objectId}/{relation}/{subject}`
275
+ * (unique on every driver, so writes are idempotent), plus a reverse key per tuple under
276
+ * `perm/relrev/{subjectType}/{subjectId}/{_ | #relation}/…` for listing. A write sets the forward
277
+ * key, then the reverse key; a delete removes the reverse key, then the forward key. So a crash
278
+ * between the two leaves a forward key without its reverse (listing misses the tuple; checks still
279
+ * see it), never the other way round; `repairRelationships()` restores the invariant.
280
+ *
281
+ * @module
282
+ */
283
+ const DEFAULT_PAGE = 100;
284
+ const DEFAULT_MAX_OBJECTS = 1e3;
285
+ const parseRef = (ref) => {
286
+ const hash = ref.indexOf("#");
287
+ const object = hash === -1 ? ref : ref.slice(0, hash);
288
+ const colon = object.indexOf(":");
289
+ return {
290
+ type: object.slice(0, colon),
291
+ id: object.slice(colon + 1),
292
+ object,
293
+ ...hash === -1 ? {} : { relation: ref.slice(hash + 1) }
294
+ };
295
+ };
296
+ const byString = (a, b) => a < b ? -1 : a > b ? 1 : 0;
297
+ /** Run `fn` over `items` with at most `limit` in flight. */
298
+ async function mapLimit(items, limit, fn) {
299
+ const out = Array.from({ length: items.length });
300
+ let next = 0;
301
+ const worker = async () => {
302
+ while (next < items.length) {
303
+ const index = next++;
304
+ out[index] = await fn(items[index]);
305
+ }
306
+ };
307
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
308
+ return out;
309
+ }
310
+ /** Build the relationship methods over the engine's plumbing. */
311
+ function createRelationships(deps) {
312
+ const { storage, hooks, onHookError } = deps;
313
+ const maxDepth = deps.options?.maxDepth ?? 25;
314
+ const requireSchema = () => {
315
+ if (!deps.schema) throw new _xtandard_lib_policy_rebac.RelationSchemaError("This catalog declares no relations: pass `relations` to definePermissions to use ReBAC.");
316
+ return deps.schema;
317
+ };
318
+ /**
319
+ * Coalesces identical reads that are in flight at the same time (concurrent checks of the same
320
+ * object share one `getKeys`); within one check the lib already reads each pair once.
321
+ */
322
+ const inflight = /* @__PURE__ */ new Map();
323
+ const scan = (prefix, parse) => {
324
+ let pending = inflight.get(prefix);
325
+ if (!pending) {
326
+ pending = storage.getKeys(prefix).then((keys) => keys.map(parse).filter((value) => value !== null)).finally(() => inflight.delete(prefix));
327
+ inflight.set(prefix, pending);
328
+ }
329
+ return pending;
330
+ };
331
+ /** The tuple reader the lib's checker plugs into: subjects stored on `(object, relation)`. */
332
+ const read = (object, relation, context = {}) => {
333
+ context.signal?.throwIfAborted();
334
+ return scan(relationSubjectsPrefix(object, relation), (key) => {
335
+ const parsed = parseRelationshipKey(key);
336
+ return parsed && parsed.object === object && parsed.relation === relation ? parsed.subject : null;
337
+ });
338
+ };
339
+ let checker = null;
340
+ const getChecker = () => {
341
+ if (!checker) checker = (0, _xtandard_lib_policy_rebac.createRelationChecker)(requireSchema(), {
342
+ read,
343
+ maxDepth
344
+ });
345
+ return checker;
346
+ };
347
+ let edgesBySource = null;
348
+ const sourceKey = (type, relation) => `${type}#${relation ?? ""}`;
349
+ const edgesFrom = (type, relation) => {
350
+ if (!edgesBySource) {
351
+ edgesBySource = /* @__PURE__ */ new Map();
352
+ for (const edge of (0, _xtandard_lib_policy_rebac.relationEdges)(requireSchema())) {
353
+ const key = sourceKey(edge.source.type, edge.source.relation);
354
+ const list = edgesBySource.get(key);
355
+ if (list) list.push(edge);
356
+ else edgesBySource.set(key, [edge]);
357
+ }
358
+ }
359
+ return edgesBySource.get(sourceKey(type, relation)) ?? [];
360
+ };
361
+ const validTuple = (input) => {
362
+ const schema = requireSchema();
363
+ const parsed = (0, _xtandard_kit_util.parseInput)(relationshipInputSchema, input);
364
+ const tuple = {
365
+ object: parsed.object,
366
+ relation: parsed.relation,
367
+ subject: parsed.subject
368
+ };
369
+ if (!(0, _xtandard_lib_policy_rebac.isAllowedTuple)(schema, tuple)) {
370
+ const { type } = parseRef(tuple.object);
371
+ throw new _xtandard_lib_policy_rebac.RelationSchemaError((0, _xtandard_lib_policy_rebac.hasRelation)(schema, type, tuple.relation) ? `The schema doesn't allow "${tuple.subject}" on ${type}#${tuple.relation}.` : `Unknown relation "${type}#${tuple.relation}".`);
372
+ }
373
+ return {
374
+ parsed,
375
+ tuple
376
+ };
377
+ };
378
+ const validQuery = (relation, object) => {
379
+ const schema = requireSchema();
380
+ const { type } = parseRef(object);
381
+ if (!(0, _xtandard_lib_policy_rebac.hasRelation)(schema, type, relation)) throw new _xtandard_lib_policy_rebac.RelationSchemaError(`Unknown relation "${type}#${relation}".`);
382
+ };
383
+ async function writeRelationship(input) {
384
+ deps.assertWritable("write relationship");
385
+ const { parsed, tuple } = validTuple(input);
386
+ const actor = deps.toActor(parsed.actor);
387
+ const key = relationshipKey(tuple.object, tuple.relation, tuple.subject);
388
+ const reverse = reverseRelationshipKey(tuple.object, tuple.relation, tuple.subject);
389
+ return deps.withLock(key, async () => {
390
+ const existing = await storage.getItem(key);
391
+ if (existing) {
392
+ if (await storage.getItem(reverse) === null) await storage.setItem(reverse, tuple);
393
+ return {
394
+ relationship: existing,
395
+ created: false
396
+ };
397
+ }
398
+ const at = deps.nowIso();
399
+ const relationship = {
400
+ object: tuple.object,
401
+ relation: tuple.relation,
402
+ subject: tuple.subject,
403
+ createdBy: actor?.id ?? null,
404
+ createdAt: at,
405
+ ...parsed.reason !== void 0 ? { reason: parsed.reason } : {}
406
+ };
407
+ await (0, _xtandard_kit_hooks.runBefore)(hooks, {
408
+ type: "relationship.write",
409
+ subject: tuple.subject,
410
+ relationship,
411
+ actor
412
+ });
413
+ if ((0, _xtandard_kit_storage.isCompareAndSwap)(storage)) {
414
+ if (!await storage.compareAndSwap({
415
+ key,
416
+ expected: null,
417
+ next: relationship
418
+ })) {
419
+ const winner = await storage.getItem(key);
420
+ if (winner) return {
421
+ relationship: winner,
422
+ created: false
423
+ };
424
+ throw new Error(`writeRelationship: storage kept changing "${key}"; giving up`);
425
+ }
426
+ } else await storage.setItem(key, relationship);
427
+ await storage.setItem(reverse, tuple);
428
+ await deps.appendHistory({
429
+ type: "relate",
430
+ subject: tuple.subject,
431
+ object: tuple.object,
432
+ relation: tuple.relation,
433
+ actor: actor?.id ?? null,
434
+ ...parsed.reason !== void 0 ? { reason: parsed.reason } : {}
435
+ }, at);
436
+ await (0, _xtandard_kit_hooks.runAfter)(hooks, {
437
+ type: "relationship.written",
438
+ subject: tuple.subject,
439
+ relationship,
440
+ actor,
441
+ at
442
+ }, onHookError);
443
+ return {
444
+ relationship,
445
+ created: true
446
+ };
447
+ });
448
+ }
449
+ async function deleteRelationship(input) {
450
+ deps.assertWritable("delete relationship");
451
+ requireSchema();
452
+ const parsed = (0, _xtandard_kit_util.parseInput)(relationshipInputSchema, input);
453
+ const actor = deps.toActor(parsed.actor);
454
+ const key = relationshipKey(parsed.object, parsed.relation, parsed.subject);
455
+ const reverse = reverseRelationshipKey(parsed.object, parsed.relation, parsed.subject);
456
+ return deps.withLock(key, async () => {
457
+ const existing = await storage.getItem(key);
458
+ if (!existing) {
459
+ if (await storage.getItem(reverse) !== null) await storage.removeItem(reverse);
460
+ return {
461
+ removed: false,
462
+ relationship: null
463
+ };
464
+ }
465
+ const reason = parsed.reason !== void 0 ? { reason: parsed.reason } : {};
466
+ await (0, _xtandard_kit_hooks.runBefore)(hooks, {
467
+ type: "relationship.delete",
468
+ subject: existing.subject,
469
+ relationship: existing,
470
+ actor,
471
+ ...reason
472
+ });
473
+ await storage.removeItem(reverse);
474
+ await storage.removeItem(key);
475
+ const at = deps.nowIso();
476
+ await deps.appendHistory({
477
+ type: "unrelate",
478
+ subject: existing.subject,
479
+ object: existing.object,
480
+ relation: existing.relation,
481
+ actor: actor?.id ?? null,
482
+ ...reason
483
+ }, at);
484
+ await (0, _xtandard_kit_hooks.runAfter)(hooks, {
485
+ type: "relationship.deleted",
486
+ subject: existing.subject,
487
+ relationship: existing,
488
+ actor,
489
+ ...reason,
490
+ at
491
+ }, onHookError);
492
+ return {
493
+ removed: true,
494
+ relationship: existing
495
+ };
496
+ });
497
+ }
498
+ async function readRelationships(query = {}) {
499
+ const parsed = (0, _xtandard_kit_util.parseInput)(relationshipQuerySchema, query);
500
+ const limit = parsed.limit ?? DEFAULT_PAGE;
501
+ const { object, relation, subject } = parsed;
502
+ const isRef = object !== void 0 && object.includes(":");
503
+ let keys;
504
+ if (isRef && relation !== void 0 && subject !== void 0) keys = [relationshipKey(object, relation, subject)];
505
+ else if (subject !== void 0 && !isRef) keys = (await storage.getKeys(subjectReversePrefix(subject))).map(parseReverseRelationshipKey).filter((t) => t !== null && t.subject === subject).filter((t) => object === void 0 || parseRef(t.object).type === object).map((t) => relationshipKey(t.object, t.relation, t.subject));
506
+ else if (isRef && relation !== void 0) keys = await storage.getKeys(relationSubjectsPrefix(object, relation));
507
+ else if (isRef) keys = await storage.getKeys(objectRelationshipsPrefix(object));
508
+ else if (object !== void 0) keys = await storage.getKeys(relationshipTypePrefix(object));
509
+ else keys = await storage.getKeys(relationshipsPrefix());
510
+ let tuples = keys.map((key) => ({
511
+ key,
512
+ tuple: parseRelationshipKey(key)
513
+ })).filter((entry) => entry.tuple !== null && (relation === void 0 || entry.tuple.relation === relation) && (subject === void 0 || entry.tuple.subject === subject) && (!isRef || entry.tuple.object === object));
514
+ tuples.sort((a, b) => byString(a.key, b.key));
515
+ if (parsed.cursor !== void 0) {
516
+ const after = parsed.cursor;
517
+ tuples = tuples.filter((entry) => entry.key > after);
518
+ }
519
+ const page = tuples.slice(0, limit);
520
+ const relationships = (await Promise.all(page.map((entry) => storage.getItem(entry.key)))).filter((r) => r !== null && typeof r === "object");
521
+ const last = page[page.length - 1];
522
+ return {
523
+ relationships,
524
+ nextCursor: tuples.length > limit && last ? last.key : null
525
+ };
526
+ }
527
+ async function checkRelation(query, context = {}) {
528
+ const parsed = (0, _xtandard_kit_util.parseInput)(relationCheckSchema, query);
529
+ validQuery(parsed.relation, parsed.object);
530
+ return getChecker().explain(parsed, context);
531
+ }
532
+ /** `checkRelation(...).allowed`, `false` when the check throws (depth, stale schema). */
533
+ const confirm = async (subject, relation, object) => {
534
+ try {
535
+ return (await getChecker().explain({
536
+ subject,
537
+ relation,
538
+ object
539
+ })).allowed;
540
+ } catch {
541
+ return false;
542
+ }
543
+ };
544
+ async function listObjects(query) {
545
+ const parsed = (0, _xtandard_kit_util.parseInput)(listObjectsQuerySchema, query);
546
+ if (!(0, _xtandard_lib_policy_rebac.hasRelation)(requireSchema(), parsed.type, parsed.relation)) throw new _xtandard_lib_policy_rebac.RelationSchemaError(`Unknown relation "${parsed.type}#${parsed.relation}".`);
547
+ const subject = parseRef(parsed.subject);
548
+ /** Every tuple naming exactly `ref`, memoized for this walk. */
549
+ const reverseMemo = /* @__PURE__ */ new Map();
550
+ const tuplesNaming = (ref) => {
551
+ let pending = reverseMemo.get(ref);
552
+ if (!pending) {
553
+ pending = storage.getKeys(subjectReversePrefix(ref)).then((keys) => keys.map(parseReverseRelationshipKey).filter((t) => t !== null && t.subject === ref));
554
+ reverseMemo.set(ref, pending);
555
+ }
556
+ return pending;
557
+ };
558
+ const reached = /* @__PURE__ */ new Map();
559
+ const found = /* @__PURE__ */ new Map();
560
+ let frontier = [];
561
+ const reach = (object, relation, exact) => {
562
+ const key = `${object}#${relation}`;
563
+ const seen = reached.get(key);
564
+ if (seen === true || seen === false && !exact) return;
565
+ reached.set(key, exact);
566
+ if (parseRef(object).type === parsed.type && relation === parsed.relation) found.set(object, (found.get(object) ?? false) || exact);
567
+ frontier.push({
568
+ object,
569
+ relation,
570
+ exact
571
+ });
572
+ };
573
+ /** Direct tuples on `(X, q)` naming `ref`, whose type `(sourceType, sourceRelation)` is allowed. */
574
+ const viaDirect = async (ref, sourceType, sourceRelation, wildcard, exact) => {
575
+ const edges = edgesFrom(sourceType, sourceRelation).filter((edge) => edge.kind === "direct" && (edge.source.wildcard ?? false) === wildcard);
576
+ if (edges.length === 0) return;
577
+ for (const tuple of await tuplesNaming(ref)) {
578
+ const type = parseRef(tuple.object).type;
579
+ for (const edge of edges) if (edge.target.type === type && edge.target.relation === tuple.relation) reach(tuple.object, tuple.relation, exact && edge.exact);
580
+ }
581
+ };
582
+ if (subject.relation !== void 0) reach(subject.object, subject.relation, true);
583
+ else {
584
+ await viaDirect(parsed.subject, subject.type, void 0, false, true);
585
+ if (subject.id !== "*") await viaDirect(`${subject.type}:*`, subject.type, void 0, true, true);
586
+ }
587
+ for (let depth = 0; frontier.length > 0 && depth < maxDepth; depth++) {
588
+ const current = frontier;
589
+ frontier = [];
590
+ await mapLimit(current, 16, async (node) => {
591
+ const { type } = parseRef(node.object);
592
+ await viaDirect(`${node.object}#${node.relation}`, type, node.relation, false, node.exact);
593
+ for (const edge of edgesFrom(type, node.relation)) if (edge.kind === "computed") reach(node.object, edge.target.relation, node.exact && edge.exact);
594
+ else if (edge.kind === "from") {
595
+ for (const tuple of await tuplesNaming(node.object)) if (tuple.relation === edge.tupleset && parseRef(tuple.object).type === edge.target.type) reach(tuple.object, edge.target.relation, node.exact && edge.exact);
596
+ }
597
+ });
598
+ }
599
+ const objects = [...found.keys()];
600
+ const allowed = await mapLimit(objects, 16, async (object) => found.get(object) ? true : confirm(parsed.subject, parsed.relation, object));
601
+ return objects.filter((_, i) => allowed[i]).sort(byString);
602
+ }
603
+ async function listRelationSubjects(query) {
604
+ const parsed = (0, _xtandard_kit_util.parseInput)(listRelationSubjectsQuerySchema, query);
605
+ const schema = requireSchema();
606
+ validQuery(parsed.relation, parsed.object);
607
+ const visited = /* @__PURE__ */ new Map();
608
+ const candidates = /* @__PURE__ */ new Map();
609
+ const add = (subject, exact) => candidates.set(subject, (candidates.get(subject) ?? false) || exact);
610
+ const expand = async (object, relation, depth, exact) => {
611
+ if (depth > maxDepth) return;
612
+ const key = `${object}#${relation}`;
613
+ const seen = visited.get(key);
614
+ if (seen === true || seen === false && !exact) return;
615
+ visited.set(key, exact);
616
+ const { type } = parseRef(object);
617
+ if (!(0, _xtandard_lib_policy_rebac.hasRelation)(schema, type, relation)) return;
618
+ await walk(schema[type][relation], object, relation, depth, exact);
619
+ };
620
+ const walk = async (expr, object, relation, depth, exact) => {
621
+ switch (expr.kind) {
622
+ case "direct":
623
+ for (const stored of await read(object, relation)) {
624
+ const ref = parseRef(stored);
625
+ if (ref.relation !== void 0) await expand(ref.object, ref.relation, depth + 1, exact);
626
+ else add(stored, exact);
627
+ }
628
+ return;
629
+ case "computed": return expand(object, expr.relation, depth + 1, exact);
630
+ case "from":
631
+ for (const related of await read(object, expr.tupleset)) if (!related.includes("#")) await expand(related, expr.relation, depth + 1, exact);
632
+ return;
633
+ case "union":
634
+ for (const child of expr.children) await walk(child, object, relation, depth, exact);
635
+ return;
636
+ case "intersection":
637
+ for (const child of expr.children) await walk(child, object, relation, depth, false);
638
+ return;
639
+ case "exclusion": return walk(expr.base, object, relation, depth, false);
640
+ }
641
+ };
642
+ await expand(parsed.object, parsed.relation, 0, true);
643
+ const subjects = [...candidates.keys()].filter((subject) => parsed.type === void 0 || parseRef(subject).type === parsed.type);
644
+ const allowed = await mapLimit(subjects, 16, async (subject) => candidates.get(subject) ? true : confirm(subject, parsed.relation, parsed.object));
645
+ return subjects.filter((_, i) => allowed[i]).sort(byString);
646
+ }
647
+ async function loadRelations(objects, options = {}) {
648
+ const schema = requireSchema();
649
+ const maxObjects = options.maxObjects ?? DEFAULT_MAX_OBJECTS;
650
+ const memory = (0, _xtandard_lib_policy_rebac.createMemoryTuples)();
651
+ const loaded = /* @__PURE__ */ new Set();
652
+ let frontier = [...new Set(objects)];
653
+ for (let depth = 0; frontier.length > 0 && depth <= maxDepth; depth++) {
654
+ const batch = frontier.filter((object) => !loaded.has(object)).slice(0, maxObjects - loaded.size);
655
+ frontier = [];
656
+ for (const object of batch) loaded.add(object);
657
+ const keys = await mapLimit(batch, 16, (object) => storage.getKeys(objectRelationshipsPrefix(object)));
658
+ for (const tuple of keys.flat().map(parseRelationshipKey)) {
659
+ if (!tuple) continue;
660
+ memory.add(tuple);
661
+ const ref = parseRef(tuple.subject);
662
+ if (ref.id !== "*" && Object.keys(schema[ref.type] ?? {}).length > 0 && !loaded.has(ref.object)) frontier.push(ref.object);
663
+ }
664
+ if (loaded.size >= maxObjects) break;
665
+ }
666
+ const sync = (0, _xtandard_lib_policy_rebac.createRelationChecker)(schema, {
667
+ read: memory.read,
668
+ maxDepth
669
+ });
670
+ return {
671
+ check: (query) => sync.check(query),
672
+ explain: (query) => sync.explain(query),
673
+ relation: (subject, relation, object) => sync.check({
674
+ subject,
675
+ relation,
676
+ object
677
+ }),
678
+ tuples: memory.tuples
679
+ };
680
+ }
681
+ async function repairRelationships() {
682
+ deps.assertWritable("repair relationships");
683
+ const [forward, reverse] = await Promise.all([storage.getKeys(relationshipsPrefix()), storage.getKeys(reverseRelationshipsPrefix())]);
684
+ const reverseSet = new Set(reverse);
685
+ const expected = /* @__PURE__ */ new Set();
686
+ let restored = 0;
687
+ let removed = 0;
688
+ for (const key of forward) {
689
+ const tuple = parseRelationshipKey(key);
690
+ if (!tuple) continue;
691
+ const rev = reverseRelationshipKey(tuple.object, tuple.relation, tuple.subject);
692
+ expected.add(rev);
693
+ if (!reverseSet.has(rev)) {
694
+ await storage.setItem(rev, tuple);
695
+ restored++;
696
+ }
697
+ }
698
+ for (const key of reverse) {
699
+ if (expected.has(key)) continue;
700
+ const tuple = parseReverseRelationshipKey(key);
701
+ if (tuple && await storage.getItem(relationshipKey(tuple.object, tuple.relation, tuple.subject))) continue;
702
+ await storage.removeItem(key);
703
+ removed++;
704
+ }
705
+ return {
706
+ scanned: forward.length,
707
+ restored,
708
+ removed
709
+ };
710
+ }
711
+ return {
712
+ writeRelationship,
713
+ deleteRelationship,
714
+ readRelationships,
715
+ checkRelation,
716
+ listObjects,
717
+ listRelationSubjects,
718
+ loadRelations,
719
+ repairRelationships
720
+ };
721
+ }
722
+ /** Render a relation expression on one line. */
723
+ function describeRelation(expr) {
724
+ const wrap = (child) => child.kind === "union" || child.kind === "intersection" || child.kind === "exclusion" ? `(${describeRelation(child)})` : describeRelation(child);
725
+ switch (expr.kind) {
726
+ case "direct": return `[${expr.types.join(", ")}]`;
727
+ case "computed": return expr.relation;
728
+ case "from": return `${expr.relation} from ${expr.tupleset}`;
729
+ case "union": return expr.children.map(wrap).join(" or ");
730
+ case "intersection": return expr.children.map(wrap).join(" and ");
731
+ case "exclusion": return `${wrap(expr.base)} but not ${wrap(expr.subtract)}`;
732
+ }
733
+ }
734
+ const directSubjects = (expr, out = []) => {
735
+ if (expr.kind === "direct") {
736
+ for (const type of expr.types) if (!out.includes(type)) out.push(type);
737
+ } else if (expr.kind === "union" || expr.kind === "intersection") for (const child of expr.children) directSubjects(child, out);
738
+ else if (expr.kind === "exclusion") {
739
+ directSubjects(expr.base, out);
740
+ directSubjects(expr.subtract, out);
741
+ }
742
+ return out;
743
+ };
744
+ /** The relation schema as plain data (types, relations, writable subject types, rules). */
745
+ function relationSchemaView(schema) {
746
+ return Object.entries(schema).map(([type, relations]) => ({
747
+ type,
748
+ relations: Object.entries(relations).map(([name, expr]) => ({
749
+ name,
750
+ subjects: directSubjects(expr),
751
+ rule: describeRelation(expr)
752
+ }))
753
+ }));
754
+ }
755
+ //#endregion
756
+ Object.defineProperty(exports, "ROOT", {
757
+ enumerable: true,
758
+ get: function() {
759
+ return ROOT;
760
+ }
761
+ });
762
+ Object.defineProperty(exports, "actorSchema", {
763
+ enumerable: true,
764
+ get: function() {
765
+ return actorSchema;
766
+ }
767
+ });
768
+ Object.defineProperty(exports, "createRelationships", {
769
+ enumerable: true,
770
+ get: function() {
771
+ return createRelationships;
772
+ }
773
+ });
774
+ Object.defineProperty(exports, "defaultHookErrorReporter", {
775
+ enumerable: true,
776
+ get: function() {
777
+ return defaultHookErrorReporter;
778
+ }
779
+ });
780
+ Object.defineProperty(exports, "grantInputSchema", {
781
+ enumerable: true,
782
+ get: function() {
783
+ return grantInputSchema;
784
+ }
785
+ });
786
+ Object.defineProperty(exports, "grantKey", {
787
+ enumerable: true,
788
+ get: function() {
789
+ return grantKey;
790
+ }
791
+ });
792
+ Object.defineProperty(exports, "grantsPrefix", {
793
+ enumerable: true,
794
+ get: function() {
795
+ return grantsPrefix;
796
+ }
797
+ });
798
+ Object.defineProperty(exports, "historyKey", {
799
+ enumerable: true,
800
+ get: function() {
801
+ return historyKey;
802
+ }
803
+ });
804
+ Object.defineProperty(exports, "historyPrefix", {
805
+ enumerable: true,
806
+ get: function() {
807
+ return historyPrefix;
808
+ }
809
+ });
810
+ Object.defineProperty(exports, "historyQuerySchema", {
811
+ enumerable: true,
812
+ get: function() {
813
+ return historyQuerySchema;
814
+ }
815
+ });
816
+ Object.defineProperty(exports, "listObjectsQuerySchema", {
817
+ enumerable: true,
818
+ get: function() {
819
+ return listObjectsQuerySchema;
820
+ }
821
+ });
822
+ Object.defineProperty(exports, "listQuerySchema", {
823
+ enumerable: true,
824
+ get: function() {
825
+ return listQuerySchema;
826
+ }
827
+ });
828
+ Object.defineProperty(exports, "listRelationSubjectsQuerySchema", {
829
+ enumerable: true,
830
+ get: function() {
831
+ return listRelationSubjectsQuerySchema;
832
+ }
833
+ });
834
+ Object.defineProperty(exports, "parseKey", {
835
+ enumerable: true,
836
+ get: function() {
837
+ return parseKey;
838
+ }
839
+ });
840
+ Object.defineProperty(exports, "relationCheckSchema", {
841
+ enumerable: true,
842
+ get: function() {
843
+ return relationCheckSchema;
844
+ }
845
+ });
846
+ Object.defineProperty(exports, "relationSchemaView", {
847
+ enumerable: true,
848
+ get: function() {
849
+ return relationSchemaView;
850
+ }
851
+ });
852
+ Object.defineProperty(exports, "relationshipInputSchema", {
853
+ enumerable: true,
854
+ get: function() {
855
+ return relationshipInputSchema;
856
+ }
857
+ });
858
+ Object.defineProperty(exports, "relationshipQuerySchema", {
859
+ enumerable: true,
860
+ get: function() {
861
+ return relationshipQuerySchema;
862
+ }
863
+ });
864
+ Object.defineProperty(exports, "revokeInputSchema", {
865
+ enumerable: true,
866
+ get: function() {
867
+ return revokeInputSchema;
868
+ }
869
+ });
870
+ Object.defineProperty(exports, "setRoleInputSchema", {
871
+ enumerable: true,
872
+ get: function() {
873
+ return setRoleInputSchema;
874
+ }
875
+ });
876
+ Object.defineProperty(exports, "subjectGrantsPrefix", {
877
+ enumerable: true,
878
+ get: function() {
879
+ return subjectGrantsPrefix;
880
+ }
881
+ });
882
+ Object.defineProperty(exports, "subjectHistoryPrefix", {
883
+ enumerable: true,
884
+ get: function() {
885
+ return subjectHistoryPrefix;
886
+ }
887
+ });
888
+ Object.defineProperty(exports, "subjectKey", {
889
+ enumerable: true,
890
+ get: function() {
891
+ return subjectKey;
892
+ }
893
+ });
894
+ Object.defineProperty(exports, "subjectsPrefix", {
895
+ enumerable: true,
896
+ get: function() {
897
+ return subjectsPrefix;
898
+ }
899
+ });
900
+ Object.defineProperty(exports, "upsertSubjectInputSchema", {
901
+ enumerable: true,
902
+ get: function() {
903
+ return upsertSubjectInputSchema;
904
+ }
905
+ });
906
+
907
+ //# sourceMappingURL=relationships-BLYEJ9tc.cjs.map