@xtandard/permissions 0.0.0-stage → 0.2.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 +364 -2
  3. package/bin/xtandard-permissions.mjs +3 -0
  4. package/dist/better-auth-BEmX8qyz.mjs +94 -0
  5. package/dist/better-auth-BEmX8qyz.mjs.map +1 -0
  6. package/dist/better-auth-DQET1sXa.d.mts +75 -0
  7. package/dist/better-auth-MR7dBtpo.cjs +111 -0
  8. package/dist/better-auth-MR7dBtpo.cjs.map +1 -0
  9. package/dist/better-auth-vgRYgjYK.d.cts +75 -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 +554 -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 +550 -0
  24. package/dist/cli.mjs.map +1 -0
  25. package/dist/contract-BAisPHBw.d.cts +78 -0
  26. package/dist/contract-BganM0fx.mjs +79 -0
  27. package/dist/contract-BganM0fx.mjs.map +1 -0
  28. package/dist/contract-Bpy8yPrS.cjs +70 -0
  29. package/dist/contract-Bpy8yPrS.cjs.map +1 -0
  30. package/dist/contract-Brnu9XXo.cjs +114 -0
  31. package/dist/contract-Brnu9XXo.cjs.map +1 -0
  32. package/dist/contract-CNgMXr2u.d.cts +46 -0
  33. package/dist/contract-CNgMXr2u.d.mts +46 -0
  34. package/dist/contract-CXPMGuHk.d.cts +391 -0
  35. package/dist/contract-D6j-yrBL.d.mts +78 -0
  36. package/dist/contract-DTdTXZtJ.mjs +47 -0
  37. package/dist/contract-DTdTXZtJ.mjs.map +1 -0
  38. package/dist/contract-DhS23Pcp.d.mts +391 -0
  39. package/dist/contract-RMkmERhT.d.cts +2 -0
  40. package/dist/contract-RMkmERhT.d.mts +2 -0
  41. package/dist/create-fetch-handler-B0twltQL.mjs +673 -0
  42. package/dist/create-fetch-handler-B0twltQL.mjs.map +1 -0
  43. package/dist/create-fetch-handler-B711wb64.d.mts +77 -0
  44. package/dist/create-fetch-handler-BHT4vSZs.cjs +690 -0
  45. package/dist/create-fetch-handler-BHT4vSZs.cjs.map +1 -0
  46. package/dist/create-fetch-handler-DxhvXuBA.d.cts +77 -0
  47. package/dist/elysia-shared-BFcWzfc9.cjs +101 -0
  48. package/dist/elysia-shared-BFcWzfc9.cjs.map +1 -0
  49. package/dist/elysia-shared-BwUYg0Ln.mjs +78 -0
  50. package/dist/elysia-shared-BwUYg0Ln.mjs.map +1 -0
  51. package/dist/elysia-shared-C2LnDOj3.d.cts +58 -0
  52. package/dist/elysia-shared-WuDr0jco.d.mts +58 -0
  53. package/dist/engine--C7zo-4M.cjs +667 -0
  54. package/dist/engine--C7zo-4M.cjs.map +1 -0
  55. package/dist/engine-BTgwbHeO.d.cts +336 -0
  56. package/dist/engine-C3xHfi3q.d.mts +336 -0
  57. package/dist/engine-CR75K253.mjs +654 -0
  58. package/dist/engine-CR75K253.mjs.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 +15 -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 +120 -0
  74. package/dist/entry-auth-jwt.cjs.map +1 -0
  75. package/dist/entry-auth-jwt.d.cts +71 -0
  76. package/dist/entry-auth-jwt.d.mts +71 -0
  77. package/dist/entry-auth-jwt.mjs +109 -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 +86 -0
  84. package/dist/entry-auth-session.cjs.map +1 -0
  85. package/dist/entry-auth-session.d.cts +25 -0
  86. package/dist/entry-auth-session.d.mts +25 -0
  87. package/dist/entry-auth-session.mjs +76 -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-CG_OLEEv.mjs +64 -0
  258. package/dist/errors-CG_OLEEv.mjs.map +1 -0
  259. package/dist/errors-CjpymzFj.cjs +105 -0
  260. package/dist/errors-CjpymzFj.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-Bj8zk23F.mjs +141 -0
  268. package/dist/guard-Bj8zk23F.mjs.map +1 -0
  269. package/dist/guard-DvaoUgjk.cjs +188 -0
  270. package/dist/guard-DvaoUgjk.cjs.map +1 -0
  271. package/dist/guard-VEK0W8ug.d.cts +62 -0
  272. package/dist/guard-k7A71SWC.d.mts +62 -0
  273. package/dist/index-BVVgDSdq.d.cts +1 -0
  274. package/dist/index-BVVgDSdq.d.mts +1 -0
  275. package/dist/index.cjs +243 -0
  276. package/dist/index.cjs.map +1 -0
  277. package/dist/index.d.cts +213 -0
  278. package/dist/index.d.mts +213 -0
  279. package/dist/index.mjs +60 -0
  280. package/dist/index.mjs.map +1 -0
  281. package/dist/kit-51JtMxsn.d.mts +62 -0
  282. package/dist/kit-BM3uosfV.mjs +80 -0
  283. package/dist/kit-BM3uosfV.mjs.map +1 -0
  284. package/dist/kit-BrqnCcDw.cjs +97 -0
  285. package/dist/kit-BrqnCcDw.cjs.map +1 -0
  286. package/dist/kit-DLF7DZrp.d.cts +62 -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-CeV6M3v7.mjs +62 -0
  292. package/dist/permissions-CeV6M3v7.mjs.map +1 -0
  293. package/dist/permissions-DDEkHNvN.cjs +73 -0
  294. package/dist/permissions-DDEkHNvN.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 +18735 -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-B2LrYpT0.cjs +1055 -0
  310. package/dist/routes-B2LrYpT0.cjs.map +1 -0
  311. package/dist/routes-Cx-kl4PY.mjs +1007 -0
  312. package/dist/routes-Cx-kl4PY.mjs.map +1 -0
  313. package/dist/server-Bn643UOy.d.mts +886 -0
  314. package/dist/server-YdH25OEA.d.cts +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 +85 -0
  328. package/dist/types-elysia2/auth-provider/kit.d.ts +62 -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 +233 -0
  333. package/dist/types-elysia2/entry-elysia2.d.ts +9 -0
  334. package/dist/types-elysia2/errors.d.ts +55 -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 +315 -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 +143 -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 +233 -0
  348. package/dist/types-react/entry-react-embed.d.ts +20 -0
  349. package/dist/types-react/errors.d.ts +55 -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 +315 -0
  356. package/dist/types-react/storage/contract.d.ts +18 -0
  357. package/dist/types-react/ui/App.d.ts +28 -0
  358. package/dist/types-react/ui/api.d.ts +73 -0
  359. package/dist/types-react/ui/components/perm-bits.d.ts +68 -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 +118 -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-DdvxpphI.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,654 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { A as revokeInputSchema, C as historyQuerySchema, M as upsertSubjectInputSchema, S as grantInputSchema, T as listQuerySchema, _ as defaultHookErrorReporter, a as isWatchable, b as runBefore, c as grantsPrefix, d as parseKey, f as subjectGrantsPrefix, h as subjectsPrefix, j as setRoleInputSchema, l as historyKey, m as subjectKey, o as ROOT, p as subjectHistoryPrefix, r as isCompareAndSwap, s as grantKey, t as createRelationships, u as historyPrefix, v as normalizeHooks, y as runAfter } from "./relationships-BfLonEMI.mjs";
