@xtandard/audit 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 (423) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +384 -2
  3. package/bin/xtandard-audit.mjs +3 -0
  4. package/dist/basic-DU_nPrWV.mjs +176 -0
  5. package/dist/basic-DU_nPrWV.mjs.map +1 -0
  6. package/dist/basic-hcXnMF9X.cjs +199 -0
  7. package/dist/basic-hcXnMF9X.cjs.map +1 -0
  8. package/dist/canonical-BOgkrX9_.d.cts +17 -0
  9. package/dist/canonical-CL7gfwhb.d.mts +17 -0
  10. package/dist/chunk-D7D4PA-g.mjs +13 -0
  11. package/dist/cli.cjs +773 -0
  12. package/dist/cli.cjs.map +1 -0
  13. package/dist/cli.d.cts +46 -0
  14. package/dist/cli.d.mts +46 -0
  15. package/dist/cli.mjs +762 -0
  16. package/dist/cli.mjs.map +1 -0
  17. package/dist/context-BtR9k9Mt.d.mts +52 -0
  18. package/dist/context-CJM87uG8.d.cts +52 -0
  19. package/dist/context-shared-AgBWIRUQ.d.mts +29 -0
  20. package/dist/context-shared-CUq3cSpV.d.cts +29 -0
  21. package/dist/context-shared-CupikwQo.mjs +39 -0
  22. package/dist/context-shared-CupikwQo.mjs.map +1 -0
  23. package/dist/context-shared-X2ulHHSB.cjs +44 -0
  24. package/dist/context-shared-X2ulHHSB.cjs.map +1 -0
  25. package/dist/context.cjs +82 -0
  26. package/dist/context.cjs.map +1 -0
  27. package/dist/context.d.cts +2 -0
  28. package/dist/context.d.mts +2 -0
  29. package/dist/context.mjs +78 -0
  30. package/dist/context.mjs.map +1 -0
  31. package/dist/contract-BljSE-Hx.mjs +33 -0
  32. package/dist/contract-BljSE-Hx.mjs.map +1 -0
  33. package/dist/contract-BmwHIiMR.d.mts +150 -0
  34. package/dist/contract-CWJSYoJl.d.cts +150 -0
  35. package/dist/contract-Cht05WYQ.d.mts +159 -0
  36. package/dist/contract-CqYQzB6e.d.cts +49 -0
  37. package/dist/contract-DYvBNdnR.cjs +74 -0
  38. package/dist/contract-DYvBNdnR.cjs.map +1 -0
  39. package/dist/contract-DlTo4u2t.d.cts +30 -0
  40. package/dist/contract-DlTo4u2t.d.mts +30 -0
  41. package/dist/contract-DsVL5-gy.cjs +50 -0
  42. package/dist/contract-DsVL5-gy.cjs.map +1 -0
  43. package/dist/contract-isM9SjjQ.mjs +39 -0
  44. package/dist/contract-isM9SjjQ.mjs.map +1 -0
  45. package/dist/contract-pU3wGFmo.d.cts +159 -0
  46. package/dist/contract-yPNuFnVy.d.mts +49 -0
  47. package/dist/core-C0ceVOTk.d.cts +513 -0
  48. package/dist/core-CTr7dw0v.cjs +1725 -0
  49. package/dist/core-CTr7dw0v.cjs.map +1 -0
  50. package/dist/core-IdGEbYdM.mjs +1541 -0
  51. package/dist/core-IdGEbYdM.mjs.map +1 -0
  52. package/dist/core-KtEHRScZ.d.mts +513 -0
  53. package/dist/core.cjs +9 -0
  54. package/dist/core.d.cts +2 -0
  55. package/dist/core.d.mts +2 -0
  56. package/dist/core.mjs +2 -0
  57. package/dist/create-fetch-handler-1pXSEhGi.d.cts +311 -0
  58. package/dist/create-fetch-handler-BwQQ_IWf.mjs +2156 -0
  59. package/dist/create-fetch-handler-BwQQ_IWf.mjs.map +1 -0
  60. package/dist/create-fetch-handler-D8cTMVX9.cjs +2232 -0
  61. package/dist/create-fetch-handler-D8cTMVX9.cjs.map +1 -0
  62. package/dist/create-fetch-handler-zioPVS18.d.mts +311 -0
  63. package/dist/elysia-shared-C7geKqPP.mjs +55 -0
  64. package/dist/elysia-shared-C7geKqPP.mjs.map +1 -0
  65. package/dist/elysia-shared-DT4bfekR.d.cts +20 -0
  66. package/dist/elysia-shared-DXyAyGz_.cjs +66 -0
  67. package/dist/elysia-shared-DXyAyGz_.cjs.map +1 -0
  68. package/dist/elysia-shared-DoL5ab52.d.mts +20 -0
  69. package/dist/entry-auth-basic.cjs +5 -0
  70. package/dist/entry-auth-basic.d.cts +83 -0
  71. package/dist/entry-auth-basic.d.mts +83 -0
  72. package/dist/entry-auth-basic.mjs +2 -0
  73. package/dist/entry-auth-delegated.cjs +28 -0
  74. package/dist/entry-auth-delegated.cjs.map +1 -0
  75. package/dist/entry-auth-delegated.d.cts +36 -0
  76. package/dist/entry-auth-delegated.d.mts +36 -0
  77. package/dist/entry-auth-delegated.mjs +27 -0
  78. package/dist/entry-auth-delegated.mjs.map +1 -0
  79. package/dist/entry-auth-none.cjs +4 -0
  80. package/dist/entry-auth-none.d.cts +25 -0
  81. package/dist/entry-auth-none.d.mts +25 -0
  82. package/dist/entry-auth-none.mjs +2 -0
  83. package/dist/entry-authorization-delegated.cjs +28 -0
  84. package/dist/entry-authorization-delegated.cjs.map +1 -0
  85. package/dist/entry-authorization-delegated.d.cts +32 -0
  86. package/dist/entry-authorization-delegated.d.mts +32 -0
  87. package/dist/entry-authorization-delegated.mjs +27 -0
  88. package/dist/entry-authorization-delegated.mjs.map +1 -0
  89. package/dist/entry-authorization-none.cjs +3 -0
  90. package/dist/entry-authorization-none.d.cts +18 -0
  91. package/dist/entry-authorization-none.d.mts +18 -0
  92. package/dist/entry-authorization-none.mjs +2 -0
  93. package/dist/entry-authorization-roles.cjs +8 -0
  94. package/dist/entry-authorization-roles.d.cts +64 -0
  95. package/dist/entry-authorization-roles.d.mts +64 -0
  96. package/dist/entry-authorization-roles.mjs +3 -0
  97. package/dist/entry-bun.cjs +55 -0
  98. package/dist/entry-bun.cjs.map +1 -0
  99. package/dist/entry-bun.d.cts +29 -0
  100. package/dist/entry-bun.d.mts +29 -0
  101. package/dist/entry-bun.mjs +52 -0
  102. package/dist/entry-bun.mjs.map +1 -0
  103. package/dist/entry-drizzle-audit.cjs +191 -0
  104. package/dist/entry-drizzle-audit.cjs.map +1 -0
  105. package/dist/entry-drizzle-audit.d.cts +118 -0
  106. package/dist/entry-drizzle-audit.d.mts +118 -0
  107. package/dist/entry-drizzle-audit.mjs +186 -0
  108. package/dist/entry-drizzle-audit.mjs.map +1 -0
  109. package/dist/entry-drizzle-mysql.cjs +75 -0
  110. package/dist/entry-drizzle-mysql.cjs.map +1 -0
  111. package/dist/entry-drizzle-mysql.d.cts +42 -0
  112. package/dist/entry-drizzle-mysql.d.mts +42 -0
  113. package/dist/entry-drizzle-mysql.mjs +71 -0
  114. package/dist/entry-drizzle-mysql.mjs.map +1 -0
  115. package/dist/entry-drizzle-pg.cjs +82 -0
  116. package/dist/entry-drizzle-pg.cjs.map +1 -0
  117. package/dist/entry-drizzle-pg.d.cts +48 -0
  118. package/dist/entry-drizzle-pg.d.mts +48 -0
  119. package/dist/entry-drizzle-pg.mjs +78 -0
  120. package/dist/entry-drizzle-pg.mjs.map +1 -0
  121. package/dist/entry-drizzle-sqlite.cjs +71 -0
  122. package/dist/entry-drizzle-sqlite.cjs.map +1 -0
  123. package/dist/entry-drizzle-sqlite.d.cts +37 -0
  124. package/dist/entry-drizzle-sqlite.d.mts +37 -0
  125. package/dist/entry-drizzle-sqlite.mjs +67 -0
  126. package/dist/entry-drizzle-sqlite.mjs.map +1 -0
  127. package/dist/entry-elysia.cjs +112 -0
  128. package/dist/entry-elysia.cjs.map +1 -0
  129. package/dist/entry-elysia.d.cts +710 -0
  130. package/dist/entry-elysia.d.mts +710 -0
  131. package/dist/entry-elysia.mjs +109 -0
  132. package/dist/entry-elysia.mjs.map +1 -0
  133. package/dist/entry-elysia2.cjs +101 -0
  134. package/dist/entry-elysia2.cjs.map +1 -0
  135. package/dist/entry-elysia2.d.cts +905 -0
  136. package/dist/entry-elysia2.d.mts +905 -0
  137. package/dist/entry-elysia2.mjs +98 -0
  138. package/dist/entry-elysia2.mjs.map +1 -0
  139. package/dist/entry-express.cjs +90 -0
  140. package/dist/entry-express.cjs.map +1 -0
  141. package/dist/entry-express.d.cts +24 -0
  142. package/dist/entry-express.d.mts +24 -0
  143. package/dist/entry-express.mjs +88 -0
  144. package/dist/entry-express.mjs.map +1 -0
  145. package/dist/entry-hono.cjs +36 -0
  146. package/dist/entry-hono.cjs.map +1 -0
  147. package/dist/entry-hono.d.cts +24 -0
  148. package/dist/entry-hono.d.mts +24 -0
  149. package/dist/entry-hono.mjs +34 -0
  150. package/dist/entry-hono.mjs.map +1 -0
  151. package/dist/entry-hooks-log.cjs +22 -0
  152. package/dist/entry-hooks-log.cjs.map +1 -0
  153. package/dist/entry-hooks-log.d.cts +23 -0
  154. package/dist/entry-hooks-log.d.mts +23 -0
  155. package/dist/entry-hooks-log.mjs +21 -0
  156. package/dist/entry-hooks-log.mjs.map +1 -0
  157. package/dist/entry-sinks-console.cjs +43 -0
  158. package/dist/entry-sinks-console.cjs.map +1 -0
  159. package/dist/entry-sinks-console.d.cts +26 -0
  160. package/dist/entry-sinks-console.d.mts +26 -0
  161. package/dist/entry-sinks-console.mjs +41 -0
  162. package/dist/entry-sinks-console.mjs.map +1 -0
  163. package/dist/entry-sinks-datadog.cjs +97 -0
  164. package/dist/entry-sinks-datadog.cjs.map +1 -0
  165. package/dist/entry-sinks-datadog.d.cts +66 -0
  166. package/dist/entry-sinks-datadog.d.mts +66 -0
  167. package/dist/entry-sinks-datadog.mjs +91 -0
  168. package/dist/entry-sinks-datadog.mjs.map +1 -0
  169. package/dist/entry-sinks-file.cjs +100 -0
  170. package/dist/entry-sinks-file.cjs.map +1 -0
  171. package/dist/entry-sinks-file.d.cts +70 -0
  172. package/dist/entry-sinks-file.d.mts +70 -0
  173. package/dist/entry-sinks-file.mjs +97 -0
  174. package/dist/entry-sinks-file.mjs.map +1 -0
  175. package/dist/entry-sinks-http.cjs +63 -0
  176. package/dist/entry-sinks-http.cjs.map +1 -0
  177. package/dist/entry-sinks-http.d.cts +55 -0
  178. package/dist/entry-sinks-http.d.mts +55 -0
  179. package/dist/entry-sinks-http.mjs +60 -0
  180. package/dist/entry-sinks-http.mjs.map +1 -0
  181. package/dist/entry-sinks-s3.cjs +115 -0
  182. package/dist/entry-sinks-s3.cjs.map +1 -0
  183. package/dist/entry-sinks-s3.d.cts +79 -0
  184. package/dist/entry-sinks-s3.d.mts +79 -0
  185. package/dist/entry-sinks-s3.mjs +112 -0
  186. package/dist/entry-sinks-s3.mjs.map +1 -0
  187. package/dist/entry-sinks-splunk.cjs +80 -0
  188. package/dist/entry-sinks-splunk.cjs.map +1 -0
  189. package/dist/entry-sinks-splunk.d.cts +58 -0
  190. package/dist/entry-sinks-splunk.d.mts +58 -0
  191. package/dist/entry-sinks-splunk.mjs +77 -0
  192. package/dist/entry-sinks-splunk.mjs.map +1 -0
  193. package/dist/entry-sinks-webhook.cjs +130 -0
  194. package/dist/entry-sinks-webhook.cjs.map +1 -0
  195. package/dist/entry-sinks-webhook.d.cts +69 -0
  196. package/dist/entry-sinks-webhook.d.mts +69 -0
  197. package/dist/entry-sinks-webhook.mjs +125 -0
  198. package/dist/entry-sinks-webhook.mjs.map +1 -0
  199. package/dist/entry-sinks-xtandard-webhooks.cjs +64 -0
  200. package/dist/entry-sinks-xtandard-webhooks.cjs.map +1 -0
  201. package/dist/entry-sinks-xtandard-webhooks.d.cts +64 -0
  202. package/dist/entry-sinks-xtandard-webhooks.d.mts +64 -0
  203. package/dist/entry-sinks-xtandard-webhooks.mjs +63 -0
  204. package/dist/entry-sinks-xtandard-webhooks.mjs.map +1 -0
  205. package/dist/entry-storage-cloudflare-kv.cjs +47 -0
  206. package/dist/entry-storage-cloudflare-kv.cjs.map +1 -0
  207. package/dist/entry-storage-cloudflare-kv.d.cts +42 -0
  208. package/dist/entry-storage-cloudflare-kv.d.mts +42 -0
  209. package/dist/entry-storage-cloudflare-kv.mjs +46 -0
  210. package/dist/entry-storage-cloudflare-kv.mjs.map +1 -0
  211. package/dist/entry-storage-drizzle.cjs +228 -0
  212. package/dist/entry-storage-drizzle.cjs.map +1 -0
  213. package/dist/entry-storage-drizzle.d.cts +43 -0
  214. package/dist/entry-storage-drizzle.d.mts +43 -0
  215. package/dist/entry-storage-drizzle.mjs +227 -0
  216. package/dist/entry-storage-drizzle.mjs.map +1 -0
  217. package/dist/entry-storage-file.cjs +175 -0
  218. package/dist/entry-storage-file.cjs.map +1 -0
  219. package/dist/entry-storage-file.d.cts +41 -0
  220. package/dist/entry-storage-file.d.mts +41 -0
  221. package/dist/entry-storage-file.mjs +171 -0
  222. package/dist/entry-storage-file.mjs.map +1 -0
  223. package/dist/entry-storage-libsql.cjs +133 -0
  224. package/dist/entry-storage-libsql.cjs.map +1 -0
  225. package/dist/entry-storage-libsql.d.cts +60 -0
  226. package/dist/entry-storage-libsql.d.mts +60 -0
  227. package/dist/entry-storage-libsql.mjs +132 -0
  228. package/dist/entry-storage-libsql.mjs.map +1 -0
  229. package/dist/entry-storage-memory.cjs +3 -0
  230. package/dist/entry-storage-memory.d.cts +2 -0
  231. package/dist/entry-storage-memory.d.mts +2 -0
  232. package/dist/entry-storage-memory.mjs +2 -0
  233. package/dist/entry-storage-mongodb.cjs +306 -0
  234. package/dist/entry-storage-mongodb.cjs.map +1 -0
  235. package/dist/entry-storage-mongodb.d.cts +65 -0
  236. package/dist/entry-storage-mongodb.d.mts +65 -0
  237. package/dist/entry-storage-mongodb.mjs +304 -0
  238. package/dist/entry-storage-mongodb.mjs.map +1 -0
  239. package/dist/entry-storage-postgres.cjs +261 -0
  240. package/dist/entry-storage-postgres.cjs.map +1 -0
  241. package/dist/entry-storage-postgres.d.cts +66 -0
  242. package/dist/entry-storage-postgres.d.mts +66 -0
  243. package/dist/entry-storage-postgres.mjs +260 -0
  244. package/dist/entry-storage-postgres.mjs.map +1 -0
  245. package/dist/entry-storage-redis.cjs +223 -0
  246. package/dist/entry-storage-redis.cjs.map +1 -0
  247. package/dist/entry-storage-redis.d.cts +77 -0
  248. package/dist/entry-storage-redis.d.mts +77 -0
  249. package/dist/entry-storage-redis.mjs +221 -0
  250. package/dist/entry-storage-redis.mjs.map +1 -0
  251. package/dist/entry-storage-sqlite.cjs +85 -0
  252. package/dist/entry-storage-sqlite.cjs.map +1 -0
  253. package/dist/entry-storage-sqlite.d.cts +40 -0
  254. package/dist/entry-storage-sqlite.d.mts +40 -0
  255. package/dist/entry-storage-sqlite.mjs +84 -0
  256. package/dist/entry-storage-sqlite.mjs.map +1 -0
  257. package/dist/entry-storage-unstorage.cjs +57 -0
  258. package/dist/entry-storage-unstorage.cjs.map +1 -0
  259. package/dist/entry-storage-unstorage.d.cts +29 -0
  260. package/dist/entry-storage-unstorage.d.mts +29 -0
  261. package/dist/entry-storage-unstorage.mjs +56 -0
  262. package/dist/entry-storage-unstorage.mjs.map +1 -0
  263. package/dist/export-B9S-JeYl.mjs +239 -0
  264. package/dist/export-B9S-JeYl.mjs.map +1 -0
  265. package/dist/export-BZq0KCCn.d.mts +70 -0
  266. package/dist/export-DYfMd-ep.cjs +280 -0
  267. package/dist/export-DYfMd-ep.cjs.map +1 -0
  268. package/dist/export-Dh8T8I1p.d.cts +70 -0
  269. package/dist/index.cjs +279 -0
  270. package/dist/index.cjs.map +1 -0
  271. package/dist/index.d.cts +286 -0
  272. package/dist/index.d.mts +284 -0
  273. package/dist/index.mjs +177 -0
  274. package/dist/index.mjs.map +1 -0
  275. package/dist/integrity-BHhjTBNk.cjs +614 -0
  276. package/dist/integrity-BHhjTBNk.cjs.map +1 -0
  277. package/dist/integrity-kfY2DNAi.mjs +483 -0
  278. package/dist/integrity-kfY2DNAi.mjs.map +1 -0
  279. package/dist/memory-CfykUo9W.cjs +155 -0
  280. package/dist/memory-CfykUo9W.cjs.map +1 -0
  281. package/dist/memory-DrR-Tlbf.d.mts +28 -0
  282. package/dist/memory-GG2Nba1D.mjs +150 -0
  283. package/dist/memory-GG2Nba1D.mjs.map +1 -0
  284. package/dist/memory-HpFdlMR_.d.cts +28 -0
  285. package/dist/none-Be7r6kHH.cjs +33 -0
  286. package/dist/none-Be7r6kHH.cjs.map +1 -0
  287. package/dist/none-CGmIIbI8.cjs +49 -0
  288. package/dist/none-CGmIIbI8.cjs.map +1 -0
  289. package/dist/none-CkV5mZsB.mjs +33 -0
  290. package/dist/none-CkV5mZsB.mjs.map +1 -0
  291. package/dist/none-DBeBeU0Z.mjs +23 -0
  292. package/dist/none-DBeBeU0Z.mjs.map +1 -0
  293. package/dist/query-ChGGtlA7.cjs +243 -0
  294. package/dist/query-ChGGtlA7.cjs.map +1 -0
  295. package/dist/query-LvZbyi37.mjs +172 -0
  296. package/dist/query-LvZbyi37.mjs.map +1 -0
  297. package/dist/react.css +1 -0
  298. package/dist/react.js +31935 -0
  299. package/dist/recorder-B3dG3jbd.d.mts +64 -0
  300. package/dist/recorder-CGY7HK29.d.cts +64 -0
  301. package/dist/roles-BARtYLSX.cjs +112 -0
  302. package/dist/roles-BARtYLSX.cjs.map +1 -0
  303. package/dist/roles-D7Pg89IJ.mjs +83 -0
  304. package/dist/roles-D7Pg89IJ.mjs.map +1 -0
  305. package/dist/schema-DmU7Wp0F.d.cts +251 -0
  306. package/dist/schema-DmU7Wp0F.d.mts +251 -0
  307. package/dist/schema.cjs +20 -0
  308. package/dist/schema.cjs.map +1 -0
  309. package/dist/schema.d.cts +2 -0
  310. package/dist/schema.d.mts +2 -0
  311. package/dist/schema.mjs +17 -0
  312. package/dist/schema.mjs.map +1 -0
  313. package/dist/shared-CJOyJKqT.d.mts +20 -0
  314. package/dist/shared-DSDY-V0n.mjs +100 -0
  315. package/dist/shared-DSDY-V0n.mjs.map +1 -0
  316. package/dist/shared-EANCdRqn.d.cts +20 -0
  317. package/dist/shared-OOAq-U4S.cjs +141 -0
  318. package/dist/shared-OOAq-U4S.cjs.map +1 -0
  319. package/dist/sql-B7b6HzGy.cjs +280 -0
  320. package/dist/sql-B7b6HzGy.cjs.map +1 -0
  321. package/dist/sql-COjPyn3F.mjs +209 -0
  322. package/dist/sql-COjPyn3F.mjs.map +1 -0
  323. package/dist/sqlite-event-log-BnoG8eos.cjs +184 -0
  324. package/dist/sqlite-event-log-BnoG8eos.cjs.map +1 -0
  325. package/dist/sqlite-event-log-nXmS2DS_.mjs +179 -0
  326. package/dist/sqlite-event-log-nXmS2DS_.mjs.map +1 -0
  327. package/dist/streams-CRuxOYcb.d.cts +124 -0
  328. package/dist/streams-DU0_gvI8.d.mts +124 -0
  329. package/dist/table-BcarDd10.d.cts +48 -0
  330. package/dist/table-BcarDd10.d.mts +48 -0
  331. package/dist/testing.cjs +189 -0
  332. package/dist/testing.cjs.map +1 -0
  333. package/dist/testing.d.cts +103 -0
  334. package/dist/testing.d.mts +103 -0
  335. package/dist/testing.mjs +185 -0
  336. package/dist/testing.mjs.map +1 -0
  337. package/dist/types-elysia2/adapters/bun.d.ts +47 -0
  338. package/dist/types-elysia2/adapters/context-shared.d.ts +40 -0
  339. package/dist/types-elysia2/adapters/elysia-shared.d.ts +36 -0
  340. package/dist/types-elysia2/adapters/elysia2.d.ts +588 -0
  341. package/dist/types-elysia2/auth/contract.d.ts +26 -0
  342. package/dist/types-elysia2/authorization/contract.d.ts +54 -0
  343. package/dist/types-elysia2/canonical.d.ts +25 -0
  344. package/dist/types-elysia2/context.d.ts +61 -0
  345. package/dist/types-elysia2/core.d.ts +232 -0
  346. package/dist/types-elysia2/duration.d.ts +26 -0
  347. package/dist/types-elysia2/entry-elysia2.d.ts +10 -0
  348. package/dist/types-elysia2/event-log.d.ts +33 -0
  349. package/dist/types-elysia2/export.d.ts +77 -0
  350. package/dist/types-elysia2/hooks/contract.d.ts +177 -0
  351. package/dist/types-elysia2/id.d.ts +27 -0
  352. package/dist/types-elysia2/integrity.d.ts +193 -0
  353. package/dist/types-elysia2/keys.d.ts +91 -0
  354. package/dist/types-elysia2/portal.d.ts +137 -0
  355. package/dist/types-elysia2/query.d.ts +88 -0
  356. package/dist/types-elysia2/schema.d.ts +247 -0
  357. package/dist/types-elysia2/server/base-path.d.ts +15 -0
  358. package/dist/types-elysia2/server/cors.d.ts +36 -0
  359. package/dist/types-elysia2/server/create-fetch-handler.d.ts +140 -0
  360. package/dist/types-elysia2/server/openapi.d.ts +25 -0
  361. package/dist/types-elysia2/server/render-index-html.d.ts +18 -0
  362. package/dist/types-elysia2/server/routes.d.ts +83 -0
  363. package/dist/types-elysia2/server/static-assets.d.ts +13 -0
  364. package/dist/types-elysia2/standard-schema.d.ts +100 -0
  365. package/dist/types-elysia2/storage/contract.d.ts +106 -0
  366. package/dist/types-elysia2/streams.d.ts +134 -0
  367. package/dist/types-elysia2/transforms.d.ts +56 -0
  368. package/dist/types-elysia2/validation.d.ts +48 -0
  369. package/dist/types-react/canonical.d.ts +25 -0
  370. package/dist/types-react/context.d.ts +61 -0
  371. package/dist/types-react/core.d.ts +232 -0
  372. package/dist/types-react/duration.d.ts +26 -0
  373. package/dist/types-react/event-log.d.ts +33 -0
  374. package/dist/types-react/hooks/contract.d.ts +177 -0
  375. package/dist/types-react/id.d.ts +27 -0
  376. package/dist/types-react/integrity.d.ts +193 -0
  377. package/dist/types-react/keys.d.ts +91 -0
  378. package/dist/types-react/query.d.ts +88 -0
  379. package/dist/types-react/react.d.ts +114 -0
  380. package/dist/types-react/schema.d.ts +247 -0
  381. package/dist/types-react/standard-schema.d.ts +100 -0
  382. package/dist/types-react/storage/contract.d.ts +106 -0
  383. package/dist/types-react/streams.d.ts +134 -0
  384. package/dist/types-react/transforms.d.ts +56 -0
  385. package/dist/types-react/ui/App.d.ts +36 -0
  386. package/dist/types-react/ui/api.d.ts +61 -0
  387. package/dist/types-react/ui/components/ActionFilter.d.ts +17 -0
  388. package/dist/types-react/ui/components/ExportMenu.d.ts +13 -0
  389. package/dist/types-react/ui/components/JsonCodeEditor.d.ts +12 -0
  390. package/dist/types-react/ui/components/ThemeToggle.d.ts +2 -0
  391. package/dist/types-react/ui/components/Toast.d.ts +16 -0
  392. package/dist/types-react/ui/components/audit-bits.d.ts +91 -0
  393. package/dist/types-react/ui/components/integrity-bits.d.ts +19 -0
  394. package/dist/types-react/ui/components/primitives.d.ts +50 -0
  395. package/dist/types-react/ui/components/ui-bits.d.ts +22 -0
  396. package/dist/types-react/ui/lib/filters.d.ts +70 -0
  397. package/dist/types-react/ui/lib/format.d.ts +82 -0
  398. package/dist/types-react/ui/lib/nav-guard.d.ts +20 -0
  399. package/dist/types-react/ui/lib/portal-container.d.ts +24 -0
  400. package/dist/types-react/ui/lib/utils.d.ts +3 -0
  401. package/dist/types-react/ui/theme.d.ts +40 -0
  402. package/dist/types-react/ui/types.d.ts +67 -0
  403. package/dist/types-react/ui/views/ActionsView.d.ts +10 -0
  404. package/dist/types-react/ui/views/EventDrawer.d.ts +15 -0
  405. package/dist/types-react/ui/views/EventsView.d.ts +10 -0
  406. package/dist/types-react/ui/views/IntegrityView.d.ts +10 -0
  407. package/dist/types-react/ui/views/OverviewView.d.ts +9 -0
  408. package/dist/types-react/ui/views/StreamsView.d.ts +10 -0
  409. package/dist/types-react/ui/views/TenantsView.d.ts +6 -0
  410. package/dist/types-react/validation.d.ts +48 -0
  411. package/dist/ui/assets/favicon-BSj8MPnj.svg +11 -0
  412. package/dist/ui/assets/index-Cd-mcIwC.css +1 -0
  413. package/dist/ui/assets/index-DUAgpiot.js +244 -0
  414. package/dist/ui/index.html +15 -0
  415. package/dist/validation-DFrLESZD.mjs +150 -0
  416. package/dist/validation-DFrLESZD.mjs.map +1 -0
  417. package/dist/validation-lb0YXrxx.cjs +235 -0
  418. package/dist/validation-lb0YXrxx.cjs.map +1 -0
  419. package/dist/verify.cjs +14 -0
  420. package/dist/verify.d.cts +5 -0
  421. package/dist/verify.d.mts +5 -0
  422. package/dist/verify.mjs +3 -0
  423. package/package.json +610 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-storage-redis.cjs","names":[],"sources":["../src/storage/redis.ts"],"sourcesContent":["/**\n * Redis storage adapters built on the [`redis`](https://github.com/redis/node-redis)\n * package (node-redis v4/v5), an optional peer dependency. You can either pass a\n * pre-connected `client` or a `url` to connect lazily on first use. An optional\n * `prefix` is prepended (with a `:` separator) to every key so multiple\n * deployments can share a Redis instance without collisions; the prefix is\n * stripped from keys returned by {@link RedisAuditStorage.getKeys}.\n *\n * Two variants over the same plumbing, differing only in the value encoding:\n *\n * - {@link createRedisStorage} — values are plain **strings** containing JSON\n * (`SET`/`GET`). Works on any Redis; the default choice.\n * - {@link createRedisJSONStorage} — values are native **RedisJSON** documents\n * (`JSON.SET`/`JSON.GET`), so the stored data is queryable with JSONPath and\n * indexable with RediSearch. Requires the JSON module (Redis 8 / Redis Stack).\n * Do NOT point both variants at the same keys — the types are incompatible\n * (`WRONGTYPE`).\n *\n * `getKeys` uses a non-blocking `SCAN` cursor (never the blocking `KEYS`\n * command). `watch` is implemented with Redis keyspace notifications; it\n * requires the server to be configured with `notify-keyspace-events` covering\n * generic + string + expiry events (e.g. `KEA` — whose `A` class also covers the\n * module events that RedisJSON writes emit, e.g. `json.set`).\n *\n * ## Events and multi-writer safety (`compareAndSwap`)\n *\n * Events go through the core's generic KV event log (ADR 0005): one key per\n * event plus secondary index keys, queried by scanning the most selective\n * index. Both variants implement `compareAndSwap` with a small Lua script that\n * runs atomically on the server: it reads the current value, compares it with\n * the expected one **structurally** (both sides decoded with `cjson`, so key\n * order and number formatting do not matter; `JSON.GET` for the RedisJSON\n * variant), and writes the next value only on a match. The core CAS-es each\n * tenant's chain head before writing events, so several processes can append to\n * the same tenant safely — a loser re-reads the head and re-chains.\n *\n * @module\n */\n\nimport type { RedisClientType } from \"redis\";\nimport { requirePeer } from \"./contract.ts\";\nimport type {\n CompareAndSwapAuditStorage,\n StorageChangeEvent,\n WatchableAuditStorage,\n} from \"./contract.ts\";\n\n/** Options for {@link createRedisStorage}. */\nexport interface RedisStorageOptions {\n /** Connection URL (e.g. `redis://localhost:6379`). Used when no `client` is given. */\n url?: string;\n /** A pre-constructed (optionally pre-connected) node-redis client. */\n client?: RedisClientType;\n /** Optional key namespace prepended to every key, joined with `:`. */\n prefix?: string;\n /**\n * Called on client `error` events (connection drops, reconnect failures).\n * A handler is always attached internally so a downed Redis never crashes the\n * process via an unhandled `error` event — this just lets you observe/log them.\n */\n onError?: (error: unknown) => void;\n}\n\n/**\n * A {@link WatchableAuditStorage} + {@link CompareAndSwapAuditStorage} backed\n * by Redis, plus a `close()` method that disconnects the client — but only the\n * one this adapter created. A client you passed in is left for you to manage.\n */\nexport interface RedisAuditStorage extends WatchableAuditStorage, CompareAndSwapAuditStorage {\n /** Disconnect the underlying client if this adapter created it. No-op otherwise. */\n close(): Promise<void>;\n}\n\n/** Minimal structural view of the node-redis client surface this adapter uses. */\ninterface RedisLike {\n isOpen?: boolean;\n on?(event: string, listener: (...args: unknown[]) => void): unknown;\n connect(): Promise<unknown>;\n quit(): Promise<unknown>;\n get(key: string): Promise<string | null>;\n set(key: string, value: string): Promise<unknown>;\n del(key: string): Promise<unknown>;\n eval(script: string, options?: { keys?: string[]; arguments?: string[] }): Promise<unknown>;\n /** RedisJSON module commands (bundled in node-redis; the SERVER needs the module). */\n json?: {\n get(key: string): Promise<unknown>;\n set(key: string, path: string, value: unknown): Promise<unknown>;\n };\n scanIterator(options?: { MATCH?: string; COUNT?: number }): AsyncIterable<string | string[]>;\n duplicate(): RedisLike;\n pSubscribe(\n pattern: string,\n listener: (message: string, channel: string) => void,\n ): Promise<unknown>;\n disconnect(): Promise<unknown>;\n}\n\n/** How a variant reads/writes values (the only place the two adapters differ). */\ninterface RedisValueCodec {\n get(c: RedisLike, key: string): Promise<unknown>;\n set(c: RedisLike, key: string, value: unknown): Promise<void>;\n /** The Lua compare-and-swap script for this encoding (see {@link casScript}). */\n casScript: string;\n}\n\n/**\n * Build the compare-and-swap Lua script around a read and a write expression.\n * `KEYS[1]` is the key; `ARGV[1]` is `\"1\"` when the expected value is `null`\n * (key must be absent); `ARGV[2]` is the expected value as JSON; `ARGV[3]` is\n * the next value as JSON. Returns `1` when swapped, `0` otherwise. Values are\n * compared structurally (decoded with `cjson`), mirroring the memory driver's\n * deep equality.\n */\nfunction casScript(read: string, write: string): string {\n return `\nlocal function eq(a, b)\n if type(a) ~= type(b) then return false end\n if type(a) ~= 'table' then return a == b end\n for k, v in pairs(a) do\n if not eq(v, b[k]) then return false end\n end\n for k in pairs(b) do\n if a[k] == nil then return false end\n end\n return true\nend\nlocal current = ${read}\nif ARGV[1] == '1' then\n if current then return 0 end\nelse\n if not current then return 0 end\n if current ~= ARGV[2] and not eq(cjson.decode(current), cjson.decode(ARGV[2])) then\n return 0\n end\nend\n${write}\nreturn 1`;\n}\n\n/** Plain strings containing JSON — works on any Redis. */\nconst stringCodec: RedisValueCodec = {\n async get(c, key) {\n const raw = await c.get(key);\n return raw === null ? null : (JSON.parse(raw) as unknown);\n },\n async set(c, key, value) {\n await c.set(key, JSON.stringify(value));\n },\n casScript: casScript(\"redis.call('GET', KEYS[1])\", \"redis.call('SET', KEYS[1], ARGV[3])\"),\n};\n\n/** Native RedisJSON documents — requires the JSON module on the server. */\nconst jsonCodec: RedisValueCodec = {\n async get(c, key) {\n const value = await requireJson(c).get(key);\n return value ?? null;\n },\n async set(c, key, value) {\n await requireJson(c).set(key, \"$\", value);\n },\n casScript: casScript(\n \"redis.call('JSON.GET', KEYS[1])\",\n \"redis.call('JSON.SET', KEYS[1], '$', ARGV[3])\",\n ),\n};\n\nfunction requireJson(c: RedisLike): NonNullable<RedisLike[\"json\"]> {\n if (!c.json) {\n throw new Error(\n \"createRedisJSONStorage: the client exposes no `json` commands — use node-redis \" +\n \"(the `redis` package) v4+, and a server with the RedisJSON module (Redis 8 / Redis Stack).\",\n );\n }\n return c.json;\n}\n\n/**\n * Create a Redis-backed {@link RedisAuditStorage}. Connection is lazy: the\n * client is created/connected on the first storage operation and reused\n * thereafter, guarded by a single connection promise so concurrent calls connect\n * once.\n *\n * @example\n * ```ts\n * import { createRedisStorage } from \"@xtandard/audit/storage/redis\";\n *\n * const storage = createRedisStorage({\n * url: process.env.REDIS_URL ?? \"redis://localhost:6379\",\n * prefix: \"myapp:audit\",\n * onError: (err) => console.error(\"[audit/redis]\", err),\n * });\n *\n * // Disconnect when the process exits:\n * // process.on(\"SIGTERM\", () => storage.close());\n * ```\n */\nexport function createRedisStorage(options: RedisStorageOptions): RedisAuditStorage {\n return buildRedisStorage(options, stringCodec);\n}\n\n/**\n * Create a Redis-backed {@link RedisAuditStorage} that stores values as native\n * **RedisJSON** documents (`JSON.SET`/`JSON.GET`) instead of strings — making\n * the stored records queryable with JSONPath (`JSON.GET key $.action`) and\n * indexable with RediSearch, while the audit system behaves identically.\n *\n * Requires the JSON module on the server (built into Redis 8; Redis Stack; or\n * `redisjson` loaded). Same options and semantics as {@link createRedisStorage},\n * including lazy connection, `SCAN`-based `getKeys`, keyspace-notification\n * `watch`, and the Lua `compareAndSwap`. **Do not point it at keys written by\n * `createRedisStorage`** (or vice versa) — the underlying types differ and\n * Redis answers `WRONGTYPE`.\n *\n * @example\n * ```ts\n * import { createRedisJSONStorage } from \"@xtandard/audit/storage/redis\";\n *\n * const storage = createRedisJSONStorage({\n * url: process.env.REDIS_URL ?? \"redis://localhost:6379\",\n * prefix: \"myapp:audit\",\n * });\n * // Then, in redis-cli: JSON.GET myapp:audit:aud/t/acme/events/000000000001 $.action\n * ```\n */\nexport function createRedisJSONStorage(options: RedisStorageOptions): RedisAuditStorage {\n return buildRedisStorage(options, jsonCodec);\n}\n\n/** Shared implementation — connection, prefixing, SCAN, CAS, watch, close. */\nfunction buildRedisStorage(\n options: RedisStorageOptions,\n codec: RedisValueCodec,\n): RedisAuditStorage {\n const { url, prefix } = options;\n const fullPrefix = prefix ? `${prefix}:` : \"\";\n const ownsClient = !options.client;\n\n let client: RedisLike | undefined = options.client as RedisLike | undefined;\n let connecting: Promise<RedisLike> | undefined;\n\n // node-redis emits `error` on connection drops and reconnect attempts. Without a\n // listener Node treats it as an unhandled error and crashes the process — which\n // would defeat the whole \"storage can be down\" promise. Always attach one.\n const attachErrorHandler = (c: RedisLike): void => {\n c.on?.(\"error\", (err: unknown) => options.onError?.(err));\n };\n if (client) attachErrorHandler(client);\n\n /** Resolve a connected client, creating/connecting on first use. */\n async function getClient(): Promise<RedisLike> {\n if (client?.isOpen) return client;\n connecting ??= (async () => {\n if (!client) {\n let createClient: (opts: Record<string, unknown>) => RedisLike;\n try {\n ({ createClient } = (await import(\"redis\")) as unknown as {\n createClient: (opts: Record<string, unknown>) => RedisLike;\n });\n } catch {\n requirePeer(\"redis\", \"storage/redis\");\n }\n // disableOfflineQueue: commands reject immediately when the socket is down\n // (instead of queueing forever) so a record fails fast (and the recorder's\n // buffer takes over). The reconnect strategy keeps trying with a capped\n // backoff so it recovers automatically.\n client = createClient({\n url,\n disableOfflineQueue: true,\n socket: { reconnectStrategy: (retries: number) => Math.min(retries * 100, 3000) },\n });\n attachErrorHandler(client);\n }\n if (!client.isOpen) await client.connect();\n return client;\n })();\n try {\n return await connecting;\n } finally {\n connecting = undefined;\n }\n }\n\n /** Prepend the namespace to a caller key. */\n const toRedisKey = (key: string): string => `${fullPrefix}${key}`;\n /** Strip the namespace off a Redis key, yielding the caller key. */\n const fromRedisKey = (key: string): string =>\n fullPrefix && key.startsWith(fullPrefix) ? key.slice(fullPrefix.length) : key;\n\n return {\n async getItem<T>(key: string): Promise<T | null> {\n const c = await getClient();\n return ((await codec.get(c, toRedisKey(key))) as T | null) ?? null;\n },\n\n async setItem<T>(key: string, value: T): Promise<void> {\n const c = await getClient();\n await codec.set(c, toRedisKey(key), value);\n },\n\n async removeItem(key: string): Promise<void> {\n const c = await getClient();\n await c.del(toRedisKey(key));\n },\n\n async getKeys(prefix: string): Promise<string[]> {\n const c = await getClient();\n const match = `${escapeGlob(toRedisKey(prefix))}*`;\n const out: string[] = [];\n for await (const entry of c.scanIterator({ MATCH: match, COUNT: 100 })) {\n // node-redis v4 yields one key per iteration; v5 may yield batches.\n if (Array.isArray(entry)) {\n for (const k of entry) out.push(fromRedisKey(k));\n } else {\n out.push(fromRedisKey(entry));\n }\n }\n // Belt and braces on top of the escaped MATCH glob: exact string-prefix semantics.\n return out.filter((key) => key.startsWith(prefix));\n },\n\n async compareAndSwap<T>(input: { key: string; expected: T | null; next: T }): Promise<boolean> {\n const c = await getClient();\n const swapped = await c.eval(codec.casScript, {\n keys: [toRedisKey(input.key)],\n arguments: [\n input.expected === null ? \"1\" : \"0\",\n input.expected === null ? \"\" : JSON.stringify(input.expected),\n JSON.stringify(input.next),\n ],\n });\n return Number(swapped) === 1;\n },\n\n async watch(\n prefix: string,\n callback: (event: StorageChangeEvent) => void,\n ): Promise<() => void> {\n // Keyspace notifications publish to `__keyspace@<db>__:<key>`; subscribe to\n // all key events under our namespaced prefix and translate them.\n const c = await getClient();\n const subscriber = c.duplicate();\n attachErrorHandler(subscriber);\n await subscriber.connect();\n const pattern = `__keyspace@*__:${escapeGlob(toRedisKey(prefix))}*`;\n await subscriber.pSubscribe(pattern, (event: string, channel: string) => {\n const idx = channel.indexOf(\"__:\");\n if (idx === -1) return;\n const redisKey = channel.slice(idx + 3);\n const key = fromRedisKey(redisKey);\n if (!key.startsWith(prefix)) return;\n const type: StorageChangeEvent[\"type\"] =\n event === \"del\" || event === \"expired\" ? \"remove\" : \"update\";\n callback({ type, key });\n });\n return () => {\n void subscriber.disconnect();\n };\n },\n\n async close(): Promise<void> {\n if (ownsClient && client?.isOpen) await client.quit();\n },\n } satisfies RedisAuditStorage;\n}\n\n/**\n * Escape Redis glob metacharacters (`*`, `?`, `[`, `]`, `\\`) so a literal key\n * prefix can be used in `SCAN MATCH` / `PSUBSCRIBE` patterns.\n */\nfunction escapeGlob(input: string): string {\n return input.replace(/[*?[\\]\\\\]/g, \"\\\\$&\");\n}\n"],"mappings":"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"}
