@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,86 @@
|
|
|
1
|
+
import { t as importPeer } from "./peer-CTHMzOdn.mjs";
|
|
2
|
+
import { n as assertIdentifier } from "./util-Dnj5T-yw.mjs";
|
|
3
|
+
import { n as sqliteKvStorage, t as sqliteKvSchema } from "./kv-sqlite-DIIPfflJ.mjs";
|
|
4
|
+
//#region src/storage/libsql.ts
|
|
5
|
+
/**
|
|
6
|
+
* libSQL / [Turso](https://turso.tech) storage driver over the `@libsql/client` package (an
|
|
7
|
+
* optional peer). Same SQL dialect as SQLite, against a remote, replicated database, an embedded
|
|
8
|
+
* replica or a local file, so it suits multi-node and edge runtimes where `bun:sqlite` does not.
|
|
9
|
+
*
|
|
10
|
+
* Pass a pre-constructed `client`, or `url` (+ `authToken`) to create one lazily on first use. The
|
|
11
|
+
* table is created on first use; a failed connect or DDL is retried on the next call (not cached).
|
|
12
|
+
* Values are canonical JSON, so `compareAndSwap` is one conditional `UPDATE` evaluated by the
|
|
13
|
+
* server (see `kv-sqlite.ts`).
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
const SUBPATH = "@xtandard/kit/storage/libsql";
|
|
18
|
+
/**
|
|
19
|
+
* Build a {@link LibsqlConnection} that runs `ddl` (in order) once before the first use. A failed
|
|
20
|
+
* connect or DDL is not cached: the next `get()` retries. Products add their own tables by passing
|
|
21
|
+
* extra statements (au's event log).
|
|
22
|
+
*/
|
|
23
|
+
function libsqlConnection(options, ddl, subpath = SUBPATH) {
|
|
24
|
+
const ownsClient = !options.client;
|
|
25
|
+
let client = options.client;
|
|
26
|
+
let ready;
|
|
27
|
+
return {
|
|
28
|
+
get() {
|
|
29
|
+
ready ??= (async () => {
|
|
30
|
+
if (!client) {
|
|
31
|
+
if (!options.url) throw new Error(`${subpath} requires either a \`client\` or a \`url\``);
|
|
32
|
+
const { createClient } = await importPeer("@libsql/client", subpath, () => import("@libsql/client"));
|
|
33
|
+
client = createClient({
|
|
34
|
+
url: options.url,
|
|
35
|
+
authToken: options.authToken
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
for (const statement of ddl) await client.execute(statement);
|
|
39
|
+
return client;
|
|
40
|
+
})().catch((error) => {
|
|
41
|
+
ready = void 0;
|
|
42
|
+
throw error;
|
|
43
|
+
});
|
|
44
|
+
return ready;
|
|
45
|
+
},
|
|
46
|
+
close() {
|
|
47
|
+
if (ownsClient) client?.close();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Adapt a libSQL client to the positional-args {@link SqliteExecutor} of the SQLite core. */
|
|
52
|
+
function libsqlExecutor(client) {
|
|
53
|
+
return { async all(sql, args) {
|
|
54
|
+
const { rows } = await client.execute({
|
|
55
|
+
sql,
|
|
56
|
+
args
|
|
57
|
+
});
|
|
58
|
+
return Array.from(rows);
|
|
59
|
+
} };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create a libSQL/Turso-backed {@link LibsqlKvStorage}.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { createLibsqlStorage } from "@xtandard/kit/storage/libsql";
|
|
67
|
+
*
|
|
68
|
+
* const storage = createLibsqlStorage({
|
|
69
|
+
* url: process.env.TURSO_DATABASE_URL!,
|
|
70
|
+
* authToken: process.env.TURSO_AUTH_TOKEN,
|
|
71
|
+
* table: "xtandard_kv",
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
function createLibsqlStorage(options) {
|
|
76
|
+
const table = assertIdentifier(options.table ?? "xtandard_kv");
|
|
77
|
+
const connection = libsqlConnection(options, [sqliteKvSchema(table)]);
|
|
78
|
+
return {
|
|
79
|
+
...sqliteKvStorage(table, async () => libsqlExecutor(await connection.get())),
|
|
80
|
+
close: connection.close
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
export { libsqlConnection as n, libsqlExecutor as r, createLibsqlStorage as t };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=libsql-CkOjQINi.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libsql-CkOjQINi.mjs","names":[],"sources":["../src/storage/libsql.ts"],"sourcesContent":["/**\n * libSQL / [Turso](https://turso.tech) storage driver over the `@libsql/client` package (an\n * optional peer). Same SQL dialect as SQLite, against a remote, replicated database, an embedded\n * replica or a local file, so it suits multi-node and edge runtimes where `bun:sqlite` does not.\n *\n * Pass a pre-constructed `client`, or `url` (+ `authToken`) to create one lazily on first use. The\n * table is created on first use; a failed connect or DDL is retried on the next call (not cached).\n * Values are canonical JSON, so `compareAndSwap` is one conditional `UPDATE` evaluated by the\n * server (see `kv-sqlite.ts`).\n *\n * @module\n */\n\nimport { importPeer } from \"../internal/peer.ts\";\nimport type { CompareAndSwapKvStorage } from \"./contract.ts\";\nimport { sqliteKvSchema, sqliteKvStorage, type SqliteExecutor } from \"./kv-sqlite.ts\";\nimport { assertIdentifier } from \"./util.ts\";\n\nconst SUBPATH = \"@xtandard/kit/storage/libsql\";\n\n/** Options for {@link createLibsqlStorage}. */\nexport interface LibsqlStorageOptions {\n /** libSQL URL (`libsql://…`, `https://…`, `file:…`, `:memory:`). Used when no `client`. */\n url?: string;\n /** Turso auth token for remote databases. */\n authToken?: string;\n /** A pre-constructed `@libsql/client` client to use instead of connecting. Never closed. */\n client?: LibsqlClientLike;\n /** Table name (default `\"xtandard_kv\"`; products pass theirs). Validated as a safe identifier. */\n table?: string;\n}\n\n/** A compare-and-swap capable storage backed by libSQL/Turso, plus `close()`. */\nexport interface LibsqlKvStorage extends CompareAndSwapKvStorage {\n /** Close the client if this driver created it; no-op for a borrowed one. */\n close(): void;\n}\n\n/** Minimal structural view of the `@libsql/client` surface the drivers use. */\nexport interface LibsqlClientLike {\n /** Run one statement. */\n execute(\n stmt: string | { sql: string; args: unknown[] },\n ): Promise<{ rows: ArrayLike<Record<string, unknown>> }>;\n /** Close the client. */\n close(): void;\n}\n\n/** A lazily created libSQL client whose DDL runs once (semi-public, ADR 0004). */\nexport interface LibsqlConnection {\n /** Resolve the client, creating it and running the DDL on first use (retried after a failure). */\n get(): Promise<LibsqlClientLike>;\n /** Close the client if this connection created it. */\n close(): void;\n}\n\n/**\n * Build a {@link LibsqlConnection} that runs `ddl` (in order) once before the first use. A failed\n * connect or DDL is not cached: the next `get()` retries. Products add their own tables by passing\n * extra statements (au's event log).\n */\nexport function libsqlConnection(\n options: Pick<LibsqlStorageOptions, \"url\" | \"authToken\" | \"client\">,\n ddl: string[],\n subpath = SUBPATH,\n): LibsqlConnection {\n const ownsClient = !options.client;\n let client: LibsqlClientLike | undefined = options.client;\n let ready: Promise<LibsqlClientLike> | undefined;\n return {\n get(): Promise<LibsqlClientLike> {\n ready ??= (async () => {\n if (!client) {\n if (!options.url) throw new Error(`${subpath} requires either a \\`client\\` or a \\`url\\``);\n const { createClient } = await importPeer(\n \"@libsql/client\",\n subpath,\n () =>\n import(\"@libsql/client\") as unknown as Promise<{\n createClient: (opts: { url: string; authToken?: string }) => LibsqlClientLike;\n }>,\n );\n client = createClient({ url: options.url, authToken: options.authToken });\n }\n for (const statement of ddl) await client.execute(statement);\n return client;\n })().catch((error: unknown) => {\n ready = undefined; // let a later call retry\n throw error;\n });\n return ready;\n },\n close(): void {\n if (ownsClient) client?.close();\n },\n };\n}\n\n/** Adapt a libSQL client to the positional-args {@link SqliteExecutor} of the SQLite core. */\nexport function libsqlExecutor(client: LibsqlClientLike): SqliteExecutor {\n return {\n async all(sql, args) {\n const { rows } = await client.execute({ sql, args });\n return Array.from(rows);\n },\n };\n}\n\n/**\n * Create a libSQL/Turso-backed {@link LibsqlKvStorage}.\n *\n * @example\n * ```ts\n * import { createLibsqlStorage } from \"@xtandard/kit/storage/libsql\";\n *\n * const storage = createLibsqlStorage({\n * url: process.env.TURSO_DATABASE_URL!,\n * authToken: process.env.TURSO_AUTH_TOKEN,\n * table: \"xtandard_kv\",\n * });\n * ```\n */\nexport function createLibsqlStorage(options: LibsqlStorageOptions): LibsqlKvStorage {\n const table = assertIdentifier(options.table ?? \"xtandard_kv\");\n const connection = libsqlConnection(options, [sqliteKvSchema(table)]);\n return {\n ...sqliteKvStorage(table, async () => libsqlExecutor(await connection.get())),\n close: connection.close,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,MAAM,UAAU;;;;;;AA2ChB,SAAgB,iBACd,SACA,KACA,UAAU,SACQ;CAClB,MAAM,aAAa,CAAC,QAAQ;CAC5B,IAAI,SAAuC,QAAQ;CACnD,IAAI;CACJ,OAAO;EACL,MAAiC;GAC/B,WAAW,YAAY;IACrB,IAAI,CAAC,QAAQ;KACX,IAAI,CAAC,QAAQ,KAAK,MAAM,IAAI,MAAM,GAAG,QAAQ,2CAA2C;KACxF,MAAM,EAAE,iBAAiB,MAAM,WAC7B,kBACA,eAEE,OAAO,iBAGX;KACA,SAAS,aAAa;MAAE,KAAK,QAAQ;MAAK,WAAW,QAAQ;KAAU,CAAC;IAC1E;IACA,KAAK,MAAM,aAAa,KAAK,MAAM,OAAO,QAAQ,SAAS;IAC3D,OAAO;GACT,GAAG,EAAE,OAAO,UAAmB;IAC7B,QAAQ,KAAA;IACR,MAAM;GACR,CAAC;GACD,OAAO;EACT;EACA,QAAc;GACZ,IAAI,YAAY,QAAQ,MAAM;EAChC;CACF;AACF;;AAGA,SAAgB,eAAe,QAA0C;CACvE,OAAO,EACL,MAAM,IAAI,KAAK,MAAM;EACnB,MAAM,EAAE,SAAS,MAAM,OAAO,QAAQ;GAAE;GAAK;EAAK,CAAC;EACnD,OAAO,MAAM,KAAK,IAAI;CACxB,EACF;AACF;;;;;;;;;;;;;;;AAgBA,SAAgB,oBAAoB,SAAgD;CAClF,MAAM,QAAQ,iBAAiB,QAAQ,SAAS,aAAa;CAC7D,MAAM,aAAa,iBAAiB,SAAS,CAAC,eAAe,KAAK,CAAC,CAAC;CACpE,OAAO;EACL,GAAG,gBAAgB,OAAO,YAAY,eAAe,MAAM,WAAW,IAAI,CAAC,CAAC;EAC5E,OAAO,WAAW;CACpB;AACF"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
const require_peer = require("./peer-BIjBFzwQ.cjs");
|
|
2
|
+
const require_util = require("./util-dAnTK9x-.cjs");
|
|
3
|
+
const require_json = require("./json-CM7TwYQ7.cjs");
|
|
4
|
+
const require_cas = require("./cas-CuPSaXBV.cjs");
|
|
5
|
+
//#region src/storage/mongodb.ts
|
|
6
|
+
const SUBPATH = "@xtandard/kit/storage/mongodb";
|
|
7
|
+
/** Build a {@link MongoConnection} from a borrowed `client` or a `url`. */
|
|
8
|
+
function mongoConnection(options, subpath = SUBPATH) {
|
|
9
|
+
const ownsClient = !options.client;
|
|
10
|
+
let client = options.client;
|
|
11
|
+
let connecting;
|
|
12
|
+
async function connect() {
|
|
13
|
+
connecting ??= (async () => {
|
|
14
|
+
if (!client) {
|
|
15
|
+
if (options.url === void 0) throw new Error(`${subpath} requires either a \`client\` or a \`url\``);
|
|
16
|
+
const mod = await require_peer.importPeer("mongodb", subpath, () => import("mongodb"));
|
|
17
|
+
client = new (mod.MongoClient ?? mod.default?.MongoClient)(options.url);
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
await client.connect();
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (!isAlreadyConnected(error)) throw error;
|
|
23
|
+
}
|
|
24
|
+
return client;
|
|
25
|
+
})();
|
|
26
|
+
try {
|
|
27
|
+
return await connecting;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
connecting = void 0;
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
async collection(name) {
|
|
35
|
+
return (await connect()).db(options.dbName).collection(name);
|
|
36
|
+
},
|
|
37
|
+
async close() {
|
|
38
|
+
if (ownsClient && client) await client.close();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** True for a MongoDB duplicate-key error (E11000). Semi-public. */
|
|
43
|
+
function isDuplicateKey(error) {
|
|
44
|
+
return error?.code === 11e3;
|
|
45
|
+
}
|
|
46
|
+
const isAlreadyConnected = (error) => {
|
|
47
|
+
const message = error instanceof Error ? error.message.toLowerCase() : "";
|
|
48
|
+
return message.includes("already") && message.includes("connect");
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The KV operations over a collection (semi-public, ADR 0004): `collection` resolves it before
|
|
52
|
+
* every operation. {@link createMongoStorage} is this plus {@link mongoConnection}.
|
|
53
|
+
*/
|
|
54
|
+
function mongoKvStorage(collection) {
|
|
55
|
+
return {
|
|
56
|
+
async getItem(key) {
|
|
57
|
+
const doc = await (await collection()).findOne({ _id: key });
|
|
58
|
+
return doc ? doc.value : null;
|
|
59
|
+
},
|
|
60
|
+
async setItem(key, value) {
|
|
61
|
+
await (await collection()).updateOne({ _id: key }, { $set: { value: require_json.canonical(value) } }, { upsert: true });
|
|
62
|
+
},
|
|
63
|
+
async removeItem(key) {
|
|
64
|
+
await (await collection()).deleteOne({ _id: key });
|
|
65
|
+
},
|
|
66
|
+
async getKeys(prefix) {
|
|
67
|
+
const cursor = (await collection()).find({ _id: { $regex: `^${require_util.escapeRegex(prefix)}` } }).project({ _id: 1 });
|
|
68
|
+
const out = [];
|
|
69
|
+
for await (const doc of cursor) if (doc._id.startsWith(prefix)) out.push(doc._id);
|
|
70
|
+
return out;
|
|
71
|
+
},
|
|
72
|
+
async compareAndSwap(input) {
|
|
73
|
+
const c = await collection();
|
|
74
|
+
const next = require_json.canonical(input.next);
|
|
75
|
+
if (input.expected === null) try {
|
|
76
|
+
await c.insertOne({
|
|
77
|
+
_id: input.key,
|
|
78
|
+
value: next
|
|
79
|
+
});
|
|
80
|
+
return true;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (isDuplicateKey(error)) return false;
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
const swap = async (current) => (await c.updateOne({
|
|
86
|
+
_id: input.key,
|
|
87
|
+
$expr: { $eq: ["$value", { $literal: current }] }
|
|
88
|
+
}, { $set: { value: next } })).matchedCount === 1;
|
|
89
|
+
return require_cas.swapWithFallback(input.expected, {
|
|
90
|
+
fast: () => swap(require_json.canonical(input.expected)),
|
|
91
|
+
async read() {
|
|
92
|
+
const doc = await c.findOne({ _id: input.key });
|
|
93
|
+
return doc ? {
|
|
94
|
+
raw: doc.value,
|
|
95
|
+
value: doc.value
|
|
96
|
+
} : null;
|
|
97
|
+
},
|
|
98
|
+
swapRaw: swap
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a MongoDB-backed {@link MongoKvStorage}. Connection is lazy and shared.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* import { createMongoStorage } from "@xtandard/kit/storage/mongodb";
|
|
109
|
+
*
|
|
110
|
+
* const storage = createMongoStorage({ url: process.env.MONGO_URL, dbName: "app", collectionName: "kv" });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
function createMongoStorage(options) {
|
|
114
|
+
const { dbName = "xtandard", collectionName = "kv" } = options;
|
|
115
|
+
const connection = mongoConnection({
|
|
116
|
+
...options,
|
|
117
|
+
dbName
|
|
118
|
+
});
|
|
119
|
+
return {
|
|
120
|
+
...mongoKvStorage(() => connection.collection(collectionName)),
|
|
121
|
+
close: connection.close
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
Object.defineProperty(exports, "createMongoStorage", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
get: function() {
|
|
128
|
+
return createMongoStorage;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
Object.defineProperty(exports, "isDuplicateKey", {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
get: function() {
|
|
134
|
+
return isDuplicateKey;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
Object.defineProperty(exports, "mongoConnection", {
|
|
138
|
+
enumerable: true,
|
|
139
|
+
get: function() {
|
|
140
|
+
return mongoConnection;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(exports, "mongoKvStorage", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
get: function() {
|
|
146
|
+
return mongoKvStorage;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=mongodb--Cuj7V_9.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongodb--Cuj7V_9.cjs","names":["importPeer","canonical","escapeRegex","swapWithFallback"],"sources":["../src/storage/mongodb.ts"],"sourcesContent":["/**\n * MongoDB storage driver over the [`mongodb`](https://github.com/mongodb/node-mongodb-native)\n * driver (an optional peer). Pass a (optionally pre-connected) `MongoClient`, or a `url` to create\n * and connect one lazily on first use; a failed connect is retried on the next call.\n *\n * - One collection of `{ _id: <key>, value: <BSON> }` documents. Values are written with sorted\n * object keys, because BSON document equality is field-order sensitive.\n * - `getKeys` matches `_id` with an anchored, escaped regex (projecting only `_id`) plus an exact\n * `startsWith` filter, which guards against a case-insensitive collection collation.\n * - `compareAndSwap` is one `updateOne({ _id, $expr: { $eq: [\"$value\", { $literal: expected }] } })`\n * (`$literal`: a value with `$`-prefixed keys is never read as an expression), or an `insertOne`\n * guarded by the unique `_id` for an absent key. A document written before canonicalisation\n * (fields in insertion order) misses that fast path; the swap then reads it, compares it\n * structurally and swaps on the exact stored document (ADR 0005).\n * - No `watch`: change streams need a replica set. Compose `withWatch` if you have one.\n *\n * @module\n */\n\nimport type { Collection, Document, MongoClient } from \"mongodb\";\nimport { canonical } from \"../internal/json.ts\";\nimport { importPeer } from \"../internal/peer.ts\";\nimport { swapWithFallback } from \"./cas.ts\";\nimport type { CompareAndSwapInput, CompareAndSwapKvStorage } from \"./contract.ts\";\nimport { escapeRegex } from \"./util.ts\";\n\nconst SUBPATH = \"@xtandard/kit/storage/mongodb\";\n\n/** Options for {@link createMongoStorage}. */\nexport interface MongoStorageOptions {\n /** A pre-constructed (optionally pre-connected) `MongoClient`. Never closed by the driver. */\n client?: MongoClient;\n /** Connection string; a `MongoClient` is created lazily when no `client` is given. */\n url?: string;\n /** Database name (default `\"xtandard\"`; products pass theirs). */\n dbName?: string;\n /** Collection name (default `\"kv\"`; products pass theirs). */\n collectionName?: string;\n}\n\n/** A compare-and-swap capable storage backed by MongoDB, plus `close()`. */\nexport interface MongoKvStorage extends CompareAndSwapKvStorage {\n /** Disconnect the client if this driver created it; no-op for a borrowed one. */\n close(): Promise<void>;\n}\n\n/** One key/value document. */\nexport interface KvDocument extends Document {\n /** The storage key, verbatim. */\n _id: string;\n /** The stored value (any BSON). */\n value: unknown;\n}\n\n/** A lazily connected Mongo database handle (semi-public, ADR 0004). */\nexport interface MongoConnection {\n /** Resolve a collection, creating and connecting the client on first use (retried after a failure). */\n collection<T extends Document>(name: string): Promise<Collection<T>>;\n /** Close the client if this connection created it. */\n close(): Promise<void>;\n}\n\n/** Build a {@link MongoConnection} from a borrowed `client` or a `url`. */\nexport function mongoConnection(\n options: { client?: MongoClient; url?: string; dbName: string },\n subpath = SUBPATH,\n): MongoConnection {\n const ownsClient = !options.client;\n let client: MongoClient | undefined = options.client;\n let connecting: Promise<MongoClient> | undefined;\n\n async function connect(): Promise<MongoClient> {\n connecting ??= (async () => {\n if (!client) {\n if (options.url === undefined) {\n throw new Error(`${subpath} requires either a \\`client\\` or a \\`url\\``);\n }\n type Ctor = new (url: string) => MongoClient;\n const mod = await importPeer(\n \"mongodb\",\n subpath,\n () =>\n import(\"mongodb\") as unknown as Promise<{\n MongoClient?: Ctor;\n default?: { MongoClient: Ctor };\n }>,\n );\n const MongoClientCtor = (mod.MongoClient ?? mod.default?.MongoClient) as Ctor;\n client = new MongoClientCtor(options.url);\n }\n // connect() on an already connected client is a no-op in current drivers; older ones threw.\n try {\n await client.connect();\n } catch (error) {\n if (!isAlreadyConnected(error)) throw error;\n }\n return client;\n })();\n try {\n return await connecting;\n } catch (error) {\n connecting = undefined; // let a later operation retry\n throw error;\n }\n }\n\n return {\n async collection<T extends Document>(name: string): Promise<Collection<T>> {\n return (await connect()).db(options.dbName).collection<T>(name);\n },\n async close(): Promise<void> {\n if (ownsClient && client) await client.close();\n },\n };\n}\n\n/** True for a MongoDB duplicate-key error (E11000). Semi-public. */\nexport function isDuplicateKey(error: unknown): boolean {\n return (error as { code?: unknown } | null)?.code === 11000;\n}\n\nconst isAlreadyConnected = (error: unknown): boolean => {\n const message = error instanceof Error ? error.message.toLowerCase() : \"\";\n return message.includes(\"already\") && message.includes(\"connect\");\n};\n\n/**\n * The KV operations over a collection (semi-public, ADR 0004): `collection` resolves it before\n * every operation. {@link createMongoStorage} is this plus {@link mongoConnection}.\n */\nexport function mongoKvStorage(\n collection: () => Promise<Collection<KvDocument>>,\n): CompareAndSwapKvStorage {\n return {\n async getItem<T>(key: string): Promise<T | null> {\n const doc = await (await collection()).findOne({ _id: key });\n return doc ? (doc.value as T) : null;\n },\n\n async setItem<T>(key: string, value: T): Promise<void> {\n await (\n await collection()\n ).updateOne({ _id: key }, { $set: { value: canonical(value) } }, { upsert: true });\n },\n\n async removeItem(key: string): Promise<void> {\n await (await collection()).deleteOne({ _id: key });\n },\n\n async getKeys(prefix: string): Promise<string[]> {\n const cursor = (await collection())\n .find({ _id: { $regex: `^${escapeRegex(prefix)}` } })\n .project<{ _id: string }>({ _id: 1 });\n const out: string[] = [];\n for await (const doc of cursor) if (doc._id.startsWith(prefix)) out.push(doc._id);\n return out;\n },\n\n async compareAndSwap<T>(input: CompareAndSwapInput<T>): Promise<boolean> {\n const c = await collection();\n const next = canonical(input.next);\n if (input.expected === null) {\n try {\n await c.insertOne({ _id: input.key, value: next });\n return true;\n } catch (error) {\n if (isDuplicateKey(error)) return false;\n throw error;\n }\n }\n // `$expr` + `$literal`: exact equality (no array traversal), and `$`-prefixed keys stay data.\n const swap = async (current: unknown): Promise<boolean> =>\n (\n await c.updateOne(\n { _id: input.key, $expr: { $eq: [\"$value\", { $literal: current }] } },\n { $set: { value: next } },\n )\n ).matchedCount === 1;\n return swapWithFallback<unknown>(input.expected, {\n fast: () => swap(canonical(input.expected)),\n async read() {\n const doc = await c.findOne({ _id: input.key });\n return doc ? { raw: doc.value, value: doc.value } : null;\n },\n swapRaw: swap,\n });\n },\n };\n}\n\n/**\n * Create a MongoDB-backed {@link MongoKvStorage}. Connection is lazy and shared.\n *\n * @example\n * ```ts\n * import { createMongoStorage } from \"@xtandard/kit/storage/mongodb\";\n *\n * const storage = createMongoStorage({ url: process.env.MONGO_URL, dbName: \"app\", collectionName: \"kv\" });\n * ```\n */\nexport function createMongoStorage(options: MongoStorageOptions): MongoKvStorage {\n const { dbName = \"xtandard\", collectionName = \"kv\" } = options;\n const connection = mongoConnection({ ...options, dbName });\n return {\n ...mongoKvStorage(() => connection.collection<KvDocument>(collectionName)),\n close: connection.close,\n };\n}\n"],"mappings":";;;;;AA0BA,MAAM,UAAU;;AAqChB,SAAgB,gBACd,SACA,UAAU,SACO;CACjB,MAAM,aAAa,CAAC,QAAQ;CAC5B,IAAI,SAAkC,QAAQ;CAC9C,IAAI;CAEJ,eAAe,UAAgC;EAC7C,gBAAgB,YAAY;GAC1B,IAAI,CAAC,QAAQ;IACX,IAAI,QAAQ,QAAQ,KAAA,GAClB,MAAM,IAAI,MAAM,GAAG,QAAQ,2CAA2C;IAGxE,MAAM,MAAM,MAAMA,aAAAA,WAChB,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;AACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { n as CompareAndSwapKvStorage } from "./contract-BvgtswLX.cjs";
|
|
2
|
+
import { Collection, Document, MongoClient } from "mongodb";
|
|
3
|
+
|
|
4
|
+
//#region src/storage/mongodb.d.ts
|
|
5
|
+
/** Options for {@link createMongoStorage}. */
|
|
6
|
+
interface MongoStorageOptions {
|
|
7
|
+
/** A pre-constructed (optionally pre-connected) `MongoClient`. Never closed by the driver. */
|
|
8
|
+
client?: MongoClient;
|
|
9
|
+
/** Connection string; a `MongoClient` is created lazily when no `client` is given. */
|
|
10
|
+
url?: string;
|
|
11
|
+
/** Database name (default `"xtandard"`; products pass theirs). */
|
|
12
|
+
dbName?: string;
|
|
13
|
+
/** Collection name (default `"kv"`; products pass theirs). */
|
|
14
|
+
collectionName?: string;
|
|
15
|
+
}
|
|
16
|
+
/** A compare-and-swap capable storage backed by MongoDB, plus `close()`. */
|
|
17
|
+
interface MongoKvStorage extends CompareAndSwapKvStorage {
|
|
18
|
+
/** Disconnect the client if this driver created it; no-op for a borrowed one. */
|
|
19
|
+
close(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/** One key/value document. */
|
|
22
|
+
interface KvDocument extends Document {
|
|
23
|
+
/** The storage key, verbatim. */
|
|
24
|
+
_id: string;
|
|
25
|
+
/** The stored value (any BSON). */
|
|
26
|
+
value: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** A lazily connected Mongo database handle (semi-public, ADR 0004). */
|
|
29
|
+
interface MongoConnection {
|
|
30
|
+
/** Resolve a collection, creating and connecting the client on first use (retried after a failure). */
|
|
31
|
+
collection<T extends Document>(name: string): Promise<Collection<T>>;
|
|
32
|
+
/** Close the client if this connection created it. */
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/** Build a {@link MongoConnection} from a borrowed `client` or a `url`. */
|
|
36
|
+
declare function mongoConnection(options: {
|
|
37
|
+
client?: MongoClient;
|
|
38
|
+
url?: string;
|
|
39
|
+
dbName: string;
|
|
40
|
+
}, subpath?: string): MongoConnection;
|
|
41
|
+
/** True for a MongoDB duplicate-key error (E11000). Semi-public. */
|
|
42
|
+
declare function isDuplicateKey(error: unknown): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The KV operations over a collection (semi-public, ADR 0004): `collection` resolves it before
|
|
45
|
+
* every operation. {@link createMongoStorage} is this plus {@link mongoConnection}.
|
|
46
|
+
*/
|
|
47
|
+
declare function mongoKvStorage(collection: () => Promise<Collection<KvDocument>>): CompareAndSwapKvStorage;
|
|
48
|
+
/**
|
|
49
|
+
* Create a MongoDB-backed {@link MongoKvStorage}. Connection is lazy and shared.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { createMongoStorage } from "@xtandard/kit/storage/mongodb";
|
|
54
|
+
*
|
|
55
|
+
* const storage = createMongoStorage({ url: process.env.MONGO_URL, dbName: "app", collectionName: "kv" });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function createMongoStorage(options: MongoStorageOptions): MongoKvStorage;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { createMongoStorage as a, mongoKvStorage as c, MongoStorageOptions as i, MongoConnection as n, isDuplicateKey as o, MongoKvStorage as r, mongoConnection as s, KvDocument as t };
|
|
61
|
+
//# sourceMappingURL=mongodb-DGtsolQ2.d.cts.map
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { t as importPeer } from "./peer-CTHMzOdn.mjs";
|
|
2
|
+
import { o as escapeRegex } from "./util-Dnj5T-yw.mjs";
|
|
3
|
+
import { t as canonical } from "./json-CmM1M5Kz.mjs";
|
|
4
|
+
import { t as swapWithFallback } from "./cas-CzA-yECx.mjs";
|
|
5
|
+
//#region src/storage/mongodb.ts
|
|
6
|
+
const SUBPATH = "@xtandard/kit/storage/mongodb";
|
|
7
|
+
/** Build a {@link MongoConnection} from a borrowed `client` or a `url`. */
|
|
8
|
+
function mongoConnection(options, subpath = SUBPATH) {
|
|
9
|
+
const ownsClient = !options.client;
|
|
10
|
+
let client = options.client;
|
|
11
|
+
let connecting;
|
|
12
|
+
async function connect() {
|
|
13
|
+
connecting ??= (async () => {
|
|
14
|
+
if (!client) {
|
|
15
|
+
if (options.url === void 0) throw new Error(`${subpath} requires either a \`client\` or a \`url\``);
|
|
16
|
+
const mod = await importPeer("mongodb", subpath, () => import("mongodb"));
|
|
17
|
+
client = new (mod.MongoClient ?? mod.default?.MongoClient)(options.url);
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
await client.connect();
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (!isAlreadyConnected(error)) throw error;
|
|
23
|
+
}
|
|
24
|
+
return client;
|
|
25
|
+
})();
|
|
26
|
+
try {
|
|
27
|
+
return await connecting;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
connecting = void 0;
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
async collection(name) {
|
|
35
|
+
return (await connect()).db(options.dbName).collection(name);
|
|
36
|
+
},
|
|
37
|
+
async close() {
|
|
38
|
+
if (ownsClient && client) await client.close();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** True for a MongoDB duplicate-key error (E11000). Semi-public. */
|
|
43
|
+
function isDuplicateKey(error) {
|
|
44
|
+
return error?.code === 11e3;
|
|
45
|
+
}
|
|
46
|
+
const isAlreadyConnected = (error) => {
|
|
47
|
+
const message = error instanceof Error ? error.message.toLowerCase() : "";
|
|
48
|
+
return message.includes("already") && message.includes("connect");
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The KV operations over a collection (semi-public, ADR 0004): `collection` resolves it before
|
|
52
|
+
* every operation. {@link createMongoStorage} is this plus {@link mongoConnection}.
|
|
53
|
+
*/
|
|
54
|
+
function mongoKvStorage(collection) {
|
|
55
|
+
return {
|
|
56
|
+
async getItem(key) {
|
|
57
|
+
const doc = await (await collection()).findOne({ _id: key });
|
|
58
|
+
return doc ? doc.value : null;
|
|
59
|
+
},
|
|
60
|
+
async setItem(key, value) {
|
|
61
|
+
await (await collection()).updateOne({ _id: key }, { $set: { value: canonical(value) } }, { upsert: true });
|
|
62
|
+
},
|
|
63
|
+
async removeItem(key) {
|
|
64
|
+
await (await collection()).deleteOne({ _id: key });
|
|
65
|
+
},
|
|
66
|
+
async getKeys(prefix) {
|
|
67
|
+
const cursor = (await collection()).find({ _id: { $regex: `^${escapeRegex(prefix)}` } }).project({ _id: 1 });
|
|
68
|
+
const out = [];
|
|
69
|
+
for await (const doc of cursor) if (doc._id.startsWith(prefix)) out.push(doc._id);
|
|
70
|
+
return out;
|
|
71
|
+
},
|
|
72
|
+
async compareAndSwap(input) {
|
|
73
|
+
const c = await collection();
|
|
74
|
+
const next = canonical(input.next);
|
|
75
|
+
if (input.expected === null) try {
|
|
76
|
+
await c.insertOne({
|
|
77
|
+
_id: input.key,
|
|
78
|
+
value: next
|
|
79
|
+
});
|
|
80
|
+
return true;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (isDuplicateKey(error)) return false;
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
const swap = async (current) => (await c.updateOne({
|
|
86
|
+
_id: input.key,
|
|
87
|
+
$expr: { $eq: ["$value", { $literal: current }] }
|
|
88
|
+
}, { $set: { value: next } })).matchedCount === 1;
|
|
89
|
+
return swapWithFallback(input.expected, {
|
|
90
|
+
fast: () => swap(canonical(input.expected)),
|
|
91
|
+
async read() {
|
|
92
|
+
const doc = await c.findOne({ _id: input.key });
|
|
93
|
+
return doc ? {
|
|
94
|
+
raw: doc.value,
|
|
95
|
+
value: doc.value
|
|
96
|
+
} : null;
|
|
97
|
+
},
|
|
98
|
+
swapRaw: swap
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a MongoDB-backed {@link MongoKvStorage}. Connection is lazy and shared.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* import { createMongoStorage } from "@xtandard/kit/storage/mongodb";
|
|
109
|
+
*
|
|
110
|
+
* const storage = createMongoStorage({ url: process.env.MONGO_URL, dbName: "app", collectionName: "kv" });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
function createMongoStorage(options) {
|
|
114
|
+
const { dbName = "xtandard", collectionName = "kv" } = options;
|
|
115
|
+
const connection = mongoConnection({
|
|
116
|
+
...options,
|
|
117
|
+
dbName
|
|
118
|
+
});
|
|
119
|
+
return {
|
|
120
|
+
...mongoKvStorage(() => connection.collection(collectionName)),
|
|
121
|
+
close: connection.close
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
export { mongoKvStorage as i, isDuplicateKey as n, mongoConnection as r, createMongoStorage as t };
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=mongodb-JMizy4Wg.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongodb-JMizy4Wg.mjs","names":[],"sources":["../src/storage/mongodb.ts"],"sourcesContent":["/**\n * MongoDB storage driver over the [`mongodb`](https://github.com/mongodb/node-mongodb-native)\n * driver (an optional peer). Pass a (optionally pre-connected) `MongoClient`, or a `url` to create\n * and connect one lazily on first use; a failed connect is retried on the next call.\n *\n * - One collection of `{ _id: <key>, value: <BSON> }` documents. Values are written with sorted\n * object keys, because BSON document equality is field-order sensitive.\n * - `getKeys` matches `_id` with an anchored, escaped regex (projecting only `_id`) plus an exact\n * `startsWith` filter, which guards against a case-insensitive collection collation.\n * - `compareAndSwap` is one `updateOne({ _id, $expr: { $eq: [\"$value\", { $literal: expected }] } })`\n * (`$literal`: a value with `$`-prefixed keys is never read as an expression), or an `insertOne`\n * guarded by the unique `_id` for an absent key. A document written before canonicalisation\n * (fields in insertion order) misses that fast path; the swap then reads it, compares it\n * structurally and swaps on the exact stored document (ADR 0005).\n * - No `watch`: change streams need a replica set. Compose `withWatch` if you have one.\n *\n * @module\n */\n\nimport type { Collection, Document, MongoClient } from \"mongodb\";\nimport { canonical } from \"../internal/json.ts\";\nimport { importPeer } from \"../internal/peer.ts\";\nimport { swapWithFallback } from \"./cas.ts\";\nimport type { CompareAndSwapInput, CompareAndSwapKvStorage } from \"./contract.ts\";\nimport { escapeRegex } from \"./util.ts\";\n\nconst SUBPATH = \"@xtandard/kit/storage/mongodb\";\n\n/** Options for {@link createMongoStorage}. */\nexport interface MongoStorageOptions {\n /** A pre-constructed (optionally pre-connected) `MongoClient`. Never closed by the driver. */\n client?: MongoClient;\n /** Connection string; a `MongoClient` is created lazily when no `client` is given. */\n url?: string;\n /** Database name (default `\"xtandard\"`; products pass theirs). */\n dbName?: string;\n /** Collection name (default `\"kv\"`; products pass theirs). */\n collectionName?: string;\n}\n\n/** A compare-and-swap capable storage backed by MongoDB, plus `close()`. */\nexport interface MongoKvStorage extends CompareAndSwapKvStorage {\n /** Disconnect the client if this driver created it; no-op for a borrowed one. */\n close(): Promise<void>;\n}\n\n/** One key/value document. */\nexport interface KvDocument extends Document {\n /** The storage key, verbatim. */\n _id: string;\n /** The stored value (any BSON). */\n value: unknown;\n}\n\n/** A lazily connected Mongo database handle (semi-public, ADR 0004). */\nexport interface MongoConnection {\n /** Resolve a collection, creating and connecting the client on first use (retried after a failure). */\n collection<T extends Document>(name: string): Promise<Collection<T>>;\n /** Close the client if this connection created it. */\n close(): Promise<void>;\n}\n\n/** Build a {@link MongoConnection} from a borrowed `client` or a `url`. */\nexport function mongoConnection(\n options: { client?: MongoClient; url?: string; dbName: string },\n subpath = SUBPATH,\n): MongoConnection {\n const ownsClient = !options.client;\n let client: MongoClient | undefined = options.client;\n let connecting: Promise<MongoClient> | undefined;\n\n async function connect(): Promise<MongoClient> {\n connecting ??= (async () => {\n if (!client) {\n if (options.url === undefined) {\n throw new Error(`${subpath} requires either a \\`client\\` or a \\`url\\``);\n }\n type Ctor = new (url: string) => MongoClient;\n const mod = await importPeer(\n \"mongodb\",\n subpath,\n () =>\n import(\"mongodb\") as unknown as Promise<{\n MongoClient?: Ctor;\n default?: { MongoClient: Ctor };\n }>,\n );\n const MongoClientCtor = (mod.MongoClient ?? mod.default?.MongoClient) as Ctor;\n client = new MongoClientCtor(options.url);\n }\n // connect() on an already connected client is a no-op in current drivers; older ones threw.\n try {\n await client.connect();\n } catch (error) {\n if (!isAlreadyConnected(error)) throw error;\n }\n return client;\n })();\n try {\n return await connecting;\n } catch (error) {\n connecting = undefined; // let a later operation retry\n throw error;\n }\n }\n\n return {\n async collection<T extends Document>(name: string): Promise<Collection<T>> {\n return (await connect()).db(options.dbName).collection<T>(name);\n },\n async close(): Promise<void> {\n if (ownsClient && client) await client.close();\n },\n };\n}\n\n/** True for a MongoDB duplicate-key error (E11000). Semi-public. */\nexport function isDuplicateKey(error: unknown): boolean {\n return (error as { code?: unknown } | null)?.code === 11000;\n}\n\nconst isAlreadyConnected = (error: unknown): boolean => {\n const message = error instanceof Error ? error.message.toLowerCase() : \"\";\n return message.includes(\"already\") && message.includes(\"connect\");\n};\n\n/**\n * The KV operations over a collection (semi-public, ADR 0004): `collection` resolves it before\n * every operation. {@link createMongoStorage} is this plus {@link mongoConnection}.\n */\nexport function mongoKvStorage(\n collection: () => Promise<Collection<KvDocument>>,\n): CompareAndSwapKvStorage {\n return {\n async getItem<T>(key: string): Promise<T | null> {\n const doc = await (await collection()).findOne({ _id: key });\n return doc ? (doc.value as T) : null;\n },\n\n async setItem<T>(key: string, value: T): Promise<void> {\n await (\n await collection()\n ).updateOne({ _id: key }, { $set: { value: canonical(value) } }, { upsert: true });\n },\n\n async removeItem(key: string): Promise<void> {\n await (await collection()).deleteOne({ _id: key });\n },\n\n async getKeys(prefix: string): Promise<string[]> {\n const cursor = (await collection())\n .find({ _id: { $regex: `^${escapeRegex(prefix)}` } })\n .project<{ _id: string }>({ _id: 1 });\n const out: string[] = [];\n for await (const doc of cursor) if (doc._id.startsWith(prefix)) out.push(doc._id);\n return out;\n },\n\n async compareAndSwap<T>(input: CompareAndSwapInput<T>): Promise<boolean> {\n const c = await collection();\n const next = canonical(input.next);\n if (input.expected === null) {\n try {\n await c.insertOne({ _id: input.key, value: next });\n return true;\n } catch (error) {\n if (isDuplicateKey(error)) return false;\n throw error;\n }\n }\n // `$expr` + `$literal`: exact equality (no array traversal), and `$`-prefixed keys stay data.\n const swap = async (current: unknown): Promise<boolean> =>\n (\n await c.updateOne(\n { _id: input.key, $expr: { $eq: [\"$value\", { $literal: current }] } },\n { $set: { value: next } },\n )\n ).matchedCount === 1;\n return swapWithFallback<unknown>(input.expected, {\n fast: () => swap(canonical(input.expected)),\n async read() {\n const doc = await c.findOne({ _id: input.key });\n return doc ? { raw: doc.value, value: doc.value } : null;\n },\n swapRaw: swap,\n });\n },\n };\n}\n\n/**\n * Create a MongoDB-backed {@link MongoKvStorage}. Connection is lazy and shared.\n *\n * @example\n * ```ts\n * import { createMongoStorage } from \"@xtandard/kit/storage/mongodb\";\n *\n * const storage = createMongoStorage({ url: process.env.MONGO_URL, dbName: \"app\", collectionName: \"kv\" });\n * ```\n */\nexport function createMongoStorage(options: MongoStorageOptions): MongoKvStorage {\n const { dbName = \"xtandard\", collectionName = \"kv\" } = options;\n const connection = mongoConnection({ ...options, dbName });\n return {\n ...mongoKvStorage(() => connection.collection<KvDocument>(collectionName)),\n close: connection.close,\n };\n}\n"],"mappings":";;;;;AA0BA,MAAM,UAAU;;AAqChB,SAAgB,gBACd,SACA,UAAU,SACO;CACjB,MAAM,aAAa,CAAC,QAAQ;CAC5B,IAAI,SAAkC,QAAQ;CAC9C,IAAI;CAEJ,eAAe,UAAgC;EAC7C,gBAAgB,YAAY;GAC1B,IAAI,CAAC,QAAQ;IACX,IAAI,QAAQ,QAAQ,KAAA,GAClB,MAAM,IAAI,MAAM,GAAG,QAAQ,2CAA2C;IAGxE,MAAM,MAAM,MAAM,WAChB,WACA,eAEE,OAAO,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wapKvStorage } from "./contract-BvgtswLX.mjs";
|
|
2
|
+
import { Collection, Document, MongoClient } from "mongodb";
|
|
3
|
+
|
|
4
|
+
//#region src/storage/mongodb.d.ts
|
|
5
|
+
/** Options for {@link createMongoStorage}. */
|
|
6
|
+
interface MongoStorageOptions {
|
|
7
|
+
/** A pre-constructed (optionally pre-connected) `MongoClient`. Never closed by the driver. */
|
|
8
|
+
client?: MongoClient;
|
|
9
|
+
/** Connection string; a `MongoClient` is created lazily when no `client` is given. */
|
|
10
|
+
url?: string;
|
|
11
|
+
/** Database name (default `"xtandard"`; products pass theirs). */
|
|
12
|
+
dbName?: string;
|
|
13
|
+
/** Collection name (default `"kv"`; products pass theirs). */
|
|
14
|
+
collectionName?: string;
|
|
15
|
+
}
|
|
16
|
+
/** A compare-and-swap capable storage backed by MongoDB, plus `close()`. */
|
|
17
|
+
interface MongoKvStorage extends CompareAndSwapKvStorage {
|
|
18
|
+
/** Disconnect the client if this driver created it; no-op for a borrowed one. */
|
|
19
|
+
close(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/** One key/value document. */
|
|
22
|
+
interface KvDocument extends Document {
|
|
23
|
+
/** The storage key, verbatim. */
|
|
24
|
+
_id: string;
|
|
25
|
+
/** The stored value (any BSON). */
|
|
26
|
+
value: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** A lazily connected Mongo database handle (semi-public, ADR 0004). */
|
|
29
|
+
interface MongoConnection {
|
|
30
|
+
/** Resolve a collection, creating and connecting the client on first use (retried after a failure). */
|
|
31
|
+
collection<T extends Document>(name: string): Promise<Collection<T>>;
|
|
32
|
+
/** Close the client if this connection created it. */
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/** Build a {@link MongoConnection} from a borrowed `client` or a `url`. */
|
|
36
|
+
declare function mongoConnection(options: {
|
|
37
|
+
client?: MongoClient;
|
|
38
|
+
url?: string;
|
|
39
|
+
dbName: string;
|
|
40
|
+
}, subpath?: string): MongoConnection;
|
|
41
|
+
/** True for a MongoDB duplicate-key error (E11000). Semi-public. */
|
|
42
|
+
declare function isDuplicateKey(error: unknown): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The KV operations over a collection (semi-public, ADR 0004): `collection` resolves it before
|
|
45
|
+
* every operation. {@link createMongoStorage} is this plus {@link mongoConnection}.
|
|
46
|
+
*/
|
|
47
|
+
declare function mongoKvStorage(collection: () => Promise<Collection<KvDocument>>): CompareAndSwapKvStorage;
|
|
48
|
+
/**
|
|
49
|
+
* Create a MongoDB-backed {@link MongoKvStorage}. Connection is lazy and shared.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { createMongoStorage } from "@xtandard/kit/storage/mongodb";
|
|
54
|
+
*
|
|
55
|
+
* const storage = createMongoStorage({ url: process.env.MONGO_URL, dbName: "app", collectionName: "kv" });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function createMongoStorage(options: MongoStorageOptions): MongoKvStorage;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { createMongoStorage as a, mongoKvStorage as c, MongoStorageOptions as i, MongoConnection as n, isDuplicateKey as o, MongoKvStorage as r, mongoConnection as s, KvDocument as t };
|
|
61
|
+
//# sourceMappingURL=mongodb-xGEU5Gwz.d.mts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
|
|
3
|
+
//#region src/adapters/node.d.ts
|
|
4
|
+
/** A web-standard fetch handler. */
|
|
5
|
+
type FetchHandler = (request: Request) => Response | Promise<Response>;
|
|
6
|
+
/** A Node request, possibly decorated by Express (`originalUrl`, `protocol`, `body`). */
|
|
7
|
+
type NodeRequest = IncomingMessage & {
|
|
8
|
+
originalUrl?: string;
|
|
9
|
+
protocol?: string;
|
|
10
|
+
body?: unknown;
|
|
11
|
+
};
|
|
12
|
+
/** Options for {@link toWebRequest}. */
|
|
13
|
+
interface ToWebRequestOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Stream the request body to the handler only when it reads it, instead of
|
|
16
|
+
* buffering it first. Lets later middleware see an untouched stream when the
|
|
17
|
+
* handler ignores the body. Default `false`.
|
|
18
|
+
*/
|
|
19
|
+
lazyBody?: boolean;
|
|
20
|
+
/** Override the origin (`https://example.com`); default: protocol + `Host` header. */
|
|
21
|
+
origin?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Copy Node headers into `Headers`, appending each value of a multi-value header. */
|
|
24
|
+
declare function headersFrom(req: IncomingMessage): Headers;
|
|
25
|
+
/** The absolute URL of a Node request; `originalUrl` keeps an Express mount prefix. */
|
|
26
|
+
declare function requestUrl(req: NodeRequest, origin?: string): string;
|
|
27
|
+
/** Convert a Node (or Express) request into a web `Request`. */
|
|
28
|
+
declare function toWebRequest(req: NodeRequest, options?: ToWebRequestOptions): Promise<Request>;
|
|
29
|
+
/**
|
|
30
|
+
* Write a web `Response` to a Node `ServerResponse`, streaming the body with
|
|
31
|
+
* backpressure. Stops reading (and cancels the body) when the client
|
|
32
|
+
* disconnects.
|
|
33
|
+
*/
|
|
34
|
+
declare function writeWebResponse(res: ServerResponse, response: Response, request?: {
|
|
35
|
+
method?: string;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
/** Options for {@link toNodeHandler}. */
|
|
38
|
+
interface NodeHandlerOptions extends ToWebRequestOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Called when the handler throws. Default: a plain `500` (when headers have
|
|
41
|
+
* not been sent yet).
|
|
42
|
+
*/
|
|
43
|
+
onError?: (error: unknown, req: IncomingMessage, res: ServerResponse) => void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Wrap a fetch handler as a `node:http` request listener.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { createServer } from "node:http";
|
|
51
|
+
* createServer(toNodeHandler(panel.fetch)).listen(3000);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare function toNodeHandler(fetch: FetchHandler, options?: NodeHandlerOptions): (req: IncomingMessage, res: ServerResponse) => void;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { headersFrom as a, toWebRequest as c, ToWebRequestOptions as i, writeWebResponse as l, NodeHandlerOptions as n, requestUrl as o, NodeRequest as r, toNodeHandler as s, FetchHandler as t };
|
|
57
|
+
//# sourceMappingURL=node-B1Djcwfi.d.cts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
|
|
3
|
+
//#region src/adapters/node.d.ts
|
|
4
|
+
/** A web-standard fetch handler. */
|
|
5
|
+
type FetchHandler = (request: Request) => Response | Promise<Response>;
|
|
6
|
+
/** A Node request, possibly decorated by Express (`originalUrl`, `protocol`, `body`). */
|
|
7
|
+
type NodeRequest = IncomingMessage & {
|
|
8
|
+
originalUrl?: string;
|
|
9
|
+
protocol?: string;
|
|
10
|
+
body?: unknown;
|
|
11
|
+
};
|
|
12
|
+
/** Options for {@link toWebRequest}. */
|
|
13
|
+
interface ToWebRequestOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Stream the request body to the handler only when it reads it, instead of
|
|
16
|
+
* buffering it first. Lets later middleware see an untouched stream when the
|
|
17
|
+
* handler ignores the body. Default `false`.
|
|
18
|
+
*/
|
|
19
|
+
lazyBody?: boolean;
|
|
20
|
+
/** Override the origin (`https://example.com`); default: protocol + `Host` header. */
|
|
21
|
+
origin?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Copy Node headers into `Headers`, appending each value of a multi-value header. */
|
|
24
|
+
declare function headersFrom(req: IncomingMessage): Headers;
|
|
25
|
+
/** The absolute URL of a Node request; `originalUrl` keeps an Express mount prefix. */
|
|
26
|
+
declare function requestUrl(req: NodeRequest, origin?: string): string;
|
|
27
|
+
/** Convert a Node (or Express) request into a web `Request`. */
|
|
28
|
+
declare function toWebRequest(req: NodeRequest, options?: ToWebRequestOptions): Promise<Request>;
|
|
29
|
+
/**
|
|
30
|
+
* Write a web `Response` to a Node `ServerResponse`, streaming the body with
|
|
31
|
+
* backpressure. Stops reading (and cancels the body) when the client
|
|
32
|
+
* disconnects.
|
|
33
|
+
*/
|
|
34
|
+
declare function writeWebResponse(res: ServerResponse, response: Response, request?: {
|
|
35
|
+
method?: string;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
/** Options for {@link toNodeHandler}. */
|
|
38
|
+
interface NodeHandlerOptions extends ToWebRequestOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Called when the handler throws. Default: a plain `500` (when headers have
|
|
41
|
+
* not been sent yet).
|
|
42
|
+
*/
|
|
43
|
+
onError?: (error: unknown, req: IncomingMessage, res: ServerResponse) => void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Wrap a fetch handler as a `node:http` request listener.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { createServer } from "node:http";
|
|
51
|
+
* createServer(toNodeHandler(panel.fetch)).listen(3000);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare function toNodeHandler(fetch: FetchHandler, options?: NodeHandlerOptions): (req: IncomingMessage, res: ServerResponse) => void;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { headersFrom as a, toWebRequest as c, ToWebRequestOptions as i, writeWebResponse as l, NodeHandlerOptions as n, requestUrl as o, NodeRequest as r, toNodeHandler as s, FetchHandler as t };
|
|
57
|
+
//# sourceMappingURL=node-B1Djcwfi.d.mts.map
|