3
+ import { a as ReadonlyError, o as UnknownPermissionError, r as NoSubjectError, s as UnknownRoleError, t as ExternalRolesError } from "./errors-CG_OLEEv.mjs";
4
+ import { createIdGenerator } from "@xtandard/kit/util/core";
5
+ import { ValidationError, parseInput } from "@xtandard/kit/util";
6
+ //#region src/engine.ts
7
+ /**
8
+ * The engine: `createPermissions({ catalog, storage, hooks, cache, now, readonly })`.
9
+ *
10
+ * Writes (grant, revoke, role assignment, subject records) go to the storage
11
+ * under the `perm/` key root (ADR 0003) and fire the hooks. Checks load the
12
+ * subject's stored role and grants (async, cached per subject), resolve the
13
+ * effective role from the `roleSource` (ADR 0014), then evaluate
14
+ * the catalog's rules **synchronously** with `@xtandard/lib/policy/permix`
15
+ * (ADR 0005).
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { createPermissions } from "@xtandard/permissions";
20
+ * import { createMemoryStorage } from "@xtandard/permissions/storage/memory";
21
+ * import { permissions } from "./permissions.ts"; // definePermissions(...)
22
+ *
23
+ * const perms = createPermissions({ catalog: permissions, storage: createMemoryStorage() });
24
+ * await perms.grant({ subject: "user_1", permission: "post:moderate", actor: "admin_1" });
25
+ * await perms.can({ id: "user_1", role: "member" }, "post.publish", post); // true
26
+ * ```
27
+ *
28
+ * @module
29
+ */
30
+ var engine_exports = /* @__PURE__ */ __exportAll({ createPermissions: () => createPermissions });
31
+ const DEFAULT_HISTORY_LIMIT = 50;
32
+ const CAS_ATTEMPTS = 8;
33
+ const isNonEmptyString = (value) => typeof value === "string" && value.length > 0;
34
+ function requireSubjectId(value) {
35
+ if (!isNonEmptyString(value)) throw new NoSubjectError();
36
+ return value;
37
+ }
38
+ function toActor(actor) {
39
+ if (actor === void 0 || actor === null) return null;
40
+ return typeof actor === "string" ? { id: actor } : actor;
41
+ }
42
+ function toIso(at) {
43
+ const ms = typeof at === "number" ? at : typeof at === "string" ? Date.parse(at) : at.getTime();
44
+ return new Date(ms).toISOString();
45
+ }
46
+ /** Last segment of a history key, decoded: the `{at}-{id}` sort token. */
47
+ function historyToken(key) {
48
+ const segment = key.slice(key.lastIndexOf("/") + 1);
49
+ try {
50
+ return `${decodeURIComponent(segment)}\u0000${key}`;
51
+ } catch {
52
+ return `\u0000${key}`;
53
+ }
54
+ }
55
+ /**
56
+ * Create the engine.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const perms = createPermissions({ catalog, storage, cache: { ttlMs: 5_000 } });
61
+ * const decision = await perms.check({ id: "u1", role: "member" }, "post.publish", post);
62
+ * // { allowed, path, subject, role, reason: "role-rule" | "denied-by-rule" | …, explanation }
63
+ * ```
64
+ */
65
+ function createPermissions(options) {
66
+ const { catalog, storage } = options;
67
+ const now = options.now ?? Date.now;
68
+ const readonly = options.readonly ?? false;
69
+ const hooks = normalizeHooks(options.hooks);
70
+ const onHookError = options.onHookError ?? defaultHookErrorReporter;
71
+ const logger = options.logger ?? { warn: (message, error) => console.warn(`[@xtandard/permissions] ${message}`, ...error === void 0 ? [] : [error]) };
72
+ const cacheEnabled = options.cache !== false;
73
+ const cacheTtl = (options.cache ? options.cache.ttlMs : void 0) ?? 5e3;
74
+ const cacheMax = (options.cache ? options.cache.max : void 0) ?? 1e4;
75
+ const roleSource = options.roleSource ?? "stored";
76
+ if (roleSource !== "stored" && roleSource !== "external") throw new TypeError(`createPermissions: roleSource must be "stored" or "external"`);
77
+ const lookupSubject = options.lookupSubject;
78
+ const ids = createIdGenerator({ format: "ulid-lower22" });
79
+ const nowIso = () => new Date(now()).toISOString();
80
+ const active = (grant) => grant.expiresAt === void 0 || grant.expiresAt === null || Date.parse(grant.expiresAt) > now();
81
+ const assertWritable = (operation) => {
82
+ if (readonly) throw new ReadonlyError(operation);
83
+ };
84
+ const requirePermission = (permission) => {
85
+ if (!catalog.isAssignable(permission)) throw new UnknownPermissionError(permission);
86
+ return permission;
87
+ };
88
+ const locks = /* @__PURE__ */ new Map();
89
+ async function withLock(key, fn) {
90
+ const prev = locks.get(key) ?? Promise.resolve();
91
+ let release;
92
+ const mine = new Promise((resolve) => release = resolve);
93
+ const chained = prev.then(() => mine);
94
+ locks.set(key, chained);
95
+ await prev.catch(() => {});
96
+ try {
97
+ return await fn();
98
+ } finally {
99
+ release();
100
+ if (locks.get(key) === chained) locks.delete(key);
101
+ }
102
+ }
103
+ /** Write `next` if the key still holds `expected` (CAS), or unconditionally without CAS. */
104
+ async function swap(key, expected, next) {
105
+ if (isCompareAndSwap(storage)) return storage.compareAndSwap({
106
+ key,
107
+ expected,
108
+ next
109
+ });
110
+ await storage.setItem(key, next);
111
+ return true;
112
+ }
113
+ const cache = /* @__PURE__ */ new Map();
114
+ /** `lookupSubject` results: same TTL, size bound and invalidation as {@link cache}. */
115
+ const lookups = /* @__PURE__ */ new Map();
116
+ const generations = /* @__PURE__ */ new Map();
117
+ const inflight = /* @__PURE__ */ new Map();
118
+ let unwatch = null;
119
+ let watching = null;
120
+ const invalidate = (subject) => {
121
+ if (subject === void 0) {
122
+ cache.clear();
123
+ lookups.clear();
124
+ inflight.clear();
125
+ for (const key of generations.keys()) generations.set(key, (generations.get(key) ?? 0) + 1);
126
+ return;
127
+ }
128
+ cache.delete(subject);
129
+ lookups.delete(subject);
130
+ inflight.delete(subject);
131
+ generations.set(subject, (generations.get(subject) ?? 0) + 1);
132
+ };
133
+ const ensureWatch = () => {
134
+ if (watching || !cacheEnabled || !isWatchable(storage)) return;
135
+ watching = storage.watch(`${ROOT}/`, (event) => {
136
+ const parsed = parseKey(event.key);
137
+ if (parsed && parsed.area !== "history") invalidate(parsed.subject);
138
+ }).then((off) => {
139
+ unwatch = off;
140
+ }).catch((error) => logger.warn("storage watch failed; relying on the cache TTL", error));
141
+ };
142
+ async function readSubject(subject) {
143
+ const [record, keys] = await Promise.all([storage.getItem(subjectKey(subject)), storage.getKeys(subjectGrantsPrefix(subject))]);
144
+ const grants = (await Promise.all(keys.map((key) => storage.getItem(key)))).filter((grant) => grant !== null && typeof grant === "object");
145
+ return {
146
+ record: record ?? null,
147
+ grants
148
+ };
149
+ }
150
+ function load(subject) {
151
+ if (!cacheEnabled) return readSubject(subject).then((e) => ({
152
+ ...e,
153
+ loadedAt: now()
154
+ }));
155
+ ensureWatch();
156
+ const cached = cache.get(subject);
157
+ if (cached && now() - cached.loadedAt < cacheTtl) return Promise.resolve(cached);
158
+ const pending = inflight.get(subject);
159
+ if (pending) return pending;
160
+ const generation = generations.get(subject) ?? 0;
161
+ const promise = readSubject(subject).then((data) => {
162
+ const entry = {
163
+ ...data,
164
+ loadedAt: now()
165
+ };
166
+ if ((generations.get(subject) ?? 0) === generation) {
167
+ cache.delete(subject);
168
+ cache.set(subject, entry);
169
+ while (cache.size > cacheMax) cache.delete(cache.keys().next().value);
170
+ }
171
+ return entry;
172
+ }).finally(() => {
173
+ if (inflight.get(subject) === promise) inflight.delete(subject);
174
+ });
175
+ inflight.set(subject, promise);
176
+ return promise;
177
+ }
178
+ async function appendHistory(entry, at) {
179
+ const id = ids.newId("hst", Date.parse(at));
180
+ const full = {
181
+ id,
182
+ at,
183
+ ...entry
184
+ };
185
+ await storage.setItem(historyKey(entry.subject, at, id), full);
186
+ }
187
+ const storedRole = (record) => record?.role !== void 0 && catalog.isRole(record.role) && record.role !== catalog.guestRole ? record.role : null;
188
+ /** The provider's identity of `id` from `lookupSubject` (cached; `null` without one). */
189
+ function lookup(id) {
190
+ if (!lookupSubject) return Promise.resolve(null);
191
+ const cached = cacheEnabled ? lookups.get(id) : void 0;
192
+ if (cached && now() - cached.at < cacheTtl) return cached.identity;
193
+ const identity = Promise.resolve().then(() => lookupSubject(id)).then((found) => found && typeof found === "object" ? found : null);
194
+ if (cacheEnabled) {
195
+ lookups.delete(id);
196
+ lookups.set(id, {
197
+ identity,
198
+ at: now()
199
+ });
200
+ while (lookups.size > cacheMax) lookups.delete(lookups.keys().next().value);
201
+ identity.catch(() => {
202
+ if (lookups.get(id)?.identity === identity) lookups.delete(id);
203
+ });
204
+ }
205
+ return identity;
206
+ }
207
+ /** True when a raw provider role names a known, non-guest role (else `defaultRole` applies). */
208
+ const knownRole = (raw) => {
209
+ return (typeof raw === "string" ? raw.split(",").map((s) => s.trim()) : Array.isArray(raw) ? raw : []).some((c) => catalog.isRole(c) && c !== catalog.guestRole);
210
+ };
211
+ /**
212
+ * The effective role (ADR 0014). `external`: the provider's role (passed with the identity, else
213
+ * looked up), else `defaultRole`. `stored`: the stored role, else the same. The lookup runs only
214
+ * when the identity carries no `role` (`null` means "the provider says none": no lookup).
215
+ */
216
+ async function decideRole(id, record, identity, lookupFailed) {
217
+ if (roleSource === "stored") {
218
+ const stored = storedRole(record);
219
+ if (stored !== null) return {
220
+ role: stored,
221
+ source: "stored",
222
+ looked: null
223
+ };
224
+ }
225
+ let looked = null;
226
+ let raw = identity?.role;
227
+ if (raw === void 0) {
228
+ looked = lookupFailed ? await lookup(id).catch(lookupFailed) : await lookup(id);
229
+ raw = looked?.role;
230
+ }
231
+ return knownRole(raw) ? {
232
+ role: catalog.effectiveRole(raw),
233
+ source: "provider",
234
+ looked
235
+ } : {
236
+ role: catalog.defaultRole,
237
+ source: "default",
238
+ looked
239
+ };
240
+ }
241
+ async function resolve(input) {
242
+ if (input === null || input === void 0) return {
243
+ id: null,
244
+ role: catalog.guestRole,
245
+ roleSource: void 0,
246
+ user: void 0,
247
+ grants: []
248
+ };
249
+ const identity = typeof input === "string" ? { id: input } : input;
250
+ const id = requireSubjectId(identity.id);
251
+ const entry = await load(id);
252
+ const { role, source, looked } = await decideRole(id, entry.record, identity);
253
+ const name = identity.name ?? entry.record?.name ?? looked?.name;
254
+ const email = identity.email ?? entry.record?.email ?? looked?.email;
255
+ const attributes = identity.attributes ?? looked?.attributes;
256
+ return {
257
+ id,
258
+ role,
259
+ roleSource: source,
260
+ user: {
261
+ id,
262
+ role,
263
+ ...name !== void 0 ? { name } : {},
264
+ ...email !== void 0 ? { email } : {},
265
+ ...attributes !== void 0 ? { attributes } : {}
266
+ },
267
+ grants: entry.grants.filter(active)
268
+ };
269
+ }
270
+ async function buildAbility(input, facts) {
271
+ const resolved = await resolve(input);
272
+ const createAbility = catalog.authorization.createAbility;
273
+ const ability = createAbility(resolved.user, {
274
+ permissions: resolved.grants.map((grant) => grant.permission),
275
+ ...facts && "ctx" in facts ? { ctx: facts.ctx } : {}
276
+ });
277
+ const decide = (path, explanation) => {
278
+ const base = {
279
+ path,
280
+ subject: resolved.id,
281
+ role: ability.role,
282
+ ...resolved.roleSource !== void 0 ? { roleSource: resolved.roleSource } : {},
283
+ explanation
284
+ };
285
+ if (catalog.directGrants && resolved.id !== null && ability.permissions.has(path)) return {
286
+ ...base,
287
+ allowed: true,
288
+ reason: "grant"
289
+ };
290
+ if (explanation.type === "allowed") return {
291
+ ...base,
292
+ allowed: true,
293
+ reason: "role-rule"
294
+ };
295
+ if (explanation.type === "unknown_path") return {
296
+ ...base,
297
+ allowed: false,
298
+ reason: "unknown-path"
299
+ };
300
+ return {
301
+ ...base,
302
+ allowed: false,
303
+ reason: explanation.decidedBy === "threw" ? "rule-threw" : "denied-by-rule"
304
+ };
305
+ };
306
+ const check = (path, data) => decide(path, ability.explain({
307
+ path,
308
+ data
309
+ }));
310
+ const checkAsync = async (path, data) => decide(path, await ability.explainAsync({
311
+ path,
312
+ data
313
+ }));
314
+ return {
315
+ ...ability,
316
+ subject: resolved.id,
317
+ grants: resolved.grants,
318
+ check,
319
+ checkAsync
320
+ };
321
+ }
322
+ async function grant(input) {
323
+ assertWritable("grant");
324
+ const subject = requireSubjectId(input?.subject);
325
+ const permission = requirePermission(input.permission);
326
+ const parsed = parseInput(grantInputSchema, input);
327
+ const actor = toActor(parsed.actor);
328
+ const expiresAt = parsed.expiresAt === void 0 || parsed.expiresAt === null ? null : toIso(parsed.expiresAt);
329
+ if (expiresAt !== null && Date.parse(expiresAt) <= now()) throw new ValidationError([{
330
+ path: "expiresAt",
331
+ message: "must be in the future"
332
+ }]);
333
+ const key = grantKey(subject, permission);
334
+ return withLock(key, async () => {
335
+ for (let attempt = 0; attempt < CAS_ATTEMPTS; attempt++) {
336
+ const existing = await storage.getItem(key);
337
+ if (existing && active(existing)) return {
338
+ grant: existing,
339
+ created: false
340
+ };
341
+ const at = nowIso();
342
+ const next = {
343
+ subject,
344
+ permission,
345
+ grantedBy: actor?.id ?? null,
346
+ grantedAt: at,
347
+ ...parsed.reason !== void 0 ? { reason: parsed.reason } : {},
348
+ ...expiresAt !== null ? { expiresAt } : {}
349
+ };
350
+ await runBefore(hooks, {
351
+ type: "grant.create",
352
+ subject,
353
+ grant: next,
354
+ actor
355
+ });
356
+ if (!await swap(key, existing ?? null, next)) continue;
357
+ invalidate(subject);
358
+ await appendHistory({
359
+ type: "grant",
360
+ subject,
361
+ permission,
362
+ actor: actor?.id ?? null,
363
+ ...parsed.reason !== void 0 ? { reason: parsed.reason } : {},
364
+ ...expiresAt !== null ? { expiresAt } : {}
365
+ }, at);
366
+ await runAfter(hooks, {
367
+ type: "grant.created",
368
+ subject,
369
+ grant: next,
370
+ actor,
371
+ at
372
+ }, onHookError);
373
+ return {
374
+ grant: next,
375
+ created: true
376
+ };
377
+ }
378
+ throw new Error(`grant: storage kept changing "${key}"; giving up`);
379
+ });
380
+ }
381
+ async function revoke(input) {
382
+ assertWritable("revoke");
383
+ const subject = requireSubjectId(input?.subject);
384
+ const permission = requirePermission(input.permission);
385
+ const parsed = parseInput(revokeInputSchema, input);
386
+ const actor = toActor(parsed.actor);
387
+ const key = grantKey(subject, permission);
388
+ return withLock(key, async () => {
389
+ const existing = await storage.getItem(key);
390
+ if (!existing) return {
391
+ removed: false,
392
+ grant: null
393
+ };
394
+ const reason = parsed.reason !== void 0 ? { reason: parsed.reason } : {};
395
+ await runBefore(hooks, {
396
+ type: "grant.revoke",
397
+ subject,
398
+ grant: existing,
399
+ actor,
400
+ ...reason
401
+ });
402
+ await storage.removeItem(key);
403
+ invalidate(subject);
404
+ const at = nowIso();
405
+ await appendHistory({
406
+ type: "revoke",
407
+ subject,
408
+ permission,
409
+ actor: actor?.id ?? null,
410
+ ...reason
411
+ }, at);
412
+ await runAfter(hooks, {
413
+ type: "grant.revoked",
414
+ subject,
415
+ grant: existing,
416
+ actor,
417
+ ...reason,
418
+ at
419
+ }, onHookError);
420
+ return {
421
+ removed: true,
422
+ grant: existing
423
+ };
424
+ });
425
+ }
426
+ async function setRole(input) {
427
+ if (roleSource === "external") throw new ExternalRolesError();
428
+ assertWritable("set role");
429
+ const subject = requireSubjectId(input?.subject);
430
+ const role = input.role;
431
+ if (role !== null) {
432
+ if (!catalog.isRole(role)) throw new UnknownRoleError(role);
433
+ if (role === catalog.guestRole) throw new UnknownRoleError(role, `The guest role "${role}" can't be assigned to a subject.`);
434
+ }
435
+ const parsed = parseInput(setRoleInputSchema, input);
436
+ const actor = toActor(parsed.actor);
437
+ const reason = parsed.reason !== void 0 ? { reason: parsed.reason } : {};
438
+ const key = subjectKey(subject);
439
+ return withLock(key, async () => {
440
+ for (let attempt = 0; attempt < CAS_ATTEMPTS; attempt++) {
441
+ const current = await storage.getItem(key);
442
+ const previous = current?.role ?? null;
443
+ if (previous === role) return {
444
+ record: current ?? null,
445
+ changed: false
446
+ };
447
+ const at = nowIso();
448
+ const { role: _old, ...rest } = current ?? { id: subject };
449
+ const next = {
450
+ ...rest,
451
+ id: subject,
452
+ ...role !== null ? { role } : {},
453
+ updatedAt: at
454
+ };
455
+ await runBefore(hooks, {
456
+ type: "role.set",
457
+ subject,
458
+ role,
459
+ previous,
460
+ actor,
461
+ ...reason
462
+ });
463
+ if (!await swap(key, current ?? null, next)) continue;
464
+ invalidate(subject);
465
+ await appendHistory({
466
+ type: "role",
467
+ subject,
468
+ role,
469
+ previousRole: previous,
470
+ actor: actor?.id ?? null,
471
+ ...reason
472
+ }, at);
473
+ await runAfter(hooks, {
474
+ type: "role.changed",
475
+ subject,
476
+ role,
477
+ previous,
478
+ record: next,
479
+ actor,
480
+ ...reason,
481
+ at
482
+ }, onHookError);
483
+ return {
484
+ record: next,
485
+ changed: true
486
+ };
487
+ }
488
+ throw new Error(`setRole: storage kept changing "${key}"; giving up`);
489
+ });
490
+ }
491
+ async function upsertSubject(input) {
492
+ assertWritable("update subject");
493
+ const subject = requireSubjectId(input?.id);
494
+ const parsed = parseInput(upsertSubjectInputSchema, input);
495
+ const key = subjectKey(subject);
496
+ return withLock(key, async () => {
497
+ for (let attempt = 0; attempt < CAS_ATTEMPTS; attempt++) {
498
+ const current = await storage.getItem(key);
499
+ const next = {
500
+ ...current,
501
+ id: subject,
502
+ updatedAt: nowIso()
503
+ };
504
+ for (const field of ["name", "email"]) {
505
+ const value = parsed[field];
506
+ if (value === null) delete next[field];
507
+ else if (value !== void 0) next[field] = value;
508
+ }
509
+ if (!await swap(key, current ?? null, next)) continue;
510
+ invalidate(subject);
511
+ return next;
512
+ }
513
+ throw new Error(`upsertSubject: storage kept changing "${key}"; giving up`);
514
+ });
515
+ }
516
+ async function list(query = {}) {
517
+ const parsed = parseInput(listQuerySchema, query);
518
+ let keys;
519
+ if (parsed.subject !== void 0 && parsed.permission !== void 0) keys = [grantKey(parsed.subject, parsed.permission)];
520
+ else if (parsed.subject !== void 0) keys = await storage.getKeys(subjectGrantsPrefix(parsed.subject));
521
+ else {
522
+ keys = await storage.getKeys(grantsPrefix());
523
+ if (parsed.permission !== void 0) {
524
+ const permission = parsed.permission;
525
+ keys = keys.filter((key) => {
526
+ const p = parseKey(key);
527
+ return p?.area === "grants" && p.rest === permission;
528
+ });
529
+ }
530
+ }
531
+ return (await Promise.all(keys.map((key) => storage.getItem(key)))).filter((grant) => grant !== null && typeof grant === "object" && (parsed.includeExpired === true || active(grant))).sort((a, b) => a.subject === b.subject ? a.permission < b.permission ? -1 : a.permission > b.permission ? 1 : 0 : a.subject < b.subject ? -1 : 1);
532
+ }
533
+ async function getSubject(id, opts = {}) {
534
+ const subject = requireSubjectId(id);
535
+ const { record, grants } = await readSubject(subject);
536
+ const { role, source } = await decideRole(subject, record, null);
537
+ const shown = opts.includeExpired ? grants : grants.filter(active);
538
+ shown.sort((a, b) => a.permission < b.permission ? -1 : a.permission > b.permission ? 1 : 0);
539
+ return {
540
+ id: subject,
541
+ record,
542
+ role: storedRole(record),
543
+ effectiveRole: role,
544
+ roleSource: source,
545
+ grants: shown
546
+ };
547
+ }
548
+ async function listSubjects() {
549
+ const [recordKeys, grantKeys] = await Promise.all([storage.getKeys(subjectsPrefix()), storage.getKeys(grantsPrefix())]);
550
+ const counts = /* @__PURE__ */ new Map();
551
+ for (const key of grantKeys) {
552
+ const parsed = parseKey(key);
553
+ if (parsed?.area === "grants") counts.set(parsed.subject, (counts.get(parsed.subject) ?? 0) + 1);
554
+ }
555
+ const records = /* @__PURE__ */ new Map();
556
+ await Promise.all(recordKeys.map(async (key) => {
557
+ const parsed = parseKey(key);
558
+ if (parsed?.area !== "subjects" || parsed.rest !== void 0) return;
559
+ const record = await storage.getItem(key);
560
+ if (record) records.set(parsed.subject, record);
561
+ }));
562
+ const ids = [...new Set([...records.keys(), ...counts.keys()])].sort();
563
+ return Promise.all(ids.map(async (id) => {
564
+ const record = records.get(id) ?? null;
565
+ const { role, source, looked } = await decideRole(id, record, null, (error) => {
566
+ logger.warn(`lookupSubject("${id}") failed; listing its default role`, error);
567
+ return null;
568
+ });
569
+ const name = record?.name ?? looked?.name;
570
+ const email = record?.email ?? looked?.email;
571
+ return {
572
+ id,
573
+ role: record?.role ?? null,
574
+ effectiveRole: role,
575
+ roleSource: source,
576
+ ...name !== void 0 ? { name } : {},
577
+ ...email !== void 0 ? { email } : {},
578
+ grantCount: counts.get(id) ?? 0
579
+ };
580
+ }));
581
+ }
582
+ async function history(query = {}) {
583
+ const parsed = parseInput(historyQuerySchema, query);
584
+ const limit = parsed.limit ?? DEFAULT_HISTORY_LIMIT;
585
+ let tokens = (await storage.getKeys(parsed.subject !== void 0 ? subjectHistoryPrefix(parsed.subject) : historyPrefix())).map((key) => ({
586
+ key,
587
+ token: historyToken(key)
588
+ }));
589
+ tokens.sort((a, b) => a.token < b.token ? 1 : a.token > b.token ? -1 : 0);
590
+ if (parsed.cursor !== void 0) {
591
+ const after = historyToken(parsed.cursor);
592
+ tokens = tokens.filter((t) => t.token < after);
593
+ }
594
+ const page = tokens.slice(0, limit);
595
+ const entries = (await Promise.all(page.map((t) => storage.getItem(t.key)))).filter((entry) => entry !== null && typeof entry === "object");
596
+ const last = page[page.length - 1];
597
+ return {
598
+ entries,
599
+ nextCursor: tokens.length > limit && last ? last.key : null
600
+ };
601
+ }
602
+ return {
603
+ ...createRelationships({
604
+ storage,
605
+ schema: catalog.relations,
606
+ options: options.relations,
607
+ hooks,
608
+ onHookError,
609
+ nowIso,
610
+ assertWritable,
611
+ withLock,
612
+ appendHistory,
613
+ toActor
614
+ }),
615
+ catalog,
616
+ storage,
617
+ readonly,
618
+ roleSource,
619
+ grant,
620
+ revoke,
621
+ list,
622
+ setRole,
623
+ getSubject,
624
+ listSubjects,
625
+ upsertSubject,
626
+ history,
627
+ ability: (subject, ...[facts]) => buildAbility(subject, facts),
628
+ check: async (subject, path, data, ...[facts]) => (await buildAbility(subject, facts)).checkAsync(path, data),
629
+ can: async (subject, path, data, ...[facts]) => (await (await buildAbility(subject, facts)).checkAsync(path, data)).allowed,
630
+ async snapshot(subject) {
631
+ const resolved = await resolve(subject);
632
+ const permissions = [...new Set(resolved.grants.map((grant) => grant.permission).filter(catalog.isAssignable))].sort();
633
+ return {
634
+ subject: {
635
+ id: resolved.id,
636
+ role: resolved.role,
637
+ ...resolved.roleSource !== void 0 ? { roleSource: resolved.roleSource } : {}
638
+ },
639
+ permissions
640
+ };
641
+ },
642
+ invalidate,
643
+ async close() {
644
+ await watching;
645
+ const off = unwatch;
646
+ unwatch = null;
647
+ off?.();
648
+ }
649
+ };
650
+ }
651
+ //#endregion
652
+ export { engine_exports as n, createPermissions as t };
653
+
654
+ //# sourceMappingURL=engine-CR75K253.mjs.map