@xtandard/audit 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +384 -2
- package/bin/xtandard-audit.mjs +3 -0
- package/dist/basic-DU_nPrWV.mjs +176 -0
- package/dist/basic-DU_nPrWV.mjs.map +1 -0
- package/dist/basic-hcXnMF9X.cjs +199 -0
- package/dist/basic-hcXnMF9X.cjs.map +1 -0
- package/dist/canonical-BOgkrX9_.d.cts +17 -0
- package/dist/canonical-CL7gfwhb.d.mts +17 -0
- package/dist/chunk-D7D4PA-g.mjs +13 -0
- package/dist/cli.cjs +773 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +46 -0
- package/dist/cli.d.mts +46 -0
- package/dist/cli.mjs +762 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/context-BtR9k9Mt.d.mts +52 -0
- package/dist/context-CJM87uG8.d.cts +52 -0
- package/dist/context-shared-AgBWIRUQ.d.mts +29 -0
- package/dist/context-shared-CUq3cSpV.d.cts +29 -0
- package/dist/context-shared-CupikwQo.mjs +39 -0
- package/dist/context-shared-CupikwQo.mjs.map +1 -0
- package/dist/context-shared-X2ulHHSB.cjs +44 -0
- package/dist/context-shared-X2ulHHSB.cjs.map +1 -0
- package/dist/context.cjs +82 -0
- package/dist/context.cjs.map +1 -0
- package/dist/context.d.cts +2 -0
- package/dist/context.d.mts +2 -0
- package/dist/context.mjs +78 -0
- package/dist/context.mjs.map +1 -0
- package/dist/contract-BljSE-Hx.mjs +33 -0
- package/dist/contract-BljSE-Hx.mjs.map +1 -0
- package/dist/contract-BmwHIiMR.d.mts +150 -0
- package/dist/contract-CWJSYoJl.d.cts +150 -0
- package/dist/contract-Cht05WYQ.d.mts +159 -0
- package/dist/contract-CqYQzB6e.d.cts +49 -0
- package/dist/contract-DYvBNdnR.cjs +74 -0
- package/dist/contract-DYvBNdnR.cjs.map +1 -0
- package/dist/contract-DlTo4u2t.d.cts +30 -0
- package/dist/contract-DlTo4u2t.d.mts +30 -0
- package/dist/contract-DsVL5-gy.cjs +50 -0
- package/dist/contract-DsVL5-gy.cjs.map +1 -0
- package/dist/contract-isM9SjjQ.mjs +39 -0
- package/dist/contract-isM9SjjQ.mjs.map +1 -0
- package/dist/contract-pU3wGFmo.d.cts +159 -0
- package/dist/contract-yPNuFnVy.d.mts +49 -0
- package/dist/core-C0ceVOTk.d.cts +513 -0
- package/dist/core-CTr7dw0v.cjs +1725 -0
- package/dist/core-CTr7dw0v.cjs.map +1 -0
- package/dist/core-IdGEbYdM.mjs +1541 -0
- package/dist/core-IdGEbYdM.mjs.map +1 -0
- package/dist/core-KtEHRScZ.d.mts +513 -0
- package/dist/core.cjs +9 -0
- package/dist/core.d.cts +2 -0
- package/dist/core.d.mts +2 -0
- package/dist/core.mjs +2 -0
- package/dist/create-fetch-handler-1pXSEhGi.d.cts +311 -0
- package/dist/create-fetch-handler-BwQQ_IWf.mjs +2156 -0
- package/dist/create-fetch-handler-BwQQ_IWf.mjs.map +1 -0
- package/dist/create-fetch-handler-D8cTMVX9.cjs +2232 -0
- package/dist/create-fetch-handler-D8cTMVX9.cjs.map +1 -0
- package/dist/create-fetch-handler-zioPVS18.d.mts +311 -0
- package/dist/elysia-shared-C7geKqPP.mjs +55 -0
- package/dist/elysia-shared-C7geKqPP.mjs.map +1 -0
- package/dist/elysia-shared-DT4bfekR.d.cts +20 -0
- package/dist/elysia-shared-DXyAyGz_.cjs +66 -0
- package/dist/elysia-shared-DXyAyGz_.cjs.map +1 -0
- package/dist/elysia-shared-DoL5ab52.d.mts +20 -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-authorization-delegated.cjs +28 -0
- package/dist/entry-authorization-delegated.cjs.map +1 -0
- package/dist/entry-authorization-delegated.d.cts +32 -0
- package/dist/entry-authorization-delegated.d.mts +32 -0
- package/dist/entry-authorization-delegated.mjs +27 -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 +8 -0
- package/dist/entry-authorization-roles.d.cts +64 -0
- package/dist/entry-authorization-roles.d.mts +64 -0
- package/dist/entry-authorization-roles.mjs +3 -0
- package/dist/entry-bun.cjs +55 -0
- package/dist/entry-bun.cjs.map +1 -0
- package/dist/entry-bun.d.cts +29 -0
- package/dist/entry-bun.d.mts +29 -0
- package/dist/entry-bun.mjs +52 -0
- package/dist/entry-bun.mjs.map +1 -0
- package/dist/entry-drizzle-audit.cjs +191 -0
- package/dist/entry-drizzle-audit.cjs.map +1 -0
- package/dist/entry-drizzle-audit.d.cts +118 -0
- package/dist/entry-drizzle-audit.d.mts +118 -0
- package/dist/entry-drizzle-audit.mjs +186 -0
- package/dist/entry-drizzle-audit.mjs.map +1 -0
- package/dist/entry-drizzle-mysql.cjs +75 -0
- package/dist/entry-drizzle-mysql.cjs.map +1 -0
- package/dist/entry-drizzle-mysql.d.cts +42 -0
- package/dist/entry-drizzle-mysql.d.mts +42 -0
- package/dist/entry-drizzle-mysql.mjs +71 -0
- package/dist/entry-drizzle-mysql.mjs.map +1 -0
- package/dist/entry-drizzle-pg.cjs +82 -0
- package/dist/entry-drizzle-pg.cjs.map +1 -0
- package/dist/entry-drizzle-pg.d.cts +48 -0
- package/dist/entry-drizzle-pg.d.mts +48 -0
- package/dist/entry-drizzle-pg.mjs +78 -0
- package/dist/entry-drizzle-pg.mjs.map +1 -0
- package/dist/entry-drizzle-sqlite.cjs +71 -0
- package/dist/entry-drizzle-sqlite.cjs.map +1 -0
- package/dist/entry-drizzle-sqlite.d.cts +37 -0
- package/dist/entry-drizzle-sqlite.d.mts +37 -0
- package/dist/entry-drizzle-sqlite.mjs +67 -0
- package/dist/entry-drizzle-sqlite.mjs.map +1 -0
- package/dist/entry-elysia.cjs +112 -0
- package/dist/entry-elysia.cjs.map +1 -0
- package/dist/entry-elysia.d.cts +710 -0
- package/dist/entry-elysia.d.mts +710 -0
- package/dist/entry-elysia.mjs +109 -0
- package/dist/entry-elysia.mjs.map +1 -0
- package/dist/entry-elysia2.cjs +101 -0
- package/dist/entry-elysia2.cjs.map +1 -0
- package/dist/entry-elysia2.d.cts +905 -0
- package/dist/entry-elysia2.d.mts +905 -0
- package/dist/entry-elysia2.mjs +98 -0
- package/dist/entry-elysia2.mjs.map +1 -0
- package/dist/entry-express.cjs +90 -0
- package/dist/entry-express.cjs.map +1 -0
- package/dist/entry-express.d.cts +24 -0
- package/dist/entry-express.d.mts +24 -0
- package/dist/entry-express.mjs +88 -0
- package/dist/entry-express.mjs.map +1 -0
- package/dist/entry-hono.cjs +36 -0
- package/dist/entry-hono.cjs.map +1 -0
- package/dist/entry-hono.d.cts +24 -0
- package/dist/entry-hono.d.mts +24 -0
- package/dist/entry-hono.mjs +34 -0
- package/dist/entry-hono.mjs.map +1 -0
- package/dist/entry-hooks-log.cjs +22 -0
- package/dist/entry-hooks-log.cjs.map +1 -0
- package/dist/entry-hooks-log.d.cts +23 -0
- package/dist/entry-hooks-log.d.mts +23 -0
- package/dist/entry-hooks-log.mjs +21 -0
- package/dist/entry-hooks-log.mjs.map +1 -0
- package/dist/entry-sinks-console.cjs +43 -0
- package/dist/entry-sinks-console.cjs.map +1 -0
- package/dist/entry-sinks-console.d.cts +26 -0
- package/dist/entry-sinks-console.d.mts +26 -0
- package/dist/entry-sinks-console.mjs +41 -0
- package/dist/entry-sinks-console.mjs.map +1 -0
- package/dist/entry-sinks-datadog.cjs +97 -0
- package/dist/entry-sinks-datadog.cjs.map +1 -0
- package/dist/entry-sinks-datadog.d.cts +66 -0
- package/dist/entry-sinks-datadog.d.mts +66 -0
- package/dist/entry-sinks-datadog.mjs +91 -0
- package/dist/entry-sinks-datadog.mjs.map +1 -0
- package/dist/entry-sinks-file.cjs +100 -0
- package/dist/entry-sinks-file.cjs.map +1 -0
- package/dist/entry-sinks-file.d.cts +70 -0
- package/dist/entry-sinks-file.d.mts +70 -0
- package/dist/entry-sinks-file.mjs +97 -0
- package/dist/entry-sinks-file.mjs.map +1 -0
- package/dist/entry-sinks-http.cjs +63 -0
- package/dist/entry-sinks-http.cjs.map +1 -0
- package/dist/entry-sinks-http.d.cts +55 -0
- package/dist/entry-sinks-http.d.mts +55 -0
- package/dist/entry-sinks-http.mjs +60 -0
- package/dist/entry-sinks-http.mjs.map +1 -0
- package/dist/entry-sinks-s3.cjs +115 -0
- package/dist/entry-sinks-s3.cjs.map +1 -0
- package/dist/entry-sinks-s3.d.cts +79 -0
- package/dist/entry-sinks-s3.d.mts +79 -0
- package/dist/entry-sinks-s3.mjs +112 -0
- package/dist/entry-sinks-s3.mjs.map +1 -0
- package/dist/entry-sinks-splunk.cjs +80 -0
- package/dist/entry-sinks-splunk.cjs.map +1 -0
- package/dist/entry-sinks-splunk.d.cts +58 -0
- package/dist/entry-sinks-splunk.d.mts +58 -0
- package/dist/entry-sinks-splunk.mjs +77 -0
- package/dist/entry-sinks-splunk.mjs.map +1 -0
- package/dist/entry-sinks-webhook.cjs +130 -0
- package/dist/entry-sinks-webhook.cjs.map +1 -0
- package/dist/entry-sinks-webhook.d.cts +69 -0
- package/dist/entry-sinks-webhook.d.mts +69 -0
- package/dist/entry-sinks-webhook.mjs +125 -0
- package/dist/entry-sinks-webhook.mjs.map +1 -0
- package/dist/entry-sinks-xtandard-webhooks.cjs +64 -0
- package/dist/entry-sinks-xtandard-webhooks.cjs.map +1 -0
- package/dist/entry-sinks-xtandard-webhooks.d.cts +64 -0
- package/dist/entry-sinks-xtandard-webhooks.d.mts +64 -0
- package/dist/entry-sinks-xtandard-webhooks.mjs +63 -0
- package/dist/entry-sinks-xtandard-webhooks.mjs.map +1 -0
- package/dist/entry-storage-cloudflare-kv.cjs +47 -0
- package/dist/entry-storage-cloudflare-kv.cjs.map +1 -0
- package/dist/entry-storage-cloudflare-kv.d.cts +42 -0
- package/dist/entry-storage-cloudflare-kv.d.mts +42 -0
- package/dist/entry-storage-cloudflare-kv.mjs +46 -0
- package/dist/entry-storage-cloudflare-kv.mjs.map +1 -0
- package/dist/entry-storage-drizzle.cjs +228 -0
- package/dist/entry-storage-drizzle.cjs.map +1 -0
- package/dist/entry-storage-drizzle.d.cts +43 -0
- package/dist/entry-storage-drizzle.d.mts +43 -0
- package/dist/entry-storage-drizzle.mjs +227 -0
- package/dist/entry-storage-drizzle.mjs.map +1 -0
- package/dist/entry-storage-file.cjs +175 -0
- package/dist/entry-storage-file.cjs.map +1 -0
- package/dist/entry-storage-file.d.cts +41 -0
- package/dist/entry-storage-file.d.mts +41 -0
- package/dist/entry-storage-file.mjs +171 -0
- package/dist/entry-storage-file.mjs.map +1 -0
- package/dist/entry-storage-libsql.cjs +133 -0
- package/dist/entry-storage-libsql.cjs.map +1 -0
- package/dist/entry-storage-libsql.d.cts +60 -0
- package/dist/entry-storage-libsql.d.mts +60 -0
- package/dist/entry-storage-libsql.mjs +132 -0
- package/dist/entry-storage-libsql.mjs.map +1 -0
- package/dist/entry-storage-memory.cjs +3 -0
- package/dist/entry-storage-memory.d.cts +2 -0
- package/dist/entry-storage-memory.d.mts +2 -0
- package/dist/entry-storage-memory.mjs +2 -0
- package/dist/entry-storage-mongodb.cjs +306 -0
- package/dist/entry-storage-mongodb.cjs.map +1 -0
- package/dist/entry-storage-mongodb.d.cts +65 -0
- package/dist/entry-storage-mongodb.d.mts +65 -0
- package/dist/entry-storage-mongodb.mjs +304 -0
- package/dist/entry-storage-mongodb.mjs.map +1 -0
- package/dist/entry-storage-postgres.cjs +261 -0
- package/dist/entry-storage-postgres.cjs.map +1 -0
- package/dist/entry-storage-postgres.d.cts +66 -0
- package/dist/entry-storage-postgres.d.mts +66 -0
- package/dist/entry-storage-postgres.mjs +260 -0
- package/dist/entry-storage-postgres.mjs.map +1 -0
- package/dist/entry-storage-redis.cjs +223 -0
- package/dist/entry-storage-redis.cjs.map +1 -0
- package/dist/entry-storage-redis.d.cts +77 -0
- package/dist/entry-storage-redis.d.mts +77 -0
- package/dist/entry-storage-redis.mjs +221 -0
- package/dist/entry-storage-redis.mjs.map +1 -0
- package/dist/entry-storage-sqlite.cjs +85 -0
- package/dist/entry-storage-sqlite.cjs.map +1 -0
- package/dist/entry-storage-sqlite.d.cts +40 -0
- package/dist/entry-storage-sqlite.d.mts +40 -0
- package/dist/entry-storage-sqlite.mjs +84 -0
- package/dist/entry-storage-sqlite.mjs.map +1 -0
- package/dist/entry-storage-unstorage.cjs +57 -0
- package/dist/entry-storage-unstorage.cjs.map +1 -0
- package/dist/entry-storage-unstorage.d.cts +29 -0
- package/dist/entry-storage-unstorage.d.mts +29 -0
- package/dist/entry-storage-unstorage.mjs +56 -0
- package/dist/entry-storage-unstorage.mjs.map +1 -0
- package/dist/export-B9S-JeYl.mjs +239 -0
- package/dist/export-B9S-JeYl.mjs.map +1 -0
- package/dist/export-BZq0KCCn.d.mts +70 -0
- package/dist/export-DYfMd-ep.cjs +280 -0
- package/dist/export-DYfMd-ep.cjs.map +1 -0
- package/dist/export-Dh8T8I1p.d.cts +70 -0
- package/dist/index.cjs +279 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +286 -0
- package/dist/index.d.mts +284 -0
- package/dist/index.mjs +177 -0
- package/dist/index.mjs.map +1 -0
- package/dist/integrity-BHhjTBNk.cjs +614 -0
- package/dist/integrity-BHhjTBNk.cjs.map +1 -0
- package/dist/integrity-kfY2DNAi.mjs +483 -0
- package/dist/integrity-kfY2DNAi.mjs.map +1 -0
- package/dist/memory-CfykUo9W.cjs +155 -0
- package/dist/memory-CfykUo9W.cjs.map +1 -0
- package/dist/memory-DrR-Tlbf.d.mts +28 -0
- package/dist/memory-GG2Nba1D.mjs +150 -0
- package/dist/memory-GG2Nba1D.mjs.map +1 -0
- package/dist/memory-HpFdlMR_.d.cts +28 -0
- package/dist/none-Be7r6kHH.cjs +33 -0
- package/dist/none-Be7r6kHH.cjs.map +1 -0
- package/dist/none-CGmIIbI8.cjs +49 -0
- package/dist/none-CGmIIbI8.cjs.map +1 -0
- package/dist/none-CkV5mZsB.mjs +33 -0
- package/dist/none-CkV5mZsB.mjs.map +1 -0
- package/dist/none-DBeBeU0Z.mjs +23 -0
- package/dist/none-DBeBeU0Z.mjs.map +1 -0
- package/dist/query-ChGGtlA7.cjs +243 -0
- package/dist/query-ChGGtlA7.cjs.map +1 -0
- package/dist/query-LvZbyi37.mjs +172 -0
- package/dist/query-LvZbyi37.mjs.map +1 -0
- package/dist/react.css +1 -0
- package/dist/react.js +31935 -0
- package/dist/recorder-B3dG3jbd.d.mts +64 -0
- package/dist/recorder-CGY7HK29.d.cts +64 -0
- package/dist/roles-BARtYLSX.cjs +112 -0
- package/dist/roles-BARtYLSX.cjs.map +1 -0
- package/dist/roles-D7Pg89IJ.mjs +83 -0
- package/dist/roles-D7Pg89IJ.mjs.map +1 -0
- package/dist/schema-DmU7Wp0F.d.cts +251 -0
- package/dist/schema-DmU7Wp0F.d.mts +251 -0
- package/dist/schema.cjs +20 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +2 -0
- package/dist/schema.d.mts +2 -0
- package/dist/schema.mjs +17 -0
- package/dist/schema.mjs.map +1 -0
- package/dist/shared-CJOyJKqT.d.mts +20 -0
- package/dist/shared-DSDY-V0n.mjs +100 -0
- package/dist/shared-DSDY-V0n.mjs.map +1 -0
- package/dist/shared-EANCdRqn.d.cts +20 -0
- package/dist/shared-OOAq-U4S.cjs +141 -0
- package/dist/shared-OOAq-U4S.cjs.map +1 -0
- package/dist/sql-B7b6HzGy.cjs +280 -0
- package/dist/sql-B7b6HzGy.cjs.map +1 -0
- package/dist/sql-COjPyn3F.mjs +209 -0
- package/dist/sql-COjPyn3F.mjs.map +1 -0
- package/dist/sqlite-event-log-BnoG8eos.cjs +184 -0
- package/dist/sqlite-event-log-BnoG8eos.cjs.map +1 -0
- package/dist/sqlite-event-log-nXmS2DS_.mjs +179 -0
- package/dist/sqlite-event-log-nXmS2DS_.mjs.map +1 -0
- package/dist/streams-CRuxOYcb.d.cts +124 -0
- package/dist/streams-DU0_gvI8.d.mts +124 -0
- package/dist/table-BcarDd10.d.cts +48 -0
- package/dist/table-BcarDd10.d.mts +48 -0
- package/dist/testing.cjs +189 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +103 -0
- package/dist/testing.d.mts +103 -0
- package/dist/testing.mjs +185 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/types-elysia2/adapters/bun.d.ts +47 -0
- package/dist/types-elysia2/adapters/context-shared.d.ts +40 -0
- package/dist/types-elysia2/adapters/elysia-shared.d.ts +36 -0
- package/dist/types-elysia2/adapters/elysia2.d.ts +588 -0
- package/dist/types-elysia2/auth/contract.d.ts +26 -0
- package/dist/types-elysia2/authorization/contract.d.ts +54 -0
- package/dist/types-elysia2/canonical.d.ts +25 -0
- package/dist/types-elysia2/context.d.ts +61 -0
- package/dist/types-elysia2/core.d.ts +232 -0
- package/dist/types-elysia2/duration.d.ts +26 -0
- package/dist/types-elysia2/entry-elysia2.d.ts +10 -0
- package/dist/types-elysia2/event-log.d.ts +33 -0
- package/dist/types-elysia2/export.d.ts +77 -0
- package/dist/types-elysia2/hooks/contract.d.ts +177 -0
- package/dist/types-elysia2/id.d.ts +27 -0
- package/dist/types-elysia2/integrity.d.ts +193 -0
- package/dist/types-elysia2/keys.d.ts +91 -0
- package/dist/types-elysia2/portal.d.ts +137 -0
- package/dist/types-elysia2/query.d.ts +88 -0
- package/dist/types-elysia2/schema.d.ts +247 -0
- package/dist/types-elysia2/server/base-path.d.ts +15 -0
- package/dist/types-elysia2/server/cors.d.ts +36 -0
- package/dist/types-elysia2/server/create-fetch-handler.d.ts +140 -0
- package/dist/types-elysia2/server/openapi.d.ts +25 -0
- package/dist/types-elysia2/server/render-index-html.d.ts +18 -0
- package/dist/types-elysia2/server/routes.d.ts +83 -0
- package/dist/types-elysia2/server/static-assets.d.ts +13 -0
- package/dist/types-elysia2/standard-schema.d.ts +100 -0
- package/dist/types-elysia2/storage/contract.d.ts +106 -0
- package/dist/types-elysia2/streams.d.ts +134 -0
- package/dist/types-elysia2/transforms.d.ts +56 -0
- package/dist/types-elysia2/validation.d.ts +48 -0
- package/dist/types-react/canonical.d.ts +25 -0
- package/dist/types-react/context.d.ts +61 -0
- package/dist/types-react/core.d.ts +232 -0
- package/dist/types-react/duration.d.ts +26 -0
- package/dist/types-react/event-log.d.ts +33 -0
- package/dist/types-react/hooks/contract.d.ts +177 -0
- package/dist/types-react/id.d.ts +27 -0
- package/dist/types-react/integrity.d.ts +193 -0
- package/dist/types-react/keys.d.ts +91 -0
- package/dist/types-react/query.d.ts +88 -0
- package/dist/types-react/react.d.ts +114 -0
- package/dist/types-react/schema.d.ts +247 -0
- package/dist/types-react/standard-schema.d.ts +100 -0
- package/dist/types-react/storage/contract.d.ts +106 -0
- package/dist/types-react/streams.d.ts +134 -0
- package/dist/types-react/transforms.d.ts +56 -0
- package/dist/types-react/ui/App.d.ts +36 -0
- package/dist/types-react/ui/api.d.ts +61 -0
- package/dist/types-react/ui/components/ActionFilter.d.ts +17 -0
- package/dist/types-react/ui/components/ExportMenu.d.ts +13 -0
- package/dist/types-react/ui/components/JsonCodeEditor.d.ts +12 -0
- package/dist/types-react/ui/components/ThemeToggle.d.ts +2 -0
- package/dist/types-react/ui/components/Toast.d.ts +16 -0
- package/dist/types-react/ui/components/audit-bits.d.ts +91 -0
- package/dist/types-react/ui/components/integrity-bits.d.ts +19 -0
- package/dist/types-react/ui/components/primitives.d.ts +50 -0
- package/dist/types-react/ui/components/ui-bits.d.ts +22 -0
- package/dist/types-react/ui/lib/filters.d.ts +70 -0
- package/dist/types-react/ui/lib/format.d.ts +82 -0
- package/dist/types-react/ui/lib/nav-guard.d.ts +20 -0
- package/dist/types-react/ui/lib/portal-container.d.ts +24 -0
- package/dist/types-react/ui/lib/utils.d.ts +3 -0
- package/dist/types-react/ui/theme.d.ts +40 -0
- package/dist/types-react/ui/types.d.ts +67 -0
- package/dist/types-react/ui/views/ActionsView.d.ts +10 -0
- package/dist/types-react/ui/views/EventDrawer.d.ts +15 -0
- package/dist/types-react/ui/views/EventsView.d.ts +10 -0
- package/dist/types-react/ui/views/IntegrityView.d.ts +10 -0
- package/dist/types-react/ui/views/OverviewView.d.ts +9 -0
- package/dist/types-react/ui/views/StreamsView.d.ts +10 -0
- package/dist/types-react/ui/views/TenantsView.d.ts +6 -0
- package/dist/types-react/validation.d.ts +48 -0
- package/dist/ui/assets/favicon-BSj8MPnj.svg +11 -0
- package/dist/ui/assets/index-Cd-mcIwC.css +1 -0
- package/dist/ui/assets/index-DUAgpiot.js +244 -0
- package/dist/ui/index.html +15 -0
- package/dist/validation-DFrLESZD.mjs +150 -0
- package/dist/validation-DFrLESZD.mjs.map +1 -0
- package/dist/validation-lb0YXrxx.cjs +235 -0
- package/dist/validation-lb0YXrxx.cjs.map +1 -0
- package/dist/verify.cjs +14 -0
- package/dist/verify.d.cts +5 -0
- package/dist/verify.d.mts +5 -0
- package/dist/verify.mjs +3 -0
- package/package.json +610 -4
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { existsSync, watch } from "node:fs";
|
|
2
|
+
import { mkdir, readFile, readdir, rename, rm, unlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join, relative, sep } from "node:path";
|
|
4
|
+
//#region src/storage/file.ts
|
|
5
|
+
/**
|
|
6
|
+
* File-system storage adapter. Persists each key as a JSON file under a base
|
|
7
|
+
* directory, mirroring the slash-delimited key layout (`aud/t/{tenant}/…`) as a
|
|
8
|
+
* tree of nested directories with a `.json` extension on the leaf. Zero
|
|
9
|
+
* external dependencies — uses `node:fs/promises`, which works in both Bun and
|
|
10
|
+
* Node.
|
|
11
|
+
*
|
|
12
|
+
* KV only: events go through the core's generic KV event log (ADR 0005), one
|
|
13
|
+
* file per event plus one per index entry. Fine for development, demos and
|
|
14
|
+
* small single-process deployments; there is no compare-and-swap, so the core
|
|
15
|
+
* assumes a **single writer per tenant** (one process). Writes go to a temp file
|
|
16
|
+
* that is then renamed over the target, so a concurrent reader never sees a
|
|
17
|
+
* half-written value.
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
/** Suffix appended to the leaf file for every stored key. */
|
|
22
|
+
const JSON_SUFFIX = ".json";
|
|
23
|
+
/**
|
|
24
|
+
* Encode one key segment as a file name that survives case-insensitive and
|
|
25
|
+
* normalization-insensitive filesystems (macOS, Windows) and never escapes its
|
|
26
|
+
* directory: uppercase letters become `^` + the lowercase letter, `^` becomes
|
|
27
|
+
* `^^`, bytes outside `[a-z0-9._~!@,=+-]` become `%XX`, and a leading `.` is
|
|
28
|
+
* `%2E` (so `.` / `..` / dotfiles cannot appear). Without it, tenants `Acme` and
|
|
29
|
+
* `acme` would share files on a default macOS volume.
|
|
30
|
+
*/
|
|
31
|
+
function encodeSegment(segment) {
|
|
32
|
+
let out = "";
|
|
33
|
+
for (const byte of new TextEncoder().encode(segment)) {
|
|
34
|
+
const ch = String.fromCharCode(byte);
|
|
35
|
+
if (byte >= 65 && byte <= 90) out += `^${ch.toLowerCase()}`;
|
|
36
|
+
else if (ch === "^") out += "^^";
|
|
37
|
+
else if (/[a-z0-9._~!@,=+-]/.test(ch) && !(ch === "." && out === "")) out += ch;
|
|
38
|
+
else out += `%${byte.toString(16).toUpperCase().padStart(2, "0")}`;
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
/** Reverse {@link encodeSegment}. */
|
|
43
|
+
function decodeSegment(name) {
|
|
44
|
+
const bytes = [];
|
|
45
|
+
for (let i = 0; i < name.length; i++) {
|
|
46
|
+
const ch = name[i];
|
|
47
|
+
if (ch === "^") {
|
|
48
|
+
const next = name[++i] ?? "";
|
|
49
|
+
bytes.push((next === "^" ? "^" : next.toUpperCase()).charCodeAt(0));
|
|
50
|
+
} else if (ch === "%") {
|
|
51
|
+
bytes.push(Number.parseInt(name.slice(i + 1, i + 3), 16));
|
|
52
|
+
i += 2;
|
|
53
|
+
} else bytes.push(ch.charCodeAt(0));
|
|
54
|
+
}
|
|
55
|
+
return new TextDecoder().decode(new Uint8Array(bytes));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Map a storage key (e.g. `aud/t/acme/head`) to an absolute file path inside
|
|
59
|
+
* `dir`. Each key segment becomes a directory; the last segment gains a
|
|
60
|
+
* `.json` extension.
|
|
61
|
+
*/
|
|
62
|
+
function keyToPath(dir, key) {
|
|
63
|
+
return join(dir, ...key.split("/").map(encodeSegment)) + JSON_SUFFIX;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Reverse {@link keyToPath}: turn an absolute (or `dir`-relative) file path back
|
|
67
|
+
* into the original slash-delimited storage key. Returns `null` for paths that
|
|
68
|
+
* are not `.json` leaves under `dir` (including in-flight temp files).
|
|
69
|
+
*/
|
|
70
|
+
function pathToKey(dir, filePath) {
|
|
71
|
+
const rel = relative(dir, filePath);
|
|
72
|
+
if (rel.startsWith("..") || !rel.endsWith(JSON_SUFFIX)) return null;
|
|
73
|
+
return rel.slice(0, -5).split(sep).map(decodeSegment).join("/");
|
|
74
|
+
}
|
|
75
|
+
/** Recursively collect every `.json` leaf file path under `root`. */
|
|
76
|
+
async function walk(root) {
|
|
77
|
+
const out = [];
|
|
78
|
+
let entries;
|
|
79
|
+
try {
|
|
80
|
+
entries = await readdir(root, { withFileTypes: true });
|
|
81
|
+
} catch (err) {
|
|
82
|
+
if (err.code === "ENOENT") return out;
|
|
83
|
+
throw err;
|
|
84
|
+
}
|
|
85
|
+
for (const entry of entries) {
|
|
86
|
+
const name = entry.name.toString();
|
|
87
|
+
const full = join(root, name);
|
|
88
|
+
if (entry.isDirectory()) out.push(...await walk(full));
|
|
89
|
+
else if (entry.isFile() && name.endsWith(JSON_SUFFIX)) out.push(full);
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
let tmpCounter = 0;
|
|
94
|
+
/**
|
|
95
|
+
* Create a file-backed {@link WatchableAuditStorage}. Values are serialized
|
|
96
|
+
* as pretty-printed JSON. `watch` is implemented via `fs.watch` on the base
|
|
97
|
+
* directory (recursive); it is best-effort and may coalesce or miss events on
|
|
98
|
+
* platforms without recursive-watch support.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* import { createFileStorage } from "@xtandard/audit/storage/file";
|
|
103
|
+
*
|
|
104
|
+
* const storage = createFileStorage({ dir: "./data/audit" });
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
function createFileStorage(options) {
|
|
108
|
+
const { dir } = options;
|
|
109
|
+
return {
|
|
110
|
+
async getItem(key) {
|
|
111
|
+
try {
|
|
112
|
+
const raw = await readFile(keyToPath(dir, key), "utf8");
|
|
113
|
+
return JSON.parse(raw);
|
|
114
|
+
} catch (err) {
|
|
115
|
+
if (err.code === "ENOENT") return null;
|
|
116
|
+
throw err;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
async setItem(key, value) {
|
|
120
|
+
const path = keyToPath(dir, key);
|
|
121
|
+
await mkdir(dirname(path), { recursive: true });
|
|
122
|
+
const tmp = `${path}.${process.pid}.${tmpCounter++}.tmp`;
|
|
123
|
+
await writeFile(tmp, JSON.stringify(value, null, 2), "utf8");
|
|
124
|
+
await rename(tmp, path);
|
|
125
|
+
},
|
|
126
|
+
async removeItem(key) {
|
|
127
|
+
try {
|
|
128
|
+
await unlink(keyToPath(dir, key));
|
|
129
|
+
} catch (err) {
|
|
130
|
+
if (err.code !== "ENOENT") throw err;
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
async getKeys(prefix) {
|
|
134
|
+
const files = await walk(dir);
|
|
135
|
+
const out = [];
|
|
136
|
+
for (const file of files) {
|
|
137
|
+
const key = pathToKey(dir, file);
|
|
138
|
+
if (key !== null && key.startsWith(prefix)) out.push(key);
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
},
|
|
142
|
+
async watch(prefix, callback) {
|
|
143
|
+
await mkdir(dir, { recursive: true });
|
|
144
|
+
const watcher = watch(dir, { recursive: true }, (eventType, filename) => {
|
|
145
|
+
if (!filename) return;
|
|
146
|
+
const path = join(dir, filename.toString());
|
|
147
|
+
const key = pathToKey(dir, path);
|
|
148
|
+
if (key === null || !key.startsWith(prefix)) return;
|
|
149
|
+
callback({
|
|
150
|
+
type: eventType === "rename" && !existsSync(path) ? "remove" : "update",
|
|
151
|
+
key
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
return () => watcher.close();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Delete every file written by a {@link createFileStorage} instance by removing
|
|
160
|
+
* its base directory. Exposed primarily for tests and cleanup tooling.
|
|
161
|
+
*/
|
|
162
|
+
async function clearFileStorage(options) {
|
|
163
|
+
await rm(options.dir, {
|
|
164
|
+
recursive: true,
|
|
165
|
+
force: true
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
//#endregion
|
|
169
|
+
export { clearFileStorage, createFileStorage, decodeSegment, encodeSegment };
|
|
170
|
+
|
|
171
|
+
//# sourceMappingURL=entry-storage-file.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-storage-file.mjs","names":["fsWatch"],"sources":["../src/storage/file.ts"],"sourcesContent":["/**\n * File-system storage adapter. Persists each key as a JSON file under a base\n * directory, mirroring the slash-delimited key layout (`aud/t/{tenant}/…`) as a\n * tree of nested directories with a `.json` extension on the leaf. Zero\n * external dependencies — uses `node:fs/promises`, which works in both Bun and\n * Node.\n *\n * KV only: events go through the core's generic KV event log (ADR 0005), one\n * file per event plus one per index entry. Fine for development, demos and\n * small single-process deployments; there is no compare-and-swap, so the core\n * assumes a **single writer per tenant** (one process). Writes go to a temp file\n * that is then renamed over the target, so a concurrent reader never sees a\n * half-written value.\n *\n * @module\n */\n\nimport { existsSync, watch as fsWatch } from \"node:fs\";\nimport type { Dirent } from \"node:fs\";\nimport { mkdir, readdir, readFile, rename, rm, unlink, writeFile } from \"node:fs/promises\";\nimport { dirname, join, relative, sep } from \"node:path\";\nimport type { StorageChangeEvent, WatchableAuditStorage } from \"./contract.ts\";\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}\n\n/** Suffix appended to the leaf file for 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 (macOS, Windows) and never escapes its\n * directory: uppercase letters become `^` + the lowercase letter, `^` becomes\n * `^^`, bytes outside `[a-z0-9._~!@,=+-]` become `%XX`, and a leading `.` is\n * `%2E` (so `.` / `..` / dotfiles cannot appear). Without it, tenants `Acme` and\n * `acme` would share files on a default macOS volume.\n */\nexport function encodeSegment(segment: string): string {\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 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/**\n * Map a storage key (e.g. `aud/t/acme/head`) to an absolute file path inside\n * `dir`. Each key segment becomes a directory; the last segment gains a\n * `.json` extension.\n */\nfunction keyToPath(dir: string, key: string): string {\n return join(dir, ...key.split(\"/\").map(encodeSegment)) + JSON_SUFFIX;\n}\n\n/**\n * Reverse {@link keyToPath}: turn an absolute (or `dir`-relative) file path back\n * into the original slash-delimited storage key. Returns `null` for paths that\n * are not `.json` leaves under `dir` (including in-flight temp files).\n */\nfunction pathToKey(dir: string, filePath: string): string | null {\n const rel = relative(dir, filePath);\n if (rel.startsWith(\"..\") || !rel.endsWith(JSON_SUFFIX)) return null;\n return rel.slice(0, -JSON_SUFFIX.length).split(sep).map(decodeSegment).join(\"/\");\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()) {\n out.push(...(await walk(full)));\n } else if (entry.isFile() && name.endsWith(JSON_SUFFIX)) {\n out.push(full);\n }\n }\n return out;\n}\n\nlet tmpCounter = 0;\n\n/**\n * Create a file-backed {@link WatchableAuditStorage}. Values are serialized\n * as pretty-printed JSON. `watch` is implemented via `fs.watch` on the base\n * directory (recursive); it is best-effort and may coalesce or miss events on\n * platforms without recursive-watch support.\n *\n * @example\n * ```ts\n * import { createFileStorage } from \"@xtandard/audit/storage/file\";\n *\n * const storage = createFileStorage({ dir: \"./data/audit\" });\n * ```\n */\nexport function createFileStorage(options: FileStorageOptions): WatchableAuditStorage {\n const { dir } = options;\n\n return {\n async getItem<T>(key: string): Promise<T | null> {\n try {\n const raw = await readFile(keyToPath(dir, key), \"utf8\");\n return JSON.parse(raw) as T;\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return null;\n throw err;\n }\n },\n\n async setItem<T>(key: string, value: T): Promise<void> {\n const path = keyToPath(dir, key);\n await mkdir(dirname(path), { recursive: true });\n // Write-then-rename: rename is atomic within a filesystem, so readers see\n // either the old or the new value, never a truncated 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 },\n\n async removeItem(key: string): Promise<void> {\n try {\n await unlink(keyToPath(dir, key));\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"ENOENT\") throw err;\n }\n },\n\n async getKeys(prefix: string): Promise<string[]> {\n const files = await walk(dir);\n const out: string[] = [];\n for (const file of files) {\n const key = pathToKey(dir, file);\n if (key !== null && key.startsWith(prefix)) out.push(key);\n }\n return out;\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 path = join(dir, filename.toString());\n const key = pathToKey(dir, path);\n if (key === null || !key.startsWith(prefix)) return;\n // `rename` covers creation (incl. our temp-file rename), replacement and\n // deletion; the file's presence tells them apart.\n const type: StorageChangeEvent[\"type\"] =\n eventType === \"rename\" && !existsSync(path) ? \"remove\" : \"update\";\n callback({ type, key });\n });\n return () => watcher.close();\n },\n } satisfies WatchableAuditStorage;\n}\n\n/**\n * Delete every file written by a {@link createFileStorage} instance by removing\n * its base directory. Exposed primarily for tests and cleanup tooling.\n */\nexport async function clearFileStorage(options: FileStorageOptions): Promise<void> {\n await rm(options.dir, { recursive: true, force: true });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,cAAc;;;;;;;;;AAUpB,SAAgB,cAAc,SAAyB;CACrD,IAAI,MAAM;CACV,KAAK,MAAM,QAAQ,IAAI,YAAY,EAAE,OAAO,OAAO,GAAG;EACpD,MAAM,KAAK,OAAO,aAAa,IAAI;EACnC,IAAI,QAAQ,MAAQ,QAAQ,IAAM,OAAO,IAAI,GAAG,YAAY;OACvD,IAAI,OAAO,KAAK,OAAO;OACvB,IAAI,oBAAoB,KAAK,EAAE,KAAK,EAAE,OAAO,OAAO,QAAQ,KAAK,OAAO;OACxE,OAAO,IAAI,KAAK,SAAS,EAAE,EAAE,YAAY,EAAE,SAAS,GAAG,GAAG;CACjE;CACA,OAAO;AACT;;AAGA,SAAgB,cAAc,MAAsB;CAClD,MAAM,QAAkB,CAAC;CACzB,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,KAAK,KAAK;EAChB,IAAI,OAAO,KAAK;GACd,MAAM,OAAO,KAAK,EAAE,MAAM;GAC1B,MAAM,MAAM,SAAS,MAAM,MAAM,KAAK,YAAY,GAAG,WAAW,CAAC,CAAC;EACpE,OAAO,IAAI,OAAO,KAAK;GACrB,MAAM,KAAK,OAAO,SAAS,KAAK,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;GACxD,KAAK;EACP,OAAO,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC;CACpC;CACA,OAAO,IAAI,YAAY,EAAE,OAAO,IAAI,WAAW,KAAK,CAAC;AACvD;;;;;;AAOA,SAAS,UAAU,KAAa,KAAqB;CACnD,OAAO,KAAK,KAAK,GAAG,IAAI,MAAM,GAAG,EAAE,IAAI,aAAa,CAAC,IAAI;AAC3D;;;;;;AAOA,SAAS,UAAU,KAAa,UAAiC;CAC/D,MAAM,MAAM,SAAS,KAAK,QAAQ;CAClC,IAAI,IAAI,WAAW,IAAI,KAAK,CAAC,IAAI,SAAS,WAAW,GAAG,OAAO;CAC/D,OAAO,IAAI,MAAM,GAAG,EAAmB,EAAE,MAAM,GAAG,EAAE,IAAI,aAAa,EAAE,KAAK,GAAG;AACjF;;AAGA,eAAe,KAAK,MAAiC;CACnD,MAAM,MAAgB,CAAC;CACvB,IAAI;CACJ,IAAI;EACF,UAAW,MAAM,QAAQ,MAAM,EAAE,eAAe,KAAK,CAAC;CACxD,SAAS,KAAK;EACZ,IAAK,IAA8B,SAAS,UAAU,OAAO;EAC7D,MAAM;CACR;CACA,KAAK,MAAM,SAAS,SAAS;EAC3B,MAAM,OAAO,MAAM,KAAK,SAAS;EACjC,MAAM,OAAO,KAAK,MAAM,IAAI;EAC5B,IAAI,MAAM,YAAY,GACpB,IAAI,KAAK,GAAI,MAAM,KAAK,IAAI,CAAE;OACzB,IAAI,MAAM,OAAO,KAAK,KAAK,SAAS,WAAW,GACpD,IAAI,KAAK,IAAI;CAEjB;CACA,OAAO;AACT;AAEA,IAAI,aAAa;;;;;;;;;;;;;;AAejB,SAAgB,kBAAkB,SAAoD;CACpF,MAAM,EAAE,QAAQ;CAEhB,OAAO;EACL,MAAM,QAAW,KAAgC;GAC/C,IAAI;IACF,MAAM,MAAM,MAAM,SAAS,UAAU,KAAK,GAAG,GAAG,MAAM;IACtD,OAAO,KAAK,MAAM,GAAG;GACvB,SAAS,KAAK;IACZ,IAAK,IAA8B,SAAS,UAAU,OAAO;IAC7D,MAAM;GACR;EACF;EAEA,MAAM,QAAW,KAAa,OAAyB;GACrD,MAAM,OAAO,UAAU,KAAK,GAAG;GAC/B,MAAM,MAAM,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;GAG9C,MAAM,MAAM,GAAG,KAAK,GAAG,QAAQ,IAAI,GAAG,aAAa;GACnD,MAAM,UAAU,KAAK,KAAK,UAAU,OAAO,MAAM,CAAC,GAAG,MAAM;GAC3D,MAAM,OAAO,KAAK,IAAI;EACxB;EAEA,MAAM,WAAW,KAA4B;GAC3C,IAAI;IACF,MAAM,OAAO,UAAU,KAAK,GAAG,CAAC;GAClC,SAAS,KAAK;IACZ,IAAK,IAA8B,SAAS,UAAU,MAAM;GAC9D;EACF;EAEA,MAAM,QAAQ,QAAmC;GAC/C,MAAM,QAAQ,MAAM,KAAK,GAAG;GAC5B,MAAM,MAAgB,CAAC;GACvB,KAAK,MAAM,QAAQ,OAAO;IACxB,MAAM,MAAM,UAAU,KAAK,IAAI;IAC/B,IAAI,QAAQ,QAAQ,IAAI,WAAW,MAAM,GAAG,IAAI,KAAK,GAAG;GAC1D;GACA,OAAO;EACT;EAEA,MAAM,MACJ,QACA,UACqB;GAErB,MAAM,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;GACpC,MAAM,UAAUA,MAAQ,KAAK,EAAE,WAAW,KAAK,IAAI,WAAW,aAAa;IACzE,IAAI,CAAC,UAAU;IACf,MAAM,OAAO,KAAK,KAAK,SAAS,SAAS,CAAC;IAC1C,MAAM,MAAM,UAAU,KAAK,IAAI;IAC/B,IAAI,QAAQ,QAAQ,CAAC,IAAI,WAAW,MAAM,GAAG;IAK7C,SAAS;KAAE,MADT,cAAc,YAAY,CAAC,WAAW,IAAI,IAAI,WAAW;KAC1C;IAAI,CAAC;GACxB,CAAC;GACD,aAAa,QAAQ,MAAM;EAC7B;CACF;AACF;;;;;AAMA,eAAsB,iBAAiB,SAA4C;CACjF,MAAM,GAAG,QAAQ,KAAK;EAAE,WAAW;EAAM,OAAO;CAAK,CAAC;AACxD"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_contract = require("./contract-DYvBNdnR.cjs");
|
|
3
|
+
const require_sql = require("./sql-B7b6HzGy.cjs");
|
|
4
|
+
const require_sqlite_event_log = require("./sqlite-event-log-BnoG8eos.cjs");
|
|
5
|
+
//#region src/storage/libsql.ts
|
|
6
|
+
/**
|
|
7
|
+
* libSQL / [Turso](https://turso.tech) storage adapter built on the
|
|
8
|
+
* [`@libsql/client`](https://github.com/tursodatabase/libsql-client-ts) package
|
|
9
|
+
* (an optional peer dependency). It speaks the same SQL dialect as SQLite but
|
|
10
|
+
* works against a **remote, replicated, edge-distributed** database — or a local
|
|
11
|
+
* file / embedded replica — so it suits multi-node and edge runtimes where
|
|
12
|
+
* `bun:sqlite` (single-file, Bun-only) does not.
|
|
13
|
+
*
|
|
14
|
+
* Control data lives in a key/value table; events live in the **native event
|
|
15
|
+
* log** tables `{table}_events` / `{table}_event_targets` (ADR 0005, see
|
|
16
|
+
* {@link ./sql}). Every event-log write is one `batch(…, "write")` call — a
|
|
17
|
+
* single round-trip that libSQL runs as one transaction.
|
|
18
|
+
*
|
|
19
|
+
* Pass either a pre-constructed `client`, or `url` (+ optional `authToken`) to let
|
|
20
|
+
* the adapter construct one lazily on first use. An optional `prefix` is **not**
|
|
21
|
+
* used here — keys are stored verbatim as the primary key; namespace via a
|
|
22
|
+
* distinct `table` or a separate database instead.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { createLibsqlStorage } from "@xtandard/audit/storage/libsql";
|
|
26
|
+
*
|
|
27
|
+
* // Turso (remote):
|
|
28
|
+
* const storage = createLibsqlStorage({
|
|
29
|
+
* url: process.env.TURSO_DATABASE_URL!, // libsql://<db>-<org>.turso.io
|
|
30
|
+
* authToken: process.env.TURSO_AUTH_TOKEN!,
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Local file or embedded replica:
|
|
34
|
+
* // const storage = createLibsqlStorage({ url: "file:audit.db" });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @module
|
|
38
|
+
*/
|
|
39
|
+
const escapeLike = (prefix) => prefix.replace(/[\\%_]/g, (c) => `\\${c}`);
|
|
40
|
+
/**
|
|
41
|
+
* Create a libSQL/Turso-backed {@link LibsqlAuditStorage}. The tables are
|
|
42
|
+
* created on first use; connection (when constructed from `url`) is lazy and
|
|
43
|
+
* shared.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { createLibsqlStorage } from "@xtandard/audit/storage/libsql";
|
|
48
|
+
*
|
|
49
|
+
* const storage = createLibsqlStorage({
|
|
50
|
+
* url: process.env.TURSO_DATABASE_URL!,
|
|
51
|
+
* authToken: process.env.TURSO_AUTH_TOKEN,
|
|
52
|
+
* });
|
|
53
|
+
* // process.on("SIGTERM", () => storage.close());
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
function createLibsqlStorage(options) {
|
|
57
|
+
const table = require_sql.assertSafeIdentifier(options.table ?? "xtandard_audit");
|
|
58
|
+
const ownsClient = !options.client;
|
|
59
|
+
let client = options.client;
|
|
60
|
+
let ready;
|
|
61
|
+
/** Resolve a connected client and ensure the tables exist (once). */
|
|
62
|
+
function getClient() {
|
|
63
|
+
ready ??= (async () => {
|
|
64
|
+
if (!client) {
|
|
65
|
+
if (!options.url) throw new Error("createLibsqlStorage requires either a `client` or a `url`");
|
|
66
|
+
let createClient;
|
|
67
|
+
try {
|
|
68
|
+
const specifier = "@libsql/client";
|
|
69
|
+
({createClient} = await import(specifier));
|
|
70
|
+
} catch {
|
|
71
|
+
require_contract.requirePeer("@libsql/client", "storage/libsql");
|
|
72
|
+
}
|
|
73
|
+
client = createClient({
|
|
74
|
+
url: options.url,
|
|
75
|
+
authToken: options.authToken
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
await client.execute(`CREATE TABLE IF NOT EXISTS ${table} (key TEXT PRIMARY KEY, value TEXT NOT NULL)`);
|
|
79
|
+
for (const ddl of require_sql.eventLogDdl("sqlite", table)) await client.execute(ddl);
|
|
80
|
+
return client;
|
|
81
|
+
})();
|
|
82
|
+
return ready;
|
|
83
|
+
}
|
|
84
|
+
let executor;
|
|
85
|
+
const exec = () => executor ??= getClient().then((c) => ({
|
|
86
|
+
async all(sql, args) {
|
|
87
|
+
return (await c.execute({
|
|
88
|
+
sql,
|
|
89
|
+
args
|
|
90
|
+
})).rows;
|
|
91
|
+
},
|
|
92
|
+
async atomic(statements) {
|
|
93
|
+
return (await c.batch(statements, "write")).map((r) => r.rowsAffected ?? 0);
|
|
94
|
+
}
|
|
95
|
+
}));
|
|
96
|
+
return {
|
|
97
|
+
async getItem(key) {
|
|
98
|
+
const { rows } = await (await getClient()).execute({
|
|
99
|
+
sql: `SELECT value FROM ${table} WHERE key = ?`,
|
|
100
|
+
args: [key]
|
|
101
|
+
});
|
|
102
|
+
const value = rows[0]?.value;
|
|
103
|
+
return typeof value === "string" ? JSON.parse(value) : null;
|
|
104
|
+
},
|
|
105
|
+
async setItem(key, value) {
|
|
106
|
+
await (await getClient()).execute({
|
|
107
|
+
sql: `INSERT INTO ${table} (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value`,
|
|
108
|
+
args: [key, JSON.stringify(value)]
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
async removeItem(key) {
|
|
112
|
+
await (await getClient()).execute({
|
|
113
|
+
sql: `DELETE FROM ${table} WHERE key = ?`,
|
|
114
|
+
args: [key]
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
async getKeys(prefix) {
|
|
118
|
+
const { rows } = await (await getClient()).execute({
|
|
119
|
+
sql: `SELECT key FROM ${table} WHERE key LIKE ? ESCAPE '\\'`,
|
|
120
|
+
args: [`${escapeLike(prefix)}%`]
|
|
121
|
+
});
|
|
122
|
+
return rows.map((r) => String(r.key)).filter((key) => key.startsWith(prefix));
|
|
123
|
+
},
|
|
124
|
+
...require_sqlite_event_log.createSqliteEventLog(exec, table),
|
|
125
|
+
close() {
|
|
126
|
+
if (ownsClient) client?.close();
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
exports.createLibsqlStorage = createLibsqlStorage;
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=entry-storage-libsql.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-storage-libsql.cjs","names":["assertSafeIdentifier","eventLogDdl","createSqliteEventLog"],"sources":["../src/storage/libsql.ts"],"sourcesContent":["/**\n * libSQL / [Turso](https://turso.tech) storage adapter built on the\n * [`@libsql/client`](https://github.com/tursodatabase/libsql-client-ts) package\n * (an optional peer dependency). It speaks the same SQL dialect as SQLite but\n * works against a **remote, replicated, edge-distributed** database — or a local\n * file / embedded replica — so it suits multi-node and edge runtimes where\n * `bun:sqlite` (single-file, Bun-only) does not.\n *\n * Control data lives in a key/value table; events live in the **native event\n * log** tables `{table}_events` / `{table}_event_targets` (ADR 0005, see\n * {@link ./sql}). Every event-log write is one `batch(…, \"write\")` call — a\n * single round-trip that libSQL runs as one transaction.\n *\n * Pass either a pre-constructed `client`, or `url` (+ optional `authToken`) to let\n * the adapter construct one lazily on first use. An optional `prefix` is **not**\n * used here — keys are stored verbatim as the primary key; namespace via a\n * distinct `table` or a separate database instead.\n *\n * ```ts\n * import { createLibsqlStorage } from \"@xtandard/audit/storage/libsql\";\n *\n * // Turso (remote):\n * const storage = createLibsqlStorage({\n * url: process.env.TURSO_DATABASE_URL!, // libsql://<db>-<org>.turso.io\n * authToken: process.env.TURSO_AUTH_TOKEN!,\n * });\n *\n * // Local file or embedded replica:\n * // const storage = createLibsqlStorage({ url: \"file:audit.db\" });\n * ```\n *\n * @module\n */\n\nimport { requirePeer } from \"./contract.ts\";\nimport type { EventLogStorage } from \"./contract.ts\";\nimport { createSqliteEventLog, type SqliteExecutor } from \"./sqlite-event-log.ts\";\nimport { assertSafeIdentifier, eventLogDdl } from \"./sql.ts\";\n\n/** Options for {@link createLibsqlStorage}. */\nexport interface LibsqlStorageOptions {\n /** libSQL connection 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. */\n client?: LibsqlClientLike;\n /**\n * KV table name (default `\"xtandard_audit\"`); the event log uses\n * `{table}_events` and `{table}_event_targets`. Validated as a safe identifier.\n */\n table?: string;\n}\n\n/** A storage backed by libSQL/Turso with the native {@link EventLogStorage}, plus `close()`. */\nexport interface LibsqlAuditStorage extends EventLogStorage {\n /** Close the client if this adapter created it; no-op for a borrowed instance. */\n close(): void;\n}\n\n/** One `@libsql/client` result set (the fields this adapter reads). */\nexport interface LibsqlResultLike {\n rows: Array<Record<string, unknown>>;\n rowsAffected?: number;\n}\n\n/** Minimal structural view of the `@libsql/client` surface this adapter uses. */\nexport interface LibsqlClientLike {\n execute(stmt: string | { sql: string; args: unknown[] }): Promise<LibsqlResultLike>;\n /** Run statements in one transaction (`\"write\"` mode); resolves to one result per statement. */\n batch(\n stmts: Array<{ sql: string; args: unknown[] }>,\n mode?: \"write\" | \"read\" | \"deferred\",\n ): Promise<LibsqlResultLike[]>;\n close(): void;\n}\n\nconst escapeLike = (prefix: string): string => prefix.replace(/[\\\\%_]/g, (c) => `\\\\${c}`);\n\n/**\n * Create a libSQL/Turso-backed {@link LibsqlAuditStorage}. The tables are\n * created on first use; connection (when constructed from `url`) is lazy and\n * shared.\n *\n * @example\n * ```ts\n * import { createLibsqlStorage } from \"@xtandard/audit/storage/libsql\";\n *\n * const storage = createLibsqlStorage({\n * url: process.env.TURSO_DATABASE_URL!,\n * authToken: process.env.TURSO_AUTH_TOKEN,\n * });\n * // process.on(\"SIGTERM\", () => storage.close());\n * ```\n */\nexport function createLibsqlStorage(options: LibsqlStorageOptions): LibsqlAuditStorage {\n const table = assertSafeIdentifier(options.table ?? \"xtandard_audit\");\n\n const ownsClient = !options.client;\n let client: LibsqlClientLike | undefined = options.client;\n let ready: Promise<LibsqlClientLike> | undefined;\n\n /** Resolve a connected client and ensure the tables exist (once). */\n function getClient(): Promise<LibsqlClientLike> {\n ready ??= (async () => {\n if (!client) {\n if (!options.url) {\n throw new Error(\"createLibsqlStorage requires either a `client` or a `url`\");\n }\n let createClient: (opts: { url: string; authToken?: string }) => LibsqlClientLike;\n try {\n // Non-literal specifier so the type-checker doesn't require the optional\n // peer to be installed at build time (it's resolved at runtime only).\n const specifier: string = \"@libsql/client\";\n ({ createClient } = (await import(specifier)) as {\n createClient: (opts: { url: string; authToken?: string }) => LibsqlClientLike;\n });\n } catch {\n requirePeer(\"@libsql/client\", \"storage/libsql\");\n }\n client = createClient({ url: options.url, authToken: options.authToken });\n }\n await client.execute(\n `CREATE TABLE IF NOT EXISTS ${table} (key TEXT PRIMARY KEY, value TEXT NOT NULL)`,\n );\n for (const ddl of eventLogDdl(\"sqlite\", table)) await client.execute(ddl);\n return client;\n })();\n return ready;\n }\n\n let executor: Promise<SqliteExecutor> | undefined;\n const exec = () =>\n (executor ??= getClient().then(\n (c): SqliteExecutor => ({\n async all(sql, args) {\n return (await c.execute({ sql, args })).rows;\n },\n async atomic(statements) {\n const results = await c.batch(statements, \"write\");\n return results.map((r) => r.rowsAffected ?? 0);\n },\n }),\n ));\n\n return {\n async getItem<T>(key: string): Promise<T | null> {\n const c = await getClient();\n const { rows } = await c.execute({\n sql: `SELECT value FROM ${table} WHERE key = ?`,\n args: [key],\n });\n const value = rows[0]?.value;\n return typeof value === \"string\" ? (JSON.parse(value) as T) : null;\n },\n\n async setItem<T>(key: string, value: T): Promise<void> {\n const c = await getClient();\n await c.execute({\n sql: `INSERT INTO ${table} (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value`,\n args: [key, JSON.stringify(value)],\n });\n },\n\n async removeItem(key: string): Promise<void> {\n const c = await getClient();\n await c.execute({ sql: `DELETE FROM ${table} WHERE key = ?`, args: [key] });\n },\n\n async getKeys(prefix: string): Promise<string[]> {\n const c = await getClient();\n const { rows } = await c.execute({\n sql: `SELECT key FROM ${table} WHERE key LIKE ? ESCAPE '\\\\'`,\n args: [`${escapeLike(prefix)}%`],\n });\n // SQLite LIKE folds ASCII case: keep only exact prefix matches.\n return rows.map((r) => String(r.key)).filter((key) => key.startsWith(prefix));\n },\n\n ...createSqliteEventLog(exec, table),\n\n close(): void {\n if (ownsClient) client?.close();\n },\n } satisfies LibsqlAuditStorage;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,MAAM,cAAc,WAA2B,OAAO,QAAQ,YAAY,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;AAkBxF,SAAgB,oBAAoB,SAAmD;CACrF,MAAM,QAAQA,YAAAA,qBAAqB,QAAQ,SAAS,gBAAgB;CAEpE,MAAM,aAAa,CAAC,QAAQ;CAC5B,IAAI,SAAuC,QAAQ;CACnD,IAAI;;CAGJ,SAAS,YAAuC;EAC9C,WAAW,YAAY;GACrB,IAAI,CAAC,QAAQ;IACX,IAAI,CAAC,QAAQ,KACX,MAAM,IAAI,MAAM,2DAA2D;IAE7E,IAAI;IACJ,IAAI;KAGF,MAAM,YAAoB;KAC1B,CAAC,CAAE,gBAAkB,MAAM,OAAO;IAGpC,QAAQ;KACN,iBAAA,YAAY,kBAAkB,gBAAgB;IAChD;IACA,SAAS,aAAa;KAAE,KAAK,QAAQ;KAAK,WAAW,QAAQ;IAAU,CAAC;GAC1E;GACA,MAAM,OAAO,QACX,8BAA8B,MAAM,6CACtC;GACA,KAAK,MAAM,OAAOC,YAAAA,YAAY,UAAU,KAAK,GAAG,MAAM,OAAO,QAAQ,GAAG;GACxE,OAAO;EACT,GAAG;EACH,OAAO;CACT;CAEA,IAAI;CACJ,MAAM,aACH,aAAa,UAAU,EAAE,MACvB,OAAuB;EACtB,MAAM,IAAI,KAAK,MAAM;GACnB,QAAQ,MAAM,EAAE,QAAQ;IAAE;IAAK;GAAK,CAAC,GAAG;EAC1C;EACA,MAAM,OAAO,YAAY;GAEvB,QAAO,MADe,EAAE,MAAM,YAAY,OAAO,GAClC,KAAK,MAAM,EAAE,gBAAgB,CAAC;EAC/C;CACF,EACF;CAEF,OAAO;EACL,MAAM,QAAW,KAAgC;GAE/C,MAAM,EAAE,SAAS,OAAM,MADP,UAAU,GACD,QAAQ;IAC/B,KAAK,qBAAqB,MAAM;IAChC,MAAM,CAAC,GAAG;GACZ,CAAC;GACD,MAAM,QAAQ,KAAK,IAAI;GACvB,OAAO,OAAO,UAAU,WAAY,KAAK,MAAM,KAAK,IAAU;EAChE;EAEA,MAAM,QAAW,KAAa,OAAyB;GAErD,OAAM,MADU,UAAU,GAClB,QAAQ;IACd,KAAK,eAAe,MAAM;IAC1B,MAAM,CAAC,KAAK,KAAK,UAAU,KAAK,CAAC;GACnC,CAAC;EACH;EAEA,MAAM,WAAW,KAA4B;GAE3C,OAAM,MADU,UAAU,GAClB,QAAQ;IAAE,KAAK,eAAe,MAAM;IAAiB,MAAM,CAAC,GAAG;GAAE,CAAC;EAC5E;EAEA,MAAM,QAAQ,QAAmC;GAE/C,MAAM,EAAE,SAAS,OAAM,MADP,UAAU,GACD,QAAQ;IAC/B,KAAK,mBAAmB,MAAM;IAC9B,MAAM,CAAC,GAAG,WAAW,MAAM,EAAE,EAAE;GACjC,CAAC;GAED,OAAO,KAAK,KAAK,MAAM,OAAO,EAAE,GAAG,CAAC,EAAE,QAAQ,QAAQ,IAAI,WAAW,MAAM,CAAC;EAC9E;EAEA,GAAGC,yBAAAA,qBAAqB,MAAM,KAAK;EAEnC,QAAc;GACZ,IAAI,YAAY,QAAQ,MAAM;EAChC;CACF;AACF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { i as EventLogStorage } from "./contract-CWJSYoJl.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/storage/libsql.d.ts
|
|
4
|
+
/** Options for {@link createLibsqlStorage}. */
|
|
5
|
+
interface LibsqlStorageOptions {
|
|
6
|
+
/** libSQL connection URL (`libsql://…`, `https://…`, `file:…`, `:memory:`). Used when no `client`. */
|
|
7
|
+
url?: string;
|
|
8
|
+
/** Turso auth token for remote databases. */
|
|
9
|
+
authToken?: string;
|
|
10
|
+
/** A pre-constructed `@libsql/client` client to use instead of connecting. */
|
|
11
|
+
client?: LibsqlClientLike;
|
|
12
|
+
/**
|
|
13
|
+
* KV table name (default `"xtandard_audit"`); the event log uses
|
|
14
|
+
* `{table}_events` and `{table}_event_targets`. Validated as a safe identifier.
|
|
15
|
+
*/
|
|
16
|
+
table?: string;
|
|
17
|
+
}
|
|
18
|
+
/** A storage backed by libSQL/Turso with the native {@link EventLogStorage}, plus `close()`. */
|
|
19
|
+
interface LibsqlAuditStorage extends EventLogStorage {
|
|
20
|
+
/** Close the client if this adapter created it; no-op for a borrowed instance. */
|
|
21
|
+
close(): void;
|
|
22
|
+
}
|
|
23
|
+
/** One `@libsql/client` result set (the fields this adapter reads). */
|
|
24
|
+
interface LibsqlResultLike {
|
|
25
|
+
rows: Array<Record<string, unknown>>;
|
|
26
|
+
rowsAffected?: number;
|
|
27
|
+
}
|
|
28
|
+
/** Minimal structural view of the `@libsql/client` surface this adapter uses. */
|
|
29
|
+
interface LibsqlClientLike {
|
|
30
|
+
execute(stmt: string | {
|
|
31
|
+
sql: string;
|
|
32
|
+
args: unknown[];
|
|
33
|
+
}): Promise<LibsqlResultLike>;
|
|
34
|
+
/** Run statements in one transaction (`"write"` mode); resolves to one result per statement. */
|
|
35
|
+
batch(stmts: Array<{
|
|
36
|
+
sql: string;
|
|
37
|
+
args: unknown[];
|
|
38
|
+
}>, mode?: "write" | "read" | "deferred"): Promise<LibsqlResultLike[]>;
|
|
39
|
+
close(): void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a libSQL/Turso-backed {@link LibsqlAuditStorage}. The tables are
|
|
43
|
+
* created on first use; connection (when constructed from `url`) is lazy and
|
|
44
|
+
* shared.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { createLibsqlStorage } from "@xtandard/audit/storage/libsql";
|
|
49
|
+
*
|
|
50
|
+
* const storage = createLibsqlStorage({
|
|
51
|
+
* url: process.env.TURSO_DATABASE_URL!,
|
|
52
|
+
* authToken: process.env.TURSO_AUTH_TOKEN,
|
|
53
|
+
* });
|
|
54
|
+
* // process.on("SIGTERM", () => storage.close());
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function createLibsqlStorage(options: LibsqlStorageOptions): LibsqlAuditStorage;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { LibsqlAuditStorage, LibsqlClientLike, LibsqlResultLike, LibsqlStorageOptions, createLibsqlStorage };
|
|
60
|
+
//# sourceMappingURL=entry-storage-libsql.d.cts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { i as EventLogStorage } from "./contract-BmwHIiMR.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/storage/libsql.d.ts
|
|
4
|
+
/** Options for {@link createLibsqlStorage}. */
|
|
5
|
+
interface LibsqlStorageOptions {
|
|
6
|
+
/** libSQL connection URL (`libsql://…`, `https://…`, `file:…`, `:memory:`). Used when no `client`. */
|
|
7
|
+
url?: string;
|
|
8
|
+
/** Turso auth token for remote databases. */
|
|
9
|
+
authToken?: string;
|
|
10
|
+
/** A pre-constructed `@libsql/client` client to use instead of connecting. */
|
|
11
|
+
client?: LibsqlClientLike;
|
|
12
|
+
/**
|
|
13
|
+
* KV table name (default `"xtandard_audit"`); the event log uses
|
|
14
|
+
* `{table}_events` and `{table}_event_targets`. Validated as a safe identifier.
|
|
15
|
+
*/
|
|
16
|
+
table?: string;
|
|
17
|
+
}
|
|
18
|
+
/** A storage backed by libSQL/Turso with the native {@link EventLogStorage}, plus `close()`. */
|
|
19
|
+
interface LibsqlAuditStorage extends EventLogStorage {
|
|
20
|
+
/** Close the client if this adapter created it; no-op for a borrowed instance. */
|
|
21
|
+
close(): void;
|
|
22
|
+
}
|
|
23
|
+
/** One `@libsql/client` result set (the fields this adapter reads). */
|
|
24
|
+
interface LibsqlResultLike {
|
|
25
|
+
rows: Array<Record<string, unknown>>;
|
|
26
|
+
rowsAffected?: number;
|
|
27
|
+
}
|
|
28
|
+
/** Minimal structural view of the `@libsql/client` surface this adapter uses. */
|
|
29
|
+
interface LibsqlClientLike {
|
|
30
|
+
execute(stmt: string | {
|
|
31
|
+
sql: string;
|
|
32
|
+
args: unknown[];
|
|
33
|
+
}): Promise<LibsqlResultLike>;
|
|
34
|
+
/** Run statements in one transaction (`"write"` mode); resolves to one result per statement. */
|
|
35
|
+
batch(stmts: Array<{
|
|
36
|
+
sql: string;
|
|
37
|
+
args: unknown[];
|
|
38
|
+
}>, mode?: "write" | "read" | "deferred"): Promise<LibsqlResultLike[]>;
|
|
39
|
+
close(): void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a libSQL/Turso-backed {@link LibsqlAuditStorage}. The tables are
|
|
43
|
+
* created on first use; connection (when constructed from `url`) is lazy and
|
|
44
|
+
* shared.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { createLibsqlStorage } from "@xtandard/audit/storage/libsql";
|
|
49
|
+
*
|
|
50
|
+
* const storage = createLibsqlStorage({
|
|
51
|
+
* url: process.env.TURSO_DATABASE_URL!,
|
|
52
|
+
* authToken: process.env.TURSO_AUTH_TOKEN,
|
|
53
|
+
* });
|
|
54
|
+
* // process.on("SIGTERM", () => storage.close());
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function createLibsqlStorage(options: LibsqlStorageOptions): LibsqlAuditStorage;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { LibsqlAuditStorage, LibsqlClientLike, LibsqlResultLike, LibsqlStorageOptions, createLibsqlStorage };
|
|
60
|
+
//# sourceMappingURL=entry-storage-libsql.d.mts.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { o as requirePeer } from "./contract-isM9SjjQ.mjs";
|
|
2
|
+
import { n as assertSafeIdentifier, s as eventLogDdl } from "./sql-COjPyn3F.mjs";
|
|
3
|
+
import { t as createSqliteEventLog } from "./sqlite-event-log-nXmS2DS_.mjs";
|
|
4
|
+
//#region src/storage/libsql.ts
|
|
5
|
+
/**
|
|
6
|
+
* libSQL / [Turso](https://turso.tech) storage adapter built on the
|
|
7
|
+
* [`@libsql/client`](https://github.com/tursodatabase/libsql-client-ts) package
|
|
8
|
+
* (an optional peer dependency). It speaks the same SQL dialect as SQLite but
|
|
9
|
+
* works against a **remote, replicated, edge-distributed** database — or a local
|
|
10
|
+
* file / embedded replica — so it suits multi-node and edge runtimes where
|
|
11
|
+
* `bun:sqlite` (single-file, Bun-only) does not.
|
|
12
|
+
*
|
|
13
|
+
* Control data lives in a key/value table; events live in the **native event
|
|
14
|
+
* log** tables `{table}_events` / `{table}_event_targets` (ADR 0005, see
|
|
15
|
+
* {@link ./sql}). Every event-log write is one `batch(…, "write")` call — a
|
|
16
|
+
* single round-trip that libSQL runs as one transaction.
|
|
17
|
+
*
|
|
18
|
+
* Pass either a pre-constructed `client`, or `url` (+ optional `authToken`) to let
|
|
19
|
+
* the adapter construct one lazily on first use. An optional `prefix` is **not**
|
|
20
|
+
* used here — keys are stored verbatim as the primary key; namespace via a
|
|
21
|
+
* distinct `table` or a separate database instead.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { createLibsqlStorage } from "@xtandard/audit/storage/libsql";
|
|
25
|
+
*
|
|
26
|
+
* // Turso (remote):
|
|
27
|
+
* const storage = createLibsqlStorage({
|
|
28
|
+
* url: process.env.TURSO_DATABASE_URL!, // libsql://<db>-<org>.turso.io
|
|
29
|
+
* authToken: process.env.TURSO_AUTH_TOKEN!,
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Local file or embedded replica:
|
|
33
|
+
* // const storage = createLibsqlStorage({ url: "file:audit.db" });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @module
|
|
37
|
+
*/
|
|
38
|
+
const escapeLike = (prefix) => prefix.replace(/[\\%_]/g, (c) => `\\${c}`);
|
|
39
|
+
/**
|
|
40
|
+
* Create a libSQL/Turso-backed {@link LibsqlAuditStorage}. The tables are
|
|
41
|
+
* created on first use; connection (when constructed from `url`) is lazy and
|
|
42
|
+
* shared.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { createLibsqlStorage } from "@xtandard/audit/storage/libsql";
|
|
47
|
+
*
|
|
48
|
+
* const storage = createLibsqlStorage({
|
|
49
|
+
* url: process.env.TURSO_DATABASE_URL!,
|
|
50
|
+
* authToken: process.env.TURSO_AUTH_TOKEN,
|
|
51
|
+
* });
|
|
52
|
+
* // process.on("SIGTERM", () => storage.close());
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
function createLibsqlStorage(options) {
|
|
56
|
+
const table = assertSafeIdentifier(options.table ?? "xtandard_audit");
|
|
57
|
+
const ownsClient = !options.client;
|
|
58
|
+
let client = options.client;
|
|
59
|
+
let ready;
|
|
60
|
+
/** Resolve a connected client and ensure the tables exist (once). */
|
|
61
|
+
function getClient() {
|
|
62
|
+
ready ??= (async () => {
|
|
63
|
+
if (!client) {
|
|
64
|
+
if (!options.url) throw new Error("createLibsqlStorage requires either a `client` or a `url`");
|
|
65
|
+
let createClient;
|
|
66
|
+
try {
|
|
67
|
+
const specifier = "@libsql/client";
|
|
68
|
+
({createClient} = await import(specifier));
|
|
69
|
+
} catch {
|
|
70
|
+
requirePeer("@libsql/client", "storage/libsql");
|
|
71
|
+
}
|
|
72
|
+
client = createClient({
|
|
73
|
+
url: options.url,
|
|
74
|
+
authToken: options.authToken
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
await client.execute(`CREATE TABLE IF NOT EXISTS ${table} (key TEXT PRIMARY KEY, value TEXT NOT NULL)`);
|
|
78
|
+
for (const ddl of eventLogDdl("sqlite", table)) await client.execute(ddl);
|
|
79
|
+
return client;
|
|
80
|
+
})();
|
|
81
|
+
return ready;
|
|
82
|
+
}
|
|
83
|
+
let executor;
|
|
84
|
+
const exec = () => executor ??= getClient().then((c) => ({
|
|
85
|
+
async all(sql, args) {
|
|
86
|
+
return (await c.execute({
|
|
87
|
+
sql,
|
|
88
|
+
args
|
|
89
|
+
})).rows;
|
|
90
|
+
},
|
|
91
|
+
async atomic(statements) {
|
|
92
|
+
return (await c.batch(statements, "write")).map((r) => r.rowsAffected ?? 0);
|
|
93
|
+
}
|
|
94
|
+
}));
|
|
95
|
+
return {
|
|
96
|
+
async getItem(key) {
|
|
97
|
+
const { rows } = await (await getClient()).execute({
|
|
98
|
+
sql: `SELECT value FROM ${table} WHERE key = ?`,
|
|
99
|
+
args: [key]
|
|
100
|
+
});
|
|
101
|
+
const value = rows[0]?.value;
|
|
102
|
+
return typeof value === "string" ? JSON.parse(value) : null;
|
|
103
|
+
},
|
|
104
|
+
async setItem(key, value) {
|
|
105
|
+
await (await getClient()).execute({
|
|
106
|
+
sql: `INSERT INTO ${table} (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value`,
|
|
107
|
+
args: [key, JSON.stringify(value)]
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
async removeItem(key) {
|
|
111
|
+
await (await getClient()).execute({
|
|
112
|
+
sql: `DELETE FROM ${table} WHERE key = ?`,
|
|
113
|
+
args: [key]
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
async getKeys(prefix) {
|
|
117
|
+
const { rows } = await (await getClient()).execute({
|
|
118
|
+
sql: `SELECT key FROM ${table} WHERE key LIKE ? ESCAPE '\\'`,
|
|
119
|
+
args: [`${escapeLike(prefix)}%`]
|
|
120
|
+
});
|
|
121
|
+
return rows.map((r) => String(r.key)).filter((key) => key.startsWith(prefix));
|
|
122
|
+
},
|
|
123
|
+
...createSqliteEventLog(exec, table),
|
|
124
|
+
close() {
|
|
125
|
+
if (ownsClient) client?.close();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
export { createLibsqlStorage };
|
|
131
|
+
|
|
132
|
+
//# sourceMappingURL=entry-storage-libsql.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-storage-libsql.mjs","names":[],"sources":["../src/storage/libsql.ts"],"sourcesContent":["/**\n * libSQL / [Turso](https://turso.tech) storage adapter built on the\n * [`@libsql/client`](https://github.com/tursodatabase/libsql-client-ts) package\n * (an optional peer dependency). It speaks the same SQL dialect as SQLite but\n * works against a **remote, replicated, edge-distributed** database — or a local\n * file / embedded replica — so it suits multi-node and edge runtimes where\n * `bun:sqlite` (single-file, Bun-only) does not.\n *\n * Control data lives in a key/value table; events live in the **native event\n * log** tables `{table}_events` / `{table}_event_targets` (ADR 0005, see\n * {@link ./sql}). Every event-log write is one `batch(…, \"write\")` call — a\n * single round-trip that libSQL runs as one transaction.\n *\n * Pass either a pre-constructed `client`, or `url` (+ optional `authToken`) to let\n * the adapter construct one lazily on first use. An optional `prefix` is **not**\n * used here — keys are stored verbatim as the primary key; namespace via a\n * distinct `table` or a separate database instead.\n *\n * ```ts\n * import { createLibsqlStorage } from \"@xtandard/audit/storage/libsql\";\n *\n * // Turso (remote):\n * const storage = createLibsqlStorage({\n * url: process.env.TURSO_DATABASE_URL!, // libsql://<db>-<org>.turso.io\n * authToken: process.env.TURSO_AUTH_TOKEN!,\n * });\n *\n * // Local file or embedded replica:\n * // const storage = createLibsqlStorage({ url: \"file:audit.db\" });\n * ```\n *\n * @module\n */\n\nimport { requirePeer } from \"./contract.ts\";\nimport type { EventLogStorage } from \"./contract.ts\";\nimport { createSqliteEventLog, type SqliteExecutor } from \"./sqlite-event-log.ts\";\nimport { assertSafeIdentifier, eventLogDdl } from \"./sql.ts\";\n\n/** Options for {@link createLibsqlStorage}. */\nexport interface LibsqlStorageOptions {\n /** libSQL connection 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. */\n client?: LibsqlClientLike;\n /**\n * KV table name (default `\"xtandard_audit\"`); the event log uses\n * `{table}_events` and `{table}_event_targets`. Validated as a safe identifier.\n */\n table?: string;\n}\n\n/** A storage backed by libSQL/Turso with the native {@link EventLogStorage}, plus `close()`. */\nexport interface LibsqlAuditStorage extends EventLogStorage {\n /** Close the client if this adapter created it; no-op for a borrowed instance. */\n close(): void;\n}\n\n/** One `@libsql/client` result set (the fields this adapter reads). */\nexport interface LibsqlResultLike {\n rows: Array<Record<string, unknown>>;\n rowsAffected?: number;\n}\n\n/** Minimal structural view of the `@libsql/client` surface this adapter uses. */\nexport interface LibsqlClientLike {\n execute(stmt: string | { sql: string; args: unknown[] }): Promise<LibsqlResultLike>;\n /** Run statements in one transaction (`\"write\"` mode); resolves to one result per statement. */\n batch(\n stmts: Array<{ sql: string; args: unknown[] }>,\n mode?: \"write\" | \"read\" | \"deferred\",\n ): Promise<LibsqlResultLike[]>;\n close(): void;\n}\n\nconst escapeLike = (prefix: string): string => prefix.replace(/[\\\\%_]/g, (c) => `\\\\${c}`);\n\n/**\n * Create a libSQL/Turso-backed {@link LibsqlAuditStorage}. The tables are\n * created on first use; connection (when constructed from `url`) is lazy and\n * shared.\n *\n * @example\n * ```ts\n * import { createLibsqlStorage } from \"@xtandard/audit/storage/libsql\";\n *\n * const storage = createLibsqlStorage({\n * url: process.env.TURSO_DATABASE_URL!,\n * authToken: process.env.TURSO_AUTH_TOKEN,\n * });\n * // process.on(\"SIGTERM\", () => storage.close());\n * ```\n */\nexport function createLibsqlStorage(options: LibsqlStorageOptions): LibsqlAuditStorage {\n const table = assertSafeIdentifier(options.table ?? \"xtandard_audit\");\n\n const ownsClient = !options.client;\n let client: LibsqlClientLike | undefined = options.client;\n let ready: Promise<LibsqlClientLike> | undefined;\n\n /** Resolve a connected client and ensure the tables exist (once). */\n function getClient(): Promise<LibsqlClientLike> {\n ready ??= (async () => {\n if (!client) {\n if (!options.url) {\n throw new Error(\"createLibsqlStorage requires either a `client` or a `url`\");\n }\n let createClient: (opts: { url: string; authToken?: string }) => LibsqlClientLike;\n try {\n // Non-literal specifier so the type-checker doesn't require the optional\n // peer to be installed at build time (it's resolved at runtime only).\n const specifier: string = \"@libsql/client\";\n ({ createClient } = (await import(specifier)) as {\n createClient: (opts: { url: string; authToken?: string }) => LibsqlClientLike;\n });\n } catch {\n requirePeer(\"@libsql/client\", \"storage/libsql\");\n }\n client = createClient({ url: options.url, authToken: options.authToken });\n }\n await client.execute(\n `CREATE TABLE IF NOT EXISTS ${table} (key TEXT PRIMARY KEY, value TEXT NOT NULL)`,\n );\n for (const ddl of eventLogDdl(\"sqlite\", table)) await client.execute(ddl);\n return client;\n })();\n return ready;\n }\n\n let executor: Promise<SqliteExecutor> | undefined;\n const exec = () =>\n (executor ??= getClient().then(\n (c): SqliteExecutor => ({\n async all(sql, args) {\n return (await c.execute({ sql, args })).rows;\n },\n async atomic(statements) {\n const results = await c.batch(statements, \"write\");\n return results.map((r) => r.rowsAffected ?? 0);\n },\n }),\n ));\n\n return {\n async getItem<T>(key: string): Promise<T | null> {\n const c = await getClient();\n const { rows } = await c.execute({\n sql: `SELECT value FROM ${table} WHERE key = ?`,\n args: [key],\n });\n const value = rows[0]?.value;\n return typeof value === \"string\" ? (JSON.parse(value) as T) : null;\n },\n\n async setItem<T>(key: string, value: T): Promise<void> {\n const c = await getClient();\n await c.execute({\n sql: `INSERT INTO ${table} (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value`,\n args: [key, JSON.stringify(value)],\n });\n },\n\n async removeItem(key: string): Promise<void> {\n const c = await getClient();\n await c.execute({ sql: `DELETE FROM ${table} WHERE key = ?`, args: [key] });\n },\n\n async getKeys(prefix: string): Promise<string[]> {\n const c = await getClient();\n const { rows } = await c.execute({\n sql: `SELECT key FROM ${table} WHERE key LIKE ? ESCAPE '\\\\'`,\n args: [`${escapeLike(prefix)}%`],\n });\n // SQLite LIKE folds ASCII case: keep only exact prefix matches.\n return rows.map((r) => String(r.key)).filter((key) => key.startsWith(prefix));\n },\n\n ...createSqliteEventLog(exec, table),\n\n close(): void {\n if (ownsClient) client?.close();\n },\n } satisfies LibsqlAuditStorage;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,MAAM,cAAc,WAA2B,OAAO,QAAQ,YAAY,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;AAkBxF,SAAgB,oBAAoB,SAAmD;CACrF,MAAM,QAAQ,qBAAqB,QAAQ,SAAS,gBAAgB;CAEpE,MAAM,aAAa,CAAC,QAAQ;CAC5B,IAAI,SAAuC,QAAQ;CACnD,IAAI;;CAGJ,SAAS,YAAuC;EAC9C,WAAW,YAAY;GACrB,IAAI,CAAC,QAAQ;IACX,IAAI,CAAC,QAAQ,KACX,MAAM,IAAI,MAAM,2DAA2D;IAE7E,IAAI;IACJ,IAAI;KAGF,MAAM,YAAoB;KAC1B,CAAC,CAAE,gBAAkB,MAAM,OAAO;IAGpC,QAAQ;KACN,YAAY,kBAAkB,gBAAgB;IAChD;IACA,SAAS,aAAa;KAAE,KAAK,QAAQ;KAAK,WAAW,QAAQ;IAAU,CAAC;GAC1E;GACA,MAAM,OAAO,QACX,8BAA8B,MAAM,6CACtC;GACA,KAAK,MAAM,OAAO,YAAY,UAAU,KAAK,GAAG,MAAM,OAAO,QAAQ,GAAG;GACxE,OAAO;EACT,GAAG;EACH,OAAO;CACT;CAEA,IAAI;CACJ,MAAM,aACH,aAAa,UAAU,EAAE,MACvB,OAAuB;EACtB,MAAM,IAAI,KAAK,MAAM;GACnB,QAAQ,MAAM,EAAE,QAAQ;IAAE;IAAK;GAAK,CAAC,GAAG;EAC1C;EACA,MAAM,OAAO,YAAY;GAEvB,QAAO,MADe,EAAE,MAAM,YAAY,OAAO,GAClC,KAAK,MAAM,EAAE,gBAAgB,CAAC;EAC/C;CACF,EACF;CAEF,OAAO;EACL,MAAM,QAAW,KAAgC;GAE/C,MAAM,EAAE,SAAS,OAAM,MADP,UAAU,GACD,QAAQ;IAC/B,KAAK,qBAAqB,MAAM;IAChC,MAAM,CAAC,GAAG;GACZ,CAAC;GACD,MAAM,QAAQ,KAAK,IAAI;GACvB,OAAO,OAAO,UAAU,WAAY,KAAK,MAAM,KAAK,IAAU;EAChE;EAEA,MAAM,QAAW,KAAa,OAAyB;GAErD,OAAM,MADU,UAAU,GAClB,QAAQ;IACd,KAAK,eAAe,MAAM;IAC1B,MAAM,CAAC,KAAK,KAAK,UAAU,KAAK,CAAC;GACnC,CAAC;EACH;EAEA,MAAM,WAAW,KAA4B;GAE3C,OAAM,MADU,UAAU,GAClB,QAAQ;IAAE,KAAK,eAAe,MAAM;IAAiB,MAAM,CAAC,GAAG;GAAE,CAAC;EAC5E;EAEA,MAAM,QAAQ,QAAmC;GAE/C,MAAM,EAAE,SAAS,OAAM,MADP,UAAU,GACD,QAAQ;IAC/B,KAAK,mBAAmB,MAAM;IAC9B,MAAM,CAAC,GAAG,WAAW,MAAM,EAAE,EAAE;GACjC,CAAC;GAED,OAAO,KAAK,KAAK,MAAM,OAAO,EAAE,GAAG,CAAC,EAAE,QAAQ,QAAQ,IAAI,WAAW,MAAM,CAAC;EAC9E;EAEA,GAAG,qBAAqB,MAAM,KAAK;EAEnC,QAAc;GACZ,IAAI,YAAY,QAAQ,MAAM;EAChC;CACF;AACF"}
|