@xtandard/audit 0.0.0-stage → 0.1.1
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 +386 -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 +31936 -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-B-qrQSOM.css +1 -0
- package/dist/ui/assets/index-CemlP5hR.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,43 @@
|
|
|
1
|
+
import { i as EventLogStorage, t as AuditStorage } from "./contract-BmwHIiMR.mjs";
|
|
2
|
+
import { i as DrizzleKvTable, n as DrizzleEventTargetsTable, r as DrizzleEventsTable, t as DrizzleAuditTables } from "./table-BcarDd10.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/storage/drizzle.d.ts
|
|
5
|
+
/** Options for {@link createDrizzleStorage}. */
|
|
6
|
+
interface DrizzleStorageOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Your Drizzle database (node-postgres / mysql2 / better-sqlite3 / pglite / …).
|
|
9
|
+
* Typed `unknown` intentionally — a single dialect-agnostic type can't match
|
|
10
|
+
* every dialect's db; the adapter only calls the query builder and
|
|
11
|
+
* `transaction`.
|
|
12
|
+
*/
|
|
13
|
+
db: unknown;
|
|
14
|
+
/** The KV table built with a `*AuditTable` factory (or matching that shape). */
|
|
15
|
+
table: DrizzleKvTable;
|
|
16
|
+
/** The events table (`*AuditEventsTable`). Pass with `eventTargets` for the native event log. */
|
|
17
|
+
events?: DrizzleEventsTable;
|
|
18
|
+
/** The event-targets table (`*AuditEventTargetsTable`). */
|
|
19
|
+
eventTargets?: DrizzleEventTargetsTable;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A KV-only {@link AuditStorage} over a Drizzle table. For push
|
|
23
|
+
* change-notifications, compose it with {@link ./watch.withWatch} + a change
|
|
24
|
+
* source (e.g. {@link ./watch.pgListenNotify}) — `watch` is orthogonal to the
|
|
25
|
+
* adapter.
|
|
26
|
+
*/
|
|
27
|
+
type DrizzleAuditStorage = AuditStorage;
|
|
28
|
+
/** A Drizzle storage with the native {@link EventLogStorage} capability. */
|
|
29
|
+
type DrizzleEventLogAuditStorage = EventLogStorage;
|
|
30
|
+
/**
|
|
31
|
+
* Create a Drizzle-backed storage. No DDL, no connection ownership. The upsert
|
|
32
|
+
* dialect (Postgres/SQLite `onConflictDoUpdate` vs MySQL `onDuplicateKeyUpdate`)
|
|
33
|
+
* is detected at runtime from the insert builder. With `events` +
|
|
34
|
+
* `eventTargets` the result implements the native event log.
|
|
35
|
+
*/
|
|
36
|
+
declare function createDrizzleStorage(options: DrizzleStorageOptions & {
|
|
37
|
+
events: DrizzleEventsTable;
|
|
38
|
+
eventTargets: DrizzleEventTargetsTable;
|
|
39
|
+
}): DrizzleEventLogAuditStorage;
|
|
40
|
+
declare function createDrizzleStorage(options: DrizzleStorageOptions): DrizzleAuditStorage;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { DrizzleAuditStorage, type DrizzleAuditTables, DrizzleEventLogAuditStorage, type DrizzleEventTargetsTable, type DrizzleEventsTable, type DrizzleKvTable, DrizzleStorageOptions, createDrizzleStorage };
|
|
43
|
+
//# sourceMappingURL=entry-storage-drizzle.d.mts.map
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { t as ChainConflictError } from "./contract-isM9SjjQ.mjs";
|
|
2
|
+
import { a as escapeLike, d as parseEvent, f as toQueryResult, i as escapeGlob, l as eventTargets, o as eventColumns, t as assertContiguous, u as isWriteConflict } from "./sql-COjPyn3F.mjs";
|
|
3
|
+
import { and, asc, count, desc, eq, exists, gt, gte, inArray, is, lt, lte, max, not, notInArray, or, sql } from "drizzle-orm";
|
|
4
|
+
import { SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
5
|
+
//#region src/storage/drizzle.ts
|
|
6
|
+
/**
|
|
7
|
+
* Drizzle storage adapter — a {@link AuditStorage} over **consumer-owned**
|
|
8
|
+
* Drizzle tables and database. Unlike {@link ./postgres.createPostgresStorage}
|
|
9
|
+
* it issues **no DDL** (the tables live in your Drizzle schema + migrations)
|
|
10
|
+
* and **owns no connection** (it reuses the `db` you pass, and never closes it).
|
|
11
|
+
*
|
|
12
|
+
* Dialect-agnostic: works with Postgres, MySQL, and SQLite Drizzle databases.
|
|
13
|
+
* Build the tables with the matching factory —
|
|
14
|
+
* {@link ../drizzle/pg.pgAuditTables} / {@link ../drizzle/mysql.mysqlAuditTables} /
|
|
15
|
+
* {@link ../drizzle/sqlite.sqliteAuditTables} (or the per-table factories).
|
|
16
|
+
* Control data goes to the KV `table`; when you also pass `events` and
|
|
17
|
+
* `eventTargets`, the adapter implements the **native event log** (ADR 0005):
|
|
18
|
+
* indexed queries compiled with Drizzle's query builder, and appends in one
|
|
19
|
+
* transaction that checks the tenant's head seq. Without them it is KV-only and
|
|
20
|
+
* the core falls back to its generic KV event log.
|
|
21
|
+
*
|
|
22
|
+
* Transactions use `db.transaction`: async callbacks on Postgres, MySQL and
|
|
23
|
+
* async SQLite drivers (libSQL), a synchronous `immediate` transaction on sync
|
|
24
|
+
* SQLite drivers (`bun:sqlite`, `better-sqlite3`). Drivers without
|
|
25
|
+
* transactions (e.g. `neon-http`) cannot use the native event log.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { drizzle } from "drizzle-orm/node-postgres";
|
|
30
|
+
* import { createDrizzleStorage } from "@xtandard/audit/storage/drizzle";
|
|
31
|
+
* import { pgAuditTables } from "@xtandard/audit/drizzle/pg";
|
|
32
|
+
*
|
|
33
|
+
* // schema.ts: export each table so drizzle-kit migrates it
|
|
34
|
+
* export const {
|
|
35
|
+
* table: auditKv,
|
|
36
|
+
* events: auditEvents,
|
|
37
|
+
* eventTargets: auditEventTargets,
|
|
38
|
+
* } = pgAuditTables();
|
|
39
|
+
*
|
|
40
|
+
* const db = drizzle(pool); // your existing pool
|
|
41
|
+
* const storage = createDrizzleStorage({
|
|
42
|
+
* db,
|
|
43
|
+
* table: auditKv,
|
|
44
|
+
* events: auditEvents,
|
|
45
|
+
* eventTargets: auditEventTargets,
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @module
|
|
50
|
+
*/
|
|
51
|
+
/** Rows per INSERT statement (keeps every dialect well under its bind-parameter limit). */
|
|
52
|
+
const INSERT_CHUNK = 500;
|
|
53
|
+
/** Parse a value defensively — Drizzle returns json parsed, but a string is parsed too. */
|
|
54
|
+
const parseValue = (value) => {
|
|
55
|
+
if (typeof value === "string") try {
|
|
56
|
+
return JSON.parse(value);
|
|
57
|
+
} catch {
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
};
|
|
62
|
+
function chunks(list) {
|
|
63
|
+
const out = [];
|
|
64
|
+
for (let i = 0; i < list.length; i += INSERT_CHUNK) out.push(list.slice(i, i + INSERT_CHUNK));
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
function createDrizzleStorage(options) {
|
|
68
|
+
const db = options.db;
|
|
69
|
+
const { table } = options;
|
|
70
|
+
if (!options.events !== !options.eventTargets) throw new Error("createDrizzleStorage: pass both `events` and `eventTargets`, or neither");
|
|
71
|
+
const kv = {
|
|
72
|
+
async getItem(key) {
|
|
73
|
+
const row = (await db.select({ value: table.value }).from(table).where(eq(table.key, key)))[0];
|
|
74
|
+
if (row === void 0 || row.value === null || row.value === void 0) return null;
|
|
75
|
+
return parseValue(row.value);
|
|
76
|
+
},
|
|
77
|
+
async setItem(key, value) {
|
|
78
|
+
const insert = db.insert(table).values({
|
|
79
|
+
key,
|
|
80
|
+
value
|
|
81
|
+
});
|
|
82
|
+
if (typeof insert.onConflictDoUpdate === "function") await insert.onConflictDoUpdate({
|
|
83
|
+
target: table.key,
|
|
84
|
+
set: { value }
|
|
85
|
+
});
|
|
86
|
+
else if (typeof insert.onDuplicateKeyUpdate === "function") await insert.onDuplicateKeyUpdate({ set: { value } });
|
|
87
|
+
else throw new Error("createDrizzleStorage: the Drizzle database exposes no known upsert method (onConflictDoUpdate / onDuplicateKeyUpdate).");
|
|
88
|
+
},
|
|
89
|
+
async removeItem(key) {
|
|
90
|
+
await db.delete(table).where(eq(table.key, key));
|
|
91
|
+
},
|
|
92
|
+
async getKeys(prefix) {
|
|
93
|
+
const pattern = `${escapeLike(prefix)}%`;
|
|
94
|
+
return (await db.select({ key: table.key }).from(table).where(sql`${table.key} like ${pattern} escape '!'`)).map((row) => String(row.key)).filter((key) => key.startsWith(prefix));
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
if (!options.events || !options.eventTargets) return kv;
|
|
98
|
+
return {
|
|
99
|
+
...kv,
|
|
100
|
+
...createDrizzleEventLog(options.db, options.events, options.eventTargets)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** The native event log over Drizzle's query builder. */
|
|
104
|
+
function createDrizzleEventLog(db, ev, tg) {
|
|
105
|
+
const sync = db.resultKind === "sync";
|
|
106
|
+
const sqlite = is(ev, SQLiteTable);
|
|
107
|
+
const actionPrefix = (pre) => sqlite ? sql`${ev.action} glob ${`${escapeGlob(pre)}*`}` : sql`${ev.action} like ${`${escapeLike(pre)}%`} escape '!'`;
|
|
108
|
+
/**
|
|
109
|
+
* Run `read`, then the writes `write` derives from its rows, in one
|
|
110
|
+
* transaction; resolves to the rows read. Sync SQLite drivers need a
|
|
111
|
+
* synchronous callback (`all()`/`run()`), everything else awaits builders.
|
|
112
|
+
*/
|
|
113
|
+
async function atomic(read, write) {
|
|
114
|
+
if (sync) return await db.transaction((tx) => {
|
|
115
|
+
const rows = read(tx).all();
|
|
116
|
+
for (const w of write(tx, rows)) w.run();
|
|
117
|
+
return rows;
|
|
118
|
+
}, { behavior: "immediate" });
|
|
119
|
+
return await db.transaction(async (tx) => {
|
|
120
|
+
const rows = await read(tx);
|
|
121
|
+
for (const w of write(tx, rows)) await w;
|
|
122
|
+
return rows;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
const one = async (where, order) => {
|
|
126
|
+
let q = db.select({ data: ev.data }).from(ev).where(where);
|
|
127
|
+
if (order) q = q.orderBy(order);
|
|
128
|
+
const [row] = await q.limit(1);
|
|
129
|
+
return row ? parseEvent(row.data) : null;
|
|
130
|
+
};
|
|
131
|
+
function whereFor(q) {
|
|
132
|
+
const conds = [];
|
|
133
|
+
if (q.tenant !== void 0) conds.push(eq(ev.tenant, q.tenant));
|
|
134
|
+
if (q.actions.length > 0 || q.actionPrefixes.length > 0) conds.push(or(q.actions.length > 0 ? inArray(ev.action, q.actions) : void 0, ...q.actionPrefixes.map(actionPrefix)));
|
|
135
|
+
if (q.excludeActions.length > 0) conds.push(notInArray(ev.action, q.excludeActions));
|
|
136
|
+
for (const pre of q.excludeActionPrefixes) conds.push(not(actionPrefix(pre)));
|
|
137
|
+
if (q.actorId !== void 0) conds.push(eq(ev.actorId, q.actorId));
|
|
138
|
+
if (q.actorType !== void 0) conds.push(eq(ev.actorType, q.actorType));
|
|
139
|
+
if (q.targetType !== void 0 || q.targetId !== void 0) conds.push(exists(db.select({ one: sql`1` }).from(tg).where(and(eq(tg.tenant, ev.tenant), eq(tg.seq, ev.seq), q.targetType !== void 0 ? eq(tg.type, q.targetType) : void 0, q.targetId !== void 0 ? eq(tg.targetId, q.targetId) : void 0))));
|
|
140
|
+
if (q.outcome !== void 0) conds.push(eq(ev.outcome, q.outcome));
|
|
141
|
+
if (q.from !== void 0) conds.push(gte(ev.occurredAt, q.from));
|
|
142
|
+
if (q.to !== void 0) conds.push(lt(ev.occurredAt, q.to));
|
|
143
|
+
if (q.search !== void 0) conds.push(sql`${ev.search} like ${`%${escapeLike(q.search)}%`} escape '!'`);
|
|
144
|
+
if (q.after) {
|
|
145
|
+
const cmp = q.order === "desc" ? lt : gt;
|
|
146
|
+
conds.push(or(cmp(ev.occurredAt, q.after.occurredAt), and(eq(ev.occurredAt, q.after.occurredAt), cmp(ev.id, q.after.id))));
|
|
147
|
+
}
|
|
148
|
+
return and(...conds);
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
async appendEvents(tenant, events, { expectedSeq }) {
|
|
152
|
+
if (events.length === 0) return;
|
|
153
|
+
assertContiguous(tenant, events, expectedSeq);
|
|
154
|
+
const eventRows = events.map((e) => ({
|
|
155
|
+
...eventColumns(e),
|
|
156
|
+
data: e
|
|
157
|
+
}));
|
|
158
|
+
const targetRows = events.flatMap((e) => eventTargets(e).map((t) => ({
|
|
159
|
+
tenant,
|
|
160
|
+
seq: e.seq,
|
|
161
|
+
type: t.type,
|
|
162
|
+
targetId: t.targetId
|
|
163
|
+
})));
|
|
164
|
+
try {
|
|
165
|
+
await atomic((tx) => tx.select({ m: max(ev.seq) }).from(ev).where(eq(ev.tenant, tenant)), (tx, rows) => {
|
|
166
|
+
const head = Number(rows[0]?.m ?? 0);
|
|
167
|
+
if (head !== expectedSeq && head !== 0) throw new ChainConflictError(tenant, expectedSeq);
|
|
168
|
+
return [...chunks(eventRows).map((c) => tx.insert(ev).values(c)), ...chunks(targetRows).map((c) => tx.insert(tg).values(c))];
|
|
169
|
+
});
|
|
170
|
+
} catch (err) {
|
|
171
|
+
if (err instanceof ChainConflictError) throw err;
|
|
172
|
+
if (isWriteConflict(err)) throw new ChainConflictError(tenant, expectedSeq);
|
|
173
|
+
throw err;
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
getEvent: (tenant, id) => one(and(eq(ev.tenant, tenant), eq(ev.id, id))),
|
|
177
|
+
lastEvent: (tenant) => one(eq(ev.tenant, tenant), desc(ev.seq)),
|
|
178
|
+
async eventsBySeq(tenant, { afterSeq, limit }) {
|
|
179
|
+
return (await db.select({ data: ev.data }).from(ev).where(and(eq(ev.tenant, tenant), gt(ev.seq, afterSeq))).orderBy(asc(ev.seq)).limit(limit)).map((r) => parseEvent(r.data));
|
|
180
|
+
},
|
|
181
|
+
async queryEvents(q) {
|
|
182
|
+
const dir = q.order === "desc" ? desc : asc;
|
|
183
|
+
return toQueryResult(await db.select({ data: ev.data }).from(ev).where(whereFor(q)).orderBy(dir(ev.occurredAt), dir(ev.id)).limit(q.limit + 1), q.limit);
|
|
184
|
+
},
|
|
185
|
+
async replaceEvent(event) {
|
|
186
|
+
const c = eventColumns(event);
|
|
187
|
+
const key = and(eq(ev.tenant, c.tenant), eq(ev.seq, c.seq), eq(ev.id, c.id));
|
|
188
|
+
const targets = eventTargets(event).map((t) => ({
|
|
189
|
+
tenant: c.tenant,
|
|
190
|
+
seq: c.seq,
|
|
191
|
+
type: t.type,
|
|
192
|
+
targetId: t.targetId
|
|
193
|
+
}));
|
|
194
|
+
await atomic((tx) => tx.select({ seq: ev.seq }).from(ev).where(key), (tx, rows) => rows.length === 0 ? [] : [
|
|
195
|
+
tx.update(ev).set({
|
|
196
|
+
action: c.action,
|
|
197
|
+
occurredAt: c.occurredAt,
|
|
198
|
+
recordedAt: c.recordedAt,
|
|
199
|
+
actorId: c.actorId,
|
|
200
|
+
actorType: c.actorType,
|
|
201
|
+
outcome: c.outcome,
|
|
202
|
+
search: c.search,
|
|
203
|
+
data: event
|
|
204
|
+
}).where(key),
|
|
205
|
+
tx.delete(tg).where(and(eq(tg.tenant, c.tenant), eq(tg.seq, c.seq))),
|
|
206
|
+
...targets.length > 0 ? [tx.insert(tg).values(targets)] : []
|
|
207
|
+
]);
|
|
208
|
+
},
|
|
209
|
+
async deleteEventsThrough(tenant, throughSeq) {
|
|
210
|
+
const [row] = await atomic((tx) => tx.select({ n: count() }).from(ev).where(and(eq(ev.tenant, tenant), lte(ev.seq, throughSeq))), (tx) => [tx.delete(tg).where(and(eq(tg.tenant, tenant), lte(tg.seq, throughSeq))), tx.delete(ev).where(and(eq(ev.tenant, tenant), lte(ev.seq, throughSeq)))]);
|
|
211
|
+
return Number(row?.n ?? 0);
|
|
212
|
+
},
|
|
213
|
+
async countEvents(tenant) {
|
|
214
|
+
let q = db.select({ n: count() }).from(ev);
|
|
215
|
+
if (tenant !== void 0) q = q.where(eq(ev.tenant, tenant));
|
|
216
|
+
const [row] = await q;
|
|
217
|
+
return Number(row?.n ?? 0);
|
|
218
|
+
},
|
|
219
|
+
async listEventTenants() {
|
|
220
|
+
return (await db.selectDistinct({ tenant: ev.tenant }).from(ev).orderBy(asc(ev.tenant))).map((r) => String(r.tenant));
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
export { createDrizzleStorage };
|
|
226
|
+
|
|
227
|
+
//# sourceMappingURL=entry-storage-drizzle.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-storage-drizzle.mjs","names":[],"sources":["../src/storage/drizzle.ts"],"sourcesContent":["/**\n * Drizzle storage adapter — a {@link AuditStorage} over **consumer-owned**\n * Drizzle tables and database. Unlike {@link ./postgres.createPostgresStorage}\n * it issues **no DDL** (the tables live in your Drizzle schema + migrations)\n * and **owns no connection** (it reuses the `db` you pass, and never closes it).\n *\n * Dialect-agnostic: works with Postgres, MySQL, and SQLite Drizzle databases.\n * Build the tables with the matching factory —\n * {@link ../drizzle/pg.pgAuditTables} / {@link ../drizzle/mysql.mysqlAuditTables} /\n * {@link ../drizzle/sqlite.sqliteAuditTables} (or the per-table factories).\n * Control data goes to the KV `table`; when you also pass `events` and\n * `eventTargets`, the adapter implements the **native event log** (ADR 0005):\n * indexed queries compiled with Drizzle's query builder, and appends in one\n * transaction that checks the tenant's head seq. Without them it is KV-only and\n * the core falls back to its generic KV event log.\n *\n * Transactions use `db.transaction`: async callbacks on Postgres, MySQL and\n * async SQLite drivers (libSQL), a synchronous `immediate` transaction on sync\n * SQLite drivers (`bun:sqlite`, `better-sqlite3`). Drivers without\n * transactions (e.g. `neon-http`) cannot use the native event log.\n *\n * @example\n * ```ts\n * import { drizzle } from \"drizzle-orm/node-postgres\";\n * import { createDrizzleStorage } from \"@xtandard/audit/storage/drizzle\";\n * import { pgAuditTables } from \"@xtandard/audit/drizzle/pg\";\n *\n * // schema.ts: export each table so drizzle-kit migrates it\n * export const {\n * table: auditKv,\n * events: auditEvents,\n * eventTargets: auditEventTargets,\n * } = pgAuditTables();\n *\n * const db = drizzle(pool); // your existing pool\n * const storage = createDrizzleStorage({\n * db,\n * table: auditKv,\n * events: auditEvents,\n * eventTargets: auditEventTargets,\n * });\n * ```\n *\n * @module\n */\n\nimport {\n and,\n asc,\n count,\n desc,\n eq,\n exists,\n gt,\n gte,\n inArray,\n is,\n lt,\n lte,\n max,\n not,\n notInArray,\n or,\n sql,\n type Column,\n type SQL,\n type Table,\n} from \"drizzle-orm\";\nimport { SQLiteTable } from \"drizzle-orm/sqlite-core\";\nimport type { NormalizedQuery } from \"../query.ts\";\nimport { ChainConflictError, type AuditStorage, type EventLogStorage } from \"./contract.ts\";\nimport {\n assertContiguous,\n escapeGlob,\n escapeLike,\n eventColumns,\n eventTargets,\n isWriteConflict,\n parseEvent,\n toQueryResult,\n type EventLogMethods,\n} from \"./sql.ts\";\nimport type {\n DrizzleEventTargetsTable,\n DrizzleEventsTable,\n DrizzleKvTable,\n} from \"../drizzle/table.ts\";\n\nexport type {\n DrizzleAuditTables,\n DrizzleEventTargetsTable,\n DrizzleEventsTable,\n DrizzleKvTable,\n} from \"../drizzle/table.ts\";\n\n/**\n * Minimal structural view of a Drizzle database — the query-builder entry points\n * the KV adapter uses. This is the internal contract the adapter casts `db` to;\n * the public option is typed `unknown` because a dialect-agnostic structural type\n * cannot match dialect-specific dbs (their `.from`/`.insert` want `PgTable` etc.,\n * not the base `Table`). The upsert method differs by dialect and is\n * feature-detected at runtime.\n */\ninterface DrizzleLikeDatabase {\n select(fields: Record<string, Column>): {\n from(table: Table): { where(where: SQL): PromiseLike<unknown[]> };\n };\n insert(table: Table): {\n values(row: { key: string; value: unknown }): {\n /** Postgres + SQLite upsert. */\n onConflictDoUpdate?(config: {\n target: Column;\n set: { value: unknown };\n }): PromiseLike<unknown>;\n /** MySQL upsert. */\n onDuplicateKeyUpdate?(config: { set: { value: unknown } }): PromiseLike<unknown>;\n };\n };\n delete(table: Table): { where(where: SQL): PromiseLike<unknown> };\n}\n\n/**\n * A Drizzle query builder as the event log uses it: chainable, awaitable, and\n * (on sync SQLite drivers) executable with `all()` / `run()`. Loosely typed on\n * purpose — the dialect-specific builder types do not unify.\n */\ninterface Builder extends PromiseLike<unknown> {\n [method: string]: any;\n}\n\n/** The Drizzle database surface the event log uses (any dialect). */\ninterface DrizzleEventLogDatabase {\n select(fields?: Record<string, unknown>): Builder;\n selectDistinct(fields: Record<string, unknown>): Builder;\n insert(table: Table): Builder;\n update(table: Table): Builder;\n delete(table: Table): Builder;\n transaction(fn: (tx: DrizzleEventLogDatabase) => unknown, config?: unknown): Promise<unknown>;\n /** `\"sync\"` on `bun:sqlite` / `better-sqlite3` Drizzle databases. */\n resultKind?: string;\n}\n\n/** Options for {@link createDrizzleStorage}. */\nexport interface DrizzleStorageOptions {\n /**\n * Your Drizzle database (node-postgres / mysql2 / better-sqlite3 / pglite / …).\n * Typed `unknown` intentionally — a single dialect-agnostic type can't match\n * every dialect's db; the adapter only calls the query builder and\n * `transaction`.\n */\n db: unknown;\n /** The KV table built with a `*AuditTable` factory (or matching that shape). */\n table: DrizzleKvTable;\n /** The events table (`*AuditEventsTable`). Pass with `eventTargets` for the native event log. */\n events?: DrizzleEventsTable;\n /** The event-targets table (`*AuditEventTargetsTable`). */\n eventTargets?: DrizzleEventTargetsTable;\n}\n\n/**\n * A KV-only {@link AuditStorage} over a Drizzle table. For push\n * change-notifications, compose it with {@link ./watch.withWatch} + a change\n * source (e.g. {@link ./watch.pgListenNotify}) — `watch` is orthogonal to the\n * adapter.\n */\nexport type DrizzleAuditStorage = AuditStorage;\n\n/** A Drizzle storage with the native {@link EventLogStorage} capability. */\nexport type DrizzleEventLogAuditStorage = EventLogStorage;\n\n/** Rows per INSERT statement (keeps every dialect well under its bind-parameter limit). */\nconst INSERT_CHUNK = 500;\n\n/** Parse a value defensively — Drizzle returns json parsed, but a string is parsed too. */\nconst parseValue = <T>(value: unknown): T => {\n if (typeof value === \"string\") {\n try {\n return JSON.parse(value) as T;\n } catch {\n return value as T;\n }\n }\n return value as T;\n};\n\nfunction chunks<T>(list: T[]): T[][] {\n const out: T[][] = [];\n for (let i = 0; i < list.length; i += INSERT_CHUNK) out.push(list.slice(i, i + INSERT_CHUNK));\n return out;\n}\n\n/**\n * Create a Drizzle-backed storage. No DDL, no connection ownership. The upsert\n * dialect (Postgres/SQLite `onConflictDoUpdate` vs MySQL `onDuplicateKeyUpdate`)\n * is detected at runtime from the insert builder. With `events` +\n * `eventTargets` the result implements the native event log.\n */\nexport function createDrizzleStorage(\n options: DrizzleStorageOptions & {\n events: DrizzleEventsTable;\n eventTargets: DrizzleEventTargetsTable;\n },\n): DrizzleEventLogAuditStorage;\nexport function createDrizzleStorage(options: DrizzleStorageOptions): DrizzleAuditStorage;\nexport function createDrizzleStorage(\n options: DrizzleStorageOptions,\n): DrizzleAuditStorage | DrizzleEventLogAuditStorage {\n const db = options.db as DrizzleLikeDatabase;\n const { table } = options;\n if (!options.events !== !options.eventTargets) {\n throw new Error(\"createDrizzleStorage: pass both `events` and `eventTargets`, or neither\");\n }\n\n const kv: AuditStorage = {\n async getItem<T>(key: string): Promise<T | null> {\n const rows = (await db\n .select({ value: table.value })\n .from(table)\n .where(eq(table.key, key))) as Array<{ value: unknown }>;\n const row = rows[0];\n if (row === undefined || row.value === null || row.value === undefined) return null;\n return parseValue<T>(row.value);\n },\n\n async setItem<T>(key: string, value: T): Promise<void> {\n const insert = db.insert(table).values({ key, value });\n if (typeof insert.onConflictDoUpdate === \"function\") {\n await insert.onConflictDoUpdate({ target: table.key, set: { value } });\n } else if (typeof insert.onDuplicateKeyUpdate === \"function\") {\n await insert.onDuplicateKeyUpdate({ set: { value } });\n } else {\n throw new Error(\n \"createDrizzleStorage: the Drizzle database exposes no known upsert method \" +\n \"(onConflictDoUpdate / onDuplicateKeyUpdate).\",\n );\n }\n },\n\n async removeItem(key: string): Promise<void> {\n await db.delete(table).where(eq(table.key, key));\n },\n\n async getKeys(prefix: string): Promise<string[]> {\n // `!` as the LIKE escape: a backslash literal is not portable (MySQL eats it).\n const pattern = `${escapeLike(prefix)}%`;\n const rows = (await db\n .select({ key: table.key })\n .from(table)\n .where(sql`${table.key} like ${pattern} escape '!'`)) as Array<{ key: unknown }>;\n // SQLite LIKE folds case and MySQL collations may too: keep only exact prefix matches.\n return rows.map((row) => String(row.key)).filter((key) => key.startsWith(prefix));\n },\n };\n\n if (!options.events || !options.eventTargets) return kv;\n return {\n ...kv,\n ...createDrizzleEventLog(\n options.db as DrizzleEventLogDatabase,\n options.events,\n options.eventTargets,\n ),\n } satisfies DrizzleEventLogAuditStorage;\n}\n\n/** The native event log over Drizzle's query builder. */\nfunction createDrizzleEventLog(\n db: DrizzleEventLogDatabase,\n ev: DrizzleEventsTable,\n tg: DrizzleEventTargetsTable,\n): EventLogMethods {\n const sync = db.resultKind === \"sync\";\n // SQLite's LIKE folds ASCII case; GLOB is case-sensitive like the in-memory matcher.\n const sqlite = is(ev as object, SQLiteTable); // (not `is(ev, …)`: that would narrow `ev`)\n const actionPrefix = (pre: string): SQL =>\n sqlite\n ? sql`${ev.action} glob ${`${escapeGlob(pre)}*`}`\n : sql`${ev.action} like ${`${escapeLike(pre)}%`} escape '!'`;\n\n type Row = Record<string, unknown>;\n\n /**\n * Run `read`, then the writes `write` derives from its rows, in one\n * transaction; resolves to the rows read. Sync SQLite drivers need a\n * synchronous callback (`all()`/`run()`), everything else awaits builders.\n */\n async function atomic(\n read: (tx: DrizzleEventLogDatabase) => Builder,\n write: (tx: DrizzleEventLogDatabase, rows: Row[]) => Builder[],\n ): Promise<Row[]> {\n if (sync) {\n return (await db.transaction(\n (tx) => {\n const rows = read(tx).all() as Row[];\n for (const w of write(tx, rows)) w.run();\n return rows;\n },\n { behavior: \"immediate\" },\n )) as Row[];\n }\n return (await db.transaction(async (tx) => {\n const rows = (await read(tx)) as Row[];\n for (const w of write(tx, rows)) await w;\n return rows;\n })) as Row[];\n }\n\n const one = async (where: SQL, order?: SQL) => {\n let q = db.select({ data: ev.data }).from(ev).where(where);\n if (order) q = q.orderBy(order);\n const [row] = (await q.limit(1)) as Row[];\n return row ? parseEvent(row.data) : null;\n };\n\n function whereFor(q: NormalizedQuery): SQL | undefined {\n const conds: (SQL | undefined)[] = [];\n if (q.tenant !== undefined) conds.push(eq(ev.tenant, q.tenant));\n if (q.actions.length > 0 || q.actionPrefixes.length > 0) {\n conds.push(\n or(\n q.actions.length > 0 ? inArray(ev.action, q.actions) : undefined,\n ...q.actionPrefixes.map(actionPrefix),\n ),\n );\n }\n if (q.excludeActions.length > 0) conds.push(notInArray(ev.action, q.excludeActions));\n for (const pre of q.excludeActionPrefixes) conds.push(not(actionPrefix(pre)));\n if (q.actorId !== undefined) conds.push(eq(ev.actorId, q.actorId));\n if (q.actorType !== undefined) conds.push(eq(ev.actorType, q.actorType));\n if (q.targetType !== undefined || q.targetId !== undefined) {\n conds.push(\n exists(\n db\n .select({ one: sql`1` })\n .from(tg)\n .where(\n and(\n eq(tg.tenant, ev.tenant),\n eq(tg.seq, ev.seq),\n q.targetType !== undefined ? eq(tg.type, q.targetType) : undefined,\n q.targetId !== undefined ? eq(tg.targetId, q.targetId) : undefined,\n ),\n ),\n ),\n );\n }\n if (q.outcome !== undefined) conds.push(eq(ev.outcome, q.outcome));\n if (q.from !== undefined) conds.push(gte(ev.occurredAt, q.from));\n if (q.to !== undefined) conds.push(lt(ev.occurredAt, q.to));\n if (q.search !== undefined) {\n conds.push(sql`${ev.search} like ${`%${escapeLike(q.search)}%`} escape '!'`);\n }\n if (q.after) {\n const cmp = q.order === \"desc\" ? lt : gt;\n conds.push(\n or(\n cmp(ev.occurredAt, q.after.occurredAt),\n and(eq(ev.occurredAt, q.after.occurredAt), cmp(ev.id, q.after.id)),\n ),\n );\n }\n return and(...conds);\n }\n\n return {\n async appendEvents(tenant, events, { expectedSeq }) {\n if (events.length === 0) return;\n assertContiguous(tenant, events, expectedSeq);\n const eventRows = events.map((e) => ({ ...eventColumns(e), data: e }));\n const targetRows = events.flatMap((e) =>\n eventTargets(e).map((t) => ({ tenant, seq: e.seq, type: t.type, targetId: t.targetId })),\n );\n try {\n await atomic(\n (tx) =>\n tx\n .select({ m: max(ev.seq) })\n .from(ev)\n .where(eq(ev.tenant, tenant)),\n (tx, rows) => {\n // The tenant's head must be the expected one (or empty, e.g. after a full prune).\n const head = Number(rows[0]?.m ?? 0);\n if (head !== expectedSeq && head !== 0) {\n throw new ChainConflictError(tenant, expectedSeq);\n }\n return [\n ...chunks(eventRows).map((c) => tx.insert(ev).values(c)),\n ...chunks(targetRows).map((c) => tx.insert(tg).values(c)),\n ];\n },\n );\n } catch (err) {\n if (err instanceof ChainConflictError) throw err;\n if (isWriteConflict(err)) throw new ChainConflictError(tenant, expectedSeq);\n throw err;\n }\n },\n\n getEvent: (tenant, id) => one(and(eq(ev.tenant, tenant), eq(ev.id, id))!),\n\n lastEvent: (tenant) => one(eq(ev.tenant, tenant), desc(ev.seq)),\n\n async eventsBySeq(tenant, { afterSeq, limit }) {\n const rows = (await db\n .select({ data: ev.data })\n .from(ev)\n .where(and(eq(ev.tenant, tenant), gt(ev.seq, afterSeq)))\n .orderBy(asc(ev.seq))\n .limit(limit)) as Row[];\n return rows.map((r) => parseEvent(r.data));\n },\n\n async queryEvents(q) {\n const dir = q.order === \"desc\" ? desc : asc;\n const rows = (await db\n .select({ data: ev.data })\n .from(ev)\n .where(whereFor(q))\n .orderBy(dir(ev.occurredAt), dir(ev.id))\n .limit(q.limit + 1)) as Row[];\n return toQueryResult(rows, q.limit);\n },\n\n async replaceEvent(event) {\n const c = eventColumns(event);\n const key = and(eq(ev.tenant, c.tenant), eq(ev.seq, c.seq), eq(ev.id, c.id));\n const targets = eventTargets(event).map((t) => ({\n tenant: c.tenant,\n seq: c.seq,\n type: t.type,\n targetId: t.targetId,\n }));\n await atomic(\n (tx) => tx.select({ seq: ev.seq }).from(ev).where(key),\n (tx, rows) =>\n rows.length === 0\n ? []\n : [\n tx\n .update(ev)\n .set({\n action: c.action,\n occurredAt: c.occurredAt,\n recordedAt: c.recordedAt,\n actorId: c.actorId,\n actorType: c.actorType,\n outcome: c.outcome,\n search: c.search,\n data: event,\n })\n .where(key),\n tx.delete(tg).where(and(eq(tg.tenant, c.tenant), eq(tg.seq, c.seq))),\n ...(targets.length > 0 ? [tx.insert(tg).values(targets)] : []),\n ],\n );\n },\n\n async deleteEventsThrough(tenant, throughSeq) {\n const [row] = await atomic(\n (tx) =>\n tx\n .select({ n: count() })\n .from(ev)\n .where(and(eq(ev.tenant, tenant), lte(ev.seq, throughSeq))),\n (tx) => [\n tx.delete(tg).where(and(eq(tg.tenant, tenant), lte(tg.seq, throughSeq))),\n tx.delete(ev).where(and(eq(ev.tenant, tenant), lte(ev.seq, throughSeq))),\n ],\n );\n return Number(row?.n ?? 0);\n },\n\n async countEvents(tenant) {\n let q = db.select({ n: count() }).from(ev);\n if (tenant !== undefined) q = q.where(eq(ev.tenant, tenant));\n const [row] = (await q) as Row[];\n return Number(row?.n ?? 0);\n },\n\n async listEventTenants() {\n const rows = (await db\n .selectDistinct({ tenant: ev.tenant })\n .from(ev)\n .orderBy(asc(ev.tenant))) as Row[];\n return rows.map((r) => String(r.tenant));\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2KA,MAAM,eAAe;;AAGrB,MAAM,cAAiB,UAAsB;CAC3C,IAAI,OAAO,UAAU,UACnB,IAAI;EACF,OAAO,KAAK,MAAM,KAAK;CACzB,QAAQ;EACN,OAAO;CACT;CAEF,OAAO;AACT;AAEA,SAAS,OAAU,MAAkB;CACnC,MAAM,MAAa,CAAC;CACpB,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK,cAAc,IAAI,KAAK,KAAK,MAAM,GAAG,IAAI,YAAY,CAAC;CAC5F,OAAO;AACT;AAeA,SAAgB,qBACd,SACmD;CACnD,MAAM,KAAK,QAAQ;CACnB,MAAM,EAAE,UAAU;CAClB,IAAI,CAAC,QAAQ,WAAW,CAAC,QAAQ,cAC/B,MAAM,IAAI,MAAM,yEAAyE;CAG3F,MAAM,KAAmB;EACvB,MAAM,QAAW,KAAgC;GAK/C,MAAM,OAAM,MAJQ,GACjB,OAAO,EAAE,OAAO,MAAM,MAAM,CAAC,EAC7B,KAAK,KAAK,EACV,MAAM,GAAG,MAAM,KAAK,GAAG,CAAC,GACV;GACjB,IAAI,QAAQ,KAAA,KAAa,IAAI,UAAU,QAAQ,IAAI,UAAU,KAAA,GAAW,OAAO;GAC/E,OAAO,WAAc,IAAI,KAAK;EAChC;E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C;GAC9D,CACR;EACF;EAEA,MAAM,oBAAoB,QAAQ,YAAY;GAC5C,MAAM,CAAC,OAAO,MAAM,QACjB,OACC,GACG,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,EACrB,KAAK,EAAE,EACP,MAAM,IAAI,GAAG,GAAG,QAAQ,MAAM,GAAG,IAAI,GAAG,KAAK,UAAU,CAAC,CAAC,IAC7D,OAAO,CACN,GAAG,OAAO,EAAE,EAAE,MAAM,IAAI,GAAG,GAAG,QAAQ,MAAM,GAAG,IAAI,GAAG,KAAK,UAAU,CAAC,CAAC,GACvE,GAAG,OAAO,EAAE,EAAE,MAAM,IAAI,GAAG,GAAG,QAAQ,MAAM,GAAG,IAAI,GAAG,KAAK,UAAU,CAAC,CAAC,CACzE,CACF;GACA,OAAO,OAAO,KAAK,KAAK,CAAC;EAC3B;EAEA,MAAM,YAAY,QAAQ;GACxB,IAAI,IAAI,GAAG,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE;GACzC,IAAI,WAAW,KAAA,GAAW,IAAI,EAAE,MAAM,GAAG,GAAG,QAAQ,MAAM,CAAC;GAC3D,MAAM,CAAC,OAAQ,MAAM;GACrB,OAAO,OAAO,KAAK,KAAK,CAAC;EAC3B;EAEA,MAAM,mBAAmB;GAKvB,QAAO,MAJa,GACjB,eAAe,EAAE,QAAQ,GAAG,OAAO,CAAC,EACpC,KAAK,EAAE,EACP,QAAQ,IAAI,GAAG,MAAM,CAAC,GACb,KAAK,MAAM,OAAO,EAAE,MAAM,CAAC;EACzC;CACF;AACF"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let node_fs = require("node:fs");
|
|
3
|
+
let node_fs_promises = require("node:fs/promises");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
//#region src/storage/file.ts
|
|
6
|
+
/**
|
|
7
|
+
* File-system storage adapter. Persists each key as a JSON file under a base
|
|
8
|
+
* directory, mirroring the slash-delimited key layout (`aud/t/{tenant}/…`) as a
|
|
9
|
+
* tree of nested directories with a `.json` extension on the leaf. Zero
|
|
10
|
+
* external dependencies — uses `node:fs/promises`, which works in both Bun and
|
|
11
|
+
* Node.
|
|
12
|
+
*
|
|
13
|
+
* KV only: events go through the core's generic KV event log (ADR 0005), one
|
|
14
|
+
* file per event plus one per index entry. Fine for development, demos and
|
|
15
|
+
* small single-process deployments; there is no compare-and-swap, so the core
|
|
16
|
+
* assumes a **single writer per tenant** (one process). Writes go to a temp file
|
|
17
|
+
* that is then renamed over the target, so a concurrent reader never sees a
|
|
18
|
+
* half-written value.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
/** Suffix appended to the leaf file for every stored key. */
|
|
23
|
+
const JSON_SUFFIX = ".json";
|
|
24
|
+
/**
|
|
25
|
+
* Encode one key segment as a file name that survives case-insensitive and
|
|
26
|
+
* normalization-insensitive filesystems (macOS, Windows) and never escapes its
|
|
27
|
+
* directory: uppercase letters become `^` + the lowercase letter, `^` becomes
|
|
28
|
+
* `^^`, bytes outside `[a-z0-9._~!@,=+-]` become `%XX`, and a leading `.` is
|
|
29
|
+
* `%2E` (so `.` / `..` / dotfiles cannot appear). Without it, tenants `Acme` and
|
|
30
|
+
* `acme` would share files on a default macOS volume.
|
|
31
|
+
*/
|
|
32
|
+
function encodeSegment(segment) {
|
|
33
|
+
let out = "";
|
|
34
|
+
for (const byte of new TextEncoder().encode(segment)) {
|
|
35
|
+
const ch = String.fromCharCode(byte);
|
|
36
|
+
if (byte >= 65 && byte <= 90) out += `^${ch.toLowerCase()}`;
|
|
37
|
+
else if (ch === "^") out += "^^";
|
|
38
|
+
else if (/[a-z0-9._~!@,=+-]/.test(ch) && !(ch === "." && out === "")) out += ch;
|
|
39
|
+
else out += `%${byte.toString(16).toUpperCase().padStart(2, "0")}`;
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/** Reverse {@link encodeSegment}. */
|
|
44
|
+
function decodeSegment(name) {
|
|
45
|
+
const bytes = [];
|
|
46
|
+
for (let i = 0; i < name.length; i++) {
|
|
47
|
+
const ch = name[i];
|
|
48
|
+
if (ch === "^") {
|
|
49
|
+
const next = name[++i] ?? "";
|
|
50
|
+
bytes.push((next === "^" ? "^" : next.toUpperCase()).charCodeAt(0));
|
|
51
|
+
} else if (ch === "%") {
|
|
52
|
+
bytes.push(Number.parseInt(name.slice(i + 1, i + 3), 16));
|
|
53
|
+
i += 2;
|
|
54
|
+
} else bytes.push(ch.charCodeAt(0));
|
|
55
|
+
}
|
|
56
|
+
return new TextDecoder().decode(new Uint8Array(bytes));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Map a storage key (e.g. `aud/t/acme/head`) to an absolute file path inside
|
|
60
|
+
* `dir`. Each key segment becomes a directory; the last segment gains a
|
|
61
|
+
* `.json` extension.
|
|
62
|
+
*/
|
|
63
|
+
function keyToPath(dir, key) {
|
|
64
|
+
return (0, node_path.join)(dir, ...key.split("/").map(encodeSegment)) + JSON_SUFFIX;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Reverse {@link keyToPath}: turn an absolute (or `dir`-relative) file path back
|
|
68
|
+
* into the original slash-delimited storage key. Returns `null` for paths that
|
|
69
|
+
* are not `.json` leaves under `dir` (including in-flight temp files).
|
|
70
|
+
*/
|
|
71
|
+
function pathToKey(dir, filePath) {
|
|
72
|
+
const rel = (0, node_path.relative)(dir, filePath);
|
|
73
|
+
if (rel.startsWith("..") || !rel.endsWith(JSON_SUFFIX)) return null;
|
|
74
|
+
return rel.slice(0, -5).split(node_path.sep).map(decodeSegment).join("/");
|
|
75
|
+
}
|
|
76
|
+
/** Recursively collect every `.json` leaf file path under `root`. */
|
|
77
|
+
async function walk(root) {
|
|
78
|
+
const out = [];
|
|
79
|
+
let entries;
|
|
80
|
+
try {
|
|
81
|
+
entries = await (0, node_fs_promises.readdir)(root, { withFileTypes: true });
|
|
82
|
+
} catch (err) {
|
|
83
|
+
if (err.code === "ENOENT") return out;
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
for (const entry of entries) {
|
|
87
|
+
const name = entry.name.toString();
|
|
88
|
+
const full = (0, node_path.join)(root, name);
|
|
89
|
+
if (entry.isDirectory()) out.push(...await walk(full));
|
|
90
|
+
else if (entry.isFile() && name.endsWith(JSON_SUFFIX)) out.push(full);
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
let tmpCounter = 0;
|
|
95
|
+
/**
|
|
96
|
+
* Create a file-backed {@link WatchableAuditStorage}. Values are serialized
|
|
97
|
+
* as pretty-printed JSON. `watch` is implemented via `fs.watch` on the base
|
|
98
|
+
* directory (recursive); it is best-effort and may coalesce or miss events on
|
|
99
|
+
* platforms without recursive-watch support.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { createFileStorage } from "@xtandard/audit/storage/file";
|
|
104
|
+
*
|
|
105
|
+
* const storage = createFileStorage({ dir: "./data/audit" });
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
function createFileStorage(options) {
|
|
109
|
+
const { dir } = options;
|
|
110
|
+
return {
|
|
111
|
+
async getItem(key) {
|
|
112
|
+
try {
|
|
113
|
+
const raw = await (0, node_fs_promises.readFile)(keyToPath(dir, key), "utf8");
|
|
114
|
+
return JSON.parse(raw);
|
|
115
|
+
} catch (err) {
|
|
116
|
+
if (err.code === "ENOENT") return null;
|
|
117
|
+
throw err;
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
async setItem(key, value) {
|
|
121
|
+
const path = keyToPath(dir, key);
|
|
122
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), { recursive: true });
|
|
123
|
+
const tmp = `${path}.${process.pid}.${tmpCounter++}.tmp`;
|
|
124
|
+
await (0, node_fs_promises.writeFile)(tmp, JSON.stringify(value, null, 2), "utf8");
|
|
125
|
+
await (0, node_fs_promises.rename)(tmp, path);
|
|
126
|
+
},
|
|
127
|
+
async removeItem(key) {
|
|
128
|
+
try {
|
|
129
|
+
await (0, node_fs_promises.unlink)(keyToPath(dir, key));
|
|
130
|
+
} catch (err) {
|
|
131
|
+
if (err.code !== "ENOENT") throw err;
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
async getKeys(prefix) {
|
|
135
|
+
const files = await walk(dir);
|
|
136
|
+
const out = [];
|
|
137
|
+
for (const file of files) {
|
|
138
|
+
const key = pathToKey(dir, file);
|
|
139
|
+
if (key !== null && key.startsWith(prefix)) out.push(key);
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
},
|
|
143
|
+
async watch(prefix, callback) {
|
|
144
|
+
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
145
|
+
const watcher = (0, node_fs.watch)(dir, { recursive: true }, (eventType, filename) => {
|
|
146
|
+
if (!filename) return;
|
|
147
|
+
const path = (0, node_path.join)(dir, filename.toString());
|
|
148
|
+
const key = pathToKey(dir, path);
|
|
149
|
+
if (key === null || !key.startsWith(prefix)) return;
|
|
150
|
+
callback({
|
|
151
|
+
type: eventType === "rename" && !(0, node_fs.existsSync)(path) ? "remove" : "update",
|
|
152
|
+
key
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
return () => watcher.close();
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Delete every file written by a {@link createFileStorage} instance by removing
|
|
161
|
+
* its base directory. Exposed primarily for tests and cleanup tooling.
|
|
162
|
+
*/
|
|
163
|
+
async function clearFileStorage(options) {
|
|
164
|
+
await (0, node_fs_promises.rm)(options.dir, {
|
|
165
|
+
recursive: true,
|
|
166
|
+
force: true
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
exports.clearFileStorage = clearFileStorage;
|
|
171
|
+
exports.createFileStorage = createFileStorage;
|
|
172
|
+
exports.decodeSegment = decodeSegment;
|
|
173
|
+
exports.encodeSegment = encodeSegment;
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=entry-storage-file.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-storage-file.cjs","names":["sep"],"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,K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AAA,GAAA,QAAA,YAAY,IAAI,IAAI,WAAW;KAC1C;IAAI,CAAC;GACxB,CAAC;GACD,aAAa,QAAQ,MAAM;EAC7B;CACF;AACF;;;;;AAMA,eAAsB,iBAAiB,SAA4C;CACjF,OAAA,GAAA,iBAAA,IAAS,QAAQ,KAAK;EAAE,WAAW;EAAM,OAAO;CAAK,CAAC;AACxD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { s as WatchableAuditStorage } from "./contract-CWJSYoJl.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/storage/file.d.ts
|
|
4
|
+
/** Options for {@link createFileStorage}. */
|
|
5
|
+
interface FileStorageOptions {
|
|
6
|
+
/** Base directory under which key files are written. Created on demand. */
|
|
7
|
+
dir: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Encode one key segment as a file name that survives case-insensitive and
|
|
11
|
+
* normalization-insensitive filesystems (macOS, Windows) and never escapes its
|
|
12
|
+
* directory: uppercase letters become `^` + the lowercase letter, `^` becomes
|
|
13
|
+
* `^^`, bytes outside `[a-z0-9._~!@,=+-]` become `%XX`, and a leading `.` is
|
|
14
|
+
* `%2E` (so `.` / `..` / dotfiles cannot appear). Without it, tenants `Acme` and
|
|
15
|
+
* `acme` would share files on a default macOS volume.
|
|
16
|
+
*/
|
|
17
|
+
declare function encodeSegment(segment: string): string;
|
|
18
|
+
/** Reverse {@link encodeSegment}. */
|
|
19
|
+
declare function decodeSegment(name: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Create a file-backed {@link WatchableAuditStorage}. Values are serialized
|
|
22
|
+
* as pretty-printed JSON. `watch` is implemented via `fs.watch` on the base
|
|
23
|
+
* directory (recursive); it is best-effort and may coalesce or miss events on
|
|
24
|
+
* platforms without recursive-watch support.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { createFileStorage } from "@xtandard/audit/storage/file";
|
|
29
|
+
*
|
|
30
|
+
* const storage = createFileStorage({ dir: "./data/audit" });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function createFileStorage(options: FileStorageOptions): WatchableAuditStorage;
|
|
34
|
+
/**
|
|
35
|
+
* Delete every file written by a {@link createFileStorage} instance by removing
|
|
36
|
+
* its base directory. Exposed primarily for tests and cleanup tooling.
|
|
37
|
+
*/
|
|
38
|
+
declare function clearFileStorage(options: FileStorageOptions): Promise<void>;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { FileStorageOptions, clearFileStorage, createFileStorage, decodeSegment, encodeSegment };
|
|
41
|
+
//# sourceMappingURL=entry-storage-file.d.cts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { s as WatchableAuditStorage } from "./contract-BmwHIiMR.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/storage/file.d.ts
|
|
4
|
+
/** Options for {@link createFileStorage}. */
|
|
5
|
+
interface FileStorageOptions {
|
|
6
|
+
/** Base directory under which key files are written. Created on demand. */
|
|
7
|
+
dir: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Encode one key segment as a file name that survives case-insensitive and
|
|
11
|
+
* normalization-insensitive filesystems (macOS, Windows) and never escapes its
|
|
12
|
+
* directory: uppercase letters become `^` + the lowercase letter, `^` becomes
|
|
13
|
+
* `^^`, bytes outside `[a-z0-9._~!@,=+-]` become `%XX`, and a leading `.` is
|
|
14
|
+
* `%2E` (so `.` / `..` / dotfiles cannot appear). Without it, tenants `Acme` and
|
|
15
|
+
* `acme` would share files on a default macOS volume.
|
|
16
|
+
*/
|
|
17
|
+
declare function encodeSegment(segment: string): string;
|
|
18
|
+
/** Reverse {@link encodeSegment}. */
|
|
19
|
+
declare function decodeSegment(name: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Create a file-backed {@link WatchableAuditStorage}. Values are serialized
|
|
22
|
+
* as pretty-printed JSON. `watch` is implemented via `fs.watch` on the base
|
|
23
|
+
* directory (recursive); it is best-effort and may coalesce or miss events on
|
|
24
|
+
* platforms without recursive-watch support.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { createFileStorage } from "@xtandard/audit/storage/file";
|
|
29
|
+
*
|
|
30
|
+
* const storage = createFileStorage({ dir: "./data/audit" });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function createFileStorage(options: FileStorageOptions): WatchableAuditStorage;
|
|
34
|
+
/**
|
|
35
|
+
* Delete every file written by a {@link createFileStorage} instance by removing
|
|
36
|
+
* its base directory. Exposed primarily for tests and cleanup tooling.
|
|
37
|
+
*/
|
|
38
|
+
declare function clearFileStorage(options: FileStorageOptions): Promise<void>;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { FileStorageOptions, clearFileStorage, createFileStorage, decodeSegment, encodeSegment };
|
|
41
|
+
//# sourceMappingURL=entry-storage-file.d.mts.map
|