silgi 0.43.29 → 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 -92
- 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
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { getCtx, runWithCtx } from "../../core/context-bridge.mjs";
|
|
2
|
+
//#region src/integrations/drizzle/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Silgi + Drizzle ORM tracing integration.
|
|
5
|
+
*
|
|
6
|
+
* Wraps Drizzle session methods to intercept every query and record
|
|
7
|
+
* spans in silgi analytics. Uses AsyncLocalStorage to bridge request
|
|
8
|
+
* context to the DB layer.
|
|
9
|
+
*
|
|
10
|
+
* Patching priority (inspired by @kubiks/otel-drizzle):
|
|
11
|
+
* 1. `db.session.prepareQuery` — wrap returned prepared.execute (main ORM path)
|
|
12
|
+
* 2. `db.session.query` — for direct string queries
|
|
13
|
+
* 3. `db.session.transaction` — re-instrument tx session per transaction call
|
|
14
|
+
* 4. `db.$client.query` or `db.$client.execute` — fallback to raw driver
|
|
15
|
+
* 5. `db._.session.execute` — deep internal fallback
|
|
16
|
+
*
|
|
17
|
+
* Instance patching, NOT prototype patching. Idempotent via flag.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { instrumentDrizzle, withCtx } from 'silgi/drizzle'
|
|
22
|
+
*
|
|
23
|
+
* const db = instrumentDrizzle(drizzle(url, { schema }), {
|
|
24
|
+
* dbName: 'ecommerce',
|
|
25
|
+
* peerName: 'db.example.com',
|
|
26
|
+
* peerPort: 5432,
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* const listUsers = s.$resolve(async ({ ctx }) => {
|
|
30
|
+
* return withCtx(ctx, () => db.select().from(users))
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
const INSTRUMENTED = "__silgiDrizzleInstrumented";
|
|
35
|
+
const DEFAULT_DB_SYSTEM = "postgresql";
|
|
36
|
+
const DEFAULT_MAX_QUERY_LENGTH = 1e3;
|
|
37
|
+
/**
|
|
38
|
+
* Instrument a Drizzle db instance to record query spans in silgi analytics.
|
|
39
|
+
* Returns the same db instance (mutated). Safe to call multiple times.
|
|
40
|
+
*/
|
|
41
|
+
function instrumentDrizzle(db, config) {
|
|
42
|
+
if (!db || db[INSTRUMENTED]) return db;
|
|
43
|
+
const cfg = resolveConfig(config);
|
|
44
|
+
let instrumented = false;
|
|
45
|
+
const session = db.session ?? db._?.session;
|
|
46
|
+
if (session) instrumented = patchSession(session, cfg, false);
|
|
47
|
+
if (!instrumented && db.$client) instrumented = patchRawClient(db.$client, cfg);
|
|
48
|
+
if (!instrumented && db._?.session && typeof db._.session.execute === "function") instrumented = patchSessionExecute(db._.session, cfg);
|
|
49
|
+
if (!instrumented) {
|
|
50
|
+
console.warn("[silgi/drizzle] Could not find any patchable method — skipping instrumentation");
|
|
51
|
+
return db;
|
|
52
|
+
}
|
|
53
|
+
db[INSTRUMENTED] = true;
|
|
54
|
+
return db;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Run a function with silgi context available to instrumented Drizzle instances.
|
|
58
|
+
* All Drizzle queries inside `fn` will be recorded as trace spans.
|
|
59
|
+
*/
|
|
60
|
+
function withCtx(ctx, fn) {
|
|
61
|
+
return runWithCtx(ctx, fn);
|
|
62
|
+
}
|
|
63
|
+
function resolveConfig(config) {
|
|
64
|
+
return {
|
|
65
|
+
dbSystem: config?.dbSystem ?? DEFAULT_DB_SYSTEM,
|
|
66
|
+
dbName: config?.dbName,
|
|
67
|
+
captureQueryText: config?.captureQueryText !== false,
|
|
68
|
+
maxQueryTextLength: config?.maxQueryTextLength ?? DEFAULT_MAX_QUERY_LENGTH,
|
|
69
|
+
peerName: config?.peerName,
|
|
70
|
+
peerPort: config?.peerPort
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Patch session.prepareQuery, session.query, and session.transaction.
|
|
75
|
+
* Returns true if any method was patched.
|
|
76
|
+
*/
|
|
77
|
+
function patchSession(session, cfg, isTx) {
|
|
78
|
+
const flagSuffix = isTx ? "_tx" : "";
|
|
79
|
+
if (session[INSTRUMENTED + flagSuffix]) return true;
|
|
80
|
+
let patched = false;
|
|
81
|
+
if (typeof session.prepareQuery === "function") {
|
|
82
|
+
const originalPrepareQuery = session.prepareQuery.bind(session);
|
|
83
|
+
session.prepareQuery = function patchedPrepareQuery(...args) {
|
|
84
|
+
const prepared = originalPrepareQuery.apply(this, args);
|
|
85
|
+
if (!prepared || typeof prepared.execute !== "function") return prepared;
|
|
86
|
+
const reqTrace = getCtx()?.__analyticsTrace;
|
|
87
|
+
if (!reqTrace) return prepared;
|
|
88
|
+
const queryText = extractQueryText(args[0]) ?? prepared.rawQueryConfig?.text ?? prepared.queryConfig?.text ?? null;
|
|
89
|
+
const originalExecute = prepared.execute.bind(prepared);
|
|
90
|
+
prepared.execute = function tracedExecute(...execArgs) {
|
|
91
|
+
return traceExecution(reqTrace, cfg, queryText, isTx, originalExecute, this, execArgs);
|
|
92
|
+
};
|
|
93
|
+
return prepared;
|
|
94
|
+
};
|
|
95
|
+
patched = true;
|
|
96
|
+
}
|
|
97
|
+
if (typeof session.query === "function") {
|
|
98
|
+
const originalQuery = session.query.bind(session);
|
|
99
|
+
session.query = function patchedQuery(queryString, params) {
|
|
100
|
+
const reqTrace = getCtx()?.__analyticsTrace;
|
|
101
|
+
if (!reqTrace) return originalQuery.call(this, queryString, params);
|
|
102
|
+
return traceExecution(reqTrace, cfg, queryString ?? null, isTx, originalQuery, this, [queryString, params]);
|
|
103
|
+
};
|
|
104
|
+
patched = true;
|
|
105
|
+
}
|
|
106
|
+
if (!isTx && typeof session.transaction === "function") {
|
|
107
|
+
const originalTransaction = session.transaction.bind(session);
|
|
108
|
+
session.transaction = function patchedTransaction(callback, txConfig) {
|
|
109
|
+
return originalTransaction.call(this, (tx) => {
|
|
110
|
+
const txSession = tx.session ?? tx;
|
|
111
|
+
if (txSession && typeof txSession.prepareQuery === "function") patchSession(txSession, cfg, true);
|
|
112
|
+
return callback(tx);
|
|
113
|
+
}, txConfig);
|
|
114
|
+
};
|
|
115
|
+
patched = true;
|
|
116
|
+
}
|
|
117
|
+
if (patched) session[INSTRUMENTED + flagSuffix] = true;
|
|
118
|
+
return patched;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Patch $client.query or $client.execute as fallback for raw driver access.
|
|
122
|
+
*/
|
|
123
|
+
function patchRawClient(client, cfg) {
|
|
124
|
+
if (!client || client[INSTRUMENTED]) return false;
|
|
125
|
+
const methodName = typeof client.query === "function" ? "query" : typeof client.execute === "function" ? "execute" : null;
|
|
126
|
+
if (!methodName) return false;
|
|
127
|
+
const originalMethod = client[methodName].bind(client);
|
|
128
|
+
client[methodName] = function patchedClientMethod(...args) {
|
|
129
|
+
const reqTrace = getCtx()?.__analyticsTrace;
|
|
130
|
+
if (!reqTrace) return originalMethod.apply(this, args);
|
|
131
|
+
return traceExecution(reqTrace, cfg, extractQueryText(args[0]) ?? null, false, originalMethod, this, args);
|
|
132
|
+
};
|
|
133
|
+
client[INSTRUMENTED] = true;
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Patch db._.session.execute as deep internal fallback.
|
|
138
|
+
*/
|
|
139
|
+
function patchSessionExecute(session, cfg) {
|
|
140
|
+
if (session[INSTRUMENTED]) return false;
|
|
141
|
+
const originalExecute = session.execute.bind(session);
|
|
142
|
+
session.execute = function patchedDeepExecute(...args) {
|
|
143
|
+
const reqTrace = getCtx()?.__analyticsTrace;
|
|
144
|
+
if (!reqTrace) return originalExecute.apply(this, args);
|
|
145
|
+
return traceExecution(reqTrace, cfg, extractQueryText(args[0]) ?? null, false, originalExecute, this, args);
|
|
146
|
+
};
|
|
147
|
+
session[INSTRUMENTED] = true;
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Execute a function and record a trace span with timing, attributes, and error handling.
|
|
152
|
+
* Handles both sync and async (Promise) return values.
|
|
153
|
+
*/
|
|
154
|
+
function traceExecution(reqTrace, cfg, queryText, isTx, fn, thisArg, args) {
|
|
155
|
+
const spanName = buildSpanName(queryText, isTx);
|
|
156
|
+
const attributes = buildAttributes(cfg, queryText, isTx);
|
|
157
|
+
const start = performance.now();
|
|
158
|
+
try {
|
|
159
|
+
const result = fn.apply(thisArg, args);
|
|
160
|
+
if (result instanceof Promise) return result.then((value) => {
|
|
161
|
+
pushSpan(reqTrace, spanName, start, queryText, cfg, attributes, void 0);
|
|
162
|
+
return value;
|
|
163
|
+
}, (error) => {
|
|
164
|
+
pushSpan(reqTrace, spanName, start, queryText, cfg, attributes, error);
|
|
165
|
+
throw error;
|
|
166
|
+
});
|
|
167
|
+
pushSpan(reqTrace, spanName, start, queryText, cfg, attributes, void 0);
|
|
168
|
+
return result;
|
|
169
|
+
} catch (error) {
|
|
170
|
+
pushSpan(reqTrace, spanName, start, queryText, cfg, attributes, error);
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function pushSpan(reqTrace, name, start, queryText, cfg, attributes, error) {
|
|
175
|
+
const detail = cfg.captureQueryText && queryText ? truncateQuery(queryText, cfg.maxQueryTextLength) : void 0;
|
|
176
|
+
reqTrace.spans.push({
|
|
177
|
+
name,
|
|
178
|
+
kind: "db",
|
|
179
|
+
durationMs: round(performance.now() - start),
|
|
180
|
+
startOffsetMs: round(start - reqTrace.t0),
|
|
181
|
+
detail,
|
|
182
|
+
attributes,
|
|
183
|
+
error: error ? formatError(error) : void 0
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function buildAttributes(cfg, queryText, isTx) {
|
|
187
|
+
const attrs = { "db.system": cfg.dbSystem };
|
|
188
|
+
if (cfg.dbName) attrs["db.name"] = cfg.dbName;
|
|
189
|
+
if (cfg.peerName) attrs["net.peer.name"] = cfg.peerName;
|
|
190
|
+
if (cfg.peerPort) attrs["net.peer.port"] = cfg.peerPort;
|
|
191
|
+
if (isTx) attrs["db.transaction"] = true;
|
|
192
|
+
if (queryText) {
|
|
193
|
+
const op = extractOperationName(queryText);
|
|
194
|
+
if (op) attrs["db.operation"] = op;
|
|
195
|
+
if (cfg.captureQueryText) attrs["db.statement"] = truncateQuery(queryText, cfg.maxQueryTextLength);
|
|
196
|
+
}
|
|
197
|
+
return attrs;
|
|
198
|
+
}
|
|
199
|
+
function buildSpanName(queryText, isTx) {
|
|
200
|
+
const prefix = isTx ? "db.tx" : "db";
|
|
201
|
+
if (!queryText) return `${prefix}.query`;
|
|
202
|
+
const opInfo = extractOperationInfo(queryText);
|
|
203
|
+
if (!opInfo) return `${prefix}.query`;
|
|
204
|
+
return opInfo.table ? `${prefix}.${opInfo.op}.${opInfo.table}` : `${prefix}.${opInfo.op}`;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Extract SQL text from various query argument formats:
|
|
208
|
+
* - Plain string
|
|
209
|
+
* - { sql: string }
|
|
210
|
+
* - { text: string }
|
|
211
|
+
* - { queryString: string }
|
|
212
|
+
* - { queryChunks: ..., sql: string }
|
|
213
|
+
*/
|
|
214
|
+
function extractQueryText(queryArg) {
|
|
215
|
+
if (typeof queryArg === "string") return queryArg;
|
|
216
|
+
if (queryArg && typeof queryArg === "object") {
|
|
217
|
+
const q = queryArg;
|
|
218
|
+
if (typeof q.sql === "string") return q.sql;
|
|
219
|
+
if (typeof q.text === "string") return q.text;
|
|
220
|
+
if (typeof q.queryString === "string") return q.queryString;
|
|
221
|
+
if (typeof q.queryChunks === "object" && typeof q.sql === "string") return q.sql;
|
|
222
|
+
}
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
function truncateQuery(text, maxLength) {
|
|
226
|
+
if (text.length <= maxLength) return text;
|
|
227
|
+
return text.slice(0, maxLength) + "...";
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Parse the SQL operation and target table from query text.
|
|
231
|
+
* Returns lowercase op name and table for span naming.
|
|
232
|
+
*/
|
|
233
|
+
function extractOperationInfo(sql) {
|
|
234
|
+
const upper = sql.trimStart().toUpperCase();
|
|
235
|
+
if (upper.startsWith("SELECT")) return {
|
|
236
|
+
op: "select",
|
|
237
|
+
table: matchTable(sql, /from\s+"?(\w+)"?/i)
|
|
238
|
+
};
|
|
239
|
+
if (upper.startsWith("INSERT")) return {
|
|
240
|
+
op: "insert",
|
|
241
|
+
table: matchTable(sql, /into\s+"?(\w+)"?/i)
|
|
242
|
+
};
|
|
243
|
+
if (upper.startsWith("UPDATE")) return {
|
|
244
|
+
op: "update",
|
|
245
|
+
table: matchTable(sql, /update\s+"?(\w+)"?/i)
|
|
246
|
+
};
|
|
247
|
+
if (upper.startsWith("DELETE")) return {
|
|
248
|
+
op: "delete",
|
|
249
|
+
table: matchTable(sql, /from\s+"?(\w+)"?/i)
|
|
250
|
+
};
|
|
251
|
+
if (upper.startsWith("BEGIN") || upper.startsWith("START TRANSACTION")) return {
|
|
252
|
+
op: "begin",
|
|
253
|
+
table: null
|
|
254
|
+
};
|
|
255
|
+
if (upper.startsWith("COMMIT")) return {
|
|
256
|
+
op: "commit",
|
|
257
|
+
table: null
|
|
258
|
+
};
|
|
259
|
+
if (upper.startsWith("ROLLBACK")) return {
|
|
260
|
+
op: "rollback",
|
|
261
|
+
table: null
|
|
262
|
+
};
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Extract uppercase operation name for the db.operation attribute.
|
|
267
|
+
*/
|
|
268
|
+
function extractOperationName(sql) {
|
|
269
|
+
const trimmed = sql.trimStart();
|
|
270
|
+
const match = /^(\w+)/u.exec(trimmed);
|
|
271
|
+
return match ? match[1].toUpperCase() : null;
|
|
272
|
+
}
|
|
273
|
+
function matchTable(sql, pattern) {
|
|
274
|
+
const m = sql.match(pattern);
|
|
275
|
+
return m ? m[1] : null;
|
|
276
|
+
}
|
|
277
|
+
function formatError(error) {
|
|
278
|
+
if (error instanceof Error) return error.stack ?? `${error.name}: ${error.message}`;
|
|
279
|
+
return String(error);
|
|
280
|
+
}
|
|
281
|
+
function round(n) {
|
|
282
|
+
return Math.round(n * 100) / 100;
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
export { instrumentDrizzle, withCtx };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SilgiError } from "../../core/error.mjs";
|
|
2
|
+
import { Client } from "../../client/types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/integrations/hey-api/to-client.d.ts
|
|
5
|
+
type ToClientResult<T extends Record<string, any>> = { [K in keyof T]: T[K] extends ((options: infer UInput) => Promise<infer UResult>) ? Client<Record<never, never>, UInput, {
|
|
6
|
+
body: UResult extends {
|
|
7
|
+
data: infer USuccess;
|
|
8
|
+
} ? Exclude<USuccess, undefined> : never;
|
|
9
|
+
request: Request;
|
|
10
|
+
response: Response;
|
|
11
|
+
}, SilgiError> : T[K] extends Record<string, any> ? ToClientResult<T[K]> : never };
|
|
12
|
+
/**
|
|
13
|
+
* Convert a Hey API SDK to a Silgi client.
|
|
14
|
+
*
|
|
15
|
+
* This allows you to use any Hey API generated client with the Silgi
|
|
16
|
+
* ecosystem — including TanStack Query, Pinia Colada, and other integrations.
|
|
17
|
+
*/
|
|
18
|
+
declare function toClient<T extends Record<string, any>>(sdk: T): ToClientResult<T>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { ToClientResult, toClient };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/integrations/hey-api/to-client.ts
|
|
2
|
+
/**
|
|
3
|
+
* Convert a Hey API SDK to a Silgi client.
|
|
4
|
+
*
|
|
5
|
+
* This allows you to use any Hey API generated client with the Silgi
|
|
6
|
+
* ecosystem — including TanStack Query, Pinia Colada, and other integrations.
|
|
7
|
+
*/
|
|
8
|
+
function toClient(sdk) {
|
|
9
|
+
const client = {};
|
|
10
|
+
for (const key in sdk) {
|
|
11
|
+
const fn = sdk[key];
|
|
12
|
+
if (!fn || typeof fn !== "function") continue;
|
|
13
|
+
client[key] = async (input, options) => {
|
|
14
|
+
const controller = new AbortController();
|
|
15
|
+
if (input?.signal?.aborted || options?.signal?.aborted) controller.abort();
|
|
16
|
+
else {
|
|
17
|
+
input?.signal?.addEventListener("abort", () => controller.abort());
|
|
18
|
+
options?.signal?.addEventListener("abort", () => controller.abort());
|
|
19
|
+
}
|
|
20
|
+
const result = await fn({
|
|
21
|
+
...input,
|
|
22
|
+
signal: controller.signal,
|
|
23
|
+
headers: {
|
|
24
|
+
...input?.headers,
|
|
25
|
+
...typeof options?.lastEventId === "string" ? { "last-event-id": options.lastEventId } : {}
|
|
26
|
+
},
|
|
27
|
+
throwOnError: true
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
body: result.data,
|
|
31
|
+
request: result.request,
|
|
32
|
+
response: result.response
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return client;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { toClient };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BuildKeyOptions } from "./key.mjs";
|
|
2
|
+
import { EntryKey } from "@pinia/colada";
|
|
3
|
+
|
|
4
|
+
//#region src/integrations/pinia-colada/general-utils.d.ts
|
|
5
|
+
interface GeneralUtils<TInput> {
|
|
6
|
+
/**
|
|
7
|
+
* Generate a query/mutation key for checking status, invalidate, set, get, etc.
|
|
8
|
+
*/
|
|
9
|
+
key(options?: BuildKeyOptions<TInput>): EntryKey;
|
|
10
|
+
}
|
|
11
|
+
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { GeneralUtils, createGeneralUtils };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BuildKeyOptions, PartialDeep, buildKey } from "./key.mjs";
|
|
2
|
+
import { GeneralUtils, createGeneralUtils } from "./general-utils.mjs";
|
|
3
|
+
import { MaybeOptionalOptions, MutationOptions, MutationOptionsIn, QueryOptions, QueryOptionsIn, UseQueryFnContext } from "./types.mjs";
|
|
4
|
+
import { CreateProcedureUtilsOptions, ProcedureUtils, createProcedureUtils } from "./procedure-utils.mjs";
|
|
5
|
+
import { CreateRouterUtilsOptions, RouterUtils, createRouterUtils } from "./router-utils.mjs";
|
|
6
|
+
export { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, MaybeOptionalOptions, MutationOptions, MutationOptionsIn, PartialDeep, ProcedureUtils, QueryOptions, QueryOptionsIn, RouterUtils, UseQueryFnContext, buildKey, createRouterUtils as createColadaUtils, createGeneralUtils, createProcedureUtils, createRouterUtils };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { buildKey } from "./key.mjs";
|
|
2
|
+
import { createGeneralUtils } from "./general-utils.mjs";
|
|
3
|
+
import { createProcedureUtils } from "./procedure-utils.mjs";
|
|
4
|
+
import { createRouterUtils } from "./router-utils.mjs";
|
|
5
|
+
export { buildKey, createRouterUtils as createColadaUtils, createGeneralUtils, createProcedureUtils, createRouterUtils };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EntryKey } from "@pinia/colada";
|
|
2
|
+
|
|
3
|
+
//#region src/integrations/pinia-colada/key.d.ts
|
|
4
|
+
type PartialDeep<T> = T extends object ? { [K in keyof T]?: PartialDeep<T[K]> } : T;
|
|
5
|
+
interface BuildKeyOptions<TInput> {
|
|
6
|
+
type?: 'query' | 'mutation';
|
|
7
|
+
input?: PartialDeep<TInput>;
|
|
8
|
+
}
|
|
9
|
+
declare function buildKey<TInput>(path: string[], options?: BuildKeyOptions<TInput>): EntryKey;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { BuildKeyOptions, PartialDeep, buildKey };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/integrations/pinia-colada/key.ts
|
|
2
|
+
function buildKey(path, options = {}) {
|
|
3
|
+
const withInput = options.input !== void 0 ? { input: options.input } : {};
|
|
4
|
+
const withType = options.type !== void 0 ? { type: options.type } : {};
|
|
5
|
+
return [path, {
|
|
6
|
+
...withInput,
|
|
7
|
+
...withType
|
|
8
|
+
}];
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { buildKey };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Client, ClientContext } from "../../client/types.mjs";
|
|
2
|
+
import { MaybeOptionalOptions, MutationOptions, MutationOptionsIn, QueryOptions, QueryOptionsIn } from "./types.mjs";
|
|
3
|
+
import { _EmptyObject } from "@pinia/colada";
|
|
4
|
+
|
|
5
|
+
//#region src/integrations/pinia-colada/procedure-utils.d.ts
|
|
6
|
+
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
7
|
+
/**
|
|
8
|
+
* Calling corresponding procedure client
|
|
9
|
+
*/
|
|
10
|
+
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
11
|
+
/**
|
|
12
|
+
* Generate options used for useQuery
|
|
13
|
+
*/
|
|
14
|
+
queryOptions<UInitialData extends TOutput | undefined = TOutput | undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError, UInitialData>>): NoInfer<QueryOptions<TOutput, TError, UInitialData>>;
|
|
15
|
+
/**
|
|
16
|
+
* Generate options used for useMutation
|
|
17
|
+
*/
|
|
18
|
+
mutationOptions<UMutationContext extends Record<any, any> = _EmptyObject>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptions<TInput, TOutput, TError, UMutationContext>>;
|
|
19
|
+
}
|
|
20
|
+
interface CreateProcedureUtilsOptions {
|
|
21
|
+
path: string[];
|
|
22
|
+
}
|
|
23
|
+
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { CreateProcedureUtilsOptions, ProcedureUtils, createProcedureUtils };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { buildKey } from "./key.mjs";
|
|
2
|
+
import { computed, toValue } from "vue";
|
|
3
|
+
//#region src/integrations/pinia-colada/procedure-utils.ts
|
|
4
|
+
function createProcedureUtils(client, options) {
|
|
5
|
+
return {
|
|
6
|
+
call: client,
|
|
7
|
+
queryOptions(...[{ input, context, ...rest } = {}]) {
|
|
8
|
+
return {
|
|
9
|
+
key: computed(() => buildKey(options.path, {
|
|
10
|
+
type: "query",
|
|
11
|
+
input: toValue(input)
|
|
12
|
+
})),
|
|
13
|
+
query: ({ signal }) => client(toValue(input), {
|
|
14
|
+
signal,
|
|
15
|
+
context: toValue(context)
|
|
16
|
+
}),
|
|
17
|
+
...rest
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
mutationOptions(...[{ context, ...rest } = {}]) {
|
|
21
|
+
return {
|
|
22
|
+
key: (input) => buildKey(options.path, {
|
|
23
|
+
type: "mutation",
|
|
24
|
+
input
|
|
25
|
+
}),
|
|
26
|
+
mutation: (input) => client(input, { context: toValue(context) }),
|
|
27
|
+
...rest
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { createProcedureUtils };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Client, NestedClient } from "../../client/types.mjs";
|
|
2
|
+
import { GeneralUtils } from "./general-utils.mjs";
|
|
3
|
+
import { ProcedureUtils } from "./procedure-utils.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/integrations/pinia-colada/router-utils.d.ts
|
|
6
|
+
type RouterUtils<T extends NestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : { [K in keyof T]: T[K] extends NestedClient ? RouterUtils<T[K]> : never } & GeneralUtils<unknown>;
|
|
7
|
+
interface CreateRouterUtilsOptions {
|
|
8
|
+
path?: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create Pinia Colada utilities from a Silgi client.
|
|
12
|
+
*
|
|
13
|
+
* Both client-side and server-side clients are supported.
|
|
14
|
+
*/
|
|
15
|
+
declare function createRouterUtils<T extends NestedClient>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { CreateRouterUtilsOptions, RouterUtils, createRouterUtils };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createGeneralUtils } from "./general-utils.mjs";
|
|
2
|
+
import { createProcedureUtils } from "./procedure-utils.mjs";
|
|
3
|
+
//#region src/integrations/pinia-colada/router-utils.ts
|
|
4
|
+
/**
|
|
5
|
+
* Create Pinia Colada utilities from a Silgi client.
|
|
6
|
+
*
|
|
7
|
+
* Both client-side and server-side clients are supported.
|
|
8
|
+
*/
|
|
9
|
+
function createRouterUtils(client, options = {}) {
|
|
10
|
+
const path = options.path ?? [];
|
|
11
|
+
const generalUtils = createGeneralUtils(path);
|
|
12
|
+
const procedureUtils = createProcedureUtils(client, { path });
|
|
13
|
+
return new Proxy({
|
|
14
|
+
...generalUtils,
|
|
15
|
+
...procedureUtils
|
|
16
|
+
}, { get(target, prop) {
|
|
17
|
+
const value = Reflect.get(target, prop);
|
|
18
|
+
if (typeof prop !== "string") return value;
|
|
19
|
+
const nextUtils = createRouterUtils(client[prop], {
|
|
20
|
+
...options,
|
|
21
|
+
path: [...path, prop]
|
|
22
|
+
});
|
|
23
|
+
if (typeof value !== "function") return nextUtils;
|
|
24
|
+
return new Proxy(value, { get(_, prop) {
|
|
25
|
+
return Reflect.get(nextUtils, prop);
|
|
26
|
+
} });
|
|
27
|
+
} });
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { createRouterUtils };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ClientContext } from "../../client/types.mjs";
|
|
2
|
+
import { MaybeRefOrGetter } from "vue";
|
|
3
|
+
import { UseMutationOptions, UseQueryOptions } from "@pinia/colada";
|
|
4
|
+
|
|
5
|
+
//#region src/integrations/pinia-colada/types.d.ts
|
|
6
|
+
type MaybeOptionalOptions<T> = Partial<T> extends T ? [options?: T] : [options: T];
|
|
7
|
+
type UseQueryFnContext = Parameters<UseQueryOptions<any>['query']>[0];
|
|
8
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TInitialData extends TOutput | undefined> = (undefined extends TInput ? {
|
|
9
|
+
input?: MaybeRefOrGetter<TInput>;
|
|
10
|
+
} : {
|
|
11
|
+
input: MaybeRefOrGetter<TInput>;
|
|
12
|
+
}) & (Record<never, never> extends TClientContext ? {
|
|
13
|
+
context?: MaybeRefOrGetter<TClientContext>;
|
|
14
|
+
} : {
|
|
15
|
+
context: MaybeRefOrGetter<TClientContext>;
|
|
16
|
+
}) & Partial<QueryOptions<TOutput, TError, TInitialData>>;
|
|
17
|
+
type QueryOptions<TOutput, TError, TInitialData extends TOutput | undefined> = UseQueryOptions<TOutput, TError, TInitialData>;
|
|
18
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext extends Record<any, any>> = (Record<never, never> extends TClientContext ? {
|
|
19
|
+
context?: MaybeRefOrGetter<TClientContext>;
|
|
20
|
+
} : {
|
|
21
|
+
context: MaybeRefOrGetter<TClientContext>;
|
|
22
|
+
}) & Partial<MutationOptions<TInput, TOutput, TError, TMutationContext>>;
|
|
23
|
+
type MutationOptions<TInput, TOutput, TError, TMutationContext extends Record<any, any>> = UseMutationOptions<TOutput, TInput, TError, TMutationContext>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { MaybeOptionalOptions, MutationOptions, MutationOptionsIn, QueryOptions, QueryOptionsIn, UseQueryFnContext };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ProcedureDef, RouterDef } from "../../types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/integrations/react/index.d.ts
|
|
4
|
+
type ActionResult<TOutput> = [error: null, data: TOutput] | [error: {
|
|
5
|
+
code: string;
|
|
6
|
+
status: number;
|
|
7
|
+
message: string;
|
|
8
|
+
data?: unknown;
|
|
9
|
+
}, data: undefined];
|
|
10
|
+
/**
|
|
11
|
+
* Create a server action from a v2 ProcedureDef.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // app/actions.ts
|
|
16
|
+
* "use server"
|
|
17
|
+
* import { createAction } from "silgi/react"
|
|
18
|
+
*
|
|
19
|
+
* export const createUser = createAction(appRouter.users.create)
|
|
20
|
+
*
|
|
21
|
+
* // app/page.tsx
|
|
22
|
+
* const [error, user] = await createUser({ name: "Alice" })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function createAction<TInput = unknown, TOutput = unknown>(procedure: ProcedureDef): (input: TInput) => Promise<ActionResult<TOutput>>;
|
|
26
|
+
/**
|
|
27
|
+
* Create a FormData-accepting server action from a v2 procedure.
|
|
28
|
+
*/
|
|
29
|
+
declare function createFormAction<TOutput = unknown>(procedure: ProcedureDef, options?: {
|
|
30
|
+
parseFormData?: (fd: FormData) => unknown;
|
|
31
|
+
}): (formData: FormData) => Promise<ActionResult<TOutput>>;
|
|
32
|
+
/**
|
|
33
|
+
* Create actions for all procedures in a router.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const actions = createActions(appRouter)
|
|
38
|
+
* const [error, users] = await actions.users.list({ limit: 10 })
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function createActions<T extends RouterDef>(router: T): ActionRouter<T>;
|
|
42
|
+
/**
|
|
43
|
+
* React hook for calling server actions with loading/error state.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* const { execute, data, error, isPending } = useServerAction(createUser)
|
|
48
|
+
*
|
|
49
|
+
* <button onClick={() => execute({ name: "Alice" })} disabled={isPending}>
|
|
50
|
+
* {isPending ? "Creating..." : "Create User"}
|
|
51
|
+
* </button>
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare function useServerAction<TInput, TOutput>(action: (input: TInput) => Promise<ActionResult<TOutput>>): {
|
|
55
|
+
execute: any;
|
|
56
|
+
data: any;
|
|
57
|
+
error: any;
|
|
58
|
+
isPending: any;
|
|
59
|
+
reset: any;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* React hook for server actions with optimistic UI updates.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```tsx
|
|
66
|
+
* const { execute, data, optimisticData, isPending } = useOptimisticServerAction(updateUser, {
|
|
67
|
+
* optimistic: (input) => ({ ...currentUser, ...input }),
|
|
68
|
+
* })
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare function useOptimisticServerAction<TInput, TOutput>(action: (input: TInput) => Promise<ActionResult<TOutput>>, options: {
|
|
72
|
+
optimistic: (input: TInput) => TOutput;
|
|
73
|
+
}): {
|
|
74
|
+
execute: any; /** Confirmed server data */
|
|
75
|
+
data: any; /** Optimistic data (shown while pending, cleared on settle) */
|
|
76
|
+
optimisticData: any; /** The value to display: optimistic while pending, confirmed otherwise */
|
|
77
|
+
displayData: any;
|
|
78
|
+
error: any;
|
|
79
|
+
isPending: any;
|
|
80
|
+
};
|
|
81
|
+
type ActionRouter<T extends RouterDef> = { [K in keyof T]: T[K] extends ProcedureDef<any, infer TInput, infer TOutput> ? (input: TInput extends undefined ? void : TInput) => Promise<ActionResult<TOutput>> : T[K] extends RouterDef ? ActionRouter<T[K]> : never };
|
|
82
|
+
//#endregion
|
|
83
|
+
export { ActionResult, createAction, createActions, createFormAction, useOptimisticServerAction, useServerAction };
|