@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 @@
|
|
|
1
|
+
{"version":3,"file":"entry-storage-testing.mjs","names":[],"sources":["../src/storage/testing/conformance.ts","../src/storage/testing/fake-redis.ts"],"sourcesContent":["/**\n * The shared storage conformance suite (ADR 0006). The test API is injected, so the suite runs under\n * vitest, `bun:test` or anything with the same `describe` / `test` / `expect` shape; nothing here\n * imports a test runner.\n *\n * The cases are the union of the products' suites plus the regression cases for every storage fix\n * the kit carries (empty segments, `$` / `#` / unicode keys, many keys, SCAN duplicates, `PSUBSCRIBE`\n * with glob characters, concurrent CAS, `{}` vs `[]`, legacy non-canonical values).\n *\n * @module\n */\n\nimport {\n isCompareAndSwap,\n isWatchable,\n type CompareAndSwapKvStorage,\n type KvStorage,\n type StorageChangeEvent,\n type WatchableKvStorage,\n} from \"../contract.ts\";\nimport { sortableLeaf } from \"../keys.ts\";\n\n/** The matchers the suite uses. vitest's and `bun:test`'s `expect` both satisfy it. */\nexport interface ConformanceMatchers {\n /** `Object.is` equality. */\n toBe(expected: unknown): void;\n /** Deep equality. */\n toEqual(expected: unknown): void;\n /** `=== null`. */\n toBeNull(): void;\n}\n\n/** The injected test API: pass `{ describe, test, expect }` from your runner. */\nexport interface ConformanceTestApi {\n /** Group tests. */\n describe(name: string, fn: () => void): void;\n /** Register one test (the third argument is the timeout in ms). */\n test(name: string, fn: () => Promise<void>, timeout?: number): void;\n /** Make an assertion. */\n expect(actual: unknown): ConformanceMatchers;\n}\n\n/** A factory producing a fresh, **empty** storage (or an empty namespace of one) for each test. */\nexport type MakeStorage = () => KvStorage | Promise<KvStorage>;\n\n/**\n * Write a value in a legacy, non-canonical stored form, bypassing the driver (e.g. a raw SQL\n * `INSERT` of `json` text with unsorted keys, a Mongo document with fields in insertion order).\n * Enables the legacy-value CAS case (ADR 0005).\n */\nexport type SeedLegacy = (storage: KvStorage, key: string, rawJson: string) => Promise<void>;\n\n/**\n * The optional capabilities the driver under test implements. Declare each one: a capability case\n * checks the declaration against the storage itself, so a driver that implements `compareAndSwap`\n * or `watch` without declaring it (or declares one it lacks) fails instead of silently skipping\n * cases. Pass `false` for a capability the driver doesn't have.\n */\nexport interface ConformanceCapabilities {\n /** Run the compare-and-swap cases (the storage must implement `compareAndSwap`). */\n compareAndSwap?: boolean;\n /**\n * Run the watch cases (the storage must implement `watch`). `settleMs` is how long to wait for\n * notifications to arrive (default 50 ms). `removals: false` is for watchers that report every\n * change as `update` (a {@link withWatch} storage, whose notifier gives only a key): a removal must\n * then still produce an event, of any type. Default `true`.\n */\n watch?: boolean | { settleMs?: number; removals?: boolean };\n}\n\n/** Options for {@link runStorageConformance}. */\nexport interface ConformanceOptions {\n /** The injected test API. */\n t: ConformanceTestApi;\n /** Capabilities to exercise. */\n capabilities?: ConformanceCapabilities;\n /** First segment of every key the suite writes (products pass their root, e.g. `\"whk\"`). Default `\"kit\"`. */\n keyRoot?: string;\n /** Per-test timeout in ms (live backends may need more than the runner default). */\n timeout?: number;\n /** Enables the legacy-value CAS case; see {@link SeedLegacy}. */\n seedLegacy?: SeedLegacy;\n}\n\n/** What a {@link ConformanceCase} receives. */\nexport interface ConformanceContext {\n /** A fresh storage from the factory. */\n storage: KvStorage;\n /** Build a key under the suite's root: `key(\"a\", \"b\")` → `\"<root>/a/b\"`. */\n key(...segments: string[]): string;\n /** The injected `expect`. */\n expect: ConformanceTestApi[\"expect\"];\n /** Wait for `ms` (watch notifications, eventual consistency). */\n settle(ms: number): Promise<void>;\n /** The options the suite runs with. */\n options: ConformanceOptions;\n}\n\n/** One named case. Products register extra suites as lists of these. */\nexport interface ConformanceCase {\n /** Test name. */\n name: string;\n /** The test body. */\n run(ctx: ConformanceContext): Promise<void>;\n}\n\n/** Resolve after `ms` milliseconds. */\nexport const settle = (ms: number): Promise<void> => new Promise((r) => setTimeout(r, ms));\n\n/** Narrow to {@link CompareAndSwapKvStorage} or throw a clear error. */\nexport function requireCompareAndSwap(storage: KvStorage): CompareAndSwapKvStorage {\n if (!isCompareAndSwap(storage)) throw new Error(\"storage has no compareAndSwap capability\");\n return storage;\n}\n\n/** Narrow to {@link WatchableKvStorage} or throw a clear error. */\nexport function requireWatchable(storage: KvStorage): WatchableKvStorage {\n if (!isWatchable(storage)) throw new Error(\"storage has no watch capability\");\n return storage;\n}\n\nconst sorted = (keys: string[]): string[] => [...keys].sort();\n\n/**\n * Register `describe(title, …)` with one test per case. Each test gets a fresh storage from `make`.\n * This is how products register their own extra suites next to {@link runStorageConformance}.\n */\nexport function runConformanceCases(\n title: string,\n cases: ConformanceCase[],\n make: MakeStorage,\n options: ConformanceOptions,\n): void {\n const { t, keyRoot = \"kit\", timeout } = options;\n t.describe(title, () => {\n for (const c of cases) {\n t.test(\n c.name,\n async () => {\n const storage = await make();\n try {\n await c.run({\n storage,\n key: (...segments) => [keyRoot, ...segments].join(\"/\"),\n expect: t.expect,\n settle,\n options,\n });\n } finally {\n await (storage as { close?: () => unknown }).close?.();\n }\n },\n timeout,\n );\n }\n });\n}\n\n/** The base-contract cases every driver must pass. */\nexport const contractCases: ConformanceCase[] = [\n {\n name: \"returns null for a missing key\",\n async run({ storage, key, expect }) {\n expect(await storage.getItem(key(\"missing\"))).toBeNull();\n },\n },\n {\n name: \"round-trips objects, arrays, primitives and empty containers\",\n async run({ storage, key, expect }) {\n const values: Record<string, unknown> = {\n object: { url: \"https://x.example/a?b=1\", tags: [\"a\", \"b\"], nested: { x: 1, y: null } },\n array: [\"a\", { b: [1, 2] }],\n string: \"hello\",\n number: 42.5,\n zero: 0,\n boolTrue: true,\n boolFalse: false,\n emptyObject: {},\n emptyArray: [],\n };\n for (const [k, v] of Object.entries(values)) await storage.setItem(key(\"v\", k), v);\n for (const [k, v] of Object.entries(values))\n expect(await storage.getItem(key(\"v\", k))).toEqual(v);\n expect(Array.isArray(await storage.getItem(key(\"v\", \"emptyArray\")))).toBe(true);\n expect(Array.isArray(await storage.getItem(key(\"v\", \"emptyObject\")))).toBe(false);\n },\n },\n {\n name: \"strings that look like JSON stay strings\",\n async run({ storage, key, expect }) {\n const values = [\"123\", \"true\", \"null\", '{\"a\":1}', '\"quoted\"', \"[1]\", \"\"];\n for (const [i, v] of values.entries()) await storage.setItem(key(\"str\", String(i)), v);\n for (const [i, v] of values.entries())\n expect(await storage.getItem(key(\"str\", String(i)))).toBe(v);\n },\n },\n {\n name: \"overwrites an existing key\",\n async run({ storage, key, expect }) {\n await storage.setItem(key(\"k\"), { v: 1 });\n await storage.setItem(key(\"k\"), { v: 2 });\n expect(await storage.getItem(key(\"k\"))).toEqual({ v: 2 });\n },\n },\n {\n name: \"removeItem deletes a key; removing a missing key is a no-op\",\n async run({ storage, key, expect }) {\n await storage.setItem(key(\"k\"), { v: 1 });\n await storage.removeItem(key(\"k\"));\n expect(await storage.getItem(key(\"k\"))).toBeNull();\n expect(await storage.getKeys(key(\"\"))).toEqual([]);\n expect(await storage.removeItem(key(\"nope\"))).toBe(undefined);\n },\n },\n {\n name: \"getKeys lists nested keys under a prefix, isolated from sibling prefixes\",\n async run({ storage, key, expect }) {\n await storage.setItem(key(\"app1\", \"a\"), 1);\n await storage.setItem(key(\"app1\", \"deep\", \"b\"), 2);\n await storage.setItem(key(\"app10\", \"c\"), 3);\n expect(sorted(await storage.getKeys(key(\"app1\", \"\")))).toEqual(\n sorted([key(\"app1\", \"a\"), key(\"app1\", \"deep\", \"b\")]),\n );\n expect(await storage.getKeys(key(\"app10\", \"\"))).toEqual([key(\"app10\", \"c\")]);\n expect(sorted(await storage.getKeys(key(\"app1\")))).toEqual(\n sorted([key(\"app1\", \"a\"), key(\"app1\", \"deep\", \"b\"), key(\"app10\", \"c\")]),\n );\n expect(await storage.getKeys(key(\"nothing\", \"\"))).toEqual([]);\n },\n },\n {\n name: \"keys are case- and accent-sensitive (no collation folding)\",\n async run({ storage, key, expect }) {\n await storage.setItem(key(\"t\", \"Acme\", \"x\"), { v: \"upper\" });\n await storage.setItem(key(\"t\", \"acme\", \"x\"), { v: \"lower\" });\n await storage.setItem(key(\"t\", \"acmé\", \"x\"), { v: \"accent\" });\n expect(await storage.getItem(key(\"t\", \"Acme\", \"x\"))).toEqual({ v: \"upper\" });\n expect(await storage.getItem(key(\"t\", \"acme\", \"x\"))).toEqual({ v: \"lower\" });\n expect(await storage.getItem(key(\"t\", \"acmé\", \"x\"))).toEqual({ v: \"accent\" });\n expect(await storage.getItem(key(\"t\", \"ACME\", \"x\"))).toBeNull();\n expect(await storage.getKeys(key(\"t\", \"Acme\", \"\"))).toEqual([key(\"t\", \"Acme\", \"x\")]);\n expect(await storage.getKeys(key(\"t\", \"acme\", \"\"))).toEqual([key(\"t\", \"acme\", \"x\")]);\n expect(await storage.getKeys(key(\"t\", \"A\"))).toEqual([key(\"t\", \"Acme\", \"x\")]);\n await storage.removeItem(key(\"t\", \"ACME\", \"x\"));\n expect(await storage.getItem(key(\"t\", \"Acme\", \"x\"))).toEqual({ v: \"upper\" });\n },\n },\n {\n name: \"case-distinct tenants are isolated\",\n async run({ storage, key, expect }) {\n for (const tenant of [\"Acme\", \"acme\", \"ACME\"]) {\n await storage.setItem(key(\"tenant\", tenant, \"item\"), { tenant });\n await storage.setItem(key(\"tenants\", tenant), tenant);\n }\n for (const tenant of [\"Acme\", \"acme\", \"ACME\"]) {\n expect(await storage.getItem(key(\"tenant\", tenant, \"item\"))).toEqual({ tenant });\n expect(await storage.getKeys(key(\"tenant\", tenant, \"\"))).toEqual([\n key(\"tenant\", tenant, \"item\"),\n ]);\n }\n expect(sorted(await storage.getKeys(key(\"tenants\", \"\")))).toEqual(\n sorted([\"Acme\", \"acme\", \"ACME\"].map((t) => key(\"tenants\", t))),\n );\n },\n },\n {\n name: \"LIKE / GLOB / Redis-glob / unstorage metacharacters in keys and prefixes are literal\",\n async run({ storage, key, expect }) {\n const specials = [\"%\", \"_\", \"!\", \"\\\\\", \"*\", \"?\", \"[\", \"]\", \":\", \"%25\", \"#\", \"$\", \"[x]\"];\n const keys = specials.map((c) => key(`x${c}y`, \"a\"));\n keys.push(key(\"xzy\", \"a\"), key(\"xay\", \"a\"), key(\"x\", \"y\", \"a\"), key(\"xy\", \"a\"));\n for (const k of keys) await storage.setItem(k, { k });\n for (const k of keys) expect(await storage.getItem(k)).toEqual({ k });\n for (const c of specials) {\n expect(sorted(await storage.getKeys(key(`x${c}y`, \"\")))).toEqual(\n keys.filter((k) => k.startsWith(key(`x${c}y`, \"\"))),\n );\n // A plain prefix ending mid-segment, right after the metacharacter.\n expect(sorted(await storage.getKeys(key(`x${c}`)))).toEqual(\n sorted(keys.filter((k) => k.startsWith(key(`x${c}`)))),\n );\n }\n expect(sorted(await storage.getKeys(key(\"x\")))).toEqual(sorted(keys));\n },\n },\n {\n name: \"keys with ? \\\\ ] : # % %25 stay distinct (no normalization)\",\n async run({ storage, key, expect }) {\n const keys = [\"a?b\", \"ab\", \"a\\\\b\", \"a:b\", \"a]b\", \"a#b\", \"a%b\", \"a%25b\", \"a/b\"].map((s) =>\n key(\"s\", s),\n );\n for (const [i, k] of keys.entries()) await storage.setItem(k, { i });\n for (const [i, k] of keys.entries()) expect(await storage.getItem(k)).toEqual({ i });\n expect(sorted(await storage.getKeys(key(\"s\", \"\")))).toEqual(sorted(keys));\n expect(await storage.getKeys(key(\"s\", \"a?\"))).toEqual([key(\"s\", \"a?b\")]);\n expect(await storage.getKeys(key(\"s\", \"a%25\"))).toEqual([key(\"s\", \"a%25b\")]);\n expect(await storage.getItem(key(\"s\", \"a%b\"))).toEqual({ i: 6 });\n },\n },\n {\n name: \"keys with $ (trailing, inner, alone) round-trip and are listed\",\n async run({ storage, key, expect }) {\n const keys = [\n key(\"d\", \"end$\"),\n key(\"d\", \"a$b\"),\n key(\"d\", \"$\"),\n key(\"d$\", \"x\"),\n key(\"d\", \"$$\"),\n ];\n for (const [i, k] of keys.entries()) await storage.setItem(k, i);\n for (const [i, k] of keys.entries()) expect(await storage.getItem(k)).toBe(i);\n expect(sorted(await storage.getKeys(key(\"d\")))).toEqual(sorted(keys));\n expect(await storage.getKeys(key(\"d$\", \"\"))).toEqual([key(\"d$\", \"x\")]);\n await storage.removeItem(key(\"d\", \"end$\"));\n expect(await storage.getItem(key(\"d\", \"end$\"))).toBeNull();\n },\n },\n {\n name: \"keys differing only by trailing spaces stay distinct\",\n async run({ storage, key, expect }) {\n const keys = [key(\"sp\", \"a\"), key(\"sp\", \"a \"), key(\"sp\", \"a \"), key(\"sp\", \"a\", \" \")];\n for (const [i, k] of keys.entries()) await storage.setItem(k, { i });\n for (const [i, k] of keys.entries()) expect(await storage.getItem(k)).toEqual({ i });\n expect(sorted(await storage.getKeys(key(\"sp\", \"\")))).toEqual(sorted(keys));\n expect(sorted(await storage.getKeys(key(\"sp\", \"a \")))).toEqual(\n sorted([key(\"sp\", \"a \"), key(\"sp\", \"a \")]),\n );\n await storage.removeItem(key(\"sp\", \"a \"));\n expect(await storage.getItem(key(\"sp\", \"a\"))).toEqual({ i: 0 });\n expect(await storage.getItem(key(\"sp\", \"a \"))).toBeNull();\n },\n },\n {\n name: \"unicode keys (emoji, CJK, NFC ≠ NFD) round-trip and stay distinct\",\n async run({ storage, key, expect }) {\n const nfc = \"café\";\n const nfd = \"café\";\n const keys = [\n key(\"u\", \"🚀\"),\n key(\"u\", \"日本語\"),\n key(\"u\", nfc),\n key(\"u\", nfd),\n key(\"u\", \"cafe\"),\n ];\n for (const [i, k] of keys.entries()) await storage.setItem(k, { i });\n for (const [i, k] of keys.entries()) expect(await storage.getItem(k)).toEqual({ i });\n expect(sorted(await storage.getKeys(key(\"u\", \"\")))).toEqual(sorted(keys));\n expect(await storage.getKeys(key(\"u\", \"日\"))).toEqual([key(\"u\", \"日本語\")]);\n },\n },\n {\n name: \"empty key segments are distinct keys (a//b ≠ a/b, trailing /)\",\n async run({ storage, key, expect }) {\n const keys = [\n key(\"e\", \"\", \"b\"),\n key(\"e\", \"b\"),\n key(\"e\", \"\"),\n key(\"e\", \"x\", \"\"),\n key(\"e\", \"x\"),\n ];\n for (const [i, k] of keys.entries()) await storage.setItem(k, { i });\n for (const [i, k] of keys.entries()) expect(await storage.getItem(k)).toEqual({ i });\n expect(sorted(await storage.getKeys(key(\"e\", \"\")))).toEqual(sorted(keys));\n expect(await storage.getKeys(key(\"e\", \"\", \"\"))).toEqual([key(\"e\", \"\", \"b\")]);\n expect(sorted(await storage.getKeys(key(\"e\", \"x\")))).toEqual(\n sorted([key(\"e\", \"x\", \"\"), key(\"e\", \"x\")]),\n );\n await storage.removeItem(key(\"e\", \"\", \"b\"));\n expect(await storage.getItem(key(\"e\", \"b\"))).toEqual({ i: 1 });\n },\n },\n {\n name: \"zero-padded sortable leaves list in chronological order once sorted\",\n async run({ storage, key, expect }) {\n const times = [1_700_000_000_123, 5, 1_700_000_000_122, 99_999, 1_600_000_000_000];\n for (const [i, ms] of times.entries())\n await storage.setItem(key(\"due\", sortableLeaf(ms, `id${i}`)), i);\n const listed = sorted(await storage.getKeys(key(\"due\", \"\")));\n expect(listed).toEqual(\n [...times.entries()]\n .sort(([, a], [, b]) => a - b)\n .map(([i, ms]) => key(\"due\", sortableLeaf(ms, `id${i}`))),\n );\n },\n },\n {\n name: \"lists many keys (pagination) without duplicates\",\n async run({ storage, key, expect }) {\n const keys = Array.from({ length: 250 }, (_, i) => key(\"bulk\", String(i).padStart(3, \"0\")));\n await Promise.all(keys.map((k, i) => storage.setItem(k, { i })));\n const listed = await storage.getKeys(key(\"bulk\", \"\"));\n expect(listed.length).toBe(250);\n expect(new Set(listed).size).toBe(250);\n expect(sorted(listed)).toEqual(keys);\n },\n },\n];\n\n/** The compare-and-swap cases (`capabilities.compareAndSwap`). */\nexport const compareAndSwapCases: ConformanceCase[] = [\n {\n name: \"swaps only when the expectation holds (absence, mismatch, match)\",\n async run({ storage, key, expect }) {\n const cas = requireCompareAndSwap(storage);\n const k = key(\"cas\");\n expect(\n await cas.compareAndSwap<unknown>({ key: k, expected: { v: 1 }, next: { v: 2 } }),\n ).toBe(false);\n expect(await cas.getItem(k)).toBeNull();\n expect(\n await cas.compareAndSwap<unknown>({ key: k, expected: null, next: { v: 1, tags: [\"a\"] } }),\n ).toBe(true);\n expect(await cas.compareAndSwap<unknown>({ key: k, expected: null, next: { v: 9 } })).toBe(\n false,\n );\n expect(\n await cas.compareAndSwap<unknown>({ key: k, expected: { v: 0 }, next: { v: 2 } }),\n ).toBe(false);\n expect(\n await cas.compareAndSwap<unknown>({ key: k, expected: { v: 1 }, next: { v: 2 } }),\n ).toBe(false);\n expect(\n await cas.compareAndSwap<unknown>({\n key: k,\n expected: { v: 1, tags: [\"a\"] },\n next: { v: 2 },\n }),\n ).toBe(true);\n expect(await cas.getItem(k)).toEqual({ v: 2 });\n },\n },\n {\n name: \"compares structurally: object key order is ignored, arrays are ordered\",\n async run({ storage, key, expect }) {\n const cas = requireCompareAndSwap(storage);\n const k = key(\"order\");\n await cas.setItem(k, { b: 1, a: { d: [1, 2], c: null } });\n expect(\n await cas.compareAndSwap<unknown>({\n key: k,\n expected: { a: { c: null, d: [2, 1] }, b: 1 },\n next: 0,\n }),\n ).toBe(false);\n expect(\n await cas.compareAndSwap<unknown>({\n key: k,\n expected: { a: { c: null, d: [1, 2] }, b: 1 },\n next: { n: 1 },\n }),\n ).toBe(true);\n expect(await cas.getItem(k)).toEqual({ n: 1 });\n },\n },\n {\n name: \"{} and [] are different values\",\n async run({ storage, key, expect }) {\n const cas = requireCompareAndSwap(storage);\n await cas.setItem(key(\"obj\"), {});\n await cas.setItem(key(\"arr\"), []);\n expect(await cas.compareAndSwap<unknown>({ key: key(\"obj\"), expected: [], next: 1 })).toBe(\n false,\n );\n expect(await cas.compareAndSwap<unknown>({ key: key(\"arr\"), expected: {}, next: 1 })).toBe(\n false,\n );\n expect(await cas.compareAndSwap<unknown>({ key: key(\"obj\"), expected: {}, next: 2 })).toBe(\n true,\n );\n expect(await cas.compareAndSwap<unknown>({ key: key(\"arr\"), expected: [], next: 3 })).toBe(\n true,\n );\n expect(await cas.getItem(key(\"obj\"))).toBe(2);\n expect(await cas.getItem(key(\"arr\"))).toBe(3);\n },\n },\n {\n name: \"swaps primitives\",\n async run({ storage, key, expect }) {\n const cas = requireCompareAndSwap(storage);\n await cas.setItem(key(\"p\"), \"a\");\n expect(await cas.compareAndSwap<unknown>({ key: key(\"p\"), expected: \"b\", next: \"c\" })).toBe(\n false,\n );\n expect(await cas.compareAndSwap<unknown>({ key: key(\"p\"), expected: \"a\", next: 7 })).toBe(\n true,\n );\n expect(await cas.compareAndSwap<unknown>({ key: key(\"p\"), expected: 7, next: false })).toBe(\n true,\n );\n expect(await cas.getItem(key(\"p\"))).toBe(false);\n },\n },\n {\n name: \"concurrent claims of an absent key: exactly one wins\",\n async run({ storage, key, expect }) {\n const cas = requireCompareAndSwap(storage);\n const results = await Promise.all(\n Array.from({ length: 8 }, (_, i) =>\n cas.compareAndSwap<unknown>({ key: key(\"claim\"), expected: null, next: { by: i } }),\n ),\n );\n expect(results.filter(Boolean).length).toBe(1);\n const winner = results.indexOf(true);\n expect(await cas.getItem(key(\"claim\"))).toEqual({ by: winner });\n },\n },\n {\n name: \"concurrent swaps from the same expectation: exactly one wins\",\n async run({ storage, key, expect }) {\n const cas = requireCompareAndSwap(storage);\n await cas.setItem(key(\"race\"), { n: 0, meta: { b: 1, a: 2 } });\n const results = await Promise.all(\n Array.from({ length: 8 }, (_, i) =>\n cas.compareAndSwap<unknown>({\n key: key(\"race\"),\n expected: { meta: { a: 2, b: 1 }, n: 0 },\n next: { n: i + 1 },\n }),\n ),\n );\n expect(results.filter(Boolean).length).toBe(1);\n },\n },\n {\n name: \"legacy non-canonical stored values: read, listed and swapped (ADR 0005)\",\n async run({ storage, key, expect, options }) {\n const seed = options.seedLegacy;\n if (!seed) return;\n const cas = requireCompareAndSwap(storage);\n const k = key(\"legacy\", \"v\");\n const value = { b: 1, a: { d: [1, { z: 1, y: 2 }], c: \"x\" } };\n await seed(storage, k, '{\"b\":1,\"a\":{\"d\":[1,{\"z\":1,\"y\":2}],\"c\":\"x\"}}');\n expect(await cas.getItem(k)).toEqual(value);\n expect(await cas.getKeys(key(\"legacy\", \"\"))).toEqual([k]);\n expect(await cas.compareAndSwap<unknown>({ key: k, expected: { b: 2 }, next: 0 })).toBe(\n false,\n );\n expect(await cas.compareAndSwap<unknown>({ key: k, expected: null, next: 0 })).toBe(false);\n expect(await cas.compareAndSwap<unknown>({ key: k, expected: value, next: { n: 1 } })).toBe(\n true,\n );\n expect(await cas.getItem(k)).toEqual({ n: 1 });\n // Concurrent swaps over a legacy value: still exactly one winner.\n const k2 = key(\"legacy\", \"race\");\n await seed(storage, k2, '{\"b\":1,\"a\":2}');\n const results = await Promise.all(\n Array.from({ length: 6 }, (_, i) =>\n cas.compareAndSwap<unknown>({ key: k2, expected: { a: 2, b: 1 }, next: { i } }),\n ),\n );\n expect(results.filter(Boolean).length).toBe(1);\n },\n },\n];\n\n/** The watch cases (`capabilities.watch`). */\nexport const watchCases: ConformanceCase[] = [\n {\n name: \"notifies updates and removals under the prefix only\",\n async run({ storage, key, expect, settle, options }) {\n const ms = settleMs(options);\n const watchable = requireWatchable(storage);\n const events: StorageChangeEvent[] = [];\n const off = await watchable.watch(key(\"w\", \"\"), (e) => events.push(e));\n await settle(ms);\n await watchable.setItem(key(\"w\", \"a\"), { v: 1 });\n await watchable.setItem(key(\"other\", \"b\"), { v: 1 });\n // Filesystem watchers coalesce a create immediately followed by a delete.\n await settle(ms);\n const beforeRemove = events.length;\n await watchable.removeItem(key(\"w\", \"a\"));\n await settle(ms);\n await off();\n expect(events.some((e) => e.type === \"update\" && e.key === key(\"w\", \"a\"))).toBe(true);\n if (reportsRemovals(options)) {\n expect(events.some((e) => e.type === \"remove\" && e.key === key(\"w\", \"a\"))).toBe(true);\n } else {\n expect(events.slice(beforeRemove).some((e) => e.key === key(\"w\", \"a\"))).toBe(true);\n }\n expect(events.every((e) => e.key.startsWith(key(\"w\", \"\")))).toBe(true);\n },\n },\n {\n name: \"a prefix with glob characters ([ ] * ? \\\\) matches literally\",\n async run({ storage, key, expect, settle, options }) {\n const ms = settleMs(options);\n const watchable = requireWatchable(storage);\n const prefix = key(\"g[x]*?\\\\\", \"\");\n const events: StorageChangeEvent[] = [];\n const off = await watchable.watch(prefix, (e) => events.push(e));\n await settle(ms);\n await watchable.setItem(`${prefix}a`, 1);\n await watchable.setItem(key(\"gx\", \"b\"), 1);\n await settle(ms);\n await off();\n expect(events.some((e) => e.type === \"update\" && e.key === `${prefix}a`)).toBe(true);\n expect(events.every((e) => e.key.startsWith(prefix))).toBe(true);\n },\n },\n {\n name: \"unsubscribe stops notifications\",\n async run({ storage, key, expect, settle, options }) {\n const ms = settleMs(options);\n const watchable = requireWatchable(storage);\n const events: StorageChangeEvent[] = [];\n const off = await watchable.watch(key(\"off\", \"\"), (e) => events.push(e));\n await settle(ms);\n await off();\n await settle(ms);\n await watchable.setItem(key(\"off\", \"a\"), 1);\n await settle(ms);\n expect(events.length).toBe(0);\n },\n },\n];\n\n/**\n * The declared capabilities match the storage: an undeclared `compareAndSwap` or `watch` would skip\n * those cases silently, and a declared one the storage lacks would fail them obscurely.\n */\nexport const capabilitiesCase: ConformanceCase = {\n name: \"declared capabilities match the storage\",\n async run({ storage, expect, options }) {\n const declared = options.capabilities ?? {};\n const problems: string[] = [];\n const check = (name: \"compareAndSwap\" | \"watch\", has: boolean): void => {\n const value = declared[name];\n if (value === undefined && has) {\n problems.push(\n `implements ${name} but capabilities.${name} is not declared (true to run its cases, false to skip)`,\n );\n } else if (value && !has) {\n problems.push(`declares capabilities.${name} but does not implement it`);\n }\n };\n check(\"compareAndSwap\", isCompareAndSwap(storage));\n check(\"watch\", isWatchable(storage));\n expect(problems).toEqual([]);\n },\n};\n\nconst settleMs = (options: ConformanceOptions): number => {\n const watch = options.capabilities?.watch;\n return typeof watch === \"object\" ? (watch.settleMs ?? 50) : 50;\n};\n\nconst reportsRemovals = (options: ConformanceOptions): boolean => {\n const watch = options.capabilities?.watch;\n return typeof watch === \"object\" ? watch.removals !== false : true;\n};\n\n/**\n * Register the full conformance suite for one driver: the base contract, plus the\n * compare-and-swap and watch cases when `capabilities` says the driver has them.\n *\n * @example\n * ```ts\n * import { describe, expect, test } from \"vitest\"; // or \"bun:test\"\n * import { runStorageConformance } from \"@xtandard/kit/storage/testing\";\n * import { createMemoryStorage } from \"@xtandard/kit/storage/memory\";\n *\n * runStorageConformance(\"memory\", () => createMemoryStorage(), {\n * t: { describe, test, expect },\n * capabilities: { compareAndSwap: true, watch: true },\n * keyRoot: \"whk\",\n * });\n * ```\n */\nexport function runStorageConformance(\n name: string,\n make: MakeStorage,\n options: ConformanceOptions,\n): void {\n runConformanceCases(\n `KvStorage contract: ${name}`,\n [capabilitiesCase, ...contractCases],\n make,\n options,\n );\n if (options.capabilities?.compareAndSwap) {\n runConformanceCases(`compareAndSwap: ${name}`, compareAndSwapCases, make, options);\n }\n if (options.capabilities?.watch) {\n runConformanceCases(`watch: ${name}`, watchCases, make, options);\n }\n}\n","/**\n * An in-memory node-redis look-alike for tests (semi-public): string and RedisJSON values, the kit\n * redis driver's Lua scripts emulated, sorted sets (`zAdd`/`zRem`/`zRangeByScore`), a SCAN that\n * yields keys more than once (as Redis may) and PSUBSCRIBE with real glob matching. Products run the\n * conformance suite on their wrapped redis driver with it, without a live server; a product's own\n * Lua scripts can be emulated through {@link FakeRedisOptions.eval}.\n *\n * @module\n */\n\nimport type { RedisLike, RedisStorageOptions } from \"../redis.ts\";\n\n/** The fake's state, exposed for assertions. */\nexport type FakeRedis = RedisLike & {\n /** String and RedisJSON values by full key. */\n strings: Map<string, string>;\n /** Every PSUBSCRIBE pattern received. */\n patterns: string[];\n /** Sorted sets: member → score, by key. */\n zsets: Map<string, Map<string, number>>;\n};\n\n/** Options for {@link fakeRedis}. */\nexport interface FakeRedisOptions {\n /**\n * Emulate a product's own Lua scripts: return a value to answer `EVAL`, or `undefined` to fall back\n * to the kit driver's scripts.\n */\n eval?: (script: string, keys: string[], args: string[], fake: FakeRedis) => unknown;\n}\n\n/** Redis glob → RegExp (backslash escapes, `*`, `?`, `[…]`). */\nfunction globToRegExp(glob: string): RegExp {\n let re = \"\";\n for (let i = 0; i < glob.length; i++) {\n const c = glob[i]!;\n if (c === \"\\\\\") re += `\\\\${glob[++i] ?? \"\"}`.replace(/\\\\([^\\w])/, (_, x: string) => `\\\\${x}`);\n else if (c === \"*\") re += \".*\";\n else if (c === \"?\") re += \".\";\n else if (c === \"[\") {\n const end = glob.indexOf(\"]\", i + 1);\n re += `[${glob.slice(i + 1, end).replace(/\\\\/g, \"\\\\\\\\\")}]`;\n i = end;\n } else re += c.replace(/[.+^${}()|\\\\/]/g, \"\\\\$&\");\n }\n return new RegExp(`^${re}$`, \"s\");\n}\n\n/**\n * An in-memory node-redis look-alike: string and RedisJSON values, the driver's two Lua scripts\n * emulated, a SCAN that yields every key twice (Redis may repeat keys), and PSUBSCRIBE with real\n * glob matching (so an unescaped prefix would miss events).\n */\nexport function fakeRedis(options: FakeRedisOptions = {}): FakeRedis {\n return makeFakeRedis(options);\n}\n\nfunction makeFakeRedis(options: FakeRedisOptions): RedisLike & {\n strings: Map<string, string>;\n patterns: string[];\n zsets: Map<string, Map<string, number>>;\n} {\n const strings = new Map<string, string>();\n const zsets = new Map<string, Map<string, number>>();\n const subs = new Set<{ re: RegExp; listener: (m: string, ch: string) => void }>();\n const patterns: string[] = [];\n const emit = (key: string, event: string) => {\n for (const s of subs) {\n const ch = `__keyspace@0__:${key}`;\n if (s.re.test(ch)) queueMicrotask(() => s.listener(event, ch));\n }\n };\n const self: RedisLike & {\n strings: Map<string, string>;\n patterns: string[];\n zsets: Map<string, Map<string, number>>;\n } = {\n strings,\n patterns,\n zsets,\n async zAdd(key, members) {\n const set = zsets.get(key) ?? new Map<string, number>();\n for (const m of [members].flat()) set.set(m.value, m.score);\n zsets.set(key, set);\n },\n async zRem(key, members) {\n for (const m of [members].flat()) zsets.get(key)?.delete(m);\n },\n async zRangeByScore(key, min, max) {\n const bound = (v: number | string) =>\n v === \"-inf\" ? -Infinity : v === \"+inf\" ? Infinity : Number(v);\n const lo = bound(min);\n const hi = bound(max);\n return [...(zsets.get(key) ?? new Map<string, number>())]\n .filter(([, score]) => score >= lo && score <= hi)\n .sort((a, b) => a[1] - b[1])\n .map(([member]) => member);\n },\n isOpen: false,\n on: () => self,\n async connect() {\n self.isOpen = true;\n },\n async quit() {\n self.isOpen = false;\n },\n async disconnect() {\n self.isOpen = false;\n },\n async get(key) {\n return strings.get(key) ?? null;\n },\n async set(key, value) {\n strings.set(key, value);\n emit(key, \"set\");\n },\n async del(key) {\n for (const k of [key].flat()) if (strings.delete(k)) emit(k, \"del\");\n },\n json: {\n async get(key) {\n const raw = strings.get(key);\n return raw === undefined ? null : JSON.parse(raw);\n },\n async set(key, _path, value) {\n strings.set(key, JSON.stringify(value));\n emit(key, \"json.set\");\n },\n },\n async eval(script, opts = {}) {\n const [key] = opts.keys ?? [];\n const args = opts.arguments ?? [];\n const custom = options.eval?.(script, opts.keys ?? [], args, self);\n if (custom !== undefined) return custom;\n const raw = strings.get(key!) ?? null;\n if (!script.includes(\"ARGV[4]\")) return raw;\n const [mode, expected, next] = args;\n if (mode === \"0\" ? raw !== null : raw !== expected) return 0;\n strings.set(key!, next!);\n emit(key!, \"set\");\n return 1;\n },\n async *scanIterator(opts = {}) {\n const re = globToRegExp(opts.MATCH ?? \"*\");\n const keys = [...strings.keys()].filter((k) => re.test(k));\n yield keys;\n yield keys.slice(0, 3); // SCAN may return a key more than once\n },\n duplicate() {\n const sub = fakeRedisSubscriber();\n return sub;\n },\n async pSubscribe() {},\n };\n function fakeRedisSubscriber(): RedisLike {\n return {\n ...self,\n isOpen: false,\n async connect() {},\n async pSubscribe(pattern, listener) {\n patterns.push(pattern);\n const entry = { re: globToRegExp(pattern), listener };\n subs.add(entry);\n this.disconnect = async () => {\n subs.delete(entry);\n };\n },\n };\n }\n return self;\n}\n\n/** Cast a fake to the `client` option type of the redis driver factories. */\nexport const asRedisClient = (c: RedisLike) =>\n c as unknown as NonNullable<RedisStorageOptions[\"client\"]>;\n"],"mappings":";;;;;;;;;;;;;;AA2GA,MAAa,UAAU,OAA8B,IAAI,SAAS,MAAM,WAAW,GAAG,EAAE,CAAC;;AAGzF,SAAgB,sBAAsB,SAA6C;CACjF,IAAI,CAAC,iBAAiB,OAAO,GAAG,MAAM,IAAI,MAAM,0CAA0C;CAC1F,OAAO;AACT;;AAGA,SAAgB,iBAAiB,SAAwC;CACvE,IAAI,CAAC,YAAY,OAAO,GAAG,MAAM,IAAI,MAAM,iCAAiC;CAC5E,OAAO;AACT;AAEA,MAAM,UAAU,SAA6B,CAAC,GAAG,IAAI,EAAE,KAAK;;;;;AAM5D,SAAgB,oBACd,OACA,OACA,MACA,SACM;CACN,MAAM,EAAE,GAAG,UAAU,OAAO,YAAY;CACxC,EAAE,SAAS,aAAa;EACtB,KAAK,MAAM,KAAK,OACd,EAAE,KACA,EAAE,MACF,YAAY;GACV,MAAM,UAAU,MAAM,KAAK;GAC3B,IAAI;IACF,MAAM,EAAE,IAAI;KACV;KACA,MAAM,GAAG,aAAa,CAAC,SAAS,GAAG,QAAQ,EAAE,KAAK,GAAG;KACrD,QAAQ,EAAE;KACV;KACA;IACF,CAAC;GACH,UAAU;IACR,MAAO,QAAsC,QAAQ;GACvD;EACF,GACA,OACF;CAEJ,CAAC;AACH;;AAGA,MAAa,gBAAmC;CAC9C;EACE,MAAM;EACN,MAAM,IAAI,EAAE,SAAS,KAAK,UAAU;GAClC,OAAO,MAAM,QAAQ,QAAQ,IAAI,SAAS,CAAC,CAAC,EAAE,SAAS;EACzD;CACF;CACA;EACE,MAAM;E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K;GACjC,IAAI,CAAC,OAAO,SAAS,SAAS,GAAG,OAAO;GACxC,MAAM,CAAC,MAAM,UAAU,QAAQ;GAC/B,IAAI,SAAS,MAAM,QAAQ,OAAO,QAAQ,UAAU,OAAO;GAC3D,QAAQ,IAAI,KAAM,IAAK;GACvB,KAAK,KAAM,KAAK;GAChB,OAAO;EACT;EACA,OAAO,aAAa,OAAO,CAAC,GAAG;GAC7B,MAAM,KAAK,aAAa,KAAK,SAAS,GAAG;GACzC,MAAM,OAAO,CAAC,GAAG,QAAQ,KAAK,CAAC,EAAE,QAAQ,MAAM,GAAG,KAAK,CAAC,CAAC;GACzD,MAAM;GACN,MAAM,KAAK,MAAM,GAAG,CAAC;EACvB;EACA,YAAY;GAEV,OADY,oBACH;EACX;EACA,MAAM,aAAa,CAAC;CACtB;CACA,SAAS,sBAAiC;EACxC,OAAO;GACL,GAAG;GACH,QAAQ;GACR,MAAM,UAAU,CAAC;GACjB,MAAM,WAAW,SAAS,UAAU;IAClC,SAAS,KAAK,OAAO;IACrB,MAAM,QAAQ;KAAE,IAAI,aAAa,OAAO;KAAG;IAAS;IACpD,KAAK,IAAI,KAAK;IACd,KAAK,aAAa,YAAY;KAC5B,KAAK,OAAO,KAAK;IACnB;GACF;EACF;CACF;CACA,OAAO;AACT;;AAGA,MAAa,iBAAiB,MAC5B"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/storage/unstorage.ts
|
|
3
|
+
const hex = (c) => `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`;
|
|
4
|
+
/** Encode `key` (empty segments as `%`) with the given `$` spelling. */
|
|
5
|
+
function encodeKey(key, dollars) {
|
|
6
|
+
const encoded = key.split("/").map((s) => s === "" ? "%" : s.replace(dollars === "all" ? /[%:\\?$]/g : /[%:\\?]/g, hex)).join("/");
|
|
7
|
+
return dollars === "trailing" ? encoded.replace(/\$$/, "%24") : encoded;
|
|
8
|
+
}
|
|
9
|
+
/** The key as written today: trailing `$` encoded, empty segments as `%`. */
|
|
10
|
+
const toUnstorageKey = (key) => encodeKey(key, "trailing");
|
|
11
|
+
/**
|
|
12
|
+
* Legacy spellings of `key` that differ from {@link toUnstorageKey}: the raw trailing `$` (wh, fl,
|
|
13
|
+
* au, li) and the every-`$`-encoded form (en). Keys with empty segments have none: those were
|
|
14
|
+
* collapsed onto another key.
|
|
15
|
+
*/
|
|
16
|
+
function legacyKeys(key) {
|
|
17
|
+
if (!key.includes("$") || key.split("/").includes("")) return [];
|
|
18
|
+
const current = toUnstorageKey(key);
|
|
19
|
+
return [...new Set([encodeKey(key, "none"), encodeKey(key, "all")])].filter((k) => k !== current);
|
|
20
|
+
}
|
|
21
|
+
/** Convert an unstorage `:`-separated key back to the caller's `/`-separated form. */
|
|
22
|
+
const fromUnstorageKey = (key) => key.split(":").map((s) => s === "%" ? "" : s.replace(/%(25|3A|5C|3F|24)/g, (_, h) => String.fromCharCode(Number.parseInt(h, 16)))).join("/");
|
|
23
|
+
/**
|
|
24
|
+
* Create a {@link KvStorage} backed by an unstorage `Storage` instance. unstorage serializes JSON
|
|
25
|
+
* values, so values round-trip structurally; missing keys read back as `null`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { createUnstorageStorage } from "@xtandard/kit/storage/unstorage";
|
|
30
|
+
* import { createStorage } from "unstorage";
|
|
31
|
+
* import fsDriver from "unstorage/drivers/fs";
|
|
32
|
+
*
|
|
33
|
+
* const storage = createUnstorageStorage({
|
|
34
|
+
* storage: createStorage({ driver: fsDriver({ base: "./data" }) }),
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function createUnstorageStorage(options) {
|
|
39
|
+
const { storage } = options;
|
|
40
|
+
const read = async (key) => {
|
|
41
|
+
const value = await storage.getItem(key);
|
|
42
|
+
return value === void 0 ? null : value;
|
|
43
|
+
};
|
|
44
|
+
const removeLegacy = async (key) => {
|
|
45
|
+
for (const legacy of legacyKeys(key)) await storage.removeItem(legacy);
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
async getItem(key) {
|
|
49
|
+
const value = await read(toUnstorageKey(key));
|
|
50
|
+
if (value !== null) return value;
|
|
51
|
+
for (const legacy of legacyKeys(key)) {
|
|
52
|
+
const old = await read(legacy);
|
|
53
|
+
if (old !== null) return old;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
},
|
|
57
|
+
async setItem(key, value) {
|
|
58
|
+
const stored = typeof value === "string" ? JSON.stringify(value) : value;
|
|
59
|
+
await storage.setItem(toUnstorageKey(key), stored);
|
|
60
|
+
await removeLegacy(key);
|
|
61
|
+
},
|
|
62
|
+
async removeItem(key) {
|
|
63
|
+
await storage.removeItem(toUnstorageKey(key));
|
|
64
|
+
await removeLegacy(key);
|
|
65
|
+
},
|
|
66
|
+
async getKeys(prefix) {
|
|
67
|
+
const parent = prefix.slice(0, prefix.lastIndexOf("/") + 1);
|
|
68
|
+
const bases = parent === "" ? [""] : [...new Set([encodeKey(parent, "none"), encodeKey(parent, "all")])].map((b) => `${b.slice(0, -2)}/`);
|
|
69
|
+
const out = /* @__PURE__ */ new Set();
|
|
70
|
+
for (const base of bases) for (const key of await storage.getKeys(base)) out.add(fromUnstorageKey(key));
|
|
71
|
+
return [...out].filter((key) => key.startsWith(prefix));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
exports.createUnstorageStorage = createUnstorageStorage;
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=entry-storage-unstorage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-storage-unstorage.cjs","names":[],"sources":["../src/storage/unstorage.ts"],"sourcesContent":["/**\n * unstorage driver: wraps an [unstorage](https://unstorage.unjs.io) `Storage` (any driver) as a\n * {@link KvStorage}. The caller builds and configures the unstorage instance; this module only\n * imports its type, so `unstorage` stays an optional peer.\n *\n * unstorage normalizes keys: `/` and `\\` become `:`, anything after `?` is dropped, repeated and\n * leading/trailing separators collapse, and keys ending in `$` are meta keys hidden from\n * `getKeys`. So this driver encodes:\n *\n * - `%`, `:`, `\\` and `?` as `%25`, `%3A`, `%5C`, `%3F` (every copy did this);\n * - a **trailing** `$` as `%24` (only that one; a `$` elsewhere is stored as-is, ADR 0005);\n * - an empty segment (`a//b`, `a/`) as a lone `%` (which a literal `%` never produces).\n *\n * String values are written JSON-encoded (`\"\\\"123\\\"\"`), because unstorage reads strings back\n * through `destr`, which would turn `\"123\"` into `123`; older raw strings still read as before.\n *\n * Reads fall back to the legacy spellings of a key containing `$` (the raw trailing `$` of the\n * older copies, and the every-`$`-encoded form), and `getKeys` lists both, so data written by\n * earlier product releases stays readable. Because unstorage matches whole segments only,\n * `getKeys(prefix)` lists the prefix's parent segment and filters by the full prefix.\n *\n * No `compareAndSwap`: unstorage drivers share no atomic primitive.\n *\n * @module\n */\n\nimport type { Storage } from \"unstorage\";\nimport type { KvStorage } from \"./contract.ts\";\n\n/** Options for {@link createUnstorageStorage}. */\nexport interface UnstorageStorageOptions {\n /** A pre-constructed unstorage `Storage` instance (any driver). */\n storage: Storage;\n}\n\n/** The unstorage storage (no optional capabilities). */\nexport type UnstorageKvStorage = KvStorage;\n\nconst hex = (c: string): string =>\n `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, \"0\")}`;\n\n/** How a spelling writes `$`: only a trailing one (current), never (wh/fl/au/li) or always (en). */\ntype DollarMode = \"trailing\" | \"none\" | \"all\";\n\n/** Encode `key` (empty segments as `%`) with the given `$` spelling. */\nfunction encodeKey(key: string, dollars: DollarMode): string {\n const encoded = key\n .split(\"/\")\n .map((s) => (s === \"\" ? \"%\" : s.replace(dollars === \"all\" ? /[%:\\\\?$]/g : /[%:\\\\?]/g, hex)))\n .join(\"/\");\n return dollars === \"trailing\" ? encoded.replace(/\\$$/, \"%24\") : encoded;\n}\n\n/** The key as written today: trailing `$` encoded, empty segments as `%`. */\nexport const toUnstorageKey = (key: string): string => encodeKey(key, \"trailing\");\n\n/**\n * Legacy spellings of `key` that differ from {@link toUnstorageKey}: the raw trailing `$` (wh, fl,\n * au, li) and the every-`$`-encoded form (en). Keys with empty segments have none: those were\n * collapsed onto another key.\n */\nfunction legacyKeys(key: string): string[] {\n if (!key.includes(\"$\") || key.split(\"/\").includes(\"\")) return [];\n const current = toUnstorageKey(key);\n return [...new Set([encodeKey(key, \"none\"), encodeKey(key, \"all\")])].filter((k) => k !== current);\n}\n\n/** Convert an unstorage `:`-separated key back to the caller's `/`-separated form. */\nexport const fromUnstorageKey = (key: string): string =>\n key\n .split(\":\")\n .map((s) =>\n s === \"%\"\n ? \"\"\n : s.replace(/%(25|3A|5C|3F|24)/g, (_, h: string) =>\n String.fromCharCode(Number.parseInt(h, 16)),\n ),\n )\n .join(\"/\");\n\n/**\n * Create a {@link KvStorage} backed by an unstorage `Storage` instance. unstorage serializes JSON\n * values, so values round-trip structurally; missing keys read back as `null`.\n *\n * @example\n * ```ts\n * import { createUnstorageStorage } from \"@xtandard/kit/storage/unstorage\";\n * import { createStorage } from \"unstorage\";\n * import fsDriver from \"unstorage/drivers/fs\";\n *\n * const storage = createUnstorageStorage({\n * storage: createStorage({ driver: fsDriver({ base: \"./data\" }) }),\n * });\n * ```\n */\nexport function createUnstorageStorage(options: UnstorageStorageOptions): UnstorageKvStorage {\n const { storage } = options;\n\n const read = async <T>(key: string): Promise<T | null> => {\n const value = await storage.getItem<T>(key);\n return value === undefined ? null : value;\n };\n const removeLegacy = async (key: string): Promise<void> => {\n for (const legacy of legacyKeys(key)) await storage.removeItem(legacy);\n };\n\n return {\n async getItem<T>(key: string): Promise<T | null> {\n const value = await read<T>(toUnstorageKey(key));\n if (value !== null) return value;\n for (const legacy of legacyKeys(key)) {\n const old = await read<T>(legacy);\n if (old !== null) return old;\n }\n return null;\n },\n\n async setItem<T>(key: string, value: T): Promise<void> {\n // unstorage stores a string verbatim and reads it back through `destr`, which turns \"123\"\n // into 123: write strings JSON-encoded (`destr` reads both forms). unstorage's setItem\n // rejects `undefined`; the contract never stores it.\n const stored = typeof value === \"string\" ? JSON.stringify(value) : value;\n await storage.setItem(toUnstorageKey(key), stored as NonNullable<T>);\n await removeLegacy(key);\n },\n\n async removeItem(key: string): Promise<void> {\n await storage.removeItem(toUnstorageKey(key));\n await removeLegacy(key);\n },\n\n async getKeys(prefix: string): Promise<string[]> {\n // unstorage's getKeys takes a whole-segment base and returns `:`-separated keys; list the\n // parent segment, convert back and filter by the plain prefix. A Set: a legacy spelling and\n // the current one decode to the same key.\n // A `$` in a parent segment is stored raw today and was `%24` in en's layout: list both.\n const parent = prefix.slice(0, prefix.lastIndexOf(\"/\") + 1);\n const bases =\n parent === \"\"\n ? [\"\"]\n : [...new Set([encodeKey(parent, \"none\"), encodeKey(parent, \"all\")])].map(\n (b) => `${b.slice(0, -2)}/`,\n );\n const out = new Set<string>();\n for (const base of bases)\n for (const key of await storage.getKeys(base)) out.add(fromUnstorageKey(key));\n return [...out].filter((key) => key.startsWith(prefix));\n },\n };\n}\n"],"mappings":";;AAsCA,MAAM,OAAO,MACX,IAAI,EAAE,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,SAAS,GAAG,GAAG;;AAMhE,SAAS,UAAU,KAAa,SAA6B;CAC3D,MAAM,UAAU,IACb,MAAM,GAAG,EACT,KAAK,MAAO,MAAM,KAAK,MAAM,EAAE,QAAQ,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAE,EAC1F,KAAK,GAAG;CACX,OAAO,YAAY,aAAa,QAAQ,QAAQ,OAAO,KAAK,IAAI;AAClE;;AAGA,MAAa,kBAAkB,QAAwB,UAAU,KAAK,UAAU;;;;;;AAOhF,SAAS,WAAW,KAAuB;CACzC,IAAI,CAAC,IAAI,SAAS,GAAG,KAAK,IAAI,MAAM,GAAG,EAAE,SAAS,EAAE,GAAG,OA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AS,OAAO,MAAM,GAAG,OAAO,YAAY,GAAG,IAAI,CAAC;GAC1D,MAAM,QACJ,WAAW,KACP,CAAC,EAAE,IACH,CAAC,GAAG,IAAI,IAAI,CAAC,UAAU,QAAQ,MAAM,GAAG,UAAU,QAAQ,KAAK,CAAC,CAAC,CAAC,EAAE,KACjE,MAAM,GAAG,EAAE,MAAM,GAAG,EAAE,EAAE,EAC3B;GACN,MAAM,sBAAM,IAAI,IAAY;GAC5B,KAAK,MAAM,QAAQ,OACjB,KAAK,MAAM,OAAO,MAAM,QAAQ,QAAQ,IAAI,GAAG,IAAI,IAAI,iBAAiB,GAAG,CAAC;GAC9E,OAAO,CAAC,GAAG,GAAG,EAAE,QAAQ,QAAQ,IAAI,WAAW,MAAM,CAAC;EACxD;CACF;AACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { r as KvStorage } from "./contract-BvgtswLX.cjs";
|
|
2
|
+
import { Storage } from "unstorage";
|
|
3
|
+
|
|
4
|
+
//#region src/storage/unstorage.d.ts
|
|
5
|
+
/** Options for {@link createUnstorageStorage}. */
|
|
6
|
+
interface UnstorageStorageOptions {
|
|
7
|
+
/** A pre-constructed unstorage `Storage` instance (any driver). */
|
|
8
|
+
storage: Storage;
|
|
9
|
+
}
|
|
10
|
+
/** The unstorage storage (no optional capabilities). */
|
|
11
|
+
type UnstorageKvStorage = KvStorage;
|
|
12
|
+
/**
|
|
13
|
+
* Create a {@link KvStorage} backed by an unstorage `Storage` instance. unstorage serializes JSON
|
|
14
|
+
* values, so values round-trip structurally; missing keys read back as `null`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { createUnstorageStorage } from "@xtandard/kit/storage/unstorage";
|
|
19
|
+
* import { createStorage } from "unstorage";
|
|
20
|
+
* import fsDriver from "unstorage/drivers/fs";
|
|
21
|
+
*
|
|
22
|
+
* const storage = createUnstorageStorage({
|
|
23
|
+
* storage: createStorage({ driver: fsDriver({ base: "./data" }) }),
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function createUnstorageStorage(options: UnstorageStorageOptions): UnstorageKvStorage;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { type UnstorageKvStorage, type UnstorageStorageOptions, createUnstorageStorage };
|
|
30
|
+
//# sourceMappingURL=entry-storage-unstorage.d.cts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { r as KvStorage } from "./contract-BvgtswLX.mjs";
|
|
2
|
+
import { Storage } from "unstorage";
|
|
3
|
+
|
|
4
|
+
//#region src/storage/unstorage.d.ts
|
|
5
|
+
/** Options for {@link createUnstorageStorage}. */
|
|
6
|
+
interface UnstorageStorageOptions {
|
|
7
|
+
/** A pre-constructed unstorage `Storage` instance (any driver). */
|
|
8
|
+
storage: Storage;
|
|
9
|
+
}
|
|
10
|
+
/** The unstorage storage (no optional capabilities). */
|
|
11
|
+
type UnstorageKvStorage = KvStorage;
|
|
12
|
+
/**
|
|
13
|
+
* Create a {@link KvStorage} backed by an unstorage `Storage` instance. unstorage serializes JSON
|
|
14
|
+
* values, so values round-trip structurally; missing keys read back as `null`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { createUnstorageStorage } from "@xtandard/kit/storage/unstorage";
|
|
19
|
+
* import { createStorage } from "unstorage";
|
|
20
|
+
* import fsDriver from "unstorage/drivers/fs";
|
|
21
|
+
*
|
|
22
|
+
* const storage = createUnstorageStorage({
|
|
23
|
+
* storage: createStorage({ driver: fsDriver({ base: "./data" }) }),
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function createUnstorageStorage(options: UnstorageStorageOptions): UnstorageKvStorage;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { type UnstorageKvStorage, type UnstorageStorageOptions, createUnstorageStorage };
|
|
30
|
+
//# sourceMappingURL=entry-storage-unstorage.d.mts.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region src/storage/unstorage.ts
|
|
2
|
+
const hex = (c) => `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`;
|
|
3
|
+
/** Encode `key` (empty segments as `%`) with the given `$` spelling. */
|
|
4
|
+
function encodeKey(key, dollars) {
|
|
5
|
+
const encoded = key.split("/").map((s) => s === "" ? "%" : s.replace(dollars === "all" ? /[%:\\?$]/g : /[%:\\?]/g, hex)).join("/");
|
|
6
|
+
return dollars === "trailing" ? encoded.replace(/\$$/, "%24") : encoded;
|
|
7
|
+
}
|
|
8
|
+
/** The key as written today: trailing `$` encoded, empty segments as `%`. */
|
|
9
|
+
const toUnstorageKey = (key) => encodeKey(key, "trailing");
|
|
10
|
+
/**
|
|
11
|
+
* Legacy spellings of `key` that differ from {@link toUnstorageKey}: the raw trailing `$` (wh, fl,
|
|
12
|
+
* au, li) and the every-`$`-encoded form (en). Keys with empty segments have none: those were
|
|
13
|
+
* collapsed onto another key.
|
|
14
|
+
*/
|
|
15
|
+
function legacyKeys(key) {
|
|
16
|
+
if (!key.includes("$") || key.split("/").includes("")) return [];
|
|
17
|
+
const current = toUnstorageKey(key);
|
|
18
|
+
return [...new Set([encodeKey(key, "none"), encodeKey(key, "all")])].filter((k) => k !== current);
|
|
19
|
+
}
|
|
20
|
+
/** Convert an unstorage `:`-separated key back to the caller's `/`-separated form. */
|
|
21
|
+
const fromUnstorageKey = (key) => key.split(":").map((s) => s === "%" ? "" : s.replace(/%(25|3A|5C|3F|24)/g, (_, h) => String.fromCharCode(Number.parseInt(h, 16)))).join("/");
|
|
22
|
+
/**
|
|
23
|
+
* Create a {@link KvStorage} backed by an unstorage `Storage` instance. unstorage serializes JSON
|
|
24
|
+
* values, so values round-trip structurally; missing keys read back as `null`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { createUnstorageStorage } from "@xtandard/kit/storage/unstorage";
|
|
29
|
+
* import { createStorage } from "unstorage";
|
|
30
|
+
* import fsDriver from "unstorage/drivers/fs";
|
|
31
|
+
*
|
|
32
|
+
* const storage = createUnstorageStorage({
|
|
33
|
+
* storage: createStorage({ driver: fsDriver({ base: "./data" }) }),
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
function createUnstorageStorage(options) {
|
|
38
|
+
const { storage } = options;
|
|
39
|
+
const read = async (key) => {
|
|
40
|
+
const value = await storage.getItem(key);
|
|
41
|
+
return value === void 0 ? null : value;
|
|
42
|
+
};
|
|
43
|
+
const removeLegacy = async (key) => {
|
|
44
|
+
for (const legacy of legacyKeys(key)) await storage.removeItem(legacy);
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
async getItem(key) {
|
|
48
|
+
const value = await read(toUnstorageKey(key));
|
|
49
|
+
if (value !== null) return value;
|
|
50
|
+
for (const legacy of legacyKeys(key)) {
|
|
51
|
+
const old = await read(legacy);
|
|
52
|
+
if (old !== null) return old;
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
},
|
|
56
|
+
async setItem(key, value) {
|
|
57
|
+
const stored = typeof value === "string" ? JSON.stringify(value) : value;
|
|
58
|
+
await storage.setItem(toUnstorageKey(key), stored);
|
|
59
|
+
await removeLegacy(key);
|
|
60
|
+
},
|
|
61
|
+
async removeItem(key) {
|
|
62
|
+
await storage.removeItem(toUnstorageKey(key));
|
|
63
|
+
await removeLegacy(key);
|
|
64
|
+
},
|
|
65
|
+
async getKeys(prefix) {
|
|
66
|
+
const parent = prefix.slice(0, prefix.lastIndexOf("/") + 1);
|
|
67
|
+
const bases = parent === "" ? [""] : [...new Set([encodeKey(parent, "none"), encodeKey(parent, "all")])].map((b) => `${b.slice(0, -2)}/`);
|
|
68
|
+
const out = /* @__PURE__ */ new Set();
|
|
69
|
+
for (const base of bases) for (const key of await storage.getKeys(base)) out.add(fromUnstorageKey(key));
|
|
70
|
+
return [...out].filter((key) => key.startsWith(prefix));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { createUnstorageStorage };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=entry-storage-unstorage.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-storage-unstorage.mjs","names":[],"sources":["../src/storage/unstorage.ts"],"sourcesContent":["/**\n * unstorage driver: wraps an [unstorage](https://unstorage.unjs.io) `Storage` (any driver) as a\n * {@link KvStorage}. The caller builds and configures the unstorage instance; this module only\n * imports its type, so `unstorage` stays an optional peer.\n *\n * unstorage normalizes keys: `/` and `\\` become `:`, anything after `?` is dropped, repeated and\n * leading/trailing separators collapse, and keys ending in `$` are meta keys hidden from\n * `getKeys`. So this driver encodes:\n *\n * - `%`, `:`, `\\` and `?` as `%25`, `%3A`, `%5C`, `%3F` (every copy did this);\n * - a **trailing** `$` as `%24` (only that one; a `$` elsewhere is stored as-is, ADR 0005);\n * - an empty segment (`a//b`, `a/`) as a lone `%` (which a literal `%` never produces).\n *\n * String values are written JSON-encoded (`\"\\\"123\\\"\"`), because unstorage reads strings back\n * through `destr`, which would turn `\"123\"` into `123`; older raw strings still read as before.\n *\n * Reads fall back to the legacy spellings of a key containing `$` (the raw trailing `$` of the\n * older copies, and the every-`$`-encoded form), and `getKeys` lists both, so data written by\n * earlier product releases stays readable. Because unstorage matches whole segments only,\n * `getKeys(prefix)` lists the prefix's parent segment and filters by the full prefix.\n *\n * No `compareAndSwap`: unstorage drivers share no atomic primitive.\n *\n * @module\n */\n\nimport type { Storage } from \"unstorage\";\nimport type { KvStorage } from \"./contract.ts\";\n\n/** Options for {@link createUnstorageStorage}. */\nexport interface UnstorageStorageOptions {\n /** A pre-constructed unstorage `Storage` instance (any driver). */\n storage: Storage;\n}\n\n/** The unstorage storage (no optional capabilities). */\nexport type UnstorageKvStorage = KvStorage;\n\nconst hex = (c: string): string =>\n `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, \"0\")}`;\n\n/** How a spelling writes `$`: only a trailing one (current), never (wh/fl/au/li) or always (en). */\ntype DollarMode = \"trailing\" | \"none\" | \"all\";\n\n/** Encode `key` (empty segments as `%`) with the given `$` spelling. */\nfunction encodeKey(key: string, dollars: DollarMode): string {\n const encoded = key\n .split(\"/\")\n .map((s) => (s === \"\" ? \"%\" : s.replace(dollars === \"all\" ? /[%:\\\\?$]/g : /[%:\\\\?]/g, hex)))\n .join(\"/\");\n return dollars === \"trailing\" ? encoded.replace(/\\$$/, \"%24\") : encoded;\n}\n\n/** The key as written today: trailing `$` encoded, empty segments as `%`. */\nexport const toUnstorageKey = (key: string): string => encodeKey(key, \"trailing\");\n\n/**\n * Legacy spellings of `key` that differ from {@link toUnstorageKey}: the raw trailing `$` (wh, fl,\n * au, li) and the every-`$`-encoded form (en). Keys with empty segments have none: those were\n * collapsed onto another key.\n */\nfunction legacyKeys(key: string): string[] {\n if (!key.includes(\"$\") || key.split(\"/\").includes(\"\")) return [];\n const current = toUnstorageKey(key);\n return [...new Set([encodeKey(key, \"none\"), encodeKey(key, \"all\")])].filter((k) => k !== current);\n}\n\n/** Convert an unstorage `:`-separated key back to the caller's `/`-separated form. */\nexport const fromUnstorageKey = (key: string): string =>\n key\n .split(\":\")\n .map((s) =>\n s === \"%\"\n ? \"\"\n : s.replace(/%(25|3A|5C|3F|24)/g, (_, h: string) =>\n String.fromCharCode(Number.parseInt(h, 16)),\n ),\n )\n .join(\"/\");\n\n/**\n * Create a {@link KvStorage} backed by an unstorage `Storage` instance. unstorage serializes JSON\n * values, so values round-trip structurally; missing keys read back as `null`.\n *\n * @example\n * ```ts\n * import { createUnstorageStorage } from \"@xtandard/kit/storage/unstorage\";\n * import { createStorage } from \"unstorage\";\n * import fsDriver from \"unstorage/drivers/fs\";\n *\n * const storage = createUnstorageStorage({\n * storage: createStorage({ driver: fsDriver({ base: \"./data\" }) }),\n * });\n * ```\n */\nexport function createUnstorageStorage(options: UnstorageStorageOptions): UnstorageKvStorage {\n const { storage } = options;\n\n const read = async <T>(key: string): Promise<T | null> => {\n const value = await storage.getItem<T>(key);\n return value === undefined ? null : value;\n };\n const removeLegacy = async (key: string): Promise<void> => {\n for (const legacy of legacyKeys(key)) await storage.removeItem(legacy);\n };\n\n return {\n async getItem<T>(key: string): Promise<T | null> {\n const value = await read<T>(toUnstorageKey(key));\n if (value !== null) return value;\n for (const legacy of legacyKeys(key)) {\n const old = await read<T>(legacy);\n if (old !== null) return old;\n }\n return null;\n },\n\n async setItem<T>(key: string, value: T): Promise<void> {\n // unstorage stores a string verbatim and reads it back through `destr`, which turns \"123\"\n // into 123: write strings JSON-encoded (`destr` reads both forms). unstorage's setItem\n // rejects `undefined`; the contract never stores it.\n const stored = typeof value === \"string\" ? JSON.stringify(value) : value;\n await storage.setItem(toUnstorageKey(key), stored as NonNullable<T>);\n await removeLegacy(key);\n },\n\n async removeItem(key: string): Promise<void> {\n await storage.removeItem(toUnstorageKey(key));\n await removeLegacy(key);\n },\n\n async getKeys(prefix: string): Promise<string[]> {\n // unstorage's getKeys takes a whole-segment base and returns `:`-separated keys; list the\n // parent segment, convert back and filter by the plain prefix. A Set: a legacy spelling and\n // the current one decode to the same key.\n // A `$` in a parent segment is stored raw today and was `%24` in en's layout: list both.\n const parent = prefix.slice(0, prefix.lastIndexOf(\"/\") + 1);\n const bases =\n parent === \"\"\n ? [\"\"]\n : [...new Set([encodeKey(parent, \"none\"), encodeKey(parent, \"all\")])].map(\n (b) => `${b.slice(0, -2)}/`,\n );\n const out = new Set<string>();\n for (const base of bases)\n for (const key of await storage.getKeys(base)) out.add(fromUnstorageKey(key));\n return [...out].filter((key) => key.startsWith(prefix));\n },\n };\n}\n"],"mappings":";AAsCA,MAAM,OAAO,MACX,IAAI,EAAE,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,SAAS,GAAG,GAAG;;AAMhE,SAAS,UAAU,KAAa,SAA6B;CAC3D,MAAM,UAAU,IACb,MAAM,GAAG,E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A,OAAO;EACT;EAEA,MAAM,QAAW,KAAa,OAAyB;GAIrD,MAAM,SAAS,OAAO,UAAU,WAAW,KAAK,UAAU,KAAK,IAAI;GACnE,MAAM,QAAQ,QAAQ,eAAe,GAAG,GAAG,MAAwB;GACnE,MAAM,aAAa,GAAG;EACxB;EAEA,MAAM,WAAW,KAA4B;GAC3C,MAAM,QAAQ,WAAW,eAAe,GAAG,CAAC;GAC5C,MAAM,aAAa,GAAG;EACxB;EAEA,MAAM,QAAQ,QAAmC;GAK/C,MAAM,SAAS,OAAO,MAAM,GAAG,OAAO,YAAY,GAAG,IAAI,CAAC;GAC1D,MAAM,QACJ,WAAW,KACP,CAAC,EAAE,IACH,CAAC,GAAG,IAAI,IAAI,CAAC,UAAU,QAAQ,MAAM,GAAG,UAAU,QAAQ,KAAK,CAAC,CAAC,CAAC,EAAE,KACjE,MAAM,GAAG,EAAE,MAAM,GAAG,EAAE,EAAE,EAC3B;GACN,MAAM,sBAAM,IAAI,IAAY;GAC5B,KAAK,MAAM,QAAQ,OACjB,KAAK,MAAM,OAAO,MAAM,QAAQ,QAAQ,IAAI,GAAG,IAAI,IAAI,iBAAiB,GAAG,CAAC;GAC9E,OAAO,CAAC,GAAG,GAAG,EAAE,QAAQ,QAAQ,IAAI,WAAW,MAAM,CAAC;EACxD;CACF;AACF"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_peer = require("./peer-BIjBFzwQ.cjs");
|
|
3
|
+
const require_keys = require("./keys-DQrwxDKI.cjs");
|
|
4
|
+
const require_util = require("./util-dAnTK9x-.cjs");
|
|
5
|
+
const require_json = require("./json-CM7TwYQ7.cjs");
|
|
6
|
+
//#region src/storage/watch.ts
|
|
7
|
+
/**
|
|
8
|
+
* Wrap a storage so it implements {@link WatchableKvStorage} using `subscribe` as the change
|
|
9
|
+
* source. The wrapper delegates every other member to `storage` and only adds `watch`; keys outside
|
|
10
|
+
* the watched `prefix` are filtered out. A notification without a key is delivered as an `update`
|
|
11
|
+
* of the prefix itself (enough to trigger a refresh).
|
|
12
|
+
*
|
|
13
|
+
* The wrapper inherits from `storage` **and** carries every member of `storage` (own, inherited and
|
|
14
|
+
* class methods, bound to `storage`) as an own enumerable property, so `{ ...withWatch(s, sub) }`
|
|
15
|
+
* keeps the methods (the copies' `Object.create`-only wrapper lost them on spread).
|
|
16
|
+
*/
|
|
17
|
+
function withWatch(storage, subscribe) {
|
|
18
|
+
const watchable = Object.create(storage);
|
|
19
|
+
for (const name of memberNames(storage)) {
|
|
20
|
+
if (name === "watch") continue;
|
|
21
|
+
const value = storage[name];
|
|
22
|
+
Object.defineProperty(watchable, name, {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
...typeof value === "function" ? {
|
|
26
|
+
value: value.bind(storage),
|
|
27
|
+
writable: true
|
|
28
|
+
} : {
|
|
29
|
+
get: () => storage[name],
|
|
30
|
+
set: (next) => {
|
|
31
|
+
storage[name] = next;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
Object.defineProperty(watchable, "watch", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true,
|
|
40
|
+
value: (prefix, callback) => {
|
|
41
|
+
const notify = (key) => {
|
|
42
|
+
if (key !== void 0 && key !== "" && !key.startsWith(prefix)) return;
|
|
43
|
+
callback({
|
|
44
|
+
type: "update",
|
|
45
|
+
key: key || prefix
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
return Promise.resolve(subscribe(notify));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return watchable;
|
|
52
|
+
}
|
|
53
|
+
/** Every string-keyed member reachable from `obj`, up to (not including) `Object.prototype`. */
|
|
54
|
+
function memberNames(obj) {
|
|
55
|
+
const names = /* @__PURE__ */ new Set();
|
|
56
|
+
for (let o = obj; o && o !== Object.prototype; o = Object.getPrototypeOf(o)) for (const name of Object.getOwnPropertyNames(o)) if (name !== "constructor") names.add(name);
|
|
57
|
+
return names;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A {@link WatchSubscribe} backed by Postgres `LISTEN`/`NOTIFY`. Pair it with {@link withWatch} for
|
|
61
|
+
* the postgres or drizzle-over-pg drivers. Your migration owns the trigger that `pg_notify`s
|
|
62
|
+
* `channel` with the changed key as payload; this only `LISTEN`s.
|
|
63
|
+
*
|
|
64
|
+
* The channel is a parameter: products pass the channel they document (`"xtandard_webhooks"`, …).
|
|
65
|
+
* The neutral default is `"xtandard_kv"`.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { Client } from "pg";
|
|
70
|
+
* const listener = new Client({ connectionString: process.env.DATABASE_URL });
|
|
71
|
+
* await listener.connect();
|
|
72
|
+
* const storage = withWatch(base, pgListenNotify(listener, "xtandard_webhooks"));
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
function pgListenNotify(client, channel = "xtandard_kv") {
|
|
76
|
+
const quoted = `"${channel.replace(/"/g, "\"\"")}"`;
|
|
77
|
+
return async (notify) => {
|
|
78
|
+
const listener = (msg) => {
|
|
79
|
+
if (msg.channel === channel) notify(msg.payload);
|
|
80
|
+
};
|
|
81
|
+
client.on("notification", listener);
|
|
82
|
+
await client.query(`LISTEN ${quoted}`);
|
|
83
|
+
return async () => {
|
|
84
|
+
client.removeListener("notification", listener);
|
|
85
|
+
await client.query(`UNLISTEN ${quoted}`);
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
exports.SAFE_IDENTIFIER = require_util.SAFE_IDENTIFIER;
|
|
91
|
+
exports.assertIdentifier = require_util.assertIdentifier;
|
|
92
|
+
exports.canonical = require_json.canonical;
|
|
93
|
+
exports.canonicalJson = require_json.canonicalJson;
|
|
94
|
+
exports.decodeSegment = require_keys.decodeSegment;
|
|
95
|
+
exports.deepEqual = require_json.deepEqual;
|
|
96
|
+
exports.encodeSegment = require_keys.encodeSegment;
|
|
97
|
+
exports.escapeGlob = require_util.escapeGlob;
|
|
98
|
+
exports.escapeLike = require_util.escapeLike;
|
|
99
|
+
exports.escapeRedisGlob = require_util.escapeRedisGlob;
|
|
100
|
+
exports.escapeRegex = require_util.escapeRegex;
|
|
101
|
+
exports.importPeer = require_peer.importPeer;
|
|
102
|
+
exports.isCompareAndSwap = require_keys.isCompareAndSwap;
|
|
103
|
+
exports.isTransactional = require_keys.isTransactional;
|
|
104
|
+
exports.isWatchable = require_keys.isWatchable;
|
|
105
|
+
exports.lastSegment = require_keys.lastSegment;
|
|
106
|
+
exports.padMillis = require_keys.padMillis;
|
|
107
|
+
exports.parseJsonValue = require_json.parseJsonValue;
|
|
108
|
+
exports.parseSortableLeaf = require_keys.parseSortableLeaf;
|
|
109
|
+
exports.pgListenNotify = pgListenNotify;
|
|
110
|
+
exports.requirePeer = require_peer.requirePeer;
|
|
111
|
+
exports.sortableLeaf = require_keys.sortableLeaf;
|
|
112
|
+
exports.withWatch = withWatch;
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=entry-storage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-storage.cjs","names":[],"sources":["../src/storage/watch.ts"],"sourcesContent":["/**\n * Composable change notifications. `watch` is orthogonal to which storage you use, so instead of\n * baking it into each driver, {@link withWatch} wraps *any* {@link KvStorage} with a\n * {@link WatchSubscribe} source you provide: Postgres `LISTEN`/`NOTIFY` ({@link pgListenNotify}),\n * Redis pub/sub, an ORM after-write hook, a websocket, an `EventEmitter`…\n *\n * @example\n * ```ts\n * import { pgListenNotify, withWatch } from \"@xtandard/kit/storage\";\n * import { createDrizzleStorage } from \"@xtandard/kit/storage/drizzle\";\n *\n * const storage = withWatch(createDrizzleStorage({ db, table }), pgListenNotify(listener, \"my_channel\"));\n * ```\n *\n * @module\n */\n\nimport type { KvStorage, StorageChangeEvent, WatchableKvStorage } from \"./contract.ts\";\n\n/**\n * A change source. Called with a `notify` callback: wire your source to invoke it (optionally with\n * the changed key) on every change, and return an unsubscribe function (sync or async).\n */\nexport type WatchSubscribe = (\n notify: (key?: string) => void,\n) => (() => void | Promise<void>) | Promise<() => void | Promise<void>>;\n\n/**\n * Wrap a storage so it implements {@link WatchableKvStorage} using `subscribe` as the change\n * source. The wrapper delegates every other member to `storage` and only adds `watch`; keys outside\n * the watched `prefix` are filtered out. A notification without a key is delivered as an `update`\n * of the prefix itself (enough to trigger a refresh).\n *\n * The wrapper inherits from `storage` **and** carries every member of `storage` (own, inherited and\n * class methods, bound to `storage`) as an own enumerable property, so `{ ...withWatch(s, sub) }`\n * keeps the methods (the copies' `Object.create`-only wrapper lost them on spread).\n */\nexport function withWatch<S extends KvStorage>(\n storage: S,\n subscribe: WatchSubscribe,\n): S & WatchableKvStorage {\n const watchable = Object.create(storage) as S & WatchableKvStorage;\n for (const name of memberNames(storage)) {\n if (name === \"watch\") continue;\n const value = (storage as Record<string, unknown>)[name];\n Object.defineProperty(watchable, name, {\n enumerable: true,\n configurable: true,\n ...(typeof value === \"function\"\n ? { value: (value as (...args: unknown[]) => unknown).bind(storage), writable: true }\n : {\n get: () => (storage as Record<string, unknown>)[name],\n set: (next: unknown) => {\n (storage as Record<string, unknown>)[name] = next;\n },\n }),\n });\n }\n Object.defineProperty(watchable, \"watch\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: (prefix: string, callback: (event: StorageChangeEvent) => void) => {\n const notify = (key?: string): void => {\n if (key !== undefined && key !== \"\" && !key.startsWith(prefix)) return;\n callback({ type: \"update\", key: key || prefix });\n };\n return Promise.resolve(subscribe(notify));\n },\n });\n return watchable;\n}\n\n/** Every string-keyed member reachable from `obj`, up to (not including) `Object.prototype`. */\nfunction memberNames(obj: object): Set<string> {\n const names = new Set<string>();\n for (let o: object | null = obj; o && o !== Object.prototype; o = Object.getPrototypeOf(o)) {\n for (const name of Object.getOwnPropertyNames(o)) if (name !== \"constructor\") names.add(name);\n }\n return names;\n}\n\n/**\n * A dedicated notification client for {@link pgListenNotify}, satisfied by a `pg` `Client`. A\n * `Pool` won't do (it rotates connections); use a `Client` you `connect()`.\n */\nexport interface PgNotificationClient {\n /** Run a statement (`LISTEN`/`UNLISTEN`). */\n query(sql: string): Promise<unknown>;\n /** Register the notification listener. */\n on(event: \"notification\", listener: (msg: { channel: string; payload?: string }) => void): void;\n /** Remove the notification listener. */\n removeListener(\n event: \"notification\",\n listener: (msg: { channel: string; payload?: string }) => void,\n ): void;\n}\n\n/**\n * A {@link WatchSubscribe} backed by Postgres `LISTEN`/`NOTIFY`. Pair it with {@link withWatch} for\n * the postgres or drizzle-over-pg drivers. Your migration owns the trigger that `pg_notify`s\n * `channel` with the changed key as payload; this only `LISTEN`s.\n *\n * The channel is a parameter: products pass the channel they document (`\"xtandard_webhooks\"`, …).\n * The neutral default is `\"xtandard_kv\"`.\n *\n * @example\n * ```ts\n * import { Client } from \"pg\";\n * const listener = new Client({ connectionString: process.env.DATABASE_URL });\n * await listener.connect();\n * const storage = withWatch(base, pgListenNotify(listener, \"xtandard_webhooks\"));\n * ```\n */\nexport function pgListenNotify(\n client: PgNotificationClient,\n channel = \"xtandard_kv\",\n): WatchSubscribe {\n const quoted = `\"${channel.replace(/\"/g, '\"\"')}\"`;\n return async (notify) => {\n const listener = (msg: { channel: string; payload?: string }): void => {\n if (msg.channel === channel) notify(msg.payload);\n };\n client.on(\"notification\", listener);\n await client.query(`LISTEN ${quoted}`);\n return async () => {\n client.removeListener(\"notification\", listener);\n await client.query(`UNLISTEN ${quoted}`);\n };\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,SAAgB,UACd,SACA,WACwB;CACxB,MAAM,YAAY,OAAO,OAAO,OAAO;CACvC,KAAK,MAAM,QAAQ,YAAY,OAAO,GAAG;EACvC,IAAI,SAAS,SAAS;EACtB,MAAM,QAAS,QAAoC;EACnD,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