@encore.dev/sdk 2.0.0-beta.7 → 2.0.0-beta.8
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 +55 -0
- package/app_meta.ts +8 -0
- package/config/config.test.ts +10 -3
- package/config/config.ts +75 -21
- package/config/mod.ts +4 -3
- package/config/secrets.ts +72 -55
- package/cron/mod.ts +32 -0
- package/dist/app_meta.d.ts +7 -0
- package/dist/app_meta.d.ts.map +1 -0
- package/dist/app_meta.js +1 -0
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +44 -18
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +43 -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 +62 -39
- package/dist/config/secrets.d.ts.map +1 -0
- package/dist/config/secrets.js +21 -37
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +1 -0
- package/dist/config/value.d.ts.map +1 -0
- package/dist/cron/mod.d.ts +31 -0
- package/dist/cron/mod.d.ts.map +1 -0
- package/dist/cron/mod.js +23 -0
- package/dist/cron/mod.js.map +1 -1
- 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 +129 -0
- package/dist/gateway/mod.d.ts.map +1 -0
- package/dist/gateway/mod.js +187 -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/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 +54 -0
- package/dist/internal/fetch.d.ts.map +1 -0
- package/dist/internal/fetch.js +240 -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/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 +1 -0
- package/dist/internal/otel/provider.d.ts.map +1 -0
- package/dist/internal/otel/span.d.ts +4 -0
- package/dist/internal/otel/span.d.ts.map +1 -0
- package/dist/internal/otel/span.js +5 -0
- 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 +150 -0
- package/dist/internal/reqfields.d.ts.map +1 -0
- package/dist/internal/reqfields.js +312 -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 +160 -16
- package/dist/internal/runtime/napi/napi.d.cts +474 -29
- 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/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 +81 -0
- package/dist/internal/testing/scope.d.ts.map +1 -0
- package/dist/internal/testing/scope.js +237 -0
- package/dist/internal/testing/scope.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 +1 -2
- 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 +4 -3
- 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 +104 -10
- 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 +87 -23
- package/dist/pubsub/topic.d.ts.map +1 -0
- package/dist/pubsub/topic.js +143 -40
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +191 -0
- package/dist/reqctx/mod.d.ts.map +1 -0
- package/dist/reqctx/mod.js +160 -0
- package/dist/reqctx/mod.js.map +1 -0
- package/dist/services/index.d.ts +145 -4
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +155 -8
- 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 +312 -7
- package/dist/storage/objects/bucket.d.ts.map +1 -0
- package/dist/storage/objects/bucket.js +305 -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 +81 -25
- package/dist/storage/postgres/database.d.ts.map +1 -0
- package/dist/storage/postgres/database.js +125 -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 +160 -0
- package/dist/testing/mod.d.ts.map +1 -0
- package/dist/testing/mod.js +227 -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/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/mod.d.ts +19 -0
- package/dist/tracing/mod.d.ts.map +1 -0
- package/dist/tracing/mod.js +46 -0
- package/dist/tracing/mod.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/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 +210 -0
- package/gateway/request.ts +578 -0
- package/gateway/serve.ts +738 -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 +276 -0
- package/internal/otel/index.ts +1 -7
- package/internal/otel/span.ts +6 -0
- package/internal/otel/tracer.test.ts +43 -15
- package/internal/otel/tracer.ts +12 -5
- package/internal/reqfields.ts +390 -0
- package/internal/runtime/mod.ts +41 -2
- package/internal/runtime/napi/napi.cjs +160 -16
- package/internal/runtime/napi/napi.d.cts +474 -29
- package/internal/runtime/shutdown.ts +11 -1
- package/internal/testing/runner.ts +10 -0
- package/internal/testing/scope.ts +273 -0
- package/metrics/mod.test.ts +13 -16
- package/metrics/mod.ts +57 -226
- package/mod.ts +0 -8
- package/otel.test.ts +13 -6
- package/package.json +67 -15
- package/pubsub/encoding.ts +11 -1
- package/pubsub/mod.ts +10 -3
- package/pubsub/pubsub.test.ts +232 -14
- package/pubsub/refs.ts +16 -0
- package/pubsub/subscription.ts +194 -16
- package/pubsub/topic.test.ts +26 -0
- package/pubsub/topic.ts +220 -25
- package/reqctx/mod.ts +284 -0
- package/reqctx/reqctx.test.ts +193 -0
- package/scripts/postprocess-docs.test.ts +48 -0
- package/services/index.test.ts +341 -1
- package/services/index.ts +183 -8
- package/storage/objects/bucket.test.ts +573 -0
- package/storage/objects/bucket.ts +649 -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 +202 -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 +337 -0
- package/testing/node.ts +12 -0
- package/testing/vitest.ts +13 -0
- package/tracing/mod.ts +82 -0
- package/tracing/native.test.ts +170 -0
- package/tracing/tracing.test.ts +317 -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
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
/// <reference types="node" />
|
|
11
|
+
/// <reference types="node" />
|
|
11
12
|
/** A value sent to Redis as an argument: text, bytes, or a number. */
|
|
12
13
|
export type RedisArg = string | number | bigint | Buffer | Uint8Array;
|
|
13
14
|
/** A key and its value, or a field and its value, in the order given. */
|
|
@@ -24,10 +25,12 @@ export declare class Cmd {
|
|
|
24
25
|
readonly write: boolean;
|
|
25
26
|
readonly args: Arg[];
|
|
26
27
|
/**
|
|
27
|
-
* Whether the
|
|
28
|
-
*
|
|
28
|
+
* Whether the app named the command itself, with `command()`: the runtime
|
|
29
|
+
* then checks it against Redis's command table before sending it.
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
+
raw: boolean;
|
|
32
|
+
/** Whether it is sent through a handle that can only read. */
|
|
33
|
+
readOnly: boolean;
|
|
31
34
|
/** A command Redis calls `name`, traced as `operation`. */
|
|
32
35
|
constructor(operation: string, name: string, write: boolean);
|
|
33
36
|
/** Appends a key: an argument the database's key prefix applies to. */
|
|
@@ -49,8 +52,6 @@ export declare class Cmd {
|
|
|
49
52
|
fields(items: Pairs<RedisArg>): this;
|
|
50
53
|
/** Appends each member's score, then the member: `ZADD`'s. */
|
|
51
54
|
scores(items: Pairs<number>): this;
|
|
52
|
-
/** Marks the reply as naming keys. */
|
|
53
|
-
withReplyKeys(): this;
|
|
54
55
|
/** A copy, to append more arguments to. */
|
|
55
56
|
clone(): Cmd;
|
|
56
57
|
}
|
|
@@ -97,9 +98,5 @@ export declare class Status {
|
|
|
97
98
|
export type Value = null | bigint | number | boolean | Buffer | Status | Value[] | MapReply | ServerError;
|
|
98
99
|
/** Decodes an encoded reply. */
|
|
99
100
|
export declare function decodeReply(buf: Buffer): Value;
|
|
100
|
-
/**
|
|
101
|
-
* Removes the database's key prefix from the stream names in a stream read's
|
|
102
|
-
* reply, which is a list of (or a map from) stream name to entries.
|
|
103
|
-
*/
|
|
104
|
-
export declare function stripReplyKeys(v: Value, prefix: string | undefined): void;
|
|
105
101
|
export {};
|
|
102
|
+
//# sourceMappingURL=wire.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../../storage/redis/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;;;AAEH,sEAAsE;AACtE,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;AAEtE,yEAAyE;AACzE,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAElE,iCAAiC;AACjC,UAAU,GAAG;IACX,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,iFAAiF;AACjF,qBAAa,GAAG;IAYZ,QAAQ,CAAC,SAAS,EAAE,MAAM;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,KAAK,EAAE,OAAO;IAbzB,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,CAAM;IAC1B;;;OAGG;IACH,GAAG,UAAS;IACZ,8DAA8D;IAC9D,QAAQ,UAAS;IAEjB,2DAA2D;gBAEhD,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO;IAGzB,uEAAuE;IACvE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAKtB,4BAA4B;IAC5B,IAAI,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAKnC;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAItC,6CAA6C;IAC7C,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAK1B,mDAAmD;IACnD,MAAM,CAAC,MAAM,EAAE,SAAS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,MAAM,GACN,KAAK,EAAE,GACP,QAAQ,GACR,WAAW,CAAC;AAIhB,gCAAgC;AAChC,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAwE9C"}
|
|
@@ -14,10 +14,12 @@ export class Cmd {
|
|
|
14
14
|
write;
|
|
15
15
|
args = [];
|
|
16
16
|
/**
|
|
17
|
-
* Whether the
|
|
18
|
-
*
|
|
17
|
+
* Whether the app named the command itself, with `command()`: the runtime
|
|
18
|
+
* then checks it against Redis's command table before sending it.
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
raw = false;
|
|
21
|
+
/** Whether it is sent through a handle that can only read. */
|
|
22
|
+
readOnly = false;
|
|
21
23
|
/** A command Redis calls `name`, traced as `operation`. */
|
|
22
24
|
constructor(operation, name, write) {
|
|
23
25
|
this.operation = operation;
|
|
@@ -71,16 +73,12 @@ export class Cmd {
|
|
|
71
73
|
this.arg(score).arg(member);
|
|
72
74
|
return this;
|
|
73
75
|
}
|
|
74
|
-
/** Marks the reply as naming keys. */
|
|
75
|
-
withReplyKeys() {
|
|
76
|
-
this.replyKeys = true;
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
76
|
/** A copy, to append more arguments to. */
|
|
80
77
|
clone() {
|
|
81
78
|
const out = new Cmd(this.operation, this.name, this.write);
|
|
82
79
|
out.args.push(...this.args);
|
|
83
|
-
out.
|
|
80
|
+
out.raw = this.raw;
|
|
81
|
+
out.readOnly = this.readOnly;
|
|
84
82
|
return out;
|
|
85
83
|
}
|
|
86
84
|
}
|
|
@@ -155,7 +153,7 @@ function commandSize(cmd) {
|
|
|
155
153
|
return size;
|
|
156
154
|
}
|
|
157
155
|
function writeCommand(w, cmd) {
|
|
158
|
-
w.u8(cmd.write ? 1 : 0);
|
|
156
|
+
w.u8((cmd.write ? 1 : 0) | (cmd.raw ? 2 : 0) | (cmd.readOnly ? 4 : 0));
|
|
159
157
|
w.bytes(Buffer.from(cmd.operation, 'utf8'));
|
|
160
158
|
w.bytes(Buffer.from(cmd.name, 'utf8'));
|
|
161
159
|
w.u32(cmd.args.length);
|
|
@@ -308,26 +306,4 @@ export function decodeReply(buf) {
|
|
|
308
306
|
throw malformed();
|
|
309
307
|
return out;
|
|
310
308
|
}
|
|
311
|
-
/**
|
|
312
|
-
* Removes the database's key prefix from the stream names in a stream read's
|
|
313
|
-
* reply, which is a list of (or a map from) stream name to entries.
|
|
314
|
-
*/
|
|
315
|
-
export function stripReplyKeys(v, prefix) {
|
|
316
|
-
if (!prefix)
|
|
317
|
-
return;
|
|
318
|
-
const p = Buffer.from(prefix, 'utf8');
|
|
319
|
-
const strip = (name) => Buffer.isBuffer(name) && name.subarray(0, p.length).equals(p)
|
|
320
|
-
? name.subarray(p.length)
|
|
321
|
-
: name;
|
|
322
|
-
if (Array.isArray(v)) {
|
|
323
|
-
for (const stream of v) {
|
|
324
|
-
if (Array.isArray(stream) && stream.length > 0)
|
|
325
|
-
stream[0] = strip(stream[0]);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
else if (v instanceof MapReply) {
|
|
329
|
-
for (const pair of v.entries)
|
|
330
|
-
pair[0] = strip(pair[0]);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
309
|
//# sourceMappingURL=wire.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../storage/redis/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAcH,iFAAiF;AACjF,MAAM,OAAO,GAAG;
|
|
1
|
+
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../storage/redis/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAcH,iFAAiF;AACjF,MAAM,OAAO,GAAG;IAYH;IACA;IACA;IAbF,IAAI,GAAU,EAAE,CAAC;IAC1B;;;OAGG;IACH,GAAG,GAAG,KAAK,CAAC;IACZ,8DAA8D;IAC9D,QAAQ,GAAG,KAAK,CAAC;IAEjB,2DA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AAC,GAAG,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;gBAC/B,EAAE,IAAI,CAAC,CAAC;gBACR,OAAO,CAAC,CAAC;YACX,CAAC;YACD,KAAK,CAAC,CAAC,CAAC,CAAC;gBACP,IAAI,CAAC,CAAC,CAAC,CAAC;gBACR,MAAM,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;gBAClC,EAAE,IAAI,CAAC,CAAC;gBACR,OAAO,CAAC,CAAC;YACX,CAAC;YACD,KAAK,CAAC;gBACJ,OAAO,IAAI,WAAW,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;YACnD,KAAK,EAAE;gBACL,OAAO,MAAM,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;YAC3C;gBACE,MAAM,SAAS,EAAE,CAAC;QACtB,CAAC;IACH,CAAC,CAAC;IACF,MAAM,GAAG,GAAG,KAAK,EAAE,CAAC;IACpB,IAAI,EAAE,KAAK,GAAG,CAAC,MAAM;QAAE,MAAM,SAAS,EAAE,CAAC;IACzC,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun.d.ts","sourceRoot":"","sources":["../../testing/bun.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-test infrastructure under `bun test`: `[test] preload =
|
|
3
|
+
* ["@encore.dev/sdk/testing/bun"]` in `bunfig.toml`.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import '../internal/testing/runner.js';
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- an error in the build only, without bun's types
|
|
9
|
+
// @ts-ignore: bun's own module, there when bun runs this.
|
|
10
|
+
import { afterAll, afterEach, beforeEach } from 'bun:test';
|
|
11
|
+
import { setup } from './mod.js';
|
|
12
|
+
setup({ beforeEach, afterEach, afterAll });
|
|
13
|
+
//# sourceMappingURL=bun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun.js","sourceRoot":"","sources":["../../testing/bun.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,4BAA4B,CAAC;AACpC,gHAAgH;AAChH,0DAA0D;AAC1D,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AACzD,OAAO,EAAC,KAAK,EAAC,MAAM,OAAO,CAAC;AAE5B,KAAK,CAAC,EAAC,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest.d.ts","sourceRoot":"","sources":["../../testing/jest.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-test infrastructure under jest: `setupFilesAfterEnv:
|
|
3
|
+
* ["@encore.dev/sdk/testing/jest"]` in the jest config.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import '../internal/testing/runner.js';
|
|
8
|
+
import { setup } from './mod.js';
|
|
9
|
+
// jest's hooks are globals.
|
|
10
|
+
setup(globalThis);
|
|
11
|
+
//# sourceMappingURL=jest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest.js","sourceRoot":"","sources":["../../testing/jest.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,4BAA4B,CAAC;AACpC,OAAO,EAAC,KAAK,EAAa,MAAM,OAAO,CAAC;AAExC,4BAA4B;AAC5B,KAAK,CAAC,UAA8B,CAAC,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests of an Encore app. Each test gets infrastructure of its own —
|
|
3
|
+
* databases, buckets, Redis databases and topics no other test sees — with
|
|
4
|
+
* nothing to set up but one line of runner config:
|
|
5
|
+
*
|
|
6
|
+
* | Runner | Config |
|
|
7
|
+
* |-----------|---------------------------------------------------------------------|
|
|
8
|
+
* | vitest | `test.setupFiles: ["@encore.dev/sdk/testing/vitest"]` |
|
|
9
|
+
* | jest | `setupFilesAfterEnv: ["@encore.dev/sdk/testing/jest"]` |
|
|
10
|
+
* | bun | `bunfig.toml`: `[test] preload = ["@encore.dev/sdk/testing/bun"]` |
|
|
11
|
+
* | node:test | `import "@encore.dev/sdk/testing/node"` at the top of each test file |
|
|
12
|
+
*
|
|
13
|
+
* The tests run with `encore test`, or with the runner itself (`vitest`,
|
|
14
|
+
* `bun test`, an editor's test button): Encore finds the app the tests are in,
|
|
15
|
+
* and starts its daemon if it is not running. `ENCORE_TEST=0` turns this off,
|
|
16
|
+
* and `ENCORE_TEST=1` turns it on for a runner Encore does not recognize.
|
|
17
|
+
*
|
|
18
|
+
* Nothing runs by itself in a test: what a test publishes is recorded, for it
|
|
19
|
+
* to read back with {@link published} and hand to a subscription with
|
|
20
|
+
* {@link deliver}.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* import {deliver, published} from "@encore.dev/sdk/testing";
|
|
24
|
+
*
|
|
25
|
+
* test("signup sends a welcome", async () => {
|
|
26
|
+
* await signup("ada");
|
|
27
|
+
* expect(published(signups)).toHaveLength(1);
|
|
28
|
+
* expect(await deliver(sendWelcome)).toBe(1);
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* @module
|
|
32
|
+
*/
|
|
33
|
+
import type { AnySecret } from '../config/secrets.js';
|
|
34
|
+
import { type Config } from '../config/config.js';
|
|
35
|
+
import type { Message } from '../pubsub/subscription.js';
|
|
36
|
+
import { Subscription } from '../pubsub/subscription.js';
|
|
37
|
+
import type { OrderedTopic, Topic } from '../pubsub/topic.js';
|
|
38
|
+
import { type Hooks } from '../internal/testing/scope.js';
|
|
39
|
+
export type { Hooks } from '../internal/testing/scope.js';
|
|
40
|
+
/** The options of {@link setup} and {@link scoped}. */
|
|
41
|
+
export interface ScopeOptions {
|
|
42
|
+
/**
|
|
43
|
+
* What each test starts from: a {@link Fixture}, or `null` for the
|
|
44
|
+
* resources' initial state, whatever {@link useFixture} says.
|
|
45
|
+
*/
|
|
46
|
+
fixture?: Fixture | null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Registers per-test infrastructure with a runner's hooks: each test begins
|
|
50
|
+
* with resources of its own, released after it. The per-runner entry points
|
|
51
|
+
* (`@encore.dev/sdk/testing/vitest` and the others) call this for you.
|
|
52
|
+
*
|
|
53
|
+
* Once it has, a resource used outside any test — in a `beforeAll`, or at
|
|
54
|
+
* module level — throws: no test would see what it does. Set up what each
|
|
55
|
+
* test needs in `beforeEach`, or in a {@link fixture}.
|
|
56
|
+
*
|
|
57
|
+
* Outside test mode it registers nothing, so a test file still runs.
|
|
58
|
+
*/
|
|
59
|
+
export declare function setup(hooks: Hooks, options?: ScopeOptions): void;
|
|
60
|
+
/**
|
|
61
|
+
* Wraps a test body to run in a scope of its own: for concurrent tests,
|
|
62
|
+
* which the runner's hooks cannot tell apart, or a runner without hooks.
|
|
63
|
+
*
|
|
64
|
+
* test.concurrent("x", scoped(async () => { ... }));
|
|
65
|
+
*
|
|
66
|
+
* The test starts from `options.fixture` if given, else from the fixture
|
|
67
|
+
* {@link useFixture} chose for it, where the runner hands the test its
|
|
68
|
+
* context (vitest, node:test). Outside test mode it runs `fn` as it is.
|
|
69
|
+
*/
|
|
70
|
+
export declare function scoped<A extends unknown[], R>(fn: (...args: A) => Promise<R> | R, options?: ScopeOptions): (...args: A) => Promise<R>;
|
|
71
|
+
/**
|
|
72
|
+
* What the current test has published to `topic`, in the order it was
|
|
73
|
+
* published: by the test itself, and by the code it called. Nothing handles
|
|
74
|
+
* it otherwise: hand it to a subscription with {@link deliver}.
|
|
75
|
+
*
|
|
76
|
+
* Each message's `data` is what was published: decoded from JSON, or the
|
|
77
|
+
* bytes published as bytes.
|
|
78
|
+
*/
|
|
79
|
+
export declare function published<T>(topic: Topic<T> | OrderedTopic<T>): Message<T>[];
|
|
80
|
+
/**
|
|
81
|
+
* Runs `subscription`'s handler on each message the current test — or the
|
|
82
|
+
* code it called — published to its topic that the subscription has not
|
|
83
|
+
* handled yet, one at a time, in the order they were published, as part of
|
|
84
|
+
* the test. Resolves to how many it handled.
|
|
85
|
+
*
|
|
86
|
+
* As in a real delivery, the handler gets a message only if the
|
|
87
|
+
* subscription's filter matches it, decoded as the subscription says, with
|
|
88
|
+
* the Request Context fields it was published with, and `deliveryAttempt` 1
|
|
89
|
+
* the first time. What the handler publishes to the topic in turn is handed
|
|
90
|
+
* over in the same call.
|
|
91
|
+
*
|
|
92
|
+
* It stops at the first message the handler fails, and rejects with its
|
|
93
|
+
* error. That message stays unhandled: the next call hands it over again,
|
|
94
|
+
* its `deliveryAttempt` one more. Retry policies, ack deadlines and dead
|
|
95
|
+
* letters play no part.
|
|
96
|
+
*/
|
|
97
|
+
export declare function deliver<T>(subscription: Subscription<T>): Promise<number>;
|
|
98
|
+
/**
|
|
99
|
+
* Gives `secret` a value for the current test, in place of the app's. No
|
|
100
|
+
* other test sees it, and it is gone when the test ends.
|
|
101
|
+
*/
|
|
102
|
+
export declare function setSecret(secret: AnySecret, value: string | Uint8Array): void;
|
|
103
|
+
/**
|
|
104
|
+
* Gives `config` a value for the current test, in place of the app's: what
|
|
105
|
+
* calling the config returns in the test from then on. No other test sees
|
|
106
|
+
* it, and it is gone when the test ends. Throws if the value does not
|
|
107
|
+
* satisfy the config's schema.
|
|
108
|
+
*/
|
|
109
|
+
export declare function setConfig<T>(config: Config<T>, value: T): void;
|
|
110
|
+
/**
|
|
111
|
+
* A saved state for tests to start from, in place of the app's freshly
|
|
112
|
+
* provisioned one: the rows a setup inserted, say. Declare one with
|
|
113
|
+
* {@link fixture}.
|
|
114
|
+
*/
|
|
115
|
+
export interface Fixture {
|
|
116
|
+
/** The fixture's name, which identifies it across the app's test files. */
|
|
117
|
+
readonly name: string;
|
|
118
|
+
/** The fixture it extends: its setup starts from what that one saved. */
|
|
119
|
+
readonly parent?: Fixture;
|
|
120
|
+
/**
|
|
121
|
+
* Makes the current test start from the fixture, building it first if no
|
|
122
|
+
* test of the run has yet. Call it before the test first uses a resource:
|
|
123
|
+
* a test that has used one already cannot change what it started from.
|
|
124
|
+
*/
|
|
125
|
+
load(): Promise<void>;
|
|
126
|
+
}
|
|
127
|
+
/** The options of {@link fixture}. */
|
|
128
|
+
export interface FixtureOptions {
|
|
129
|
+
/** A fixture to build on: the setup starts from what it saved. */
|
|
130
|
+
extends?: Fixture;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Declares a fixture: a state `setup` leaves the app's resources in,
|
|
134
|
+
* built once per test run and copied for each test that starts from it.
|
|
135
|
+
*
|
|
136
|
+
* const seeded = fixture("users.seeded", async () => {
|
|
137
|
+
* await db.exec`INSERT INTO users (name) VALUES ('ada'), ('grace')`;
|
|
138
|
+
* });
|
|
139
|
+
* useFixture(seeded);
|
|
140
|
+
*
|
|
141
|
+
* The setup is ordinary app code: its resources are the fixture's while it
|
|
142
|
+
* runs. It runs the first time a test loads the fixture, however many test
|
|
143
|
+
* files and workers load it. What it leaves in each database, bucket and
|
|
144
|
+
* Redis database it touched is saved; each test that loads the fixture gets
|
|
145
|
+
* a copy of its own. Other kinds of resource start each test from their
|
|
146
|
+
* initial state.
|
|
147
|
+
*
|
|
148
|
+
* The name identifies the fixture across the app's test files: two fixtures
|
|
149
|
+
* of one name are one fixture, built by whichever is loaded first.
|
|
150
|
+
*/
|
|
151
|
+
export declare function fixture(name: string, setup: () => Promise<void> | void, options?: FixtureOptions): Fixture;
|
|
152
|
+
/**
|
|
153
|
+
* Makes `f` what every test after this call in the file — or, called in a
|
|
154
|
+
* `describe` block, in the block — starts from; `null` for the resources'
|
|
155
|
+
* initial state. A {@link scoped} test starts from it too, unless told
|
|
156
|
+
* otherwise. Needs the runner adapter (or {@link setup}), whose hooks it
|
|
157
|
+
* adds to. Outside test mode it does nothing.
|
|
158
|
+
*/
|
|
159
|
+
export declare function useFixture(f: Fixture | null): void;
|
|
160
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../testing/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAe,KAAK,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,EAAC,YAAY,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAWL,KAAK,KAAK,EACX,MAAM,2BAA2B,CAAC;AAEnC,YAAY,EAAC,KAAK,EAAC,MAAM,2BAA2B,CAAC;AAErD,uDAAuD;AACvD,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC1B;AAKD;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,CAOhE;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAC3C,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAClC,OAAO,CAAC,EAAE,YAAY,GACrB,CAAC,GAAG,IAAI,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
|
1
|
+
import { setTestValue } from '../config/config.js';
|
|
2
|
+
import { Subscription } from '../pubsub/subscription.js';
|
|
3
|
+
import { fromMessageAttributes } from '../internal/reqfields.js';
|
|
4
|
+
import { begin, hookScope, isContext, requireScope, requireScopes, runIn, Scope, setupHooks, testMode, testName, } from '../internal/testing/scope.js';
|
|
5
|
+
/** The hooks {@link setup} was given, for {@link useFixture}. */
|
|
6
|
+
let registered;
|
|
7
|
+
/**
|
|
8
|
+
* Registers per-test infrastructure with a runner's hooks: each test begins
|
|
9
|
+
* with resources of its own, released after it. The per-runner entry points
|
|
10
|
+
* (`@encore.dev/sdk/testing/vitest` and the others) call this for you.
|
|
11
|
+
*
|
|
12
|
+
* Once it has, a resource used outside any test — in a `beforeAll`, or at
|
|
13
|
+
* module level — throws: no test would see what it does. Set up what each
|
|
14
|
+
* test needs in `beforeEach`, or in a {@link fixture}.
|
|
15
|
+
*
|
|
16
|
+
* Outside test mode it registers nothing, so a test file still runs.
|
|
17
|
+
*/
|
|
18
|
+
export function setup(hooks, options) {
|
|
19
|
+
registered = hooks;
|
|
20
|
+
const fixture = options?.fixture;
|
|
21
|
+
setupHooks(hooks, fixture === undefined ? undefined : scope => choose(scope, fixture));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Wraps a test body to run in a scope of its own: for concurrent tests,
|
|
25
|
+
* which the runner's hooks cannot tell apart, or a runner without hooks.
|
|
26
|
+
*
|
|
27
|
+
* test.concurrent("x", scoped(async () => { ... }));
|
|
28
|
+
*
|
|
29
|
+
* The test starts from `options.fixture` if given, else from the fixture
|
|
30
|
+
* {@link useFixture} chose for it, where the runner hands the test its
|
|
31
|
+
* context (vitest, node:test). Outside test mode it runs `fn` as it is.
|
|
32
|
+
*/
|
|
33
|
+
export function scoped(fn, options) {
|
|
34
|
+
// No parameters by name: jest and bun pass a test with parameters a
|
|
35
|
+
// `done` callback to call.
|
|
36
|
+
return async (...args) => {
|
|
37
|
+
const scope = begin(testName(args[0]));
|
|
38
|
+
if (scope === null)
|
|
39
|
+
return fn(...args);
|
|
40
|
+
try {
|
|
41
|
+
return await runIn(scope, async () => {
|
|
42
|
+
const fixture = options?.fixture !== undefined ? options.fixture : chosen(args[0]);
|
|
43
|
+
if (fixture !== undefined)
|
|
44
|
+
await choose(scope, fixture);
|
|
45
|
+
return fn(...args);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
scope.end();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* What the current test has published to `topic`, in the order it was
|
|
55
|
+
* published: by the test itself, and by the code it called. Nothing handles
|
|
56
|
+
* it otherwise: hand it to a subscription with {@link deliver}.
|
|
57
|
+
*
|
|
58
|
+
* Each message's `data` is what was published: decoded from JSON, or the
|
|
59
|
+
* bytes published as bytes.
|
|
60
|
+
*/
|
|
61
|
+
export function published(topic) {
|
|
62
|
+
const scope = requireScope();
|
|
63
|
+
return scope.native.published(topic.name).map(msg => ({
|
|
64
|
+
data: (scope.raw.has(msg.id)
|
|
65
|
+
? msg.data
|
|
66
|
+
: JSON.parse(msg.data.toString('utf8'))),
|
|
67
|
+
rawData: msg.data,
|
|
68
|
+
id: msg.id,
|
|
69
|
+
attributes: fromMessageAttributes(msg.attributes).rest,
|
|
70
|
+
deliveryAttempt: 1,
|
|
71
|
+
publishTime: new Date(msg.publishTime),
|
|
72
|
+
orderingKey: msg.orderingKey ?? null,
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Runs `subscription`'s handler on each message the current test — or the
|
|
77
|
+
* code it called — published to its topic that the subscription has not
|
|
78
|
+
* handled yet, one at a time, in the order they were published, as part of
|
|
79
|
+
* the test. Resolves to how many it handled.
|
|
80
|
+
*
|
|
81
|
+
* As in a real delivery, the handler gets a message only if the
|
|
82
|
+
* subscription's filter matches it, decoded as the subscription says, with
|
|
83
|
+
* the Request Context fields it was published with, and `deliveryAttempt` 1
|
|
84
|
+
* the first time. What the handler publishes to the topic in turn is handed
|
|
85
|
+
* over in the same call.
|
|
86
|
+
*
|
|
87
|
+
* It stops at the first message the handler fails, and rejects with its
|
|
88
|
+
* error. That message stays unhandled: the next call hands it over again,
|
|
89
|
+
* its `deliveryAttempt` one more. Retry policies, ack deadlines and dead
|
|
90
|
+
* letters play no part.
|
|
91
|
+
*/
|
|
92
|
+
export async function deliver(subscription) {
|
|
93
|
+
const scope = requireScope();
|
|
94
|
+
return Subscription.deliverIn(subscription, scope, requireScopes().maxDeliveries);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Gives `secret` a value for the current test, in place of the app's. No
|
|
98
|
+
* other test sees it, and it is gone when the test ends.
|
|
99
|
+
*/
|
|
100
|
+
export function setSecret(secret, value) {
|
|
101
|
+
requireScope().native.setSecret(secret.name, Buffer.from(value));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Gives `config` a value for the current test, in place of the app's: what
|
|
105
|
+
* calling the config returns in the test from then on. No other test sees
|
|
106
|
+
* it, and it is gone when the test ends. Throws if the value does not
|
|
107
|
+
* satisfy the config's schema.
|
|
108
|
+
*/
|
|
109
|
+
export function setConfig(config, value) {
|
|
110
|
+
setTestValue(requireScope(), config, value);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Declares a fixture: a state `setup` leaves the app's resources in,
|
|
114
|
+
* built once per test run and copied for each test that starts from it.
|
|
115
|
+
*
|
|
116
|
+
* const seeded = fixture("users.seeded", async () => {
|
|
117
|
+
* await db.exec`INSERT INTO users (name) VALUES ('ada'), ('grace')`;
|
|
118
|
+
* });
|
|
119
|
+
* useFixture(seeded);
|
|
120
|
+
*
|
|
121
|
+
* The setup is ordinary app code: its resources are the fixture's while it
|
|
122
|
+
* runs. It runs the first time a test loads the fixture, however many test
|
|
123
|
+
* files and workers load it. What it leaves in each database, bucket and
|
|
124
|
+
* Redis database it touched is saved; each test that loads the fixture gets
|
|
125
|
+
* a copy of its own. Other kinds of resource start each test from their
|
|
126
|
+
* initial state.
|
|
127
|
+
*
|
|
128
|
+
* The name identifies the fixture across the app's test files: two fixtures
|
|
129
|
+
* of one name are one fixture, built by whichever is loaded first.
|
|
130
|
+
*/
|
|
131
|
+
export function fixture(name, setup, options) {
|
|
132
|
+
const f = {
|
|
133
|
+
name,
|
|
134
|
+
parent: options?.extends,
|
|
135
|
+
load: () => load(f, requireScope()),
|
|
136
|
+
};
|
|
137
|
+
setups.set(f, setup);
|
|
138
|
+
return f;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Makes `f` what every test after this call in the file — or, called in a
|
|
142
|
+
* `describe` block, in the block — starts from; `null` for the resources'
|
|
143
|
+
* initial state. A {@link scoped} test starts from it too, unless told
|
|
144
|
+
* otherwise. Needs the runner adapter (or {@link setup}), whose hooks it
|
|
145
|
+
* adds to. Outside test mode it does nothing.
|
|
146
|
+
*/
|
|
147
|
+
export function useFixture(f) {
|
|
148
|
+
if (!testMode)
|
|
149
|
+
return;
|
|
150
|
+
if (registered === undefined) {
|
|
151
|
+
throw new Error('useFixture needs the runner adapter for your test runner, such as ' +
|
|
152
|
+
"@encore.dev/sdk/testing/vitest in vitest's setupFiles");
|
|
153
|
+
}
|
|
154
|
+
registered.beforeEach((...args) => {
|
|
155
|
+
const ctx = args[0];
|
|
156
|
+
if (isContext(ctx))
|
|
157
|
+
chosenFor.set(ctx, f);
|
|
158
|
+
const scope = hookScope(ctx);
|
|
159
|
+
return scope === null ? undefined : choose(scope, f);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/** Each fixture's setup. */
|
|
163
|
+
const setups = new WeakMap();
|
|
164
|
+
/** The fixture `useFixture` chose for the test of a runner's context. */
|
|
165
|
+
const chosenFor = new WeakMap();
|
|
166
|
+
function chosen(ctx) {
|
|
167
|
+
return isContext(ctx) ? chosenFor.get(ctx) : undefined;
|
|
168
|
+
}
|
|
169
|
+
/** Makes `scope`'s test start from `f`, or from nothing for `null`. */
|
|
170
|
+
async function choose(scope, f) {
|
|
171
|
+
if (f === null)
|
|
172
|
+
scope.native.useFixture(null);
|
|
173
|
+
else
|
|
174
|
+
await load(f, scope);
|
|
175
|
+
}
|
|
176
|
+
/** Loads the fixture `f` into `scope`, building it first if need be. */
|
|
177
|
+
async function load(f, scope) {
|
|
178
|
+
await ensureBuilt(f);
|
|
179
|
+
scope.native.useFixture(f.name);
|
|
180
|
+
}
|
|
181
|
+
/** Each fixture's build, as far as this process has asked. */
|
|
182
|
+
const builds = new WeakMap();
|
|
183
|
+
function ensureBuilt(f) {
|
|
184
|
+
let built = builds.get(f);
|
|
185
|
+
if (built === undefined) {
|
|
186
|
+
built = build(f);
|
|
187
|
+
builds.set(f, built);
|
|
188
|
+
}
|
|
189
|
+
return built;
|
|
190
|
+
}
|
|
191
|
+
/** Builds the fixture `f`, unless this process or another has already. */
|
|
192
|
+
async function build(f) {
|
|
193
|
+
if (f.parent !== undefined)
|
|
194
|
+
await ensureBuilt(f.parent);
|
|
195
|
+
const scopes = requireScopes();
|
|
196
|
+
const failed = (reason, cause) => new Error(`cannot load the fixture ${JSON.stringify(f.name)}: ${reason}`, {
|
|
197
|
+
cause,
|
|
198
|
+
});
|
|
199
|
+
let native;
|
|
200
|
+
try {
|
|
201
|
+
native = await scopes.acquireFixture(f.name, f.parent?.name ?? null);
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
throw failed(err.message, err);
|
|
205
|
+
}
|
|
206
|
+
if (native === null)
|
|
207
|
+
return;
|
|
208
|
+
// The setup runs in a scope of its own, starting from the parent.
|
|
209
|
+
const scope = new Scope(native, `fixture ${JSON.stringify(f.name)}`);
|
|
210
|
+
try {
|
|
211
|
+
await runIn(scope, async () => setups.get(f)());
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
const error = failed(`its setup failed: ${err instanceof Error ? err.message : String(err)}`, err);
|
|
215
|
+
scopes.failFixture(f.name, error.message);
|
|
216
|
+
scope.end();
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
219
|
+
// The resources become the fixture's: saved, not released.
|
|
220
|
+
try {
|
|
221
|
+
await native.saveFixture(f.name);
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
throw failed(err.message, err);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=mod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../testing/mod.ts"],"names":[],"mappings":"AAiCA,OAAO,EAAC,YAAY,EAAc,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAC,qBAAqB,EAAC,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,KAAK,EACL,SAAS,EACT,SAAS,EACT,YAAY,EACZ,aAAa,EACb,KAAK,EACL,KAAK,EACL,UAAU,EACV,QAAQ,EACR,QAAQ,GAET,MAAM,2BAA2B,CAAC;AAanC,iEAAiE;AACjE,IAAI,UAA6B,CAAC;AAElC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,KAAK,CAAC,KAAY,EAAE,OAAsB;IACxD,UAAU,GAAG,KAAK,CAAC;IACnB,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,CAAC;IACjC,UAAU,CACR,KAAK,EACL,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CACpE,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,MAAM,CACpB,EAAkC,EAClC,OAAsB;IAEtB,oEAAoE;IACpE,2BAA2B;IAC3B,OAAO,KAAK,EAAE,GAAG,IAAO,EAAc,EAAE;QACtC,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAA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