exisjs 0.1.2
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 +52 -0
- package/bin/exis.js +2 -0
- package/dist/adapters/aws-lambda.d.ts +21 -0
- package/dist/adapters/aws-lambda.d.ts.map +1 -0
- package/dist/adapters/aws-lambda.js +110 -0
- package/dist/adapters/aws-lambda.js.map +1 -0
- package/dist/adapters/bun.d.ts +9 -0
- package/dist/adapters/bun.d.ts.map +1 -0
- package/dist/adapters/bun.js +15 -0
- package/dist/adapters/bun.js.map +1 -0
- package/dist/adapters/cloudflare.d.ts +10 -0
- package/dist/adapters/cloudflare.d.ts.map +1 -0
- package/dist/adapters/cloudflare.js +14 -0
- package/dist/adapters/cloudflare.js.map +1 -0
- package/dist/adapters/deno.d.ts +7 -0
- package/dist/adapters/deno.d.ts.map +1 -0
- package/dist/adapters/deno.js +11 -0
- package/dist/adapters/deno.js.map +1 -0
- package/dist/adapters/fastly.d.ts +6 -0
- package/dist/adapters/fastly.d.ts.map +1 -0
- package/dist/adapters/fastly.js +12 -0
- package/dist/adapters/fastly.js.map +1 -0
- package/dist/adapters/fetch.d.ts +30 -0
- package/dist/adapters/fetch.d.ts.map +1 -0
- package/dist/adapters/fetch.js +119 -0
- package/dist/adapters/fetch.js.map +1 -0
- package/dist/adapters/index.d.ts +9 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +28 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/netlify.d.ts +8 -0
- package/dist/adapters/netlify.d.ts.map +1 -0
- package/dist/adapters/netlify.js +12 -0
- package/dist/adapters/netlify.js.map +1 -0
- package/dist/adapters/vercel.d.ts +14 -0
- package/dist/adapters/vercel.d.ts.map +1 -0
- package/dist/adapters/vercel.js +20 -0
- package/dist/adapters/vercel.js.map +1 -0
- package/dist/auth/jwt.d.ts +20 -0
- package/dist/auth/jwt.d.ts.map +1 -0
- package/dist/auth/jwt.js +79 -0
- package/dist/auth/jwt.js.map +1 -0
- package/dist/auth/password.d.ts +25 -0
- package/dist/auth/password.d.ts.map +1 -0
- package/dist/auth/password.js +93 -0
- package/dist/auth/password.js.map +1 -0
- package/dist/auth/rbac.d.ts +10 -0
- package/dist/auth/rbac.d.ts.map +1 -0
- package/dist/auth/rbac.js +34 -0
- package/dist/auth/rbac.js.map +1 -0
- package/dist/auth/session.d.ts +23 -0
- package/dist/auth/session.d.ts.map +1 -0
- package/dist/auth/session.js +105 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/cache/index.d.ts +2 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +9 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/store.d.ts +48 -0
- package/dist/cache/store.d.ts.map +1 -0
- package/dist/cache/store.js +211 -0
- package/dist/cache/store.js.map +1 -0
- package/dist/cli/commands/build.d.ts +7 -0
- package/dist/cli/commands/build.d.ts.map +1 -0
- package/dist/cli/commands/build.js +183 -0
- package/dist/cli/commands/build.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +9 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +290 -0
- package/dist/cli/commands/dev.js.map +1 -0
- package/dist/cli/commands/exports.d.ts +2 -0
- package/dist/cli/commands/exports.d.ts.map +1 -0
- package/dist/cli/commands/exports.js +76 -0
- package/dist/cli/commands/exports.js.map +1 -0
- package/dist/cli/commands/generate.d.ts +5 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +149 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +37 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/repl.d.ts +6 -0
- package/dist/cli/commands/repl.d.ts.map +1 -0
- package/dist/cli/commands/repl.js +75 -0
- package/dist/cli/commands/repl.js.map +1 -0
- package/dist/cli/commands/start.d.ts +7 -0
- package/dist/cli/commands/start.d.ts.map +1 -0
- package/dist/cli/commands/start.js +111 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/test.d.ts +7 -0
- package/dist/cli/commands/test.d.ts.map +1 -0
- package/dist/cli/commands/test.js +170 -0
- package/dist/cli/commands/test.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +183 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/manifest.d.ts +2 -0
- package/dist/cli/manifest.d.ts.map +1 -0
- package/dist/cli/manifest.js +160 -0
- package/dist/cli/manifest.js.map +1 -0
- package/dist/cli/optimizers/aot-routes.d.ts +2 -0
- package/dist/cli/optimizers/aot-routes.d.ts.map +1 -0
- package/dist/cli/optimizers/aot-routes.js +59 -0
- package/dist/cli/optimizers/aot-routes.js.map +1 -0
- package/dist/cli/optimizers/precompile-serializers.d.ts +2 -0
- package/dist/cli/optimizers/precompile-serializers.d.ts.map +1 -0
- package/dist/cli/optimizers/precompile-serializers.js +68 -0
- package/dist/cli/optimizers/precompile-serializers.js.map +1 -0
- package/dist/cli/optimizers/tree-shake.d.ts +2 -0
- package/dist/cli/optimizers/tree-shake.d.ts.map +1 -0
- package/dist/cli/optimizers/tree-shake.js +64 -0
- package/dist/cli/optimizers/tree-shake.js.map +1 -0
- package/dist/cli/routes.d.ts +2 -0
- package/dist/cli/routes.d.ts.map +1 -0
- package/dist/cli/routes.js +158 -0
- package/dist/cli/routes.js.map +1 -0
- package/dist/cli/utils.d.ts +24 -0
- package/dist/cli/utils.d.ts.map +1 -0
- package/dist/cli/utils.js +54 -0
- package/dist/cli/utils.js.map +1 -0
- package/dist/config/constants.d.ts +11 -0
- package/dist/config/constants.d.ts.map +1 -0
- package/dist/config/constants.js +14 -0
- package/dist/config/constants.js.map +1 -0
- package/dist/cron/parser.d.ts +2 -0
- package/dist/cron/parser.d.ts.map +1 -0
- package/dist/cron/parser.js +52 -0
- package/dist/cron/parser.js.map +1 -0
- package/dist/cron/scheduler.d.ts +22 -0
- package/dist/cron/scheduler.d.ts.map +1 -0
- package/dist/cron/scheduler.js +102 -0
- package/dist/cron/scheduler.js.map +1 -0
- package/dist/dataloader/dataloader.d.ts +23 -0
- package/dist/dataloader/dataloader.d.ts.map +1 -0
- package/dist/dataloader/dataloader.js +98 -0
- package/dist/dataloader/dataloader.js.map +1 -0
- package/dist/dataloader/registry.d.ts +17 -0
- package/dist/dataloader/registry.d.ts.map +1 -0
- package/dist/dataloader/registry.js +47 -0
- package/dist/dataloader/registry.js.map +1 -0
- package/dist/decorators/index.d.ts +63 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +460 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/di/container.d.ts +21 -0
- package/dist/di/container.d.ts.map +1 -0
- package/dist/di/container.js +81 -0
- package/dist/di/container.js.map +1 -0
- package/dist/di/inject.d.ts +3 -0
- package/dist/di/inject.d.ts.map +1 -0
- package/dist/di/inject.js +12 -0
- package/dist/di/inject.js.map +1 -0
- package/dist/exports/auth.d.ts +6 -0
- package/dist/exports/auth.d.ts.map +1 -0
- package/dist/exports/auth.js +46 -0
- package/dist/exports/auth.js.map +1 -0
- package/dist/exports/cache.d.ts +4 -0
- package/dist/exports/cache.d.ts.map +1 -0
- package/dist/exports/cache.js +20 -0
- package/dist/exports/cache.js.map +1 -0
- package/dist/exports/config.d.ts +4 -0
- package/dist/exports/config.d.ts.map +1 -0
- package/dist/exports/config.js +23 -0
- package/dist/exports/config.js.map +1 -0
- package/dist/exports/dataloader.d.ts +3 -0
- package/dist/exports/dataloader.d.ts.map +1 -0
- package/dist/exports/dataloader.js +19 -0
- package/dist/exports/dataloader.js.map +1 -0
- package/dist/exports/decorators.d.ts +2 -0
- package/dist/exports/decorators.d.ts.map +1 -0
- package/dist/exports/decorators.js +18 -0
- package/dist/exports/decorators.js.map +1 -0
- package/dist/exports/di.d.ts +4 -0
- package/dist/exports/di.d.ts.map +1 -0
- package/dist/exports/di.js +8 -0
- package/dist/exports/di.js.map +1 -0
- package/dist/exports/error.d.ts +2 -0
- package/dist/exports/error.d.ts.map +1 -0
- package/dist/exports/error.js +16 -0
- package/dist/exports/error.js.map +1 -0
- package/dist/exports/module.d.ts +3 -0
- package/dist/exports/module.d.ts.map +1 -0
- package/dist/exports/module.js +6 -0
- package/dist/exports/module.js.map +1 -0
- package/dist/exports/plugin.d.ts +3 -0
- package/dist/exports/plugin.d.ts.map +1 -0
- package/dist/exports/plugin.js +6 -0
- package/dist/exports/plugin.js.map +1 -0
- package/dist/exports/queue.d.ts +9 -0
- package/dist/exports/queue.d.ts.map +1 -0
- package/dist/exports/queue.js +16 -0
- package/dist/exports/queue.js.map +1 -0
- package/dist/exports/response.d.ts +2 -0
- package/dist/exports/response.d.ts.map +1 -0
- package/dist/exports/response.js +18 -0
- package/dist/exports/response.js.map +1 -0
- package/dist/exports/route.d.ts +14 -0
- package/dist/exports/route.d.ts.map +1 -0
- package/dist/exports/route.js +25 -0
- package/dist/exports/route.js.map +1 -0
- package/dist/exports/security.d.ts +3 -0
- package/dist/exports/security.d.ts.map +1 -0
- package/dist/exports/security.js +13 -0
- package/dist/exports/security.js.map +1 -0
- package/dist/exports/swagger.d.ts +3 -0
- package/dist/exports/swagger.d.ts.map +1 -0
- package/dist/exports/swagger.js +6 -0
- package/dist/exports/swagger.js.map +1 -0
- package/dist/exports/validation.d.ts +2 -0
- package/dist/exports/validation.d.ts.map +1 -0
- package/dist/exports/validation.js +8 -0
- package/dist/exports/validation.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/drizzle.d.ts +10 -0
- package/dist/integrations/drizzle.d.ts.map +1 -0
- package/dist/integrations/drizzle.js +34 -0
- package/dist/integrations/drizzle.js.map +1 -0
- package/dist/integrations/jwt.d.ts +12 -0
- package/dist/integrations/jwt.d.ts.map +1 -0
- package/dist/integrations/jwt.js +27 -0
- package/dist/integrations/jwt.js.map +1 -0
- package/dist/integrations/mongodb.d.ts +13 -0
- package/dist/integrations/mongodb.d.ts.map +1 -0
- package/dist/integrations/mongodb.js +48 -0
- package/dist/integrations/mongodb.js.map +1 -0
- package/dist/integrations/mongoose.d.ts +13 -0
- package/dist/integrations/mongoose.d.ts.map +1 -0
- package/dist/integrations/mongoose.js +58 -0
- package/dist/integrations/mongoose.js.map +1 -0
- package/dist/integrations/openai.d.ts +12 -0
- package/dist/integrations/openai.d.ts.map +1 -0
- package/dist/integrations/openai.js +47 -0
- package/dist/integrations/openai.js.map +1 -0
- package/dist/integrations/postgres.d.ts +13 -0
- package/dist/integrations/postgres.d.ts.map +1 -0
- package/dist/integrations/postgres.js +55 -0
- package/dist/integrations/postgres.js.map +1 -0
- package/dist/integrations/posthog.d.ts +13 -0
- package/dist/integrations/posthog.d.ts.map +1 -0
- package/dist/integrations/posthog.js +49 -0
- package/dist/integrations/posthog.js.map +1 -0
- package/dist/integrations/prisma.d.ts +10 -0
- package/dist/integrations/prisma.d.ts.map +1 -0
- package/dist/integrations/prisma.js +27 -0
- package/dist/integrations/prisma.js.map +1 -0
- package/dist/integrations/redis.d.ts +12 -0
- package/dist/integrations/redis.d.ts.map +1 -0
- package/dist/integrations/redis.js +48 -0
- package/dist/integrations/redis.js.map +1 -0
- package/dist/integrations/resend.d.ts +12 -0
- package/dist/integrations/resend.d.ts.map +1 -0
- package/dist/integrations/resend.js +47 -0
- package/dist/integrations/resend.js.map +1 -0
- package/dist/integrations/s3.d.ts +15 -0
- package/dist/integrations/s3.d.ts.map +1 -0
- package/dist/integrations/s3.js +60 -0
- package/dist/integrations/s3.js.map +1 -0
- package/dist/integrations/supabase.d.ts +13 -0
- package/dist/integrations/supabase.d.ts.map +1 -0
- package/dist/integrations/supabase.js +51 -0
- package/dist/integrations/supabase.js.map +1 -0
- package/dist/lib/start-repl.d.ts +2 -0
- package/dist/lib/start-repl.d.ts.map +1 -0
- package/dist/lib/start-repl.js +122 -0
- package/dist/lib/start-repl.js.map +1 -0
- package/dist/lib/start-server.d.ts +2 -0
- package/dist/lib/start-server.d.ts.map +1 -0
- package/dist/lib/start-server.js +103 -0
- package/dist/lib/start-server.js.map +1 -0
- package/dist/middleware/backpressure.d.ts +11 -0
- package/dist/middleware/backpressure.d.ts.map +1 -0
- package/dist/middleware/backpressure.js +55 -0
- package/dist/middleware/backpressure.js.map +1 -0
- package/dist/middleware/cache.d.ts +10 -0
- package/dist/middleware/cache.d.ts.map +1 -0
- package/dist/middleware/cache.js +97 -0
- package/dist/middleware/cache.js.map +1 -0
- package/dist/middleware/compression.d.ts +3 -0
- package/dist/middleware/compression.d.ts.map +1 -0
- package/dist/middleware/compression.js +132 -0
- package/dist/middleware/compression.js.map +1 -0
- package/dist/middleware/dedupe.d.ts +10 -0
- package/dist/middleware/dedupe.d.ts.map +1 -0
- package/dist/middleware/dedupe.js +79 -0
- package/dist/middleware/dedupe.js.map +1 -0
- package/dist/middleware/exception-filter.d.ts +9 -0
- package/dist/middleware/exception-filter.d.ts.map +1 -0
- package/dist/middleware/exception-filter.js +26 -0
- package/dist/middleware/exception-filter.js.map +1 -0
- package/dist/middleware/guard.d.ts +11 -0
- package/dist/middleware/guard.d.ts.map +1 -0
- package/dist/middleware/guard.js +26 -0
- package/dist/middleware/guard.js.map +1 -0
- package/dist/middleware/interceptor.d.ts +4 -0
- package/dist/middleware/interceptor.d.ts.map +1 -0
- package/dist/middleware/interceptor.js +32 -0
- package/dist/middleware/interceptor.js.map +1 -0
- package/dist/middleware/ip-filter.d.ts +11 -0
- package/dist/middleware/ip-filter.d.ts.map +1 -0
- package/dist/middleware/ip-filter.js +27 -0
- package/dist/middleware/ip-filter.js.map +1 -0
- package/dist/middleware/middleware.d.ts +26 -0
- package/dist/middleware/middleware.d.ts.map +1 -0
- package/dist/middleware/middleware.js +271 -0
- package/dist/middleware/middleware.js.map +1 -0
- package/dist/middleware/pipe.d.ts +9 -0
- package/dist/middleware/pipe.d.ts.map +1 -0
- package/dist/middleware/pipe.js +24 -0
- package/dist/middleware/pipe.js.map +1 -0
- package/dist/middleware/security.d.ts +53 -0
- package/dist/middleware/security.d.ts.map +1 -0
- package/dist/middleware/security.js +257 -0
- package/dist/middleware/security.js.map +1 -0
- package/dist/module/module.d.ts +17 -0
- package/dist/module/module.d.ts.map +1 -0
- package/dist/module/module.js +37 -0
- package/dist/module/module.js.map +1 -0
- package/dist/observability/health.d.ts +23 -0
- package/dist/observability/health.d.ts.map +1 -0
- package/dist/observability/health.js +49 -0
- package/dist/observability/health.js.map +1 -0
- package/dist/observability/index.d.ts +4 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +10 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/otel.d.ts +27 -0
- package/dist/observability/otel.d.ts.map +1 -0
- package/dist/observability/otel.js +45 -0
- package/dist/observability/otel.js.map +1 -0
- package/dist/observability/prometheus.d.ts +30 -0
- package/dist/observability/prometheus.d.ts.map +1 -0
- package/dist/observability/prometheus.js +31 -0
- package/dist/observability/prometheus.js.map +1 -0
- package/dist/queue/client.d.ts +13 -0
- package/dist/queue/client.d.ts.map +1 -0
- package/dist/queue/client.js +64 -0
- package/dist/queue/client.js.map +1 -0
- package/dist/queue/drivers/MemoryDriver.d.ts +17 -0
- package/dist/queue/drivers/MemoryDriver.d.ts.map +1 -0
- package/dist/queue/drivers/MemoryDriver.js +109 -0
- package/dist/queue/drivers/MemoryDriver.js.map +1 -0
- package/dist/queue/drivers/RedisDriver.d.ts +18 -0
- package/dist/queue/drivers/RedisDriver.d.ts.map +1 -0
- package/dist/queue/drivers/RedisDriver.js +120 -0
- package/dist/queue/drivers/RedisDriver.js.map +1 -0
- package/dist/queue/index.d.ts +12 -0
- package/dist/queue/index.d.ts.map +1 -0
- package/dist/queue/index.js +27 -0
- package/dist/queue/index.js.map +1 -0
- package/dist/queue/types.d.ts +51 -0
- package/dist/queue/types.d.ts.map +1 -0
- package/dist/queue/types.js +3 -0
- package/dist/queue/types.js.map +1 -0
- package/dist/queue/worker.d.ts +18 -0
- package/dist/queue/worker.d.ts.map +1 -0
- package/dist/queue/worker.js +160 -0
- package/dist/queue/worker.js.map +1 -0
- package/dist/response/index.d.ts +16 -0
- package/dist/response/index.d.ts.map +1 -0
- package/dist/response/index.js +19 -0
- package/dist/response/index.js.map +1 -0
- package/dist/router/gateway.d.ts +64 -0
- package/dist/router/gateway.d.ts.map +1 -0
- package/dist/router/gateway.js +11 -0
- package/dist/router/gateway.js.map +1 -0
- package/dist/router/radix.d.ts +42 -0
- package/dist/router/radix.d.ts.map +1 -0
- package/dist/router/radix.js +523 -0
- package/dist/router/radix.js.map +1 -0
- package/dist/router/router.d.ts +59 -0
- package/dist/router/router.d.ts.map +1 -0
- package/dist/router/router.js +386 -0
- package/dist/router/router.js.map +1 -0
- package/dist/server/app.d.ts +206 -0
- package/dist/server/app.d.ts.map +1 -0
- package/dist/server/app.js +2191 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/cluster.d.ts +52 -0
- package/dist/server/cluster.d.ts.map +1 -0
- package/dist/server/cluster.js +165 -0
- package/dist/server/cluster.js.map +1 -0
- package/dist/server/context.d.ts +40 -0
- package/dist/server/context.d.ts.map +1 -0
- package/dist/server/context.js +74 -0
- package/dist/server/context.js.map +1 -0
- package/dist/server/define.d.ts +14 -0
- package/dist/server/define.d.ts.map +1 -0
- package/dist/server/define.js +22 -0
- package/dist/server/define.js.map +1 -0
- package/dist/server/dep-graph.d.ts +2 -0
- package/dist/server/dep-graph.d.ts.map +1 -0
- package/dist/server/dep-graph.js +109 -0
- package/dist/server/dep-graph.js.map +1 -0
- package/dist/server/dev-error-overlay.d.ts +3 -0
- package/dist/server/dev-error-overlay.d.ts.map +1 -0
- package/dist/server/dev-error-overlay.js +116 -0
- package/dist/server/dev-error-overlay.js.map +1 -0
- package/dist/server/hot-reload.d.ts +28 -0
- package/dist/server/hot-reload.d.ts.map +1 -0
- package/dist/server/hot-reload.js +253 -0
- package/dist/server/hot-reload.js.map +1 -0
- package/dist/server/request.d.ts +71 -0
- package/dist/server/request.d.ts.map +1 -0
- package/dist/server/request.js +408 -0
- package/dist/server/request.js.map +1 -0
- package/dist/server/response.d.ts +36 -0
- package/dist/server/response.d.ts.map +1 -0
- package/dist/server/response.js +254 -0
- package/dist/server/response.js.map +1 -0
- package/dist/server/route.d.ts +148 -0
- package/dist/server/route.d.ts.map +1 -0
- package/dist/server/route.js +56 -0
- package/dist/server/route.js.map +1 -0
- package/dist/server/sse.d.ts +16 -0
- package/dist/server/sse.d.ts.map +1 -0
- package/dist/server/sse.js +51 -0
- package/dist/server/sse.js.map +1 -0
- package/dist/server/uws-adapter.d.ts +101 -0
- package/dist/server/uws-adapter.d.ts.map +1 -0
- package/dist/server/uws-adapter.js +338 -0
- package/dist/server/uws-adapter.js.map +1 -0
- package/dist/swagger/index.d.ts +9 -0
- package/dist/swagger/index.d.ts.map +1 -0
- package/dist/swagger/index.js +147 -0
- package/dist/swagger/index.js.map +1 -0
- package/dist/testing/client.d.ts +44 -0
- package/dist/testing/client.d.ts.map +1 -0
- package/dist/testing/client.js +105 -0
- package/dist/testing/client.js.map +1 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +128 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mocks.d.ts +25 -0
- package/dist/testing/mocks.d.ts.map +1 -0
- package/dist/testing/mocks.js +117 -0
- package/dist/testing/mocks.js.map +1 -0
- package/dist/testing/reporter.d.ts +13 -0
- package/dist/testing/reporter.d.ts.map +1 -0
- package/dist/testing/reporter.js +101 -0
- package/dist/testing/reporter.js.map +1 -0
- package/dist/threads/pool.d.ts +13 -0
- package/dist/threads/pool.d.ts.map +1 -0
- package/dist/threads/pool.js +93 -0
- package/dist/threads/pool.js.map +1 -0
- package/dist/threads/worker-runner.d.ts +2 -0
- package/dist/threads/worker-runner.d.ts.map +1 -0
- package/dist/threads/worker-runner.js +71 -0
- package/dist/threads/worker-runner.js.map +1 -0
- package/dist/types.d.ts +200 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/circuit-breaker.d.ts +30 -0
- package/dist/utils/circuit-breaker.d.ts.map +1 -0
- package/dist/utils/circuit-breaker.js +72 -0
- package/dist/utils/circuit-breaker.js.map +1 -0
- package/dist/utils/config.d.ts +9 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +229 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/env.d.ts +25 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +155 -0
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/errors.d.ts +51 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +233 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/logger.d.ts +6 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +70 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/plugin.d.ts +7 -0
- package/dist/utils/plugin.d.ts.map +1 -0
- package/dist/utils/plugin.js +30 -0
- package/dist/utils/plugin.js.map +1 -0
- package/dist/utils/validator.d.ts +300 -0
- package/dist/utils/validator.d.ts.map +1 -0
- package/dist/utils/validator.js +719 -0
- package/dist/utils/validator.js.map +1 -0
- package/dist/websocket/server.d.ts +66 -0
- package/dist/websocket/server.d.ts.map +1 -0
- package/dist/websocket/server.js +156 -0
- package/dist/websocket/server.js.map +1 -0
- package/dist/websocket/socket.d.ts +119 -0
- package/dist/websocket/socket.d.ts.map +1 -0
- package/dist/websocket/socket.js +240 -0
- package/dist/websocket/socket.js.map +1 -0
- package/package.json +270 -0
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.v = exports.FileValidator = exports.AnyValidator = exports.RecordValidator = exports.DateValidator = exports.UnionValidator = exports.LiteralValidator = exports.EnumValidator = exports.ArrayValidator = exports.ObjectValidator = exports.BooleanValidator = exports.NumberValidator = exports.StringValidator = exports.AsyncRefineValidator = exports.TransformValidator = exports.RefineValidator = exports.ValidatorType = exports.ValidatorError = void 0;
|
|
4
|
+
class ValidatorError extends Error {
|
|
5
|
+
constructor(errors) {
|
|
6
|
+
super('Validation Error: ' +
|
|
7
|
+
errors.map((e) => `${e.path}: ${e.message}`).join(', '));
|
|
8
|
+
this.errors = errors;
|
|
9
|
+
this.name = 'ValidatorError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ValidatorError = ValidatorError;
|
|
13
|
+
class ValidatorType {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.isOptional = false;
|
|
16
|
+
this._hasDefault = false;
|
|
17
|
+
}
|
|
18
|
+
optional() {
|
|
19
|
+
this.isOptional = true;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
default(val) {
|
|
23
|
+
this.isOptional = true;
|
|
24
|
+
this._hasDefault = true;
|
|
25
|
+
this.defaultValue = val;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
refine(check, message = 'Invalid value') {
|
|
29
|
+
return new RefineValidator(this, check, message);
|
|
30
|
+
}
|
|
31
|
+
transform(fn) {
|
|
32
|
+
return new TransformValidator(this, fn);
|
|
33
|
+
}
|
|
34
|
+
async _validateAsync(value, path) {
|
|
35
|
+
return this._validate(value, path);
|
|
36
|
+
}
|
|
37
|
+
validate(value, path = '') {
|
|
38
|
+
if (this._hasDefault && value === undefined) {
|
|
39
|
+
const def = typeof this.defaultValue === 'function'
|
|
40
|
+
? this.defaultValue()
|
|
41
|
+
: this.defaultValue;
|
|
42
|
+
return { success: true, data: def };
|
|
43
|
+
}
|
|
44
|
+
return this._validate(value, path);
|
|
45
|
+
}
|
|
46
|
+
async validateAsync(value, path = '') {
|
|
47
|
+
if (this._hasDefault && value === undefined) {
|
|
48
|
+
const def = typeof this.defaultValue === 'function'
|
|
49
|
+
? this.defaultValue()
|
|
50
|
+
: this.defaultValue;
|
|
51
|
+
return { success: true, data: def };
|
|
52
|
+
}
|
|
53
|
+
return this._validateAsync(value, path);
|
|
54
|
+
}
|
|
55
|
+
refineAsync(check, message = 'Invalid value') {
|
|
56
|
+
return new AsyncRefineValidator(this, check, message);
|
|
57
|
+
}
|
|
58
|
+
parse(value) {
|
|
59
|
+
const result = this.validate(value, '');
|
|
60
|
+
if (!result.success)
|
|
61
|
+
throw new ValidatorError(result.errors);
|
|
62
|
+
return result.data;
|
|
63
|
+
}
|
|
64
|
+
async parseAsync(value) {
|
|
65
|
+
const result = await this.validateAsync(value, '');
|
|
66
|
+
if (!result.success)
|
|
67
|
+
throw new ValidatorError(result.errors);
|
|
68
|
+
return result.data;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.ValidatorType = ValidatorType;
|
|
72
|
+
class RefineValidator extends ValidatorType {
|
|
73
|
+
constructor(base, check, message) {
|
|
74
|
+
super();
|
|
75
|
+
this.base = base;
|
|
76
|
+
this.check = check;
|
|
77
|
+
this.message = message;
|
|
78
|
+
}
|
|
79
|
+
toOpenApi() {
|
|
80
|
+
return this.base.toOpenApi();
|
|
81
|
+
}
|
|
82
|
+
_validate(value, path) {
|
|
83
|
+
const res = this.base._validate(value, path);
|
|
84
|
+
if (!res.success)
|
|
85
|
+
return res;
|
|
86
|
+
if (res.data !== undefined) {
|
|
87
|
+
if (!this.check(res.data)) {
|
|
88
|
+
const msg = typeof this.message === 'function'
|
|
89
|
+
? this.message(res.data)
|
|
90
|
+
: this.message;
|
|
91
|
+
return { success: false, errors: [{ path, message: msg }] };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return res;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.RefineValidator = RefineValidator;
|
|
98
|
+
class TransformValidator extends ValidatorType {
|
|
99
|
+
constructor(base, fn) {
|
|
100
|
+
super();
|
|
101
|
+
this.base = base;
|
|
102
|
+
this.fn = fn;
|
|
103
|
+
}
|
|
104
|
+
toOpenApi() {
|
|
105
|
+
return this.base.toOpenApi();
|
|
106
|
+
}
|
|
107
|
+
_validate(value, path) {
|
|
108
|
+
const res = this.base._validate(value, path);
|
|
109
|
+
if (!res.success)
|
|
110
|
+
return res;
|
|
111
|
+
if (res.data !== undefined) {
|
|
112
|
+
try {
|
|
113
|
+
const transformed = this.fn(res.data);
|
|
114
|
+
return { success: true, data: transformed };
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
return {
|
|
118
|
+
success: false,
|
|
119
|
+
errors: [
|
|
120
|
+
{
|
|
121
|
+
path,
|
|
122
|
+
message: err instanceof Error ? err.message : 'Transform failed',
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { success: true, data: res.data };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.TransformValidator = TransformValidator;
|
|
132
|
+
class AsyncRefineValidator extends ValidatorType {
|
|
133
|
+
constructor(base, check, message) {
|
|
134
|
+
super();
|
|
135
|
+
this.base = base;
|
|
136
|
+
this.check = check;
|
|
137
|
+
this.message = message;
|
|
138
|
+
}
|
|
139
|
+
toOpenApi() {
|
|
140
|
+
return this.base.toOpenApi();
|
|
141
|
+
}
|
|
142
|
+
_validate(_value, _path) {
|
|
143
|
+
throw new Error('Async validation requires parseAsync() to be used');
|
|
144
|
+
}
|
|
145
|
+
async _validateAsync(value, path) {
|
|
146
|
+
const res = await this.base.validateAsync(value, path);
|
|
147
|
+
if (!res.success)
|
|
148
|
+
return res;
|
|
149
|
+
if (res.data !== undefined) {
|
|
150
|
+
if (!(await this.check(res.data))) {
|
|
151
|
+
const msg = typeof this.message === 'function'
|
|
152
|
+
? this.message(res.data)
|
|
153
|
+
: this.message;
|
|
154
|
+
return { success: false, errors: [{ path, message: msg }] };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return res;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.AsyncRefineValidator = AsyncRefineValidator;
|
|
161
|
+
class StringValidator extends ValidatorType {
|
|
162
|
+
min(len, message) {
|
|
163
|
+
this.minLen = len;
|
|
164
|
+
this.minMsg = message;
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
max(len, message) {
|
|
168
|
+
this.maxLen = len;
|
|
169
|
+
this.maxMsg = message;
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
email(message) {
|
|
173
|
+
this.isEmail = true;
|
|
174
|
+
this.emailMsg = message;
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
regex(pattern, message) {
|
|
178
|
+
this.regexPattern = pattern;
|
|
179
|
+
this.regexMsg = message;
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
toOpenApi() {
|
|
183
|
+
const schema = { type: 'string' };
|
|
184
|
+
if (this.minLen !== undefined)
|
|
185
|
+
schema.minLength = this.minLen;
|
|
186
|
+
if (this.maxLen !== undefined)
|
|
187
|
+
schema.maxLength = this.maxLen;
|
|
188
|
+
if (this.isEmail)
|
|
189
|
+
schema.format = 'email';
|
|
190
|
+
return schema;
|
|
191
|
+
}
|
|
192
|
+
_validate(value, path) {
|
|
193
|
+
if (value === undefined || value === null) {
|
|
194
|
+
if (this.isOptional)
|
|
195
|
+
return { success: true, data: undefined };
|
|
196
|
+
return { success: false, errors: [{ path, message: 'Required' }] };
|
|
197
|
+
}
|
|
198
|
+
if (typeof value !== 'string')
|
|
199
|
+
return { success: false, errors: [{ path, message: 'Expected string' }] };
|
|
200
|
+
if (this.minLen !== undefined && value.length < this.minLen)
|
|
201
|
+
return {
|
|
202
|
+
success: false,
|
|
203
|
+
errors: [
|
|
204
|
+
{
|
|
205
|
+
path,
|
|
206
|
+
message: this.minMsg ??
|
|
207
|
+
`String must be at least ${this.minLen} characters`,
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
};
|
|
211
|
+
if (this.maxLen !== undefined && value.length > this.maxLen)
|
|
212
|
+
return {
|
|
213
|
+
success: false,
|
|
214
|
+
errors: [
|
|
215
|
+
{
|
|
216
|
+
path,
|
|
217
|
+
message: this.maxMsg ?? `String must be at most ${this.maxLen} characters`,
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
};
|
|
221
|
+
if (this.isEmail && !/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(value))
|
|
222
|
+
return {
|
|
223
|
+
success: false,
|
|
224
|
+
errors: [{ path, message: this.emailMsg ?? 'Invalid email' }],
|
|
225
|
+
};
|
|
226
|
+
if (this.regexPattern !== undefined && !this.regexPattern.test(value))
|
|
227
|
+
return {
|
|
228
|
+
success: false,
|
|
229
|
+
errors: [{ path, message: this.regexMsg ?? 'Invalid format' }],
|
|
230
|
+
};
|
|
231
|
+
return { success: true, data: value };
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
exports.StringValidator = StringValidator;
|
|
235
|
+
class NumberValidator extends ValidatorType {
|
|
236
|
+
min(val, message) {
|
|
237
|
+
this.minVal = val;
|
|
238
|
+
this.minMsg = message;
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
max(val, message) {
|
|
242
|
+
this.maxVal = val;
|
|
243
|
+
this.maxMsg = message;
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
toOpenApi() {
|
|
247
|
+
const schema = { type: 'number' };
|
|
248
|
+
if (this.minVal !== undefined)
|
|
249
|
+
schema.minimum = this.minVal;
|
|
250
|
+
if (this.maxVal !== undefined)
|
|
251
|
+
schema.maximum = this.maxVal;
|
|
252
|
+
return schema;
|
|
253
|
+
}
|
|
254
|
+
_validate(value, path) {
|
|
255
|
+
if (value === undefined || value === null) {
|
|
256
|
+
if (this.isOptional)
|
|
257
|
+
return { success: true, data: undefined };
|
|
258
|
+
return { success: false, errors: [{ path, message: 'Required' }] };
|
|
259
|
+
}
|
|
260
|
+
if (typeof value === 'boolean' ||
|
|
261
|
+
(typeof value === 'string' && value.trim() === '')) {
|
|
262
|
+
return { success: false, errors: [{ path, message: 'Expected number' }] };
|
|
263
|
+
}
|
|
264
|
+
const num = Number(value);
|
|
265
|
+
if (isNaN(num))
|
|
266
|
+
return { success: false, errors: [{ path, message: 'Expected number' }] };
|
|
267
|
+
if (this.minVal !== undefined && num < this.minVal)
|
|
268
|
+
return {
|
|
269
|
+
success: false,
|
|
270
|
+
errors: [
|
|
271
|
+
{
|
|
272
|
+
path,
|
|
273
|
+
message: this.minMsg ?? `Number must be at least ${this.minVal}`,
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
};
|
|
277
|
+
if (this.maxVal !== undefined && num > this.maxVal)
|
|
278
|
+
return {
|
|
279
|
+
success: false,
|
|
280
|
+
errors: [
|
|
281
|
+
{
|
|
282
|
+
path,
|
|
283
|
+
message: this.maxMsg ?? `Number must be at most ${this.maxVal}`,
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
};
|
|
287
|
+
return { success: true, data: num };
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
exports.NumberValidator = NumberValidator;
|
|
291
|
+
class BooleanValidator extends ValidatorType {
|
|
292
|
+
toOpenApi() {
|
|
293
|
+
return { type: 'boolean' };
|
|
294
|
+
}
|
|
295
|
+
_validate(value, path) {
|
|
296
|
+
if (value === undefined || value === null) {
|
|
297
|
+
if (this.isOptional)
|
|
298
|
+
return { success: true, data: undefined };
|
|
299
|
+
return { success: false, errors: [{ path, message: 'Required' }] };
|
|
300
|
+
}
|
|
301
|
+
if (typeof value === 'boolean')
|
|
302
|
+
return { success: true, data: value };
|
|
303
|
+
if (value === 'true' || value === '1')
|
|
304
|
+
return { success: true, data: true };
|
|
305
|
+
if (value === 'false' || value === '0')
|
|
306
|
+
return { success: true, data: false };
|
|
307
|
+
return { success: false, errors: [{ path, message: 'Expected boolean' }] };
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
exports.BooleanValidator = BooleanValidator;
|
|
311
|
+
class ObjectValidator extends ValidatorType {
|
|
312
|
+
constructor(shape) {
|
|
313
|
+
super();
|
|
314
|
+
this.shape = shape;
|
|
315
|
+
this._keys = Object.keys(shape);
|
|
316
|
+
}
|
|
317
|
+
partial() {
|
|
318
|
+
const newShape = {};
|
|
319
|
+
for (const key of this._keys) {
|
|
320
|
+
newShape[key] = this.shape[key].optional();
|
|
321
|
+
}
|
|
322
|
+
return new ObjectValidator(newShape);
|
|
323
|
+
}
|
|
324
|
+
pick(keys) {
|
|
325
|
+
const newShape = {};
|
|
326
|
+
for (const key of keys) {
|
|
327
|
+
if (key in this.shape) {
|
|
328
|
+
newShape[key] = this.shape[key];
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return new ObjectValidator(newShape);
|
|
332
|
+
}
|
|
333
|
+
omit(keys) {
|
|
334
|
+
const newShape = {};
|
|
335
|
+
for (const key of this._keys) {
|
|
336
|
+
if (!keys.includes(key)) {
|
|
337
|
+
newShape[key] = this.shape[key];
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return new ObjectValidator(newShape);
|
|
341
|
+
}
|
|
342
|
+
toOpenApi() {
|
|
343
|
+
const properties = {};
|
|
344
|
+
const required = [];
|
|
345
|
+
for (const key of this._keys) {
|
|
346
|
+
const validator = this.shape[key];
|
|
347
|
+
properties[key] = validator.toOpenApi();
|
|
348
|
+
if (!validator.isOptional) {
|
|
349
|
+
required.push(key);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const schema = {
|
|
353
|
+
type: 'object',
|
|
354
|
+
properties,
|
|
355
|
+
};
|
|
356
|
+
if (required.length > 0)
|
|
357
|
+
schema.required = required;
|
|
358
|
+
return schema;
|
|
359
|
+
}
|
|
360
|
+
_validate(value, path) {
|
|
361
|
+
if (value === undefined || value === null) {
|
|
362
|
+
if (this.isOptional)
|
|
363
|
+
return { success: true, data: undefined };
|
|
364
|
+
return { success: false, errors: [{ path, message: 'Required' }] };
|
|
365
|
+
}
|
|
366
|
+
if (typeof value !== 'object' || Array.isArray(value))
|
|
367
|
+
return { success: false, errors: [{ path, message: 'Expected object' }] };
|
|
368
|
+
const errors = [];
|
|
369
|
+
const data = {};
|
|
370
|
+
for (const key of this._keys) {
|
|
371
|
+
const validator = this.shape[key];
|
|
372
|
+
const fieldPath = path ? `${path}.${key}` : key;
|
|
373
|
+
const result = validator.validate(value[key], fieldPath);
|
|
374
|
+
if (result.success) {
|
|
375
|
+
if (result.data !== undefined)
|
|
376
|
+
data[key] = result.data;
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
for (const error of result.errors) {
|
|
380
|
+
errors.push(error);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (errors.length > 0)
|
|
385
|
+
return { success: false, errors };
|
|
386
|
+
return { success: true, data: data };
|
|
387
|
+
}
|
|
388
|
+
async _validateAsync(value, path) {
|
|
389
|
+
if (value === undefined || value === null) {
|
|
390
|
+
if (this.isOptional)
|
|
391
|
+
return { success: true, data: undefined };
|
|
392
|
+
return { success: false, errors: [{ path, message: 'Required' }] };
|
|
393
|
+
}
|
|
394
|
+
if (typeof value !== 'object' || Array.isArray(value))
|
|
395
|
+
return { success: false, errors: [{ path, message: 'Expected object' }] };
|
|
396
|
+
const errors = [];
|
|
397
|
+
const data = {};
|
|
398
|
+
await Promise.all(this._keys.map(async (key) => {
|
|
399
|
+
const validator = this.shape[key];
|
|
400
|
+
const fieldPath = path ? `${path}.${key}` : key;
|
|
401
|
+
const result = await validator.validateAsync(value[key], fieldPath);
|
|
402
|
+
if (result.success) {
|
|
403
|
+
if (result.data !== undefined)
|
|
404
|
+
data[key] = result.data;
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
for (const error of result.errors) {
|
|
408
|
+
errors.push(error);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}));
|
|
412
|
+
if (errors.length > 0)
|
|
413
|
+
return { success: false, errors };
|
|
414
|
+
return { success: true, data: data };
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
exports.ObjectValidator = ObjectValidator;
|
|
418
|
+
class ArrayValidator extends ValidatorType {
|
|
419
|
+
constructor(schema) {
|
|
420
|
+
super();
|
|
421
|
+
this.schema = schema;
|
|
422
|
+
}
|
|
423
|
+
min(len, message) {
|
|
424
|
+
this.minLen = len;
|
|
425
|
+
this.minMsg = message;
|
|
426
|
+
return this;
|
|
427
|
+
}
|
|
428
|
+
max(len, message) {
|
|
429
|
+
this.maxLen = len;
|
|
430
|
+
this.maxMsg = message;
|
|
431
|
+
return this;
|
|
432
|
+
}
|
|
433
|
+
toOpenApi() {
|
|
434
|
+
const schema = {
|
|
435
|
+
type: 'array',
|
|
436
|
+
items: this.schema.toOpenApi(),
|
|
437
|
+
};
|
|
438
|
+
if (this.minLen !== undefined)
|
|
439
|
+
schema.minItems = this.minLen;
|
|
440
|
+
if (this.maxLen !== undefined)
|
|
441
|
+
schema.maxItems = this.maxLen;
|
|
442
|
+
return schema;
|
|
443
|
+
}
|
|
444
|
+
_validate(value, path) {
|
|
445
|
+
if (value === undefined || value === null) {
|
|
446
|
+
if (this.isOptional)
|
|
447
|
+
return { success: true, data: undefined };
|
|
448
|
+
return { success: false, errors: [{ path, message: 'Required' }] };
|
|
449
|
+
}
|
|
450
|
+
if (!Array.isArray(value))
|
|
451
|
+
return { success: false, errors: [{ path, message: 'Expected array' }] };
|
|
452
|
+
if (this.minLen !== undefined && value.length < this.minLen)
|
|
453
|
+
return {
|
|
454
|
+
success: false,
|
|
455
|
+
errors: [
|
|
456
|
+
{
|
|
457
|
+
path,
|
|
458
|
+
message: this.minMsg ?? `Array must have at least ${this.minLen} items`,
|
|
459
|
+
},
|
|
460
|
+
],
|
|
461
|
+
};
|
|
462
|
+
if (this.maxLen !== undefined && value.length > this.maxLen)
|
|
463
|
+
return {
|
|
464
|
+
success: false,
|
|
465
|
+
errors: [
|
|
466
|
+
{
|
|
467
|
+
path,
|
|
468
|
+
message: this.maxMsg ?? `Array must have at most ${this.maxLen} items`,
|
|
469
|
+
},
|
|
470
|
+
],
|
|
471
|
+
};
|
|
472
|
+
const errors = [];
|
|
473
|
+
const data = [];
|
|
474
|
+
for (let i = 0; i < value.length; i++) {
|
|
475
|
+
const res = this.schema.validate(value[i], path ? `${path}[${i}]` : `[${i}]`);
|
|
476
|
+
if (res.success) {
|
|
477
|
+
data.push(res.data);
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
for (const error of res.errors) {
|
|
481
|
+
errors.push(error);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (errors.length > 0)
|
|
486
|
+
return { success: false, errors };
|
|
487
|
+
return { success: true, data: data };
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
exports.ArrayValidator = ArrayValidator;
|
|
491
|
+
class EnumValidator extends ValidatorType {
|
|
492
|
+
constructor(values) {
|
|
493
|
+
super();
|
|
494
|
+
this.values = values;
|
|
495
|
+
}
|
|
496
|
+
toOpenApi() {
|
|
497
|
+
return { type: 'string', enum: this.values };
|
|
498
|
+
}
|
|
499
|
+
_validate(value, path) {
|
|
500
|
+
if (value === undefined || value === null) {
|
|
501
|
+
if (this.isOptional)
|
|
502
|
+
return { success: true, data: undefined };
|
|
503
|
+
return { success: false, errors: [{ path, message: 'Required' }] };
|
|
504
|
+
}
|
|
505
|
+
if (typeof value !== 'string')
|
|
506
|
+
return { success: false, errors: [{ path, message: 'Expected string' }] };
|
|
507
|
+
if (!this.values.includes(value))
|
|
508
|
+
return {
|
|
509
|
+
success: false,
|
|
510
|
+
errors: [
|
|
511
|
+
{ path, message: `Expected one of: ${this.values.join(', ')}` },
|
|
512
|
+
],
|
|
513
|
+
};
|
|
514
|
+
return { success: true, data: value };
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
exports.EnumValidator = EnumValidator;
|
|
518
|
+
class LiteralValidator extends ValidatorType {
|
|
519
|
+
constructor(exact) {
|
|
520
|
+
super();
|
|
521
|
+
this.exact = exact;
|
|
522
|
+
}
|
|
523
|
+
toOpenApi() {
|
|
524
|
+
return { type: typeof this.exact, enum: [this.exact] };
|
|
525
|
+
}
|
|
526
|
+
_validate(value, path) {
|
|
527
|
+
if (value === undefined || value === null) {
|
|
528
|
+
if (this.isOptional)
|
|
529
|
+
return { success: true, data: undefined };
|
|
530
|
+
return { success: false, errors: [{ path, message: 'Required' }] };
|
|
531
|
+
}
|
|
532
|
+
if (value !== this.exact)
|
|
533
|
+
return {
|
|
534
|
+
success: false,
|
|
535
|
+
errors: [{ path, message: `Expected literal ${this.exact}` }],
|
|
536
|
+
};
|
|
537
|
+
return { success: true, data: value };
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
exports.LiteralValidator = LiteralValidator;
|
|
541
|
+
class UnionValidator extends ValidatorType {
|
|
542
|
+
constructor(schemas) {
|
|
543
|
+
super();
|
|
544
|
+
this.schemas = schemas;
|
|
545
|
+
}
|
|
546
|
+
toOpenApi() {
|
|
547
|
+
return { anyOf: this.schemas.map((s) => s.toOpenApi()) };
|
|
548
|
+
}
|
|
549
|
+
_validate(value, path) {
|
|
550
|
+
if (value === undefined || value === null) {
|
|
551
|
+
if (this.isOptional)
|
|
552
|
+
return { success: true, data: undefined };
|
|
553
|
+
return { success: false, errors: [{ path, message: 'Required' }] };
|
|
554
|
+
}
|
|
555
|
+
const errors = [];
|
|
556
|
+
for (const schema of this.schemas) {
|
|
557
|
+
const res = schema.validate(value, path);
|
|
558
|
+
if (res.success)
|
|
559
|
+
return res;
|
|
560
|
+
errors.push(...res.errors);
|
|
561
|
+
}
|
|
562
|
+
return {
|
|
563
|
+
success: false,
|
|
564
|
+
errors: [{ path, message: 'Invalid union value' }],
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
exports.UnionValidator = UnionValidator;
|
|
569
|
+
class DateValidator extends ValidatorType {
|
|
570
|
+
toOpenApi() {
|
|
571
|
+
return { type: 'string', format: 'date-time' };
|
|
572
|
+
}
|
|
573
|
+
_validate(value, path) {
|
|
574
|
+
if (value === undefined || value === null) {
|
|
575
|
+
if (this.isOptional)
|
|
576
|
+
return { success: true, data: undefined };
|
|
577
|
+
return { success: false, errors: [{ path, message: 'Required' }] };
|
|
578
|
+
}
|
|
579
|
+
let date;
|
|
580
|
+
if (value instanceof Date) {
|
|
581
|
+
date = value;
|
|
582
|
+
}
|
|
583
|
+
else if (typeof value === 'string' || typeof value === 'number') {
|
|
584
|
+
date = new Date(value);
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
return {
|
|
588
|
+
success: false,
|
|
589
|
+
errors: [{ path, message: 'Expected date string or object' }],
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
if (isNaN(date.getTime())) {
|
|
593
|
+
return { success: false, errors: [{ path, message: 'Invalid date' }] };
|
|
594
|
+
}
|
|
595
|
+
return { success: true, data: date };
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
exports.DateValidator = DateValidator;
|
|
599
|
+
class RecordValidator extends ValidatorType {
|
|
600
|
+
constructor(schema) {
|
|
601
|
+
super();
|
|
602
|
+
this.schema = schema;
|
|
603
|
+
}
|
|
604
|
+
toOpenApi() {
|
|
605
|
+
return { type: 'object', additionalProperties: this.schema.toOpenApi() };
|
|
606
|
+
}
|
|
607
|
+
_validate(value, path) {
|
|
608
|
+
if (value === undefined || value === null) {
|
|
609
|
+
if (this.isOptional)
|
|
610
|
+
return { success: true, data: undefined };
|
|
611
|
+
return { success: false, errors: [{ path, message: 'Required' }] };
|
|
612
|
+
}
|
|
613
|
+
if (typeof value !== 'object' || Array.isArray(value))
|
|
614
|
+
return { success: false, errors: [{ path, message: 'Expected object' }] };
|
|
615
|
+
const errors = [];
|
|
616
|
+
const data = {};
|
|
617
|
+
for (const key in value) {
|
|
618
|
+
const fieldPath = path ? `${path}.${key}` : key;
|
|
619
|
+
const res = this.schema.validate(value[key], fieldPath);
|
|
620
|
+
if (res.success) {
|
|
621
|
+
data[key] = res.data;
|
|
622
|
+
}
|
|
623
|
+
else {
|
|
624
|
+
for (const error of res.errors) {
|
|
625
|
+
errors.push(error);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (errors.length > 0)
|
|
630
|
+
return { success: false, errors };
|
|
631
|
+
return { success: true, data: data };
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
exports.RecordValidator = RecordValidator;
|
|
635
|
+
// ─── Any Validator ─────────────────────────────────────────────────────────────
|
|
636
|
+
class AnyValidator extends ValidatorType {
|
|
637
|
+
toOpenApi() {
|
|
638
|
+
return {};
|
|
639
|
+
}
|
|
640
|
+
_validate(value) {
|
|
641
|
+
return { success: true, data: value };
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
exports.AnyValidator = AnyValidator;
|
|
645
|
+
class FileValidator extends ValidatorType {
|
|
646
|
+
maxSize(bytes) {
|
|
647
|
+
this._maxSize = bytes;
|
|
648
|
+
return this;
|
|
649
|
+
}
|
|
650
|
+
mimeTypes(types) {
|
|
651
|
+
this._mimeTypes = types;
|
|
652
|
+
return this;
|
|
653
|
+
}
|
|
654
|
+
toOpenApi() {
|
|
655
|
+
return { type: 'string', format: 'binary' };
|
|
656
|
+
}
|
|
657
|
+
_validate(value, path) {
|
|
658
|
+
if (value === undefined || value === null) {
|
|
659
|
+
if (this.isOptional)
|
|
660
|
+
return { success: true, data: undefined };
|
|
661
|
+
return { success: false, errors: [{ path, message: 'Required' }] };
|
|
662
|
+
}
|
|
663
|
+
// We expect the busboy parsed object: { filename, mimeType, buffer }
|
|
664
|
+
if (typeof value === 'object' &&
|
|
665
|
+
value !== null &&
|
|
666
|
+
'buffer' in value &&
|
|
667
|
+
Buffer.isBuffer(value.buffer)) {
|
|
668
|
+
const file = value;
|
|
669
|
+
if (this._maxSize && file.buffer.length > this._maxSize) {
|
|
670
|
+
return {
|
|
671
|
+
success: false,
|
|
672
|
+
errors: [
|
|
673
|
+
{ path, message: `File size exceeds ${this._maxSize} bytes` },
|
|
674
|
+
],
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
if (this._mimeTypes && !this._mimeTypes.includes(file.mimeType)) {
|
|
678
|
+
return {
|
|
679
|
+
success: false,
|
|
680
|
+
errors: [
|
|
681
|
+
{
|
|
682
|
+
path,
|
|
683
|
+
message: `Invalid mime type. Expected one of: ${this._mimeTypes.join(', ')}`,
|
|
684
|
+
},
|
|
685
|
+
],
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
return { success: true, data: file };
|
|
689
|
+
}
|
|
690
|
+
return { success: false, errors: [{ path, message: 'Expected file' }] };
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
exports.FileValidator = FileValidator;
|
|
694
|
+
exports.v = {
|
|
695
|
+
string: () => new StringValidator(),
|
|
696
|
+
number: () => new NumberValidator(),
|
|
697
|
+
boolean: () => new BooleanValidator(),
|
|
698
|
+
object: (shape) => new ObjectValidator(shape),
|
|
699
|
+
array: (schema) => new ArrayValidator(schema),
|
|
700
|
+
enum: (values) => new EnumValidator(values),
|
|
701
|
+
literal: (exact) => new LiteralValidator(exact),
|
|
702
|
+
union: (schemas) => new UnionValidator(schemas),
|
|
703
|
+
date: () => new DateValidator(),
|
|
704
|
+
record: (schema) => new RecordValidator(schema),
|
|
705
|
+
any: () => new AnyValidator(),
|
|
706
|
+
file: () => new FileValidator(),
|
|
707
|
+
env: (schema) => {
|
|
708
|
+
const result = schema.validate(process.env, 'process.env');
|
|
709
|
+
if (!result.success) {
|
|
710
|
+
const messages = result.errors
|
|
711
|
+
.map((e) => ` - ${e.path.replace('process.env.', '')}: ${e.message}`)
|
|
712
|
+
.join('\n');
|
|
713
|
+
console.error(`\x1b[31m Environment Validation Failed:\x1b[0m\n${messages}`);
|
|
714
|
+
process.exit(1);
|
|
715
|
+
}
|
|
716
|
+
return result.data;
|
|
717
|
+
},
|
|
718
|
+
};
|
|
719
|
+
//# sourceMappingURL=validator.js.map
|