@encore.dev/sdk 2.0.0-beta.7 → 2.0.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -0
- package/app_meta.test.ts +25 -5
- package/app_meta.ts +51 -12
- package/config/config.test.ts +18 -15
- package/config/config.ts +89 -31
- package/config/mod.ts +4 -3
- package/config/secrets.ts +79 -53
- package/config/value.ts +13 -17
- package/cron/mod.test.ts +52 -0
- package/cron/mod.ts +41 -2
- package/dist/app_meta.d.ts +44 -12
- package/dist/app_meta.d.ts.map +1 -0
- package/dist/app_meta.js +2 -0
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +58 -28
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +46 -18
- package/dist/config/config.js.map +1 -1
- package/dist/config/mod.d.ts +5 -4
- package/dist/config/mod.d.ts.map +1 -0
- package/dist/config/mod.js +2 -2
- package/dist/config/mod.js.map +1 -1
- package/dist/config/secrets.d.ts +71 -39
- package/dist/config/secrets.d.ts.map +1 -0
- package/dist/config/secrets.js +31 -38
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +8 -5
- package/dist/config/value.d.ts.map +1 -0
- package/dist/config/value.js +10 -7
- package/dist/config/value.js.map +1 -1
- package/dist/cron/mod.d.ts +36 -1
- package/dist/cron/mod.d.ts.map +1 -0
- package/dist/cron/mod.js +31 -1
- package/dist/cron/mod.js.map +1 -1
- 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 +147 -0
- package/dist/internal/clients/call.d.ts.map +1 -0
- package/dist/internal/clients/call.js +274 -0
- package/dist/internal/clients/call.js.map +1 -0
- package/dist/internal/clients/grpc.d.ts +90 -0
- package/dist/internal/clients/grpc.d.ts.map +1 -0
- package/dist/internal/clients/grpc.js +355 -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 +58 -0
- package/dist/internal/fetch.d.ts.map +1 -0
- package/dist/internal/fetch.js +251 -0
- package/dist/internal/fetch.js.map +1 -0
- package/dist/internal/otel/backend.d.ts +2 -0
- package/dist/internal/otel/backend.d.ts.map +1 -0
- package/dist/internal/otel/context.d.ts +1 -0
- package/dist/internal/otel/context.d.ts.map +1 -0
- package/dist/internal/otel/context_manager.d.ts +1 -0
- package/dist/internal/otel/context_manager.d.ts.map +1 -0
- package/dist/internal/otel/encode.d.ts +2 -0
- package/dist/internal/otel/encode.d.ts.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 +64 -0
- package/dist/internal/otel/http.js.map +1 -0
- package/dist/internal/otel/index.d.ts +2 -2
- package/dist/internal/otel/index.d.ts.map +1 -0
- package/dist/internal/otel/index.js +1 -2
- package/dist/internal/otel/index.js.map +1 -1
- package/dist/internal/otel/meter.d.ts +1 -0
- package/dist/internal/otel/meter.d.ts.map +1 -0
- package/dist/internal/otel/propagator.d.ts +1 -0
- package/dist/internal/otel/propagator.d.ts.map +1 -0
- package/dist/internal/otel/provider.d.ts +4 -0
- package/dist/internal/otel/provider.d.ts.map +1 -0
- package/dist/internal/otel/provider.js +3 -0
- package/dist/internal/otel/provider.js.map +1 -1
- package/dist/internal/otel/span.d.ts +15 -1
- package/dist/internal/otel/span.d.ts.map +1 -0
- package/dist/internal/otel/span.js +30 -2
- package/dist/internal/otel/span.js.map +1 -1
- package/dist/internal/otel/tracer.d.ts +1 -0
- package/dist/internal/otel/tracer.d.ts.map +1 -0
- package/dist/internal/otel/tracer.js +11 -5
- package/dist/internal/otel/tracer.js.map +1 -1
- 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 +1 -0
- package/dist/internal/runtime/meter.d.ts.map +1 -0
- package/dist/internal/runtime/mod.d.ts +6 -0
- package/dist/internal/runtime/mod.d.ts.map +1 -0
- package/dist/internal/runtime/mod.js +32 -2
- package/dist/internal/runtime/mod.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +192 -16
- package/dist/internal/runtime/napi/napi.d.cts +573 -33
- package/dist/internal/runtime/shutdown.d.ts +5 -0
- package/dist/internal/runtime/shutdown.d.ts.map +1 -0
- package/dist/internal/runtime/shutdown.js +9 -1
- package/dist/internal/runtime/shutdown.js.map +1 -1
- 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 +109 -0
- package/dist/internal/testing/scope.d.ts.map +1 -0
- package/dist/internal/testing/scope.js +335 -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 +1 -0
- package/dist/internal/utils/constraints.d.ts.map +1 -0
- package/dist/log/index.d.ts +1 -0
- package/dist/log/index.d.ts.map +1 -0
- package/dist/log/logger.d.ts +2 -0
- package/dist/log/logger.d.ts.map +1 -0
- package/dist/log/runtime.d.ts +2 -0
- package/dist/log/runtime.d.ts.map +1 -0
- package/dist/log/stderr.d.ts +1 -0
- package/dist/log/stderr.d.ts.map +1 -0
- package/dist/metrics/mod.d.ts +45 -118
- package/dist/metrics/mod.d.ts.map +1 -0
- package/dist/metrics/mod.js +44 -179
- package/dist/metrics/mod.js.map +1 -1
- package/dist/mod.d.ts +2 -3
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +0 -1
- package/dist/mod.js.map +1 -1
- package/dist/otel.d.ts +1 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/pubsub/encoding.d.ts +5 -0
- package/dist/pubsub/encoding.d.ts.map +1 -0
- package/dist/pubsub/encoding.js +10 -2
- package/dist/pubsub/encoding.js.map +1 -1
- package/dist/pubsub/mod.d.ts +5 -4
- package/dist/pubsub/mod.d.ts.map +1 -0
- package/dist/pubsub/mod.js +2 -2
- package/dist/pubsub/mod.js.map +1 -1
- package/dist/pubsub/refs.d.ts +8 -0
- package/dist/pubsub/refs.d.ts.map +1 -0
- package/dist/pubsub/refs.js.map +1 -1
- package/dist/pubsub/subscription.d.ts +110 -15
- package/dist/pubsub/subscription.d.ts.map +1 -0
- package/dist/pubsub/subscription.js +98 -16
- package/dist/pubsub/subscription.js.map +1 -1
- package/dist/pubsub/topic.d.ts +101 -31
- package/dist/pubsub/topic.d.ts.map +1 -0
- package/dist/pubsub/topic.js +168 -51
- package/dist/pubsub/topic.js.map +1 -1
- 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 +147 -5
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +157 -9
- package/dist/services/index.js.map +1 -1
- package/dist/shutdown/mod.d.ts +1 -0
- package/dist/shutdown/mod.d.ts.map +1 -0
- package/dist/storage/objects/bucket.d.ts +313 -7
- package/dist/storage/objects/bucket.d.ts.map +1 -0
- package/dist/storage/objects/bucket.js +306 -15
- package/dist/storage/objects/bucket.js.map +1 -1
- package/dist/storage/objects/error.d.ts +10 -0
- package/dist/storage/objects/error.d.ts.map +1 -0
- package/dist/storage/objects/error.js +25 -1
- package/dist/storage/objects/error.js.map +1 -1
- package/dist/storage/objects/mod.d.ts +4 -3
- package/dist/storage/objects/mod.d.ts.map +1 -0
- package/dist/storage/objects/mod.js +1 -1
- package/dist/storage/objects/mod.js.map +1 -1
- package/dist/storage/objects/refs.d.ts +20 -4
- package/dist/storage/objects/refs.d.ts.map +1 -0
- package/dist/storage/objects/refs.js +6 -0
- package/dist/storage/objects/refs.js.map +1 -1
- package/dist/storage/postgres/database.d.ts +85 -25
- package/dist/storage/postgres/database.d.ts.map +1 -0
- package/dist/storage/postgres/database.js +129 -37
- package/dist/storage/postgres/database.js.map +1 -1
- 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 +4 -1
- package/dist/storage/postgres/mod.d.ts.map +1 -0
- package/dist/storage/postgres/mod.js +2 -0
- package/dist/storage/postgres/mod.js.map +1 -1
- 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 +223 -139
- package/dist/storage/redis/commands.d.ts.map +1 -0
- package/dist/storage/redis/commands.js +128 -6
- package/dist/storage/redis/commands.js.map +1 -1
- package/dist/storage/redis/database.d.ts +56 -22
- package/dist/storage/redis/database.d.ts.map +1 -0
- package/dist/storage/redis/database.js +62 -0
- package/dist/storage/redis/database.js.map +1 -1
- package/dist/storage/redis/mod.d.ts +31 -4
- package/dist/storage/redis/mod.d.ts.map +1 -0
- package/dist/storage/redis/mod.js +26 -1
- package/dist/storage/redis/mod.js.map +1 -1
- package/dist/storage/redis/native.d.ts +8 -0
- package/dist/storage/redis/native.d.ts.map +1 -0
- package/dist/storage/redis/native.js +10 -0
- package/dist/storage/redis/native.js.map +1 -1
- package/dist/storage/redis/options.d.ts +1 -0
- package/dist/storage/redis/options.d.ts.map +1 -0
- package/dist/storage/redis/pubsub.d.ts +2 -0
- package/dist/storage/redis/pubsub.d.ts.map +1 -0
- package/dist/storage/redis/reply.d.ts +34 -0
- package/dist/storage/redis/reply.d.ts.map +1 -0
- package/dist/storage/redis/reply.js +40 -1
- package/dist/storage/redis/reply.js.map +1 -1
- package/dist/storage/redis/scan.d.ts +1 -0
- package/dist/storage/redis/scan.d.ts.map +1 -0
- package/dist/storage/redis/script.d.ts +1 -0
- package/dist/storage/redis/script.d.ts.map +1 -0
- package/dist/storage/redis/target.d.ts +5 -3
- package/dist/storage/redis/target.d.ts.map +1 -0
- package/dist/storage/redis/target.js +39 -28
- package/dist/storage/redis/target.js.map +1 -1
- package/dist/storage/redis/wire.d.ts +7 -10
- package/dist/storage/redis/wire.d.ts.map +1 -0
- package/dist/storage/redis/wire.js +8 -32
- package/dist/storage/redis/wire.js.map +1 -1
- 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 -1
- package/dist/types/mod.d.ts +1 -0
- package/dist/types/mod.d.ts.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 +389 -0
- package/internal/clients/grpc.test.ts +368 -0
- package/internal/clients/grpc.ts +485 -0
- package/internal/clients/mod.test.ts +464 -0
- package/internal/clients/mod.ts +337 -0
- package/internal/fetch.ts +287 -0
- package/internal/otel/http.ts +91 -0
- package/internal/otel/index.ts +1 -7
- package/internal/otel/provider.ts +3 -0
- package/internal/otel/span.ts +31 -2
- package/internal/otel/tracer.test.ts +43 -15
- package/internal/otel/tracer.ts +12 -5
- package/internal/reqfields.ts +423 -0
- package/internal/runtime/mod.ts +41 -2
- package/internal/runtime/napi/napi.cjs +192 -16
- package/internal/runtime/napi/napi.d.cts +573 -33
- package/internal/runtime/shutdown.ts +11 -1
- 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 +372 -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/metrics/mod.test.ts +13 -16
- package/metrics/mod.ts +57 -226
- package/mod.ts +1 -8
- package/otel.test.ts +13 -6
- package/package.json +92 -15
- package/pubsub/encoding.ts +11 -1
- package/pubsub/mod.ts +16 -4
- package/pubsub/pubsub.test.ts +233 -14
- package/pubsub/refs.ts +16 -0
- package/pubsub/subscription.ts +200 -21
- package/pubsub/topic.test.ts +26 -0
- package/pubsub/topic.ts +255 -36
- 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 +341 -1
- package/services/index.ts +185 -9
- package/storage/objects/bucket.test.ts +573 -0
- package/storage/objects/bucket.ts +650 -20
- package/storage/objects/error.ts +28 -1
- package/storage/objects/mod.ts +15 -0
- package/storage/objects/refs.ts +51 -3
- package/storage/postgres/database.integration.test.ts +275 -0
- package/storage/postgres/database.test.ts +193 -6
- package/storage/postgres/database.ts +206 -55
- 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 +4 -0
- package/storage/redis/bitfield.ts +162 -0
- package/storage/redis/command.ts +84 -0
- package/storage/redis/commands.ts +271 -21
- package/storage/redis/database.ts +77 -23
- package/storage/redis/mod.ts +38 -2
- package/storage/redis/native.ts +11 -0
- package/storage/redis/redis.test.ts +170 -10
- package/storage/redis/reply.ts +76 -1
- package/storage/redis/runtime.test.ts +15 -0
- package/storage/redis/target.ts +47 -44
- package/storage/redis/wire.ts +8 -32
- 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 +267 -0
- package/tracing/node.ts +176 -0
- package/tracing/tracing.test.ts +953 -0
- package/dist/internal/otel/request_context.d.ts +0 -11
- package/dist/internal/otel/request_context.js +0 -20
- package/dist/internal/otel/request_context.js.map +0 -1
- package/dist/internal/reqtrack/mod.d.ts +0 -6
- package/dist/internal/reqtrack/mod.js +0 -28
- package/dist/internal/reqtrack/mod.js.map +0 -1
- package/dist/req_meta.d.ts +0 -47
- package/dist/req_meta.js +0 -26
- package/dist/req_meta.js.map +0 -1
- package/internal/otel/request_context.ts +0 -32
- package/internal/reqtrack/mod.ts +0 -39
- package/req_meta.ts +0 -75
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which test a call belongs to, in test mode: each test has a scope of its
|
|
3
|
+
* own, the core's (`encore_sdk_core::test_scope`), with its own instances of
|
|
4
|
+
* the app's databases, buckets and Redis databases, what it published, and
|
|
5
|
+
* the values it gave secrets and configs.
|
|
6
|
+
*
|
|
7
|
+
* A call belongs to the scope `scoped()` runs it in (AsyncLocalStorage, which
|
|
8
|
+
* follows `await`, timers and handlers), else to the one test the runner's
|
|
9
|
+
* hooks began ({@link setupHooks}). Outside test mode there are no scopes,
|
|
10
|
+
* and every lookup is `null` at once.
|
|
11
|
+
*
|
|
12
|
+
* In a system test's process the tests run against the app's test session
|
|
13
|
+
* ({@link systemTest}): each scope is then a test the session knows, with an
|
|
14
|
+
* id its calls and messages carry ({@link Scope.carried}).
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
19
|
+
import * as runtime from '../runtime/mod.js';
|
|
20
|
+
import { setCarriedLookup } from './carry.js';
|
|
21
|
+
import { causedBy, Telemetry } from './telemetry.js';
|
|
22
|
+
/** The core's scopes: `null` outside test mode. */
|
|
23
|
+
const scopes = runtime.TEST_SCOPES ?? null;
|
|
24
|
+
/** Whether the process runs as a test, under `encore test` or a test runner. */
|
|
25
|
+
export const testMode = scopes !== null;
|
|
26
|
+
/**
|
|
27
|
+
* The test session the process's tests run against, when they are system
|
|
28
|
+
* tests, those of a suite: `null` for a service's tests, and outside test
|
|
29
|
+
* mode.
|
|
30
|
+
*/
|
|
31
|
+
export const systemTest = scopes?.system() ?? null;
|
|
32
|
+
/** One test: the core's scope, and the handles made of it. */
|
|
33
|
+
export class Scope {
|
|
34
|
+
native;
|
|
35
|
+
name;
|
|
36
|
+
databases = new Map();
|
|
37
|
+
buckets = new Map();
|
|
38
|
+
redis = new Map();
|
|
39
|
+
/** The ids of the messages published as bytes rather than JSON. */
|
|
40
|
+
raw = new Set();
|
|
41
|
+
/** The values the test gave configs, built as the config's type. */
|
|
42
|
+
configs = new Map();
|
|
43
|
+
/** Done with, but left to the hooks that run after the test's own. */
|
|
44
|
+
finished = false;
|
|
45
|
+
/** How the test ended, once something has said. */
|
|
46
|
+
outcome;
|
|
47
|
+
carry;
|
|
48
|
+
constructor(native, name) {
|
|
49
|
+
this.native = native;
|
|
50
|
+
this.name = name;
|
|
51
|
+
}
|
|
52
|
+
/** What the test's calls and messages carry of it, when it is a system
|
|
53
|
+
* test: `null` for a service's test. */
|
|
54
|
+
get carried() {
|
|
55
|
+
if (this.carry === undefined)
|
|
56
|
+
this.carry = this.native.carried();
|
|
57
|
+
return this.carry;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Says how a system test ended, for its session to record, and prints
|
|
61
|
+
* what a failed one caused in the app to standard error, under the
|
|
62
|
+
* failure its runner prints. Once per test: the first to say so is the
|
|
63
|
+
* one that saw it end. Nothing for a service's test.
|
|
64
|
+
*/
|
|
65
|
+
async ended(outcome) {
|
|
66
|
+
if (systemTest === null || this.outcome !== undefined)
|
|
67
|
+
return;
|
|
68
|
+
this.outcome = outcome;
|
|
69
|
+
this.native.setOutcome(outcome);
|
|
70
|
+
if (outcome !== 'failed')
|
|
71
|
+
return;
|
|
72
|
+
let caused;
|
|
73
|
+
try {
|
|
74
|
+
// As it is now: a failed test may have left the app at work.
|
|
75
|
+
caused = causedBy(Telemetry.parse(await this.native.telemetry(false, null)));
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// The test's own failure is what there is to say.
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (caused !== '')
|
|
82
|
+
console.error(caused);
|
|
83
|
+
}
|
|
84
|
+
/** The test's instance of the database `name`, for `access`. */
|
|
85
|
+
sqlDatabase(name, access) {
|
|
86
|
+
let db = this.databases.get(name);
|
|
87
|
+
if (db === undefined) {
|
|
88
|
+
db = this.native.sqlDatabase(name);
|
|
89
|
+
this.databases.set(name, db);
|
|
90
|
+
}
|
|
91
|
+
if (access === undefined)
|
|
92
|
+
return db;
|
|
93
|
+
const key = `${name}\0${access}`;
|
|
94
|
+
let handle = this.databases.get(key);
|
|
95
|
+
if (handle === undefined) {
|
|
96
|
+
handle = db.withAccess(access);
|
|
97
|
+
this.databases.set(key, handle);
|
|
98
|
+
}
|
|
99
|
+
return handle;
|
|
100
|
+
}
|
|
101
|
+
/** The test's instance of the bucket `name`. */
|
|
102
|
+
bucket(name) {
|
|
103
|
+
let bucket = this.buckets.get(name);
|
|
104
|
+
if (bucket === undefined) {
|
|
105
|
+
bucket = this.native.bucket(name);
|
|
106
|
+
this.buckets.set(name, bucket);
|
|
107
|
+
}
|
|
108
|
+
return bucket;
|
|
109
|
+
}
|
|
110
|
+
/** The test's instance of the Redis database `name`. */
|
|
111
|
+
redisDatabase(name) {
|
|
112
|
+
let db = this.redis.get(name);
|
|
113
|
+
if (db === undefined) {
|
|
114
|
+
db = this.native.redisDatabase(name);
|
|
115
|
+
this.redis.set(name, db);
|
|
116
|
+
}
|
|
117
|
+
return db;
|
|
118
|
+
}
|
|
119
|
+
/** Ends the test, releasing its resources. */
|
|
120
|
+
end() {
|
|
121
|
+
this.databases.clear();
|
|
122
|
+
this.buckets.clear();
|
|
123
|
+
this.redis.clear();
|
|
124
|
+
this.native.end();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const storage = new AsyncLocalStorage();
|
|
128
|
+
/** The scopes the hooks began and have not ended. */
|
|
129
|
+
const hooked = new Set();
|
|
130
|
+
/** Whether a runner's hooks begin a scope for each test: then a resource
|
|
131
|
+
* used outside any test is a mistake. */
|
|
132
|
+
let hooksActive = false;
|
|
133
|
+
/** Begins a test's scope. `null` outside test mode. */
|
|
134
|
+
export function begin(name) {
|
|
135
|
+
if (scopes === null)
|
|
136
|
+
return null;
|
|
137
|
+
return new Scope(scopes.begin(name ?? null), name);
|
|
138
|
+
}
|
|
139
|
+
/** Runs `fn` as part of `scope`'s test. */
|
|
140
|
+
export function runIn(scope, fn) {
|
|
141
|
+
return storage.run(scope, fn);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The scope of the test the call belongs to, without the error for a call
|
|
145
|
+
* outside any test: `null` then, as outside test mode. Throws when several
|
|
146
|
+
* tests the hooks began run at once, as it cannot tell which.
|
|
147
|
+
*/
|
|
148
|
+
export function lookupScope() {
|
|
149
|
+
if (scopes === null)
|
|
150
|
+
return null;
|
|
151
|
+
const scope = storage.getStore();
|
|
152
|
+
if (scope !== undefined)
|
|
153
|
+
return scope;
|
|
154
|
+
if (hooked.size === 1)
|
|
155
|
+
return hooked.values().next().value;
|
|
156
|
+
if (hooked.size > 1) {
|
|
157
|
+
throw new Error('several tests are running at once, so Encore cannot tell which one this call belongs to: ' +
|
|
158
|
+
'wrap each concurrent test in `scoped()` from @encore.dev/sdk/testing');
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* The scope of the test a use of a resource belongs to, or `null` to use the
|
|
164
|
+
* process's own instances: outside test mode, or in a test runner whose
|
|
165
|
+
* hooks begin no scopes. Throws for a use outside any test while the hooks
|
|
166
|
+
* do, as the tests would never see what it does.
|
|
167
|
+
*/
|
|
168
|
+
export function currentScope() {
|
|
169
|
+
const scope = lookupScope();
|
|
170
|
+
if (scope === null && hooksActive) {
|
|
171
|
+
throw new Error('a resource was used outside any test (in a beforeAll, an afterAll, or at module level), ' +
|
|
172
|
+
'where no test will see what it does: each test has databases, buckets and topics of its own. ' +
|
|
173
|
+
'Set up the data each test needs in beforeEach, or in a fixture (`fixture()` and ' +
|
|
174
|
+
'`useFixture()` from @encore.dev/sdk/testing)');
|
|
175
|
+
}
|
|
176
|
+
return scope;
|
|
177
|
+
}
|
|
178
|
+
/** The scope of the current test, or an error saying there is none. */
|
|
179
|
+
export function requireScope() {
|
|
180
|
+
if (scopes === null) {
|
|
181
|
+
throw new Error('not running as a test: run it with your test runner, or `encore test`');
|
|
182
|
+
}
|
|
183
|
+
const scope = lookupScope();
|
|
184
|
+
if (scope === null) {
|
|
185
|
+
throw new Error('there is no current test: add the runner adapter for your test runner ' +
|
|
186
|
+
'(such as @encore.dev/sdk/testing/vitest), or wrap the test in `scoped()`');
|
|
187
|
+
}
|
|
188
|
+
return scope;
|
|
189
|
+
}
|
|
190
|
+
/** The core's scopes, or an error outside test mode. */
|
|
191
|
+
export function requireScopes() {
|
|
192
|
+
if (scopes === null) {
|
|
193
|
+
throw new Error('not running as a test: run it with your test runner, or `encore test`');
|
|
194
|
+
}
|
|
195
|
+
return scopes;
|
|
196
|
+
}
|
|
197
|
+
/** Ends the scopes whose tests are done. */
|
|
198
|
+
function endFinished() {
|
|
199
|
+
for (const scope of hooked) {
|
|
200
|
+
if (scope.finished) {
|
|
201
|
+
hooked.delete(scope);
|
|
202
|
+
scope.end();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** The scope the hooks began for the test of a runner's test context. */
|
|
207
|
+
const byContext = new WeakMap();
|
|
208
|
+
/** The scopes that end with their runner's `onTestFinished`. */
|
|
209
|
+
const endsItself = new WeakSet();
|
|
210
|
+
/** Whether a hook's argument is its runner's test context: an object, or
|
|
211
|
+
* vitest's, a function with properties. */
|
|
212
|
+
export function isContext(ctx) {
|
|
213
|
+
return (typeof ctx === 'object' && ctx !== null) || typeof ctx === 'function';
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The scope a `beforeEach` hook added after {@link setupHooks}' belongs to:
|
|
217
|
+
* that of the test with the context `ctx`, or without one, as in jest and
|
|
218
|
+
* bun, the one begun last.
|
|
219
|
+
*/
|
|
220
|
+
export function hookScope(ctx) {
|
|
221
|
+
if (isContext(ctx))
|
|
222
|
+
return byContext.get(ctx) ?? null;
|
|
223
|
+
return [...hooked].reverse().find(scope => !scope.finished) ?? null;
|
|
224
|
+
}
|
|
225
|
+
/** The name of the test a hook runs for, for diagnostics: vitest's and
|
|
226
|
+
* node:test's contexts have it, and jest's and bun's `expect`. */
|
|
227
|
+
export function testName(ctx) {
|
|
228
|
+
const c = ctx;
|
|
229
|
+
const name = c?.task?.name ?? c?.name;
|
|
230
|
+
if (typeof name === 'string')
|
|
231
|
+
return name;
|
|
232
|
+
const expect = globalThis.expect;
|
|
233
|
+
const state = expect?.getState?.();
|
|
234
|
+
return typeof state?.currentTestName === 'string'
|
|
235
|
+
? state.currentTestName
|
|
236
|
+
: undefined;
|
|
237
|
+
}
|
|
238
|
+
if (systemTest !== null) {
|
|
239
|
+
// A call or a publish carries the test it is made for, found as a
|
|
240
|
+
// resource finds its test. Where several tests run at once and none is
|
|
241
|
+
// current, it cannot be told which, and the lookup throws as a resource's
|
|
242
|
+
// does: a call made without the test would be done on data no test sees.
|
|
243
|
+
setCarriedLookup(() => lookupScope()?.carried ?? null);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* How the test of a runner's test context ended, where the context says:
|
|
247
|
+
* vitest's has the test's result once it is done, and node:test's whether it
|
|
248
|
+
* passed. `undefined` where it does not, as in jest and bun, whose hooks are
|
|
249
|
+
* not told.
|
|
250
|
+
*/
|
|
251
|
+
export function outcomeOf(ctx) {
|
|
252
|
+
if (!isContext(ctx))
|
|
253
|
+
return undefined;
|
|
254
|
+
const c = ctx;
|
|
255
|
+
switch (c.task?.result?.state) {
|
|
256
|
+
case 'pass':
|
|
257
|
+
return 'passed';
|
|
258
|
+
case 'fail':
|
|
259
|
+
return 'failed';
|
|
260
|
+
case 'skip':
|
|
261
|
+
case 'todo':
|
|
262
|
+
return 'skipped';
|
|
263
|
+
}
|
|
264
|
+
if (typeof c.passed === 'boolean')
|
|
265
|
+
return c.passed ? 'passed' : 'failed';
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Registers per-test scopes with a runner's hooks: a scope begins before each
|
|
270
|
+
* test and ends after it. `prepare` runs in each test's scope after it
|
|
271
|
+
* begins, as the test's first hook.
|
|
272
|
+
*
|
|
273
|
+
* A runner that gives the test's context an `onTestFinished` (vitest) ends
|
|
274
|
+
* the scope after every other hook. Others run the hooks a test file
|
|
275
|
+
* registers after these, so the scope is only marked done after the test,
|
|
276
|
+
* for the hooks after it to use, and ends when the next test begins or the
|
|
277
|
+
* file's tests are done.
|
|
278
|
+
*
|
|
279
|
+
* A system test is also told how it ended, where the runner's context says
|
|
280
|
+
* ({@link outcomeOf}), and a failed one prints what it caused in the app.
|
|
281
|
+
*/
|
|
282
|
+
export function setupHooks(hooks, prepare) {
|
|
283
|
+
if (scopes === null)
|
|
284
|
+
return;
|
|
285
|
+
hooksActive = true;
|
|
286
|
+
// The functions take no parameters by name: jest and bun pass a hook that
|
|
287
|
+
// does a `done` callback to call.
|
|
288
|
+
hooks.beforeEach((...args) => {
|
|
289
|
+
endFinished();
|
|
290
|
+
const ctx = args[0];
|
|
291
|
+
const scope = begin(testName(ctx));
|
|
292
|
+
hooked.add(scope);
|
|
293
|
+
if (isContext(ctx)) {
|
|
294
|
+
byContext.set(ctx, scope);
|
|
295
|
+
const onFinished = ctx.onTestFinished;
|
|
296
|
+
if (typeof onFinished === 'function') {
|
|
297
|
+
endsItself.add(scope);
|
|
298
|
+
onFinished.call(ctx, async () => {
|
|
299
|
+
try {
|
|
300
|
+
const outcome = outcomeOf(ctx);
|
|
301
|
+
if (outcome !== undefined)
|
|
302
|
+
await scope.ended(outcome);
|
|
303
|
+
}
|
|
304
|
+
finally {
|
|
305
|
+
hooked.delete(scope);
|
|
306
|
+
scope.end();
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (prepare !== undefined)
|
|
312
|
+
return runIn(scope, () => prepare(scope));
|
|
313
|
+
return undefined;
|
|
314
|
+
});
|
|
315
|
+
hooks.afterEach((...args) => {
|
|
316
|
+
const ctx = args[0];
|
|
317
|
+
// Without the test's context, as in jest and bun, the test that began
|
|
318
|
+
// first: concurrent tests there use `scoped()`, not these scopes.
|
|
319
|
+
const scope = isContext(ctx)
|
|
320
|
+
? byContext.get(ctx)
|
|
321
|
+
: [...hooked].find(scope => !scope.finished);
|
|
322
|
+
if (scope === undefined || !hooked.has(scope))
|
|
323
|
+
return undefined;
|
|
324
|
+
scope.finished = true;
|
|
325
|
+
// A scope that ends itself says how its test ended then, once the
|
|
326
|
+
// hooks after this one have run. Any other says so now, while the
|
|
327
|
+
// failure is what the runner prints next.
|
|
328
|
+
if (endsItself.has(scope))
|
|
329
|
+
return undefined;
|
|
330
|
+
const outcome = outcomeOf(ctx);
|
|
331
|
+
return outcome === undefined ? undefined : scope.ended(outcome);
|
|
332
|
+
});
|
|
333
|
+
hooks.afterAll?.(() => endFinished());
|
|
334
|
+
}
|
|
335
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../internal/testing/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAC,iBAAiB,EAAC,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK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AAE;QACpC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,sEAAsE;QACtE,kEAAkE;QAClE,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC;YAC1B,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC;YACpB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAChE,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;QACtB,kEAAkE;QAClE,kEAAkE;QAClE,0CAA0C;QAC1C,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAC5C,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAC/B,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;IACH,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Says which statement of a test is running while it has its browser do
|
|
3
|
+
* something, for the adapters of `@encore.dev/sdk/testing`.
|
|
4
|
+
*
|
|
5
|
+
* A test's browser is reached through Encore, which reads what the test's
|
|
6
|
+
* tool has it do — a click, a key, a navigation — off the protocol. That
|
|
7
|
+
* says what was done, not which line of the test did it. So each call the
|
|
8
|
+
* test makes on its tool's objects is reported as a **step**, with the call
|
|
9
|
+
* as written and where it is, on the connection the tool's own commands go
|
|
10
|
+
* over: what the browser is told between a step's beginning and its end is
|
|
11
|
+
* that statement's doing.
|
|
12
|
+
*
|
|
13
|
+
* The tool's objects are wrapped ({@link wrap}), not changed: a call on a
|
|
14
|
+
* wrapper reports the step and makes the call on the object itself.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
/** Sends a command of Encore's own over a tool's connection to the browser. */
|
|
19
|
+
export type Send = (method: string, params: Record<string, unknown>) => Promise<unknown>;
|
|
20
|
+
/** Reports steps over a connection. */
|
|
21
|
+
export declare class Steps {
|
|
22
|
+
private readonly send;
|
|
23
|
+
/** Set once the connection has failed: nothing more is reported. */
|
|
24
|
+
private gone;
|
|
25
|
+
constructor(send: Send);
|
|
26
|
+
/** Runs `fn` as the step `name`, made at `at`. */
|
|
27
|
+
run<R>(name: string, at: Location | null, fn: () => R): Promise<Awaited<R>>;
|
|
28
|
+
/**
|
|
29
|
+
* Says the step `name` begins, now: the word is on its way before this
|
|
30
|
+
* returns, ahead of whatever the caller has the browser do next. Resolves
|
|
31
|
+
* to the step's id, or `null` where nothing took it.
|
|
32
|
+
*/
|
|
33
|
+
begin(name: string, at: Location | null): Promise<string | null>;
|
|
34
|
+
/** Says the step `step` ended, with `error` if it failed. */
|
|
35
|
+
end(step: Promise<string | null>, error?: string): Promise<void>;
|
|
36
|
+
/** Takes back the step `step`: what began was no statement of its own. */
|
|
37
|
+
discard(step: Promise<string | null>): Promise<void>;
|
|
38
|
+
private finish;
|
|
39
|
+
}
|
|
40
|
+
/** Where in the test a call was made. */
|
|
41
|
+
export interface Location {
|
|
42
|
+
file: string;
|
|
43
|
+
line: number;
|
|
44
|
+
}
|
|
45
|
+
/** Where the test called from: the first frame of the stack that is its own. */
|
|
46
|
+
export declare function caller(): Location | null;
|
|
47
|
+
/** The tool's own object for `value`, if `value` is a wrapper of one. */
|
|
48
|
+
export declare function unwrap<T>(value: T): T;
|
|
49
|
+
/**
|
|
50
|
+
* Wraps `target`, an object of a test's tool, so that each call made on it
|
|
51
|
+
* is reported to `steps`: `label` is what it is called in a step's name
|
|
52
|
+
* (`page`, or the call that gave it, as `page.locator("#pay")`).
|
|
53
|
+
*/
|
|
54
|
+
export declare function wrap<T extends object>(target: T, label: string, steps: Steps): T;
|
|
55
|
+
//# sourceMappingURL=steps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steps.d.ts","sourceRoot":"","sources":["../../../internal/testing/steps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,+EAA+E;AAC/E,MAAM,MAAM,IAAI,GAAG,CACjB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,uCAAuC;AACvC,qBAAa,KAAK;IAChB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAO;IAC5B,oEAAoE;IACpE,OAAO,CAAC,IAAI,CAAS;gBAET,IAAI,EAAE,IAAI;IAItB,kDAAkD;IAC5C,GAAG,CAAC,CAAC,EACT,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,QAAQ,GAAG,IAAI,EACnB,EAAE,EAAE,MAAM,CAAC,GACV,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAYtB;;;;OAIG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAsBhE,6DAA6D;IACvD,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItE,0EAA0E;IACpE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YAI5C,MAAM;CAYrB;AAOD,yCAAyC;AACzC,MAAM,WAAW,QAA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