@@ -0,0 +1,77 @@
1
+ import { r as CompareAndSwapAuditStorage, s as WatchableAuditStorage } from "./contract-CWJSYoJl.cjs";
2
+ import { RedisClientType } from "redis";
3
+
4
+ //#region src/storage/redis.d.ts
5
+ /** Options for {@link createRedisStorage}. */
6
+ interface RedisStorageOptions {
7
+ /** Connection URL (e.g. `redis://localhost:6379`). Used when no `client` is given. */
8
+ url?: string;
9
+ /** A pre-constructed (optionally pre-connected) node-redis client. */
10
+ client?: RedisClientType;
11
+ /** Optional key namespace prepended to every key, joined with `:`. */
12
+ prefix?: string;
13
+ /**
14
+ * Called on client `error` events (connection drops, reconnect failures).
15
+ * A handler is always attached internally so a downed Redis never crashes the
16
+ * process via an unhandled `error` event — this just lets you observe/log them.
17
+ */
18
+ onError?: (error: unknown) => void;
19
+ }
20
+ /**
21
+ * A {@link WatchableAuditStorage} + {@link CompareAndSwapAuditStorage} backed
22
+ * by Redis, plus a `close()` method that disconnects the client — but only the
23
+ * one this adapter created. A client you passed in is left for you to manage.
24
+ */
25
+ interface RedisAuditStorage extends WatchableAuditStorage, CompareAndSwapAuditStorage {
26
+ /** Disconnect the underlying client if this adapter created it. No-op otherwise. */
27
+ close(): Promise<void>;
28
+ }
29
+ /**
30
+ * Create a Redis-backed {@link RedisAuditStorage}. Connection is lazy: the
31
+ * client is created/connected on the first storage operation and reused
32
+ * thereafter, guarded by a single connection promise so concurrent calls connect
33
+ * once.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import { createRedisStorage } from "@xtandard/audit/storage/redis";
38
+ *
39
+ * const storage = createRedisStorage({
40
+ * url: process.env.REDIS_URL ?? "redis://localhost:6379",
41
+ * prefix: "myapp:audit",
42
+ * onError: (err) => console.error("[audit/redis]", err),
43
+ * });
44
+ *
45
+ * // Disconnect when the process exits:
46
+ * // process.on("SIGTERM", () => storage.close());
47
+ * ```
48
+ */
49
+ declare function createRedisStorage(options: RedisStorageOptions): RedisAuditStorage;
50
+ /**
51
+ * Create a Redis-backed {@link RedisAuditStorage} that stores values as native
52
+ * **RedisJSON** documents (`JSON.SET`/`JSON.GET`) instead of strings — making
53
+ * the stored records queryable with JSONPath (`JSON.GET key $.action`) and
54
+ * indexable with RediSearch, while the audit system behaves identically.
55
+ *
56
+ * Requires the JSON module on the server (built into Redis 8; Redis Stack; or
57
+ * `redisjson` loaded). Same options and semantics as {@link createRedisStorage},
58
+ * including lazy connection, `SCAN`-based `getKeys`, keyspace-notification
59
+ * `watch`, and the Lua `compareAndSwap`. **Do not point it at keys written by
60
+ * `createRedisStorage`** (or vice versa) — the underlying types differ and
61
+ * Redis answers `WRONGTYPE`.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * import { createRedisJSONStorage } from "@xtandard/audit/storage/redis";
66
+ *
67
+ * const storage = createRedisJSONStorage({
68
+ * url: process.env.REDIS_URL ?? "redis://localhost:6379",
69
+ * prefix: "myapp:audit",
70
+ * });
71
+ * // Then, in redis-cli: JSON.GET myapp:audit:aud/t/acme/events/000000000001 $.action
72
+ * ```
73
+ */
74
+ declare function createRedisJSONStorage(options: RedisStorageOptions): RedisAuditStorage;
75
+ //#endregion
76
+ export { RedisAuditStorage, RedisStorageOptions, createRedisJSONStorage, createRedisStorage };
77
+ //# sourceMappingURL=entry-storage-redis.d.cts.map
@@ -0,0 +1,77 @@
1
+ import { r as CompareAndSwapAuditStorage, s as WatchableAuditStorage } from "./contract-BmwHIiMR.mjs";
2
+ import { RedisClientType } from "redis";
3
+
4
+ //#region src/storage/redis.d.ts
5
+ /** Options for {@link createRedisStorage}. */
6
+ interface RedisStorageOptions {
7
+ /** Connection URL (e.g. `redis://localhost:6379`). Used when no `client` is given. */
8
+ url?: string;
9
+ /** A pre-constructed (optionally pre-connected) node-redis client. */
10
+ client?: RedisClientType;
11
+ /** Optional key namespace prepended to every key, joined with `:`. */
12
+ prefix?: string;
13
+ /**
14
+ * Called on client `error` events (connection drops, reconnect failures).
15
+ * A handler is always attached internally so a downed Redis never crashes the
16
+ * process via an unhandled `error` event — this just lets you observe/log them.
17
+ */
18
+ onError?: (error: unknown) => void;
19
+ }
20
+ /**
21
+ * A {@link WatchableAuditStorage} + {@link CompareAndSwapAuditStorage} backed
22
+ * by Redis, plus a `close()` method that disconnects the client — but only the
23
+ * one this adapter created. A client you passed in is left for you to manage.
24
+ */
25
+ interface RedisAuditStorage extends WatchableAuditStorage, CompareAndSwapAuditStorage {
26
+ /** Disconnect the underlying client if this adapter created it. No-op otherwise. */
27
+ close(): Promise<void>;
28
+ }
29
+ /**
30
+ * Create a Redis-backed {@link RedisAuditStorage}. Connection is lazy: the
31
+ * client is created/connected on the first storage operation and reused
32
+ * thereafter, guarded by a single connection promise so concurrent calls connect
33
+ * once.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import { createRedisStorage } from "@xtandard/audit/storage/redis";
38
+ *
39
+ * const storage = createRedisStorage({
40
+ * url: process.env.REDIS_URL ?? "redis://localhost:6379",
41
+ * prefix: "myapp:audit",
42
+ * onError: (err) => console.error("[audit/redis]", err),
43
+ * });
44
+ *
45
+ * // Disconnect when the process exits:
46
+ * // process.on("SIGTERM", () => storage.close());
47
+ * ```
48
+ */
49
+ declare function createRedisStorage(options: RedisStorageOptions): RedisAuditStorage;
50
+ /**
51
+ * Create a Redis-backed {@link RedisAuditStorage} that stores values as native
52
+ * **RedisJSON** documents (`JSON.SET`/`JSON.GET`) instead of strings — making
53
+ * the stored records queryable with JSONPath (`JSON.GET key $.action`) and
54
+ * indexable with RediSearch, while the audit system behaves identically.
55
+ *
56
+ * Requires the JSON module on the server (built into Redis 8; Redis Stack; or
57
+ * `redisjson` loaded). Same options and semantics as {@link createRedisStorage},
58
+ * including lazy connection, `SCAN`-based `getKeys`, keyspace-notification
59
+ * `watch`, and the Lua `compareAndSwap`. **Do not point it at keys written by
60
+ * `createRedisStorage`** (or vice versa) — the underlying types differ and
61
+ * Redis answers `WRONGTYPE`.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * import { createRedisJSONStorage } from "@xtandard/audit/storage/redis";
66
+ *
67
+ * const storage = createRedisJSONStorage({
68
+ * url: process.env.REDIS_URL ?? "redis://localhost:6379",
69
+ * prefix: "myapp:audit",
70
+ * });
71
+ * // Then, in redis-cli: JSON.GET myapp:audit:aud/t/acme/events/000000000001 $.action
72
+ * ```
73
+ */
74
+ declare function createRedisJSONStorage(options: RedisStorageOptions): RedisAuditStorage;
75
+ //#endregion
76
+ export { RedisAuditStorage, RedisStorageOptions, createRedisJSONStorage, createRedisStorage };
77
+ //# sourceMappingURL=entry-storage-redis.d.mts.map
@@ -0,0 +1,221 @@
1
+ import { o as requirePeer } from "./contract-isM9SjjQ.mjs";
2
+ //#region src/storage/redis.ts
3
+ /**
4
+ * Build the compare-and-swap Lua script around a read and a write expression.
5
+ * `KEYS[1]` is the key; `ARGV[1]` is `"1"` when the expected value is `null`
6
+ * (key must be absent); `ARGV[2]` is the expected value as JSON; `ARGV[3]` is
7
+ * the next value as JSON. Returns `1` when swapped, `0` otherwise. Values are
8
+ * compared structurally (decoded with `cjson`), mirroring the memory driver's
9
+ * deep equality.
10
+ */
11
+ function casScript(read, write) {
12
+ return `
13
+ local function eq(a, b)
14
+ if type(a) ~= type(b) then return false end
15
+ if type(a) ~= 'table' then return a == b end
16
+ for k, v in pairs(a) do
17
+ if not eq(v, b[k]) then return false end
18
+ end
19
+ for k in pairs(b) do
20
+ if a[k] == nil then return false end
21
+ end
22
+ return true
23
+ end
24
+ local current = ${read}
25
+ if ARGV[1] == '1' then
26
+ if current then return 0 end
27
+ else
28
+ if not current then return 0 end
29
+ if current ~= ARGV[2] and not eq(cjson.decode(current), cjson.decode(ARGV[2])) then
30
+ return 0
31
+ end
32
+ end
33
+ ${write}
34
+ return 1`;
35
+ }
36
+ /** Plain strings containing JSON — works on any Redis. */
37
+ const stringCodec = {
38
+ async get(c, key) {
39
+ const raw = await c.get(key);
40
+ return raw === null ? null : JSON.parse(raw);
41
+ },
42
+ async set(c, key, value) {
43
+ await c.set(key, JSON.stringify(value));
44
+ },
45
+ casScript: casScript("redis.call('GET', KEYS[1])", "redis.call('SET', KEYS[1], ARGV[3])")
46
+ };
47
+ /** Native RedisJSON documents — requires the JSON module on the server. */
48
+ const jsonCodec = {
49
+ async get(c, key) {
50
+ return await requireJson(c).get(key) ?? null;
51
+ },
52
+ async set(c, key, value) {
53
+ await requireJson(c).set(key, "$", value);
54
+ },
55
+ casScript: casScript("redis.call('JSON.GET', KEYS[1])", "redis.call('JSON.SET', KEYS[1], '$', ARGV[3])")
56
+ };
57
+ function requireJson(c) {
58
+ if (!c.json) throw new Error("createRedisJSONStorage: the client exposes no `json` commands — use node-redis (the `redis` package) v4+, and a server with the RedisJSON module (Redis 8 / Redis Stack).");
59
+ return c.json;
60
+ }
61
+ /**
62
+ * Create a Redis-backed {@link RedisAuditStorage}. Connection is lazy: the
63
+ * client is created/connected on the first storage operation and reused
64
+ * thereafter, guarded by a single connection promise so concurrent calls connect
65
+ * once.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * import { createRedisStorage } from "@xtandard/audit/storage/redis";
70
+ *
71
+ * const storage = createRedisStorage({
72
+ * url: process.env.REDIS_URL ?? "redis://localhost:6379",
73
+ * prefix: "myapp:audit",
74
+ * onError: (err) => console.error("[audit/redis]", err),
75
+ * });
76
+ *
77
+ * // Disconnect when the process exits:
78
+ * // process.on("SIGTERM", () => storage.close());
79
+ * ```
80
+ */
81
+ function createRedisStorage(options) {
82
+ return buildRedisStorage(options, stringCodec);
83
+ }
84
+ /**
85
+ * Create a Redis-backed {@link RedisAuditStorage} that stores values as native
86
+ * **RedisJSON** documents (`JSON.SET`/`JSON.GET`) instead of strings — making
87
+ * the stored records queryable with JSONPath (`JSON.GET key $.action`) and
88
+ * indexable with RediSearch, while the audit system behaves identically.
89
+ *
90
+ * Requires the JSON module on the server (built into Redis 8; Redis Stack; or
91
+ * `redisjson` loaded). Same options and semantics as {@link createRedisStorage},
92
+ * including lazy connection, `SCAN`-based `getKeys`, keyspace-notification
93
+ * `watch`, and the Lua `compareAndSwap`. **Do not point it at keys written by
94
+ * `createRedisStorage`** (or vice versa) — the underlying types differ and
95
+ * Redis answers `WRONGTYPE`.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * import { createRedisJSONStorage } from "@xtandard/audit/storage/redis";
100
+ *
101
+ * const storage = createRedisJSONStorage({
102
+ * url: process.env.REDIS_URL ?? "redis://localhost:6379",
103
+ * prefix: "myapp:audit",
104
+ * });
105
+ * // Then, in redis-cli: JSON.GET myapp:audit:aud/t/acme/events/000000000001 $.action
106
+ * ```
107
+ */
108
+ function createRedisJSONStorage(options) {
109
+ return buildRedisStorage(options, jsonCodec);
110
+ }
111
+ /** Shared implementation — connection, prefixing, SCAN, CAS, watch, close. */
112
+ function buildRedisStorage(options, codec) {
113
+ const { url, prefix } = options;
114
+ const fullPrefix = prefix ? `${prefix}:` : "";
115
+ const ownsClient = !options.client;
116
+ let client = options.client;
117
+ let connecting;
118
+ const attachErrorHandler = (c) => {
119
+ c.on?.("error", (err) => options.onError?.(err));
120
+ };
121
+ if (client) attachErrorHandler(client);
122
+ /** Resolve a connected client, creating/connecting on first use. */
123
+ async function getClient() {
124
+ if (client?.isOpen) return client;
125
+ connecting ??= (async () => {
126
+ if (!client) {
127
+ let createClient;
128
+ try {
129
+ ({createClient} = await import("redis"));
130
+ } catch {
131
+ requirePeer("redis", "storage/redis");
132
+ }
133
+ client = createClient({
134
+ url,
135
+ disableOfflineQueue: true,
136
+ socket: { reconnectStrategy: (retries) => Math.min(retries * 100, 3e3) }
137
+ });
138
+ attachErrorHandler(client);
139
+ }
140
+ if (!client.isOpen) await client.connect();
141
+ return client;
142
+ })();
143
+ try {
144
+ return await connecting;
145
+ } finally {
146
+ connecting = void 0;
147
+ }
148
+ }
149
+ /** Prepend the namespace to a caller key. */
150
+ const toRedisKey = (key) => `${fullPrefix}${key}`;
151
+ /** Strip the namespace off a Redis key, yielding the caller key. */
152
+ const fromRedisKey = (key) => fullPrefix && key.startsWith(fullPrefix) ? key.slice(fullPrefix.length) : key;
153
+ return {
154
+ async getItem(key) {
155
+ const c = await getClient();
156
+ return await codec.get(c, toRedisKey(key)) ?? null;
157
+ },
158
+ async setItem(key, value) {
159
+ const c = await getClient();
160
+ await codec.set(c, toRedisKey(key), value);
161
+ },
162
+ async removeItem(key) {
163
+ await (await getClient()).del(toRedisKey(key));
164
+ },
165
+ async getKeys(prefix) {
166
+ const c = await getClient();
167
+ const match = `${escapeGlob(toRedisKey(prefix))}*`;
168
+ const out = [];
169
+ for await (const entry of c.scanIterator({
170
+ MATCH: match,
171
+ COUNT: 100
172
+ })) if (Array.isArray(entry)) for (const k of entry) out.push(fromRedisKey(k));
173
+ else out.push(fromRedisKey(entry));
174
+ return out.filter((key) => key.startsWith(prefix));
175
+ },
176
+ async compareAndSwap(input) {
177
+ const swapped = await (await getClient()).eval(codec.casScript, {
178
+ keys: [toRedisKey(input.key)],
179
+ arguments: [
180
+ input.expected === null ? "1" : "0",
181
+ input.expected === null ? "" : JSON.stringify(input.expected),
182
+ JSON.stringify(input.next)
183
+ ]
184
+ });
185
+ return Number(swapped) === 1;
186
+ },
187
+ async watch(prefix, callback) {
188
+ const subscriber = (await getClient()).duplicate();
189
+ attachErrorHandler(subscriber);
190
+ await subscriber.connect();
191
+ const pattern = `__keyspace@*__:${escapeGlob(toRedisKey(prefix))}*`;
192
+ await subscriber.pSubscribe(pattern, (event, channel) => {
193
+ const idx = channel.indexOf("__:");
194
+ if (idx === -1) return;
195
+ const key = fromRedisKey(channel.slice(idx + 3));
196
+ if (!key.startsWith(prefix)) return;
197
+ callback({
198
+ type: event === "del" || event === "expired" ? "remove" : "update",
199
+ key
200
+ });
201
+ });
202
+ return () => {
203
+ subscriber.disconnect();
204
+ };
205
+ },
206
+ async close() {
207
+ if (ownsClient && client?.isOpen) await client.quit();
208
+ }
209
+ };
210
+ }
211
+ /**
212
+ * Escape Redis glob metacharacters (`*`, `?`, `[`, `]`, `\`) so a literal key
213
+ * prefix can be used in `SCAN MATCH` / `PSUBSCRIBE` patterns.
214
+ */
215
+ function escapeGlob(input) {
216
+ return input.replace(/[*?[\]\\]/g, "\\$&");
217
+ }
218
+ //#endregion
219
+ export { createRedisJSONStorage, createRedisStorage };
220
+
221
+ //# sourceMappingURL=entry-storage-redis.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-storage-redis.mjs","names":[],"sources":["../src/storage/redis.ts"],"sourcesContent":["/**\n * Redis storage adapters built on the [`redis`](https://github.com/redis/node-redis)\n * package (node-redis v4/v5), an optional peer dependency. You can either pass a\n * pre-connected `client` or a `url` to connect lazily on first use. An optional\n * `prefix` is prepended (with a `:` separator) to every key so multiple\n * deployments can share a Redis instance without collisions; the prefix is\n * stripped from keys returned by {@link RedisAuditStorage.getKeys}.\n *\n * Two variants over the same plumbing, differing only in the value encoding:\n *\n * - {@link createRedisStorage} — values are plain **strings** containing JSON\n * (`SET`/`GET`). Works on any Redis; the default choice.\n * - {@link createRedisJSONStorage} — values are native **RedisJSON** documents\n * (`JSON.SET`/`JSON.GET`), so the stored data is queryable with JSONPath and\n * indexable with RediSearch. Requires the JSON module (Redis 8 / Redis Stack).\n * Do NOT point both variants at the same keys — the types are incompatible\n * (`WRONGTYPE`).\n *\n * `getKeys` uses a non-blocking `SCAN` cursor (never the blocking `KEYS`\n * command). `watch` is implemented with Redis keyspace notifications; it\n * requires the server to be configured with `notify-keyspace-events` covering\n * generic + string + expiry events (e.g. `KEA` — whose `A` class also covers the\n * module events that RedisJSON writes emit, e.g. `json.set`).\n *\n * ## Events and multi-writer safety (`compareAndSwap`)\n *\n * Events go through the core's generic KV event log (ADR 0005): one key per\n * event plus secondary index keys, queried by scanning the most selective\n * index. Both variants implement `compareAndSwap` with a small Lua script that\n * runs atomically on the server: it reads the current value, compares it with\n * the expected one **structurally** (both sides decoded with `cjson`, so key\n * order and number formatting do not matter; `JSON.GET` for the RedisJSON\n * variant), and writes the next value only on a match. The core CAS-es each\n * tenant's chain head before writing events, so several processes can append to\n * the same tenant safely — a loser re-reads the head and re-chains.\n *\n * @module\n */\n\nimport type { RedisClientType } from \"redis\";\nimport { requirePeer } from \"./contract.ts\";\nimport type {\n CompareAndSwapAuditStorage,\n StorageChangeEvent,\n WatchableAuditStorage,\n} from \"./contract.ts\";\n\n/** Options for {@link createRedisStorage}. */\nexport interface RedisStorageOptions {\n /** Connection URL (e.g. `redis://localhost:6379`). Used when no `client` is given. */\n url?: string;\n /** A pre-constructed (optionally pre-connected) node-redis client. */\n client?: RedisClientType;\n /** Optional key namespace prepended to every key, joined with `:`. */\n prefix?: string;\n /**\n * Called on client `error` events (connection drops, reconnect failures).\n * A handler is always attached internally so a downed Redis never crashes the\n * process via an unhandled `error` event — this just lets you observe/log them.\n */\n onError?: (error: unknown) => void;\n}\n\n/**\n * A {@link WatchableAuditStorage} + {@link CompareAndSwapAuditStorage} backed\n * by Redis, plus a `close()` method that disconnects the client — but only the\n * one this adapter created. A client you passed in is left for you to manage.\n */\nexport interface RedisAuditStorage extends WatchableAuditStorage, CompareAndSwapAuditStorage {\n /** Disconnect the underlying client if this adapter created it. No-op otherwise. */\n close(): Promise<void>;\n}\n\n/** Minimal structural view of the node-redis client surface this adapter uses. */\ninterface RedisLike {\n isOpen?: boolean;\n on?(event: string, listener: (...args: unknown[]) => void): unknown;\n connect(): Promise<unknown>;\n quit(): Promise<unknown>;\n get(key: string): Promise<string | null>;\n set(key: string, value: string): Promise<unknown>;\n del(key: string): Promise<unknown>;\n eval(script: string, options?: { keys?: string[]; arguments?: string[] }): Promise<unknown>;\n /** RedisJSON module commands (bundled in node-redis; the SERVER needs the module). */\n json?: {\n get(key: string): Promise<unknown>;\n set(key: string, path: string, value: unknown): Promise<unknown>;\n };\n scanIterator(options?: { MATCH?: string; COUNT?: number }): AsyncIterable<string | string[]>;\n duplicate(): RedisLike;\n pSubscribe(\n pattern: string,\n listener: (message: string, channel: string) => void,\n ): Promise<unknown>;\n disconnect(): Promise<unknown>;\n}\n\n/** How a variant reads/writes values (the only place the two adapters differ). */\ninterface RedisValueCodec {\n get(c: RedisLike, key: string): Promise<unknown>;\n set(c: RedisLike, key: string, value: unknown): Promise<void>;\n /** The Lua compare-and-swap script for this encoding (see {@link casScript}). */\n casScript: string;\n}\n\n/**\n * Build the compare-and-swap Lua script around a read and a write expression.\n * `KEYS[1]` is the key; `ARGV[1]` is `\"1\"` when the expected value is `null`\n * (key must be absent); `ARGV[2]` is the expected value as JSON; `ARGV[3]` is\n * the next value as JSON. Returns `1` when swapped, `0` otherwise. Values are\n * compared structurally (decoded with `cjson`), mirroring the memory driver's\n * deep equality.\n */\nfunction casScript(read: string, write: string): string {\n return `\nlocal function eq(a, b)\n if type(a) ~= type(b) then return false end\n if type(a) ~= 'table' then return a == b end\n for k, v in pairs(a) do\n if not eq(v, b[k]) then return false end\n end\n for k in pairs(b) do\n if a[k] == nil then return false end\n end\n return true\nend\nlocal current = ${read}\nif ARGV[1] == '1' then\n if current then return 0 end\nelse\n if not current then return 0 end\n if current ~= ARGV[2] and not eq(cjson.decode(current), cjson.decode(ARGV[2])) then\n return 0\n end\nend\n${write}\nreturn 1`;\n}\n\n/** Plain strings containing JSON — works on any Redis. */\nconst stringCodec: RedisValueCodec = {\n async get(c, key) {\n const raw = await c.get(key);\n return raw === null ? null : (JSON.parse(raw) as unknown);\n },\n async set(c, key, value) {\n await c.set(key, JSON.stringify(value));\n },\n casScript: casScript(\"redis.call('GET', KEYS[1])\", \"redis.call('SET', KEYS[1], ARGV[3])\"),\n};\n\n/** Native RedisJSON documents — requires the JSON module on the server. */\nconst jsonCodec: RedisValueCodec = {\n async get(c, key) {\n const value = await requireJson(c).get(key);\n return value ?? null;\n },\n async set(c, key, value) {\n await requireJson(c).set(key, \"$\", value);\n },\n casScript: casScript(\n \"redis.call('JSON.GET', KEYS[1])\",\n \"redis.call('JSON.SET', KEYS[1], '$', ARGV[3])\",\n ),\n};\n\nfunction requireJson(c: RedisLike): NonNullable<RedisLike[\"json\"]> {\n if (!c.json) {\n throw new Error(\n \"createRedisJSONStorage: the client exposes no `json` commands — use node-redis \" +\n \"(the `redis` package) v4+, and a server with the RedisJSON module (Redis 8 / Redis Stack).\",\n );\n }\n return c.json;\n}\n\n/**\n * Create a Redis-backed {@link RedisAuditStorage}. Connection is lazy: the\n * client is created/connected on the first storage operation and reused\n * thereafter, guarded by a single connection promise so concurrent calls connect\n * once.\n *\n * @example\n * ```ts\n * import { createRedisStorage } from \"@xtandard/audit/storage/redis\";\n *\n * const storage = createRedisStorage({\n * url: process.env.REDIS_URL ?? \"redis://localhost:6379\",\n * prefix: \"myapp:audit\",\n * onError: (err) => console.error(\"[audit/redis]\", err),\n * });\n *\n * // Disconnect when the process exits:\n * // process.on(\"SIGTERM\", () => storage.close());\n * ```\n */\nexport function createRedisStorage(options: RedisStorageOptions): RedisAuditStorage {\n return buildRedisStorage(options, stringCodec);\n}\n\n/**\n * Create a Redis-backed {@link RedisAuditStorage} that stores values as native\n * **RedisJSON** documents (`JSON.SET`/`JSON.GET`) instead of strings — making\n * the stored records queryable with JSONPath (`JSON.GET key $.action`) and\n * indexable with RediSearch, while the audit system behaves identically.\n *\n * Requires the JSON module on the server (built into Redis 8; Redis Stack; or\n * `redisjson` loaded). Same options and semantics as {@link createRedisStorage},\n * including lazy connection, `SCAN`-based `getKeys`, keyspace-notification\n * `watch`, and the Lua `compareAndSwap`. **Do not point it at keys written by\n * `createRedisStorage`** (or vice versa) — the underlying types differ and\n * Redis answers `WRONGTYPE`.\n *\n * @example\n * ```ts\n * import { createRedisJSONStorage } from \"@xtandard/audit/storage/redis\";\n *\n * const storage = createRedisJSONStorage({\n * url: process.env.REDIS_URL ?? \"redis://localhost:6379\",\n * prefix: \"myapp:audit\",\n * });\n * // Then, in redis-cli: JSON.GET myapp:audit:aud/t/acme/events/000000000001 $.action\n * ```\n */\nexport function createRedisJSONStorage(options: RedisStorageOptions): RedisAuditStorage {\n return buildRedisStorage(options, jsonCodec);\n}\n\n/** Shared implementation — connection, prefixing, SCAN, CAS, watch, close. */\nfunction buildRedisStorage(\n options: RedisStorageOptions,\n codec: RedisValueCodec,\n): RedisAuditStorage {\n const { url, prefix } = options;\n const fullPrefix = prefix ? `${prefix}:` : \"\";\n const ownsClient = !options.client;\n\n let client: RedisLike | undefined = options.client as RedisLike | undefined;\n let connecting: Promise<RedisLike> | undefined;\n\n // node-redis emits `error` on connection drops and reconnect attempts. Without a\n // listener Node treats it as an unhandled error and crashes the process — which\n // would defeat the whole \"storage can be down\" promise. Always attach one.\n const attachErrorHandler = (c: RedisLike): void => {\n c.on?.(\"error\", (err: unknown) => options.onError?.(err));\n };\n if (client) attachErrorHandler(client);\n\n /** Resolve a connected client, creating/connecting on first use. */\n async function getClient(): Promise<RedisLike> {\n if (client?.isOpen) return client;\n connecting ??= (async () => {\n if (!client) {\n let createClient: (opts: Record<string, unknown>) => RedisLike;\n try {\n ({ createClient } = (await import(\"redis\")) as unknown as {\n createClient: (opts: Record<string, unknown>) => RedisLike;\n });\n } catch {\n requirePeer(\"redis\", \"storage/redis\");\n }\n // disableOfflineQueue: commands reject immediately when the socket is down\n // (instead of queueing forever) so a record fails fast (and the recorder's\n // buffer takes over). The reconnect strategy keeps trying with a capped\n // backoff so it recovers automatically.\n client = createClient({\n url,\n disableOfflineQueue: true,\n socket: { reconnectStrategy: (retries: number) => Math.min(retries * 100, 3000) },\n });\n attachErrorHandler(client);\n }\n if (!client.isOpen) await client.connect();\n return client;\n })();\n try {\n return await connecting;\n } finally {\n connecting = undefined;\n }\n }\n\n /** Prepend the namespace to a caller key. */\n const toRedisKey = (key: string): string => `${fullPrefix}${key}`;\n /** Strip the namespace off a Redis key, yielding the caller key. */\n const fromRedisKey = (key: string): string =>\n fullPrefix && key.startsWith(fullPrefix) ? key.slice(fullPrefix.length) : key;\n\n return {\n async getItem<T>(key: string): Promise<T | null> {\n const c = await getClient();\n return ((await codec.get(c, toRedisKey(key))) as T | null) ?? null;\n },\n\n async setItem<T>(key: string, value: T): Promise<void> {\n const c = await getClient();\n await codec.set(c, toRedisKey(key), value);\n },\n\n async removeItem(key: string): Promise<void> {\n const c = await getClient();\n await c.del(toRedisKey(key));\n },\n\n async getKeys(prefix: string): Promise<string[]> {\n const c = await getClient();\n const match = `${escapeGlob(toRedisKey(prefix))}*`;\n const out: string[] = [];\n for await (const entry of c.scanIterator({ MATCH: match, COUNT: 100 })) {\n // node-redis v4 yields one key per iteration; v5 may yield batches.\n if (Array.isArray(entry)) {\n for (const k of entry) out.push(fromRedisKey(k));\n } else {\n out.push(fromRedisKey(entry));\n }\n }\n // Belt and braces on top of the escaped MATCH glob: exact string-prefix semantics.\n return out.filter((key) => key.startsWith(prefix));\n },\n\n async compareAndSwap<T>(input: { key: string; expected: T | null; next: T }): Promise<boolean> {\n const c = await getClient();\n const swapped = await c.eval(codec.casScript, {\n keys: [toRedisKey(input.key)],\n arguments: [\n input.expected === null ? \"1\" : \"0\",\n input.expected === null ? \"\" : JSON.stringify(input.expected),\n JSON.stringify(input.next),\n ],\n });\n return Number(swapped) === 1;\n },\n\n async watch(\n prefix: string,\n callback: (event: StorageChangeEvent) => void,\n ): Promise<() => void> {\n // Keyspace notifications publish to `__keyspace@<db>__:<key>`; subscribe to\n // all key events under our namespaced prefix and translate them.\n const c = await getClient();\n const subscriber = c.duplicate();\n attachErrorHandler(subscriber);\n await subscriber.connect();\n const pattern = `__keyspace@*__:${escapeGlob(toRedisKey(prefix))}*`;\n await subscriber.pSubscribe(pattern, (event: string, channel: string) => {\n const idx = channel.indexOf(\"__:\");\n if (idx === -1) return;\n const redisKey = channel.slice(idx + 3);\n const key = fromRedisKey(redisKey);\n if (!key.startsWith(prefix)) return;\n const type: StorageChangeEvent[\"type\"] =\n event === \"del\" || event === \"expired\" ? \"remove\" : \"update\";\n callback({ type, key });\n });\n return () => {\n void subscriber.disconnect();\n };\n },\n\n async close(): Promise<void> {\n if (ownsClient && client?.isOpen) await client.quit();\n },\n } satisfies RedisAuditStorage;\n}\n\n/**\n * Escape Redis glob metacharacters (`*`, `?`, `[`, `]`, `\\`) so a literal key\n * prefix can be used in `SCAN MATCH` / `PSUBSCRIBE` patterns.\n */\nfunction escapeGlob(input: string): string {\n return input.replace(/[*?[\\]\\\\]/g, \"\\\\$&\");\n}\n"],"mappings":"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"}
@@ -0,0 +1,85 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sql = require("./sql-B7b6HzGy.cjs");
3
+ const require_sqlite_event_log = require("./sqlite-event-log-BnoG8eos.cjs");
4
+ let bun_sqlite = require("bun:sqlite");
5
+ //#region src/storage/sqlite.ts
6
+ /**
7
+ * SQLite storage adapter built on `bun:sqlite` — **Bun only**, zero npm deps.
8
+ * Ideal for single-node deployments and local/dev persistence: durable, fast, and
9
+ * file-backed (or in-memory). For multi-node runtimes prefer Postgres/libSQL.
10
+ *
11
+ * Control data lives in a key/value table; events live in the **native event
12
+ * log** tables `{table}_events` / `{table}_event_targets` (ADR 0005, see
13
+ * {@link ./sql}), so queries run on indexes instead of KV scans. Event-log
14
+ * writes run in `BEGIN IMMEDIATE` transactions, so several processes sharing
15
+ * one database file stay consistent.
16
+ *
17
+ * `bun:sqlite` is marked external at build time, so this module only resolves
18
+ * under the Bun runtime. Importing it under Node will throw — by design.
19
+ *
20
+ * ```ts
21
+ * import { createSqliteStorage } from "@xtandard/audit/storage/sqlite";
22
+ * const storage = createSqliteStorage({ path: "./audit.sqlite" });
23
+ * ```
24
+ *
25
+ * @module
26
+ */
27
+ const escapeLike = (prefix) => prefix.replace(/[\\%_]/g, (c) => `\\${c}`);
28
+ /**
29
+ * Create a SQLite-backed storage. Requires the Bun runtime (`bun:sqlite`). The
30
+ * tables are created (`IF NOT EXISTS`) when the adapter is constructed.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { createSqliteStorage } from "@xtandard/audit/storage/sqlite";
35
+ *
36
+ * // File-backed (persists across restarts):
37
+ * const storage = createSqliteStorage({ path: "./audit.sqlite" });
38
+ *
39
+ * // In-memory (reset each run, useful for tests):
40
+ * // const storage = createSqliteStorage({ path: ":memory:" });
41
+ * ```
42
+ */
43
+ function createSqliteStorage(options = {}) {
44
+ const table = require_sql.assertSafeIdentifier(options.table ?? "xtandard_audit");
45
+ const ownsDb = !options.database;
46
+ const db = options.database ?? new bun_sqlite.Database(options.path ?? ":memory:");
47
+ db.run(`CREATE TABLE IF NOT EXISTS ${table} (key TEXT PRIMARY KEY, value TEXT NOT NULL)`);
48
+ for (const ddl of require_sql.eventLogDdl("sqlite", table)) db.run(ddl);
49
+ const selectStmt = db.query(`SELECT value FROM ${table} WHERE key = ?`);
50
+ const upsertStmt = db.query(`INSERT INTO ${table} (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value`);
51
+ const deleteStmt = db.query(`DELETE FROM ${table} WHERE key = ?`);
52
+ const keysStmt = db.query(`SELECT key FROM ${table} WHERE key LIKE ? ESCAPE '\\'`);
53
+ const atomic = db.transaction((statements) => statements.map((s) => db.query(s.sql).run(...s.args).changes));
54
+ const ready = Promise.resolve({
55
+ async all(sql, args) {
56
+ return db.query(sql).all(...args);
57
+ },
58
+ async atomic(statements) {
59
+ return atomic.immediate(statements);
60
+ }
61
+ });
62
+ return {
63
+ async getItem(key) {
64
+ const row = selectStmt.get(key);
65
+ return row ? JSON.parse(row.value) : null;
66
+ },
67
+ async setItem(key, value) {
68
+ upsertStmt.run(key, JSON.stringify(value));
69
+ },
70
+ async removeItem(key) {
71
+ deleteStmt.run(key);
72
+ },
73
+ async getKeys(prefix) {
74
+ return keysStmt.all(`${escapeLike(prefix)}%`).map((r) => r.key).filter((key) => key.startsWith(prefix));
75
+ },
76
+ ...require_sqlite_event_log.createSqliteEventLog(() => ready, table),
77
+ close() {
78
+ if (ownsDb) db.close();
79
+ }
80
+ };
81
+ }
82
+ //#endregion
83
+ exports.createSqliteStorage = createSqliteStorage;
84
+
85
+ //# sourceMappingURL=entry-storage-sqlite.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-storage-sqlite.cjs","names":["assertSafeIdentifier","Database","eventLogDdl","createSqliteEventLog"],"sources":["../src/storage/sqlite.ts"],"sourcesContent":["/**\n * SQLite storage adapter built on `bun:sqlite` — **Bun only**, zero npm deps.\n * Ideal for single-node deployments and local/dev persistence: durable, fast, and\n * file-backed (or in-memory). For multi-node runtimes prefer Postgres/libSQL.\n *\n * Control data lives in a key/value table; events live in the **native event\n * log** tables `{table}_events` / `{table}_event_targets` (ADR 0005, see\n * {@link ./sql}), so queries run on indexes instead of KV scans. Event-log\n * writes run in `BEGIN IMMEDIATE` transactions, so several processes sharing\n * one database file stay consistent.\n *\n * `bun:sqlite` is marked external at build time, so this module only resolves\n * under the Bun runtime. Importing it under Node will throw — by design.\n *\n * ```ts\n * import { createSqliteStorage } from \"@xtandard/audit/storage/sqlite\";\n * const storage = createSqliteStorage({ path: \"./audit.sqlite\" });\n * ```\n *\n * @module\n */\n\nimport { Database } from \"bun:sqlite\";\nimport type { EventLogStorage } from \"./contract.ts\";\nimport { createSqliteEventLog, type SqliteExecutor } from \"./sqlite-event-log.ts\";\nimport { assertSafeIdentifier, eventLogDdl, type SqlStatement } from \"./sql.ts\";\n\n/** Options for {@link createSqliteStorage}. */\nexport interface SqliteStorageOptions {\n /** File path for the database. Default `\":memory:\"`. Ignored when `database` is given. */\n path?: string;\n /** An existing `bun:sqlite` Database instance to use instead of opening one. */\n database?: Database;\n /**\n * KV table name (default `\"xtandard_audit\"`); the event log uses\n * `{table}_events` and `{table}_event_targets`. Validated as a safe identifier.\n */\n table?: string;\n}\n\n/** A storage backed by SQLite with the native {@link EventLogStorage}, plus `close()`. */\nexport interface SqliteAuditStorage extends EventLogStorage {\n /** Close the database if this adapter opened it; no-op for a borrowed instance. */\n close(): void;\n}\n\nconst escapeLike = (prefix: string): string => prefix.replace(/[\\\\%_]/g, (c) => `\\\\${c}`);\n\ntype Binding = string | number | bigint | boolean | null | Uint8Array;\n\n/**\n * Create a SQLite-backed storage. Requires the Bun runtime (`bun:sqlite`). The\n * tables are created (`IF NOT EXISTS`) when the adapter is constructed.\n *\n * @example\n * ```ts\n * import { createSqliteStorage } from \"@xtandard/audit/storage/sqlite\";\n *\n * // File-backed (persists across restarts):\n * const storage = createSqliteStorage({ path: \"./audit.sqlite\" });\n *\n * // In-memory (reset each run, useful for tests):\n * // const storage = createSqliteStorage({ path: \":memory:\" });\n * ```\n */\nexport function createSqliteStorage(options: SqliteStorageOptions = {}): SqliteAuditStorage {\n const table = assertSafeIdentifier(options.table ?? \"xtandard_audit\");\n\n const ownsDb = !options.database;\n const db = options.database ?? new Database(options.path ?? \":memory:\");\n db.run(`CREATE TABLE IF NOT EXISTS ${table} (key TEXT PRIMARY KEY, value TEXT NOT NULL)`);\n for (const ddl of eventLogDdl(\"sqlite\", table)) db.run(ddl);\n\n const selectStmt = db.query(`SELECT value FROM ${table} WHERE key = ?`);\n const upsertStmt = db.query(\n `INSERT INTO ${table} (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value`,\n );\n const deleteStmt = db.query(`DELETE FROM ${table} WHERE key = ?`);\n const keysStmt = db.query(`SELECT key FROM ${table} WHERE key LIKE ? ESCAPE '\\\\'`);\n\n // Synchronous under the hood: a transaction can never interleave with another call.\n const atomic = db.transaction((statements: SqlStatement[]) =>\n statements.map((s) => db.query(s.sql).run(...(s.args as Binding[])).changes),\n );\n const executor: SqliteExecutor = {\n async all(sql, args) {\n return db.query(sql).all(...(args as Binding[])) as Array<Record<string, unknown>>;\n },\n async atomic(statements) {\n return atomic.immediate(statements);\n },\n };\n const ready = Promise.resolve(executor);\n\n return {\n async getItem<T>(key: string): Promise<T | null> {\n const row = selectStmt.get(key) as { value: string } | null;\n return row ? (JSON.parse(row.value) as T) : null;\n },\n async setItem<T>(key: string, value: T): Promise<void> {\n upsertStmt.run(key, JSON.stringify(value));\n },\n async removeItem(key: string): Promise<void> {\n deleteStmt.run(key);\n },\n async getKeys(prefix: string): Promise<string[]> {\n const rows = keysStmt.all(`${escapeLike(prefix)}%`) as Array<{ key: string }>;\n // SQLite LIKE folds ASCII case: keep only exact prefix matches.\n return rows.map((r) => r.key).filter((key) => key.startsWith(prefix));\n },\n ...createSqliteEventLog(() => ready, table),\n close(): void {\n if (ownsDb) db.close();\n },\n } satisfies SqliteAuditStorage;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAM,cAAc,WAA2B,OAAO,QAAQ,YAAY,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;AAmBxF,SAAgB,oBAAoB,UAAgC,CAAC,GAAuB;CAC1F,MAAM,QAAQA,YAAAA,qBAAqB,QAAQ,SAAS,gBAAgB;CAEpE,MAAM,SAAS,CAAC,QAAQ;CACxB,MAAM,KAAK,QAAQ,YAAY,IAAIC,WAAAA,SAAS,QAAQ,QAAQ,UAAU;CACtE,GAAG,IAAI,8BAA8B,MAAM,6CAA6C;CACxF,KAAK,MAAM,OAAOC,YAAAA,YAAY,UAAU,KAAK,GAAG,GAAG,IAAI,GAAG;CAE1D,MAAM,aAAa,GAAG,MAAM,qBAAqB,MAAM,eAAe;CACtE,MAAM,aAAa,GAAG,MACpB,eAAe,MAAM,kFACvB;CACA,MAAM,aAAa,GAAG,MAAM,eAAe,MAAM,eAAe;CAChE,MAAM,WAAW,GAAG,MAAM,mBAAmB,MAAM,8BAA8B;CAGjF,MAAM,SAAS,GAAG,aAAa,eAC7B,WAAW,KAAK,MAAM,GAAG,MAAM,EAAE,GAAG,EAAE,IAAI,GAAI,EAAE,IAAkB,EAAE,OAAO,CAC7E;CASA,MAAM,QAAQ,QAAQ,QAAQ;EAP5B,MAAM,IAAI,KAAK,MAAM;GACnB,OAAO,GAAG,MAAM,GAAG,EAAE,IAAI,GAAI,IAAkB;EACjD;EACA,MAAM,OAAO,YAAY;GACvB,OAAO,OAAO,UAAU,UAAU;EACpC;CAEmC,CAAC;CAEtC,OAAO;EACL,MAAM,QAAW,KAAgC;GAC/C,MAAM,MAAM,WAAW,IAAI,GAAG;GAC9B,OAAO,MAAO,KAAK,MAAM,IAAI,KAAK,IAAU;EAC9C;EACA,MAAM,QAAW,KAAa,OAAyB;GACrD,WAAW,IAAI,KAAK,KAAK,UAAU,KAAK,CAAC;EAC3C;EACA,MAAM,WAAW,KAA4B;GAC3C,WAAW,IAAI,GAAG;EACpB;EACA,MAAM,QAAQ,QAAmC;GAG/C,OAFa,SAAS,IAAI,GAAG,WAAW,MAAM,EAAE,EAEtC,EAAE,KAAK,MAAM,EAAE,GAAG,EAAE,QAAQ,QAAQ,IAAI,WAAW,MAAM,CAAC;EACtE;EACA,GAAGC,yBAAAA,2BAA2B,OAAO,KAAK;EAC1C,QAAc;GACZ,IAAI,QAAQ,GAAG,MAAM;EACvB;CACF;AACF"}
@@ -0,0 +1,40 @@
1
+ import { i as EventLogStorage } from "./contract-CWJSYoJl.cjs";
2
+ import { Database } from "bun:sqlite";
3
+
4
+ //#region src/storage/sqlite.d.ts
5
+ /** Options for {@link createSqliteStorage}. */
6
+ interface SqliteStorageOptions {
7
+ /** File path for the database. Default `":memory:"`. Ignored when `database` is given. */
8
+ path?: string;
9
+ /** An existing `bun:sqlite` Database instance to use instead of opening one. */
10
+ database?: Database;
11
+ /**
12
+ * KV table name (default `"xtandard_audit"`); the event log uses
13
+ * `{table}_events` and `{table}_event_targets`. Validated as a safe identifier.
14
+ */
15
+ table?: string;
16
+ }
17
+ /** A storage backed by SQLite with the native {@link EventLogStorage}, plus `close()`. */
18
+ interface SqliteAuditStorage extends EventLogStorage {
19
+ /** Close the database if this adapter opened it; no-op for a borrowed instance. */
20
+ close(): void;
21
+ }
22
+ /**
23
+ * Create a SQLite-backed storage. Requires the Bun runtime (`bun:sqlite`). The
24
+ * tables are created (`IF NOT EXISTS`) when the adapter is constructed.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { createSqliteStorage } from "@xtandard/audit/storage/sqlite";
29
+ *
30
+ * // File-backed (persists across restarts):
31
+ * const storage = createSqliteStorage({ path: "./audit.sqlite" });
32
+ *
33
+ * // In-memory (reset each run, useful for tests):
34
+ * // const storage = createSqliteStorage({ path: ":memory:" });
35
+ * ```
36
+ */
37
+ declare function createSqliteStorage(options?: SqliteStorageOptions): SqliteAuditStorage;
38
+ //#endregion
39
+ export { SqliteAuditStorage, SqliteStorageOptions, createSqliteStorage };
40
+ //# sourceMappingURL=entry-storage-sqlite.d.cts.map
@@ -0,0 +1,40 @@
1
+ import { i as EventLogStorage } from "./contract-BmwHIiMR.mjs";
2
+ import { Database } from "bun:sqlite";
3
+
4
+ //#region src/storage/sqlite.d.ts
5
+ /** Options for {@link createSqliteStorage}. */
6
+ interface SqliteStorageOptions {
7
+ /** File path for the database. Default `":memory:"`. Ignored when `database` is given. */
8
+ path?: string;
9
+ /** An existing `bun:sqlite` Database instance to use instead of opening one. */
10
+ database?: Database;
11
+ /**
12
+ * KV table name (default `"xtandard_audit"`); the event log uses
13
+ * `{table}_events` and `{table}_event_targets`. Validated as a safe identifier.
14
+ */
15
+ table?: string;
16
+ }
17
+ /** A storage backed by SQLite with the native {@link EventLogStorage}, plus `close()`. */
18
+ interface SqliteAuditStorage extends EventLogStorage {
19
+ /** Close the database if this adapter opened it; no-op for a borrowed instance. */
20
+ close(): void;
21
+ }
22
+ /**
23
+ * Create a SQLite-backed storage. Requires the Bun runtime (`bun:sqlite`). The
24
+ * tables are created (`IF NOT EXISTS`) when the adapter is constructed.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { createSqliteStorage } from "@xtandard/audit/storage/sqlite";
29
+ *
30
+ * // File-backed (persists across restarts):
31
+ * const storage = createSqliteStorage({ path: "./audit.sqlite" });
32
+ *
33
+ * // In-memory (reset each run, useful for tests):
34
+ * // const storage = createSqliteStorage({ path: ":memory:" });
35
+ * ```
36
+ */
37
+ declare function createSqliteStorage(options?: SqliteStorageOptions): SqliteAuditStorage;
38
+ //#endregion
39
+ export { SqliteAuditStorage, SqliteStorageOptions, createSqliteStorage };
40
+ //# sourceMappingURL=entry-storage-sqlite.d.mts.map