@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,866 @@
|
|
|
1
|
+
import {beforeEach, describe, expect, mock, test} from 'bun:test';
|
|
2
|
+
import {createHash} from 'node:crypto';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The SDK over a native database that is no Redis: it decodes the commands it
|
|
6
|
+
* is sent, records them, and answers each from a script, encoded as the core
|
|
7
|
+
* encodes replies. What crosses the napi boundary, both ways, is what these
|
|
8
|
+
* tests check; `runtime.test.ts` runs the real one.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** A reply as a test writes it. */
|
|
12
|
+
type R =
|
|
13
|
+
| null
|
|
14
|
+
| bigint
|
|
15
|
+
| number
|
|
16
|
+
| boolean
|
|
17
|
+
| string
|
|
18
|
+
| Buffer
|
|
19
|
+
| R[]
|
|
20
|
+
| {status: string}
|
|
21
|
+
| {error: string}
|
|
22
|
+
| {map: [R, R][]};
|
|
23
|
+
|
|
24
|
+
function encode(r: R): Buffer {
|
|
25
|
+
const bytes = (tag: number, b: Buffer) => {
|
|
26
|
+
const head = Buffer.alloc(5);
|
|
27
|
+
head.writeUInt8(tag, 0);
|
|
28
|
+
head.writeUInt32LE(b.length, 1);
|
|
29
|
+
return Buffer.concat([head, b]);
|
|
30
|
+
};
|
|
31
|
+
const count = (tag: number, n: number) => {
|
|
32
|
+
const head = Buffer.alloc(5);
|
|
33
|
+
head.writeUInt8(tag, 0);
|
|
34
|
+
head.writeUInt32LE(n, 1);
|
|
35
|
+
return head;
|
|
36
|
+
};
|
|
37
|
+
if (r === null) return Buffer.from([0]);
|
|
38
|
+
if (typeof r === 'bigint') {
|
|
39
|
+
const b = Buffer.alloc(9);
|
|
40
|
+
b.writeUInt8(1, 0);
|
|
41
|
+
b.writeBigInt64LE(r, 1);
|
|
42
|
+
return b;
|
|
43
|
+
}
|
|
44
|
+
if (typeof r === 'number') {
|
|
45
|
+
const b = Buffer.alloc(9);
|
|
46
|
+
b.writeUInt8(7, 0);
|
|
47
|
+
b.writeDoubleLE(r, 1);
|
|
48
|
+
return b;
|
|
49
|
+
}
|
|
50
|
+
if (typeof r === 'boolean') return Buffer.from([8, r ? 1 : 0]);
|
|
51
|
+
if (typeof r === 'string') return bytes(2, Buffer.from(r));
|
|
52
|
+
if (Buffer.isBuffer(r)) return bytes(2, r);
|
|
53
|
+
if (Array.isArray(r))
|
|
54
|
+
return Buffer.concat([count(4, r.length), ...r.map(encode)]);
|
|
55
|
+
if ('status' in r) return bytes(3, Buffer.from(r.status));
|
|
56
|
+
if ('error' in r) return bytes(9, Buffer.from(r.error));
|
|
57
|
+
return Buffer.concat([count(5, r.map.length), ...r.map.flat().map(encode)]);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A command as it was sent: its name, then its arguments, keys in braces. */
|
|
61
|
+
function decodeCommand(
|
|
62
|
+
buf: Buffer,
|
|
63
|
+
at = 0,
|
|
64
|
+
): [string, number, {write: boolean; op: string; raw?: true; readOnly?: true}] {
|
|
65
|
+
const flags = buf.readUInt8(at);
|
|
66
|
+
const write = (flags & 1) === 1;
|
|
67
|
+
at += 1;
|
|
68
|
+
const str = () => {
|
|
69
|
+
const n = buf.readUInt32LE(at);
|
|
70
|
+
const s = buf.subarray(at + 4, at + 4 + n);
|
|
71
|
+
at += 4 + n;
|
|
72
|
+
return s;
|
|
73
|
+
};
|
|
74
|
+
const op = str().toString();
|
|
75
|
+
const parts = [str().toString()];
|
|
76
|
+
const argc = buf.readUInt32LE(at);
|
|
77
|
+
at += 4;
|
|
78
|
+
for (let i = 0; i < argc; i++) {
|
|
79
|
+
const key = buf.readUInt8(at) === 1;
|
|
80
|
+
at += 1;
|
|
81
|
+
const arg = str();
|
|
82
|
+
const text = arg.every(c => c >= 0x20 && c < 0x7f)
|
|
83
|
+
? arg.toString()
|
|
84
|
+
: `0x${arg.toString('hex')}`;
|
|
85
|
+
parts.push(key ? `{${text}}` : text);
|
|
86
|
+
}
|
|
87
|
+
const meta: {write: boolean; op: string; raw?: true; readOnly?: true} = {
|
|
88
|
+
write,
|
|
89
|
+
op,
|
|
90
|
+
};
|
|
91
|
+
if (flags & 2) meta.raw = true;
|
|
92
|
+
if (flags & 4) meta.readOnly = true;
|
|
93
|
+
return [parts.join(' '), at, meta];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function decodeBatch(buf: Buffer): string[] {
|
|
97
|
+
const n = buf.readUInt32LE(0);
|
|
98
|
+
let at = 4;
|
|
99
|
+
const out: string[] = [];
|
|
100
|
+
for (let i = 0; i < n; i++) {
|
|
101
|
+
const [cmd, next] = decodeCommand(buf, at);
|
|
102
|
+
out.push(cmd);
|
|
103
|
+
at = next;
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function decodeList(buf: Buffer): string[] {
|
|
109
|
+
const n = buf.readUInt32LE(0);
|
|
110
|
+
let at = 4;
|
|
111
|
+
const out: string[] = [];
|
|
112
|
+
for (let i = 0; i < n; i++) {
|
|
113
|
+
const len = buf.readUInt32LE(at);
|
|
114
|
+
out.push(buf.subarray(at + 4, at + 4 + len).toString());
|
|
115
|
+
at += 4 + len;
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The fake's state, reset between tests. */
|
|
121
|
+
const server = {
|
|
122
|
+
prefix: 'p/' as string | null,
|
|
123
|
+
/** Every command sent, in order. */
|
|
124
|
+
sent: [] as string[],
|
|
125
|
+
/** What each command was traced as, and whether it was sent as a write. */
|
|
126
|
+
meta: [] as {write: boolean; op: string}[],
|
|
127
|
+
/** The batches sent, as `pipeline` or `transaction` and their commands. */
|
|
128
|
+
batches: [] as string[],
|
|
129
|
+
/** Replies by command name, used up in order; the last answers any after. */
|
|
130
|
+
replies: new Map<string, R[]>(),
|
|
131
|
+
/** How many watched transactions abort before one runs. */
|
|
132
|
+
aborts: 0,
|
|
133
|
+
/** What a connection did: watch, unwatch, release. */
|
|
134
|
+
connLog: [] as string[],
|
|
135
|
+
subscribed: [] as string[],
|
|
136
|
+
messages: [] as {channel: string; payload: string}[],
|
|
137
|
+
subscriptionClosed: false,
|
|
138
|
+
/** Commands the runtime refuses, by name, and why. */
|
|
139
|
+
refuse: new Map<string, string>(),
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
function script(name: string, ...replies: R[]) {
|
|
143
|
+
server.replies.set(name, replies);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function answer(cmd: string): R {
|
|
147
|
+
const name = cmd.split(' ')[0];
|
|
148
|
+
const scripted = server.replies.get(name);
|
|
149
|
+
if (!scripted || scripted.length === 0) return {status: 'OK'};
|
|
150
|
+
return scripted.length > 1 ? scripted.shift()! : scripted[0];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function execute(cmd: Buffer): Promise<Buffer> {
|
|
154
|
+
const [sent, , meta] = decodeCommand(cmd);
|
|
155
|
+
server.sent.push(sent);
|
|
156
|
+
server.meta.push(meta);
|
|
157
|
+
// The runtime refuses what Redis's command table says may not be sent, as
|
|
158
|
+
// an invalid argument.
|
|
159
|
+
const refusal = server.refuse.get(sent.split(' ')[0]);
|
|
160
|
+
if (refusal) {
|
|
161
|
+
return Promise.reject(
|
|
162
|
+
Object.assign(new Error(refusal), {code: 'InvalidArg'}),
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
return Promise.resolve(encode(answer(sent)));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function executeEach(batch: Buffer, atomic: boolean): Promise<Buffer> {
|
|
169
|
+
const cmds = decodeBatch(batch);
|
|
170
|
+
server.sent.push(...cmds);
|
|
171
|
+
server.batches.push(
|
|
172
|
+
`${atomic ? 'transaction' : 'pipeline'}: ${cmds.join('; ')}`,
|
|
173
|
+
);
|
|
174
|
+
return Promise.resolve(encode(cmds.map(answer)));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const native = {
|
|
178
|
+
keyPrefix: () => server.prefix,
|
|
179
|
+
connectionUrl: () => 'redis://127.0.0.1:6379/0',
|
|
180
|
+
execute,
|
|
181
|
+
executeEach,
|
|
182
|
+
acquire: async () => ({
|
|
183
|
+
execute,
|
|
184
|
+
executeEach: async (batch: Buffer, atomic: boolean) => {
|
|
185
|
+
if (server.aborts > 0) {
|
|
186
|
+
server.aborts--;
|
|
187
|
+
server.connLog.push('aborted');
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
return executeEach(batch, atomic);
|
|
191
|
+
},
|
|
192
|
+
watch: async (keys: Buffer) => {
|
|
193
|
+
server.connLog.push(`watch ${decodeList(keys).join(' ')}`);
|
|
194
|
+
},
|
|
195
|
+
unwatch: async () => {
|
|
196
|
+
server.connLog.push('unwatch');
|
|
197
|
+
},
|
|
198
|
+
release: async () => {
|
|
199
|
+
server.connLog.push('release');
|
|
200
|
+
},
|
|
201
|
+
}),
|
|
202
|
+
subscribe: async (channels: Buffer, patterns: Buffer) => {
|
|
203
|
+
server.subscribed = [
|
|
204
|
+
...decodeList(channels),
|
|
205
|
+
...decodeList(patterns).map(p => `pattern ${p}`),
|
|
206
|
+
];
|
|
207
|
+
return {
|
|
208
|
+
next: async () => {
|
|
209
|
+
const message = server.messages.shift();
|
|
210
|
+
if (!message) return null;
|
|
211
|
+
return {
|
|
212
|
+
channel: Buffer.from(message.channel),
|
|
213
|
+
payload: Buffer.from(message.payload),
|
|
214
|
+
};
|
|
215
|
+
},
|
|
216
|
+
close: async () => {
|
|
217
|
+
server.subscriptionClosed = true;
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const opened: string[] = [];
|
|
224
|
+
|
|
225
|
+
// The module, not the runtime's, so that no other test's mock of the
|
|
226
|
+
// runtime stands in for it.
|
|
227
|
+
mock.module('./native', () => ({
|
|
228
|
+
openDatabase: (name: string) => {
|
|
229
|
+
opened.push(name);
|
|
230
|
+
return native;
|
|
231
|
+
},
|
|
232
|
+
testDatabase: () => null,
|
|
233
|
+
}));
|
|
234
|
+
|
|
235
|
+
const redis = await import('./mod');
|
|
236
|
+
const {Database, Script, ServerError, BatchError} = redis;
|
|
237
|
+
|
|
238
|
+
const DB = new Database('test-db');
|
|
239
|
+
|
|
240
|
+
beforeEach(() => {
|
|
241
|
+
server.prefix = 'p/';
|
|
242
|
+
server.sent = [];
|
|
243
|
+
server.meta = [];
|
|
244
|
+
server.batches = [];
|
|
245
|
+
server.replies = new Map();
|
|
246
|
+
server.aborts = 0;
|
|
247
|
+
server.connLog = [];
|
|
248
|
+
server.subscribed = [];
|
|
249
|
+
server.messages = [];
|
|
250
|
+
server.subscriptionClosed = false;
|
|
251
|
+
server.refuse = new Map();
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
describe('commands', () => {
|
|
255
|
+
test('cross with their keys marked, and their replies come back decoded', async () => {
|
|
256
|
+
script('GET', 'ada', null, Buffer.from([0, 0xff, 0x0d, 0x0a]));
|
|
257
|
+
script('INCRBY', 2n);
|
|
258
|
+
script('INCRBYFLOAT', '2.5');
|
|
259
|
+
script('MGET', ['ada', null]);
|
|
260
|
+
|
|
261
|
+
await DB.string.set('name', 'ada');
|
|
262
|
+
expect(await DB.string.get('name').text()).toBe('ada');
|
|
263
|
+
expect(await DB.string.get('nobody').text()).toBeNull();
|
|
264
|
+
expect(await DB.string.get('bin').bytes()).toEqual(
|
|
265
|
+
Buffer.from([0, 0xff, 0x0d, 0x0a]),
|
|
266
|
+
);
|
|
267
|
+
expect(await DB.string.incr('visits', 2)).toBe(2);
|
|
268
|
+
expect(await DB.string.incrFloat('ratio', 1.5)).toBe(2.5);
|
|
269
|
+
expect(await DB.string.mget('a', 'b').optionalTexts()).toEqual([
|
|
270
|
+
'ada',
|
|
271
|
+
null,
|
|
272
|
+
]);
|
|
273
|
+
await DB.string.set('blob', Buffer.from([0, 0xff]));
|
|
274
|
+
await DB.string.mset(
|
|
275
|
+
new Map<string, string | number>([
|
|
276
|
+
['a', 1],
|
|
277
|
+
['b', 'x'],
|
|
278
|
+
]),
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
expect(server.sent).toEqual([
|
|
282
|
+
'SET {name} ada',
|
|
283
|
+
'GET {name}',
|
|
284
|
+
'GET {nobody}',
|
|
285
|
+
'GET {bin}',
|
|
286
|
+
'INCRBY {visits} 2',
|
|
287
|
+
'INCRBYFLOAT {ratio} 1.5',
|
|
288
|
+
'MGET {a} {b}',
|
|
289
|
+
'SET {blob} 0x00ff',
|
|
290
|
+
'MSET {a} 1 {b} x',
|
|
291
|
+
]);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test("are traced under the Rust SDK's names, and say whether they write", async () => {
|
|
295
|
+
script('GET', null);
|
|
296
|
+
await DB.string.setEx('k', 'v', 10);
|
|
297
|
+
await DB.string.get('k');
|
|
298
|
+
await DB.sortedSet.zrangeWithscores('z', 0, -1);
|
|
299
|
+
expect(server.meta).toEqual([
|
|
300
|
+
{write: true, op: 'set_ex'},
|
|
301
|
+
{write: false, op: 'get'},
|
|
302
|
+
{write: false, op: 'zrange_withscores'},
|
|
303
|
+
]);
|
|
304
|
+
expect(server.sent[0]).toBe('SETEX {k} 10 v');
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test('send numbers as Redis spells them, and refuse what it cannot take', async () => {
|
|
308
|
+
script('ZADD', 1n);
|
|
309
|
+
script('INCRBY', 1n);
|
|
310
|
+
await DB.sortedSet.zrangebyscore('z', -Infinity, '(1.5');
|
|
311
|
+
await DB.sortedSet.zadd('z', 'm', Infinity);
|
|
312
|
+
await DB.string.incr('big', 9007199254740993n);
|
|
313
|
+
expect(server.sent).toEqual([
|
|
314
|
+
'ZRANGEBYSCORE {z} -inf (1.5',
|
|
315
|
+
'ZADD {z} +inf m',
|
|
316
|
+
'INCRBY {big} 9007199254740993',
|
|
317
|
+
]);
|
|
318
|
+
|
|
319
|
+
const bad = DB.string.set('k', true as unknown as string);
|
|
320
|
+
await expect(bad).rejects.toThrow('cannot send a boolean');
|
|
321
|
+
await expect(
|
|
322
|
+
DB.string.get(NaN as unknown as string).text(),
|
|
323
|
+
).rejects.toThrow();
|
|
324
|
+
await expect(DB.sortedSet.zadd('z', 'm', NaN)).rejects.toThrow('NaN');
|
|
325
|
+
expect(server.sent).toHaveLength(3);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test('fail with the error the server rejected them with', async () => {
|
|
329
|
+
script('INCRBY', {
|
|
330
|
+
error:
|
|
331
|
+
'WRONGTYPE Operation against a key holding the wrong kind of value',
|
|
332
|
+
});
|
|
333
|
+
script('GET', {error: 'ERR boom'});
|
|
334
|
+
|
|
335
|
+
const err = await DB.string.incr('k', 1).catch(e => e);
|
|
336
|
+
expect(err).toBeInstanceOf(ServerError);
|
|
337
|
+
expect(err.code).toBe('WRONGTYPE');
|
|
338
|
+
|
|
339
|
+
const reply = DB.string.get('k');
|
|
340
|
+
await expect(reply.text()).rejects.toThrow('ERR boom');
|
|
341
|
+
await expect(Promise.resolve(reply)).rejects.toBeInstanceOf(ServerError);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test('read their replies as the caller asks', async () => {
|
|
345
|
+
script('HGETALL', ['name', 'ada', 'age', '36'], {map: [['k', 'v']]});
|
|
346
|
+
script(
|
|
347
|
+
'ZRANGE',
|
|
348
|
+
['a', '1', 'b', '2.5'],
|
|
349
|
+
[
|
|
350
|
+
['a', 1],
|
|
351
|
+
['b', 2.5],
|
|
352
|
+
],
|
|
353
|
+
);
|
|
354
|
+
script('SMEMBERS', ['x', 'y']);
|
|
355
|
+
script('LPOP', null);
|
|
356
|
+
script('TTL', 5n);
|
|
357
|
+
script('ZSCORE', null);
|
|
358
|
+
script('SMISMEMBER', [1n, 0n]);
|
|
359
|
+
script('TYPE', {status: 'string'});
|
|
360
|
+
script('GET', '123', '{"a":[1,2]}');
|
|
361
|
+
|
|
362
|
+
expect(await DB.hash.hgetall('u').textMap()).toEqual({
|
|
363
|
+
name: 'ada',
|
|
364
|
+
age: '36',
|
|
365
|
+
});
|
|
366
|
+
expect(await DB.hash.hgetall('u').textMap()).toEqual({k: 'v'});
|
|
367
|
+
const scored = [
|
|
368
|
+
{member: 'a', score: 1},
|
|
369
|
+
{member: 'b', score: 2.5},
|
|
370
|
+
];
|
|
371
|
+
// RESP2 sends members and scores flat; RESP3 in pairs.
|
|
372
|
+
expect(
|
|
373
|
+
await DB.sortedSet.zrangeWithscores('z', 0, -1).scoredMembers(),
|
|
374
|
+
).toEqual(scored);
|
|
375
|
+
expect(
|
|
376
|
+
await DB.sortedSet.zrangeWithscores('z', 0, -1).scoredMembers(),
|
|
377
|
+
).toEqual(scored);
|
|
378
|
+
expect(await DB.set.smembers('s').texts()).toEqual(['x', 'y']);
|
|
379
|
+
expect(await DB.list.lpop('l', 2).texts()).toEqual([]);
|
|
380
|
+
expect(await DB.generic.ttl('k')).toBe(5);
|
|
381
|
+
expect(await DB.sortedSet.zscore('z', 'nobody')).toBeNull();
|
|
382
|
+
expect(await DB.set.smismember('s', 'x', 'z')).toEqual([true, false]);
|
|
383
|
+
expect(await DB.generic.keyType('k')).toBe('string');
|
|
384
|
+
expect(await DB.string.get('n').bigint()).toBe(123n);
|
|
385
|
+
expect(await DB.string.get('j').json()).toEqual({a: [1, 2]});
|
|
386
|
+
expect(server.sent).toContain('LPOP {l} 2');
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test('read a field named __proto__ as a field like any other', async () => {
|
|
390
|
+
const pairs = ['__proto__', 'a', 'constructor', 'b'];
|
|
391
|
+
const map: {map: [R, R][]} = {
|
|
392
|
+
map: [
|
|
393
|
+
['__proto__', 'a'],
|
|
394
|
+
['constructor', 'b'],
|
|
395
|
+
],
|
|
396
|
+
};
|
|
397
|
+
// RESP2 sends a hash as pairs, RESP3 as a map.
|
|
398
|
+
script('HGETALL', pairs, map, {map: [['__proto__', map]]});
|
|
399
|
+
script('XRANGE', [['1-0', pairs]]);
|
|
400
|
+
|
|
401
|
+
const own = (o: object) => Object.getOwnPropertyNames(o).sort();
|
|
402
|
+
for (let i = 0; i < 2; i++) {
|
|
403
|
+
const fields = await DB.hash.hgetall('h').textMap();
|
|
404
|
+
expect(own(fields)).toEqual(['__proto__', 'constructor']);
|
|
405
|
+
expect(fields['__proto__']).toBe('a');
|
|
406
|
+
expect(fields['constructor']).toBe('b');
|
|
407
|
+
}
|
|
408
|
+
const value = (await DB.hash.hgetall('h').value()) as Record<
|
|
409
|
+
string,
|
|
410
|
+
Record<string, unknown>
|
|
411
|
+
>;
|
|
412
|
+
expect(own(value)).toEqual(['__proto__']);
|
|
413
|
+
expect(own(value['__proto__'])).toEqual(['__proto__', 'constructor']);
|
|
414
|
+
expect(value['__proto__']['__proto__']).toBe('a');
|
|
415
|
+
|
|
416
|
+
const [entry] = await DB.stream.xrange('s', '-', '+').streamEntries();
|
|
417
|
+
expect(own(entry.fields)).toEqual(['__proto__', 'constructor']);
|
|
418
|
+
expect(entry.fields['__proto__']).toBe('a');
|
|
419
|
+
// A field the reply does not hold is not there, not an inherited one.
|
|
420
|
+
expect(entry.fields['toString']).toBeUndefined();
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
test("take their options as Redis's arguments", async () => {
|
|
424
|
+
script('SET', null);
|
|
425
|
+
script('ZINTERSTORE', 0n);
|
|
426
|
+
script('BITOP', 0n);
|
|
427
|
+
await DB.string.setOptions('k', 'v', {
|
|
428
|
+
condition: 'nx',
|
|
429
|
+
get: true,
|
|
430
|
+
expiry: {px: 500},
|
|
431
|
+
});
|
|
432
|
+
await DB.string.getEx('k', {persist: true});
|
|
433
|
+
await DB.list.lmove('a', 'b', 'left', 'right');
|
|
434
|
+
await DB.geo.geoRadius('g', 13.4, 52.5, 10, 'km', {
|
|
435
|
+
withDist: true,
|
|
436
|
+
count: 3,
|
|
437
|
+
order: 'asc',
|
|
438
|
+
});
|
|
439
|
+
await DB.stream.xaddMaxlen('s', {maxlen: 100, approx: true}, '*', {
|
|
440
|
+
a: 1,
|
|
441
|
+
});
|
|
442
|
+
await DB.stream.xreadGroup('g', 'c', ['s'], ['>'], 10);
|
|
443
|
+
await DB.sortedSet.zinterstore('dest', 'a', 'b');
|
|
444
|
+
await DB.bitmap.bitAnd('dest', 'a', 'b');
|
|
445
|
+
expect(server.sent).toEqual([
|
|
446
|
+
'SET {k} v NX GET PX 500',
|
|
447
|
+
'GETEX {k} PERSIST',
|
|
448
|
+
'LMOVE {a} {b} LEFT RIGHT',
|
|
449
|
+
'GEORADIUS_RO {g} 13.4 52.5 10 km WITHDIST COUNT 3 ASC',
|
|
450
|
+
'XADD {s} MAXLEN ~ 100 * a 1',
|
|
451
|
+
'XREADGROUP GROUP g c COUNT 10 STREAMS {s} >',
|
|
452
|
+
'ZINTERSTORE {dest} 2 {a} {b}',
|
|
453
|
+
'BITOP AND {dest} {a} {b}',
|
|
454
|
+
]);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
// The runtime removes the prefix from the keys a reply names (the core's
|
|
458
|
+
// tests check that), so the reply comes without it.
|
|
459
|
+
test('a stream read names its streams', async () => {
|
|
460
|
+
const entries = [['1-0', ['f', 'v']]];
|
|
461
|
+
script('XREAD', [['orders', entries]], {map: [['orders', entries]]}, null);
|
|
462
|
+
const want = [{key: 'orders', entries: [{id: '1-0', fields: {f: 'v'}}]}];
|
|
463
|
+
expect(await DB.stream.xread(['orders'], ['0']).streams()).toEqual(want);
|
|
464
|
+
expect(await DB.stream.xread(['orders'], ['0']).streams()).toEqual(want);
|
|
465
|
+
expect(await DB.stream.xread(['orders'], ['$']).streams()).toEqual([]);
|
|
466
|
+
expect(server.sent[0]).toBe('XREAD STREAMS {orders} 0');
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
test('stream and geo replies read as their shapes', async () => {
|
|
470
|
+
script('XPENDING', [2n, '1-0', '2-0', [['alice', '2']]]);
|
|
471
|
+
script('XAUTOCLAIM', ['0-0', [['1-0', ['f', 'v']]], ['3-0']]);
|
|
472
|
+
script('XINFO', [
|
|
473
|
+
'length',
|
|
474
|
+
2n,
|
|
475
|
+
'groups',
|
|
476
|
+
1n,
|
|
477
|
+
'last-generated-id',
|
|
478
|
+
'2-0',
|
|
479
|
+
'first-entry',
|
|
480
|
+
['1-0', ['f', 'v']],
|
|
481
|
+
'last-entry',
|
|
482
|
+
null,
|
|
483
|
+
]);
|
|
484
|
+
script('GEOPOS', [['13.4', '52.5'], null]);
|
|
485
|
+
script('GEORADIUS_RO', [
|
|
486
|
+
['berlin', '1.5', 123n, ['13.4', '52.5']],
|
|
487
|
+
'paris',
|
|
488
|
+
]);
|
|
489
|
+
|
|
490
|
+
expect(await DB.stream.xpending('s', 'g').streamPending()).toEqual({
|
|
491
|
+
count: 2,
|
|
492
|
+
lowest: '1-0',
|
|
493
|
+
highest: '2-0',
|
|
494
|
+
consumers: [{name: 'alice', pending: 2}],
|
|
495
|
+
});
|
|
496
|
+
expect(
|
|
497
|
+
await DB.stream.xautoclaim('s', 'g', 'c', 1000, '0').streamAutoClaim(),
|
|
498
|
+
).toEqual({
|
|
499
|
+
next: '0-0',
|
|
500
|
+
claimed: [{id: '1-0', fields: {f: 'v'}}],
|
|
501
|
+
deleted: ['3-0'],
|
|
502
|
+
});
|
|
503
|
+
const info = await DB.stream.xinfoStream('s').streamInfo();
|
|
504
|
+
expect(info.length).toBe(2);
|
|
505
|
+
expect(info.firstEntry).toEqual({id: '1-0', fields: {f: 'v'}});
|
|
506
|
+
expect(info.lastEntry).toBeNull();
|
|
507
|
+
expect(
|
|
508
|
+
await DB.geo.geoPos('g', 'berlin', 'nowhere').geoPositions(),
|
|
509
|
+
).toEqual([{longitude: 13.4, latitude: 52.5}, null]);
|
|
510
|
+
expect(await DB.geo.geoRadius('g', 0, 0, 1, 'm').geoRadius()).toEqual([
|
|
511
|
+
{
|
|
512
|
+
name: 'berlin',
|
|
513
|
+
dist: 1.5,
|
|
514
|
+
hash: 123n,
|
|
515
|
+
coord: {longitude: 13.4, latitude: 52.5},
|
|
516
|
+
},
|
|
517
|
+
{name: 'paris'},
|
|
518
|
+
]);
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
describe('handles', () => {
|
|
523
|
+
test('a read handle holds only the commands that read', async () => {
|
|
524
|
+
const reader = DB.read();
|
|
525
|
+
expect(typeof reader.string.get).toBe('function');
|
|
526
|
+
expect((reader.string as Record<string, unknown>).set).toBeUndefined();
|
|
527
|
+
expect((reader.pubsub as Record<string, unknown>).publish).toBeUndefined();
|
|
528
|
+
expect(typeof reader.pubsub.subscribe).toBe('function');
|
|
529
|
+
expect(typeof reader.generic.scan).toBe('function');
|
|
530
|
+
expect(reader.primary).toBe(false);
|
|
531
|
+
expect(DB.readPrimary().primary).toBe(true);
|
|
532
|
+
|
|
533
|
+
const writer = DB.write();
|
|
534
|
+
await writer.string.set('k', 'v');
|
|
535
|
+
expect(server.sent).toEqual(['SET {k} v']);
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
test('a read handle runs only scripts that only read', async () => {
|
|
539
|
+
const write = new Script("return redis.call('set', KEYS[1], 'x')");
|
|
540
|
+
await expect(
|
|
541
|
+
Promise.resolve(DB.read().script(write).key('k').invoke()),
|
|
542
|
+
).rejects.toThrow('Script.readOnly');
|
|
543
|
+
expect(server.sent).toEqual([]);
|
|
544
|
+
|
|
545
|
+
script('EVALSHA_RO', 1n);
|
|
546
|
+
const read = Script.readOnly('return 1');
|
|
547
|
+
expect(await DB.read().script(read).invoke().number()).toBe(1);
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
test('the database is opened once, on first use', () => {
|
|
551
|
+
expect(opened.filter(name => name === 'test-db')).toEqual(['test-db']);
|
|
552
|
+
expect(DB.connectionString).toBe('redis://127.0.0.1:6379/0');
|
|
553
|
+
});
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
describe('scripts', () => {
|
|
557
|
+
test('run by hash, and by source when the server does not have them', async () => {
|
|
558
|
+
const source = "return redis.call('get', KEYS[1])";
|
|
559
|
+
const sha = createHash('sha1').update(source).digest('hex');
|
|
560
|
+
script('EVALSHA', {error: 'NOSCRIPT No matching script.'});
|
|
561
|
+
script('EVAL', 'v');
|
|
562
|
+
|
|
563
|
+
const s = new Script(source);
|
|
564
|
+
expect(await DB.script(s).key('k').arg('a').arg(1).invoke().text()).toBe(
|
|
565
|
+
'v',
|
|
566
|
+
);
|
|
567
|
+
expect(server.sent).toEqual([
|
|
568
|
+
`EVALSHA ${sha} 1 {k} a 1`,
|
|
569
|
+
`EVAL ${source} 1 {k} a 1`,
|
|
570
|
+
]);
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
describe('batches', () => {
|
|
575
|
+
test('a pipeline sends what it queued in one round trip', async () => {
|
|
576
|
+
script('GET', 'a', 'b');
|
|
577
|
+
const pipe = DB.pipeline();
|
|
578
|
+
pipe.string.get('name:1').get('name:2');
|
|
579
|
+
pipe.hash.hset('h', 'f', 1);
|
|
580
|
+
expect(pipe.length).toBe(3);
|
|
581
|
+
const replies = await pipe.exec();
|
|
582
|
+
expect(replies.map(r => r.text())).toEqual(['a', 'b', 'OK']);
|
|
583
|
+
expect(pipe.length).toBe(0);
|
|
584
|
+
expect(server.batches).toEqual([
|
|
585
|
+
'pipeline: GET {name:1}; GET {name:2}; HSET {h} f 1',
|
|
586
|
+
]);
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
test('a queued command sends the bytes it was given, changed after or not', async () => {
|
|
590
|
+
const buf = Buffer.from('ab');
|
|
591
|
+
const view = new Uint8Array([0x63, 0x64]);
|
|
592
|
+
const pipe = DB.pipeline();
|
|
593
|
+
pipe.string.set('b', buf);
|
|
594
|
+
pipe.string.set('v', view);
|
|
595
|
+
buf.write('xy');
|
|
596
|
+
view.set([0x7a, 0x7a]);
|
|
597
|
+
await pipe.exec();
|
|
598
|
+
expect(server.batches).toEqual(['pipeline: SET {b} ab; SET {v} cd']);
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
test('a transaction runs atomically, and fails with what the server rejected', async () => {
|
|
602
|
+
script('INCRBY', {error: 'ERR not an integer'});
|
|
603
|
+
const tx = DB.transaction();
|
|
604
|
+
tx.string.set('a', 1);
|
|
605
|
+
tx.string.incr('a', 1);
|
|
606
|
+
const s = new Script('return 1');
|
|
607
|
+
tx.script(s).key('k').queue();
|
|
608
|
+
const err = await tx.exec().catch(e => e);
|
|
609
|
+
expect(err).toBeInstanceOf(BatchError);
|
|
610
|
+
expect(err.replies.map((r: {error?: Error}) => r.error?.message)).toEqual([
|
|
611
|
+
undefined,
|
|
612
|
+
'redis: ERR not an integer',
|
|
613
|
+
undefined,
|
|
614
|
+
]);
|
|
615
|
+
expect(server.batches).toEqual([
|
|
616
|
+
'transaction: SET {a} 1; INCRBY {a} 1; EVAL return 1 1 {k}',
|
|
617
|
+
]);
|
|
618
|
+
|
|
619
|
+
const discarded = DB.transaction();
|
|
620
|
+
discarded.string.set('x', 1);
|
|
621
|
+
discarded.discard();
|
|
622
|
+
expect(await discarded.exec()).toEqual([]);
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
test('watch runs its body again while a watched key changes', async () => {
|
|
626
|
+
server.aborts = 2;
|
|
627
|
+
script('GET', '10', '9', '8');
|
|
628
|
+
let runs = 0;
|
|
629
|
+
const left = await DB.watch(['balance'], async (conn, tx) => {
|
|
630
|
+
runs++;
|
|
631
|
+
const balance = (await conn.string.get('balance').number())!;
|
|
632
|
+
tx.string.set('balance', balance - 1);
|
|
633
|
+
return balance - 1;
|
|
634
|
+
});
|
|
635
|
+
expect(left).toBe(7);
|
|
636
|
+
expect(runs).toBe(3);
|
|
637
|
+
expect(server.connLog).toEqual([
|
|
638
|
+
'watch balance',
|
|
639
|
+
'aborted',
|
|
640
|
+
'watch balance',
|
|
641
|
+
'aborted',
|
|
642
|
+
'watch balance',
|
|
643
|
+
'release',
|
|
644
|
+
]);
|
|
645
|
+
expect(server.batches).toEqual(['transaction: SET {balance} 7']);
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
test('watch gives up on a key that keeps changing, and releases its connection', async () => {
|
|
649
|
+
server.aborts = 1000;
|
|
650
|
+
script('GET', '1');
|
|
651
|
+
await expect(
|
|
652
|
+
DB.watch(['k'], async (_conn, tx) => {
|
|
653
|
+
tx.string.set('k', 1);
|
|
654
|
+
}),
|
|
655
|
+
).rejects.toThrow('gave up after 64 attempts');
|
|
656
|
+
expect(server.connLog.at(-1)).toBe('release');
|
|
657
|
+
});
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
describe('scans', () => {
|
|
661
|
+
test("keys are scanned under the database's prefix, and returned without it", async () => {
|
|
662
|
+
// A database's prefix is read once, so this one is a database of its own.
|
|
663
|
+
const globbed = new Database('globbed');
|
|
664
|
+
server.prefix = 'a*b/';
|
|
665
|
+
script('SCAN', ['7', ['a*b/user:1', 'a*b/user:2']], ['0', ['a*b/user:3']]);
|
|
666
|
+
const keys: string[] = [];
|
|
667
|
+
for await (const key of globbed.generic.scan({
|
|
668
|
+
pattern: 'user:*',
|
|
669
|
+
count: 10,
|
|
670
|
+
}))
|
|
671
|
+
keys.push(key);
|
|
672
|
+
expect(keys).toEqual(['user:1', 'user:2', 'user:3']);
|
|
673
|
+
expect(server.sent).toEqual([
|
|
674
|
+
'SCAN 0 MATCH a\\*b/user:* COUNT 10',
|
|
675
|
+
'SCAN 7 MATCH a\\*b/user:* COUNT 10',
|
|
676
|
+
]);
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
test("a hash's fields come with their values, a sorted set's members with their scores", async () => {
|
|
680
|
+
script('HSCAN', ['0', ['f', 'v', 'g', 'w']]);
|
|
681
|
+
script('ZSCAN', ['0', ['m', '1.5']]);
|
|
682
|
+
const fields = [];
|
|
683
|
+
for await (const fv of DB.hash.hscan('h')) fields.push(fv);
|
|
684
|
+
expect(fields).toEqual([
|
|
685
|
+
{field: 'f', value: 'v'},
|
|
686
|
+
{field: 'g', value: 'w'},
|
|
687
|
+
]);
|
|
688
|
+
const members = [];
|
|
689
|
+
for await (const m of DB.sortedSet.zscan('z', {pattern: 'm*'}))
|
|
690
|
+
members.push(m);
|
|
691
|
+
expect(members).toEqual([{member: 'm', score: 1.5}]);
|
|
692
|
+
expect(server.sent).toEqual(['HSCAN {h} 0', 'ZSCAN {z} 0 MATCH m*']);
|
|
693
|
+
});
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
describe('channels', () => {
|
|
697
|
+
test('a subscription delivers its messages, and closes when left', async () => {
|
|
698
|
+
server.messages = [
|
|
699
|
+
{channel: 'orders', payload: 'one'},
|
|
700
|
+
{channel: 'orders', payload: '{"n":2}'},
|
|
701
|
+
];
|
|
702
|
+
const sub = await DB.pubsub.subscribe('orders', 'refunds');
|
|
703
|
+
expect(server.subscribed).toEqual(['orders', 'refunds']);
|
|
704
|
+
const got: string[] = [];
|
|
705
|
+
for await (const message of sub) {
|
|
706
|
+
got.push(`${message.channel}: ${message.text()}`);
|
|
707
|
+
if (got.length === 2) break;
|
|
708
|
+
}
|
|
709
|
+
expect(got).toEqual(['orders: one', 'orders: {"n":2}']);
|
|
710
|
+
expect(server.subscriptionClosed).toBe(true);
|
|
711
|
+
|
|
712
|
+
await DB.pubsub.psubscribe('order*');
|
|
713
|
+
expect(server.subscribed).toEqual(['pattern order*']);
|
|
714
|
+
await expect(DB.pubsub.subscribe()).rejects.toThrow('at least one channel');
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
test('publishing names its channel as a key, so it is prefixed like one', async () => {
|
|
718
|
+
script('PUBLISH', 1n);
|
|
719
|
+
expect(await DB.pubsub.publish('orders', 'hi')).toBe(1);
|
|
720
|
+
expect(server.sent).toEqual(['PUBLISH {orders} hi']);
|
|
721
|
+
});
|
|
722
|
+
});
|
|
723
|
+
|
|
724
|
+
describe('blocking commands', () => {
|
|
725
|
+
test('pop with the key they popped from, and null once the timeout passes', async () => {
|
|
726
|
+
script('BLPOP', ['jobs', 'send'], null);
|
|
727
|
+
script('BLMPOP', ['jobs', ['a', 'b']]);
|
|
728
|
+
script('BZPOPMIN', ['top', 'a', '1.5']);
|
|
729
|
+
script('BZMPOP', ['top', [['c', '3']]]);
|
|
730
|
+
|
|
731
|
+
const popped = await DB.list.blpop(['none', 'jobs'], 5);
|
|
732
|
+
expect(popped?.key).toBe('jobs');
|
|
733
|
+
expect(popped?.value.text()).toBe('send');
|
|
734
|
+
expect(await DB.list.blpop('jobs', 0.5)).toBeNull();
|
|
735
|
+
const many = await DB.list.blmpop(['jobs'], 'left', 2, 0);
|
|
736
|
+
expect(many?.values.map(v => v.text())).toEqual(['a', 'b']);
|
|
737
|
+
const scored = await DB.sortedSet.bzpopmin('top', 1);
|
|
738
|
+
expect([scored?.key, scored?.member.text(), scored?.score]).toEqual([
|
|
739
|
+
'top',
|
|
740
|
+
'a',
|
|
741
|
+
1.5,
|
|
742
|
+
]);
|
|
743
|
+
const members = await DB.sortedSet.bzmpop(['top'], 'max', 1, 1);
|
|
744
|
+
expect(members?.members.map(m => [m.member.text(), m.score])).toEqual([
|
|
745
|
+
['c', 3],
|
|
746
|
+
]);
|
|
747
|
+
await DB.list.blmove('a', 'b', 'left', 'right', 2);
|
|
748
|
+
await DB.stream.xreadBlock(['s'], ['$'], 100, 10);
|
|
749
|
+
await DB.stream.xreadGroupBlock('g', 'c', ['s'], ['>'], 0);
|
|
750
|
+
|
|
751
|
+
expect(server.sent).toEqual([
|
|
752
|
+
'BLPOP {none} {jobs} 5',
|
|
753
|
+
'BLPOP {jobs} 0.5',
|
|
754
|
+
'BLMPOP 0 1 {jobs} LEFT COUNT 2',
|
|
755
|
+
'BZPOPMIN {top} 1',
|
|
756
|
+
'BZMPOP 1 1 {top} MAX COUNT 1',
|
|
757
|
+
'BLMOVE {a} {b} LEFT RIGHT 2',
|
|
758
|
+
'XREAD COUNT 10 BLOCK 100 STREAMS {s} $',
|
|
759
|
+
'XREADGROUP GROUP g c BLOCK 0 STREAMS {s} >',
|
|
760
|
+
]);
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
test('have no queued form, and a read handle has the reads among them', () => {
|
|
764
|
+
const pipe = DB.pipeline() as unknown as {list: Record<string, unknown>};
|
|
765
|
+
expect(pipe.list.blpop).toBeUndefined();
|
|
766
|
+
expect(pipe.list.lpop).toBeDefined();
|
|
767
|
+
const read = DB.read() as unknown as {
|
|
768
|
+
stream: Record<string, unknown>;
|
|
769
|
+
list: Record<string, unknown>;
|
|
770
|
+
};
|
|
771
|
+
expect(read.stream.xreadBlock).toBeDefined();
|
|
772
|
+
expect(read.list.blpop).toBeUndefined();
|
|
773
|
+
});
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
describe('hyperloglogs', () => {
|
|
777
|
+
test('add, count and merge', async () => {
|
|
778
|
+
script('PFADD', 1n);
|
|
779
|
+
script('PFCOUNT', 3n);
|
|
780
|
+
expect(await DB.hyperloglog.pfadd('day', 'a', 'b')).toBe(true);
|
|
781
|
+
expect(await DB.read().hyperloglog.pfcount('day', 'week')).toBe(3);
|
|
782
|
+
await DB.hyperloglog.pfmerge('week', 'mon', 'tue');
|
|
783
|
+
const pipe = DB.pipeline();
|
|
784
|
+
pipe.hyperloglog.pfadd('x', 1).pfcount('x');
|
|
785
|
+
await pipe.exec();
|
|
786
|
+
expect(server.sent).toEqual([
|
|
787
|
+
'PFADD {day} a b',
|
|
788
|
+
'PFCOUNT {day} {week}',
|
|
789
|
+
'PFMERGE {week} {mon} {tue}',
|
|
790
|
+
'PFADD {x} 1',
|
|
791
|
+
'PFCOUNT {x}',
|
|
792
|
+
]);
|
|
793
|
+
});
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
describe('bitfields', () => {
|
|
797
|
+
test('send their operations in order and reply one value each', async () => {
|
|
798
|
+
script('BITFIELD', [0n, 200n, null]);
|
|
799
|
+
script('BITFIELD_RO', [-56n], [2n ** 60n]);
|
|
800
|
+
expect(
|
|
801
|
+
await DB.bitmap
|
|
802
|
+
.bitfield('b')
|
|
803
|
+
.set('u8', 0, 200)
|
|
804
|
+
.get('u8', '#0')
|
|
805
|
+
.overflow('fail')
|
|
806
|
+
.incrBy('u8', 0, 100)
|
|
807
|
+
.invoke(),
|
|
808
|
+
).toEqual([0, 200, null]);
|
|
809
|
+
expect(
|
|
810
|
+
await DB.read().bitmap.bitfieldRo('b').get('i8', 0).invoke(),
|
|
811
|
+
).toEqual([-56]);
|
|
812
|
+
// A value a number can't hold exactly.
|
|
813
|
+
expect(DB.bitmap.bitfieldRo('b').get('i64', 0).invoke()).rejects.toThrow(
|
|
814
|
+
RangeError,
|
|
815
|
+
);
|
|
816
|
+
|
|
817
|
+
const tx = DB.transaction();
|
|
818
|
+
tx.bitmap.bitfield('b').incrBy('i5', 3, 1).queue();
|
|
819
|
+
await tx.exec();
|
|
820
|
+
expect(server.sent).toEqual([
|
|
821
|
+
'BITFIELD {b} SET u8 0 200 GET u8 #0 OVERFLOW FAIL INCRBY u8 0 100',
|
|
822
|
+
'BITFIELD_RO {b} GET i8 0',
|
|
823
|
+
'BITFIELD_RO {b} GET i64 0',
|
|
824
|
+
'BITFIELD {b} INCRBY i5 3 1',
|
|
825
|
+
]);
|
|
826
|
+
expect(server.meta.slice(0, 2)).toEqual([
|
|
827
|
+
{write: true, op: 'bitfield'},
|
|
828
|
+
{write: false, op: 'bitfield_ro'},
|
|
829
|
+
]);
|
|
830
|
+
});
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
describe('commands the groups lack', () => {
|
|
834
|
+
test('are sent by name, raw, with their keys marked', async () => {
|
|
835
|
+
script('OBJECT', 3n);
|
|
836
|
+
expect(
|
|
837
|
+
await DB.command('OBJECT').arg('FREQ').key('hot').invoke().number(),
|
|
838
|
+
).toBe(3);
|
|
839
|
+
await DB.read().command('TYPE').key('k').invoke();
|
|
840
|
+
const pipe = DB.pipeline();
|
|
841
|
+
pipe.command('INCRBY').key('n').arg(2).queue();
|
|
842
|
+
await pipe.exec();
|
|
843
|
+
expect(server.sent).toEqual([
|
|
844
|
+
'OBJECT FREQ {hot}',
|
|
845
|
+
'TYPE {k}',
|
|
846
|
+
'INCRBY {n} 2',
|
|
847
|
+
]);
|
|
848
|
+
expect(server.meta).toEqual([
|
|
849
|
+
{write: true, op: '', raw: true},
|
|
850
|
+
{write: false, op: '', raw: true, readOnly: true},
|
|
851
|
+
]);
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
test('the runtime refuses fail with a TypeError', async () => {
|
|
855
|
+
server.refuse.set(
|
|
856
|
+
'FLUSHALL',
|
|
857
|
+
"FLUSHALL can't be sent as a command: it reaches beyond the database's own keys",
|
|
858
|
+
);
|
|
859
|
+
const err = await DB.command('FLUSHALL')
|
|
860
|
+
.invoke()
|
|
861
|
+
.value()
|
|
862
|
+
.catch((err: unknown) => err);
|
|
863
|
+
expect(err).toBeInstanceOf(TypeError);
|
|
864
|
+
expect((err as Error).message).toContain('reaches beyond');
|
|
865
|
+
});
|
|
866
|
+
});
|