@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,306 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_json = require("./json-CM7TwYQ7.cjs");
|
|
3
|
+
let node_fs_promises = require("node:fs/promises");
|
|
4
|
+
let node_fs = require("node:fs");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
//#region src/storage/file.ts
|
|
7
|
+
/**
|
|
8
|
+
* File-system storage driver. Persists each key as a JSON file under a base directory, mirroring the
|
|
9
|
+
* `/`-delimited key layout as nested directories with a `.json` leaf. Zero dependencies
|
|
10
|
+
* (`node:fs/promises`, which works in Bun and Node).
|
|
11
|
+
*
|
|
12
|
+
* - Segments are encoded ({@link encodeSegment}) so every key maps to a distinct, safe file name on
|
|
13
|
+
* any filesystem: `Acme` / `acme` / `acmé` never collide on case- or normalization-insensitive
|
|
14
|
+
* volumes, a key can never escape the base directory, and an empty segment (`a//b`) is `%`.
|
|
15
|
+
* - Writes go to a temporary sibling and are renamed into place, so a crash never leaves a
|
|
16
|
+
* half-written file.
|
|
17
|
+
* - `compareAndSwap` is serialized per key **within this process** (an in-process lock around read →
|
|
18
|
+
* compare → write). It is not safe across processes sharing one directory; use a database driver
|
|
19
|
+
* for that.
|
|
20
|
+
* - Stores written before segment encoding (the "legacy" layout of raw segment names) are handled by
|
|
21
|
+
* the `legacy` option: ignore them, warn once, or read through to them; {@link migrateFileStorage}
|
|
22
|
+
* moves them to the encoded layout once.
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
/** Suffix appended to the leaf file of every stored key. */
|
|
27
|
+
const JSON_SUFFIX = ".json";
|
|
28
|
+
/**
|
|
29
|
+
* Encode one key segment as a file name that survives case-insensitive and
|
|
30
|
+
* normalization-insensitive filesystems and never escapes its directory: uppercase letters become
|
|
31
|
+
* `^` + the lowercase letter, `^` becomes `^^`, bytes outside `[a-z0-9._~!@,=+-]` become `%XX` (of
|
|
32
|
+
* the UTF-8 encoding, so `é` never folds with `e`), a leading `.` is `%2E` (no `.`, `..` or
|
|
33
|
+
* dotfiles) and the empty segment is a lone `%`.
|
|
34
|
+
*/
|
|
35
|
+
function encodeSegment(segment) {
|
|
36
|
+
if (segment === "") return "%";
|
|
37
|
+
let out = "";
|
|
38
|
+
for (const byte of new TextEncoder().encode(segment)) {
|
|
39
|
+
const ch = String.fromCharCode(byte);
|
|
40
|
+
if (byte >= 65 && byte <= 90) out += `^${ch.toLowerCase()}`;
|
|
41
|
+
else if (ch === "^") out += "^^";
|
|
42
|
+
else if (/[a-z0-9._~!@,=+-]/.test(ch) && !(ch === "." && out === "")) out += ch;
|
|
43
|
+
else out += `%${byte.toString(16).toUpperCase().padStart(2, "0")}`;
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/** Reverse {@link encodeSegment}. */
|
|
48
|
+
function decodeSegment(name) {
|
|
49
|
+
if (name === "%") return "";
|
|
50
|
+
const bytes = [];
|
|
51
|
+
for (let i = 0; i < name.length; i++) {
|
|
52
|
+
const ch = name[i];
|
|
53
|
+
if (ch === "^") {
|
|
54
|
+
const next = name[++i] ?? "";
|
|
55
|
+
bytes.push((next === "^" ? "^" : next.toUpperCase()).charCodeAt(0));
|
|
56
|
+
} else if (ch === "%") {
|
|
57
|
+
bytes.push(Number.parseInt(name.slice(i + 1, i + 3), 16));
|
|
58
|
+
i += 2;
|
|
59
|
+
} else bytes.push(ch.charCodeAt(0));
|
|
60
|
+
}
|
|
61
|
+
return new TextDecoder().decode(new Uint8Array(bytes));
|
|
62
|
+
}
|
|
63
|
+
/** Whether `name` is a file name {@link encodeSegment} produces (not a legacy raw segment). */
|
|
64
|
+
const isEncoded = (name) => encodeSegment(decodeSegment(name)) === name;
|
|
65
|
+
/** The encoded path of `key` under `dir`. */
|
|
66
|
+
const keyToPath = (dir, key) => (0, node_path.join)(dir, ...key.split("/").map(encodeSegment)) + JSON_SUFFIX;
|
|
67
|
+
/**
|
|
68
|
+
* The legacy (raw segment) path of `key`, when it differs from the encoded one. Keys with an empty
|
|
69
|
+
* segment have none: the legacy layout collapsed `a//b` onto `a/b`, so reading through would alias
|
|
70
|
+
* another key.
|
|
71
|
+
*/
|
|
72
|
+
function legacyPath(dir, key) {
|
|
73
|
+
const segments = key.split("/");
|
|
74
|
+
if (segments.includes("")) return void 0;
|
|
75
|
+
const path = (0, node_path.join)(dir, ...segments) + JSON_SUFFIX;
|
|
76
|
+
return path === keyToPath(dir, key) ? void 0 : path;
|
|
77
|
+
}
|
|
78
|
+
/** The `dir`-relative segments of a `.json` leaf under `dir`, or `null`. */
|
|
79
|
+
function leafSegments(dir, filePath) {
|
|
80
|
+
const rel = (0, node_path.relative)(dir, filePath);
|
|
81
|
+
if (rel === "" || rel.startsWith("..") || !rel.endsWith(JSON_SUFFIX)) return null;
|
|
82
|
+
return rel.slice(0, -5).split(node_path.sep);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The key of a leaf: `{ key, legacy: false }` in the encoded layout, `{ key, legacy: true }` when
|
|
86
|
+
* some segment is a raw legacy name (raw segments are taken verbatim; encoded ones, such as the
|
|
87
|
+
* all-lowercase `app`, decode to themselves), or `null` for a non-leaf.
|
|
88
|
+
*/
|
|
89
|
+
function leafKey(dir, filePath) {
|
|
90
|
+
const segments = leafSegments(dir, filePath);
|
|
91
|
+
if (!segments) return null;
|
|
92
|
+
const legacy = !segments.every(isEncoded);
|
|
93
|
+
return {
|
|
94
|
+
key: segments.map((s) => legacy && !isEncoded(s) ? s : decodeSegment(s)).join("/"),
|
|
95
|
+
legacy
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Whether `path` (under `dir`) exists with exactly this spelling. On a case-insensitive filesystem
|
|
100
|
+
* `app/acme.json` would otherwise open the legacy `app/Acme.json` (and vice versa); `realpath`
|
|
101
|
+
* returns the on-disk spelling.
|
|
102
|
+
*/
|
|
103
|
+
async function existsExactly(dir, path) {
|
|
104
|
+
try {
|
|
105
|
+
return (0, node_path.relative)(await (0, node_fs_promises.realpath)(dir), await (0, node_fs_promises.realpath)(path)) === (0, node_path.relative)(dir, path);
|
|
106
|
+
} catch {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** Recursively collect every `.json` leaf file path under `root`. */
|
|
111
|
+
async function walk(root) {
|
|
112
|
+
const out = [];
|
|
113
|
+
let entries;
|
|
114
|
+
try {
|
|
115
|
+
entries = await (0, node_fs_promises.readdir)(root, { withFileTypes: true });
|
|
116
|
+
} catch (err) {
|
|
117
|
+
if (err.code === "ENOENT") return out;
|
|
118
|
+
throw err;
|
|
119
|
+
}
|
|
120
|
+
for (const entry of entries) {
|
|
121
|
+
const name = entry.name.toString();
|
|
122
|
+
const full = (0, node_path.join)(root, name);
|
|
123
|
+
if (entry.isDirectory()) out.push(...await walk(full));
|
|
124
|
+
else if (entry.isFile() && name.endsWith(JSON_SUFFIX)) out.push(full);
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
async function readIfExists(path) {
|
|
129
|
+
try {
|
|
130
|
+
return await (0, node_fs_promises.readFile)(path, "utf8");
|
|
131
|
+
} catch (err) {
|
|
132
|
+
if (err.code === "ENOENT") return null;
|
|
133
|
+
throw err;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async function unlinkIfExists(path) {
|
|
137
|
+
try {
|
|
138
|
+
await (0, node_fs_promises.unlink)(path);
|
|
139
|
+
} catch (err) {
|
|
140
|
+
if (err.code !== "ENOENT") throw err;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const defaultOnLegacy = (dir) => {
|
|
144
|
+
console.warn(`[@xtandard/kit] storage/file: ${dir} has files in the legacy (unencoded) layout, which are ignored; run migrateFileStorage({ dir }) once to move them.`);
|
|
145
|
+
};
|
|
146
|
+
let tmpCounter = 0;
|
|
147
|
+
/**
|
|
148
|
+
* Create a file-backed {@link FileKvStorage}. Values are pretty-printed JSON. `watch` uses a
|
|
149
|
+
* recursive `fs.watch` on the base directory; it is best-effort and may coalesce or miss events on
|
|
150
|
+
* platforms without recursive-watch support. A `rename` event is reported as `remove` only when the
|
|
151
|
+
* file is actually gone.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* import { createFileStorage } from "@xtandard/kit/storage/file";
|
|
156
|
+
*
|
|
157
|
+
* const storage = createFileStorage({ dir: "./data" });
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
function createFileStorage(options) {
|
|
161
|
+
const { dir, legacy = "ignore", onLegacy = defaultOnLegacy } = options;
|
|
162
|
+
const readThrough = legacy === "read-through";
|
|
163
|
+
let warnedLegacy = false;
|
|
164
|
+
/** Per-key promise chains: every write to a key runs after the previous one. */
|
|
165
|
+
const locks = /* @__PURE__ */ new Map();
|
|
166
|
+
function withLock(key, fn) {
|
|
167
|
+
const run = (locks.get(key) ?? Promise.resolve()).then(fn, fn);
|
|
168
|
+
const tail = run.catch(() => {});
|
|
169
|
+
locks.set(key, tail);
|
|
170
|
+
tail.then(() => {
|
|
171
|
+
if (locks.get(key) === tail) locks.delete(key);
|
|
172
|
+
});
|
|
173
|
+
return run;
|
|
174
|
+
}
|
|
175
|
+
async function legacyIfExists(key) {
|
|
176
|
+
if (!readThrough) return void 0;
|
|
177
|
+
const path = legacyPath(dir, key);
|
|
178
|
+
return path && await existsExactly(dir, path) ? path : void 0;
|
|
179
|
+
}
|
|
180
|
+
async function read(key) {
|
|
181
|
+
const path = keyToPath(dir, key);
|
|
182
|
+
let raw = await readIfExists(path);
|
|
183
|
+
if (raw !== null && readThrough && !await existsExactly(dir, path)) raw = null;
|
|
184
|
+
if (raw === null) {
|
|
185
|
+
const path = await legacyIfExists(key);
|
|
186
|
+
if (path) raw = await readIfExists(path);
|
|
187
|
+
}
|
|
188
|
+
return raw === null ? null : JSON.parse(raw);
|
|
189
|
+
}
|
|
190
|
+
async function removeLegacy(key) {
|
|
191
|
+
const path = await legacyIfExists(key);
|
|
192
|
+
if (path) await unlinkIfExists(path);
|
|
193
|
+
}
|
|
194
|
+
async function write(key, value) {
|
|
195
|
+
const path = keyToPath(dir, key);
|
|
196
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), { recursive: true });
|
|
197
|
+
const tmp = `${path}.${process.pid}.${tmpCounter++}.tmp`;
|
|
198
|
+
await (0, node_fs_promises.writeFile)(tmp, JSON.stringify(value, null, 2), "utf8");
|
|
199
|
+
await (0, node_fs_promises.rename)(tmp, path);
|
|
200
|
+
await removeLegacy(key);
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
getItem: read,
|
|
204
|
+
async setItem(key, value) {
|
|
205
|
+
await withLock(key, () => write(key, value));
|
|
206
|
+
},
|
|
207
|
+
async removeItem(key) {
|
|
208
|
+
await withLock(key, async () => {
|
|
209
|
+
await unlinkIfExists(keyToPath(dir, key));
|
|
210
|
+
await removeLegacy(key);
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
async getKeys(prefix) {
|
|
214
|
+
const out = /* @__PURE__ */ new Set();
|
|
215
|
+
for (const file of await walk(dir)) {
|
|
216
|
+
const leaf = leafKey(dir, file);
|
|
217
|
+
if (!leaf) continue;
|
|
218
|
+
if (leaf.legacy && !readThrough) {
|
|
219
|
+
if (legacy === "warn" && !warnedLegacy) {
|
|
220
|
+
warnedLegacy = true;
|
|
221
|
+
onLegacy(dir);
|
|
222
|
+
}
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (leaf.key.startsWith(prefix)) out.add(leaf.key);
|
|
226
|
+
}
|
|
227
|
+
return [...out];
|
|
228
|
+
},
|
|
229
|
+
async compareAndSwap(input) {
|
|
230
|
+
return withLock(input.key, async () => {
|
|
231
|
+
if (!require_json.deepEqual(await read(input.key), input.expected)) return false;
|
|
232
|
+
await write(input.key, input.next);
|
|
233
|
+
return true;
|
|
234
|
+
});
|
|
235
|
+
},
|
|
236
|
+
async watch(prefix, callback) {
|
|
237
|
+
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
238
|
+
const watcher = (0, node_fs.watch)(dir, { recursive: true }, (eventType, filename) => {
|
|
239
|
+
if (!filename) return;
|
|
240
|
+
const full = (0, node_path.join)(dir, filename.toString());
|
|
241
|
+
const leaf = leafKey(dir, full);
|
|
242
|
+
if (!leaf || leaf.legacy && !readThrough || !leaf.key.startsWith(prefix)) return;
|
|
243
|
+
callback({
|
|
244
|
+
type: eventType === "rename" && !(0, node_fs.existsSync)(full) ? "remove" : "update",
|
|
245
|
+
key: leaf.key
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
return () => watcher.close();
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* One-time upgrade of a store in the legacy layout (raw key segments as file names, so keys
|
|
254
|
+
* differing only by case shared a file on case-insensitive filesystems). Moves every leaf that is
|
|
255
|
+
* not in the encoded layout to its {@link encodeSegment} path and removes the emptied directories.
|
|
256
|
+
* Idempotent; run it with no writer on the store. Resolves how many keys moved.
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```ts
|
|
260
|
+
* import { migrateFileStorage } from "@xtandard/kit/storage/file";
|
|
261
|
+
*
|
|
262
|
+
* await migrateFileStorage({ dir: "./data" });
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
async function migrateFileStorage(options) {
|
|
266
|
+
const { dir } = options;
|
|
267
|
+
let moved = 0;
|
|
268
|
+
const emptied = /* @__PURE__ */ new Set();
|
|
269
|
+
for (const file of await walk(dir)) {
|
|
270
|
+
const leaf = leafKey(dir, file);
|
|
271
|
+
if (!leaf?.legacy) continue;
|
|
272
|
+
const target = keyToPath(dir, leaf.key);
|
|
273
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(target), { recursive: true });
|
|
274
|
+
await (0, node_fs_promises.writeFile)(target, await (0, node_fs_promises.readFile)(file, "utf8"), "utf8");
|
|
275
|
+
await (0, node_fs_promises.unlink)(file);
|
|
276
|
+
emptied.add((0, node_path.dirname)(file));
|
|
277
|
+
moved++;
|
|
278
|
+
}
|
|
279
|
+
for (let d of [...emptied].sort((a, b) => b.length - a.length)) while (d !== dir && !(0, node_path.relative)(dir, d).startsWith("..")) {
|
|
280
|
+
try {
|
|
281
|
+
await (0, node_fs_promises.rmdir)(d);
|
|
282
|
+
} catch {
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
d = (0, node_path.dirname)(d);
|
|
286
|
+
}
|
|
287
|
+
return { moved };
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Delete every file written by a {@link createFileStorage} instance by removing its base directory.
|
|
291
|
+
* Exposed for tests and cleanup tooling.
|
|
292
|
+
*/
|
|
293
|
+
async function clearFileStorage(options) {
|
|
294
|
+
await (0, node_fs_promises.rm)(options.dir, {
|
|
295
|
+
recursive: true,
|
|
296
|
+
force: true
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
//#endregion
|
|
300
|
+
exports.clearFileStorage = clearFileStorage;
|
|
301
|
+
exports.createFileStorage = createFileStorage;
|
|
302
|
+
exports.decodeSegment = decodeSegment;
|
|
303
|
+
exports.encodeSegment = encodeSegment;
|
|
304
|
+
exports.migrateFileStorage = migrateFileStorage;
|
|
305
|
+
|
|
306
|
+
//# sourceMappingURL=entry-storage-file.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-storage-file.cjs","names":["sep","deepEqual"],"sources":["../src/storage/file.ts"],"sourcesContent":["/**\n * File-system storage driver. Persists each key as a JSON file under a base directory, mirroring the\n * `/`-delimited key layout as nested directories with a `.json` leaf. Zero dependencies\n * (`node:fs/promises`, which works in Bun and Node).\n *\n * - Segments are encoded ({@link encodeSegment}) so every key maps to a distinct, safe file name on\n * any filesystem: `Acme` / `acme` / `acmé` never collide on case- or normalization-insensitive\n * volumes, a key can never escape the base directory, and an empty segment (`a//b`) is `%`.\n * - Writes go to a temporary sibling and are renamed into place, so a crash never leaves a\n * half-written file.\n * - `compareAndSwap` is serialized per key **within this process** (an in-process lock around read →\n * compare → write). It is not safe across processes sharing one directory; use a database driver\n * for that.\n * - Stores written before segment encoding (the \"legacy\" layout of raw segment names) are handled by\n * the `legacy` option: ignore them, warn once, or read through to them; {@link migrateFileStorage}\n * moves them to the encoded layout once.\n *\n * @module\n */\n\nimport { existsSync, watch as fsWatch } from \"node:fs\";\nimport type { Dirent } from \"node:fs\";\nimport {\n mkdir,\n readdir,\n readFile,\n realpath,\n rename,\n rm,\n rmdir,\n unlink,\n writeFile,\n} from \"node:fs/promises\";\nimport { dirname, join, relative, sep } from \"node:path\";\nimport { deepEqual } from \"../internal/json.ts\";\nimport type {\n CompareAndSwapInput,\n CompareAndSwapKvStorage,\n StorageChangeEvent,\n WatchableKvStorage,\n} from \"./contract.ts\";\n\n/**\n * How {@link createFileStorage} treats leaves in the legacy (pre-encoding, raw segment) layout:\n *\n * - `\"ignore\"` (default): they are invisible;\n * - `\"warn\"`: invisible, and `onLegacy` is called once (by default a `console.warn` that points at\n * {@link migrateFileStorage});\n * - `\"read-through\"`: `getItem` falls back to the legacy file when the encoded one is missing,\n * `getKeys` lists legacy leaves too, and the next write or remove of that key deletes the legacy\n * file.\n */\nexport type FileLegacyMode = \"ignore\" | \"warn\" | \"read-through\";\n\n/** Options for {@link createFileStorage}. */\nexport interface FileStorageOptions {\n /** Base directory under which key files are written. Created on demand. */\n dir: string;\n /** How to treat leaves in the legacy raw-segment layout. Default `\"ignore\"`. */\n legacy?: FileLegacyMode;\n /**\n * Called once per storage instance when `legacy: \"warn\"` meets a legacy leaf. Products pass their\n * own message (it names the product and the release that wrote the legacy layout).\n */\n onLegacy?: (dir: string) => void;\n}\n\n/** The file storage: watchable and (in-process) compare-and-swap capable. */\nexport type FileKvStorage = WatchableKvStorage & CompareAndSwapKvStorage;\n\n/** Suffix appended to the leaf file of every stored key. */\nconst JSON_SUFFIX = \".json\";\n\n/**\n * Encode one key segment as a file name that survives case-insensitive and\n * normalization-insensitive filesystems and never escapes its directory: uppercase letters become\n * `^` + the lowercase letter, `^` becomes `^^`, bytes outside `[a-z0-9._~!@,=+-]` become `%XX` (of\n * the UTF-8 encoding, so `é` never folds with `e`), a leading `.` is `%2E` (no `.`, `..` or\n * dotfiles) and the empty segment is a lone `%`.\n */\nexport function encodeSegment(segment: string): string {\n if (segment === \"\") return \"%\";\n let out = \"\";\n for (const byte of new TextEncoder().encode(segment)) {\n const ch = String.fromCharCode(byte);\n if (byte >= 0x41 && byte <= 0x5a) out += `^${ch.toLowerCase()}`;\n else if (ch === \"^\") out += \"^^\";\n else if (/[a-z0-9._~!@,=+-]/.test(ch) && !(ch === \".\" && out === \"\")) out += ch;\n else out += `%${byte.toString(16).toUpperCase().padStart(2, \"0\")}`;\n }\n return out;\n}\n\n/** Reverse {@link encodeSegment}. */\nexport function decodeSegment(name: string): string {\n if (name === \"%\") return \"\";\n const bytes: number[] = [];\n for (let i = 0; i < name.length; i++) {\n const ch = name[i] as string;\n if (ch === \"^\") {\n const next = name[++i] ?? \"\";\n bytes.push((next === \"^\" ? \"^\" : next.toUpperCase()).charCodeAt(0));\n } else if (ch === \"%\") {\n bytes.push(Number.parseInt(name.slice(i + 1, i + 3), 16));\n i += 2;\n } else bytes.push(ch.charCodeAt(0));\n }\n return new TextDecoder().decode(new Uint8Array(bytes));\n}\n\n/** Whether `name` is a file name {@link encodeSegment} produces (not a legacy raw segment). */\nconst isEncoded = (name: string): boolean => encodeSegment(decodeSegment(name)) === name;\n\n/** The encoded path of `key` under `dir`. */\nconst keyToPath = (dir: string, key: string): string =>\n join(dir, ...key.split(\"/\").map(encodeSegment)) + JSON_SUFFIX;\n\n/**\n * The legacy (raw segment) path of `key`, when it differs from the encoded one. Keys with an empty\n * segment have none: the legacy layout collapsed `a//b` onto `a/b`, so reading through would alias\n * another key.\n */\nfunction legacyPath(dir: string, key: string): string | undefined {\n const segments = key.split(\"/\");\n if (segments.includes(\"\")) return undefined;\n const path = join(dir, ...segments) + JSON_SUFFIX;\n return path === keyToPath(dir, key) ? undefined : path;\n}\n\n/** The `dir`-relative segments of a `.json` leaf under `dir`, or `null`. */\nfunction leafSegments(dir: string, filePath: string): string[] | null {\n const rel = relative(dir, filePath);\n if (rel === \"\" || rel.startsWith(\"..\") || !rel.endsWith(JSON_SUFFIX)) return null;\n return rel.slice(0, -JSON_SUFFIX.length).split(sep);\n}\n\n/**\n * The key of a leaf: `{ key, legacy: false }` in the encoded layout, `{ key, legacy: true }` when\n * some segment is a raw legacy name (raw segments are taken verbatim; encoded ones, such as the\n * all-lowercase `app`, decode to themselves), or `null` for a non-leaf.\n */\nfunction leafKey(dir: string, filePath: string): { key: string; legacy: boolean } | null {\n const segments = leafSegments(dir, filePath);\n if (!segments) return null;\n const legacy = !segments.every(isEncoded);\n return {\n key: segments.map((s) => (legacy && !isEncoded(s) ? s : decodeSegment(s))).join(\"/\"),\n legacy,\n };\n}\n\n/**\n * Whether `path` (under `dir`) exists with exactly this spelling. On a case-insensitive filesystem\n * `app/acme.json` would otherwise open the legacy `app/Acme.json` (and vice versa); `realpath`\n * returns the on-disk spelling.\n */\nasync function existsExactly(dir: string, path: string): Promise<boolean> {\n try {\n return relative(await realpath(dir), await realpath(path)) === relative(dir, path);\n } catch {\n return false;\n }\n}\n\n/** Recursively collect every `.json` leaf file path under `root`. */\nasync function walk(root: string): Promise<string[]> {\n const out: string[] = [];\n let entries: Dirent[];\n try {\n entries = (await readdir(root, { withFileTypes: true })) as Dirent[];\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return out;\n throw err;\n }\n for (const entry of entries) {\n const name = entry.name.toString();\n const full = join(root, name);\n if (entry.isDirectory()) out.push(...(await walk(full)));\n else if (entry.isFile() && name.endsWith(JSON_SUFFIX)) out.push(full);\n }\n return out;\n}\n\nasync function readIfExists(path: string): Promise<string | null> {\n try {\n return await readFile(path, \"utf8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return null;\n throw err;\n }\n}\n\nasync function unlinkIfExists(path: string): Promise<void> {\n try {\n await unlink(path);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"ENOENT\") throw err;\n }\n}\n\nconst defaultOnLegacy = (dir: string): void => {\n console.warn(\n `[@xtandard/kit] storage/file: ${dir} has files in the legacy (unencoded) layout, which are ` +\n \"ignored; run migrateFileStorage({ dir }) once to move them.\",\n );\n};\n\nlet tmpCounter = 0;\n\n/**\n * Create a file-backed {@link FileKvStorage}. Values are pretty-printed JSON. `watch` uses a\n * recursive `fs.watch` on the base directory; it is best-effort and may coalesce or miss events on\n * platforms without recursive-watch support. A `rename` event is reported as `remove` only when the\n * file is actually gone.\n *\n * @example\n * ```ts\n * import { createFileStorage } from \"@xtandard/kit/storage/file\";\n *\n * const storage = createFileStorage({ dir: \"./data\" });\n * ```\n */\nexport function createFileStorage(options: FileStorageOptions): FileKvStorage {\n const { dir, legacy = \"ignore\", onLegacy = defaultOnLegacy } = options;\n const readThrough = legacy === \"read-through\";\n let warnedLegacy = false;\n /** Per-key promise chains: every write to a key runs after the previous one. */\n const locks = new Map<string, Promise<unknown>>();\n\n function withLock<T>(key: string, fn: () => Promise<T>): Promise<T> {\n const run = (locks.get(key) ?? Promise.resolve()).then(fn, fn);\n const tail = run.catch(() => {});\n locks.set(key, tail);\n void tail.then(() => {\n if (locks.get(key) === tail) locks.delete(key);\n });\n return run;\n }\n\n async function legacyIfExists(key: string): Promise<string | undefined> {\n if (!readThrough) return undefined;\n const path = legacyPath(dir, key);\n return path && (await existsExactly(dir, path)) ? path : undefined;\n }\n\n async function read<T>(key: string): Promise<T | null> {\n const path = keyToPath(dir, key);\n let raw = await readIfExists(path);\n // With legacy files around, the encoded path may resolve to a legacy file of another case.\n if (raw !== null && readThrough && !(await existsExactly(dir, path))) raw = null;\n if (raw === null) {\n const path = await legacyIfExists(key);\n if (path) raw = await readIfExists(path);\n }\n return raw === null ? null : (JSON.parse(raw) as T);\n }\n\n async function removeLegacy(key: string): Promise<void> {\n const path = await legacyIfExists(key);\n if (path) await unlinkIfExists(path);\n }\n\n async function write(key: string, value: unknown): Promise<void> {\n const path = keyToPath(dir, key);\n await mkdir(dirname(path), { recursive: true });\n // Write-then-rename: readers never observe a partially written file.\n const tmp = `${path}.${process.pid}.${tmpCounter++}.tmp`;\n await writeFile(tmp, JSON.stringify(value, null, 2), \"utf8\");\n await rename(tmp, path);\n await removeLegacy(key);\n }\n\n return {\n getItem: read,\n\n async setItem<T>(key: string, value: T): Promise<void> {\n await withLock(key, () => write(key, value));\n },\n\n async removeItem(key: string): Promise<void> {\n await withLock(key, async () => {\n await unlinkIfExists(keyToPath(dir, key));\n await removeLegacy(key);\n });\n },\n\n async getKeys(prefix: string): Promise<string[]> {\n // A Set: in read-through mode a legacy leaf and its encoded twin are the same key.\n const out = new Set<string>();\n for (const file of await walk(dir)) {\n const leaf = leafKey(dir, file);\n if (!leaf) continue;\n if (leaf.legacy && !readThrough) {\n if (legacy === \"warn\" && !warnedLegacy) {\n warnedLegacy = true;\n onLegacy(dir);\n }\n continue;\n }\n if (leaf.key.startsWith(prefix)) out.add(leaf.key);\n }\n return [...out];\n },\n\n async compareAndSwap<T>(input: CompareAndSwapInput<T>): Promise<boolean> {\n return withLock(input.key, async () => {\n if (!deepEqual(await read<T>(input.key), input.expected)) return false;\n await write(input.key, input.next);\n return true;\n });\n },\n\n async watch(\n prefix: string,\n callback: (event: StorageChangeEvent) => void,\n ): Promise<() => void> {\n // Ensure the watched root exists so fs.watch does not throw on a fresh dir.\n await mkdir(dir, { recursive: true });\n const watcher = fsWatch(dir, { recursive: true }, (eventType, filename) => {\n if (!filename) return;\n const full = join(dir, filename.toString());\n const leaf = leafKey(dir, full);\n if (!leaf || (leaf.legacy && !readThrough) || !leaf.key.startsWith(prefix)) return;\n // `rename` covers creation, deletion and our write-then-rename: report \"remove\" only when\n // the file is actually gone.\n const type: StorageChangeEvent[\"type\"] =\n eventType === \"rename\" && !existsSync(full) ? \"remove\" : \"update\";\n callback({ type, key: leaf.key });\n });\n return () => watcher.close();\n },\n };\n}\n\n/**\n * One-time upgrade of a store in the legacy layout (raw key segments as file names, so keys\n * differing only by case shared a file on case-insensitive filesystems). Moves every leaf that is\n * not in the encoded layout to its {@link encodeSegment} path and removes the emptied directories.\n * Idempotent; run it with no writer on the store. Resolves how many keys moved.\n *\n * @example\n * ```ts\n * import { migrateFileStorage } from \"@xtandard/kit/storage/file\";\n *\n * await migrateFileStorage({ dir: \"./data\" });\n * ```\n */\nexport async function migrateFileStorage(\n options: Pick<FileStorageOptions, \"dir\">,\n): Promise<{ moved: number }> {\n const { dir } = options;\n let moved = 0;\n const emptied = new Set<string>();\n for (const file of await walk(dir)) {\n const leaf = leafKey(dir, file);\n if (!leaf?.legacy) continue;\n const target = keyToPath(dir, leaf.key);\n await mkdir(dirname(target), { recursive: true });\n await writeFile(target, await readFile(file, \"utf8\"), \"utf8\");\n await unlink(file);\n emptied.add(dirname(file));\n moved++;\n }\n // Remove legacy directories left empty, deepest first, up to (not including) dir.\n for (let d of [...emptied].sort((a, b) => b.length - a.length)) {\n while (d !== dir && !relative(dir, d).startsWith(\"..\")) {\n try {\n await rmdir(d);\n } catch {\n break; // not empty (or already gone)\n }\n d = dirname(d);\n }\n }\n return { moved };\n}\n\n/**\n * Delete every file written by a {@link createFileStorage} instance by removing its base directory.\n * Exposed for tests and cleanup tooling.\n */\nexport async function clearFileStorage(options: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AM,KAAK,GAAG,GAAG;EAClC,MAAM,OAAO,QAAQ,KAAK,IAAI;EAC9B,IAAI,CAAC,MAAM,QAAQ;EACnB,MAAM,SAAS,UAAU,KAAK,KAAK,GAAG;EACtC,OAAA,GAAA,iBAAA,QAAA,GAAA,UAAA,SAAoB,MAAM,GAAG,EAAE,WAAW,KAAK,CAAC;EAChD,OAAA,GAAA,iBAAA,WAAgB,QAAQ,OAAA,GAAA,iBAAA,UAAe,MAAM,MAAM,GAAG,MAAM;EAC5D,OAAA,GAAA,iBAAA,QAAa,IAAI;EACjB,QAAQ,KAAA,GAAA,UAAA,SAAY,IAAI,CAAC;EACzB;CACF;CAEA,KAAK,IAAI,KAAK,CAAC,GAAG,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,GAC3D,OAAO,MAAM,OAAO,EAAA,GAAA,UAAA,UAAU,KAAK,CAAC,EAAE,WAAW,IAAI,GAAG;EACtD,IAAI;GACF,OAAA,GAAA,iBAAA,OAAY,CAAC;EACf,QAAQ;GACN;EACF;EACA,KAAA,GAAA,UAAA,SAAY,CAAC;CACf;CAEF,OAAO,EAAE,MAAM;AACjB;;;;;AAMA,eAAsB,iBAAiB,SAAyD;CAC9F,OAAA,GAAA,iBAAA,IAAS,QAAQ,KAAK;EAAE,WAAW;EAAM,OAAO;CAAK,CAAC;AACxD"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { n as CompareAndSwapKvStorage, o as WatchableKvStorage } from "./contract-BvgtswLX.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/storage/file.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* How {@link createFileStorage} treats leaves in the legacy (pre-encoding, raw segment) layout:
|
|
6
|
+
*
|
|
7
|
+
* - `"ignore"` (default): they are invisible;
|
|
8
|
+
* - `"warn"`: invisible, and `onLegacy` is called once (by default a `console.warn` that points at
|
|
9
|
+
* {@link migrateFileStorage});
|
|
10
|
+
* - `"read-through"`: `getItem` falls back to the legacy file when the encoded one is missing,
|
|
11
|
+
* `getKeys` lists legacy leaves too, and the next write or remove of that key deletes the legacy
|
|
12
|
+
* file.
|
|
13
|
+
*/
|
|
14
|
+
type FileLegacyMode = "ignore" | "warn" | "read-through";
|
|
15
|
+
/** Options for {@link createFileStorage}. */
|
|
16
|
+
interface FileStorageOptions {
|
|
17
|
+
/** Base directory under which key files are written. Created on demand. */
|
|
18
|
+
dir: string;
|
|
19
|
+
/** How to treat leaves in the legacy raw-segment layout. Default `"ignore"`. */
|
|
20
|
+
legacy?: FileLegacyMode;
|
|
21
|
+
/**
|
|
22
|
+
* Called once per storage instance when `legacy: "warn"` meets a legacy leaf. Products pass their
|
|
23
|
+
* own message (it names the product and the release that wrote the legacy layout).
|
|
24
|
+
*/
|
|
25
|
+
onLegacy?: (dir: string) => void;
|
|
26
|
+
}
|
|
27
|
+
/** The file storage: watchable and (in-process) compare-and-swap capable. */
|
|
28
|
+
type FileKvStorage = WatchableKvStorage & CompareAndSwapKvStorage;
|
|
29
|
+
/**
|
|
30
|
+
* Encode one key segment as a file name that survives case-insensitive and
|
|
31
|
+
* normalization-insensitive filesystems and never escapes its directory: uppercase letters become
|
|
32
|
+
* `^` + the lowercase letter, `^` becomes `^^`, bytes outside `[a-z0-9._~!@,=+-]` become `%XX` (of
|
|
33
|
+
* the UTF-8 encoding, so `é` never folds with `e`), a leading `.` is `%2E` (no `.`, `..` or
|
|
34
|
+
* dotfiles) and the empty segment is a lone `%`.
|
|
35
|
+
*/
|
|
36
|
+
declare function encodeSegment(segment: string): string;
|
|
37
|
+
/** Reverse {@link encodeSegment}. */
|
|
38
|
+
declare function decodeSegment(name: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Create a file-backed {@link FileKvStorage}. Values are pretty-printed JSON. `watch` uses a
|
|
41
|
+
* recursive `fs.watch` on the base directory; it is best-effort and may coalesce or miss events on
|
|
42
|
+
* platforms without recursive-watch support. A `rename` event is reported as `remove` only when the
|
|
43
|
+
* file is actually gone.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { createFileStorage } from "@xtandard/kit/storage/file";
|
|
48
|
+
*
|
|
49
|
+
* const storage = createFileStorage({ dir: "./data" });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
declare function createFileStorage(options: FileStorageOptions): FileKvStorage;
|
|
53
|
+
/**
|
|
54
|
+
* One-time upgrade of a store in the legacy layout (raw key segments as file names, so keys
|
|
55
|
+
* differing only by case shared a file on case-insensitive filesystems). Moves every leaf that is
|
|
56
|
+
* not in the encoded layout to its {@link encodeSegment} path and removes the emptied directories.
|
|
57
|
+
* Idempotent; run it with no writer on the store. Resolves how many keys moved.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { migrateFileStorage } from "@xtandard/kit/storage/file";
|
|
62
|
+
*
|
|
63
|
+
* await migrateFileStorage({ dir: "./data" });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function migrateFileStorage(options: Pick<FileStorageOptions, "dir">): Promise<{
|
|
67
|
+
moved: number;
|
|
68
|
+
}>;
|
|
69
|
+
/**
|
|
70
|
+
* Delete every file written by a {@link createFileStorage} instance by removing its base directory.
|
|
71
|
+
* Exposed for tests and cleanup tooling.
|
|
72
|
+
*/
|
|
73
|
+
declare function clearFileStorage(options: Pick<FileStorageOptions, "dir">): Promise<void>;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { type FileKvStorage, type FileLegacyMode, type FileStorageOptions, clearFileStorage, createFileStorage, decodeSegment, encodeSegment, migrateFileStorage };
|
|
76
|
+
//# sourceMappingURL=entry-storage-file.d.cts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { n as CompareAndSwapKvStorage, o as WatchableKvStorage } from "./contract-BvgtswLX.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/storage/file.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* How {@link createFileStorage} treats leaves in the legacy (pre-encoding, raw segment) layout:
|
|
6
|
+
*
|
|
7
|
+
* - `"ignore"` (default): they are invisible;
|
|
8
|
+
* - `"warn"`: invisible, and `onLegacy` is called once (by default a `console.warn` that points at
|
|
9
|
+
* {@link migrateFileStorage});
|
|
10
|
+
* - `"read-through"`: `getItem` falls back to the legacy file when the encoded one is missing,
|
|
11
|
+
* `getKeys` lists legacy leaves too, and the next write or remove of that key deletes the legacy
|
|
12
|
+
* file.
|
|
13
|
+
*/
|
|
14
|
+
type FileLegacyMode = "ignore" | "warn" | "read-through";
|
|
15
|
+
/** Options for {@link createFileStorage}. */
|
|
16
|
+
interface FileStorageOptions {
|
|
17
|
+
/** Base directory under which key files are written. Created on demand. */
|
|
18
|
+
dir: string;
|
|
19
|
+
/** How to treat leaves in the legacy raw-segment layout. Default `"ignore"`. */
|
|
20
|
+
legacy?: FileLegacyMode;
|
|
21
|
+
/**
|
|
22
|
+
* Called once per storage instance when `legacy: "warn"` meets a legacy leaf. Products pass their
|
|
23
|
+
* own message (it names the product and the release that wrote the legacy layout).
|
|
24
|
+
*/
|
|
25
|
+
onLegacy?: (dir: string) => void;
|
|
26
|
+
}
|
|
27
|
+
/** The file storage: watchable and (in-process) compare-and-swap capable. */
|
|
28
|
+
type FileKvStorage = WatchableKvStorage & CompareAndSwapKvStorage;
|
|
29
|
+
/**
|
|
30
|
+
* Encode one key segment as a file name that survives case-insensitive and
|
|
31
|
+
* normalization-insensitive filesystems and never escapes its directory: uppercase letters become
|
|
32
|
+
* `^` + the lowercase letter, `^` becomes `^^`, bytes outside `[a-z0-9._~!@,=+-]` become `%XX` (of
|
|
33
|
+
* the UTF-8 encoding, so `é` never folds with `e`), a leading `.` is `%2E` (no `.`, `..` or
|
|
34
|
+
* dotfiles) and the empty segment is a lone `%`.
|
|
35
|
+
*/
|
|
36
|
+
declare function encodeSegment(segment: string): string;
|
|
37
|
+
/** Reverse {@link encodeSegment}. */
|
|
38
|
+
declare function decodeSegment(name: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Create a file-backed {@link FileKvStorage}. Values are pretty-printed JSON. `watch` uses a
|
|
41
|
+
* recursive `fs.watch` on the base directory; it is best-effort and may coalesce or miss events on
|
|
42
|
+
* platforms without recursive-watch support. A `rename` event is reported as `remove` only when the
|
|
43
|
+
* file is actually gone.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { createFileStorage } from "@xtandard/kit/storage/file";
|
|
48
|
+
*
|
|
49
|
+
* const storage = createFileStorage({ dir: "./data" });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
declare function createFileStorage(options: FileStorageOptions): FileKvStorage;
|
|
53
|
+
/**
|
|
54
|
+
* One-time upgrade of a store in the legacy layout (raw key segments as file names, so keys
|
|
55
|
+
* differing only by case shared a file on case-insensitive filesystems). Moves every leaf that is
|
|
56
|
+
* not in the encoded layout to its {@link encodeSegment} path and removes the emptied directories.
|
|
57
|
+
* Idempotent; run it with no writer on the store. Resolves how many keys moved.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { migrateFileStorage } from "@xtandard/kit/storage/file";
|
|
62
|
+
*
|
|
63
|
+
* await migrateFileStorage({ dir: "./data" });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function migrateFileStorage(options: Pick<FileStorageOptions, "dir">): Promise<{
|
|
67
|
+
moved: number;
|
|
68
|
+
}>;
|
|
69
|
+
/**
|
|
70
|
+
* Delete every file written by a {@link createFileStorage} instance by removing its base directory.
|
|
71
|
+
* Exposed for tests and cleanup tooling.
|
|
72
|
+
*/
|
|
73
|
+
declare function clearFileStorage(options: Pick<FileStorageOptions, "dir">): Promise<void>;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { type FileKvStorage, type FileLegacyMode, type FileStorageOptions, clearFileStorage, createFileStorage, decodeSegment, encodeSegment, migrateFileStorage };
|
|
76
|
+
//# sourceMappingURL=entry-storage-file.d.mts.map
|