@xtandard/kit 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.
- package/LICENSE +21 -0
- package/README.md +71 -2
- package/bin/xtandard-kit.mjs +3 -0
- package/dist/base-path-BJugWLNO.cjs +42 -0
- package/dist/base-path-BJugWLNO.cjs.map +1 -0
- package/dist/base-path-CDb4In5E.mjs +31 -0
- package/dist/base-path-CDb4In5E.mjs.map +1 -0
- package/dist/basic-Qtriv0xS.mjs +176 -0
- package/dist/basic-Qtriv0xS.mjs.map +1 -0
- package/dist/basic-ZaO92-lB.cjs +199 -0
- package/dist/basic-ZaO92-lB.cjs.map +1 -0
- package/dist/bin.cjs +126 -0
- package/dist/bin.cjs.map +1 -0
- package/dist/bin.d.cts +20 -0
- package/dist/bin.d.mts +20 -0
- package/dist/bin.mjs +125 -0
- package/dist/bin.mjs.map +1 -0
- package/dist/cas-CuPSaXBV.cjs +23 -0
- package/dist/cas-CuPSaXBV.cjs.map +1 -0
- package/dist/cas-CzA-yECx.mjs +18 -0
- package/dist/cas-CzA-yECx.mjs.map +1 -0
- package/dist/chunk-DakpK96I.cjs +43 -0
- package/dist/contract-B3UPXXLx.d.cts +30 -0
- package/dist/contract-B3UPXXLx.d.mts +30 -0
- package/dist/contract-BDPNvjtp.d.mts +64 -0
- package/dist/contract-BEdfGTPs.mjs +85 -0
- package/dist/contract-BEdfGTPs.mjs.map +1 -0
- package/dist/contract-BIVzAn4f.d.cts +64 -0
- package/dist/contract-BvgtswLX.d.cts +75 -0
- package/dist/contract-BvgtswLX.d.mts +75 -0
- package/dist/contract-DUj9P3Vt.d.cts +72 -0
- package/dist/contract-DUj9P3Vt.d.mts +72 -0
- package/dist/contract-wAEMDmYG.cjs +132 -0
- package/dist/contract-wAEMDmYG.cjs.map +1 -0
- package/dist/drizzle-BElCHWri.d.mts +115 -0
- package/dist/drizzle-BXaQXCr0.cjs +232 -0
- package/dist/drizzle-BXaQXCr0.cjs.map +1 -0
- package/dist/drizzle-CEpahWQB.d.cts +115 -0
- package/dist/drizzle-DxnelsPT.mjs +197 -0
- package/dist/drizzle-DxnelsPT.mjs.map +1 -0
- package/dist/duration-7WpAK-xe.mjs +52 -0
- package/dist/duration-7WpAK-xe.mjs.map +1 -0
- package/dist/duration-DVA0Fzkx.cjs +63 -0
- package/dist/duration-DVA0Fzkx.cjs.map +1 -0
- package/dist/duration-FPwbmWIU.d.cts +35 -0
- package/dist/duration-FPwbmWIU.d.mts +35 -0
- package/dist/entry-adapters-bun.cjs +10 -0
- package/dist/entry-adapters-bun.cjs.map +1 -0
- package/dist/entry-adapters-bun.d.cts +10 -0
- package/dist/entry-adapters-bun.d.mts +10 -0
- package/dist/entry-adapters-bun.mjs +9 -0
- package/dist/entry-adapters-bun.mjs.map +1 -0
- package/dist/entry-adapters-elysia.cjs +54 -0
- package/dist/entry-adapters-elysia.cjs.map +1 -0
- package/dist/entry-adapters-elysia.d.cts +38 -0
- package/dist/entry-adapters-elysia.d.mts +38 -0
- package/dist/entry-adapters-elysia.mjs +53 -0
- package/dist/entry-adapters-elysia.mjs.map +1 -0
- package/dist/entry-adapters-express.cjs +27 -0
- package/dist/entry-adapters-express.cjs.map +1 -0
- package/dist/entry-adapters-express.d.cts +24 -0
- package/dist/entry-adapters-express.d.mts +24 -0
- package/dist/entry-adapters-express.mjs +26 -0
- package/dist/entry-adapters-express.mjs.map +1 -0
- package/dist/entry-adapters-hono.cjs +33 -0
- package/dist/entry-adapters-hono.cjs.map +1 -0
- package/dist/entry-adapters-hono.d.cts +36 -0
- package/dist/entry-adapters-hono.d.mts +36 -0
- package/dist/entry-adapters-hono.mjs +30 -0
- package/dist/entry-adapters-hono.mjs.map +1 -0
- package/dist/entry-adapters-next.cjs +19 -0
- package/dist/entry-adapters-next.cjs.map +1 -0
- package/dist/entry-adapters-next.d.cts +35 -0
- package/dist/entry-adapters-next.d.mts +35 -0
- package/dist/entry-adapters-next.mjs +18 -0
- package/dist/entry-adapters-next.mjs.map +1 -0
- package/dist/entry-adapters-node.cjs +7 -0
- package/dist/entry-adapters-node.d.cts +2 -0
- package/dist/entry-adapters-node.d.mts +2 -0
- package/dist/entry-adapters-node.mjs +2 -0
- package/dist/entry-auth-basic.cjs +5 -0
- package/dist/entry-auth-basic.d.cts +83 -0
- package/dist/entry-auth-basic.d.mts +83 -0
- package/dist/entry-auth-basic.mjs +2 -0
- package/dist/entry-auth-delegated.cjs +28 -0
- package/dist/entry-auth-delegated.cjs.map +1 -0
- package/dist/entry-auth-delegated.d.cts +36 -0
- package/dist/entry-auth-delegated.d.mts +36 -0
- package/dist/entry-auth-delegated.mjs +27 -0
- package/dist/entry-auth-delegated.mjs.map +1 -0
- package/dist/entry-auth-none.cjs +4 -0
- package/dist/entry-auth-none.d.cts +25 -0
- package/dist/entry-auth-none.d.mts +25 -0
- package/dist/entry-auth-none.mjs +2 -0
- package/dist/entry-auth.cjs +0 -0
- package/dist/entry-auth.d.cts +2 -0
- package/dist/entry-auth.d.mts +2 -0
- package/dist/entry-auth.mjs +1 -0
- package/dist/entry-authorization-delegated.cjs +27 -0
- package/dist/entry-authorization-delegated.cjs.map +1 -0
- package/dist/entry-authorization-delegated.d.cts +31 -0
- package/dist/entry-authorization-delegated.d.mts +31 -0
- package/dist/entry-authorization-delegated.mjs +26 -0
- package/dist/entry-authorization-delegated.mjs.map +1 -0
- package/dist/entry-authorization-none.cjs +3 -0
- package/dist/entry-authorization-none.d.cts +18 -0
- package/dist/entry-authorization-none.d.mts +18 -0
- package/dist/entry-authorization-none.mjs +2 -0
- package/dist/entry-authorization-roles.cjs +3 -0
- package/dist/entry-authorization-roles.d.cts +2 -0
- package/dist/entry-authorization-roles.d.mts +2 -0
- package/dist/entry-authorization-roles.mjs +2 -0
- package/dist/entry-authorization.cjs +35 -0
- package/dist/entry-authorization.cjs.map +1 -0
- package/dist/entry-authorization.d.cts +2 -0
- package/dist/entry-authorization.d.mts +2 -0
- package/dist/entry-authorization.mjs +34 -0
- package/dist/entry-authorization.mjs.map +1 -0
- package/dist/entry-build.cjs +481 -0
- package/dist/entry-build.cjs.map +1 -0
- package/dist/entry-build.d.cts +355 -0
- package/dist/entry-build.d.mts +355 -0
- package/dist/entry-build.mjs +460 -0
- package/dist/entry-build.mjs.map +1 -0
- package/dist/entry-cli.cjs +368 -0
- package/dist/entry-cli.cjs.map +1 -0
- package/dist/entry-cli.d.cts +275 -0
- package/dist/entry-cli.d.mts +275 -0
- package/dist/entry-cli.mjs +355 -0
- package/dist/entry-cli.mjs.map +1 -0
- package/dist/entry-drizzle-mysql.cjs +36 -0
- package/dist/entry-drizzle-mysql.cjs.map +1 -0
- package/dist/entry-drizzle-mysql.d.cts +55 -0
- package/dist/entry-drizzle-mysql.d.mts +55 -0
- package/dist/entry-drizzle-mysql.mjs +34 -0
- package/dist/entry-drizzle-mysql.mjs.map +1 -0
- package/dist/entry-drizzle-pg.cjs +38 -0
- package/dist/entry-drizzle-pg.cjs.map +1 -0
- package/dist/entry-drizzle-pg.d.cts +78 -0
- package/dist/entry-drizzle-pg.d.mts +78 -0
- package/dist/entry-drizzle-pg.mjs +36 -0
- package/dist/entry-drizzle-pg.mjs.map +1 -0
- package/dist/entry-drizzle-sqlite.cjs +20 -0
- package/dist/entry-drizzle-sqlite.cjs.map +1 -0
- package/dist/entry-drizzle-sqlite.d.cts +22 -0
- package/dist/entry-drizzle-sqlite.d.mts +22 -0
- package/dist/entry-drizzle-sqlite.mjs +19 -0
- package/dist/entry-drizzle-sqlite.mjs.map +1 -0
- package/dist/entry-hooks-log.cjs +32 -0
- package/dist/entry-hooks-log.cjs.map +1 -0
- package/dist/entry-hooks-log.d.cts +36 -0
- package/dist/entry-hooks-log.d.mts +36 -0
- package/dist/entry-hooks-log.mjs +31 -0
- package/dist/entry-hooks-log.mjs.map +1 -0
- package/dist/entry-hooks.cjs +10 -0
- package/dist/entry-hooks.d.cts +2 -0
- package/dist/entry-hooks.d.mts +2 -0
- package/dist/entry-hooks.mjs +2 -0
- package/dist/entry-server-router.cjs +235 -0
- package/dist/entry-server-router.cjs.map +1 -0
- package/dist/entry-server-router.d.cts +193 -0
- package/dist/entry-server-router.d.mts +193 -0
- package/dist/entry-server-router.mjs +228 -0
- package/dist/entry-server-router.mjs.map +1 -0
- package/dist/entry-server.cjs +344 -0
- package/dist/entry-server.cjs.map +1 -0
- package/dist/entry-server.d.cts +230 -0
- package/dist/entry-server.d.mts +230 -0
- package/dist/entry-server.mjs +322 -0
- package/dist/entry-server.mjs.map +1 -0
- package/dist/entry-site.cjs +1083 -0
- package/dist/entry-site.cjs.map +1 -0
- package/dist/entry-site.d.cts +336 -0
- package/dist/entry-site.d.mts +336 -0
- package/dist/entry-site.mjs +1060 -0
- package/dist/entry-site.mjs.map +1 -0
- package/dist/entry-storage-cloudflare-kv.cjs +51 -0
- package/dist/entry-storage-cloudflare-kv.cjs.map +1 -0
- package/dist/entry-storage-cloudflare-kv.d.cts +52 -0
- package/dist/entry-storage-cloudflare-kv.d.mts +52 -0
- package/dist/entry-storage-cloudflare-kv.mjs +50 -0
- package/dist/entry-storage-cloudflare-kv.mjs.map +1 -0
- package/dist/entry-storage-drizzle-internals.cjs +6 -0
- package/dist/entry-storage-drizzle-internals.d.cts +2 -0
- package/dist/entry-storage-drizzle-internals.d.mts +2 -0
- package/dist/entry-storage-drizzle-internals.mjs +2 -0
- package/dist/entry-storage-drizzle.cjs +4 -0
- package/dist/entry-storage-drizzle.d.cts +3 -0
- package/dist/entry-storage-drizzle.d.mts +3 -0
- package/dist/entry-storage-drizzle.mjs +2 -0
- package/dist/entry-storage-file.cjs +306 -0
- package/dist/entry-storage-file.cjs.map +1 -0
- package/dist/entry-storage-file.d.cts +76 -0
- package/dist/entry-storage-file.d.mts +76 -0
- package/dist/entry-storage-file.mjs +301 -0
- package/dist/entry-storage-file.mjs.map +1 -0
- package/dist/entry-storage-libsql-internals.cjs +7 -0
- package/dist/entry-storage-libsql-internals.d.cts +3 -0
- package/dist/entry-storage-libsql-internals.d.mts +3 -0
- package/dist/entry-storage-libsql-internals.mjs +3 -0
- package/dist/entry-storage-libsql.cjs +3 -0
- package/dist/entry-storage-libsql.d.cts +2 -0
- package/dist/entry-storage-libsql.d.mts +2 -0
- package/dist/entry-storage-libsql.mjs +2 -0
- package/dist/entry-storage-memory.cjs +78 -0
- package/dist/entry-storage-memory.cjs.map +1 -0
- package/dist/entry-storage-memory.d.cts +35 -0
- package/dist/entry-storage-memory.d.mts +35 -0
- package/dist/entry-storage-memory.mjs +77 -0
- package/dist/entry-storage-memory.mjs.map +1 -0
- package/dist/entry-storage-mongodb-internals.cjs +5 -0
- package/dist/entry-storage-mongodb-internals.d.cts +2 -0
- package/dist/entry-storage-mongodb-internals.d.mts +2 -0
- package/dist/entry-storage-mongodb-internals.mjs +2 -0
- package/dist/entry-storage-mongodb.cjs +3 -0
- package/dist/entry-storage-mongodb.d.cts +2 -0
- package/dist/entry-storage-mongodb.d.mts +2 -0
- package/dist/entry-storage-mongodb.mjs +2 -0
- package/dist/entry-storage-postgres-internals.cjs +6 -0
- package/dist/entry-storage-postgres-internals.d.cts +2 -0
- package/dist/entry-storage-postgres-internals.d.mts +2 -0
- package/dist/entry-storage-postgres-internals.mjs +2 -0
- package/dist/entry-storage-postgres.cjs +4 -0
- package/dist/entry-storage-postgres.d.cts +2 -0
- package/dist/entry-storage-postgres.d.mts +2 -0
- package/dist/entry-storage-postgres.mjs +2 -0
- package/dist/entry-storage-redis-internals.cjs +7 -0
- package/dist/entry-storage-redis-internals.d.cts +2 -0
- package/dist/entry-storage-redis-internals.d.mts +2 -0
- package/dist/entry-storage-redis-internals.mjs +2 -0
- package/dist/entry-storage-redis.cjs +4 -0
- package/dist/entry-storage-redis.d.cts +2 -0
- package/dist/entry-storage-redis.d.mts +2 -0
- package/dist/entry-storage-redis.mjs +2 -0
- package/dist/entry-storage-sqlite-internals.cjs +7 -0
- package/dist/entry-storage-sqlite-internals.d.cts +3 -0
- package/dist/entry-storage-sqlite-internals.d.mts +3 -0
- package/dist/entry-storage-sqlite-internals.mjs +3 -0
- package/dist/entry-storage-sqlite.cjs +3 -0
- package/dist/entry-storage-sqlite.d.cts +2 -0
- package/dist/entry-storage-sqlite.d.mts +2 -0
- package/dist/entry-storage-sqlite.mjs +2 -0
- package/dist/entry-storage-testing.cjs +801 -0
- package/dist/entry-storage-testing.cjs.map +1 -0
- package/dist/entry-storage-testing.d.cts +150 -0
- package/dist/entry-storage-testing.d.mts +150 -0
- package/dist/entry-storage-testing.mjs +790 -0
- package/dist/entry-storage-testing.mjs.map +1 -0
- package/dist/entry-storage-unstorage.cjs +78 -0
- package/dist/entry-storage-unstorage.cjs.map +1 -0
- package/dist/entry-storage-unstorage.d.cts +30 -0
- package/dist/entry-storage-unstorage.d.mts +30 -0
- package/dist/entry-storage-unstorage.mjs +77 -0
- package/dist/entry-storage-unstorage.mjs.map +1 -0
- package/dist/entry-storage.cjs +114 -0
- package/dist/entry-storage.cjs.map +1 -0
- package/dist/entry-storage.d.cts +152 -0
- package/dist/entry-storage.d.mts +152 -0
- package/dist/entry-storage.mjs +91 -0
- package/dist/entry-storage.mjs.map +1 -0
- package/dist/entry-testing.cjs +79 -0
- package/dist/entry-testing.cjs.map +1 -0
- package/dist/entry-testing.d.cts +55 -0
- package/dist/entry-testing.d.mts +55 -0
- package/dist/entry-testing.mjs +77 -0
- package/dist/entry-testing.mjs.map +1 -0
- package/dist/entry-tokens.cjs +4 -0
- package/dist/entry-tokens.d.cts +85 -0
- package/dist/entry-tokens.d.mts +85 -0
- package/dist/entry-tokens.mjs +2 -0
- package/dist/entry-ui-embed.cjs +131 -0
- package/dist/entry-ui-embed.cjs.map +1 -0
- package/dist/entry-ui-embed.d.cts +87 -0
- package/dist/entry-ui-embed.d.mts +87 -0
- package/dist/entry-ui-embed.mjs +127 -0
- package/dist/entry-ui-embed.mjs.map +1 -0
- package/dist/entry-ui.cjs +795 -0
- package/dist/entry-ui.cjs.map +1 -0
- package/dist/entry-ui.d.cts +574 -0
- package/dist/entry-ui.d.mts +574 -0
- package/dist/entry-ui.mjs +731 -0
- package/dist/entry-ui.mjs.map +1 -0
- package/dist/entry-util.cjs +145 -0
- package/dist/entry-util.cjs.map +1 -0
- package/dist/entry-util.d.cts +85 -0
- package/dist/entry-util.d.mts +85 -0
- package/dist/entry-util.mjs +130 -0
- package/dist/entry-util.mjs.map +1 -0
- package/dist/http-B_rTnLW9.cjs +235 -0
- package/dist/http-B_rTnLW9.cjs.map +1 -0
- package/dist/http-CxYM7kPT.d.mts +133 -0
- package/dist/http-DVdVI6kJ.mjs +164 -0
- package/dist/http-DVdVI6kJ.mjs.map +1 -0
- package/dist/http-XBVRk8uo.d.cts +133 -0
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +7 -0
- package/dist/index.mjs.map +1 -0
- package/dist/json-CCyzstIm.d.cts +44 -0
- package/dist/json-CCyzstIm.d.mts +44 -0
- package/dist/json-CM7TwYQ7.cjs +92 -0
- package/dist/json-CM7TwYQ7.cjs.map +1 -0
- package/dist/json-CmM1M5Kz.mjs +63 -0
- package/dist/json-CmM1M5Kz.mjs.map +1 -0
- package/dist/keys-Bwubabk0.mjs +73 -0
- package/dist/keys-Bwubabk0.mjs.map +1 -0
- package/dist/keys-DQrwxDKI.cjs +126 -0
- package/dist/keys-DQrwxDKI.cjs.map +1 -0
- package/dist/kv-sqlite-B6iTLOx2.d.cts +20 -0
- package/dist/kv-sqlite-CHOdIMJ-.cjs +77 -0
- package/dist/kv-sqlite-CHOdIMJ-.cjs.map +1 -0
- package/dist/kv-sqlite-DIIPfflJ.mjs +66 -0
- package/dist/kv-sqlite-DIIPfflJ.mjs.map +1 -0
- package/dist/kv-sqlite-Tx4UedJs.d.mts +20 -0
- package/dist/libsql-0160BubR.d.mts +65 -0
- package/dist/libsql-BZmRZIqt.d.cts +65 -0
- package/dist/libsql-CiBfVtbS.cjs +103 -0
- package/dist/libsql-CiBfVtbS.cjs.map +1 -0
- package/dist/libsql-CkOjQINi.mjs +86 -0
- package/dist/libsql-CkOjQINi.mjs.map +1 -0
- package/dist/mongodb--Cuj7V_9.cjs +150 -0
- package/dist/mongodb--Cuj7V_9.cjs.map +1 -0
- package/dist/mongodb-DGtsolQ2.d.cts +61 -0
- package/dist/mongodb-JMizy4Wg.mjs +127 -0
- package/dist/mongodb-JMizy4Wg.mjs.map +1 -0
- package/dist/mongodb-xGEU5Gwz.d.mts +61 -0
- package/dist/node-B1Djcwfi.d.cts +57 -0
- package/dist/node-B1Djcwfi.d.mts +57 -0
- package/dist/node-BYjocCbU.mjs +167 -0
- package/dist/node-BYjocCbU.mjs.map +1 -0
- package/dist/node-DFFqYRk-.cjs +201 -0
- package/dist/node-DFFqYRk-.cjs.map +1 -0
- package/dist/none-BEY7Kc_-.mjs +33 -0
- package/dist/none-BEY7Kc_-.mjs.map +1 -0
- package/dist/none-BoQ6-30P.cjs +33 -0
- package/dist/none-BoQ6-30P.cjs.map +1 -0
- package/dist/none-CHwVkQL-.cjs +49 -0
- package/dist/none-CHwVkQL-.cjs.map +1 -0
- package/dist/none-yu3qC47E.mjs +23 -0
- package/dist/none-yu3qC47E.mjs.map +1 -0
- package/dist/peer-BIjBFzwQ.cjs +56 -0
- package/dist/peer-BIjBFzwQ.cjs.map +1 -0
- package/dist/peer-CTHMzOdn.mjs +40 -0
- package/dist/peer-CTHMzOdn.mjs.map +1 -0
- package/dist/portal-container-CJIcau3B.mjs +610 -0
- package/dist/portal-container-CJIcau3B.mjs.map +1 -0
- package/dist/portal-container-Ca1NxrLE.cjs +774 -0
- package/dist/portal-container-Ca1NxrLE.cjs.map +1 -0
- package/dist/postgres-BJzxKBk0.d.cts +72 -0
- package/dist/postgres-CA8_XcAE.cjs +164 -0
- package/dist/postgres-CA8_XcAE.cjs.map +1 -0
- package/dist/postgres-RfQMgAsj.d.mts +72 -0
- package/dist/postgres-aDiBmNzr.mjs +135 -0
- package/dist/postgres-aDiBmNzr.mjs.map +1 -0
- package/dist/redis-B2AS4xAQ.cjs +259 -0
- package/dist/redis-B2AS4xAQ.cjs.map +1 -0
- package/dist/redis-B362ofBw.d.cts +159 -0
- package/dist/redis-CahNAVTW.d.mts +159 -0
- package/dist/redis-hdoKymfG.mjs +218 -0
- package/dist/redis-hdoKymfG.mjs.map +1 -0
- package/dist/roles-7JPrQXZa.mjs +46 -0
- package/dist/roles-7JPrQXZa.mjs.map +1 -0
- package/dist/roles-B_8QqJ3j.cjs +56 -0
- package/dist/roles-B_8QqJ3j.cjs.map +1 -0
- package/dist/roles-DLISB4T3.d.mts +41 -0
- package/dist/roles-DQbbtUPW.d.cts +41 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/scope-css-BN3jf0ly.cjs +315 -0
- package/dist/scope-css-BN3jf0ly.cjs.map +1 -0
- package/dist/scope-css-BuJfRCsE.mjs +256 -0
- package/dist/scope-css-BuJfRCsE.mjs.map +1 -0
- package/dist/scoped-BRoE1W1x.cjs +175 -0
- package/dist/scoped-BRoE1W1x.cjs.map +1 -0
- package/dist/scoped-cFBbotCh.mjs +164 -0
- package/dist/scoped-cFBbotCh.mjs.map +1 -0
- package/dist/sqlite-B2g1JJz1.d.cts +47 -0
- package/dist/sqlite-BIPIlxfj.d.mts +47 -0
- package/dist/sqlite-BntoYaXZ.cjs +79 -0
- package/dist/sqlite-BntoYaXZ.cjs.map +1 -0
- package/dist/sqlite-DYJDcu7p.mjs +62 -0
- package/dist/sqlite-DYJDcu7p.mjs.map +1 -0
- package/dist/table-BrioFSra.d.cts +11 -0
- package/dist/table-BrioFSra.d.mts +11 -0
- package/dist/theme-context-DzZ1otaD.d.cts +270 -0
- package/dist/theme-context-J65pythD.d.mts +270 -0
- package/dist/ui/styles.css +239 -0
- package/dist/util-Dnj5T-yw.mjs +39 -0
- package/dist/util-Dnj5T-yw.mjs.map +1 -0
- package/dist/util-dAnTK9x-.cjs +74 -0
- package/dist/util-dAnTK9x-.cjs.map +1 -0
- package/dist/validation-B-atP968.mjs +191 -0
- package/dist/validation-B-atP968.mjs.map +1 -0
- package/dist/validation-BJifGoB2.d.mts +122 -0
- package/dist/validation-DLnzBVJr.cjs +258 -0
- package/dist/validation-DLnzBVJr.cjs.map +1 -0
- package/dist/validation-tfV2qhbD.d.cts +122 -0
- package/package.json +715 -4
- package/tsconfig/assets.d.ts +21 -0
- package/tsconfig/base.json +21 -0
- package/tsconfig/react.json +9 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { t as importPeer } from "./peer-CTHMzOdn.mjs";
|
|
2
|
+
import { a as escapeRedisGlob } from "./util-Dnj5T-yw.mjs";
|
|
3
|
+
import { n as canonicalJson, t as canonical } from "./json-CmM1M5Kz.mjs";
|
|
4
|
+
import { t as swapWithFallback } from "./cas-CzA-yECx.mjs";
|
|
5
|
+
//#region src/storage/redis.ts
|
|
6
|
+
const SUBPATH = "@xtandard/kit/storage/redis";
|
|
7
|
+
/** Plain strings containing canonical JSON; works on any Redis. */
|
|
8
|
+
const stringCodec = {
|
|
9
|
+
kind: "string",
|
|
10
|
+
async get(c, key) {
|
|
11
|
+
const raw = await c.get(key);
|
|
12
|
+
return raw === null ? null : JSON.parse(raw);
|
|
13
|
+
},
|
|
14
|
+
async set(c, key, value) {
|
|
15
|
+
await c.set(key, canonicalJson(value));
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
/** Native RedisJSON documents (written with sorted keys); needs the JSON module on the server. */
|
|
19
|
+
const jsonCodec = {
|
|
20
|
+
kind: "json",
|
|
21
|
+
async get(c, key) {
|
|
22
|
+
return await requireJson(c).get(key) ?? null;
|
|
23
|
+
},
|
|
24
|
+
async set(c, key, value) {
|
|
25
|
+
await requireJson(c).set(key, "$", canonical(value));
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
function requireJson(c) {
|
|
29
|
+
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).");
|
|
30
|
+
return c.json;
|
|
31
|
+
}
|
|
32
|
+
/** Read the raw stored text of `KEYS[1]` (`ARGV[1]` = codec). */
|
|
33
|
+
const READ_SCRIPT = `
|
|
34
|
+
if ARGV[1] == 'json' then return redis.call('JSON.GET', KEYS[1]) end
|
|
35
|
+
return redis.call('GET', KEYS[1])`;
|
|
36
|
+
/**
|
|
37
|
+
* Atomic swap. `ARGV[1]` = `"0"` to require absence, `"1"` to require that the stored text equals
|
|
38
|
+
* `ARGV[2]` exactly; `ARGV[3]` = next JSON; `ARGV[4]` = codec (`string` | `json`).
|
|
39
|
+
*/
|
|
40
|
+
const SWAP_SCRIPT = `
|
|
41
|
+
local json = ARGV[4] == 'json'
|
|
42
|
+
local raw
|
|
43
|
+
if json then raw = redis.call('JSON.GET', KEYS[1]) else raw = redis.call('GET', KEYS[1]) end
|
|
44
|
+
if ARGV[1] == '0' then
|
|
45
|
+
if raw then return 0 end
|
|
46
|
+
elseif raw ~= ARGV[2] then
|
|
47
|
+
return 0
|
|
48
|
+
end
|
|
49
|
+
if json then redis.call('JSON.SET', KEYS[1], '$', ARGV[3]) else redis.call('SET', KEYS[1], ARGV[3]) end
|
|
50
|
+
return 1`;
|
|
51
|
+
/** Build a {@link RedisConnection} from a borrowed `client` or a `url`. */
|
|
52
|
+
function redisConnection(options, subpath = SUBPATH) {
|
|
53
|
+
const ownsClient = !options.client;
|
|
54
|
+
let client = options.client;
|
|
55
|
+
let connecting;
|
|
56
|
+
const attachErrorHandler = (c) => {
|
|
57
|
+
c.on?.("error", (err) => options.onError?.(err));
|
|
58
|
+
};
|
|
59
|
+
if (client) attachErrorHandler(client);
|
|
60
|
+
return {
|
|
61
|
+
attachErrorHandler,
|
|
62
|
+
async get() {
|
|
63
|
+
if (client?.isOpen) return client;
|
|
64
|
+
connecting ??= (async () => {
|
|
65
|
+
if (!client) {
|
|
66
|
+
const mod = await importPeer("redis", subpath, () => import("redis"));
|
|
67
|
+
client = (mod.createClient ?? mod.default?.createClient)({
|
|
68
|
+
url: options.url,
|
|
69
|
+
disableOfflineQueue: true,
|
|
70
|
+
socket: { reconnectStrategy: (retries) => Math.min(retries * 100, 3e3) }
|
|
71
|
+
});
|
|
72
|
+
attachErrorHandler(client);
|
|
73
|
+
}
|
|
74
|
+
if (!client.isOpen) await client.connect();
|
|
75
|
+
return client;
|
|
76
|
+
})();
|
|
77
|
+
try {
|
|
78
|
+
return await connecting;
|
|
79
|
+
} finally {
|
|
80
|
+
connecting = void 0;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
async close() {
|
|
84
|
+
if (ownsClient && client?.isOpen) await client.quit();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Every key a `SCAN … MATCH` yields, de-duplicated (SCAN may return a key more than once; node-redis
|
|
90
|
+
* v4 yields keys, v5 batches). Semi-public.
|
|
91
|
+
*/
|
|
92
|
+
async function scanKeys(c, match) {
|
|
93
|
+
const out = /* @__PURE__ */ new Set();
|
|
94
|
+
for await (const entry of c.scanIterator({
|
|
95
|
+
MATCH: match,
|
|
96
|
+
COUNT: 100
|
|
97
|
+
})) if (Array.isArray(entry)) for (const key of entry) out.add(key);
|
|
98
|
+
else out.add(entry);
|
|
99
|
+
return [...out];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The Redis driver with an explicit codec and optional shared connection (semi-public, ADR 0004).
|
|
103
|
+
* {@link createRedisStorage} and {@link createRedisJSONStorage} are this with a fixed codec.
|
|
104
|
+
*/
|
|
105
|
+
function createRedisKvStorage(options) {
|
|
106
|
+
const { codec, onWrite } = options;
|
|
107
|
+
const fullPrefix = options.prefix ? `${options.prefix}:` : "";
|
|
108
|
+
const connection = options.connection ?? redisConnection(options);
|
|
109
|
+
const getClient = connection.get;
|
|
110
|
+
const toRedisKey = (key) => `${fullPrefix}${key}`;
|
|
111
|
+
const fromRedisKey = (key) => fullPrefix && key.startsWith(fullPrefix) ? key.slice(fullPrefix.length) : key;
|
|
112
|
+
const written = async (c, key, value) => {
|
|
113
|
+
await onWrite?.(key, value, {
|
|
114
|
+
client: c,
|
|
115
|
+
redisKey: toRedisKey(key),
|
|
116
|
+
toRedisKey
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
return {
|
|
120
|
+
async getItem(key) {
|
|
121
|
+
return await codec.get(await getClient(), toRedisKey(key)) ?? null;
|
|
122
|
+
},
|
|
123
|
+
async setItem(key, value) {
|
|
124
|
+
const c = await getClient();
|
|
125
|
+
await codec.set(c, toRedisKey(key), value);
|
|
126
|
+
await written(c, key, canonical(value));
|
|
127
|
+
},
|
|
128
|
+
async removeItem(key) {
|
|
129
|
+
const c = await getClient();
|
|
130
|
+
await c.del(toRedisKey(key));
|
|
131
|
+
await written(c, key, null);
|
|
132
|
+
},
|
|
133
|
+
async getKeys(prefix) {
|
|
134
|
+
return (await scanKeys(await getClient(), `${escapeRedisGlob(toRedisKey(prefix))}*`)).map(fromRedisKey).filter((key) => key.startsWith(prefix));
|
|
135
|
+
},
|
|
136
|
+
async compareAndSwap(input) {
|
|
137
|
+
const c = await getClient();
|
|
138
|
+
const redisKey = toRedisKey(input.key);
|
|
139
|
+
const next = canonicalJson(input.next);
|
|
140
|
+
const swap = async (mode, current) => Number(await c.eval(SWAP_SCRIPT, {
|
|
141
|
+
keys: [redisKey],
|
|
142
|
+
arguments: [
|
|
143
|
+
mode,
|
|
144
|
+
current,
|
|
145
|
+
next,
|
|
146
|
+
codec.kind
|
|
147
|
+
]
|
|
148
|
+
})) === 1;
|
|
149
|
+
const ok = input.expected === null ? await swap("0", "") : await swapWithFallback(input.expected, {
|
|
150
|
+
fast: () => swap("1", canonicalJson(input.expected)),
|
|
151
|
+
async read() {
|
|
152
|
+
const raw = await c.eval(READ_SCRIPT, {
|
|
153
|
+
keys: [redisKey],
|
|
154
|
+
arguments: [codec.kind]
|
|
155
|
+
});
|
|
156
|
+
return typeof raw === "string" ? {
|
|
157
|
+
raw,
|
|
158
|
+
value: JSON.parse(raw)
|
|
159
|
+
} : null;
|
|
160
|
+
},
|
|
161
|
+
swapRaw: (raw) => swap("1", raw)
|
|
162
|
+
});
|
|
163
|
+
if (ok) await written(c, input.key, canonical(input.next));
|
|
164
|
+
return ok;
|
|
165
|
+
},
|
|
166
|
+
async watch(prefix, callback) {
|
|
167
|
+
const subscriber = (await getClient()).duplicate();
|
|
168
|
+
connection.attachErrorHandler(subscriber);
|
|
169
|
+
await subscriber.connect();
|
|
170
|
+
const pattern = `__keyspace@*__:${escapeRedisGlob(toRedisKey(prefix))}*`;
|
|
171
|
+
await subscriber.pSubscribe(pattern, (event, channel) => {
|
|
172
|
+
const idx = channel.indexOf("__:");
|
|
173
|
+
if (idx === -1) return;
|
|
174
|
+
const key = fromRedisKey(channel.slice(idx + 3));
|
|
175
|
+
if (!key.startsWith(prefix)) return;
|
|
176
|
+
callback({
|
|
177
|
+
type: event === "del" || event === "expired" ? "remove" : "update",
|
|
178
|
+
key
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
return () => {
|
|
182
|
+
subscriber.disconnect();
|
|
183
|
+
};
|
|
184
|
+
},
|
|
185
|
+
close: connection.close
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Create a Redis-backed {@link RedisKvStorage} storing JSON strings.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* import { createRedisStorage } from "@xtandard/kit/storage/redis";
|
|
194
|
+
*
|
|
195
|
+
* const storage = createRedisStorage({ url: process.env.REDIS_URL, prefix: "app" });
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
function createRedisStorage(options) {
|
|
199
|
+
return createRedisKvStorage({
|
|
200
|
+
...options,
|
|
201
|
+
codec: stringCodec
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Create a Redis-backed {@link RedisKvStorage} storing native RedisJSON documents, queryable with
|
|
206
|
+
* JSONPath (`JSON.GET app:key $.field`) and indexable with RediSearch. Same options and semantics
|
|
207
|
+
* as {@link createRedisStorage}; never point it at keys written by `createRedisStorage`.
|
|
208
|
+
*/
|
|
209
|
+
function createRedisJSONStorage(options) {
|
|
210
|
+
return createRedisKvStorage({
|
|
211
|
+
...options,
|
|
212
|
+
codec: jsonCodec
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
export { redisConnection as a, jsonCodec as i, createRedisKvStorage as n, scanKeys as o, createRedisStorage as r, stringCodec as s, createRedisJSONStorage as t };
|
|
217
|
+
|
|
218
|
+
//# sourceMappingURL=redis-hdoKymfG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-hdoKymfG.mjs","names":[],"sources":["../src/storage/redis.ts"],"sourcesContent":["/**\n * Redis storage drivers over [`redis`](https://github.com/redis/node-redis) (node-redis v4/v5, an\n * optional peer). Pass a (optionally pre-connected) `client`, or a `url` to connect lazily on first\n * use. An optional `prefix` is prepended (joined with `:`) to every key and stripped from `getKeys`.\n *\n * Two variants over the same plumbing, differing only in the value codec:\n *\n * - {@link createRedisStorage}: values are JSON **strings** (`SET`/`GET`), on any Redis.\n * - {@link createRedisJSONStorage}: values are **RedisJSON** documents (`JSON.SET`/`JSON.GET`),\n * queryable with JSONPath. Needs the JSON module (Redis 8, Redis Stack). Never point both variants\n * at the same keys (`WRONGTYPE`).\n *\n * - `getKeys` uses a non-blocking `SCAN` (never `KEYS`) with the prefix glob-escaped, de-duplicated\n * (SCAN may return a key more than once) and re-checked with `startsWith`.\n * - `watch` uses keyspace notifications (`notify-keyspace-events` must include `KEA` or similar) on a\n * glob-escaped `PSUBSCRIBE` pattern, so a prefix with `[`, `*`, `?` or `\\` never misses events.\n * - `compareAndSwap` is a Lua script that compares the stored text with the canonical JSON of\n * `expected` **as strings** and writes `next` on a match, atomically. A value written before\n * canonicalisation (or serialized differently by RedisJSON) misses that fast path; the swap then\n * reads the raw text, compares it structurally in JS (`{}` ≠ `[]`, unlike a `cjson` decode) and\n * swaps on the exact raw text, with bounded retries (ADR 0005).\n * - `onWrite(key, value | null, ctx)` runs after every successful write, swap and remove, with the\n * connected client: wh mirrors due keys into a sorted set with it (ADR 0004).\n *\n * @module\n */\n\nimport type { RedisClientType } from \"redis\";\nimport { canonical, canonicalJson } from \"../internal/json.ts\";\nimport { importPeer } from \"../internal/peer.ts\";\nimport { swapWithFallback } from \"./cas.ts\";\nimport type {\n CompareAndSwapInput,\n CompareAndSwapKvStorage,\n StorageChangeEvent,\n WatchableKvStorage,\n} from \"./contract.ts\";\nimport { escapeRedisGlob } from \"./util.ts\";\n\nconst SUBPATH = \"@xtandard/kit/storage/redis\";\n\n/** What an {@link RedisStorageOptions.onWrite} hook receives besides the key and value. */\nexport interface RedisWriteContext {\n /** The connected client (run your own commands, e.g. `zAdd`, on it). */\n client: RedisLike;\n /** The full Redis key (with the `prefix:` namespace). */\n redisKey: string;\n /** Map another caller key to its full Redis key. */\n toRedisKey(key: string): string;\n}\n\n/**\n * A write hook (ADR 0004): called after every successful `setItem`, successful `compareAndSwap`\n * (with the new value) and `removeItem` (with `null`, whether or not the key existed). An error\n * thrown by the hook rejects the call; the write itself has already happened.\n */\nexport type RedisWriteHook = (\n key: string,\n value: unknown,\n ctx: RedisWriteContext,\n) => void | Promise<void>;\n\n/** Options for {@link createRedisStorage} and {@link createRedisJSONStorage}. */\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. Never closed by the driver. */\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, reconnects). A handler is always attached so\n * a downed Redis never crashes the process with an unhandled `error` event.\n */\n onError?: (error: unknown) => void;\n /** Called after every write, swap and remove; see {@link RedisWriteHook}. */\n onWrite?: RedisWriteHook;\n}\n\n/** A watchable, compare-and-swap capable storage backed by Redis, plus `close()`. */\nexport interface RedisKvStorage extends WatchableKvStorage, CompareAndSwapKvStorage {\n /** Disconnect the client if this driver created it; no-op for a borrowed one. */\n close(): Promise<void>;\n}\n\n/** Minimal structural view of the node-redis client surface the drivers use. */\nexport interface RedisLike {\n /** Whether the socket is open. */\n isOpen?: boolean;\n /** Register an event listener. */\n on?(event: string, listener: (...args: unknown[]) => void): unknown;\n /** Connect. */\n connect(): Promise<unknown>;\n /** Close gracefully. */\n quit(): Promise<unknown>;\n /** `GET`. */\n get(key: string): Promise<string | null>;\n /** `SET`. */\n set(key: string, value: string): Promise<unknown>;\n /** `DEL`. */\n del(key: string | string[]): Promise<unknown>;\n /** `ZADD` (sorted sets; products keep their own indexes with it, e.g. a due-time index). */\n zAdd(\n key: string,\n members: { score: number; value: string } | { score: number; value: string }[],\n ): Promise<unknown>;\n /** `ZREM`. */\n zRem(key: string, members: string | string[]): Promise<unknown>;\n /** `ZRANGEBYSCORE` (members only). */\n zRangeByScore(\n key: string,\n min: number | string,\n max: number | string,\n options?: { LIMIT?: { offset: number; count: number } },\n ): Promise<string[]>;\n /** `EVAL`. */\n eval(script: string, options?: { keys?: string[]; arguments?: string[] }): Promise<unknown>;\n /** RedisJSON 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 /** `SCAN` iterator (v4 yields keys, v5 yields batches). */\n scanIterator(options?: { MATCH?: string; COUNT?: number }): AsyncIterable<string | string[]>;\n /** A new client with the same options (for subscriptions). */\n duplicate(): RedisLike;\n /** `PSUBSCRIBE`. */\n pSubscribe(\n pattern: string,\n listener: (message: string, channel: string) => void,\n ): Promise<unknown>;\n /** Close immediately. */\n disconnect(): Promise<unknown>;\n}\n\n/** How a variant stores values (semi-public, ADR 0004). */\nexport interface RedisValueCodec {\n /** Passed to the CAS script so it reads/writes with the matching commands. */\n kind: \"string\" | \"json\";\n /** Read and decode a value (`null` when absent). */\n get(c: RedisLike, key: string): Promise<unknown>;\n /** Encode and write a value. */\n set(c: RedisLike, key: string, value: unknown): Promise<void>;\n}\n\n/** Plain strings containing canonical JSON; works on any Redis. */\nexport const stringCodec: RedisValueCodec = {\n kind: \"string\",\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, canonicalJson(value));\n },\n};\n\n/** Native RedisJSON documents (written with sorted keys); needs the JSON module on the server. */\nexport const jsonCodec: RedisValueCodec = {\n kind: \"json\",\n async get(c, key) {\n return (await requireJson(c).get(key)) ?? null;\n },\n async set(c, key, value) {\n await requireJson(c).set(key, \"$\", canonical(value));\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 (the `redis` \" +\n \"package) v4+, and a server with the RedisJSON module (Redis 8 / Redis Stack).\",\n );\n }\n return c.json;\n}\n\n/** Read the raw stored text of `KEYS[1]` (`ARGV[1]` = codec). */\nconst READ_SCRIPT = `\nif ARGV[1] == 'json' then return redis.call('JSON.GET', KEYS[1]) end\nreturn redis.call('GET', KEYS[1])`;\n\n/**\n * Atomic swap. `ARGV[1]` = `\"0\"` to require absence, `\"1\"` to require that the stored text equals\n * `ARGV[2]` exactly; `ARGV[3]` = next JSON; `ARGV[4]` = codec (`string` | `json`).\n */\nconst SWAP_SCRIPT = `\nlocal json = ARGV[4] == 'json'\nlocal raw\nif json then raw = redis.call('JSON.GET', KEYS[1]) else raw = redis.call('GET', KEYS[1]) end\nif ARGV[1] == '0' then\n if raw then return 0 end\nelseif raw ~= ARGV[2] then\n return 0\nend\nif json then redis.call('JSON.SET', KEYS[1], '$', ARGV[3]) else redis.call('SET', KEYS[1], ARGV[3]) end\nreturn 1`;\n\n/** A lazily connected node-redis client (semi-public, ADR 0004). */\nexport interface RedisConnection {\n /** Resolve a connected client, creating/connecting it on first use (retried after a failure). */\n get(): Promise<RedisLike>;\n /** Attach the internal `error` listener (and `onError`) to a client. */\n attachErrorHandler(c: RedisLike): void;\n /** Quit the client if this connection created it. */\n close(): Promise<void>;\n}\n\n/** Build a {@link RedisConnection} from a borrowed `client` or a `url`. */\nexport function redisConnection(\n options: Pick<RedisStorageOptions, \"url\" | \"client\" | \"onError\">,\n subpath = SUBPATH,\n): RedisConnection {\n const ownsClient = !options.client;\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; without a listener Node crashes the process.\n const attachErrorHandler = (c: RedisLike): void => {\n c.on?.(\"error\", (err: unknown) => options.onError?.(err));\n };\n if (client) attachErrorHandler(client);\n\n return {\n attachErrorHandler,\n async get(): Promise<RedisLike> {\n if (client?.isOpen) return client;\n connecting ??= (async () => {\n if (!client) {\n type CreateClient = (opts: Record<string, unknown>) => RedisLike;\n const mod = await importPeer(\n \"redis\",\n subpath,\n () =>\n import(\"redis\") as unknown as Promise<{\n createClient?: CreateClient;\n default?: { createClient: CreateClient };\n }>,\n );\n const createClient = (mod.createClient ?? mod.default?.createClient) as CreateClient;\n // Fail fast while the socket is down (no offline queue); reconnect with a capped backoff.\n client = createClient({\n url: options.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 async close(): Promise<void> {\n if (ownsClient && client?.isOpen) await client.quit();\n },\n };\n}\n\n/**\n * Every key a `SCAN … MATCH` yields, de-duplicated (SCAN may return a key more than once; node-redis\n * v4 yields keys, v5 batches). Semi-public.\n */\nexport async function scanKeys(c: RedisLike, match: string): Promise<string[]> {\n const out = new Set<string>();\n for await (const entry of c.scanIterator({ MATCH: match, COUNT: 100 })) {\n if (Array.isArray(entry)) for (const key of entry) out.add(key);\n else out.add(entry);\n }\n return [...out];\n}\n\n/** Options for {@link createRedisKvStorage}: the driver options plus the codec and connection. */\nexport interface RedisKvStorageOptions extends RedisStorageOptions {\n /** The value codec ({@link stringCodec} or {@link jsonCodec}). */\n codec: RedisValueCodec;\n /**\n * A connection to reuse (so a product capability layer shares the driver's client). Default: one\n * built from `url`/`client`/`onError`.\n */\n connection?: RedisConnection;\n}\n\n/**\n * The Redis driver with an explicit codec and optional shared connection (semi-public, ADR 0004).\n * {@link createRedisStorage} and {@link createRedisJSONStorage} are this with a fixed codec.\n */\nexport function createRedisKvStorage(options: RedisKvStorageOptions): RedisKvStorage {\n const { codec, onWrite } = options;\n const fullPrefix = options.prefix ? `${options.prefix}:` : \"\";\n const connection = options.connection ?? redisConnection(options);\n const getClient = connection.get;\n\n const toRedisKey = (key: string): string => `${fullPrefix}${key}`;\n const fromRedisKey = (key: string): string =>\n fullPrefix && key.startsWith(fullPrefix) ? key.slice(fullPrefix.length) : key;\n const written = async (c: RedisLike, key: string, value: unknown): Promise<void> => {\n await onWrite?.(key, value, { client: c, redisKey: toRedisKey(key), toRedisKey });\n };\n\n return {\n async getItem<T>(key: string): Promise<T | null> {\n return ((await codec.get(await getClient(), 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 await written(c, key, canonical(value));\n },\n\n async removeItem(key: string): Promise<void> {\n const c = await getClient();\n await c.del(toRedisKey(key));\n await written(c, key, null);\n },\n\n async getKeys(prefix: string): Promise<string[]> {\n const keys = await scanKeys(await getClient(), `${escapeRedisGlob(toRedisKey(prefix))}*`);\n return keys.map(fromRedisKey).filter((key) => key.startsWith(prefix));\n },\n\n async compareAndSwap<T>(input: CompareAndSwapInput<T>): Promise<boolean> {\n const c = await getClient();\n const redisKey = toRedisKey(input.key);\n const next = canonicalJson(input.next);\n const swap = async (mode: \"0\" | \"1\", current: string): Promise<boolean> =>\n Number(\n await c.eval(SWAP_SCRIPT, {\n keys: [redisKey],\n arguments: [mode, current, next, codec.kind],\n }),\n ) === 1;\n const ok =\n input.expected === null\n ? await swap(\"0\", \"\")\n : await swapWithFallback<string>(input.expected, {\n fast: () => swap(\"1\", canonicalJson(input.expected)),\n async read() {\n const raw = await c.eval(READ_SCRIPT, {\n keys: [redisKey],\n arguments: [codec.kind],\n });\n return typeof raw === \"string\" ? { raw, value: JSON.parse(raw) as unknown } : null;\n },\n swapRaw: (raw) => swap(\"1\", raw),\n });\n if (ok) await written(c, input.key, canonical(input.next));\n return ok;\n },\n\n async watch(\n prefix: string,\n callback: (event: StorageChangeEvent) => void,\n ): Promise<() => void> {\n // Keyspace notifications publish to `__keyspace@<db>__:<key>`.\n const subscriber = (await getClient()).duplicate();\n connection.attachErrorHandler(subscriber);\n await subscriber.connect();\n const pattern = `__keyspace@*__:${escapeRedisGlob(toRedisKey(prefix))}*`;\n await subscriber.pSubscribe(pattern, (event: string, channel: string) => {\n const idx = channel.indexOf(\"__:\");\n if (idx === -1) return;\n const key = fromRedisKey(channel.slice(idx + 3));\n if (!key.startsWith(prefix)) return;\n callback({ type: event === \"del\" || event === \"expired\" ? \"remove\" : \"update\", key });\n });\n return () => {\n void subscriber.disconnect();\n };\n },\n\n close: connection.close,\n };\n}\n\n/**\n * Create a Redis-backed {@link RedisKvStorage} storing JSON strings.\n *\n * @example\n * ```ts\n * import { createRedisStorage } from \"@xtandard/kit/storage/redis\";\n *\n * const storage = createRedisStorage({ url: process.env.REDIS_URL, prefix: \"app\" });\n * ```\n */\nexport function createRedisStorage(options: RedisStorageOptions): RedisKvStorage {\n return createRedisKvStorage({ ...options, codec: stringCodec });\n}\n\n/**\n * Create a Redis-backed {@link RedisKvStorage} storing native RedisJSON documents, queryable with\n * JSONPath (`JSON.GET app:key $.field`) and indexable with RediSearch. Same options and semantics\n * as {@link createRedisStorage}; never point it at keys written by `createRedisStorage`.\n */\nexport function createRedisJSONStorage(options: RedisStorageOptions): RedisKvStorage {\n return createRedisKvStorage({ ...options, codec: jsonCodec });\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
//#region src/authorization/roles.ts
|
|
3
|
+
var roles_exports = /* @__PURE__ */ __exportAll({ rolesAuthorization: () => rolesAuthorization });
|
|
4
|
+
/**
|
|
5
|
+
* Create a role-based {@link AuthorizationProvider}.
|
|
6
|
+
*
|
|
7
|
+
* Decision order:
|
|
8
|
+
* 1. If `readonly` and the action mutates → **deny**.
|
|
9
|
+
* 2. If the principal is `null` → **deny**.
|
|
10
|
+
* 3. If any of the principal's roles grants the action (via `"*"` or an explicit
|
|
11
|
+
* list) → **allow**; otherwise **deny**.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { rolesAuthorization } from "@xtandard/kit/authorization/roles";
|
|
16
|
+
*
|
|
17
|
+
* const authz = rolesAuthorization({
|
|
18
|
+
* actions, // from defineActions(...)
|
|
19
|
+
* policy: { admin: "*", viewer: ["endpoint:read", "message:read"] },
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function rolesAuthorization(options) {
|
|
24
|
+
const readonly = options.readonly ?? false;
|
|
25
|
+
const { isMutatingAction } = options.actions;
|
|
26
|
+
const grants = /* @__PURE__ */ new Map();
|
|
27
|
+
for (const [role, actions] of Object.entries(options.policy)) grants.set(role, actions === "*" ? null : new Set(actions));
|
|
28
|
+
return { async authorize(input) {
|
|
29
|
+
if (readonly && isMutatingAction(input.action)) return false;
|
|
30
|
+
const principal = input.principal;
|
|
31
|
+
if (!principal) return false;
|
|
32
|
+
const roles = principal.roles;
|
|
33
|
+
if (!roles || roles.length === 0) return false;
|
|
34
|
+
for (const role of roles) {
|
|
35
|
+
if (!grants.has(role)) continue;
|
|
36
|
+
const granted = grants.get(role);
|
|
37
|
+
if (granted === null) return true;
|
|
38
|
+
if (granted?.has(input.action)) return true;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
} };
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { roles_exports as n, rolesAuthorization as t };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=roles-7JPrQXZa.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles-7JPrQXZa.mjs","names":[],"sources":["../src/authorization/roles.ts"],"sourcesContent":["/**\n * Role-based {@link AuthorizationProvider}. Maps each role name to the set of\n * actions it grants, then allows an action when _any_ of the principal's roles\n * grants it.\n *\n * The policy is a flat `Record<roleName, Action[] | \"*\">` — `\"*\"` is a wildcard\n * granting every action. The kit has no default policy: each product passes its\n * own `DEFAULT_ROLE_POLICY` (ADR 0002).\n *\n * A `readonly` switch denies every mutating action (as defined by the\n * product's {@link defineActions} result) regardless of role — handy for\n * read-only mirrors or \"break glass\" lockdowns.\n *\n * @module\n */\n\nimport type { ActionsDefinitionResult, AuthorizationProvider, AuthorizeInput } from \"./contract.ts\";\n\n/** A role policy: each role maps to an explicit action list or the `\"*\"` wildcard. */\nexport type RolePolicy<Action extends string = string> = Record<string, readonly Action[] | \"*\">;\n\n/** Options for {@link rolesAuthorization}. */\nexport interface RolesAuthorizationOptions<Action extends string = string> {\n /** Role → granted actions. `\"*\"` grants everything. */\n policy: RolePolicy<Action>;\n /** The product's actions; only `isMutatingAction` is used (for `readonly`). */\n actions: Pick<ActionsDefinitionResult<Action>, \"isMutatingAction\">;\n /**\n * When `true`, every mutating action is denied regardless of the principal's\n * roles.\n * @default false\n */\n readonly?: boolean;\n}\n\n/**\n * Create a role-based {@link AuthorizationProvider}.\n *\n * Decision order:\n * 1. If `readonly` and the action mutates → **deny**.\n * 2. If the principal is `null` → **deny**.\n * 3. If any of the principal's roles grants the action (via `\"*\"` or an explicit\n * list) → **allow**; otherwise **deny**.\n *\n * @example\n * ```ts\n * import { rolesAuthorization } from \"@xtandard/kit/authorization/roles\";\n *\n * const authz = rolesAuthorization({\n * actions, // from defineActions(...)\n * policy: { admin: \"*\", viewer: [\"endpoint:read\", \"message:read\"] },\n * });\n * ```\n */\nexport function rolesAuthorization<Action extends string = string, Resource = unknown>(\n options: RolesAuthorizationOptions<Action>,\n): AuthorizationProvider<Action, Resource> {\n const readonly = options.readonly ?? false;\n const { isMutatingAction } = options.actions;\n\n // Pre-compute each role's granted action set for O(1) lookups. A role mapped\n // to \"*\" is recorded as `null` (wildcard).\n const grants = new Map<string, Set<Action> | null>();\n for (const [role, actions] of Object.entries(options.policy)) {\n grants.set(role, actions === \"*\" ? null : new Set(actions));\n }\n\n return {\n async authorize(input: AuthorizeInput<Action, Resource>): Promise<boolean> {\n if (readonly && isMutatingAction(input.action)) return false;\n\n const principal = input.principal;\n if (!principal) return false;\n\n const roles = principal.roles;\n if (!roles || roles.length === 0) return false;\n\n for (const role of roles) {\n if (!grants.has(role)) continue;\n const granted = grants.get(role);\n if (granted === null) return true; // wildcard\n if (granted?.has(input.action)) return true;\n }\n return false;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,mBACd,SACyC;CACzC,MAAM,WAAW,QAAQ,YAAY;CACrC,MAAM,EAAE,qBAAqB,QAAQ;CAIrC,MAAM,yBAAS,IAAI,IAAgC;CACnD,KAAK,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,QAAQ,MAAM,GACzD,OAAO,IAAI,MAAM,YAAY,MAAM,OAAO,IAAI,IAAI,OAAO,CAAC;CAG5D,OAAO,EACL,MAAM,UAAU,OAA2D;EACzE,IAAI,YAAY,iBAAiB,MAAM,MAAM,GAAG,OAAO;EAEvD,MAAM,YAAY,MAAM;EACxB,IAAI,CAAC,WAAW,OAAO;EAEvB,MAAM,QAAQ,UAAU;EACxB,IAAI,CAAC,SAAS,MAAM,WAAW,GAAG,OAAO;EAEzC,KAAK,MAAM,QAAQ,OAAO;GACxB,IAAI,CAAC,OAAO,IAAI,IAAI,GAAG;GACvB,MAAM,UAAU,OAAO,IAAI,IAAI;GAC/B,IAAI,YAAY,MAAM,OAAO;GAC7B,IAAI,SAAS,IAAI,MAAM,MAAM,GAAG,OAAO;EACzC;EACA,OAAO;CACT,EACF;AACF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//#region src/authorization/roles.ts
|
|
2
|
+
var roles_exports = /* @__PURE__ */ require("./chunk-DakpK96I.cjs").__exportAll({ rolesAuthorization: () => rolesAuthorization });
|
|
3
|
+
/**
|
|
4
|
+
* Create a role-based {@link AuthorizationProvider}.
|
|
5
|
+
*
|
|
6
|
+
* Decision order:
|
|
7
|
+
* 1. If `readonly` and the action mutates → **deny**.
|
|
8
|
+
* 2. If the principal is `null` → **deny**.
|
|
9
|
+
* 3. If any of the principal's roles grants the action (via `"*"` or an explicit
|
|
10
|
+
* list) → **allow**; otherwise **deny**.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { rolesAuthorization } from "@xtandard/kit/authorization/roles";
|
|
15
|
+
*
|
|
16
|
+
* const authz = rolesAuthorization({
|
|
17
|
+
* actions, // from defineActions(...)
|
|
18
|
+
* policy: { admin: "*", viewer: ["endpoint:read", "message:read"] },
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function rolesAuthorization(options) {
|
|
23
|
+
const readonly = options.readonly ?? false;
|
|
24
|
+
const { isMutatingAction } = options.actions;
|
|
25
|
+
const grants = /* @__PURE__ */ new Map();
|
|
26
|
+
for (const [role, actions] of Object.entries(options.policy)) grants.set(role, actions === "*" ? null : new Set(actions));
|
|
27
|
+
return { async authorize(input) {
|
|
28
|
+
if (readonly && isMutatingAction(input.action)) return false;
|
|
29
|
+
const principal = input.principal;
|
|
30
|
+
if (!principal) return false;
|
|
31
|
+
const roles = principal.roles;
|
|
32
|
+
if (!roles || roles.length === 0) return false;
|
|
33
|
+
for (const role of roles) {
|
|
34
|
+
if (!grants.has(role)) continue;
|
|
35
|
+
const granted = grants.get(role);
|
|
36
|
+
if (granted === null) return true;
|
|
37
|
+
if (granted?.has(input.action)) return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
} };
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
Object.defineProperty(exports, "rolesAuthorization", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function() {
|
|
46
|
+
return rolesAuthorization;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(exports, "roles_exports", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function() {
|
|
52
|
+
return roles_exports;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=roles-B_8QqJ3j.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles-B_8QqJ3j.cjs","names":[],"sources":["../src/authorization/roles.ts"],"sourcesContent":["/**\n * Role-based {@link AuthorizationProvider}. Maps each role name to the set of\n * actions it grants, then allows an action when _any_ of the principal's roles\n * grants it.\n *\n * The policy is a flat `Record<roleName, Action[] | \"*\">` — `\"*\"` is a wildcard\n * granting every action. The kit has no default policy: each product passes its\n * own `DEFAULT_ROLE_POLICY` (ADR 0002).\n *\n * A `readonly` switch denies every mutating action (as defined by the\n * product's {@link defineActions} result) regardless of role — handy for\n * read-only mirrors or \"break glass\" lockdowns.\n *\n * @module\n */\n\nimport type { ActionsDefinitionResult, AuthorizationProvider, AuthorizeInput } from \"./contract.ts\";\n\n/** A role policy: each role maps to an explicit action list or the `\"*\"` wildcard. */\nexport type RolePolicy<Action extends string = string> = Record<string, readonly Action[] | \"*\">;\n\n/** Options for {@link rolesAuthorization}. */\nexport interface RolesAuthorizationOptions<Action extends string = string> {\n /** Role → granted actions. `\"*\"` grants everything. */\n policy: RolePolicy<Action>;\n /** The product's actions; only `isMutatingAction` is used (for `readonly`). */\n actions: Pick<ActionsDefinitionResult<Action>, \"isMutatingAction\">;\n /**\n * When `true`, every mutating action is denied regardless of the principal's\n * roles.\n * @default false\n */\n readonly?: boolean;\n}\n\n/**\n * Create a role-based {@link AuthorizationProvider}.\n *\n * Decision order:\n * 1. If `readonly` and the action mutates → **deny**.\n * 2. If the principal is `null` → **deny**.\n * 3. If any of the principal's roles grants the action (via `\"*\"` or an explicit\n * list) → **allow**; otherwise **deny**.\n *\n * @example\n * ```ts\n * import { rolesAuthorization } from \"@xtandard/kit/authorization/roles\";\n *\n * const authz = rolesAuthorization({\n * actions, // from defineActions(...)\n * policy: { admin: \"*\", viewer: [\"endpoint:read\", \"message:read\"] },\n * });\n * ```\n */\nexport function rolesAuthorization<Action extends string = string, Resource = unknown>(\n options: RolesAuthorizationOptions<Action>,\n): AuthorizationProvider<Action, Resource> {\n const readonly = options.readonly ?? false;\n const { isMutatingAction } = options.actions;\n\n // Pre-compute each role's granted action set for O(1) lookups. A role mapped\n // to \"*\" is recorded as `null` (wildcard).\n const grants = new Map<string, Set<Action> | null>();\n for (const [role, actions] of Object.entries(options.policy)) {\n grants.set(role, actions === \"*\" ? null : new Set(actions));\n }\n\n return {\n async authorize(input: AuthorizeInput<Action, Resource>): Promise<boolean> {\n if (readonly && isMutatingAction(input.action)) return false;\n\n const principal = input.principal;\n if (!principal) return false;\n\n const roles = principal.roles;\n if (!roles || roles.length === 0) return false;\n\n for (const role of roles) {\n if (!grants.has(role)) continue;\n const granted = grants.get(role);\n if (granted === null) return true; // wildcard\n if (granted?.has(input.action)) return true;\n }\n return false;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,mBACd,SACyC;CACzC,MAAM,WAAW,QAAQ,YAAY;CACrC,MAAM,EAAE,qBAAqB,QAAQ;CAIrC,MAAM,yBAAS,IAAI,IAAgC;CACnD,KAAK,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,QAAQ,MAAM,GACzD,OAAO,IAAI,MAAM,YAAY,MAAM,OAAO,IAAI,IAAI,OAAO,CAAC;CAG5D,OAAO,EACL,MAAM,UAAU,OAA2D;EACzE,IAAI,YAAY,iBAAiB,MAAM,MAAM,GAAG,OAAO;EAEvD,MAAM,YAAY,MAAM;EACxB,IAAI,CAAC,WAAW,OAAO;EAEvB,MAAM,QAAQ,UAAU;EACxB,IAAI,CAAC,SAAS,MAAM,WAAW,GAAG,OAAO;EAEzC,KAAK,MAAM,QAAQ,OAAO;GACxB,IAAI,CAAC,OAAO,IAAI,IAAI,GAAG;GACvB,MAAM,UAAU,OAAO,IAAI,IAAI;GAC/B,IAAI,YAAY,MAAM,OAAO;GAC7B,IAAI,SAAS,IAAI,MAAM,MAAM,GAAG,OAAO;EACzC;EACA,OAAO;CACT,EACF;AACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { n as ActionsDefinitionResult, r as AuthorizationProvider } from "./contract-BDPNvjtp.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/authorization/roles.d.ts
|
|
4
|
+
/** A role policy: each role maps to an explicit action list or the `"*"` wildcard. */
|
|
5
|
+
type RolePolicy<Action extends string = string> = Record<string, readonly Action[] | "*">;
|
|
6
|
+
/** Options for {@link rolesAuthorization}. */
|
|
7
|
+
interface RolesAuthorizationOptions<Action extends string = string> {
|
|
8
|
+
/** Role → granted actions. `"*"` grants everything. */
|
|
9
|
+
policy: RolePolicy<Action>;
|
|
10
|
+
/** The product's actions; only `isMutatingAction` is used (for `readonly`). */
|
|
11
|
+
actions: Pick<ActionsDefinitionResult<Action>, "isMutatingAction">;
|
|
12
|
+
/**
|
|
13
|
+
* When `true`, every mutating action is denied regardless of the principal's
|
|
14
|
+
* roles.
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
readonly?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create a role-based {@link AuthorizationProvider}.
|
|
21
|
+
*
|
|
22
|
+
* Decision order:
|
|
23
|
+
* 1. If `readonly` and the action mutates → **deny**.
|
|
24
|
+
* 2. If the principal is `null` → **deny**.
|
|
25
|
+
* 3. If any of the principal's roles grants the action (via `"*"` or an explicit
|
|
26
|
+
* list) → **allow**; otherwise **deny**.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { rolesAuthorization } from "@xtandard/kit/authorization/roles";
|
|
31
|
+
*
|
|
32
|
+
* const authz = rolesAuthorization({
|
|
33
|
+
* actions, // from defineActions(...)
|
|
34
|
+
* policy: { admin: "*", viewer: ["endpoint:read", "message:read"] },
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
declare function rolesAuthorization<Action extends string = string, Resource = unknown>(options: RolesAuthorizationOptions<Action>): AuthorizationProvider<Action, Resource>;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { RolesAuthorizationOptions as n, rolesAuthorization as r, RolePolicy as t };
|
|
41
|
+
//# sourceMappingURL=roles-DLISB4T3.d.mts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { n as ActionsDefinitionResult, r as AuthorizationProvider } from "./contract-BIVzAn4f.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/authorization/roles.d.ts
|
|
4
|
+
/** A role policy: each role maps to an explicit action list or the `"*"` wildcard. */
|
|
5
|
+
type RolePolicy<Action extends string = string> = Record<string, readonly Action[] | "*">;
|
|
6
|
+
/** Options for {@link rolesAuthorization}. */
|
|
7
|
+
interface RolesAuthorizationOptions<Action extends string = string> {
|
|
8
|
+
/** Role → granted actions. `"*"` grants everything. */
|
|
9
|
+
policy: RolePolicy<Action>;
|
|
10
|
+
/** The product's actions; only `isMutatingAction` is used (for `readonly`). */
|
|
11
|
+
actions: Pick<ActionsDefinitionResult<Action>, "isMutatingAction">;
|
|
12
|
+
/**
|
|
13
|
+
* When `true`, every mutating action is denied regardless of the principal's
|
|
14
|
+
* roles.
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
readonly?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create a role-based {@link AuthorizationProvider}.
|
|
21
|
+
*
|
|
22
|
+
* Decision order:
|
|
23
|
+
* 1. If `readonly` and the action mutates → **deny**.
|
|
24
|
+
* 2. If the principal is `null` → **deny**.
|
|
25
|
+
* 3. If any of the principal's roles grants the action (via `"*"` or an explicit
|
|
26
|
+
* list) → **allow**; otherwise **deny**.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { rolesAuthorization } from "@xtandard/kit/authorization/roles";
|
|
31
|
+
*
|
|
32
|
+
* const authz = rolesAuthorization({
|
|
33
|
+
* actions, // from defineActions(...)
|
|
34
|
+
* policy: { admin: "*", viewer: ["endpoint:read", "message:read"] },
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
declare function rolesAuthorization<Action extends string = string, Resource = unknown>(options: RolesAuthorizationOptions<Action>): AuthorizationProvider<Action, Resource>;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { RolesAuthorizationOptions as n, rolesAuthorization as r, RolePolicy as t };
|
|
41
|
+
//# sourceMappingURL=roles-DQbbtUPW.d.cts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll as t };
|