@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,29 @@
|
|
|
1
|
+
import { n as CreateFetchHandlerResult, t as AuditPanelOptions } from "./create-fetch-handler-zioPVS18.mjs";
|
|
2
|
+
import { t as AuditContextOptions } from "./context-shared-AgBWIRUQ.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/adapters/bun.d.ts
|
|
5
|
+
/** Create a Bun-ready panel handler (`fetch` + `core` + `streams` + `openapi`). */
|
|
6
|
+
declare function auditPanel(options: AuditPanelOptions): CreateFetchHandlerResult;
|
|
7
|
+
/** The subset of Bun's `Server` the context wrapper uses (for the socket IP). */
|
|
8
|
+
interface BunServerLike {
|
|
9
|
+
requestIP?(request: Request): {
|
|
10
|
+
address: string;
|
|
11
|
+
} | null;
|
|
12
|
+
}
|
|
13
|
+
/** A `Bun.serve` fetch handler. */
|
|
14
|
+
type BunFetch<S extends BunServerLike = BunServerLike> = (request: Request, server: S) => Response | Promise<Response>;
|
|
15
|
+
/**
|
|
16
|
+
* Wrap a `Bun.serve` fetch handler so each request runs inside an audit
|
|
17
|
+
* context scope (ADR 0013): `actor` / `tenant` / `context` resolve from the
|
|
18
|
+
* request, and IP / user agent / request id are captured (the socket IP via
|
|
19
|
+
* `server.requestIP` is the fallback when no trusted proxy header is set).
|
|
20
|
+
*/
|
|
21
|
+
declare function withAuditContext<S extends BunServerLike>(fetch: BunFetch<S>, options?: AuditContextOptions<Request>): BunFetch<S>;
|
|
22
|
+
/**
|
|
23
|
+
* `auditContext(options)` → a wrapper for a `Bun.serve` fetch handler; the
|
|
24
|
+
* curried form of {@link withAuditContext}, matching the other adapters' name.
|
|
25
|
+
*/
|
|
26
|
+
declare function auditContext(options?: AuditContextOptions<Request>): <S extends BunServerLike>(fetch: BunFetch<S>) => BunFetch<S>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { type AuditContextOptions, type AuditPanelOptions, BunFetch, BunServerLike, type CreateFetchHandlerResult, auditContext, auditPanel, withAuditContext };
|
|
29
|
+
//# sourceMappingURL=entry-bun.d.mts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { runWithAuditContext } from "./context.mjs";
|
|
2
|
+
import { t as createFetchHandler } from "./create-fetch-handler-BwQQ_IWf.mjs";
|
|
3
|
+
import { t as resolveAuditScope } from "./context-shared-CupikwQo.mjs";
|
|
4
|
+
//#region src/adapters/bun.ts
|
|
5
|
+
/**
|
|
6
|
+
* Bun adapter. The handler is already web-standard, so {@link auditPanel} is a
|
|
7
|
+
* passthrough you can hand straight to `Bun.serve({ fetch })`. The panel
|
|
8
|
+
* starts the stream runner when `streams` are declared; pass
|
|
9
|
+
* `streamRunner: false` for split deployments.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { auditPanel, withAuditContext } from "@xtandard/audit/bun";
|
|
13
|
+
* const panel = auditPanel({ storage, basePath: "/audit" });
|
|
14
|
+
*
|
|
15
|
+
* Bun.serve({
|
|
16
|
+
* port: 3000,
|
|
17
|
+
* // Every `audit.record()` inside `app` picks up the actor, tenant, IP, UA and request id.
|
|
18
|
+
* fetch: withAuditContext(app, {
|
|
19
|
+
* actor: async (req) => (await session(req))?.user,
|
|
20
|
+
* tenant: async (req) => (await session(req))?.orgId,
|
|
21
|
+
* }),
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/
|
|
27
|
+
/** Create a Bun-ready panel handler (`fetch` + `core` + `streams` + `openapi`). */
|
|
28
|
+
function auditPanel(options) {
|
|
29
|
+
return createFetchHandler(options);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Wrap a `Bun.serve` fetch handler so each request runs inside an audit
|
|
33
|
+
* context scope (ADR 0013): `actor` / `tenant` / `context` resolve from the
|
|
34
|
+
* request, and IP / user agent / request id are captured (the socket IP via
|
|
35
|
+
* `server.requestIP` is the fallback when no trusted proxy header is set).
|
|
36
|
+
*/
|
|
37
|
+
function withAuditContext(fetch, options = {}) {
|
|
38
|
+
return async (request, server) => {
|
|
39
|
+
return runWithAuditContext(await resolveAuditScope(request, request, options, server?.requestIP?.(request)?.address ?? null), () => fetch(request, server));
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* `auditContext(options)` → a wrapper for a `Bun.serve` fetch handler; the
|
|
44
|
+
* curried form of {@link withAuditContext}, matching the other adapters' name.
|
|
45
|
+
*/
|
|
46
|
+
function auditContext(options = {}) {
|
|
47
|
+
return (fetch) => withAuditContext(fetch, options);
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { auditContext, auditPanel, withAuditContext };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=entry-bun.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-bun.mjs","names":[],"sources":["../src/adapters/bun.ts"],"sourcesContent":["/**\n * Bun adapter. The handler is already web-standard, so {@link auditPanel} is a\n * passthrough you can hand straight to `Bun.serve({ fetch })`. The panel\n * starts the stream runner when `streams` are declared; pass\n * `streamRunner: false` for split deployments.\n *\n * ```ts\n * import { auditPanel, withAuditContext } from \"@xtandard/audit/bun\";\n * const panel = auditPanel({ storage, basePath: \"/audit\" });\n *\n * Bun.serve({\n * port: 3000,\n * // Every `audit.record()` inside `app` picks up the actor, tenant, IP, UA and request id.\n * fetch: withAuditContext(app, {\n * actor: async (req) => (await session(req))?.user,\n * tenant: async (req) => (await session(req))?.orgId,\n * }),\n * });\n * ```\n *\n * @module\n */\n\nimport { runWithAuditContext } from \"../context.ts\";\nimport {\n createFetchHandler,\n type CreateFetchHandlerResult,\n type AuditPanelOptions,\n} from \"../server/create-fetch-handler.ts\";\nimport { resolveAuditScope, type AuditContextOptions } from \"./context-shared.ts\";\n\n/** Create a Bun-ready panel handler (`fetch` + `core` + `streams` + `openapi`). */\nexport function auditPanel(options: AuditPanelOptions): CreateFetchHandlerResult {\n return createFetchHandler(options);\n}\n\n/** The subset of Bun's `Server` the context wrapper uses (for the socket IP). */\nexport interface BunServerLike {\n requestIP?(request: Request): { address: string } | null;\n}\n\n/** A `Bun.serve` fetch handler. */\nexport type BunFetch<S extends BunServerLike = BunServerLike> = (\n request: Request,\n server: S,\n) => Response | Promise<Response>;\n\n/**\n * Wrap a `Bun.serve` fetch handler so each request runs inside an audit\n * context scope (ADR 0013): `actor` / `tenant` / `context` resolve from the\n * request, and IP / user agent / request id are captured (the socket IP via\n * `server.requestIP` is the fallback when no trusted proxy header is set).\n */\nexport function withAuditContext<S extends BunServerLike>(\n fetch: BunFetch<S>,\n options: AuditContextOptions<Request> = {},\n): BunFetch<S> {\n return async (request, server) => {\n const ip = server?.requestIP?.(request)?.address ?? null;\n const scope = await resolveAuditScope(request, request, options, ip);\n return runWithAuditContext(scope, () => fetch(request, server));\n };\n}\n\n/**\n * `auditContext(options)` → a wrapper for a `Bun.serve` fetch handler; the\n * curried form of {@link withAuditContext}, matching the other adapters' name.\n */\nexport function auditContext(\n options: AuditContextOptions<Request> = {},\n): <S extends BunServerLike>(fetch: BunFetch<S>) => BunFetch<S> {\n return (fetch) => withAuditContext(fetch, options);\n}\n\nexport type { AuditContextOptions, AuditPanelOptions, CreateFetchHandlerResult };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,WAAW,SAAsD;CAC/E,OAAO,mBAAmB,OAAO;AACnC;;;;;;;AAmBA,SAAgB,iBACd,OACA,UAAwC,CAAC,GAC5B;CACb,OAAO,OAAO,SAAS,WAAW;EAGhC,OAAO,oBAAoB,MADP,kBAAkB,SAAS,SAAS,SAD7C,QAAQ,YAAY,OAAO,GAAG,WAAW,IACe,SAC3B,MAAM,SAAS,MAAM,CAAC;CAChE;AACF;;;;;AAMA,SAAgB,aACd,UAAwC,CAAC,GACqB;CAC9D,QAAQ,UAAU,iBAAiB,OAAO,OAAO;AACnD"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_validation = require("./validation-lb0YXrxx.cjs");
|
|
3
|
+
const require_context = require("./context.cjs");
|
|
4
|
+
//#region src/bridges/drizzle-audit.ts
|
|
5
|
+
/** Context keys lifted from `entry.metadata` into the event's `context`. */
|
|
6
|
+
const CONTEXT_KEYS = [
|
|
7
|
+
"ip",
|
|
8
|
+
"userAgent",
|
|
9
|
+
"requestId"
|
|
10
|
+
];
|
|
11
|
+
const CRUD = new Set([
|
|
12
|
+
"INSERT",
|
|
13
|
+
"UPDATE",
|
|
14
|
+
"DELETE"
|
|
15
|
+
]);
|
|
16
|
+
/** Make any value JSON-safe (Dates → ISO via `toJSON`, bigints → strings, `undefined` dropped). */
|
|
17
|
+
function toJson(value) {
|
|
18
|
+
if (value === null || value === void 0) return value;
|
|
19
|
+
return JSON.parse(JSON.stringify(value, (_k, v) => typeof v === "bigint" ? v.toString() : v));
|
|
20
|
+
}
|
|
21
|
+
/** A table name as an action segment: lower-cased, unsupported characters → `_`. */
|
|
22
|
+
function actionSegment(name) {
|
|
23
|
+
return name.toLowerCase().replace(/[^a-z0-9_-]+/g, "_");
|
|
24
|
+
}
|
|
25
|
+
/** The default action of an entry. */
|
|
26
|
+
function defaultDrizzleAuditAction(entry) {
|
|
27
|
+
if (entry.tableName !== null && CRUD.has(entry.action.toUpperCase())) return `db.${actionSegment(entry.tableName)}.${entry.action.toLowerCase()}`;
|
|
28
|
+
if (require_validation.ACTION_REGEX.test(entry.action)) return entry.action;
|
|
29
|
+
return entry.action.replace(/[^a-zA-Z0-9._:-]+/g, "_").replace(/^[^a-zA-Z0-9]+/, "") || "custom";
|
|
30
|
+
}
|
|
31
|
+
function entryTime(entry) {
|
|
32
|
+
const t = entry.timestamp instanceof Date ? entry.timestamp.getTime() : new Date(entry.timestamp).getTime();
|
|
33
|
+
if (Number.isNaN(t)) throw new TypeError(`drizzle-audit entry ${entry.id}: invalid timestamp`);
|
|
34
|
+
return t;
|
|
35
|
+
}
|
|
36
|
+
const CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
37
|
+
/**
|
|
38
|
+
* A deterministic, time-sortable event id for an entry: the entry timestamp
|
|
39
|
+
* (48 bits, like every `evt_` id) followed by 80 bits of SHA-256 over the
|
|
40
|
+
* entry's content (not `entry.id`, which stored rows do not keep) — so the same
|
|
41
|
+
* change always maps to the same event, live or imported.
|
|
42
|
+
*/
|
|
43
|
+
async function drizzleAuditEventId(entry) {
|
|
44
|
+
let ms = entryTime(entry);
|
|
45
|
+
let time = "";
|
|
46
|
+
for (let i = 0; i < 10; i++) {
|
|
47
|
+
time = CROCKFORD[ms % 32] + time;
|
|
48
|
+
ms = Math.floor(ms / 32);
|
|
49
|
+
}
|
|
50
|
+
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`drizzle-audit:${JSON.stringify([
|
|
51
|
+
entryTime(entry),
|
|
52
|
+
entry.tableName,
|
|
53
|
+
entry.action,
|
|
54
|
+
entry.rowId === null ? null : String(entry.rowId),
|
|
55
|
+
entry.userId,
|
|
56
|
+
toJson(entry.changes),
|
|
57
|
+
toJson(entry.oldData),
|
|
58
|
+
toJson(entry.newData),
|
|
59
|
+
toJson(entry.metadata)
|
|
60
|
+
])}`)));
|
|
61
|
+
let random = "";
|
|
62
|
+
for (let i = 0; i < 16; i++) random += CROCKFORD[digest[i] % 32];
|
|
63
|
+
return `evt_${time}${random}`;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Map one entry to a record input (exported for custom pipelines and tests).
|
|
67
|
+
* Returns `null` when `include` rejects the entry.
|
|
68
|
+
*/
|
|
69
|
+
async function drizzleAuditEntryToInput(entry, mapping) {
|
|
70
|
+
if (mapping.include && !mapping.include(entry)) return null;
|
|
71
|
+
const scope = require_context.getAuditContext();
|
|
72
|
+
const metaTenant = entry.metadata?.tenantId;
|
|
73
|
+
const tenant = (typeof mapping.tenant === "function" ? mapping.tenant(entry) : mapping.tenant) ?? entry.tenantId ?? (typeof metaTenant === "string" ? metaTenant : void 0) ?? scope?.tenant;
|
|
74
|
+
if (!tenant) throw new TypeError(`drizzle-audit entry ${entry.id}: no tenant (set the bridge's tenant option or an audit context)`);
|
|
75
|
+
const actor = mapping.actor ? mapping.actor(entry) : entry.userId ? {
|
|
76
|
+
id: entry.userId,
|
|
77
|
+
type: "user"
|
|
78
|
+
} : scope?.actor ?? {
|
|
79
|
+
id: "system",
|
|
80
|
+
type: "system"
|
|
81
|
+
};
|
|
82
|
+
const targets = mapping.targets ? mapping.targets(entry) : entry.tableName !== null && entry.rowId !== null ? [{
|
|
83
|
+
type: entry.tableName,
|
|
84
|
+
id: String(entry.rowId)
|
|
85
|
+
}] : [];
|
|
86
|
+
const context = {};
|
|
87
|
+
const extra = {};
|
|
88
|
+
for (const [key, value] of Object.entries(toJson(entry.metadata) ?? {})) if (CONTEXT_KEYS.includes(key) && typeof value === "string") context[key] = value;
|
|
89
|
+
else if (value !== void 0) extra[key] = value;
|
|
90
|
+
const metadata = {
|
|
91
|
+
changes: toJson(entry.changes),
|
|
92
|
+
oldData: toJson(entry.oldData),
|
|
93
|
+
newData: toJson(entry.newData),
|
|
94
|
+
...Object.keys(extra).length > 0 ? { extra } : {}
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
id: await drizzleAuditEventId(entry),
|
|
98
|
+
tenant,
|
|
99
|
+
action: (mapping.action ?? defaultDrizzleAuditAction)(entry),
|
|
100
|
+
occurredAt: new Date(entryTime(entry)).toISOString(),
|
|
101
|
+
actor,
|
|
102
|
+
targets,
|
|
103
|
+
context,
|
|
104
|
+
metadata
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Create a drizzle-audit `AuditStorage` that records into an audit core.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* import { withDrizzleAudit } from "drizzle-audit";
|
|
113
|
+
* import { createDrizzleAuditStorage } from "@xtandard/audit/drizzle-audit";
|
|
114
|
+
*
|
|
115
|
+
* const db = withDrizzleAudit(rawDb, {
|
|
116
|
+
* storage: createDrizzleAuditStorage(audit, {
|
|
117
|
+
* // tenant from drizzle-audit's context metadata
|
|
118
|
+
* tenant: (entry) => entry.metadata?.tenantId as string,
|
|
119
|
+
* }),
|
|
120
|
+
* onError: "throw", // the DB write fails if the audit event cannot be recorded
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
function createDrizzleAuditStorage(core, options) {
|
|
125
|
+
return {
|
|
126
|
+
async write(entries) {
|
|
127
|
+
const inputs = [];
|
|
128
|
+
for (const entry of entries) {
|
|
129
|
+
const input = await drizzleAuditEntryToInput(entry, options);
|
|
130
|
+
if (input) inputs.push(input);
|
|
131
|
+
}
|
|
132
|
+
if (inputs.length === 0) return;
|
|
133
|
+
if (options.recorder) {
|
|
134
|
+
for (const input of inputs) options.recorder.record(input);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
await core.recordMany(inputs);
|
|
138
|
+
},
|
|
139
|
+
async flush() {
|
|
140
|
+
await options.recorder?.flush();
|
|
141
|
+
},
|
|
142
|
+
async close() {
|
|
143
|
+
await options.recorder?.flush();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Import historical drizzle-audit rows (migration, ADR 0009 §4). Rows are
|
|
149
|
+
* sorted by timestamp (then id) and chained in that order with `occurredAt`
|
|
150
|
+
* = the entry timestamp. Re-running an import is a no-op for rows already
|
|
151
|
+
* imported (deterministic event ids). Resolves to the recorded events.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* import { importDrizzleAuditEntries } from "@xtandard/audit/drizzle-audit";
|
|
156
|
+
*
|
|
157
|
+
* const rows = await db.select().from(auditLog);
|
|
158
|
+
* await importDrizzleAuditEntries(audit, rows, {
|
|
159
|
+
* tenant: (row) => (row.metadata?.tenantId as string) ?? "legacy",
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
async function importDrizzleAuditEntries(core, rows, mapping) {
|
|
164
|
+
const batchSize = mapping.batchSize ?? 500;
|
|
165
|
+
const sorted = [...rows].sort((a, b) => {
|
|
166
|
+
const d = entryTime(a) - entryTime(b);
|
|
167
|
+
if (d !== 0) return d;
|
|
168
|
+
const ai = String(a.id);
|
|
169
|
+
const bi = String(b.id);
|
|
170
|
+
return ai < bi ? -1 : ai > bi ? 1 : 0;
|
|
171
|
+
});
|
|
172
|
+
const inputs = [];
|
|
173
|
+
for (const row of sorted) {
|
|
174
|
+
const input = await drizzleAuditEntryToInput(row, mapping);
|
|
175
|
+
if (input) inputs.push(input);
|
|
176
|
+
}
|
|
177
|
+
const out = [];
|
|
178
|
+
for (let i = 0; i < inputs.length; i += batchSize) {
|
|
179
|
+
out.push(...await core.recordMany(inputs.slice(i, i + batchSize)));
|
|
180
|
+
mapping.onProgress?.(out.length, inputs.length);
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
exports.createDrizzleAuditStorage = createDrizzleAuditStorage;
|
|
186
|
+
exports.defaultDrizzleAuditAction = defaultDrizzleAuditAction;
|
|
187
|
+
exports.drizzleAuditEntryToInput = drizzleAuditEntryToInput;
|
|
188
|
+
exports.drizzleAuditEventId = drizzleAuditEventId;
|
|
189
|
+
exports.importDrizzleAuditEntries = importDrizzleAuditEntries;
|
|
190
|
+
|
|
191
|
+
//# sourceMappingURL=entry-drizzle-audit.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-drizzle-audit.cjs","names":["ACTION_REGEX","getAuditContext"],"sources":["../src/bridges/drizzle-audit.ts"],"sourcesContent":["/**\n * The `drizzle-audit` bridge (ADR 0009): `drizzle-audit` captures row-level\n * database changes; this turns them into tenant-scoped, hash-chained audit\n * events.\n *\n * - {@link createDrizzleAuditStorage} returns an object that structurally\n * satisfies drizzle-audit's `AuditStorage` (`write`, `flush`, `close`) — pass\n * it as `withDrizzleAudit(db, { storage })`.\n * - {@link importDrizzleAuditEntries} imports historical rows (e.g. from a\n * `drizzleTableStorage` table) in timestamp order.\n *\n * Mapping (overridable): `action` = `db.<table>.<insert|update|delete>`\n * (lower-cased; custom actions such as `trackAction` keep their name),\n * `targets` = `[{ type: table, id: rowId }]`, `actor.id` = `userId`,\n * `metadata` = `{ changes, oldData, newData }` (+ `extra` for\n * the context metadata that is not `ip` / `userAgent` / `requestId`), and\n * `context` = `{ ip, userAgent, requestId }` from the entry's metadata.\n *\n * The tenant is the bridge's `tenant` option when given, else drizzle-audit's\n * `entry.tenantId` (newer releases), else `entry.metadata.tenantId` (0.1.x\n * convention), else the ambient audit context's tenant.\n *\n * Each event id is derived from the entry's **content** (timestamp, table,\n * action, row id, user, changes, old/new data, metadata) — not from `entry.id`, which\n * `drizzleTableStorage` does not persist (stored rows get a fresh id). So the\n * same change forwarded live and later imported from the table maps to the same\n * event, and re-writing or re-importing is a no-op, as long as the database\n * keeps the timestamp's millisecond precision.\n *\n * Typed structurally — **no dependency** on `drizzle-audit` in either direction.\n *\n * @module\n */\n\nimport type { AuditCore, RecordInput } from \"../core.ts\";\nimport { getAuditContext } from \"../context.ts\";\nimport type { Recorder } from \"../recorder.ts\";\nimport type { AuditActor, AuditContext, AuditEvent, AuditTarget, JsonObject } from \"../schema.ts\";\nimport type { ActionMap } from \"../standard-schema.ts\";\nimport { ACTION_REGEX } from \"../validation.ts\";\n\n/**\n * drizzle-audit's `AuditEntry`, structurally. `timestamp` also accepts a\n * string/number so rows read back from any driver can be imported.\n */\nexport interface DrizzleAuditEntry {\n id: string | number;\n tableName: string | null;\n action: string;\n rowId: string | null;\n changes: Record<string, unknown> | null;\n oldData: Record<string, unknown> | null;\n newData: Record<string, unknown> | null;\n timestamp: Date | string | number;\n userId: string | null;\n metadata: Record<string, unknown> | null;\n /** The entry's tenant (drizzle-audit releases after 0.1.13). */\n tenantId?: string | null;\n}\n\n/** drizzle-audit's `AuditStorage`, structurally. */\nexport interface DrizzleAuditStorageLike {\n write(entries: DrizzleAuditEntry[]): Promise<void>;\n flush(): Promise<void>;\n close(): Promise<void>;\n}\n\n/** How a drizzle-audit entry maps to an audit event. */\nexport interface DrizzleAuditMapping {\n /**\n * The tenant of an entry: a fixed key, or a function. Return `null` /\n * `undefined` (or omit the option) to fall back to `entry.tenantId`, then\n * `entry.metadata.tenantId`, then the ambient audit context's tenant;\n * entries with no tenant at all throw.\n */\n tenant?: string | ((entry: DrizzleAuditEntry) => string | null | undefined);\n /** Override the action name. Default: see the module docs. */\n action?: (entry: DrizzleAuditEntry) => string;\n /**\n * Override the actor. Default: `{ id: userId, type: \"user\" }`, else the\n * ambient context's actor, else `{ id: \"system\", type: \"system\" }`.\n */\n actor?: (entry: DrizzleAuditEntry) => AuditActor;\n /** Override the targets. Default: `[{ type: tableName, id: rowId }]` (none without both). */\n targets?: (entry: DrizzleAuditEntry) => AuditTarget[];\n /** Only forward entries for which this returns `true` (default: all). */\n include?: (entry: DrizzleAuditEntry) => boolean;\n}\n\n/** Options for {@link createDrizzleAuditStorage}. */\nexport interface DrizzleAuditStorageOptions extends DrizzleAuditMapping {\n /**\n * Send through a buffered recorder instead of `core.recordMany` (ADR 0002):\n * `write` returns immediately and `flush` / `close` drain the recorder.\n * Default: synchronous commit, so drizzle-audit's `onError` sees failures.\n */\n recorder?: Recorder;\n}\n\n/** Context keys lifted from `entry.metadata` into the event's `context`. */\nconst CONTEXT_KEYS = [\"ip\", \"userAgent\", \"requestId\"] as const;\nconst CRUD = new Set([\"INSERT\", \"UPDATE\", \"DELETE\"]);\n\n/** Make any value JSON-safe (Dates → ISO via `toJSON`, bigints → strings, `undefined` dropped). */\nfunction toJson<T>(value: T): T {\n if (value === null || value === undefined) return value;\n return JSON.parse(\n JSON.stringify(value, (_k, v: unknown) => (typeof v === \"bigint\" ? v.toString() : v)),\n ) as T;\n}\n\n/** A table name as an action segment: lower-cased, unsupported characters → `_`. */\nfunction actionSegment(name: string): string {\n return name.toLowerCase().replace(/[^a-z0-9_-]+/g, \"_\");\n}\n\n/** The default action of an entry. */\nexport function defaultDrizzleAuditAction(entry: DrizzleAuditEntry): string {\n if (entry.tableName !== null && CRUD.has(entry.action.toUpperCase())) {\n return `db.${actionSegment(entry.tableName)}.${entry.action.toLowerCase()}`;\n }\n if (ACTION_REGEX.test(entry.action)) return entry.action;\n return entry.action.replace(/[^a-zA-Z0-9._:-]+/g, \"_\").replace(/^[^a-zA-Z0-9]+/, \"\") || \"custom\";\n}\n\nfunction entryTime(entry: DrizzleAuditEntry): number {\n const t =\n entry.timestamp instanceof Date\n ? entry.timestamp.getTime()\n : new Date(entry.timestamp).getTime();\n if (Number.isNaN(t)) throw new TypeError(`drizzle-audit entry ${entry.id}: invalid timestamp`);\n return t;\n}\n\nconst CROCKFORD = \"0123456789ABCDEFGHJKMNPQRSTVWXYZ\";\n\n/**\n * A deterministic, time-sortable event id for an entry: the entry timestamp\n * (48 bits, like every `evt_` id) followed by 80 bits of SHA-256 over the\n * entry's content (not `entry.id`, which stored rows do not keep) — so the same\n * change always maps to the same event, live or imported.\n */\nexport async function drizzleAuditEventId(entry: DrizzleAuditEntry): Promise<string> {\n let ms = entryTime(entry);\n let time = \"\";\n for (let i = 0; i < 10; i++) {\n time = CROCKFORD[ms % 32] + time;\n ms = Math.floor(ms / 32);\n }\n const digest = new Uint8Array(\n await crypto.subtle.digest(\n \"SHA-256\",\n new TextEncoder().encode(\n `drizzle-audit:${JSON.stringify([\n entryTime(entry),\n entry.tableName,\n entry.action,\n entry.rowId === null ? null : String(entry.rowId),\n entry.userId,\n toJson(entry.changes),\n toJson(entry.oldData),\n toJson(entry.newData),\n toJson(entry.metadata),\n ])}`,\n ),\n ),\n );\n let random = \"\";\n for (let i = 0; i < 16; i++) random += CROCKFORD[digest[i]! % 32];\n return `evt_${time}${random}`;\n}\n\n/**\n * Map one entry to a record input (exported for custom pipelines and tests).\n * Returns `null` when `include` rejects the entry.\n */\nexport async function drizzleAuditEntryToInput(\n entry: DrizzleAuditEntry,\n mapping: DrizzleAuditMapping,\n): Promise<RecordInput | null> {\n if (mapping.include && !mapping.include(entry)) return null;\n const scope = getAuditContext();\n const metaTenant = entry.metadata?.tenantId;\n const tenant =\n (typeof mapping.tenant === \"function\" ? mapping.tenant(entry) : mapping.tenant) ??\n entry.tenantId ??\n (typeof metaTenant === \"string\" ? metaTenant : undefined) ??\n scope?.tenant;\n if (!tenant) {\n throw new TypeError(\n `drizzle-audit entry ${entry.id}: no tenant (set the bridge's tenant option or an audit context)`,\n );\n }\n const actor: AuditActor = mapping.actor\n ? mapping.actor(entry)\n : entry.userId\n ? { id: entry.userId, type: \"user\" }\n : (scope?.actor ?? { id: \"system\", type: \"system\" });\n const targets: AuditTarget[] = mapping.targets\n ? mapping.targets(entry)\n : entry.tableName !== null && entry.rowId !== null\n ? [{ type: entry.tableName, id: String(entry.rowId) }]\n : [];\n\n const context: AuditContext = {};\n const extra: JsonObject = {};\n for (const [key, value] of Object.entries(toJson(entry.metadata) ?? {})) {\n if ((CONTEXT_KEYS as readonly string[]).includes(key) && typeof value === \"string\") {\n context[key] = value;\n } else if (value !== undefined) {\n extra[key] = value as JsonObject[string];\n }\n }\n const metadata: JsonObject = {\n changes: toJson(entry.changes) as JsonObject | null,\n oldData: toJson(entry.oldData) as JsonObject | null,\n newData: toJson(entry.newData) as JsonObject | null,\n ...(Object.keys(extra).length > 0 ? { extra } : {}),\n };\n\n return {\n id: await drizzleAuditEventId(entry),\n tenant,\n action: (mapping.action ?? defaultDrizzleAuditAction)(entry),\n occurredAt: new Date(entryTime(entry)).toISOString(),\n actor,\n targets,\n context,\n metadata,\n };\n}\n\n/**\n * Create a drizzle-audit `AuditStorage` that records into an audit core.\n *\n * @example\n * ```ts\n * import { withDrizzleAudit } from \"drizzle-audit\";\n * import { createDrizzleAuditStorage } from \"@xtandard/audit/drizzle-audit\";\n *\n * const db = withDrizzleAudit(rawDb, {\n * storage: createDrizzleAuditStorage(audit, {\n * // tenant from drizzle-audit's context metadata\n * tenant: (entry) => entry.metadata?.tenantId as string,\n * }),\n * onError: \"throw\", // the DB write fails if the audit event cannot be recorded\n * });\n * ```\n */\nexport function createDrizzleAuditStorage<A extends ActionMap>(\n core: AuditCore<A>,\n options: DrizzleAuditStorageOptions,\n): DrizzleAuditStorageLike {\n return {\n async write(entries) {\n const inputs: RecordInput[] = [];\n for (const entry of entries) {\n const input = await drizzleAuditEntryToInput(entry, options);\n if (input) inputs.push(input);\n }\n if (inputs.length === 0) return;\n if (options.recorder) {\n for (const input of inputs) options.recorder.record(input);\n return;\n }\n await core.recordMany(inputs as RecordInput<A>[]);\n },\n async flush() {\n await options.recorder?.flush();\n },\n async close() {\n await options.recorder?.flush();\n },\n };\n}\n\n/** Options for {@link importDrizzleAuditEntries}. */\nexport interface ImportDrizzleAuditOptions extends DrizzleAuditMapping {\n /** Events per `recordMany` call. Default 500. */\n batchSize?: number;\n /** Progress callback after each committed batch. */\n onProgress?: (imported: number, total: number) => void;\n}\n\n/**\n * Import historical drizzle-audit rows (migration, ADR 0009 §4). Rows are\n * sorted by timestamp (then id) and chained in that order with `occurredAt`\n * = the entry timestamp. Re-running an import is a no-op for rows already\n * imported (deterministic event ids). Resolves to the recorded events.\n *\n * @example\n * ```ts\n * import { importDrizzleAuditEntries } from \"@xtandard/audit/drizzle-audit\";\n *\n * const rows = await db.select().from(auditLog);\n * await importDrizzleAuditEntries(audit, rows, {\n * tenant: (row) => (row.metadata?.tenantId as string) ?? \"legacy\",\n * });\n * ```\n */\nexport async function importDrizzleAuditEntries<A extends ActionMap>(\n core: AuditCore<A>,\n rows: Iterable<DrizzleAuditEntry>,\n mapping: ImportDrizzleAuditOptions,\n): Promise<AuditEvent[]> {\n const batchSize = mapping.batchSize ?? 500;\n const sorted = [...rows].sort((a, b) => {\n const d = entryTime(a) - entryTime(b);\n if (d !== 0) return d;\n const ai = String(a.id);\n const bi = String(b.id);\n return ai < bi ? -1 : ai > bi ? 1 : 0;\n });\n const inputs: RecordInput[] = [];\n for (const row of sorted) {\n const input = await drizzleAuditEntryToInput(row, mapping);\n if (input) inputs.push(input);\n }\n const out: AuditEvent[] = [];\n for (let i = 0; i < inputs.length; i += batchSize) {\n out.push(...(await core.recordMany(inputs.slice(i, i + batchSize) as RecordInput<A>[])));\n mapping.onProgress?.(out.length, inputs.length);\n }\n return out;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { m as AuditTarget, r as AuditActor, s as AuditEvent } from "./schema-DmU7Wp0F.cjs";
|
|
2
|
+
import { E as ActionMap, n as AuditCore, u as RecordInput } from "./core-C0ceVOTk.cjs";
|
|
3
|
+
import { t as Recorder } from "./recorder-CGY7HK29.cjs";
|
|
4
|
+
|
|
5
|
+
//#region src/bridges/drizzle-audit.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* drizzle-audit's `AuditEntry`, structurally. `timestamp` also accepts a
|
|
8
|
+
* string/number so rows read back from any driver can be imported.
|
|
9
|
+
*/
|
|
10
|
+
interface DrizzleAuditEntry {
|
|
11
|
+
id: string | number;
|
|
12
|
+
tableName: string | null;
|
|
13
|
+
action: string;
|
|
14
|
+
rowId: string | null;
|
|
15
|
+
changes: Record<string, unknown> | null;
|
|
16
|
+
oldData: Record<string, unknown> | null;
|
|
17
|
+
newData: Record<string, unknown> | null;
|
|
18
|
+
timestamp: Date | string | number;
|
|
19
|
+
userId: string | null;
|
|
20
|
+
metadata: Record<string, unknown> | null;
|
|
21
|
+
/** The entry's tenant (drizzle-audit releases after 0.1.13). */
|
|
22
|
+
tenantId?: string | null;
|
|
23
|
+
}
|
|
24
|
+
/** drizzle-audit's `AuditStorage`, structurally. */
|
|
25
|
+
interface DrizzleAuditStorageLike {
|
|
26
|
+
write(entries: DrizzleAuditEntry[]): Promise<void>;
|
|
27
|
+
flush(): Promise<void>;
|
|
28
|
+
close(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/** How a drizzle-audit entry maps to an audit event. */
|
|
31
|
+
interface DrizzleAuditMapping {
|
|
32
|
+
/**
|
|
33
|
+
* The tenant of an entry: a fixed key, or a function. Return `null` /
|
|
34
|
+
* `undefined` (or omit the option) to fall back to `entry.tenantId`, then
|
|
35
|
+
* `entry.metadata.tenantId`, then the ambient audit context's tenant;
|
|
36
|
+
* entries with no tenant at all throw.
|
|
37
|
+
*/
|
|
38
|
+
tenant?: string | ((entry: DrizzleAuditEntry) => string | null | undefined);
|
|
39
|
+
/** Override the action name. Default: see the module docs. */
|
|
40
|
+
action?: (entry: DrizzleAuditEntry) => string;
|
|
41
|
+
/**
|
|
42
|
+
* Override the actor. Default: `{ id: userId, type: "user" }`, else the
|
|
43
|
+
* ambient context's actor, else `{ id: "system", type: "system" }`.
|
|
44
|
+
*/
|
|
45
|
+
actor?: (entry: DrizzleAuditEntry) => AuditActor;
|
|
46
|
+
/** Override the targets. Default: `[{ type: tableName, id: rowId }]` (none without both). */
|
|
47
|
+
targets?: (entry: DrizzleAuditEntry) => AuditTarget[];
|
|
48
|
+
/** Only forward entries for which this returns `true` (default: all). */
|
|
49
|
+
include?: (entry: DrizzleAuditEntry) => boolean;
|
|
50
|
+
}
|
|
51
|
+
/** Options for {@link createDrizzleAuditStorage}. */
|
|
52
|
+
interface DrizzleAuditStorageOptions extends DrizzleAuditMapping {
|
|
53
|
+
/**
|
|
54
|
+
* Send through a buffered recorder instead of `core.recordMany` (ADR 0002):
|
|
55
|
+
* `write` returns immediately and `flush` / `close` drain the recorder.
|
|
56
|
+
* Default: synchronous commit, so drizzle-audit's `onError` sees failures.
|
|
57
|
+
*/
|
|
58
|
+
recorder?: Recorder;
|
|
59
|
+
}
|
|
60
|
+
/** The default action of an entry. */
|
|
61
|
+
declare function defaultDrizzleAuditAction(entry: DrizzleAuditEntry): string;
|
|
62
|
+
/**
|
|
63
|
+
* A deterministic, time-sortable event id for an entry: the entry timestamp
|
|
64
|
+
* (48 bits, like every `evt_` id) followed by 80 bits of SHA-256 over the
|
|
65
|
+
* entry's content (not `entry.id`, which stored rows do not keep) — so the same
|
|
66
|
+
* change always maps to the same event, live or imported.
|
|
67
|
+
*/
|
|
68
|
+
declare function drizzleAuditEventId(entry: DrizzleAuditEntry): Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Map one entry to a record input (exported for custom pipelines and tests).
|
|
71
|
+
* Returns `null` when `include` rejects the entry.
|
|
72
|
+
*/
|
|
73
|
+
declare function drizzleAuditEntryToInput(entry: DrizzleAuditEntry, mapping: DrizzleAuditMapping): Promise<RecordInput | null>;
|
|
74
|
+
/**
|
|
75
|
+
* Create a drizzle-audit `AuditStorage` that records into an audit core.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { withDrizzleAudit } from "drizzle-audit";
|
|
80
|
+
* import { createDrizzleAuditStorage } from "@xtandard/audit/drizzle-audit";
|
|
81
|
+
*
|
|
82
|
+
* const db = withDrizzleAudit(rawDb, {
|
|
83
|
+
* storage: createDrizzleAuditStorage(audit, {
|
|
84
|
+
* // tenant from drizzle-audit's context metadata
|
|
85
|
+
* tenant: (entry) => entry.metadata?.tenantId as string,
|
|
86
|
+
* }),
|
|
87
|
+
* onError: "throw", // the DB write fails if the audit event cannot be recorded
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
declare function createDrizzleAuditStorage<A extends ActionMap>(core: AuditCore<A>, options: DrizzleAuditStorageOptions): DrizzleAuditStorageLike;
|
|
92
|
+
/** Options for {@link importDrizzleAuditEntries}. */
|
|
93
|
+
interface ImportDrizzleAuditOptions extends DrizzleAuditMapping {
|
|
94
|
+
/** Events per `recordMany` call. Default 500. */
|
|
95
|
+
batchSize?: number;
|
|
96
|
+
/** Progress callback after each committed batch. */
|
|
97
|
+
onProgress?: (imported: number, total: number) => void;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Import historical drizzle-audit rows (migration, ADR 0009 §4). Rows are
|
|
101
|
+
* sorted by timestamp (then id) and chained in that order with `occurredAt`
|
|
102
|
+
* = the entry timestamp. Re-running an import is a no-op for rows already
|
|
103
|
+
* imported (deterministic event ids). Resolves to the recorded events.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { importDrizzleAuditEntries } from "@xtandard/audit/drizzle-audit";
|
|
108
|
+
*
|
|
109
|
+
* const rows = await db.select().from(auditLog);
|
|
110
|
+
* await importDrizzleAuditEntries(audit, rows, {
|
|
111
|
+
* tenant: (row) => (row.metadata?.tenantId as string) ?? "legacy",
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
declare function importDrizzleAuditEntries<A extends ActionMap>(core: AuditCore<A>, rows: Iterable<DrizzleAuditEntry>, mapping: ImportDrizzleAuditOptions): Promise<AuditEvent[]>;
|
|
116
|
+
//#endregion
|
|
117
|
+
export { DrizzleAuditEntry, DrizzleAuditMapping, DrizzleAuditStorageLike, DrizzleAuditStorageOptions, ImportDrizzleAuditOptions, createDrizzleAuditStorage, defaultDrizzleAuditAction, drizzleAuditEntryToInput, drizzleAuditEventId, importDrizzleAuditEntries };
|
|
118
|
+
//# sourceMappingURL=entry-drizzle-audit.d.cts.map
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { m as AuditTarget, r as AuditActor, s as AuditEvent } from "./schema-DmU7Wp0F.mjs";
|
|
2
|
+
import { E as ActionMap, n as AuditCore, u as RecordInput } from "./core-KtEHRScZ.mjs";
|
|
3
|
+
import { t as Recorder } from "./recorder-B3dG3jbd.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/bridges/drizzle-audit.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* drizzle-audit's `AuditEntry`, structurally. `timestamp` also accepts a
|
|
8
|
+
* string/number so rows read back from any driver can be imported.
|
|
9
|
+
*/
|
|
10
|
+
interface DrizzleAuditEntry {
|
|
11
|
+
id: string | number;
|
|
12
|
+
tableName: string | null;
|
|
13
|
+
action: string;
|
|
14
|
+
rowId: string | null;
|
|
15
|
+
changes: Record<string, unknown> | null;
|
|
16
|
+
oldData: Record<string, unknown> | null;
|
|
17
|
+
newData: Record<string, unknown> | null;
|
|
18
|
+
timestamp: Date | string | number;
|
|
19
|
+
userId: string | null;
|
|
20
|
+
metadata: Record<string, unknown> | null;
|
|
21
|
+
/** The entry's tenant (drizzle-audit releases after 0.1.13). */
|
|
22
|
+
tenantId?: string | null;
|
|
23
|
+
}
|
|
24
|
+
/** drizzle-audit's `AuditStorage`, structurally. */
|
|
25
|
+
interface DrizzleAuditStorageLike {
|
|
26
|
+
write(entries: DrizzleAuditEntry[]): Promise<void>;
|
|
27
|
+
flush(): Promise<void>;
|
|
28
|
+
close(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/** How a drizzle-audit entry maps to an audit event. */
|
|
31
|
+
interface DrizzleAuditMapping {
|
|
32
|
+
/**
|
|
33
|
+
* The tenant of an entry: a fixed key, or a function. Return `null` /
|
|
34
|
+
* `undefined` (or omit the option) to fall back to `entry.tenantId`, then
|
|
35
|
+
* `entry.metadata.tenantId`, then the ambient audit context's tenant;
|
|
36
|
+
* entries with no tenant at all throw.
|
|
37
|
+
*/
|
|
38
|
+
tenant?: string | ((entry: DrizzleAuditEntry) => string | null | undefined);
|
|
39
|
+
/** Override the action name. Default: see the module docs. */
|
|
40
|
+
action?: (entry: DrizzleAuditEntry) => string;
|
|
41
|
+
/**
|
|
42
|
+
* Override the actor. Default: `{ id: userId, type: "user" }`, else the
|
|
43
|
+
* ambient context's actor, else `{ id: "system", type: "system" }`.
|
|
44
|
+
*/
|
|
45
|
+
actor?: (entry: DrizzleAuditEntry) => AuditActor;
|
|
46
|
+
/** Override the targets. Default: `[{ type: tableName, id: rowId }]` (none without both). */
|
|
47
|
+
targets?: (entry: DrizzleAuditEntry) => AuditTarget[];
|
|
48
|
+
/** Only forward entries for which this returns `true` (default: all). */
|
|
49
|
+
include?: (entry: DrizzleAuditEntry) => boolean;
|
|
50
|
+
}
|
|
51
|
+
/** Options for {@link createDrizzleAuditStorage}. */
|
|
52
|
+
interface DrizzleAuditStorageOptions extends DrizzleAuditMapping {
|
|
53
|
+
/**
|
|
54
|
+
* Send through a buffered recorder instead of `core.recordMany` (ADR 0002):
|
|
55
|
+
* `write` returns immediately and `flush` / `close` drain the recorder.
|
|
56
|
+
* Default: synchronous commit, so drizzle-audit's `onError` sees failures.
|
|
57
|
+
*/
|
|
58
|
+
recorder?: Recorder;
|
|
59
|
+
}
|
|
60
|
+
/** The default action of an entry. */
|
|
61
|
+
declare function defaultDrizzleAuditAction(entry: DrizzleAuditEntry): string;
|
|
62
|
+
/**
|
|
63
|
+
* A deterministic, time-sortable event id for an entry: the entry timestamp
|
|
64
|
+
* (48 bits, like every `evt_` id) followed by 80 bits of SHA-256 over the
|
|
65
|
+
* entry's content (not `entry.id`, which stored rows do not keep) — so the same
|
|
66
|
+
* change always maps to the same event, live or imported.
|
|
67
|
+
*/
|
|
68
|
+
declare function drizzleAuditEventId(entry: DrizzleAuditEntry): Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Map one entry to a record input (exported for custom pipelines and tests).
|
|
71
|
+
* Returns `null` when `include` rejects the entry.
|
|
72
|
+
*/
|
|
73
|
+
declare function drizzleAuditEntryToInput(entry: DrizzleAuditEntry, mapping: DrizzleAuditMapping): Promise<RecordInput | null>;
|
|
74
|
+
/**
|
|
75
|
+
* Create a drizzle-audit `AuditStorage` that records into an audit core.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { withDrizzleAudit } from "drizzle-audit";
|
|
80
|
+
* import { createDrizzleAuditStorage } from "@xtandard/audit/drizzle-audit";
|
|
81
|
+
*
|
|
82
|
+
* const db = withDrizzleAudit(rawDb, {
|
|
83
|
+
* storage: createDrizzleAuditStorage(audit, {
|
|
84
|
+
* // tenant from drizzle-audit's context metadata
|
|
85
|
+
* tenant: (entry) => entry.metadata?.tenantId as string,
|
|
86
|
+
* }),
|
|
87
|
+
* onError: "throw", // the DB write fails if the audit event cannot be recorded
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
declare function createDrizzleAuditStorage<A extends ActionMap>(core: AuditCore<A>, options: DrizzleAuditStorageOptions): DrizzleAuditStorageLike;
|
|
92
|
+
/** Options for {@link importDrizzleAuditEntries}. */
|
|
93
|
+
interface ImportDrizzleAuditOptions extends DrizzleAuditMapping {
|
|
94
|
+
/** Events per `recordMany` call. Default 500. */
|
|
95
|
+
batchSize?: number;
|
|
96
|
+
/** Progress callback after each committed batch. */
|
|
97
|
+
onProgress?: (imported: number, total: number) => void;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Import historical drizzle-audit rows (migration, ADR 0009 §4). Rows are
|
|
101
|
+
* sorted by timestamp (then id) and chained in that order with `occurredAt`
|
|
102
|
+
* = the entry timestamp. Re-running an import is a no-op for rows already
|
|
103
|
+
* imported (deterministic event ids). Resolves to the recorded events.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { importDrizzleAuditEntries } from "@xtandard/audit/drizzle-audit";
|
|
108
|
+
*
|
|
109
|
+
* const rows = await db.select().from(auditLog);
|
|
110
|
+
* await importDrizzleAuditEntries(audit, rows, {
|
|
111
|
+
* tenant: (row) => (row.metadata?.tenantId as string) ?? "legacy",
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
declare function importDrizzleAuditEntries<A extends ActionMap>(core: AuditCore<A>, rows: Iterable<DrizzleAuditEntry>, mapping: ImportDrizzleAuditOptions): Promise<AuditEvent[]>;
|
|
116
|
+
//#endregion
|
|
117
|
+
export { DrizzleAuditEntry, DrizzleAuditMapping, DrizzleAuditStorageLike, DrizzleAuditStorageOptions, ImportDrizzleAuditOptions, createDrizzleAuditStorage, defaultDrizzleAuditAction, drizzleAuditEntryToInput, drizzleAuditEventId, importDrizzleAuditEntries };
|
|
118
|
+
//# sourceMappingURL=entry-drizzle-audit.d.mts.map
|