@encore.dev/sdk 0.0.0 → 2.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +362 -0
- package/README.md +245 -2
- package/app_meta.test.ts +154 -0
- package/app_meta.ts +226 -0
- package/config/config.test.ts +384 -0
- package/config/config.ts +236 -0
- package/config/mod.ts +15 -0
- package/config/secrets.ts +173 -0
- package/config/value.ts +239 -0
- package/cron/mod.test.ts +52 -0
- package/cron/mod.ts +62 -0
- package/dist/app_meta.d.ts +126 -0
- package/dist/app_meta.d.ts.map +1 -0
- package/dist/app_meta.js +67 -0
- package/dist/app_meta.js.map +1 -0
- package/dist/config/config.d.ts +135 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +115 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/mod.d.ts +5 -0
- package/dist/config/mod.d.ts.map +1 -0
- package/dist/config/mod.js +3 -0
- package/dist/config/mod.js.map +1 -0
- package/dist/config/secrets.d.ts +124 -0
- package/dist/config/secrets.d.ts.map +1 -0
- package/dist/config/secrets.js +73 -0
- package/dist/config/secrets.js.map +1 -0
- package/dist/config/value.d.ts +54 -0
- package/dist/config/value.d.ts.map +1 -0
- package/dist/config/value.js +181 -0
- package/dist/config/value.js.map +1 -0
- package/dist/cron/mod.d.ts +57 -0
- package/dist/cron/mod.d.ts.map +1 -0
- package/dist/cron/mod.js +39 -0
- package/dist/cron/mod.js.map +1 -0
- package/dist/frontends/mod.d.ts +39 -0
- package/dist/frontends/mod.d.ts.map +1 -0
- package/dist/frontends/mod.js +47 -0
- package/dist/frontends/mod.js.map +1 -0
- package/dist/gateway/errors.d.ts +101 -0
- package/dist/gateway/errors.d.ts.map +1 -0
- package/dist/gateway/errors.js +146 -0
- package/dist/gateway/errors.js.map +1 -0
- package/dist/gateway/match.d.ts +127 -0
- package/dist/gateway/match.d.ts.map +1 -0
- package/dist/gateway/match.js +206 -0
- package/dist/gateway/match.js.map +1 -0
- package/dist/gateway/middleware.d.ts +108 -0
- package/dist/gateway/middleware.d.ts.map +1 -0
- package/dist/gateway/middleware.js +9 -0
- package/dist/gateway/middleware.js.map +1 -0
- package/dist/gateway/mod.d.ts +130 -0
- package/dist/gateway/mod.d.ts.map +1 -0
- package/dist/gateway/mod.js +188 -0
- package/dist/gateway/mod.js.map +1 -0
- package/dist/gateway/request.d.ts +304 -0
- package/dist/gateway/request.d.ts.map +1 -0
- package/dist/gateway/request.js +403 -0
- package/dist/gateway/request.js.map +1 -0
- package/dist/gateway/serve.d.ts +114 -0
- package/dist/gateway/serve.d.ts.map +1 -0
- package/dist/gateway/serve.js +510 -0
- package/dist/gateway/serve.js.map +1 -0
- package/dist/gateways/mod.d.ts +42 -0
- package/dist/gateways/mod.d.ts.map +1 -0
- package/dist/gateways/mod.js +55 -0
- package/dist/gateways/mod.js.map +1 -0
- package/dist/internal/clients/call.d.ts +171 -0
- package/dist/internal/clients/call.d.ts.map +1 -0
- package/dist/internal/clients/call.js +284 -0
- package/dist/internal/clients/call.js.map +1 -0
- package/dist/internal/clients/grpc.d.ts +108 -0
- package/dist/internal/clients/grpc.d.ts.map +1 -0
- package/dist/internal/clients/grpc.js +349 -0
- package/dist/internal/clients/grpc.js.map +1 -0
- package/dist/internal/clients/mod.d.ts +81 -0
- package/dist/internal/clients/mod.d.ts.map +1 -0
- package/dist/internal/clients/mod.js +237 -0
- package/dist/internal/clients/mod.js.map +1 -0
- package/dist/internal/fetch.d.ts +67 -0
- package/dist/internal/fetch.d.ts.map +1 -0
- package/dist/internal/fetch.js +264 -0
- package/dist/internal/fetch.js.map +1 -0
- package/dist/internal/otel/backend.d.ts +52 -0
- package/dist/internal/otel/backend.d.ts.map +1 -0
- package/dist/internal/otel/backend.js +2 -0
- package/dist/internal/otel/backend.js.map +1 -0
- package/dist/internal/otel/context.d.ts +11 -0
- package/dist/internal/otel/context.d.ts.map +1 -0
- package/dist/internal/otel/context.js +34 -0
- package/dist/internal/otel/context.js.map +1 -0
- package/dist/internal/otel/context_manager.d.ts +23 -0
- package/dist/internal/otel/context_manager.d.ts.map +1 -0
- package/dist/internal/otel/context_manager.js +120 -0
- package/dist/internal/otel/context_manager.js.map +1 -0
- package/dist/internal/otel/encode.d.ts +114 -0
- package/dist/internal/otel/encode.d.ts.map +1 -0
- package/dist/internal/otel/encode.js +290 -0
- package/dist/internal/otel/encode.js.map +1 -0
- package/dist/internal/otel/http.d.ts +11 -0
- package/dist/internal/otel/http.d.ts.map +1 -0
- package/dist/internal/otel/http.js +65 -0
- package/dist/internal/otel/http.js.map +1 -0
- package/dist/internal/otel/index.d.ts +9 -0
- package/dist/internal/otel/index.d.ts.map +1 -0
- package/dist/internal/otel/index.js +8 -0
- package/dist/internal/otel/index.js.map +1 -0
- package/dist/internal/otel/meter.d.ts +74 -0
- package/dist/internal/otel/meter.d.ts.map +1 -0
- package/dist/internal/otel/meter.js +265 -0
- package/dist/internal/otel/meter.js.map +1 -0
- package/dist/internal/otel/propagator.d.ts +15 -0
- package/dist/internal/otel/propagator.d.ts.map +1 -0
- package/dist/internal/otel/propagator.js +61 -0
- package/dist/internal/otel/propagator.js.map +1 -0
- package/dist/internal/otel/provider.d.ts +13 -0
- package/dist/internal/otel/provider.d.ts.map +1 -0
- package/dist/internal/otel/provider.js +22 -0
- package/dist/internal/otel/provider.js.map +1 -0
- package/dist/internal/otel/span.d.ts +75 -0
- package/dist/internal/otel/span.d.ts.map +1 -0
- package/dist/internal/otel/span.js +234 -0
- package/dist/internal/otel/span.js.map +1 -0
- package/dist/internal/otel/tracer.d.ts +16 -0
- package/dist/internal/otel/tracer.d.ts.map +1 -0
- package/dist/internal/otel/tracer.js +71 -0
- package/dist/internal/otel/tracer.js.map +1 -0
- package/dist/internal/reqfields.d.ts +170 -0
- package/dist/internal/reqfields.d.ts.map +1 -0
- package/dist/internal/reqfields.js +349 -0
- package/dist/internal/reqfields.js.map +1 -0
- package/dist/internal/runtime/meter.d.ts +12 -0
- package/dist/internal/runtime/meter.d.ts.map +1 -0
- package/dist/internal/runtime/meter.js +22 -0
- package/dist/internal/runtime/meter.js.map +1 -0
- package/dist/internal/runtime/mod.d.ts +18 -0
- package/dist/internal/runtime/mod.d.ts.map +1 -0
- package/dist/internal/runtime/mod.js +59 -0
- package/dist/internal/runtime/mod.js.map +1 -0
- package/dist/internal/runtime/napi/napi.cjs +308 -0
- package/dist/internal/runtime/napi/napi.d.cts +1251 -0
- package/dist/internal/runtime/shutdown.d.ts +91 -0
- package/dist/internal/runtime/shutdown.d.ts.map +1 -0
- package/dist/internal/runtime/shutdown.js +299 -0
- package/dist/internal/runtime/shutdown.js.map +1 -0
- package/dist/internal/testing/carry.d.ts +49 -0
- package/dist/internal/testing/carry.d.ts.map +1 -0
- package/dist/internal/testing/carry.js +77 -0
- package/dist/internal/testing/carry.js.map +1 -0
- package/dist/internal/testing/runner.d.ts +2 -0
- package/dist/internal/testing/runner.d.ts.map +1 -0
- package/dist/internal/testing/runner.js +10 -0
- package/dist/internal/testing/runner.js.map +1 -0
- package/dist/internal/testing/scope.d.ts +112 -0
- package/dist/internal/testing/scope.d.ts.map +1 -0
- package/dist/internal/testing/scope.js +346 -0
- package/dist/internal/testing/scope.js.map +1 -0
- package/dist/internal/testing/steps.d.ts +55 -0
- package/dist/internal/testing/steps.d.ts.map +1 -0
- package/dist/internal/testing/steps.js +295 -0
- package/dist/internal/testing/steps.js.map +1 -0
- package/dist/internal/testing/telemetry.d.ts +305 -0
- package/dist/internal/testing/telemetry.d.ts.map +1 -0
- package/dist/internal/testing/telemetry.js +188 -0
- package/dist/internal/testing/telemetry.js.map +1 -0
- package/dist/internal/utils/constraints.d.ts +10 -0
- package/dist/internal/utils/constraints.d.ts.map +1 -0
- package/dist/internal/utils/constraints.js +2 -0
- package/dist/internal/utils/constraints.js.map +1 -0
- package/dist/log/index.d.ts +40 -0
- package/dist/log/index.d.ts.map +1 -0
- package/dist/log/index.js +44 -0
- package/dist/log/index.js.map +1 -0
- package/dist/log/logger.d.ts +125 -0
- package/dist/log/logger.d.ts.map +1 -0
- package/dist/log/logger.js +203 -0
- package/dist/log/logger.js.map +1 -0
- package/dist/log/runtime.d.ts +21 -0
- package/dist/log/runtime.d.ts.map +1 -0
- package/dist/log/runtime.js +22 -0
- package/dist/log/runtime.js.map +1 -0
- package/dist/log/stderr.d.ts +10 -0
- package/dist/log/stderr.d.ts.map +1 -0
- package/dist/log/stderr.js +25 -0
- package/dist/log/stderr.js.map +1 -0
- package/dist/metrics/mod.d.ts +242 -0
- package/dist/metrics/mod.d.ts.map +1 -0
- package/dist/metrics/mod.js +353 -0
- package/dist/metrics/mod.js.map +1 -0
- package/dist/mod.d.ts +5 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +3 -0
- package/dist/mod.js.map +1 -0
- package/dist/otel.d.ts +10 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/otel.js +13 -0
- package/dist/otel.js.map +1 -0
- package/dist/pubsub/encoding.d.ts +8 -0
- package/dist/pubsub/encoding.d.ts.map +1 -0
- package/dist/pubsub/encoding.js +18 -0
- package/dist/pubsub/encoding.js.map +1 -0
- package/dist/pubsub/mod.d.ts +7 -0
- package/dist/pubsub/mod.d.ts.map +1 -0
- package/dist/pubsub/mod.js +3 -0
- package/dist/pubsub/mod.js.map +1 -0
- package/dist/pubsub/refs.d.ts +20 -0
- package/dist/pubsub/refs.d.ts.map +1 -0
- package/dist/pubsub/refs.js +11 -0
- package/dist/pubsub/refs.js.map +1 -0
- package/dist/pubsub/subscription.d.ts +223 -0
- package/dist/pubsub/subscription.d.ts.map +1 -0
- package/dist/pubsub/subscription.js +121 -0
- package/dist/pubsub/subscription.js.map +1 -0
- package/dist/pubsub/topic.d.ts +218 -0
- package/dist/pubsub/topic.d.ts.map +1 -0
- package/dist/pubsub/topic.js +281 -0
- package/dist/pubsub/topic.js.map +1 -0
- package/dist/reqctx/mod.d.ts +174 -0
- package/dist/reqctx/mod.d.ts.map +1 -0
- package/dist/reqctx/mod.js +144 -0
- package/dist/reqctx/mod.js.map +1 -0
- package/dist/services/index.d.ts +171 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +187 -0
- package/dist/services/index.js.map +1 -0
- package/dist/shutdown/mod.d.ts +60 -0
- package/dist/shutdown/mod.d.ts.map +1 -0
- package/dist/shutdown/mod.js +59 -0
- package/dist/shutdown/mod.js.map +1 -0
- package/dist/storage/clickhouse/database.d.ts +262 -0
- package/dist/storage/clickhouse/database.d.ts.map +1 -0
- package/dist/storage/clickhouse/database.js +362 -0
- package/dist/storage/clickhouse/database.js.map +1 -0
- package/dist/storage/clickhouse/errors.d.ts +67 -0
- package/dist/storage/clickhouse/errors.d.ts.map +1 -0
- package/dist/storage/clickhouse/errors.js +91 -0
- package/dist/storage/clickhouse/errors.js.map +1 -0
- package/dist/storage/clickhouse/mod.d.ts +31 -0
- package/dist/storage/clickhouse/mod.d.ts.map +1 -0
- package/dist/storage/clickhouse/mod.js +29 -0
- package/dist/storage/clickhouse/mod.js.map +1 -0
- package/dist/storage/objects/bucket.d.ts +522 -0
- package/dist/storage/objects/bucket.d.ts.map +1 -0
- package/dist/storage/objects/bucket.js +414 -0
- package/dist/storage/objects/bucket.js.map +1 -0
- package/dist/storage/objects/error.d.ts +24 -0
- package/dist/storage/objects/error.d.ts.map +1 -0
- package/dist/storage/objects/error.js +105 -0
- package/dist/storage/objects/error.js.map +1 -0
- package/dist/storage/objects/mod.d.ts +5 -0
- package/dist/storage/objects/mod.d.ts.map +1 -0
- package/dist/storage/objects/mod.js +3 -0
- package/dist/storage/objects/mod.js.map +1 -0
- package/dist/storage/objects/refs.d.ts +47 -0
- package/dist/storage/objects/refs.d.ts.map +1 -0
- package/dist/storage/objects/refs.js +26 -0
- package/dist/storage/objects/refs.js.map +1 -0
- package/dist/storage/postgres/database.d.ts +365 -0
- package/dist/storage/postgres/database.d.ts.map +1 -0
- package/dist/storage/postgres/database.js +480 -0
- package/dist/storage/postgres/database.js.map +1 -0
- package/dist/storage/postgres/errors.d.ts +120 -0
- package/dist/storage/postgres/errors.d.ts.map +1 -0
- package/dist/storage/postgres/errors.js +162 -0
- package/dist/storage/postgres/errors.js.map +1 -0
- package/dist/storage/postgres/interval.d.ts +44 -0
- package/dist/storage/postgres/interval.d.ts.map +1 -0
- package/dist/storage/postgres/interval.js +153 -0
- package/dist/storage/postgres/interval.js.map +1 -0
- package/dist/storage/postgres/mod.d.ts +5 -0
- package/dist/storage/postgres/mod.d.ts.map +1 -0
- package/dist/storage/postgres/mod.js +4 -0
- package/dist/storage/postgres/mod.js.map +1 -0
- package/dist/storage/redis/bitfield.d.ts +67 -0
- package/dist/storage/redis/bitfield.d.ts.map +1 -0
- package/dist/storage/redis/bitfield.js +114 -0
- package/dist/storage/redis/bitfield.js.map +1 -0
- package/dist/storage/redis/command.d.ts +45 -0
- package/dist/storage/redis/command.d.ts.map +1 -0
- package/dist/storage/redis/command.js +78 -0
- package/dist/storage/redis/command.js.map +1 -0
- package/dist/storage/redis/commands.d.ts +657 -0
- package/dist/storage/redis/commands.d.ts.map +1 -0
- package/dist/storage/redis/commands.js +759 -0
- package/dist/storage/redis/commands.js.map +1 -0
- package/dist/storage/redis/database.d.ts +336 -0
- package/dist/storage/redis/database.d.ts.map +1 -0
- package/dist/storage/redis/database.js +398 -0
- package/dist/storage/redis/database.js.map +1 -0
- package/dist/storage/redis/mod.d.ts +115 -0
- package/dist/storage/redis/mod.d.ts.map +1 -0
- package/dist/storage/redis/mod.js +109 -0
- package/dist/storage/redis/mod.js.map +1 -0
- package/dist/storage/redis/native.d.ts +16 -0
- package/dist/storage/redis/native.d.ts.map +1 -0
- package/dist/storage/redis/native.js +21 -0
- package/dist/storage/redis/native.js.map +1 -0
- package/dist/storage/redis/options.d.ts +90 -0
- package/dist/storage/redis/options.d.ts.map +1 -0
- package/dist/storage/redis/options.js +53 -0
- package/dist/storage/redis/options.js.map +1 -0
- package/dist/storage/redis/pubsub.d.ts +55 -0
- package/dist/storage/redis/pubsub.d.ts.map +1 -0
- package/dist/storage/redis/pubsub.js +88 -0
- package/dist/storage/redis/pubsub.js.map +1 -0
- package/dist/storage/redis/reply.d.ts +290 -0
- package/dist/storage/redis/reply.d.ts.map +1 -0
- package/dist/storage/redis/reply.js +611 -0
- package/dist/storage/redis/reply.js.map +1 -0
- package/dist/storage/redis/scan.d.ts +12 -0
- package/dist/storage/redis/scan.d.ts.map +1 -0
- package/dist/storage/redis/scan.js +76 -0
- package/dist/storage/redis/scan.js.map +1 -0
- package/dist/storage/redis/script.d.ts +92 -0
- package/dist/storage/redis/script.d.ts.map +1 -0
- package/dist/storage/redis/script.js +143 -0
- package/dist/storage/redis/script.js.map +1 -0
- package/dist/storage/redis/target.d.ts +49 -0
- package/dist/storage/redis/target.d.ts.map +1 -0
- package/dist/storage/redis/target.js +93 -0
- package/dist/storage/redis/target.js.map +1 -0
- package/dist/storage/redis/wire.d.ts +102 -0
- package/dist/storage/redis/wire.d.ts.map +1 -0
- package/dist/storage/redis/wire.js +309 -0
- package/dist/storage/redis/wire.js.map +1 -0
- package/dist/testing/bun.d.ts +8 -0
- package/dist/testing/bun.d.ts.map +1 -0
- package/dist/testing/bun.js +13 -0
- package/dist/testing/bun.js.map +1 -0
- package/dist/testing/jest.d.ts +8 -0
- package/dist/testing/jest.d.ts.map +1 -0
- package/dist/testing/jest.js +11 -0
- package/dist/testing/jest.js.map +1 -0
- package/dist/testing/mod.d.ts +183 -0
- package/dist/testing/mod.d.ts.map +1 -0
- package/dist/testing/mod.js +271 -0
- package/dist/testing/mod.js.map +1 -0
- package/dist/testing/node.d.ts +9 -0
- package/dist/testing/node.d.ts.map +1 -0
- package/dist/testing/node.js +12 -0
- package/dist/testing/node.js.map +1 -0
- package/dist/testing/playwright.d.ts +93 -0
- package/dist/testing/playwright.d.ts.map +1 -0
- package/dist/testing/playwright.js +164 -0
- package/dist/testing/playwright.js.map +1 -0
- package/dist/testing/puppeteer.d.ts +36 -0
- package/dist/testing/puppeteer.d.ts.map +1 -0
- package/dist/testing/puppeteer.js +70 -0
- package/dist/testing/puppeteer.js.map +1 -0
- package/dist/testing/system.d.ts +181 -0
- package/dist/testing/system.d.ts.map +1 -0
- package/dist/testing/system.js +255 -0
- package/dist/testing/system.js.map +1 -0
- package/dist/testing/vitest.d.ts +8 -0
- package/dist/testing/vitest.d.ts.map +1 -0
- package/dist/testing/vitest.js +13 -0
- package/dist/testing/vitest.js.map +1 -0
- package/dist/tracing/http.d.ts +11 -0
- package/dist/tracing/http.d.ts.map +1 -0
- package/dist/tracing/http.js +34 -0
- package/dist/tracing/http.js.map +1 -0
- package/dist/tracing/mod.d.ts +20 -0
- package/dist/tracing/mod.d.ts.map +1 -0
- package/dist/tracing/mod.js +47 -0
- package/dist/tracing/mod.js.map +1 -0
- package/dist/tracing/node.d.ts +10 -0
- package/dist/tracing/node.d.ts.map +1 -0
- package/dist/tracing/node.js +142 -0
- package/dist/tracing/node.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/mod.d.ts +43 -0
- package/dist/types/mod.d.ts.map +1 -0
- package/dist/types/mod.js +65 -0
- package/dist/types/mod.js.map +1 -0
- package/frontends/mod.test.ts +51 -0
- package/frontends/mod.ts +50 -0
- package/gateway/errors.ts +172 -0
- package/gateway/gateway.e2e.test.ts +297 -0
- package/gateway/gateway.test.ts +891 -0
- package/gateway/match.ts +239 -0
- package/gateway/middleware.ts +134 -0
- package/gateway/mod.ts +211 -0
- package/gateway/request.ts +578 -0
- package/gateway/serve.ts +738 -0
- package/gateways/mod.ts +60 -0
- package/internal/clients/call.ts +418 -0
- package/internal/clients/grpc.test.ts +664 -0
- package/internal/clients/grpc.ts +485 -0
- package/internal/clients/mod.test.ts +481 -0
- package/internal/clients/mod.ts +337 -0
- package/internal/fetch.ts +305 -0
- package/internal/otel/backend.ts +60 -0
- package/internal/otel/context.test.ts +70 -0
- package/internal/otel/context.ts +48 -0
- package/internal/otel/context_manager.test.ts +154 -0
- package/internal/otel/context_manager.ts +141 -0
- package/internal/otel/encode.test.ts +266 -0
- package/internal/otel/encode.ts +408 -0
- package/internal/otel/http.ts +92 -0
- package/internal/otel/index.ts +14 -0
- package/internal/otel/meter.test.ts +231 -0
- package/internal/otel/meter.ts +332 -0
- package/internal/otel/propagator.test.ts +105 -0
- package/internal/otel/propagator.ts +68 -0
- package/internal/otel/provider.ts +26 -0
- package/internal/otel/span.ts +281 -0
- package/internal/otel/tracer.test.ts +380 -0
- package/internal/otel/tracer.ts +111 -0
- package/internal/reqfields.ts +423 -0
- package/internal/runtime/meter.ts +26 -0
- package/internal/runtime/mod.ts +81 -0
- package/internal/runtime/napi/napi.cjs +308 -0
- package/internal/runtime/napi/napi.d.cts +1251 -0
- package/internal/runtime/shutdown.test.ts +457 -0
- package/internal/runtime/shutdown.ts +350 -0
- package/internal/testing/carry.test.ts +242 -0
- package/internal/testing/carry.ts +101 -0
- package/internal/testing/runner.ts +10 -0
- package/internal/testing/scope.ts +384 -0
- package/internal/testing/steps.test.ts +152 -0
- package/internal/testing/steps.ts +342 -0
- package/internal/testing/telemetry.test.ts +210 -0
- package/internal/testing/telemetry.ts +466 -0
- package/internal/utils/constraints.ts +12 -0
- package/log/index.ts +107 -0
- package/log/logger.test.ts +194 -0
- package/log/logger.ts +308 -0
- package/log/runtime.test.ts +65 -0
- package/log/runtime.ts +40 -0
- package/log/stderr.test.ts +23 -0
- package/log/stderr.ts +24 -0
- package/metrics/export.test.ts +337 -0
- package/metrics/mod.test.ts +177 -0
- package/metrics/mod.ts +450 -0
- package/mod.ts +15 -0
- package/otel.test.ts +91 -0
- package/otel.ts +17 -0
- package/package.json +208 -5
- package/pubsub/encoding.ts +18 -0
- package/pubsub/mod.ts +26 -0
- package/pubsub/pubsub.test.ts +405 -0
- package/pubsub/refs.ts +38 -0
- package/pubsub/subscription.ts +359 -0
- package/pubsub/topic.test.ts +147 -0
- package/pubsub/topic.ts +431 -0
- package/reqctx/mod.ts +267 -0
- package/reqctx/reqctx.test.ts +216 -0
- package/scripts/postprocess-docs.test.ts +58 -0
- package/services/index.test.ts +370 -0
- package/services/index.ts +215 -0
- package/shutdown/mod.ts +78 -0
- package/storage/clickhouse/database.integration.test.ts +337 -0
- package/storage/clickhouse/database.test.ts +279 -0
- package/storage/clickhouse/database.ts +586 -0
- package/storage/clickhouse/errors.ts +130 -0
- package/storage/clickhouse/mod.ts +37 -0
- package/storage/objects/bucket.test.ts +573 -0
- package/storage/objects/bucket.ts +968 -0
- package/storage/objects/error.ts +121 -0
- package/storage/objects/mod.ts +50 -0
- package/storage/objects/refs.ts +117 -0
- package/storage/postgres/database.integration.test.ts +450 -0
- package/storage/postgres/database.test.ts +428 -0
- package/storage/postgres/database.ts +658 -0
- package/storage/postgres/errors.ts +186 -0
- package/storage/postgres/interval.test.ts +72 -0
- package/storage/postgres/interval.ts +170 -0
- package/storage/postgres/mod.ts +19 -0
- package/storage/redis/bitfield.ts +162 -0
- package/storage/redis/command.ts +84 -0
- package/storage/redis/commands.ts +1471 -0
- package/storage/redis/database.ts +520 -0
- package/storage/redis/mod.ts +171 -0
- package/storage/redis/native.ts +22 -0
- package/storage/redis/options.ts +119 -0
- package/storage/redis/pubsub.ts +92 -0
- package/storage/redis/redis.test.ts +866 -0
- package/storage/redis/reply.ts +780 -0
- package/storage/redis/runtime.test.ts +248 -0
- package/storage/redis/scan.ts +125 -0
- package/storage/redis/script.ts +162 -0
- package/storage/redis/target.ts +134 -0
- package/storage/redis/wire.ts +345 -0
- package/testing/bun.ts +13 -0
- package/testing/jest.ts +11 -0
- package/testing/mod.ts +393 -0
- package/testing/node.ts +12 -0
- package/testing/playwright.ts +247 -0
- package/testing/puppeteer.ts +101 -0
- package/testing/system.test.ts +108 -0
- package/testing/system.ts +373 -0
- package/testing/vitest.ts +13 -0
- package/tracing/http.ts +49 -0
- package/tracing/mod.ts +83 -0
- package/tracing/native.test.ts +272 -0
- package/tracing/node.ts +176 -0
- package/tracing/tracing.test.ts +953 -0
- package/types/mod.ts +92 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { arrayOf, scoredMembersOf, textOf, } from './reply.js';
|
|
2
|
+
import { Cmd } from './wire.js';
|
|
3
|
+
// The scans: they return an iteration, not a reply.
|
|
4
|
+
//
|
|
5
|
+
// As with Redis's own SCAN, an element present for the whole iteration is
|
|
6
|
+
// returned at least once — possibly more — and one added or removed during it
|
|
7
|
+
// may or may not be.
|
|
8
|
+
/** Iterates over the database's keys. */
|
|
9
|
+
export async function* scanKeys(t, options = {}) {
|
|
10
|
+
const prefix = t.prefix() ?? '';
|
|
11
|
+
// Keys are scanned across the whole server, so the pattern has to select
|
|
12
|
+
// this database's: its prefix, then what was asked for.
|
|
13
|
+
const pattern = prefix
|
|
14
|
+
? escapeGlob(prefix) + (options.pattern ?? '*')
|
|
15
|
+
: options.pattern;
|
|
16
|
+
const base = new Cmd('scan', 'SCAN', false);
|
|
17
|
+
for await (const batch of scanBatches(t, base, pattern, options.count)) {
|
|
18
|
+
for (const item of batch) {
|
|
19
|
+
const key = textOf(item);
|
|
20
|
+
yield key.startsWith(prefix) ? key.slice(prefix.length) : key;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Iterates over a set's members. */
|
|
25
|
+
export async function* scanMembers(t, key, options = {}) {
|
|
26
|
+
const base = new Cmd('sscan', 'SSCAN', false).key(key);
|
|
27
|
+
for await (const batch of scanBatches(t, base, options.pattern, options.count)) {
|
|
28
|
+
for (const item of batch)
|
|
29
|
+
yield textOf(item);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Iterates over a hash's fields, each with its value. */
|
|
33
|
+
export async function* scanFields(t, key, options = {}) {
|
|
34
|
+
const base = new Cmd('hscan', 'HSCAN', false).key(key);
|
|
35
|
+
for await (const batch of scanBatches(t, base, options.pattern, options.count)) {
|
|
36
|
+
if (batch.length % 2 !== 0) {
|
|
37
|
+
throw new TypeError("redis: the scan's reply does not divide into fields and values");
|
|
38
|
+
}
|
|
39
|
+
for (let i = 0; i < batch.length; i += 2) {
|
|
40
|
+
yield { field: textOf(batch[i]), value: textOf(batch[i + 1]) };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Iterates over a sorted set's members, each with its score. */
|
|
45
|
+
export async function* scanScored(t, key, options = {}) {
|
|
46
|
+
const base = new Cmd('zscan', 'ZSCAN', false).key(key);
|
|
47
|
+
for await (const batch of scanBatches(t, base, options.pattern, options.count)) {
|
|
48
|
+
for (const member of scoredMembersOf(batch))
|
|
49
|
+
yield member;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Runs `base` — a scan command, up to its cursor — from cursor 0 until the
|
|
54
|
+
* server says there is no more, yielding each batch it returns.
|
|
55
|
+
*/
|
|
56
|
+
async function* scanBatches(t, base, pattern, count) {
|
|
57
|
+
let cursor = '0';
|
|
58
|
+
do {
|
|
59
|
+
const cmd = base.clone().arg(cursor);
|
|
60
|
+
if (pattern !== undefined)
|
|
61
|
+
cmd.arg('MATCH').arg(pattern);
|
|
62
|
+
if (count)
|
|
63
|
+
cmd.arg('COUNT').arg(count);
|
|
64
|
+
const parts = arrayOf(await t.run(cmd));
|
|
65
|
+
if (parts.length !== 2) {
|
|
66
|
+
throw new TypeError('redis: a scan replied something other than a cursor and a batch');
|
|
67
|
+
}
|
|
68
|
+
cursor = textOf(parts[0]);
|
|
69
|
+
yield arrayOf(parts[1]);
|
|
70
|
+
} while (cursor !== '0');
|
|
71
|
+
}
|
|
72
|
+
/** `text` with the characters a glob pattern gives meaning to escaped. */
|
|
73
|
+
function escapeGlob(text) {
|
|
74
|
+
return text.replace(/[*?[\]\\]/g, c => `\\${c}`);
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=scan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../../../storage/redis/scan.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,E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}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ReplyPromise } from './reply.js';
|
|
2
|
+
import type { Target } from './target.js';
|
|
3
|
+
import { Cmd, type RedisArg } from './wire.js';
|
|
4
|
+
/**
|
|
5
|
+
* A Lua script the database runs, declared at module scope.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { Database, Script } from "@encore.dev/sdk/storage/redis";
|
|
9
|
+
*
|
|
10
|
+
* const LOCKS = new Database("locks");
|
|
11
|
+
*
|
|
12
|
+
* const RELEASE = new Script(`
|
|
13
|
+
* if redis.call("get", KEYS[1]) == ARGV[1] then
|
|
14
|
+
* return redis.call("del", KEYS[1])
|
|
15
|
+
* end
|
|
16
|
+
* return 0
|
|
17
|
+
* `);
|
|
18
|
+
*
|
|
19
|
+
* async function release(job: string, token: string): Promise<boolean> {
|
|
20
|
+
* const released = await LOCKS.script(RELEASE).key(`lock:${job}`).arg(token).invoke().bool();
|
|
21
|
+
* return released === true;
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Only the keys passed through `KEYS`, with {@link Invocation.key}, get the
|
|
26
|
+
* database's key prefix. The script's source and its `ARGV` are sent as they
|
|
27
|
+
* are, and Redis cannot hold a script to `KEYS`: a key it names any other way
|
|
28
|
+
* is the server's key of that name, unprefixed, outside this database's
|
|
29
|
+
* isolation, which can be another database's on the same server. So a script
|
|
30
|
+
* must take every key it touches through `KEYS`.
|
|
31
|
+
*/
|
|
32
|
+
export declare class Script {
|
|
33
|
+
/** The script's source. */
|
|
34
|
+
readonly source: string;
|
|
35
|
+
/** Whether it only reads: see {@link Script.readOnly}. */
|
|
36
|
+
readonly isReadOnly: boolean;
|
|
37
|
+
/** The source's SHA-1, which the server caches the script under. */
|
|
38
|
+
private readonly hash;
|
|
39
|
+
/** Declares a script. */
|
|
40
|
+
constructor(source: string);
|
|
41
|
+
/**
|
|
42
|
+
* Declares a script that only reads. The server refuses to let it write,
|
|
43
|
+
* which is what lets it run on a handle that can only read.
|
|
44
|
+
*/
|
|
45
|
+
static readOnly(source: string): Script;
|
|
46
|
+
/**
|
|
47
|
+
* The command that runs the script: by its hash, which the server has if
|
|
48
|
+
* it has run it before, or by its source.
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
command(byHash: boolean, keys: readonly string[], args: readonly RedisArg[]): Cmd;
|
|
53
|
+
}
|
|
54
|
+
/** A call to a {@link Script}, to give its keys and arguments and then invoke. */
|
|
55
|
+
export declare class Invocation {
|
|
56
|
+
private readonly t;
|
|
57
|
+
private readonly script;
|
|
58
|
+
/** Whether the handle it was made from can only read. */
|
|
59
|
+
private readonly readOnly;
|
|
60
|
+
private readonly keys;
|
|
61
|
+
private readonly args;
|
|
62
|
+
/** @internal */
|
|
63
|
+
constructor(t: Target, script: Script,
|
|
64
|
+
/** Whether the handle it was made from can only read. */
|
|
65
|
+
readOnly: boolean);
|
|
66
|
+
/** A key the script works on: the next of its `KEYS`. */
|
|
67
|
+
key(key: string): this;
|
|
68
|
+
/** An argument: the next of the script's `ARGV`. */
|
|
69
|
+
arg(arg: RedisArg): this;
|
|
70
|
+
/** Runs the script, replying what it returns. */
|
|
71
|
+
invoke(): ReplyPromise;
|
|
72
|
+
private run;
|
|
73
|
+
}
|
|
74
|
+
/** A call to a {@link Script} being queued on a pipeline or a transaction. */
|
|
75
|
+
export declare class QueuedInvocation {
|
|
76
|
+
private readonly queued;
|
|
77
|
+
private readonly script;
|
|
78
|
+
private readonly keys;
|
|
79
|
+
private readonly args;
|
|
80
|
+
/** @internal */
|
|
81
|
+
constructor(queued: Cmd[], script: Script);
|
|
82
|
+
/** A key the script works on: the next of its `KEYS`. */
|
|
83
|
+
key(key: string): this;
|
|
84
|
+
/** An argument: the next of the script's `ARGV`. */
|
|
85
|
+
arg(arg: RedisArg): this;
|
|
86
|
+
/**
|
|
87
|
+
* Queues the call. It is sent by source rather than by hash: a batch cannot
|
|
88
|
+
* stop halfway to send a script the server turns out not to have.
|
|
89
|
+
*/
|
|
90
|
+
queue(): void;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=script.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../../../storage/redis/script.ts"],"names":[],"mappings":"AAEA,OAAO,EAAQ,YAAY,EAAC,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AACrC,OAAO,EAAC,GAAG,EAAe,KAAK,QAAQ,EAAC,MAAM,QAAQ,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,MAAM;IACjB,2BAA2B;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,0DAA0D;IAC1D,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAS;IACrC,oEAAoE;IACpE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAE9B,yBAAyB;gBACb,MAAM,EAAE,MAAM;IAK1B;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAMvC;;;;;OAKG;IACH,OAAO,CACL,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,IAAI,EAAE,SAAS,QAAQ,EAAE,GACxB,GAAG;CAQP;AAED,kFAAkF;AAClF,qBAAa,UAAU;IAMnB,OAAO,CAAC,QAAQ,CAAC,CAAC;IAClB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,yDAAyD;IACzD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAR3B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgB;IACrC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAkB;IAEvC,gBAAgB;gBAEG,CAAC,EAAE,MAAM,EACT,MAAM,EAAE,MAAM;IAC/B,yDAAyD;IACxC,QAAQ,EAAE,OAAO;IAGpC,yDAAyD;IACzD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAKtB,oDAAoD;IACpD,GAAG,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI;IAKxB,iDAAiD;IACjD,MAAM,IAAI,YAAY;YAIR,GAAG;CAqBlB;AAED,8EAA8E;AAC9E,qBAAa,gBAAgB;IAMzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IANzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgB;IACrC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAkB;IAEvC,gBAAgB;gBAEG,MAAM,EAAE,GAAG,EAAE,EACb,MAAM,EAAE,MAAM;IAGjC,yDAAyD;IACzD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAKtB,oDAAoD;IACpD,GAAG,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI;IAKxB;;;OAGG;IACH,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { Reply, ReplyPromise } from './reply.js';
|
|
3
|
+
import { Cmd, ServerError } from './wire.js';
|
|
4
|
+
/**
|
|
5
|
+
* A Lua script the database runs, declared at module scope.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { Database, Script } from "@encore.dev/sdk/storage/redis";
|
|
9
|
+
*
|
|
10
|
+
* const LOCKS = new Database("locks");
|
|
11
|
+
*
|
|
12
|
+
* const RELEASE = new Script(`
|
|
13
|
+
* if redis.call("get", KEYS[1]) == ARGV[1] then
|
|
14
|
+
* return redis.call("del", KEYS[1])
|
|
15
|
+
* end
|
|
16
|
+
* return 0
|
|
17
|
+
* `);
|
|
18
|
+
*
|
|
19
|
+
* async function release(job: string, token: string): Promise<boolean> {
|
|
20
|
+
* const released = await LOCKS.script(RELEASE).key(`lock:${job}`).arg(token).invoke().bool();
|
|
21
|
+
* return released === true;
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Only the keys passed through `KEYS`, with {@link Invocation.key}, get the
|
|
26
|
+
* database's key prefix. The script's source and its `ARGV` are sent as they
|
|
27
|
+
* are, and Redis cannot hold a script to `KEYS`: a key it names any other way
|
|
28
|
+
* is the server's key of that name, unprefixed, outside this database's
|
|
29
|
+
* isolation, which can be another database's on the same server. So a script
|
|
30
|
+
* must take every key it touches through `KEYS`.
|
|
31
|
+
*/
|
|
32
|
+
export class Script {
|
|
33
|
+
/** The script's source. */
|
|
34
|
+
source;
|
|
35
|
+
/** Whether it only reads: see {@link Script.readOnly}. */
|
|
36
|
+
isReadOnly = false;
|
|
37
|
+
/** The source's SHA-1, which the server caches the script under. */
|
|
38
|
+
hash;
|
|
39
|
+
/** Declares a script. */
|
|
40
|
+
constructor(source) {
|
|
41
|
+
this.source = source;
|
|
42
|
+
this.hash = createHash('sha1').update(source).digest('hex');
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Declares a script that only reads. The server refuses to let it write,
|
|
46
|
+
* which is what lets it run on a handle that can only read.
|
|
47
|
+
*/
|
|
48
|
+
static readOnly(source) {
|
|
49
|
+
const script = new Script(source);
|
|
50
|
+
script.isReadOnly = true;
|
|
51
|
+
return script;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The command that runs the script: by its hash, which the server has if
|
|
55
|
+
* it has run it before, or by its source.
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
command(byHash, keys, args) {
|
|
60
|
+
const name = (byHash ? 'EVALSHA' : 'EVAL') + (this.isReadOnly ? '_RO' : '');
|
|
61
|
+
return new Cmd('script', name, !this.isReadOnly)
|
|
62
|
+
.arg(byHash ? this.hash : this.source)
|
|
63
|
+
.arg(keys.length)
|
|
64
|
+
.keys(keys)
|
|
65
|
+
.argsOf(args);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** A call to a {@link Script}, to give its keys and arguments and then invoke. */
|
|
69
|
+
export class Invocation {
|
|
70
|
+
t;
|
|
71
|
+
script;
|
|
72
|
+
readOnly;
|
|
73
|
+
keys = [];
|
|
74
|
+
args = [];
|
|
75
|
+
/** @internal */
|
|
76
|
+
constructor(t, script,
|
|
77
|
+
/** Whether the handle it was made from can only read. */
|
|
78
|
+
readOnly) {
|
|
79
|
+
this.t = t;
|
|
80
|
+
this.script = script;
|
|
81
|
+
this.readOnly = readOnly;
|
|
82
|
+
}
|
|
83
|
+
/** A key the script works on: the next of its `KEYS`. */
|
|
84
|
+
key(key) {
|
|
85
|
+
this.keys.push(key);
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/** An argument: the next of the script's `ARGV`. */
|
|
89
|
+
arg(arg) {
|
|
90
|
+
this.args.push(arg);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
/** Runs the script, replying what it returns. */
|
|
94
|
+
invoke() {
|
|
95
|
+
return new ReplyPromise(this.run());
|
|
96
|
+
}
|
|
97
|
+
async run() {
|
|
98
|
+
try {
|
|
99
|
+
if (this.readOnly && !this.script.isReadOnly) {
|
|
100
|
+
throw new Error('redis: a handle that can only read runs only scripts declared with Script.readOnly');
|
|
101
|
+
}
|
|
102
|
+
const reply = await this.t.run(this.script.command(true, this.keys, this.args));
|
|
103
|
+
// The server has not seen the script: send it, which also caches it.
|
|
104
|
+
if (reply instanceof ServerError && reply.code === 'NOSCRIPT') {
|
|
105
|
+
return new Reply(await this.t.run(this.script.command(false, this.keys, this.args)));
|
|
106
|
+
}
|
|
107
|
+
return new Reply(reply);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
return Reply.failed(err);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** A call to a {@link Script} being queued on a pipeline or a transaction. */
|
|
115
|
+
export class QueuedInvocation {
|
|
116
|
+
queued;
|
|
117
|
+
script;
|
|
118
|
+
keys = [];
|
|
119
|
+
args = [];
|
|
120
|
+
/** @internal */
|
|
121
|
+
constructor(queued, script) {
|
|
122
|
+
this.queued = queued;
|
|
123
|
+
this.script = script;
|
|
124
|
+
}
|
|
125
|
+
/** A key the script works on: the next of its `KEYS`. */
|
|
126
|
+
key(key) {
|
|
127
|
+
this.keys.push(key);
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
/** An argument: the next of the script's `ARGV`. */
|
|
131
|
+
arg(arg) {
|
|
132
|
+
this.args.push(arg);
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Queues the call. It is sent by source rather than by hash: a batch cannot
|
|
137
|
+
* stop halfway to send a script the server turns out not to have.
|
|
138
|
+
*/
|
|
139
|
+
queue() {
|
|
140
|
+
this.queued.push(this.script.command(false, this.keys, this.args));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=script.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script.js","sourceRoot":"","sources":["../../../storage/redis/script.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAC,KAAK,EAAE,YAAY,EAAC,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAC,GAAG,EAAE,WAAW,EAAgB,MAAM,QAAQ,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,MAAM;IACjB,2BAA2B;IAClB,MAAM,CAAS;IACxB,0DAA0D;IACjD,UAAU,GAAY,KAAK,CAAC;IACrC,oEAAoE;IACnD,IAAI,CAAS;IAE9B,yBAAyB;IACzB,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,M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ACb,WAAM,GAAN,MAAM,CAAQ;IAC9B,CAAC;IAEJ,yDAAyD;IACzD,GAAG,CAAC,GAAW;QACb,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oDAAoD;IACpD,GAAG,CAAC,GAAa;QACf,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACrE,CAAC;CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type * as runtime from '../../internal/runtime/mod.js';
|
|
2
|
+
import { Cmd, type Value } from './wire.js';
|
|
3
|
+
/**
|
|
4
|
+
* Where a command runs: on a connection from the database's pool, or on one
|
|
5
|
+
* taken out of it.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface Target {
|
|
10
|
+
/**
|
|
11
|
+
* Runs `cmd`, resolving to its reply: the error the server rejected it
|
|
12
|
+
* with, if it did. Rejects if it could not be sent.
|
|
13
|
+
*/
|
|
14
|
+
run(cmd: Cmd): Promise<Value>;
|
|
15
|
+
/**
|
|
16
|
+
* Runs `cmds` in one round trip — as a transaction, if `atomic` — resolving
|
|
17
|
+
* to each one's reply. A command the server rejects fails alone. `null` for
|
|
18
|
+
* a transaction that did not run because a watched key changed.
|
|
19
|
+
*/
|
|
20
|
+
runAll(cmds: readonly Cmd[], atomic: boolean): Promise<Value[] | null>;
|
|
21
|
+
/** The prefix every key of the database is stored under. */
|
|
22
|
+
prefix(): string | undefined;
|
|
23
|
+
/** The database's native handle. */
|
|
24
|
+
database(): runtime.RedisDatabase;
|
|
25
|
+
}
|
|
26
|
+
/** A database's pool, its native handle made on first use: in a test, the
|
|
27
|
+
* test's instance of the database. */
|
|
28
|
+
export declare class PoolTarget implements Target {
|
|
29
|
+
readonly name: string;
|
|
30
|
+
private impl?;
|
|
31
|
+
/** Each native handle's key prefix: `null` once known to have none. */
|
|
32
|
+
private readonly keyPrefixes;
|
|
33
|
+
constructor(name: string);
|
|
34
|
+
database(): runtime.RedisDatabase;
|
|
35
|
+
prefix(): string | undefined;
|
|
36
|
+
run(cmd: Cmd): Promise<Value>;
|
|
37
|
+
runAll(cmds: readonly Cmd[], atomic: boolean): Promise<Value[]>;
|
|
38
|
+
}
|
|
39
|
+
/** A connection taken out of a database's pool. */
|
|
40
|
+
export declare class ConnTarget implements Target {
|
|
41
|
+
readonly conn: runtime.RedisConnection;
|
|
42
|
+
private readonly pool;
|
|
43
|
+
constructor(conn: runtime.RedisConnection, pool: PoolTarget);
|
|
44
|
+
database(): runtime.RedisDatabase;
|
|
45
|
+
prefix(): string | undefined;
|
|
46
|
+
run(cmd: Cmd): Promise<Value>;
|
|
47
|
+
runAll(cmds: readonly Cmd[], atomic: boolean): Promise<Value[] | null>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../../storage/redis/target.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,OAAO,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAC,GAAG,EAA2C,KAAK,KAAK,EAAC,MAAM,QAAQ,CAAC;AAEhF;;;;;GAKG;AACH,MAAM,WAAW,MAAM;IACrB;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;IACvE,4DAA4D;IAC5D,MAAM,IAAI,MAAM,GAAG,SAAS,CAAC;IAC7B,oCAAoC;IACpC,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC;CACnC;AAkBD;sCACsC;AACtC,qBAAa,UAAW,YAAW,MAAM;IAQ3B,QAAQ,CAAC,IAAI,EAAE,MAAM;IAPjC,OAAO,CAAC,IAAI,CAAC,CAAwB;IACrC,uEAAuE;IACvE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAGxB;gBAEiB,IAAI,EAAE,MAAM;IAEjC,QAAQ,IAAI,OAAO,CAAC,aAAa;IAIjC,MAAM,IAAI,MAAM,GAAG,SAAS;IAUtB,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC;IAO7B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;CAOtE;AAED,mDAAmD;AACnD,qBAAa,UAAW,YAAW,MAAM;IAErC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,eAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,IAAI;gBADZ,IAAI,EAAE,OAAO,CAAC,eAAe,EACrB,IAAI,EAAE,UAAU;IAGnC,QAAQ,IAAI,OAAO,CAAC,aAAa;IAIjC,MAAM,IAAI,MAAM,GAAG,SAAS;IAItB,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC;IAO7B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC;CAO7E"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { activeCtxBytes } from '../../internal/otel/index.js';
|
|
2
|
+
import { openDatabase, testDatabase } from './native.js';
|
|
3
|
+
import { decodeReply, encodeBatch, encodeCommand } from './wire.js';
|
|
4
|
+
/**
|
|
5
|
+
* The replies of a batch, one per command.
|
|
6
|
+
*/
|
|
7
|
+
function replies(out, cmds) {
|
|
8
|
+
const v = decodeReply(out);
|
|
9
|
+
if (!Array.isArray(v) || v.length !== cmds.length) {
|
|
10
|
+
// The batch as a whole was rejected, as a transaction is for a command
|
|
11
|
+
// that could not be queued.
|
|
12
|
+
if (v instanceof Error)
|
|
13
|
+
throw v;
|
|
14
|
+
throw new Error(`redis: ${cmds.length} commands got a reply of another shape`);
|
|
15
|
+
}
|
|
16
|
+
return v;
|
|
17
|
+
}
|
|
18
|
+
/** A database's pool, its native handle made on first use: in a test, the
|
|
19
|
+
* test's instance of the database. */
|
|
20
|
+
export class PoolTarget {
|
|
21
|
+
name;
|
|
22
|
+
impl;
|
|
23
|
+
/** Each native handle's key prefix: `null` once known to have none. */
|
|
24
|
+
keyPrefixes = new WeakMap();
|
|
25
|
+
constructor(name) {
|
|
26
|
+
this.name = name;
|
|
27
|
+
}
|
|
28
|
+
database() {
|
|
29
|
+
return testDatabase(this.name) ?? (this.impl ??= openDatabase(this.name));
|
|
30
|
+
}
|
|
31
|
+
prefix() {
|
|
32
|
+
const db = this.database();
|
|
33
|
+
let prefix = this.keyPrefixes.get(db);
|
|
34
|
+
if (prefix === undefined) {
|
|
35
|
+
prefix = db.keyPrefix() ?? null;
|
|
36
|
+
this.keyPrefixes.set(db, prefix);
|
|
37
|
+
}
|
|
38
|
+
return prefix ?? undefined;
|
|
39
|
+
}
|
|
40
|
+
async run(cmd) {
|
|
41
|
+
const out = await refused(this.database().execute(encodeCommand(cmd), activeCtxBytes()));
|
|
42
|
+
return decodeReply(out);
|
|
43
|
+
}
|
|
44
|
+
async runAll(cmds, atomic) {
|
|
45
|
+
if (cmds.length === 0)
|
|
46
|
+
return [];
|
|
47
|
+
const out = await refused(this.database().executeEach(encodeBatch(cmds), atomic, activeCtxBytes()));
|
|
48
|
+
return replies(out, cmds);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** A connection taken out of a database's pool. */
|
|
52
|
+
export class ConnTarget {
|
|
53
|
+
conn;
|
|
54
|
+
pool;
|
|
55
|
+
constructor(conn, pool) {
|
|
56
|
+
this.conn = conn;
|
|
57
|
+
this.pool = pool;
|
|
58
|
+
}
|
|
59
|
+
database() {
|
|
60
|
+
return this.pool.database();
|
|
61
|
+
}
|
|
62
|
+
prefix() {
|
|
63
|
+
return this.pool.prefix();
|
|
64
|
+
}
|
|
65
|
+
async run(cmd) {
|
|
66
|
+
const out = await refused(this.conn.execute(encodeCommand(cmd), activeCtxBytes()));
|
|
67
|
+
return decodeReply(out);
|
|
68
|
+
}
|
|
69
|
+
async runAll(cmds, atomic) {
|
|
70
|
+
const out = await refused(this.conn.executeEach(encodeBatch(cmds), atomic, activeCtxBytes()));
|
|
71
|
+
if (out === null)
|
|
72
|
+
return null;
|
|
73
|
+
return replies(out, cmds);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* `p`, but a command the runtime refused before sending it rejects with a
|
|
78
|
+
* `TypeError` saying why: one the app named itself that Redis's command table
|
|
79
|
+
* says it may not send as it is, or one that blocks where it would hold up a
|
|
80
|
+
* connection. The runtime reports those as invalid arguments.
|
|
81
|
+
*/
|
|
82
|
+
async function refused(p) {
|
|
83
|
+
try {
|
|
84
|
+
return await p;
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
if (err?.code === 'InvalidArg') {
|
|
88
|
+
throw new TypeError(`redis: ${err.message}`, { cause: err });
|
|
89
|
+
}
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=target.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.js","sourceRoot":"","sources":["../../../storage/redis/target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAC,YAAY,EAAE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OAAO,CACvB,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,CACnE,CAAC;QACF,IAAI,GAAG,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QAC9B,OAAO,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;CACF;AAED;;;;;GAKG;AACH,KAAK,UAAU,OAAO,CAAI,CAAa;IACrC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,CAAC;IACjB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAK,GAAwB,EAAE,IAAI,KAAK,YAAY,EAAE,CAAC;YACrD,MAAM,IAAI,SAAS,CAAC,UAAW,GAAa,CAAC,OAAO,EAAE,EAAE,EAAC,KAAK,EAAE,GAAG,EAAC,CAAC,CAAC;QACxE,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commands as they cross to the native runtime, and replies as they come back:
|
|
3
|
+
* the encoding `encore_sdk_core::cache::wire` documents. A command marks which
|
|
4
|
+
* of its arguments are keys, which is what lets the runtime prefix them with
|
|
5
|
+
* the database's own.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/// <reference types="node" />
|
|
11
|
+
/// <reference types="node" />
|
|
12
|
+
/** A value sent to Redis as an argument: text, bytes, or a number. */
|
|
13
|
+
export type RedisArg = string | number | bigint | Buffer | Uint8Array;
|
|
14
|
+
/** A key and its value, or a field and its value, in the order given. */
|
|
15
|
+
export type Pairs<V> = Record<string, V> | ReadonlyMap<string, V>;
|
|
16
|
+
/** One argument of a command. */
|
|
17
|
+
interface Arg {
|
|
18
|
+
key: boolean;
|
|
19
|
+
value: Buffer;
|
|
20
|
+
}
|
|
21
|
+
/** A command being built: the arguments in order, the keys among them marked. */
|
|
22
|
+
export declare class Cmd {
|
|
23
|
+
readonly operation: string;
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly write: boolean;
|
|
26
|
+
readonly args: Arg[];
|
|
27
|
+
/**
|
|
28
|
+
* Whether the app named the command itself, with `command()`: the runtime
|
|
29
|
+
* then checks it against Redis's command table before sending it.
|
|
30
|
+
*/
|
|
31
|
+
raw: boolean;
|
|
32
|
+
/** Whether it is sent through a handle that can only read. */
|
|
33
|
+
readOnly: boolean;
|
|
34
|
+
/** A command Redis calls `name`, traced as `operation`. */
|
|
35
|
+
constructor(operation: string, name: string, write: boolean);
|
|
36
|
+
/** Appends a key: an argument the database's key prefix applies to. */
|
|
37
|
+
key(key: string): this;
|
|
38
|
+
/** Appends several keys. */
|
|
39
|
+
keys(keys: readonly string[]): this;
|
|
40
|
+
/**
|
|
41
|
+
* Appends keys preceded by how many there are, as the commands that take a
|
|
42
|
+
* variable number of keys before their other arguments want them.
|
|
43
|
+
*/
|
|
44
|
+
numkeys(keys: readonly string[]): this;
|
|
45
|
+
/** Appends an argument that is not a key. */
|
|
46
|
+
arg(value: RedisArg): this;
|
|
47
|
+
/** Appends several arguments that are not keys. */
|
|
48
|
+
argsOf(values: readonly RedisArg[]): this;
|
|
49
|
+
/** Appends each key and its value: `MSET`'s. */
|
|
50
|
+
pairs(items: Pairs<RedisArg>): this;
|
|
51
|
+
/** Appends each field and its value, neither a key. */
|
|
52
|
+
fields(items: Pairs<RedisArg>): this;
|
|
53
|
+
/** Appends each member's score, then the member: `ZADD`'s. */
|
|
54
|
+
scores(items: Pairs<number>): this;
|
|
55
|
+
/** A copy, to append more arguments to. */
|
|
56
|
+
clone(): Cmd;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* `value` as the bytes Redis is sent. Bytes are copied: a queued command is
|
|
60
|
+
* encoded only when its batch runs, and must send what it was given.
|
|
61
|
+
*/
|
|
62
|
+
export declare function toArg(value: unknown, operation: string): Buffer;
|
|
63
|
+
/** The encoding of one command. */
|
|
64
|
+
export declare function encodeCommand(cmd: Cmd): Buffer;
|
|
65
|
+
/** The encoding of a batch of commands. */
|
|
66
|
+
export declare function encodeBatch(cmds: readonly Cmd[]): Buffer;
|
|
67
|
+
/** The encoding of a list of keys or channels. */
|
|
68
|
+
export declare function encodeList(items: readonly string[]): Buffer;
|
|
69
|
+
/**
|
|
70
|
+
* The error a command the server rejected fails with.
|
|
71
|
+
*/
|
|
72
|
+
export declare class ServerError extends Error {
|
|
73
|
+
/**
|
|
74
|
+
* The server's message, as Redis spells it:
|
|
75
|
+
* `WRONGTYPE Operation against a key holding the wrong kind of value`.
|
|
76
|
+
*/
|
|
77
|
+
readonly serverMessage: string;
|
|
78
|
+
constructor(message: string);
|
|
79
|
+
/** The error's code: the first word of its message, `WRONGTYPE`. */
|
|
80
|
+
get code(): string;
|
|
81
|
+
}
|
|
82
|
+
/** A map reply, its keys and values in the order the server sent them. */
|
|
83
|
+
export declare class MapReply {
|
|
84
|
+
readonly entries: [Value, Value][];
|
|
85
|
+
constructor(entries: [Value, Value][]);
|
|
86
|
+
}
|
|
87
|
+
/** A simple string reply, `OK` among them. */
|
|
88
|
+
export declare class Status {
|
|
89
|
+
readonly text: string;
|
|
90
|
+
constructor(text: string);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A reply as it was decoded: `null` (nil), a `bigint` (an integer, or a big
|
|
94
|
+
* number), a `number` (a double), a `boolean`, a `Buffer` (a bulk string), a
|
|
95
|
+
* {@link Status}, an array (an array or a set), {@link MapReply} (a map), or a
|
|
96
|
+
* {@link ServerError}.
|
|
97
|
+
*/
|
|
98
|
+
export type Value = null | bigint | number | boolean | Buffer | Status | Value[] | MapReply | ServerError;
|
|
99
|
+
/** Decodes an encoded reply. */
|
|
100
|
+
export declare function decodeReply(buf: Buffer): Value;
|
|
101
|
+
export {};
|
|
102
|
+
//# sourceMappingURL=wire.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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