silgi 0.43.28 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -1
- package/dist/_virtual/_rolldown/runtime.mjs +5 -0
- package/dist/adapters/_fetch-adapter.d.mts +18 -0
- package/dist/adapters/_fetch-adapter.mjs +53 -0
- package/dist/adapters/astro.d.mts +15 -0
- package/dist/adapters/astro.mjs +31 -0
- package/dist/adapters/aws-lambda.d.mts +42 -0
- package/dist/adapters/aws-lambda.mjs +92 -0
- package/dist/adapters/express.d.mts +16 -0
- package/dist/adapters/express.mjs +110 -0
- package/dist/adapters/message-port.d.mts +42 -0
- package/dist/adapters/message-port.mjs +132 -0
- package/dist/adapters/nestjs.d.mts +25 -0
- package/dist/adapters/nestjs.mjs +83 -0
- package/dist/adapters/nextjs.d.mts +14 -0
- package/dist/adapters/nextjs.mjs +29 -0
- package/dist/adapters/peer.d.mts +27 -0
- package/dist/adapters/peer.mjs +36 -0
- package/dist/adapters/remix.d.mts +15 -0
- package/dist/adapters/remix.mjs +30 -0
- package/dist/adapters/solidstart.d.mts +12 -0
- package/dist/adapters/solidstart.mjs +29 -0
- package/dist/adapters/sveltekit.d.mts +14 -0
- package/dist/adapters/sveltekit.mjs +30 -0
- package/dist/broker/index.d.mts +62 -0
- package/dist/broker/index.mjs +153 -0
- package/dist/broker/nats.d.mts +33 -0
- package/dist/broker/nats.mjs +31 -0
- package/dist/broker/redis.d.mts +51 -0
- package/dist/broker/redis.mjs +92 -0
- package/dist/builder.d.mts +55 -0
- package/dist/builder.mjs +70 -0
- package/dist/callable.d.mts +19 -0
- package/dist/callable.mjs +42 -0
- package/dist/caller.mjs +90 -0
- package/dist/client/adapters/fetch/index.d.mts +15 -0
- package/dist/client/adapters/fetch/index.mjs +57 -0
- package/dist/client/adapters/ofetch/index.d.mts +55 -0
- package/dist/client/adapters/ofetch/index.mjs +91 -0
- package/dist/client/adapters/websocket/index.d.mts +20 -0
- package/dist/client/adapters/websocket/index.mjs +101 -0
- package/dist/client/client.d.mts +37 -0
- package/dist/client/client.mjs +80 -0
- package/dist/client/consume.d.mts +50 -0
- package/dist/client/consume.mjs +66 -0
- package/dist/client/dynamic-link.d.mts +16 -0
- package/dist/client/dynamic-link.mjs +19 -0
- package/dist/client/index.d.mts +6 -0
- package/dist/client/index.mjs +5 -0
- package/dist/client/interceptor.d.mts +31 -0
- package/dist/client/interceptor.mjs +34 -0
- package/dist/client/openapi.d.mts +29 -0
- package/dist/client/openapi.mjs +89 -0
- package/dist/client/plugins/batch.d.mts +26 -0
- package/dist/client/plugins/batch.mjs +64 -0
- package/dist/client/plugins/circuit-breaker.d.mts +24 -0
- package/dist/client/plugins/circuit-breaker.mjs +60 -0
- package/dist/client/plugins/csrf.d.mts +13 -0
- package/dist/client/plugins/csrf.mjs +20 -0
- package/dist/client/plugins/dedupe.d.mts +10 -0
- package/dist/client/plugins/dedupe.mjs +28 -0
- package/dist/client/plugins/index.d.mts +8 -0
- package/dist/client/plugins/index.mjs +8 -0
- package/dist/client/plugins/otel.d.mts +12 -0
- package/dist/client/plugins/otel.mjs +27 -0
- package/dist/client/plugins/retry.d.mts +34 -0
- package/dist/client/plugins/retry.mjs +79 -0
- package/dist/client/plugins/timeout.d.mts +10 -0
- package/dist/client/plugins/timeout.mjs +14 -0
- package/dist/client/server.d.mts +16 -0
- package/dist/client/server.mjs +59 -0
- package/dist/client/types.d.mts +29 -0
- package/dist/codec/devalue.d.mts +21 -0
- package/dist/codec/devalue.mjs +33 -0
- package/dist/codec/msgpack.d.mts +18 -0
- package/dist/codec/msgpack.mjs +45 -0
- package/dist/codec/sanitize.mjs +38 -0
- package/dist/codegen/emitters.d.mts +51 -0
- package/dist/codegen/emitters.mjs +143 -0
- package/dist/codegen/generate.d.mts +25 -0
- package/dist/codegen/generate.mjs +224 -0
- package/dist/codegen/index.d.mts +44 -0
- package/dist/codegen/index.mjs +103 -0
- package/dist/codegen/parse.d.mts +124 -0
- package/dist/codegen/parse.mjs +135 -0
- package/dist/codegen/preserve.d.mts +21 -0
- package/dist/codegen/preserve.mjs +62 -0
- package/dist/codegen/schema-to-code.d.mts +57 -0
- package/dist/codegen/schema-to-code.mjs +167 -0
- package/dist/compile.d.mts +46 -0
- package/dist/compile.mjs +332 -0
- package/dist/core/codec.mjs +67 -0
- package/dist/core/context-bridge.mjs +11 -0
- package/dist/core/dispatch.mjs +62 -0
- package/dist/core/error.d.mts +99 -60
- package/dist/core/error.mjs +125 -92
- package/dist/core/handler.d.mts +6 -0
- package/dist/core/handler.mjs +153 -0
- package/dist/core/input.mjs +49 -0
- package/dist/core/iterator.d.mts +17 -0
- package/dist/core/iterator.mjs +79 -0
- package/dist/core/router-utils.mjs +22 -0
- package/dist/core/schema.d.mts +20 -0
- package/dist/core/schema.mjs +33 -0
- package/dist/core/serve.d.mts +51 -0
- package/dist/core/serve.mjs +76 -0
- package/dist/core/sse.d.mts +18 -0
- package/dist/core/sse.mjs +110 -0
- package/dist/core/storage.d.mts +17 -4
- package/dist/core/storage.mjs +60 -13
- package/dist/core/task.d.mts +62 -0
- package/dist/core/task.mjs +165 -0
- package/dist/core/trace-map.d.mts +13 -0
- package/dist/core/trace-map.mjs +13 -0
- package/dist/core/url.mjs +28 -0
- package/dist/core/utils.mjs +24 -0
- package/dist/index.d.mts +17 -21
- package/dist/index.mjs +14 -22
- package/dist/integrations/ai/index.d.mts +25 -0
- package/dist/integrations/ai/index.mjs +117 -0
- package/dist/integrations/better-auth/index.d.mts +41 -0
- package/dist/integrations/better-auth/index.mjs +331 -0
- package/dist/integrations/drizzle/index.d.mts +27 -0
- package/dist/integrations/drizzle/index.mjs +285 -0
- package/dist/integrations/hey-api/index.d.mts +2 -0
- package/dist/integrations/hey-api/index.mjs +2 -0
- package/dist/integrations/hey-api/to-client.d.mts +20 -0
- package/dist/integrations/hey-api/to-client.mjs +39 -0
- package/dist/integrations/pinia-colada/general-utils.d.mts +13 -0
- package/dist/integrations/pinia-colada/general-utils.mjs +9 -0
- package/dist/integrations/pinia-colada/index.d.mts +6 -0
- package/dist/integrations/pinia-colada/index.mjs +5 -0
- package/dist/integrations/pinia-colada/key.d.mts +11 -0
- package/dist/integrations/pinia-colada/key.mjs +11 -0
- package/dist/integrations/pinia-colada/procedure-utils.d.mts +25 -0
- package/dist/integrations/pinia-colada/procedure-utils.mjs +33 -0
- package/dist/integrations/pinia-colada/router-utils.d.mts +17 -0
- package/dist/integrations/pinia-colada/router-utils.mjs +30 -0
- package/dist/integrations/pinia-colada/types.d.mts +25 -0
- package/dist/integrations/react/index.d.mts +83 -0
- package/dist/integrations/react/index.mjs +196 -0
- package/dist/integrations/tanstack-query/index.d.mts +120 -0
- package/dist/integrations/tanstack-query/index.mjs +100 -0
- package/dist/integrations/tanstack-query/ssr.d.mts +60 -0
- package/dist/integrations/tanstack-query/ssr.mjs +102 -0
- package/dist/integrations/zod/converter.d.mts +75 -0
- package/dist/integrations/zod/converter.mjs +345 -0
- package/dist/integrations/zod/index.d.mts +2 -0
- package/dist/integrations/zod/index.mjs +2 -0
- package/dist/lazy.d.mts +22 -0
- package/dist/lazy.mjs +34 -0
- package/dist/lifecycle.d.mts +36 -0
- package/dist/lifecycle.mjs +46 -0
- package/dist/map-input.d.mts +17 -0
- package/dist/map-input.mjs +47 -0
- package/dist/plugins/analytics/accumulator.d.mts +24 -0
- package/dist/plugins/analytics/accumulator.mjs +91 -0
- package/dist/plugins/analytics/alerts.d.mts +59 -0
- package/dist/plugins/analytics/alerts.mjs +140 -0
- package/dist/plugins/analytics/collector.d.mts +38 -0
- package/dist/plugins/analytics/collector.mjs +275 -0
- package/dist/plugins/analytics/cost.d.mts +61 -0
- package/dist/plugins/analytics/cost.mjs +97 -0
- package/dist/plugins/analytics/export.d.mts +7 -0
- package/dist/plugins/analytics/export.mjs +86 -0
- package/dist/plugins/analytics/normalize.mjs +144 -0
- package/dist/plugins/analytics/query.mjs +164 -0
- package/dist/plugins/analytics/request-id.mjs +34 -0
- package/dist/plugins/analytics/routes.d.mts +11 -0
- package/dist/plugins/analytics/routes.mjs +211 -0
- package/dist/plugins/analytics/sse.d.mts +31 -0
- package/dist/plugins/analytics/sse.mjs +74 -0
- package/dist/plugins/analytics/store.mjs +103 -0
- package/dist/plugins/analytics/timeseries.d.mts +50 -0
- package/dist/plugins/analytics/timeseries.mjs +169 -0
- package/dist/plugins/analytics/trace.d.mts +48 -0
- package/dist/plugins/analytics/trace.mjs +83 -0
- package/dist/plugins/analytics/types.d.mts +145 -0
- package/dist/plugins/analytics/types.mjs +40 -0
- package/dist/plugins/analytics/utils.d.mts +4 -0
- package/dist/plugins/analytics/utils.mjs +56 -0
- package/dist/plugins/analytics.d.mts +18 -0
- package/dist/plugins/analytics.mjs +188 -0
- package/dist/plugins/batch-server.d.mts +20 -0
- package/dist/plugins/batch-server.mjs +91 -0
- package/dist/plugins/body-limit.d.mts +19 -0
- package/dist/plugins/body-limit.mjs +49 -0
- package/dist/plugins/cache.d.mts +170 -0
- package/dist/plugins/cache.mjs +212 -0
- package/dist/plugins/coerce.d.mts +24 -0
- package/dist/plugins/coerce.mjs +70 -0
- package/dist/plugins/cookies.d.mts +14 -0
- package/dist/plugins/cookies.mjs +48 -0
- package/dist/plugins/cors.d.mts +43 -0
- package/dist/plugins/cors.mjs +62 -0
- package/dist/plugins/file-upload.d.mts +38 -0
- package/dist/plugins/file-upload.mjs +102 -0
- package/dist/plugins/index.d.mts +18 -0
- package/dist/plugins/index.mjs +17 -0
- package/dist/plugins/otel.d.mts +35 -0
- package/dist/plugins/otel.mjs +40 -0
- package/dist/plugins/pino.d.mts +60 -0
- package/dist/plugins/pino.mjs +42 -0
- package/dist/plugins/pubsub.d.mts +50 -0
- package/dist/plugins/pubsub.mjs +53 -0
- package/dist/plugins/ratelimit.d.mts +53 -0
- package/dist/plugins/ratelimit.mjs +92 -0
- package/dist/plugins/signing.d.mts +41 -0
- package/dist/plugins/signing.mjs +118 -0
- package/dist/plugins/strict-get.d.mts +10 -0
- package/dist/plugins/strict-get.mjs +33 -0
- package/dist/scalar.d.mts +49 -0
- package/dist/scalar.mjs +311 -0
- package/dist/silgi.d.mts +144 -0
- package/dist/silgi.mjs +164 -0
- package/dist/trpc-interop.d.mts +22 -0
- package/dist/trpc-interop.mjs +68 -0
- package/dist/types.d.mts +108 -0
- package/dist/ws.d.mts +88 -0
- package/dist/ws.mjs +205 -0
- package/lib/dashboard/index.html +120 -0
- package/lib/ocache.d.mts +1 -0
- package/lib/ocache.mjs +1 -0
- package/lib/ofetch.d.mts +1 -0
- package/lib/ofetch.mjs +1 -0
- package/lib/srvx.d.mts +1 -0
- package/lib/srvx.mjs +1 -0
- package/lib/unstorage.d.mts +1 -0
- package/lib/unstorage.mjs +1 -0
- package/package.json +314 -150
- package/dist/build.d.mts +0 -3
- package/dist/build.mjs +0 -4
- package/dist/cli/build/build.mjs +0 -15
- package/dist/cli/build/dev.d.mts +0 -10
- package/dist/cli/build/dev.mjs +0 -91
- package/dist/cli/build/prepare.d.mts +0 -6
- package/dist/cli/build/prepare.mjs +0 -15
- package/dist/cli/commands/commands.mjs +0 -90
- package/dist/cli/commands/env.mjs +0 -53
- package/dist/cli/commands/init.mjs +0 -84
- package/dist/cli/commands/install.mjs +0 -52
- package/dist/cli/commands/prepare.mjs +0 -65
- package/dist/cli/commands/reset.mjs +0 -46
- package/dist/cli/commands/run.mjs +0 -31
- package/dist/cli/commands/watch.mjs +0 -153
- package/dist/cli/config/defaults.mjs +0 -117
- package/dist/cli/config/index.d.mts +0 -3
- package/dist/cli/config/index.mjs +0 -4
- package/dist/cli/config/loader.d.mts +0 -6
- package/dist/cli/config/loader.mjs +0 -71
- package/dist/cli/config/resolvers/compatibility.mjs +0 -71
- package/dist/cli/config/resolvers/imports.mjs +0 -35
- package/dist/cli/config/resolvers/paths.mjs +0 -98
- package/dist/cli/config/resolvers/storage.mjs +0 -23
- package/dist/cli/config/resolvers/url.mjs +0 -9
- package/dist/cli/config/types.d.mts +0 -14
- package/dist/cli/config/types.mjs +0 -147
- package/dist/cli/core/apiful.mjs +0 -36
- package/dist/cli/core/devServer.mjs +0 -10
- package/dist/cli/core/env.mjs +0 -68
- package/dist/cli/core/installPackage.mjs +0 -60
- package/dist/cli/core/runtimeConfig.mjs +0 -70
- package/dist/cli/core/scan.mjs +0 -35
- package/dist/cli/core/silgi.mjs +0 -111
- package/dist/cli/framework/emptyFramework.mjs +0 -7
- package/dist/cli/framework/h3.mjs +0 -55
- package/dist/cli/framework/index.mjs +0 -15
- package/dist/cli/framework/nitro.mjs +0 -24
- package/dist/cli/framework/nuxt.mjs +0 -10
- package/dist/cli/index.d.mts +0 -1
- package/dist/cli/index.mjs +0 -29
- package/dist/cli/module/exportScan.mjs +0 -180
- package/dist/cli/module/install.mjs +0 -49
- package/dist/cli/module/scan.mjs +0 -193
- package/dist/cli/scan/prepareCommands.mjs +0 -40
- package/dist/cli/scan/prepareConfigs.mjs +0 -33
- package/dist/cli/scan/prepareCoreFile.mjs +0 -118
- package/dist/cli/scan/prepareScanFile.mjs +0 -59
- package/dist/cli/scan/prepareSchema.mjs +0 -128
- package/dist/cli/scan/scanExportFile.mjs +0 -288
- package/dist/cli/scan/writeCoreFile.mjs +0 -22
- package/dist/cli/scan/writeTypesAndFiles.mjs +0 -72
- package/dist/cli/utils/cancel.mjs +0 -14
- package/dist/cli/utils/common.mjs +0 -15
- package/dist/cli/utils/compatibility.mjs +0 -33
- package/dist/cli/utils/debug.mjs +0 -11
- package/dist/cli/utils/ignore.mjs +0 -56
- package/dist/cli/utils/processManager.mjs +0 -170
- package/dist/cli/utils/readScanFile.mjs +0 -58
- package/dist/cli/utils/storage.mjs +0 -23
- package/dist/core/context.d.mts +0 -30
- package/dist/core/context.mjs +0 -32
- package/dist/core/createSilgi.d.mts +0 -6
- package/dist/core/createSilgi.mjs +0 -153
- package/dist/core/event.d.mts +0 -26
- package/dist/core/event.mjs +0 -44
- package/dist/core/index.d.mts +0 -25
- package/dist/core/index.mjs +0 -30
- package/dist/core/orchestrate.mjs +0 -115
- package/dist/core/response.d.mts +0 -20
- package/dist/core/response.mjs +0 -105
- package/dist/core/silgi.d.mts +0 -19
- package/dist/core/silgi.mjs +0 -141
- package/dist/core/silgiApp.d.mts +0 -9
- package/dist/core/silgiApp.mjs +0 -23
- package/dist/core/unctx.d.mts +0 -21
- package/dist/core/unctx.mjs +0 -35
- package/dist/core/utils/event-stream.d.mts +0 -53
- package/dist/core/utils/event-stream.mjs +0 -38
- package/dist/core/utils/event.d.mts +0 -8
- package/dist/core/utils/event.mjs +0 -12
- package/dist/core/utils/internal/event-stream.d.mts +0 -45
- package/dist/core/utils/internal/event-stream.mjs +0 -137
- package/dist/core/utils/internal/obj.mjs +0 -9
- package/dist/core/utils/internal/object.mjs +0 -29
- package/dist/core/utils/internal/query.mjs +0 -73
- package/dist/core/utils/internal/req.mjs +0 -35
- package/dist/core/utils/merge.d.mts +0 -14
- package/dist/core/utils/merge.mjs +0 -27
- package/dist/core/utils/middleware.d.mts +0 -14
- package/dist/core/utils/middleware.mjs +0 -12
- package/dist/core/utils/request.mjs +0 -35
- package/dist/core/utils/resolver.d.mts +0 -7
- package/dist/core/utils/resolver.mjs +0 -29
- package/dist/core/utils/runtime.d.mts +0 -7
- package/dist/core/utils/runtime.mjs +0 -20
- package/dist/core/utils/sanitize.mjs +0 -22
- package/dist/core/utils/schema.d.mts +0 -34
- package/dist/core/utils/schema.mjs +0 -33
- package/dist/core/utils/service.d.mts +0 -13
- package/dist/core/utils/service.mjs +0 -19
- package/dist/core/utils/shared.d.mts +0 -6
- package/dist/core/utils/shared.mjs +0 -7
- package/dist/core/utils/storage.d.mts +0 -24
- package/dist/core/utils/storage.mjs +0 -54
- package/dist/kit/add/add-commands.d.mts +0 -6
- package/dist/kit/add/add-commands.mjs +0 -12
- package/dist/kit/add/add-core-file.d.mts +0 -9
- package/dist/kit/add/add-core-file.mjs +0 -11
- package/dist/kit/add/add-imports.d.mts +0 -14
- package/dist/kit/add/add-imports.mjs +0 -56
- package/dist/kit/add/add-npm.d.mts +0 -14
- package/dist/kit/add/add-npm.mjs +0 -23
- package/dist/kit/define.d.mts +0 -28
- package/dist/kit/define.mjs +0 -25
- package/dist/kit/errors.d.mts +0 -6
- package/dist/kit/errors.mjs +0 -11
- package/dist/kit/esm.d.mts +0 -11
- package/dist/kit/esm.mjs +0 -21
- package/dist/kit/fs.d.mts +0 -4
- package/dist/kit/fs.mjs +0 -13
- package/dist/kit/function-utils.d.mts +0 -27
- package/dist/kit/function-utils.mjs +0 -75
- package/dist/kit/gen.d.mts +0 -5
- package/dist/kit/gen.mjs +0 -26
- package/dist/kit/hash.d.mts +0 -4
- package/dist/kit/hash.mjs +0 -10
- package/dist/kit/index.d.mts +0 -22
- package/dist/kit/index.mjs +0 -23
- package/dist/kit/isFramework.d.mts +0 -6
- package/dist/kit/isFramework.mjs +0 -21
- package/dist/kit/logger.d.mts +0 -6
- package/dist/kit/logger.mjs +0 -10
- package/dist/kit/migration.d.mts +0 -113
- package/dist/kit/migration.mjs +0 -301
- package/dist/kit/module.d.mts +0 -14
- package/dist/kit/module.mjs +0 -53
- package/dist/kit/path.d.mts +0 -7
- package/dist/kit/path.mjs +0 -26
- package/dist/kit/preset.d.mts +0 -8
- package/dist/kit/preset.mjs +0 -11
- package/dist/kit/resolve.d.mts +0 -37
- package/dist/kit/resolve.mjs +0 -82
- package/dist/kit/template.d.mts +0 -19
- package/dist/kit/template.mjs +0 -91
- package/dist/kit/useRequest.d.mts +0 -19
- package/dist/kit/useRequest.mjs +0 -63
- package/dist/kit/utils.d.mts +0 -34
- package/dist/kit/utils.mjs +0 -91
- package/dist/package.mjs +0 -176
- package/dist/presets/_all.gen.d.mts +0 -6
- package/dist/presets/_all.gen.mjs +0 -18
- package/dist/presets/_resolve.d.mts +0 -12
- package/dist/presets/_resolve.mjs +0 -57
- package/dist/presets/_types.gen.d.mts +0 -8
- package/dist/presets/_types.gen.mjs +0 -5
- package/dist/presets/h3/preset.d.mts +0 -6
- package/dist/presets/h3/preset.mjs +0 -35
- package/dist/presets/hono/preset.d.mts +0 -6
- package/dist/presets/hono/preset.mjs +0 -30
- package/dist/presets/index.d.mts +0 -3
- package/dist/presets/index.mjs +0 -3
- package/dist/presets/nitro/preset.d.mts +0 -6
- package/dist/presets/nitro/preset.mjs +0 -37
- package/dist/presets/npmpackage/preset.d.mts +0 -6
- package/dist/presets/npmpackage/preset.mjs +0 -29
- package/dist/presets/nuxt/preset.d.mts +0 -6
- package/dist/presets/nuxt/preset.mjs +0 -41
- package/dist/runtime/index.d.mts +0 -4
- package/dist/runtime/index.mjs +0 -5
- package/dist/runtime/internal/config.d.mts +0 -11
- package/dist/runtime/internal/config.mjs +0 -97
- package/dist/runtime/internal/debug.d.mts +0 -6
- package/dist/runtime/internal/debug.mjs +0 -11
- package/dist/runtime/internal/defu.d.mts +0 -4
- package/dist/runtime/internal/defu.mjs +0 -9
- package/dist/runtime/internal/index.d.mts +0 -7
- package/dist/runtime/internal/index.mjs +0 -8
- package/dist/runtime/internal/nitro.d.mts +0 -6
- package/dist/runtime/internal/nitro.mjs +0 -36
- package/dist/runtime/internal/nuxt.d.mts +0 -12
- package/dist/runtime/internal/nuxt.mjs +0 -16
- package/dist/runtime/internal/ofetch.d.mts +0 -8
- package/dist/runtime/internal/ofetch.mjs +0 -39
- package/dist/runtime/internal/plugin.d.mts +0 -7
- package/dist/runtime/internal/plugin.mjs +0 -8
- package/dist/types/cliConfig.d.mts +0 -288
- package/dist/types/cliConfig.mjs +0 -0
- package/dist/types/cliHooks.d.mts +0 -142
- package/dist/types/cliHooks.mjs +0 -0
- package/dist/types/compatibility.d.mts +0 -13
- package/dist/types/compatibility.mjs +0 -0
- package/dist/types/config.d.mts +0 -46
- package/dist/types/config.mjs +0 -0
- package/dist/types/dotenv.d.mts +0 -29
- package/dist/types/dotenv.mjs +0 -0
- package/dist/types/event.d.mts +0 -63
- package/dist/types/event.mjs +0 -0
- package/dist/types/global.d.mts +0 -24
- package/dist/types/global.mjs +0 -0
- package/dist/types/helper.d.mts +0 -25
- package/dist/types/helper.mjs +0 -0
- package/dist/types/hooks.d.mts +0 -37
- package/dist/types/hooks.mjs +0 -0
- package/dist/types/index.d.mts +0 -26
- package/dist/types/index.mjs +0 -0
- package/dist/types/kits.d.mts +0 -32
- package/dist/types/kits.mjs +0 -0
- package/dist/types/middleware.d.mts +0 -31
- package/dist/types/middleware.mjs +0 -0
- package/dist/types/module.d.mts +0 -102
- package/dist/types/module.mjs +0 -0
- package/dist/types/preset.d.mts +0 -20
- package/dist/types/preset.mjs +0 -0
- package/dist/types/route.d.mts +0 -59
- package/dist/types/route.mjs +0 -0
- package/dist/types/runtime/index.d.mts +0 -5
- package/dist/types/runtime/index.mjs +0 -0
- package/dist/types/runtime/nuxt.d.mts +0 -13
- package/dist/types/runtime/nuxt.mjs +0 -0
- package/dist/types/runtime/ofetch.d.mts +0 -14
- package/dist/types/runtime/ofetch.mjs +0 -0
- package/dist/types/runtime/plugin.d.mts +0 -8
- package/dist/types/runtime/plugin.mjs +0 -0
- package/dist/types/runtime/silgi.d.mts +0 -11
- package/dist/types/runtime/silgi.mjs +0 -0
- package/dist/types/schema.d.mts +0 -86
- package/dist/types/schema.mjs +0 -0
- package/dist/types/service.d.mts +0 -102
- package/dist/types/service.mjs +0 -0
- package/dist/types/shared.d.mts +0 -19
- package/dist/types/shared.mjs +0 -0
- package/dist/types/silgi.d.mts +0 -71
- package/dist/types/silgi.mjs +0 -0
- package/dist/types/silgiCLI.d.mts +0 -118
- package/dist/types/silgiCLI.mjs +0 -0
- package/dist/types/standard-schema.d.mts +0 -61
- package/dist/types/standard-schema.mjs +0 -0
- package/dist/types/storage.d.mts +0 -30
- package/dist/types/storage.mjs +0 -0
- package/dist/types/tree-kill.d.mts +0 -18
- package/dist/types/tree-kill.mjs +0 -0
- package/lib/config.d.mts +0 -7
- package/lib/config.mjs +0 -5
- package/lib/meta.d.mts +0 -4
- package/lib/meta.mjs +0 -6
- package/lib/runtime-meta.d.mts +0 -4
- package/lib/runtime-meta.mjs +0 -32
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
import { deepMergeObjects } from "./core/utils/merge.mjs";
|
|
16
|
-
import { createMiddleware } from "./core/utils/middleware.mjs";
|
|
17
|
-
import { createSchema } from "./core/utils/schema.mjs";
|
|
18
|
-
import { createService, createWebSocket, defineServiceSetup } from "./core/utils/service.mjs";
|
|
19
|
-
import { createShared } from "./core/utils/shared.mjs";
|
|
20
|
-
import { autoImportTypes } from "./core/index.mjs";
|
|
21
|
-
|
|
22
|
-
export { SilgiError, SilgiHttpEvent, autoImportTypes, createError, createEventStream, createMiddleware, createResolver, createSchema, createService, createShared, createSilgi, createStorage, createWebSocket, deepMergeObjects, defineServiceSetup, getEvent, getEventContext, getUrlPrefix, getWebsocket, handleResponse, handler, isError, kHandled, kNotFound, middleware, replaceRuntimeValues, silgiCLICtx, silgiCtx, silgiFetch, storageMount, tryUseSilgi, tryUseSilgiCLI, updateRuntimeStorage, useRuntime, useSilgi, useSilgiCLI, useSilgiStorage };
|
|
1
|
+
import { ValidationError, type, validateSchema } from "./core/schema.mjs";
|
|
2
|
+
import { collectCronTasks, getScheduledTasks, runTask, setTaskAnalytics, startCronJobs, stopCronJobs } from "./core/task.mjs";
|
|
3
|
+
import { SilgiError, isDefinedError, toSilgiError } from "./core/error.mjs";
|
|
4
|
+
import { compileProcedure, compileRouter, createContext } from "./compile.mjs";
|
|
5
|
+
import { AsyncIteratorClass, mapAsyncIterator } from "./core/iterator.mjs";
|
|
6
|
+
import { getEventMeta, withEventMeta } from "./core/sse.mjs";
|
|
7
|
+
import { silgi } from "./silgi.mjs";
|
|
8
|
+
import { callable } from "./callable.mjs";
|
|
9
|
+
import { lifecycleWrap } from "./lifecycle.mjs";
|
|
10
|
+
import { mapInput } from "./map-input.mjs";
|
|
11
|
+
import { isLazy, lazy, resolveLazy } from "./lazy.mjs";
|
|
12
|
+
import { initStorage, resetStorage, useStorage } from "./core/storage.mjs";
|
|
13
|
+
import { generateOpenAPI, scalarHTML } from "./scalar.mjs";
|
|
14
|
+
export { AsyncIteratorClass, SilgiError, ValidationError, callable, collectCronTasks, compileProcedure, compileRouter, createContext, generateOpenAPI, getEventMeta, getScheduledTasks, initStorage, isDefinedError, isLazy, lazy, lifecycleWrap, mapAsyncIterator, mapInput, resetStorage, resolveLazy, runTask, scalarHTML, setTaskAnalytics, silgi, startCronJobs, stopCronJobs, toSilgiError, type, useStorage, validateSchema, withEventMeta };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ProcedureDef, RouterDef } from "../../types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/integrations/ai/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Convert a single silgi procedure into an AI SDK tool.
|
|
6
|
+
*/
|
|
7
|
+
declare function procedureToTool(name: string, procedure: ProcedureDef, options?: {
|
|
8
|
+
description?: string;
|
|
9
|
+
}): any;
|
|
10
|
+
/**
|
|
11
|
+
* Convert all procedures in a silgi router into AI SDK tools.
|
|
12
|
+
* Nested routers are flattened with underscore separators.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Router: { users: { list, create }, health }
|
|
17
|
+
* // Tools: { users_list, users_create, health }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function routerToTools(router: RouterDef, options?: {
|
|
21
|
+
/** Filter which procedures to expose as tools */filter?: (path: string, procedure: ProcedureDef) => boolean; /** Custom descriptions per path */
|
|
22
|
+
descriptions?: Record<string, string>;
|
|
23
|
+
}): Record<string, any>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { procedureToTool, routerToTools };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { compileProcedure } from "../../compile.mjs";
|
|
2
|
+
import { jsonSchema, tool } from "ai";
|
|
3
|
+
//#region src/integrations/ai/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Vercel AI SDK integration — expose silgi procedures as AI tools.
|
|
6
|
+
*
|
|
7
|
+
* Converts silgi router procedures into AI SDK tools that can be
|
|
8
|
+
* called by LLMs via function calling / tool use.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { generateText } from "ai"
|
|
13
|
+
* import { openai } from "@ai-sdk/openai"
|
|
14
|
+
* import { routerToTools } from "silgi/ai"
|
|
15
|
+
*
|
|
16
|
+
* const tools = routerToTools(appRouter)
|
|
17
|
+
*
|
|
18
|
+
* const { text } = await generateText({
|
|
19
|
+
* model: openai("gpt-4o"),
|
|
20
|
+
* tools,
|
|
21
|
+
* prompt: "List all users with limit 5",
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Convert a single silgi procedure into an AI SDK tool.
|
|
27
|
+
*/
|
|
28
|
+
function procedureToTool(name, procedure, options) {
|
|
29
|
+
const handler = compileProcedure(procedure);
|
|
30
|
+
return tool({
|
|
31
|
+
description: options?.description ?? procedure.route?.description ?? procedure.route?.summary ?? `Call ${name}`,
|
|
32
|
+
parameters: jsonSchema(procedure.input ? zodToJsonSchemaSimple(procedure.input) : {
|
|
33
|
+
type: "object",
|
|
34
|
+
properties: {}
|
|
35
|
+
}),
|
|
36
|
+
execute: async (input, execOptions) => {
|
|
37
|
+
const ctx = Object.create(null);
|
|
38
|
+
const signal = execOptions?.abortSignal ?? new AbortController().signal;
|
|
39
|
+
const result = handler(ctx, input ?? {}, signal);
|
|
40
|
+
return result instanceof Promise ? await result : result;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Convert all procedures in a silgi router into AI SDK tools.
|
|
46
|
+
* Nested routers are flattened with underscore separators.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* // Router: { users: { list, create }, health }
|
|
51
|
+
* // Tools: { users_list, users_create, health }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
function routerToTools(router, options) {
|
|
55
|
+
const tools = {};
|
|
56
|
+
collectProcedures(router, [], (path, proc) => {
|
|
57
|
+
const flatName = path.join("_");
|
|
58
|
+
if (options?.filter && !options.filter(flatName, proc)) return;
|
|
59
|
+
tools[flatName] = procedureToTool(flatName, proc, { description: options?.descriptions?.[flatName] });
|
|
60
|
+
});
|
|
61
|
+
return tools;
|
|
62
|
+
}
|
|
63
|
+
function isProcedureDef(v) {
|
|
64
|
+
return typeof v === "object" && v !== null && "type" in v && "resolve" in v;
|
|
65
|
+
}
|
|
66
|
+
function collectProcedures(node, path, cb) {
|
|
67
|
+
if (isProcedureDef(node)) {
|
|
68
|
+
cb(path, node);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (typeof node === "object" && node !== null) for (const [key, child] of Object.entries(node)) collectProcedures(child, [...path, key], cb);
|
|
72
|
+
}
|
|
73
|
+
/** Simple Zod → JSON Schema for AI tool parameters */
|
|
74
|
+
function zodToJsonSchemaSimple(schema) {
|
|
75
|
+
const zod = schema?._zod ?? schema?._def;
|
|
76
|
+
if (!zod) return {
|
|
77
|
+
type: "object",
|
|
78
|
+
properties: {}
|
|
79
|
+
};
|
|
80
|
+
return convertDef(zod.def ?? zod);
|
|
81
|
+
}
|
|
82
|
+
function convertDef(def) {
|
|
83
|
+
if (!def) return {};
|
|
84
|
+
switch (def.type ?? def.typeName) {
|
|
85
|
+
case "string": return { type: "string" };
|
|
86
|
+
case "number":
|
|
87
|
+
case "float": return { type: "number" };
|
|
88
|
+
case "int": return { type: "integer" };
|
|
89
|
+
case "boolean": return { type: "boolean" };
|
|
90
|
+
case "object": {
|
|
91
|
+
const props = {};
|
|
92
|
+
const required = [];
|
|
93
|
+
if (def.shape) for (const [k, v] of Object.entries(def.shape)) {
|
|
94
|
+
props[k] = zodToJsonSchemaSimple(v);
|
|
95
|
+
const fz = v?._zod?.def ?? v?._def;
|
|
96
|
+
if (fz?.type !== "optional" && fz?.typeName !== "ZodOptional") required.push(k);
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
type: "object",
|
|
100
|
+
properties: props,
|
|
101
|
+
...required.length ? { required } : {}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
case "array": return {
|
|
105
|
+
type: "array",
|
|
106
|
+
...def.element ? { items: zodToJsonSchemaSimple(def.element) } : {}
|
|
107
|
+
};
|
|
108
|
+
case "optional": return zodToJsonSchemaSimple(def.innerType ?? def.inner);
|
|
109
|
+
case "enum": return {
|
|
110
|
+
type: "string",
|
|
111
|
+
enum: def.values ?? def.entries
|
|
112
|
+
};
|
|
113
|
+
default: return {};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { procedureToTool, routerToTools };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/integrations/better-auth/index.d.ts
|
|
2
|
+
interface TracingConfig {
|
|
3
|
+
/** Capture request body as span input (default: true) */
|
|
4
|
+
captureInput?: boolean;
|
|
5
|
+
/** Capture response data as span output (default: true) */
|
|
6
|
+
captureOutput?: boolean;
|
|
7
|
+
/** Pass `createAuthMiddleware` from `better-auth/api` to wrap hooks handler */
|
|
8
|
+
createAuthMiddleware?: (handler: any) => any;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates a Better Auth plugin that auto-traces all auth operations
|
|
12
|
+
* into silgi analytics spans.
|
|
13
|
+
*
|
|
14
|
+
* @param config - Optional configuration
|
|
15
|
+
* @returns A Better Auth plugin (typed as `any` to avoid requiring better-auth types at build time)
|
|
16
|
+
*/
|
|
17
|
+
declare function tracing(config?: TracingConfig): any;
|
|
18
|
+
/**
|
|
19
|
+
* Instrument a Better Auth instance to trace all `auth.api.*` method calls.
|
|
20
|
+
* Works with `withCtx` — programmatic calls from background jobs,
|
|
21
|
+
* server-side session fetches etc. are traced when context is available.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { instrumentBetterAuth, withCtx } from 'silgi/better-auth'
|
|
26
|
+
*
|
|
27
|
+
* const auth = instrumentBetterAuth(betterAuth({ ... }))
|
|
28
|
+
*
|
|
29
|
+
* // In a silgi procedure:
|
|
30
|
+
* const me = s.$resolve(async ({ ctx }) => {
|
|
31
|
+
* return withCtx(ctx, () => auth.api.getSession({ headers: ctx.headers }))
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function instrumentBetterAuth<T extends Record<string, any>>(auth: T): T;
|
|
36
|
+
/**
|
|
37
|
+
* Run a function with silgi context available to instrumented Better Auth API calls.
|
|
38
|
+
*/
|
|
39
|
+
declare function withCtx<T>(ctx: Record<string, unknown>, fn: () => T): T;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { TracingConfig, instrumentBetterAuth, tracing, withCtx };
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { getCtx, runWithCtx } from "../../core/context-bridge.mjs";
|
|
2
|
+
//#region src/integrations/better-auth/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Silgi + Better Auth tracing integration.
|
|
5
|
+
*
|
|
6
|
+
* Provides a Better Auth plugin factory that auto-traces all auth operations
|
|
7
|
+
* (sign-in, sign-up, OAuth, session management, etc.) into silgi analytics.
|
|
8
|
+
*
|
|
9
|
+
* The silgi request context is passed via `request.__silgiCtx`, set by
|
|
10
|
+
* the silgi auth handler before calling `auth.handler(request)`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { tracing } from 'silgi/better-auth'
|
|
15
|
+
*
|
|
16
|
+
* const auth = betterAuth({
|
|
17
|
+
* plugins: [
|
|
18
|
+
* tracing(), // auto-traces all auth operations
|
|
19
|
+
* ],
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function matchOperation(path) {
|
|
24
|
+
const normalized = path.replace(/^\/+/, "");
|
|
25
|
+
if (normalized.endsWith("/sign-up/email") || normalized === "sign-up/email") return {
|
|
26
|
+
spanName: "auth.signup.email",
|
|
27
|
+
operation: "signup",
|
|
28
|
+
method: "email"
|
|
29
|
+
};
|
|
30
|
+
if (normalized.endsWith("/sign-in/email") || normalized === "sign-in/email") return {
|
|
31
|
+
spanName: "auth.signin.email",
|
|
32
|
+
operation: "signin",
|
|
33
|
+
method: "email"
|
|
34
|
+
};
|
|
35
|
+
if (normalized.endsWith("/sign-out") || normalized === "sign-out") return {
|
|
36
|
+
spanName: "auth.signout",
|
|
37
|
+
operation: "signout"
|
|
38
|
+
};
|
|
39
|
+
if (normalized.endsWith("/get-session") || normalized === "get-session") return {
|
|
40
|
+
spanName: "auth.get_session",
|
|
41
|
+
operation: "get_session"
|
|
42
|
+
};
|
|
43
|
+
if (normalized.endsWith("/update-user") || normalized === "update-user") return {
|
|
44
|
+
spanName: "auth.update_user",
|
|
45
|
+
operation: "update_user"
|
|
46
|
+
};
|
|
47
|
+
if (normalized.endsWith("/delete-user") || normalized === "delete-user") return {
|
|
48
|
+
spanName: "auth.delete_user",
|
|
49
|
+
operation: "delete_user"
|
|
50
|
+
};
|
|
51
|
+
if (normalized.endsWith("/change-password") || normalized === "change-password") return {
|
|
52
|
+
spanName: "auth.change_password",
|
|
53
|
+
operation: "change_password"
|
|
54
|
+
};
|
|
55
|
+
if (normalized.endsWith("/change-email") || normalized === "change-email") return {
|
|
56
|
+
spanName: "auth.change_email",
|
|
57
|
+
operation: "change_email"
|
|
58
|
+
};
|
|
59
|
+
if (normalized.endsWith("/verify-email") || normalized === "verify-email") return {
|
|
60
|
+
spanName: "auth.verify_email",
|
|
61
|
+
operation: "verify_email"
|
|
62
|
+
};
|
|
63
|
+
if (normalized.endsWith("/forget-password") || normalized === "forget-password") return {
|
|
64
|
+
spanName: "auth.forgot_password",
|
|
65
|
+
operation: "forgot_password"
|
|
66
|
+
};
|
|
67
|
+
if (normalized.endsWith("/reset-password") || normalized === "reset-password") return {
|
|
68
|
+
spanName: "auth.reset_password",
|
|
69
|
+
operation: "reset_password"
|
|
70
|
+
};
|
|
71
|
+
if (normalized.endsWith("/list-sessions") || normalized === "list-sessions") return {
|
|
72
|
+
spanName: "auth.list_sessions",
|
|
73
|
+
operation: "list_sessions"
|
|
74
|
+
};
|
|
75
|
+
if (normalized.endsWith("/revoke-session") || normalized === "revoke-session") return {
|
|
76
|
+
spanName: "auth.revoke_session",
|
|
77
|
+
operation: "revoke_session"
|
|
78
|
+
};
|
|
79
|
+
const callbackMatch = normalized.match(/\/callback\/([^/?]+)/);
|
|
80
|
+
if (callbackMatch) {
|
|
81
|
+
const provider = callbackMatch[1];
|
|
82
|
+
return {
|
|
83
|
+
spanName: `auth.oauth.callback.${provider}`,
|
|
84
|
+
operation: "oauth_callback",
|
|
85
|
+
method: "oauth",
|
|
86
|
+
provider
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const signinMatch = normalized.match(/\/sign-in\/([^/?]+)$/);
|
|
90
|
+
if (signinMatch && signinMatch[1] !== "email") {
|
|
91
|
+
const provider = signinMatch[1];
|
|
92
|
+
return {
|
|
93
|
+
spanName: `auth.oauth.initiate.${provider}`,
|
|
94
|
+
operation: "oauth_initiate",
|
|
95
|
+
method: "oauth",
|
|
96
|
+
provider
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const segments = normalized.split("/");
|
|
100
|
+
return {
|
|
101
|
+
spanName: `auth.${(segments[segments.length - 1] || "unknown").replace(/-/g, "_")}`,
|
|
102
|
+
operation: "unknown"
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function round(n) {
|
|
106
|
+
return Math.round(n * 100) / 100;
|
|
107
|
+
}
|
|
108
|
+
function extractUserData(returned) {
|
|
109
|
+
const result = {};
|
|
110
|
+
if (!returned || typeof returned !== "object") return result;
|
|
111
|
+
const data = returned.data ?? returned;
|
|
112
|
+
if (data.user?.id) result.userId = String(data.user.id);
|
|
113
|
+
if (data.user?.email) result.userEmail = String(data.user.email);
|
|
114
|
+
if (data.session?.id) result.sessionId = String(data.session.id);
|
|
115
|
+
if (!result.userId && returned.id && returned.email) {
|
|
116
|
+
result.userId = String(returned.id);
|
|
117
|
+
result.userEmail = String(returned.email);
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
const requestMetas = /* @__PURE__ */ new WeakMap();
|
|
122
|
+
/**
|
|
123
|
+
* Creates a Better Auth plugin that auto-traces all auth operations
|
|
124
|
+
* into silgi analytics spans.
|
|
125
|
+
*
|
|
126
|
+
* @param config - Optional configuration
|
|
127
|
+
* @returns A Better Auth plugin (typed as `any` to avoid requiring better-auth types at build time)
|
|
128
|
+
*/
|
|
129
|
+
function tracing(config) {
|
|
130
|
+
const captureInput = config?.captureInput ?? true;
|
|
131
|
+
const captureOutput = config?.captureOutput ?? true;
|
|
132
|
+
return {
|
|
133
|
+
id: "silgi-tracing",
|
|
134
|
+
onRequest: async (request, _ctx) => {
|
|
135
|
+
try {
|
|
136
|
+
const path = new URL(request.url).pathname;
|
|
137
|
+
const match = matchOperation(path);
|
|
138
|
+
requestMetas.set(request, {
|
|
139
|
+
startTime: performance.now(),
|
|
140
|
+
path,
|
|
141
|
+
operation: match.operation,
|
|
142
|
+
method: match.method,
|
|
143
|
+
provider: match.provider,
|
|
144
|
+
spanName: match.spanName
|
|
145
|
+
});
|
|
146
|
+
} catch {}
|
|
147
|
+
},
|
|
148
|
+
hooks: { after: [{
|
|
149
|
+
matcher: () => true,
|
|
150
|
+
handler: (config?.createAuthMiddleware ?? ((fn) => fn))(async (ctx) => {
|
|
151
|
+
try {
|
|
152
|
+
const request = ctx.request;
|
|
153
|
+
if (!request) return;
|
|
154
|
+
const silgiCtx = request.__silgiCtx;
|
|
155
|
+
if (!silgiCtx) return;
|
|
156
|
+
const reqTrace = silgiCtx.__analyticsTrace;
|
|
157
|
+
if (!reqTrace) return;
|
|
158
|
+
const meta = requestMetas.get(request);
|
|
159
|
+
requestMetas.delete(request);
|
|
160
|
+
const path = ctx.path || "";
|
|
161
|
+
const match = meta ? {
|
|
162
|
+
spanName: meta.spanName,
|
|
163
|
+
operation: meta.operation,
|
|
164
|
+
method: meta.method,
|
|
165
|
+
provider: meta.provider
|
|
166
|
+
} : matchOperation(path);
|
|
167
|
+
const startTime = meta?.startTime ?? performance.now();
|
|
168
|
+
const durationMs = round(performance.now() - startTime);
|
|
169
|
+
const returned = ctx.context?.returned;
|
|
170
|
+
const newSession = ctx.context?.newSession;
|
|
171
|
+
const userData = extractUserData(returned);
|
|
172
|
+
if (!userData.userId && newSession?.user?.id) userData.userId = String(newSession.user.id);
|
|
173
|
+
if (!userData.userEmail && newSession?.user?.email) userData.userEmail = String(newSession.user.email);
|
|
174
|
+
if (!userData.sessionId && newSession?.session?.id) userData.sessionId = String(newSession.session.id);
|
|
175
|
+
const success = !returned?.error && !ctx.context?.error;
|
|
176
|
+
const attributes = {
|
|
177
|
+
"auth.operation": match.operation,
|
|
178
|
+
"auth.success": success
|
|
179
|
+
};
|
|
180
|
+
if (match.method) attributes["auth.method"] = match.method;
|
|
181
|
+
if (match.provider) attributes["auth.provider"] = match.provider;
|
|
182
|
+
if (userData.userId) attributes["user.id"] = userData.userId;
|
|
183
|
+
if (userData.userEmail) attributes["user.email"] = userData.userEmail;
|
|
184
|
+
if (userData.sessionId) attributes["session.id"] = userData.sessionId;
|
|
185
|
+
const span = {
|
|
186
|
+
name: match.spanName,
|
|
187
|
+
kind: "http",
|
|
188
|
+
durationMs,
|
|
189
|
+
startOffsetMs: round(startTime - reqTrace.t0),
|
|
190
|
+
attributes
|
|
191
|
+
};
|
|
192
|
+
if (captureInput && ctx.body) span.input = ctx.body;
|
|
193
|
+
if (captureOutput && returned && typeof returned === "object") span.output = returned;
|
|
194
|
+
if (!success && returned?.error) span.error = typeof returned.error === "string" ? returned.error : returned.error?.message ?? "error";
|
|
195
|
+
reqTrace.spans.push(span);
|
|
196
|
+
if (captureInput && ctx.body) reqTrace.procedureInput = ctx.body;
|
|
197
|
+
if (captureOutput && returned && typeof returned === "object") reqTrace.procedureOutput = returned;
|
|
198
|
+
} catch {}
|
|
199
|
+
})
|
|
200
|
+
}] }
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const API_METHOD_METADATA = {
|
|
204
|
+
getSession: { operation: "get_session" },
|
|
205
|
+
signOut: { operation: "signout" },
|
|
206
|
+
signInEmail: {
|
|
207
|
+
operation: "signin",
|
|
208
|
+
method: "email"
|
|
209
|
+
},
|
|
210
|
+
signUpEmail: {
|
|
211
|
+
operation: "signup",
|
|
212
|
+
method: "email"
|
|
213
|
+
},
|
|
214
|
+
signInSocial: {
|
|
215
|
+
operation: "signin",
|
|
216
|
+
method: "oauth"
|
|
217
|
+
},
|
|
218
|
+
callbackOAuth: {
|
|
219
|
+
operation: "oauth_callback",
|
|
220
|
+
method: "oauth"
|
|
221
|
+
},
|
|
222
|
+
linkSocialAccount: {
|
|
223
|
+
operation: "link_social_account",
|
|
224
|
+
method: "oauth"
|
|
225
|
+
},
|
|
226
|
+
unlinkAccount: { operation: "unlink_account" },
|
|
227
|
+
listUserAccounts: { operation: "list_user_accounts" },
|
|
228
|
+
updateUser: { operation: "update_user" },
|
|
229
|
+
deleteUser: { operation: "delete_user" },
|
|
230
|
+
changePassword: { operation: "change_password" },
|
|
231
|
+
setPassword: { operation: "set_password" },
|
|
232
|
+
changeEmail: { operation: "change_email" },
|
|
233
|
+
verifyEmail: { operation: "verify_email" },
|
|
234
|
+
sendVerificationEmail: { operation: "send_verification_email" },
|
|
235
|
+
forgetPassword: { operation: "forget_password" },
|
|
236
|
+
resetPassword: { operation: "reset_password" },
|
|
237
|
+
listSessions: { operation: "list_sessions" },
|
|
238
|
+
revokeSession: { operation: "revoke_session" },
|
|
239
|
+
revokeSessions: { operation: "revoke_sessions" },
|
|
240
|
+
revokeOtherSessions: { operation: "revoke_other_sessions" },
|
|
241
|
+
refreshToken: { operation: "refresh_token" },
|
|
242
|
+
getAccessToken: { operation: "get_access_token" }
|
|
243
|
+
};
|
|
244
|
+
const AUTH_INSTRUMENTED = "__silgiBetterAuthInstrumented";
|
|
245
|
+
/**
|
|
246
|
+
* Instrument a Better Auth instance to trace all `auth.api.*` method calls.
|
|
247
|
+
* Works with `withCtx` — programmatic calls from background jobs,
|
|
248
|
+
* server-side session fetches etc. are traced when context is available.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* import { instrumentBetterAuth, withCtx } from 'silgi/better-auth'
|
|
253
|
+
*
|
|
254
|
+
* const auth = instrumentBetterAuth(betterAuth({ ... }))
|
|
255
|
+
*
|
|
256
|
+
* // In a silgi procedure:
|
|
257
|
+
* const me = s.$resolve(async ({ ctx }) => {
|
|
258
|
+
* return withCtx(ctx, () => auth.api.getSession({ headers: ctx.headers }))
|
|
259
|
+
* })
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
function instrumentBetterAuth(auth) {
|
|
263
|
+
if (!auth || auth[AUTH_INSTRUMENTED]) return auth;
|
|
264
|
+
const api = auth.api;
|
|
265
|
+
if (!api || typeof api !== "object") return auth;
|
|
266
|
+
const instrumented = /* @__PURE__ */ new Set();
|
|
267
|
+
for (const [methodName, metadata] of Object.entries(API_METHOD_METADATA)) if (typeof api[methodName] === "function") {
|
|
268
|
+
api[methodName] = wrapApiMethod(api[methodName], metadata.operation, metadata.method);
|
|
269
|
+
instrumented.add(methodName);
|
|
270
|
+
}
|
|
271
|
+
for (const key of Object.keys(api)) if (typeof api[key] === "function" && !instrumented.has(key) && !key.startsWith("$") && !key.startsWith("_")) {
|
|
272
|
+
const operation = key.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "");
|
|
273
|
+
api[key] = wrapApiMethod(api[key], operation);
|
|
274
|
+
instrumented.add(key);
|
|
275
|
+
}
|
|
276
|
+
auth[AUTH_INSTRUMENTED] = true;
|
|
277
|
+
return auth;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Run a function with silgi context available to instrumented Better Auth API calls.
|
|
281
|
+
*/
|
|
282
|
+
function withCtx(ctx, fn) {
|
|
283
|
+
return runWithCtx(ctx, fn);
|
|
284
|
+
}
|
|
285
|
+
function wrapApiMethod(originalFn, operation, method) {
|
|
286
|
+
return async function instrumented(...args) {
|
|
287
|
+
const reqTrace = getCtx()?.__analyticsTrace;
|
|
288
|
+
if (!reqTrace) return originalFn.apply(this, args);
|
|
289
|
+
const spanName = `auth.api.${operation}`;
|
|
290
|
+
const start = performance.now();
|
|
291
|
+
const attributes = {
|
|
292
|
+
"auth.operation": operation,
|
|
293
|
+
"auth.success": true
|
|
294
|
+
};
|
|
295
|
+
if (method) attributes["auth.method"] = method;
|
|
296
|
+
try {
|
|
297
|
+
const result = await originalFn.apply(this, args);
|
|
298
|
+
const data = result?.data ?? result;
|
|
299
|
+
if (data?.user?.id) attributes["user.id"] = String(data.user.id);
|
|
300
|
+
if (data?.user?.email) attributes["user.email"] = String(data.user.email);
|
|
301
|
+
if (data?.session?.id) attributes["session.id"] = String(data.session.id);
|
|
302
|
+
if (result?.error) {
|
|
303
|
+
attributes["auth.success"] = false;
|
|
304
|
+
attributes["auth.error"] = typeof result.error === "string" ? result.error : result.error?.message ?? "unknown";
|
|
305
|
+
}
|
|
306
|
+
reqTrace.spans.push({
|
|
307
|
+
name: spanName,
|
|
308
|
+
kind: "http",
|
|
309
|
+
durationMs: round(performance.now() - start),
|
|
310
|
+
startOffsetMs: round(start - reqTrace.t0),
|
|
311
|
+
attributes,
|
|
312
|
+
output: result && typeof result === "object" ? result : void 0
|
|
313
|
+
});
|
|
314
|
+
return result;
|
|
315
|
+
} catch (error) {
|
|
316
|
+
attributes["auth.success"] = false;
|
|
317
|
+
attributes["auth.error"] = error instanceof Error ? error.message : String(error);
|
|
318
|
+
reqTrace.spans.push({
|
|
319
|
+
name: spanName,
|
|
320
|
+
kind: "http",
|
|
321
|
+
durationMs: round(performance.now() - start),
|
|
322
|
+
startOffsetMs: round(start - reqTrace.t0),
|
|
323
|
+
attributes,
|
|
324
|
+
error: error instanceof Error ? error.stack ?? error.message : String(error)
|
|
325
|
+
});
|
|
326
|
+
throw error;
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
//#endregion
|
|
331
|
+
export { instrumentBetterAuth, tracing, withCtx };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/integrations/drizzle/index.d.ts
|
|
2
|
+
interface InstrumentDrizzleConfig {
|
|
3
|
+
/** Logical database name (e.g. 'auth', 'ecommerce') */
|
|
4
|
+
dbName?: string;
|
|
5
|
+
/** Database system identifier. Default: 'postgresql' */
|
|
6
|
+
dbSystem?: string;
|
|
7
|
+
/** Capture SQL query text in spans. Default: true */
|
|
8
|
+
captureQueryText?: boolean;
|
|
9
|
+
/** Max query text length before truncation. Default: 1000 */
|
|
10
|
+
maxQueryTextLength?: number;
|
|
11
|
+
/** Database host */
|
|
12
|
+
peerName?: string;
|
|
13
|
+
/** Database port */
|
|
14
|
+
peerPort?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Instrument a Drizzle db instance to record query spans in silgi analytics.
|
|
18
|
+
* Returns the same db instance (mutated). Safe to call multiple times.
|
|
19
|
+
*/
|
|
20
|
+
declare function instrumentDrizzle<T extends Record<string, any>>(db: T, config?: InstrumentDrizzleConfig): T;
|
|
21
|
+
/**
|
|
22
|
+
* Run a function with silgi context available to instrumented Drizzle instances.
|
|
23
|
+
* All Drizzle queries inside `fn` will be recorded as trace spans.
|
|
24
|
+
*/
|
|
25
|
+
declare function withCtx<T>(ctx: Record<string, unknown>, fn: () => T): T;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { InstrumentDrizzleConfig, instrumentDrizzle, withCtx };
|