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
package/dist/core/error.mjs
CHANGED
|
@@ -1,106 +1,139 @@
|
|
|
1
|
-
import { hasProp } from "./utils/internal/object.mjs";
|
|
2
|
-
import { sanitizeStatusCode, sanitizeStatusMessage } from "./utils/sanitize.mjs";
|
|
3
|
-
import consola from "consola";
|
|
4
|
-
import { isDevelopment } from "std-env";
|
|
5
|
-
|
|
6
1
|
//#region src/core/error.ts
|
|
7
2
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @class
|
|
10
|
-
* @extends Error
|
|
11
|
-
* @property {number} statusCode - An integer indicating the HTTP response status code.
|
|
12
|
-
* @property {string} statusMessage - A string representing the HTTP status message.
|
|
13
|
-
* @property {boolean} fatal - Indicates if the error is a fatal error.
|
|
14
|
-
* @property {boolean} unhandled - Indicates if the error was unhandled and auto-captured.
|
|
15
|
-
* @property {DataT} data - An extra data that will be included in the response.
|
|
16
|
-
* This can be used to pass additional information about the error.
|
|
3
|
+
* SilgiError — unified RPC error with cross-realm instanceof.
|
|
17
4
|
*/
|
|
5
|
+
const COMMON_ERRORS = /* @__PURE__ */ Object.freeze({
|
|
6
|
+
BAD_REQUEST: {
|
|
7
|
+
status: 400,
|
|
8
|
+
message: "Bad Request"
|
|
9
|
+
},
|
|
10
|
+
UNAUTHORIZED: {
|
|
11
|
+
status: 401,
|
|
12
|
+
message: "Unauthorized"
|
|
13
|
+
},
|
|
14
|
+
FORBIDDEN: {
|
|
15
|
+
status: 403,
|
|
16
|
+
message: "Forbidden"
|
|
17
|
+
},
|
|
18
|
+
NOT_FOUND: {
|
|
19
|
+
status: 404,
|
|
20
|
+
message: "Not Found"
|
|
21
|
+
},
|
|
22
|
+
METHOD_NOT_ALLOWED: {
|
|
23
|
+
status: 405,
|
|
24
|
+
message: "Method Not Allowed"
|
|
25
|
+
},
|
|
26
|
+
NOT_ACCEPTABLE: {
|
|
27
|
+
status: 406,
|
|
28
|
+
message: "Not Acceptable"
|
|
29
|
+
},
|
|
30
|
+
CONFLICT: {
|
|
31
|
+
status: 409,
|
|
32
|
+
message: "Conflict"
|
|
33
|
+
},
|
|
34
|
+
GONE: {
|
|
35
|
+
status: 410,
|
|
36
|
+
message: "Gone"
|
|
37
|
+
},
|
|
38
|
+
UNPROCESSABLE_CONTENT: {
|
|
39
|
+
status: 422,
|
|
40
|
+
message: "Unprocessable Content"
|
|
41
|
+
},
|
|
42
|
+
PRECONDITION_REQUIRED: {
|
|
43
|
+
status: 428,
|
|
44
|
+
message: "Precondition Required"
|
|
45
|
+
},
|
|
46
|
+
TOO_MANY_REQUESTS: {
|
|
47
|
+
status: 429,
|
|
48
|
+
message: "Too Many Requests"
|
|
49
|
+
},
|
|
50
|
+
CLIENT_CLOSED_REQUEST: {
|
|
51
|
+
status: 499,
|
|
52
|
+
message: "Client Closed Request"
|
|
53
|
+
},
|
|
54
|
+
INTERNAL_SERVER_ERROR: {
|
|
55
|
+
status: 500,
|
|
56
|
+
message: "Internal Server Error"
|
|
57
|
+
},
|
|
58
|
+
NOT_IMPLEMENTED: {
|
|
59
|
+
status: 501,
|
|
60
|
+
message: "Not Implemented"
|
|
61
|
+
},
|
|
62
|
+
BAD_GATEWAY: {
|
|
63
|
+
status: 502,
|
|
64
|
+
message: "Bad Gateway"
|
|
65
|
+
},
|
|
66
|
+
SERVICE_UNAVAILABLE: {
|
|
67
|
+
status: 503,
|
|
68
|
+
message: "Service Unavailable"
|
|
69
|
+
},
|
|
70
|
+
GATEWAY_TIMEOUT: {
|
|
71
|
+
status: 504,
|
|
72
|
+
message: "Gateway Timeout"
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const REGISTRY_KEY = Symbol.for("silgi.error.registry");
|
|
76
|
+
const registry = globalThis[REGISTRY_KEY] ??= /* @__PURE__ */ new WeakSet();
|
|
18
77
|
var SilgiError = class extends Error {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
fatal = false;
|
|
22
|
-
unhandled = false;
|
|
23
|
-
statusMessage;
|
|
78
|
+
code;
|
|
79
|
+
status;
|
|
24
80
|
data;
|
|
25
|
-
|
|
26
|
-
constructor(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
81
|
+
defined;
|
|
82
|
+
constructor(code, options = {}) {
|
|
83
|
+
const defaults = COMMON_ERRORS[code];
|
|
84
|
+
const message = options.message ?? defaults?.message ?? code;
|
|
85
|
+
super(message, options.cause ? { cause: options.cause } : void 0);
|
|
86
|
+
this.code = code;
|
|
87
|
+
this.status = options.status ?? defaults?.status ?? 500;
|
|
88
|
+
this.data = options.data;
|
|
89
|
+
this.defined = options.defined ?? false;
|
|
90
|
+
this.name = "SilgiError";
|
|
33
91
|
}
|
|
34
92
|
toJSON() {
|
|
35
|
-
|
|
93
|
+
return {
|
|
94
|
+
defined: this.defined,
|
|
95
|
+
code: this.code,
|
|
96
|
+
status: this.status,
|
|
36
97
|
message: this.message,
|
|
37
|
-
|
|
98
|
+
data: this.data
|
|
38
99
|
};
|
|
39
|
-
if (this.statusMessage) obj.statusMessage = sanitizeStatusMessage(this.statusMessage);
|
|
40
|
-
if (this.data !== void 0) obj.data = this.data;
|
|
41
|
-
return obj;
|
|
42
100
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
* throw createError({
|
|
55
|
-
* statusCode: 400,
|
|
56
|
-
* statusMessage: "Bad Request",
|
|
57
|
-
* message: "Invalid input",
|
|
58
|
-
* data: { field: "email" }
|
|
59
|
-
* });
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* @return {SilgiError} - An instance of SilgiError.
|
|
63
|
-
*
|
|
64
|
-
* @remarks
|
|
65
|
-
* - Typically, `message` contains a brief, human-readable description of the error, while `statusMessage` is specific to HTTP responses and describes
|
|
66
|
-
* the status text related to the response status code.
|
|
67
|
-
* - In a client-server context, using a short `statusMessage` is recommended because it can be accessed on the client side. Otherwise, a `message`
|
|
68
|
-
* passed to `createError` on the server will not propagate to the client.
|
|
69
|
-
* - Consider avoiding putting dynamic user input in the `message` to prevent potential security issues.
|
|
70
|
-
*/
|
|
71
|
-
function createError(input) {
|
|
72
|
-
if (typeof input === "string") return new SilgiError(input);
|
|
73
|
-
const cause = input.cause;
|
|
74
|
-
const err = new SilgiError(input.message ?? input.statusMessage ?? "", { cause: cause || input });
|
|
75
|
-
if (hasProp(input, "stack")) try {
|
|
76
|
-
Object.defineProperty(err, "stack", { get() {
|
|
77
|
-
return input.stack;
|
|
78
|
-
} });
|
|
79
|
-
} catch {
|
|
80
|
-
try {
|
|
81
|
-
err.stack = input.stack;
|
|
82
|
-
} catch {}
|
|
101
|
+
static {
|
|
102
|
+
registry.add(this);
|
|
103
|
+
}
|
|
104
|
+
static [Symbol.hasInstance](instance) {
|
|
105
|
+
if (typeof instance !== "object" || instance === null) return false;
|
|
106
|
+
let proto = Object.getPrototypeOf(instance);
|
|
107
|
+
while (proto) {
|
|
108
|
+
if (proto.constructor && registry.has(proto.constructor)) return true;
|
|
109
|
+
proto = Object.getPrototypeOf(proto);
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
83
112
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const statusMessage = input.statusMessage ?? input.statusText ?? cause?.statusMessage ?? cause?.statusText;
|
|
88
|
-
if (statusMessage) err.statusMessage = sanitizeStatusMessage(statusMessage);
|
|
89
|
-
const fatal = input.fatal ?? cause?.fatal;
|
|
90
|
-
if (fatal !== void 0) err.fatal = fatal;
|
|
91
|
-
const unhandled = input.unhandled ?? cause?.unhandled;
|
|
92
|
-
if (unhandled !== void 0) err.unhandled = unhandled;
|
|
93
|
-
return err;
|
|
113
|
+
};
|
|
114
|
+
function isDefinedError(error) {
|
|
115
|
+
return error instanceof SilgiError && error.defined === true;
|
|
94
116
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
117
|
+
function toSilgiError(error) {
|
|
118
|
+
if (error instanceof SilgiError) return error;
|
|
119
|
+
return new SilgiError("INTERNAL_SERVER_ERROR", {
|
|
120
|
+
message: "Internal server error",
|
|
121
|
+
cause: error
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function isErrorStatus(status) {
|
|
125
|
+
return status >= 400;
|
|
126
|
+
}
|
|
127
|
+
function isSilgiErrorJSON(json) {
|
|
128
|
+
return typeof json === "object" && json !== null && "code" in json && "status" in json && typeof json.code === "string";
|
|
129
|
+
}
|
|
130
|
+
function fromSilgiErrorJSON(json) {
|
|
131
|
+
return new SilgiError(json.code, {
|
|
132
|
+
status: json.status,
|
|
133
|
+
message: json.message,
|
|
134
|
+
data: json.data,
|
|
135
|
+
defined: json.defined
|
|
136
|
+
});
|
|
103
137
|
}
|
|
104
|
-
|
|
105
138
|
//#endregion
|
|
106
|
-
export { SilgiError,
|
|
139
|
+
export { SilgiError, fromSilgiErrorJSON, isDefinedError, isErrorStatus, isSilgiErrorJSON, toSilgiError };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { routerCache } from "./router-utils.mjs";
|
|
2
|
+
import { compileRouter, createContext, releaseContext } from "../compile.mjs";
|
|
3
|
+
import { applyContext } from "./dispatch.mjs";
|
|
4
|
+
import { detectResponseFormat, encodeResponse, makeErrorResponse } from "./codec.mjs";
|
|
5
|
+
import { runWithCtx } from "./context-bridge.mjs";
|
|
6
|
+
import { parseInput } from "./input.mjs";
|
|
7
|
+
import { iteratorToEventStream } from "./sse.mjs";
|
|
8
|
+
import { analyticsTraceMap } from "./trace-map.mjs";
|
|
9
|
+
import { parseUrlPath } from "./url.mjs";
|
|
10
|
+
//#region src/core/handler.ts
|
|
11
|
+
/**
|
|
12
|
+
* Fetch API handler — single unified request handler.
|
|
13
|
+
*
|
|
14
|
+
* Orchestrates: routing → context → input parsing → pipeline → response encoding.
|
|
15
|
+
* Each concern lives in its own module (codec.ts, input.ts, sse.ts).
|
|
16
|
+
*
|
|
17
|
+
* Analytics / Scalar are NOT here — they wrap the handler externally
|
|
18
|
+
* (see wrapWithAnalytics / wrapWithScalar in their respective modules).
|
|
19
|
+
*/
|
|
20
|
+
/** Wrap a stream to release pooled context on completion or cancellation. */
|
|
21
|
+
function wrapStreamWithRelease(source, ctx) {
|
|
22
|
+
let released = false;
|
|
23
|
+
const release = () => {
|
|
24
|
+
if (!released) {
|
|
25
|
+
released = true;
|
|
26
|
+
releaseContext(ctx);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const reader = source.getReader();
|
|
30
|
+
return new ReadableStream({
|
|
31
|
+
async pull(controller) {
|
|
32
|
+
try {
|
|
33
|
+
const { done, value } = await reader.read();
|
|
34
|
+
if (done) {
|
|
35
|
+
release();
|
|
36
|
+
controller.close();
|
|
37
|
+
} else controller.enqueue(value);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
release();
|
|
40
|
+
controller.error(err);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
cancel() {
|
|
44
|
+
release();
|
|
45
|
+
reader.cancel();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function makeResponse(output, route, format, ctx) {
|
|
50
|
+
if (output instanceof Response) {
|
|
51
|
+
releaseContext(ctx);
|
|
52
|
+
return output;
|
|
53
|
+
}
|
|
54
|
+
if (output instanceof ReadableStream) return new Response(wrapStreamWithRelease(output, ctx), { headers: { "content-type": "application/octet-stream" } });
|
|
55
|
+
if (output && typeof output === "object" && Symbol.asyncIterator in output) {
|
|
56
|
+
const stream = iteratorToEventStream(output);
|
|
57
|
+
return new Response(wrapStreamWithRelease(stream, ctx), { headers: {
|
|
58
|
+
"content-type": "text/event-stream",
|
|
59
|
+
"cache-control": "no-cache"
|
|
60
|
+
} });
|
|
61
|
+
}
|
|
62
|
+
releaseContext(ctx);
|
|
63
|
+
const cacheHeaders = route.cacheControl ? { "cache-control": route.cacheControl } : void 0;
|
|
64
|
+
if (format !== "json") return encodeResponse(output, 200, format, cacheHeaders);
|
|
65
|
+
return new Response(JSON.stringify(output), { headers: cacheHeaders ? {
|
|
66
|
+
"content-type": "application/json",
|
|
67
|
+
...cacheHeaders
|
|
68
|
+
} : { "content-type": "application/json" } });
|
|
69
|
+
}
|
|
70
|
+
function createFetchHandler(routerDef, contextFactory, hooks) {
|
|
71
|
+
let compiledRouter = routerCache.get(routerDef);
|
|
72
|
+
if (!compiledRouter) {
|
|
73
|
+
compiledRouter = compileRouter(routerDef);
|
|
74
|
+
routerCache.set(routerDef, compiledRouter);
|
|
75
|
+
}
|
|
76
|
+
const jsonHeaders = { "content-type": "application/json" };
|
|
77
|
+
const notFoundBody = JSON.stringify({
|
|
78
|
+
code: "NOT_FOUND",
|
|
79
|
+
status: 404,
|
|
80
|
+
message: "Procedure not found"
|
|
81
|
+
});
|
|
82
|
+
function callHook(name, event) {
|
|
83
|
+
if (!hooks) return;
|
|
84
|
+
try {
|
|
85
|
+
const result = hooks.callHook(name, event);
|
|
86
|
+
if (result instanceof Promise) result.catch(() => {});
|
|
87
|
+
} catch {}
|
|
88
|
+
}
|
|
89
|
+
return async function handleRequest(request) {
|
|
90
|
+
const url = request.url;
|
|
91
|
+
const fullPath = parseUrlPath(url);
|
|
92
|
+
const pathname = fullPath.length > 1 ? fullPath.slice(1) : "";
|
|
93
|
+
const qMark = url.indexOf("?", url.indexOf("/", url.indexOf("//") + 2));
|
|
94
|
+
const match = compiledRouter(request.method, fullPath);
|
|
95
|
+
if (!match) return new Response(notFoundBody, {
|
|
96
|
+
status: 404,
|
|
97
|
+
headers: jsonHeaders
|
|
98
|
+
});
|
|
99
|
+
const route = match.data;
|
|
100
|
+
const reqMethod = request.method;
|
|
101
|
+
if (route.method !== "*" && reqMethod !== route.method && reqMethod !== "OPTIONS") {
|
|
102
|
+
if (!(reqMethod === "GET" && route.method === "POST")) return new Response(JSON.stringify({
|
|
103
|
+
code: "METHOD_NOT_ALLOWED",
|
|
104
|
+
status: 405,
|
|
105
|
+
message: `Method ${reqMethod} not allowed`
|
|
106
|
+
}), {
|
|
107
|
+
status: 405,
|
|
108
|
+
headers: {
|
|
109
|
+
...jsonHeaders,
|
|
110
|
+
allow: route.method
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const format = detectResponseFormat(request);
|
|
115
|
+
const ctx = createContext();
|
|
116
|
+
let rawInput;
|
|
117
|
+
try {
|
|
118
|
+
const baseCtxResult = contextFactory(request);
|
|
119
|
+
applyContext(ctx, baseCtxResult instanceof Promise ? await baseCtxResult : baseCtxResult);
|
|
120
|
+
if (match.params) ctx.params = match.params;
|
|
121
|
+
const reqTrace = analyticsTraceMap.get(request);
|
|
122
|
+
if (reqTrace) ctx.__analyticsTrace = reqTrace;
|
|
123
|
+
if (!route.passthrough) rawInput = await parseInput(request, url, qMark);
|
|
124
|
+
if (match.params && Object.keys(match.params).length > 0) rawInput = rawInput != null && typeof rawInput === "object" ? {
|
|
125
|
+
...match.params,
|
|
126
|
+
...rawInput
|
|
127
|
+
} : match.params;
|
|
128
|
+
callHook("request", {
|
|
129
|
+
path: pathname,
|
|
130
|
+
input: rawInput
|
|
131
|
+
});
|
|
132
|
+
const pipelineResult = runWithCtx(ctx, () => route.handler(ctx, rawInput, request.signal));
|
|
133
|
+
const output = pipelineResult instanceof Promise ? await pipelineResult : pipelineResult;
|
|
134
|
+
callHook("response", {
|
|
135
|
+
path: pathname,
|
|
136
|
+
output,
|
|
137
|
+
durationMs: 0
|
|
138
|
+
});
|
|
139
|
+
const response = makeResponse(output, route, format, ctx);
|
|
140
|
+
return response instanceof Promise ? await response : response;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
releaseContext(ctx);
|
|
143
|
+
callHook("error", {
|
|
144
|
+
path: pathname,
|
|
145
|
+
error
|
|
146
|
+
});
|
|
147
|
+
const errorResponse = makeErrorResponse(error, format);
|
|
148
|
+
return errorResponse instanceof Promise ? await errorResponse : errorResponse;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
export { createFetchHandler };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { SilgiError } from "./error.mjs";
|
|
2
|
+
//#region src/core/input.ts
|
|
3
|
+
/**
|
|
4
|
+
* Request input parsing — JSON, MessagePack, devalue, query string.
|
|
5
|
+
*/
|
|
6
|
+
let _msgpack;
|
|
7
|
+
let _devalue;
|
|
8
|
+
const isBun = typeof globalThis.Bun !== "undefined";
|
|
9
|
+
/** Max allowed size for GET ?data= parameter (bytes). Prevents JSON bomb via URL. */
|
|
10
|
+
const MAX_QUERY_DATA_LENGTH = 8192;
|
|
11
|
+
/** Parse request input from body or query string */
|
|
12
|
+
async function parseInput(request, url, qMark) {
|
|
13
|
+
if (request.method === "GET" || !request.body) {
|
|
14
|
+
if (qMark !== -1) {
|
|
15
|
+
const searchStr = url.slice(qMark + 1);
|
|
16
|
+
const dataIdx = searchStr.indexOf("data=");
|
|
17
|
+
if (dataIdx !== -1) {
|
|
18
|
+
const valueStart = dataIdx + 5;
|
|
19
|
+
const valueEnd = searchStr.indexOf("&", valueStart);
|
|
20
|
+
const encoded = valueEnd === -1 ? searchStr.slice(valueStart) : searchStr.slice(valueStart, valueEnd);
|
|
21
|
+
if (encoded.length > MAX_QUERY_DATA_LENGTH) throw new SilgiError("BAD_REQUEST", { message: "Query data parameter too large" });
|
|
22
|
+
return JSON.parse(decodeURIComponent(encoded));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const ct = request.headers.get("content-type");
|
|
28
|
+
if (ct) {
|
|
29
|
+
if (ct.includes("msgpack")) {
|
|
30
|
+
_msgpack ??= await import("../codec/msgpack.mjs");
|
|
31
|
+
const buf = new Uint8Array(await request.arrayBuffer());
|
|
32
|
+
return buf.length > 0 ? _msgpack.decode(buf) : void 0;
|
|
33
|
+
}
|
|
34
|
+
if (ct.includes("x-devalue")) {
|
|
35
|
+
_devalue ??= await import("../codec/devalue.mjs");
|
|
36
|
+
const text = await request.text();
|
|
37
|
+
return text ? _devalue.decode(text) : void 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (isBun) try {
|
|
41
|
+
return await request.json();
|
|
42
|
+
} catch {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const text = await request.text();
|
|
46
|
+
return text ? JSON.parse(text) : void 0;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { parseInput };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/core/iterator.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Async iterator utilities for streaming support.
|
|
4
|
+
*/
|
|
5
|
+
type CleanupReason = 'return' | 'throw' | 'next' | 'dispose';
|
|
6
|
+
declare class AsyncIteratorClass<TYield, TReturn = void> implements AsyncGenerator<TYield, TReturn> {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(nextFn: () => Promise<IteratorResult<TYield, TReturn>>, cleanup?: (reason: CleanupReason) => Promise<void>);
|
|
9
|
+
next(): Promise<IteratorResult<TYield, TReturn>>;
|
|
10
|
+
return(value?: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<TYield, TReturn>>;
|
|
11
|
+
throw(error?: unknown): Promise<IteratorResult<TYield, TReturn>>;
|
|
12
|
+
[Symbol.asyncIterator](): this;
|
|
13
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
declare function mapAsyncIterator<TIn, TOut, TReturn = void>(source: AsyncIterableIterator<TIn>, transform: (value: TIn) => Promise<TOut> | TOut, transformError?: (error: unknown) => unknown): AsyncIteratorClass<TOut, TReturn>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { AsyncIteratorClass, mapAsyncIterator };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { sequential } from "./utils.mjs";
|
|
2
|
+
//#region src/core/iterator.ts
|
|
3
|
+
/**
|
|
4
|
+
* Async iterator utilities for streaming support.
|
|
5
|
+
*/
|
|
6
|
+
var AsyncIteratorClass = class {
|
|
7
|
+
#nextFn;
|
|
8
|
+
#cleanup;
|
|
9
|
+
#isDone = false;
|
|
10
|
+
#cleanupCalled = false;
|
|
11
|
+
constructor(nextFn, cleanup) {
|
|
12
|
+
this.#nextFn = sequential(nextFn);
|
|
13
|
+
this.#cleanup = cleanup;
|
|
14
|
+
}
|
|
15
|
+
async #doCleanup(reason) {
|
|
16
|
+
if (this.#cleanupCalled) return;
|
|
17
|
+
this.#cleanupCalled = true;
|
|
18
|
+
await this.#cleanup?.(reason);
|
|
19
|
+
}
|
|
20
|
+
async next() {
|
|
21
|
+
if (this.#isDone) return {
|
|
22
|
+
done: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
};
|
|
25
|
+
try {
|
|
26
|
+
const result = await this.#nextFn();
|
|
27
|
+
if (result.done) {
|
|
28
|
+
this.#isDone = true;
|
|
29
|
+
await this.#doCleanup("next");
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
this.#isDone = true;
|
|
34
|
+
await this.#doCleanup("throw");
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async return(value) {
|
|
39
|
+
this.#isDone = true;
|
|
40
|
+
await this.#doCleanup("return");
|
|
41
|
+
return {
|
|
42
|
+
done: true,
|
|
43
|
+
value
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async throw(error) {
|
|
47
|
+
this.#isDone = true;
|
|
48
|
+
await this.#doCleanup("throw");
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
[Symbol.asyncIterator]() {
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
async [Symbol.asyncDispose]() {
|
|
55
|
+
this.#isDone = true;
|
|
56
|
+
await this.#doCleanup("dispose");
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
function mapAsyncIterator(source, transform, transformError) {
|
|
60
|
+
return new AsyncIteratorClass(async () => {
|
|
61
|
+
try {
|
|
62
|
+
const result = await source.next();
|
|
63
|
+
if (result.done) return {
|
|
64
|
+
done: true,
|
|
65
|
+
value: await transform(result.value)
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
done: false,
|
|
69
|
+
value: await transform(result.value)
|
|
70
|
+
};
|
|
71
|
+
} catch (error) {
|
|
72
|
+
throw transformError ? transformError(error) : error;
|
|
73
|
+
}
|
|
74
|
+
}, async () => {
|
|
75
|
+
await source.return?.();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { AsyncIteratorClass, mapAsyncIterator };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import "../compile.mjs";
|
|
2
|
+
//#region src/core/router-utils.ts
|
|
3
|
+
const routerCache = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
function isProcedureDef(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && "type" in value && "resolve" in value && typeof value.resolve === "function";
|
|
6
|
+
}
|
|
7
|
+
function assignPaths(def, prefix = []) {
|
|
8
|
+
const result = {};
|
|
9
|
+
for (const [key, value] of Object.entries(def)) {
|
|
10
|
+
const currentPath = [...prefix, key];
|
|
11
|
+
if (isProcedureDef(value)) if (!value.route) result[key] = {
|
|
12
|
+
...value,
|
|
13
|
+
route: { path: "/" + currentPath.join("/") }
|
|
14
|
+
};
|
|
15
|
+
else result[key] = value;
|
|
16
|
+
else if (typeof value === "object" && value !== null) result[key] = assignPaths(value, currentPath);
|
|
17
|
+
else result[key] = value;
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { assignPaths, isProcedureDef, routerCache };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/core/schema.d.ts
|
|
4
|
+
type Schema<TInput = unknown, TOutput = unknown> = StandardSchemaV1<TInput, TOutput>;
|
|
5
|
+
type AnySchema = Schema<any, any>;
|
|
6
|
+
type InferSchemaInput<T extends AnySchema> = T extends Schema<infer I, unknown> ? I : never;
|
|
7
|
+
type InferSchemaOutput<T extends AnySchema> = T extends Schema<unknown, infer O> ? O : never;
|
|
8
|
+
type SchemaIssue = StandardSchemaV1.Issue;
|
|
9
|
+
declare class ValidationError extends Error {
|
|
10
|
+
readonly issues: readonly SchemaIssue[];
|
|
11
|
+
constructor(options: {
|
|
12
|
+
message?: string;
|
|
13
|
+
issues: readonly SchemaIssue[];
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** Sync fast-path: Zod 4 validate() returns sync result — avoid Promise allocation */
|
|
17
|
+
declare function validateSchema(schema: AnySchema, value: unknown): unknown;
|
|
18
|
+
declare function type<TInput, TOutput = TInput>(...args: TInput extends TOutput ? TOutput extends TInput ? [map?: (input: TInput) => TOutput] : [map: (input: TInput) => TOutput] : [map: (input: TInput) => TOutput]): Schema<TInput, TOutput>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { AnySchema, InferSchemaInput, InferSchemaOutput, Schema, ValidationError, type, validateSchema };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/core/schema.ts
|
|
2
|
+
var ValidationError = class extends Error {
|
|
3
|
+
issues;
|
|
4
|
+
constructor(options) {
|
|
5
|
+
super(options.message ?? "Validation failed");
|
|
6
|
+
this.name = "ValidationError";
|
|
7
|
+
this.issues = options.issues;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
/** Sync fast-path: Zod 4 validate() returns sync result — avoid Promise allocation */
|
|
11
|
+
function validateSchema(schema, value) {
|
|
12
|
+
const result = schema["~standard"].validate(value);
|
|
13
|
+
if (typeof result?.then !== "function") {
|
|
14
|
+
if ("issues" in result && result.issues) throw new ValidationError({ issues: result.issues });
|
|
15
|
+
return result.value;
|
|
16
|
+
}
|
|
17
|
+
return result.then((r) => {
|
|
18
|
+
if ("issues" in r && r.issues) throw new ValidationError({ issues: r.issues });
|
|
19
|
+
return r.value;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function type(...args) {
|
|
23
|
+
const mapFn = args[0];
|
|
24
|
+
return { "~standard": {
|
|
25
|
+
version: 1,
|
|
26
|
+
vendor: "silgi",
|
|
27
|
+
validate(value) {
|
|
28
|
+
return { value: mapFn ? mapFn(value) : value };
|
|
29
|
+
}
|
|
30
|
+
} };
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { ValidationError, type, validateSchema };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AnalyticsOptions } from "../plugins/analytics/types.mjs";
|
|
2
|
+
import { ScalarOptions } from "../scalar.mjs";
|
|
3
|
+
import { WSAdapterOptions } from "../ws.mjs";
|
|
4
|
+
import { Hookable } from "hookable";
|
|
5
|
+
|
|
6
|
+
//#region src/core/serve.d.ts
|
|
7
|
+
interface SilgiServer {
|
|
8
|
+
/** Server URL (e.g. "http://127.0.0.1:3000") */
|
|
9
|
+
readonly url: string;
|
|
10
|
+
/** Configured port */
|
|
11
|
+
readonly port: number;
|
|
12
|
+
/** Configured hostname */
|
|
13
|
+
readonly hostname: string;
|
|
14
|
+
/**
|
|
15
|
+
* Gracefully shut down the server.
|
|
16
|
+
*
|
|
17
|
+
* By default waits for in-flight requests to complete.
|
|
18
|
+
* Pass `true` to forcefully terminate all active connections immediately.
|
|
19
|
+
*/
|
|
20
|
+
close(forceCloseConnections?: boolean): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
interface ServeOptions {
|
|
23
|
+
port?: number;
|
|
24
|
+
hostname?: string;
|
|
25
|
+
/** Enable Scalar API Reference UI at /api/reference and /api/openapi.json */
|
|
26
|
+
scalar?: boolean | ScalarOptions;
|
|
27
|
+
/** Enable analytics dashboard at /api/analytics */
|
|
28
|
+
analytics?: boolean | AnalyticsOptions;
|
|
29
|
+
/** Enable WebSocket RPC (requires crossws) */
|
|
30
|
+
ws?: boolean | WSAdapterOptions;
|
|
31
|
+
/** Enable HTTP/2 (requires cert + key for TLS) */
|
|
32
|
+
http2?: {
|
|
33
|
+
cert: string;
|
|
34
|
+
key: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Graceful shutdown on SIGINT/SIGTERM signals.
|
|
38
|
+
*
|
|
39
|
+
* - `true` (default): enables graceful shutdown with srvx defaults
|
|
40
|
+
* - `false`: disables automatic signal handling
|
|
41
|
+
* - `object`: fine-tune timeouts
|
|
42
|
+
*
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
gracefulShutdown?: boolean | {
|
|
46
|
+
/** Max time (ms) to wait for in-flight requests before force-closing */timeout?: number; /** Max time (ms) after graceful period before process.exit */
|
|
47
|
+
forceTimeout?: number;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { ServeOptions, SilgiServer };
|