@encore.dev/sdk 2.0.0-beta.6 → 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
|
@@ -32,6 +32,12 @@ import {
|
|
|
32
32
|
type StreamMaxlen,
|
|
33
33
|
type Unit,
|
|
34
34
|
} from './options';
|
|
35
|
+
import {
|
|
36
|
+
Bitfield,
|
|
37
|
+
BitfieldRo,
|
|
38
|
+
QueuedBitfield,
|
|
39
|
+
QueuedBitfieldRo,
|
|
40
|
+
} from './bitfield';
|
|
35
41
|
import {as, Reply, ReplyPromise} from './reply';
|
|
36
42
|
import {scanFields, scanKeys, scanMembers, scanScored} from './scan';
|
|
37
43
|
import {subscribe, type Subscription} from './pubsub';
|
|
@@ -41,13 +47,35 @@ import {Cmd, type Pairs, type RedisArg, type Value} from './wire';
|
|
|
41
47
|
/** A score bound: a number, `"-inf"` or `"+inf"`, or exclusive as `"(1.5"`. */
|
|
42
48
|
export type ScoreBound = number | string;
|
|
43
49
|
|
|
44
|
-
/**
|
|
45
|
-
|
|
50
|
+
/**
|
|
51
|
+
* A command: whether it writes, whether it blocks, how it is built, and what
|
|
52
|
+
* its reply is read as. A command that blocks waits for something to pop, on
|
|
53
|
+
* a connection of its own, and has no queued form: it would hold up the
|
|
54
|
+
* batch's connection.
|
|
55
|
+
*/
|
|
56
|
+
interface CommandDef<
|
|
57
|
+
A extends unknown[],
|
|
58
|
+
R,
|
|
59
|
+
W extends boolean,
|
|
60
|
+
B extends boolean = boolean,
|
|
61
|
+
> {
|
|
46
62
|
readonly write: W;
|
|
63
|
+
readonly blocking: B;
|
|
47
64
|
readonly build: (...args: A) => Cmd;
|
|
48
65
|
readonly reply: (v: Value) => R;
|
|
49
66
|
}
|
|
50
67
|
|
|
68
|
+
/**
|
|
69
|
+
* A command built up by the caller before it runs, `bitfield`'s: what `start`
|
|
70
|
+
* makes of it to run now, and what `queued` makes of it to queue.
|
|
71
|
+
*/
|
|
72
|
+
interface BuilderDef<A extends unknown[], R, Q, W extends boolean> {
|
|
73
|
+
readonly write: W;
|
|
74
|
+
readonly build: (...args: A) => Cmd;
|
|
75
|
+
readonly start: (t: Target, c: Cmd) => R;
|
|
76
|
+
readonly queued: (queue: Cmd[], c: Cmd) => Q;
|
|
77
|
+
}
|
|
78
|
+
|
|
51
79
|
/**
|
|
52
80
|
* What runs now and is no command of its own to queue: a scan, which returns
|
|
53
81
|
* an iteration, and a subscription.
|
|
@@ -61,16 +89,50 @@ interface RunDef<A extends unknown[], R, W extends boolean> {
|
|
|
61
89
|
function read<A extends unknown[], R>(
|
|
62
90
|
build: (...args: A) => Cmd,
|
|
63
91
|
reply: (v: Value) => R,
|
|
64
|
-
): CommandDef<A, R, false> {
|
|
65
|
-
return {write: false, build, reply};
|
|
92
|
+
): CommandDef<A, R, false, false> {
|
|
93
|
+
return {write: false, blocking: false, build, reply};
|
|
66
94
|
}
|
|
67
95
|
|
|
68
96
|
/** A command that writes. */
|
|
69
97
|
function write<A extends unknown[], R>(
|
|
70
98
|
build: (...args: A) => Cmd,
|
|
71
99
|
reply: (v: Value) => R,
|
|
72
|
-
): CommandDef<A, R, true> {
|
|
73
|
-
return {write: true, build, reply};
|
|
100
|
+
): CommandDef<A, R, true, false> {
|
|
101
|
+
return {write: true, blocking: false, build, reply};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** A command that only reads, and blocks. */
|
|
105
|
+
function readBlocking<A extends unknown[], R>(
|
|
106
|
+
build: (...args: A) => Cmd,
|
|
107
|
+
reply: (v: Value) => R,
|
|
108
|
+
): CommandDef<A, R, false, true> {
|
|
109
|
+
return {write: false, blocking: true, build, reply};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** A command that writes, and blocks. */
|
|
113
|
+
function writeBlocking<A extends unknown[], R>(
|
|
114
|
+
build: (...args: A) => Cmd,
|
|
115
|
+
reply: (v: Value) => R,
|
|
116
|
+
): CommandDef<A, R, true, true> {
|
|
117
|
+
return {write: true, blocking: true, build, reply};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** A command built up by the caller that only reads. */
|
|
121
|
+
function readBuilder<A extends unknown[], R, Q>(
|
|
122
|
+
build: (...args: A) => Cmd,
|
|
123
|
+
start: (t: Target, c: Cmd) => R,
|
|
124
|
+
queued: (queue: Cmd[], c: Cmd) => Q,
|
|
125
|
+
): BuilderDef<A, R, Q, false> {
|
|
126
|
+
return {write: false, build, start, queued};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A command built up by the caller that writes. */
|
|
130
|
+
function writeBuilder<A extends unknown[], R, Q>(
|
|
131
|
+
build: (...args: A) => Cmd,
|
|
132
|
+
start: (t: Target, c: Cmd) => R,
|
|
133
|
+
queued: (queue: Cmd[], c: Cmd) => Q,
|
|
134
|
+
): BuilderDef<A, R, Q, true> {
|
|
135
|
+
return {write: true, build, start, queued};
|
|
74
136
|
}
|
|
75
137
|
|
|
76
138
|
/** What runs now and only reads. */
|
|
@@ -91,6 +153,10 @@ function cmd(name: string): Cmd {
|
|
|
91
153
|
/** A bit as Redis takes one. */
|
|
92
154
|
const bitArg = (b: boolean) => (b ? 1 : 0);
|
|
93
155
|
|
|
156
|
+
/** One key, or several. */
|
|
157
|
+
const keyList = (keys: string | string[]): string[] =>
|
|
158
|
+
typeof keys === 'string' ? [keys] : keys;
|
|
159
|
+
|
|
94
160
|
const generic = {
|
|
95
161
|
/** Whether the key exists. */
|
|
96
162
|
exists: read((key: string) => cmd('EXISTS').key(key), as.bool),
|
|
@@ -327,6 +393,21 @@ const bitmap = {
|
|
|
327
393
|
cmd('BITOP').arg('NOT').key(destination).key(source),
|
|
328
394
|
as.number,
|
|
329
395
|
),
|
|
396
|
+
/**
|
|
397
|
+
* Integers of any width up to 64 bits, read and written at any bit offset of
|
|
398
|
+
* the string: add the operations, then {@link Bitfield.invoke}.
|
|
399
|
+
*/
|
|
400
|
+
bitfield: writeBuilder(
|
|
401
|
+
(key: string) => cmd('BITFIELD').key(key),
|
|
402
|
+
(t, c) => new Bitfield(t, c),
|
|
403
|
+
(queue, c) => new QueuedBitfield(queue, c),
|
|
404
|
+
),
|
|
405
|
+
/** {@link Bitfield} that only reads (`BITFIELD_RO`). */
|
|
406
|
+
bitfieldRo: readBuilder(
|
|
407
|
+
(key: string) => cmd('BITFIELD_RO').key(key),
|
|
408
|
+
(t, c) => new BitfieldRo(t, c),
|
|
409
|
+
(queue, c) => new QueuedBitfieldRo(queue, c),
|
|
410
|
+
),
|
|
330
411
|
};
|
|
331
412
|
|
|
332
413
|
const hash = {
|
|
@@ -521,6 +602,58 @@ const list = {
|
|
|
521
602
|
.arg(directionArg(to)),
|
|
522
603
|
as.reply,
|
|
523
604
|
),
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Removes and returns the first element of the first of `keys` that has
|
|
608
|
+
* one, with its key, waiting up to `timeout` seconds for one to be pushed:
|
|
609
|
+
* 0 waits for ever. `null` once the timeout passes.
|
|
610
|
+
*/
|
|
611
|
+
blpop: writeBlocking(
|
|
612
|
+
(keys: string | string[], timeout: number) =>
|
|
613
|
+
cmd('BLPOP').keys(keyList(keys)).arg(timeout),
|
|
614
|
+
as.popped,
|
|
615
|
+
),
|
|
616
|
+
/** {@link ListCommands.blpop}, from the end of the list. */
|
|
617
|
+
brpop: writeBlocking(
|
|
618
|
+
(keys: string | string[], timeout: number) =>
|
|
619
|
+
cmd('BRPOP').keys(keyList(keys)).arg(timeout),
|
|
620
|
+
as.popped,
|
|
621
|
+
),
|
|
622
|
+
/**
|
|
623
|
+
* {@link ListCommands.lmove}, waiting up to `timeout` seconds for `source`
|
|
624
|
+
* to have an element: 0 waits for ever. A nil reply once the timeout passes.
|
|
625
|
+
*/
|
|
626
|
+
blmove: writeBlocking(
|
|
627
|
+
(
|
|
628
|
+
source: string,
|
|
629
|
+
destination: string,
|
|
630
|
+
from: Direction,
|
|
631
|
+
to: Direction,
|
|
632
|
+
timeout: number,
|
|
633
|
+
) =>
|
|
634
|
+
cmd('BLMOVE')
|
|
635
|
+
.key(source)
|
|
636
|
+
.key(destination)
|
|
637
|
+
.arg(directionArg(from))
|
|
638
|
+
.arg(directionArg(to))
|
|
639
|
+
.arg(timeout),
|
|
640
|
+
as.reply,
|
|
641
|
+
),
|
|
642
|
+
/**
|
|
643
|
+
* Removes and returns up to `count` elements from one end of the first of
|
|
644
|
+
* `keys` that has any, with its key, waiting up to `timeout` seconds for
|
|
645
|
+
* one: 0 waits for ever. `null` once the timeout passes.
|
|
646
|
+
*/
|
|
647
|
+
blmpop: writeBlocking(
|
|
648
|
+
(keys: string[], from: Direction, count: number, timeout: number) =>
|
|
649
|
+
cmd('BLMPOP')
|
|
650
|
+
.arg(timeout)
|
|
651
|
+
.numkeys(keys)
|
|
652
|
+
.arg(directionArg(from))
|
|
653
|
+
.arg('COUNT')
|
|
654
|
+
.arg(count),
|
|
655
|
+
as.poppedMany,
|
|
656
|
+
),
|
|
524
657
|
};
|
|
525
658
|
|
|
526
659
|
const set = {
|
|
@@ -762,6 +895,39 @@ const sortedSet = {
|
|
|
762
895
|
cmd('ZUNIONSTORE').key(destination).numkeys(keys),
|
|
763
896
|
as.number,
|
|
764
897
|
),
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* Removes and returns the lowest scored member of the first of `keys` that
|
|
901
|
+
* has one, with its key and score, waiting up to `timeout` seconds for one
|
|
902
|
+
* to be added: 0 waits for ever. `null` once the timeout passes.
|
|
903
|
+
*/
|
|
904
|
+
bzpopmin: writeBlocking(
|
|
905
|
+
(keys: string | string[], timeout: number) =>
|
|
906
|
+
cmd('BZPOPMIN').keys(keyList(keys)).arg(timeout),
|
|
907
|
+
as.poppedScored,
|
|
908
|
+
),
|
|
909
|
+
/** {@link SortedSetCommands.bzpopmin}, the highest scored member. */
|
|
910
|
+
bzpopmax: writeBlocking(
|
|
911
|
+
(keys: string | string[], timeout: number) =>
|
|
912
|
+
cmd('BZPOPMAX').keys(keyList(keys)).arg(timeout),
|
|
913
|
+
as.poppedScored,
|
|
914
|
+
),
|
|
915
|
+
/**
|
|
916
|
+
* Removes and returns up to `count` of the lowest (`'min'`) or highest
|
|
917
|
+
* (`'max'`) scored members of the first of `keys` that has any, with its
|
|
918
|
+
* key and their scores, waiting up to `timeout` seconds for one: 0 waits
|
|
919
|
+
* for ever. `null` once the timeout passes.
|
|
920
|
+
*/
|
|
921
|
+
bzmpop: writeBlocking(
|
|
922
|
+
(keys: string[], which: 'min' | 'max', count: number, timeout: number) =>
|
|
923
|
+
cmd('BZMPOP')
|
|
924
|
+
.arg(timeout)
|
|
925
|
+
.numkeys(keys)
|
|
926
|
+
.arg(which === 'max' ? 'MAX' : 'MIN')
|
|
927
|
+
.arg('COUNT')
|
|
928
|
+
.arg(count),
|
|
929
|
+
as.poppedScoredMany,
|
|
930
|
+
),
|
|
765
931
|
};
|
|
766
932
|
|
|
767
933
|
const geo = {
|
|
@@ -875,7 +1041,7 @@ const stream = {
|
|
|
875
1041
|
*/
|
|
876
1042
|
xread: read(
|
|
877
1043
|
(keys: string[], ids: string[]) =>
|
|
878
|
-
cmd('XREAD').arg('STREAMS').keys(keys).argsOf(ids)
|
|
1044
|
+
cmd('XREAD').arg('STREAMS').keys(keys).argsOf(ids),
|
|
879
1045
|
as.reply,
|
|
880
1046
|
),
|
|
881
1047
|
/**
|
|
@@ -966,8 +1132,7 @@ const stream = {
|
|
|
966
1132
|
.argsOf(count === undefined ? [] : ['COUNT', count])
|
|
967
1133
|
.arg('STREAMS')
|
|
968
1134
|
.keys(keys)
|
|
969
|
-
.argsOf(ids)
|
|
970
|
-
.withReplyKeys(),
|
|
1135
|
+
.argsOf(ids),
|
|
971
1136
|
as.reply,
|
|
972
1137
|
),
|
|
973
1138
|
/**
|
|
@@ -1019,6 +1184,70 @@ const stream = {
|
|
|
1019
1184
|
.arg(start),
|
|
1020
1185
|
as.reply,
|
|
1021
1186
|
),
|
|
1187
|
+
|
|
1188
|
+
/**
|
|
1189
|
+
* {@link StreamCommands.xread}, waiting up to `blockMs` milliseconds for an
|
|
1190
|
+
* entry if there is none yet: 0 waits for ever. With a `count`, at most that
|
|
1191
|
+
* many per stream. A nil reply once the wait passes.
|
|
1192
|
+
*/
|
|
1193
|
+
xreadBlock: readBlocking(
|
|
1194
|
+
(keys: string[], ids: string[], blockMs: number, count?: number) =>
|
|
1195
|
+
cmd('XREAD')
|
|
1196
|
+
.argsOf(count === undefined ? [] : ['COUNT', count])
|
|
1197
|
+
.arg('BLOCK')
|
|
1198
|
+
.arg(blockMs)
|
|
1199
|
+
.arg('STREAMS')
|
|
1200
|
+
.keys(keys)
|
|
1201
|
+
.argsOf(ids),
|
|
1202
|
+
as.reply,
|
|
1203
|
+
),
|
|
1204
|
+
/**
|
|
1205
|
+
* {@link StreamCommands.xreadGroup}, waiting up to `blockMs` milliseconds
|
|
1206
|
+
* for an entry if there is none yet: 0 waits for ever. A nil reply once the
|
|
1207
|
+
* wait passes.
|
|
1208
|
+
*/
|
|
1209
|
+
xreadGroupBlock: writeBlocking(
|
|
1210
|
+
(
|
|
1211
|
+
group: string,
|
|
1212
|
+
consumer: string,
|
|
1213
|
+
keys: string[],
|
|
1214
|
+
ids: string[],
|
|
1215
|
+
blockMs: number,
|
|
1216
|
+
count?: number,
|
|
1217
|
+
) =>
|
|
1218
|
+
cmd('XREADGROUP')
|
|
1219
|
+
.arg('GROUP')
|
|
1220
|
+
.arg(group)
|
|
1221
|
+
.arg(consumer)
|
|
1222
|
+
.argsOf(count === undefined ? [] : ['COUNT', count])
|
|
1223
|
+
.arg('BLOCK')
|
|
1224
|
+
.arg(blockMs)
|
|
1225
|
+
.arg('STREAMS')
|
|
1226
|
+
.keys(keys)
|
|
1227
|
+
.argsOf(ids),
|
|
1228
|
+
as.reply,
|
|
1229
|
+
),
|
|
1230
|
+
};
|
|
1231
|
+
|
|
1232
|
+
const hyperloglog = {
|
|
1233
|
+
/**
|
|
1234
|
+
* The estimated number of distinct elements added to the keys, counted as
|
|
1235
|
+
* their union.
|
|
1236
|
+
*/
|
|
1237
|
+
pfcount: read((...keys: string[]) => cmd('PFCOUNT').keys(keys), as.number),
|
|
1238
|
+
|
|
1239
|
+
/** Adds the elements, returning whether the estimate changed. */
|
|
1240
|
+
pfadd: write(
|
|
1241
|
+
(key: string, ...elements: RedisArg[]) =>
|
|
1242
|
+
cmd('PFADD').key(key).argsOf(elements),
|
|
1243
|
+
as.bool,
|
|
1244
|
+
),
|
|
1245
|
+
/** Stores at `destination` the union of itself and the sources. */
|
|
1246
|
+
pfmerge: write(
|
|
1247
|
+
(destination: string, ...sources: string[]) =>
|
|
1248
|
+
cmd('PFMERGE').key(destination).keys(sources),
|
|
1249
|
+
as.none,
|
|
1250
|
+
),
|
|
1022
1251
|
};
|
|
1023
1252
|
|
|
1024
1253
|
const pubsub = {
|
|
@@ -1059,6 +1288,7 @@ const groups = {
|
|
|
1059
1288
|
sortedSet,
|
|
1060
1289
|
geo,
|
|
1061
1290
|
stream,
|
|
1291
|
+
hyperloglog,
|
|
1062
1292
|
pubsub,
|
|
1063
1293
|
};
|
|
1064
1294
|
|
|
@@ -1066,11 +1296,13 @@ type Groups = typeof groups;
|
|
|
1066
1296
|
|
|
1067
1297
|
/** A command run now: a reply for the caller to read, or one of one shape. */
|
|
1068
1298
|
type RunForm<D> =
|
|
1069
|
-
D extends
|
|
1070
|
-
? (...args: A) => R
|
|
1071
|
-
: D extends
|
|
1072
|
-
? (...args: A) => R
|
|
1073
|
-
:
|
|
1299
|
+
D extends BuilderDef<infer A, infer R, any, boolean>
|
|
1300
|
+
? (...args: A) => R
|
|
1301
|
+
: D extends CommandDef<infer A, infer R, boolean>
|
|
1302
|
+
? (...args: A) => R extends Reply ? ReplyPromise : Promise<R>
|
|
1303
|
+
: D extends RunDef<infer A, infer R, boolean>
|
|
1304
|
+
? (...args: A) => R
|
|
1305
|
+
: never;
|
|
1074
1306
|
|
|
1075
1307
|
/** A command group's commands, run as they are called. */
|
|
1076
1308
|
export type Commands<G> = {readonly [K in keyof G]: RunForm<G[K]>};
|
|
@@ -1088,10 +1320,15 @@ export type ReadCommands<G> = {
|
|
|
1088
1320
|
*/
|
|
1089
1321
|
export type Queue<G> = {
|
|
1090
1322
|
readonly [
|
|
1091
|
-
K in keyof G as G[K] extends
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1323
|
+
K in keyof G as G[K] extends
|
|
1324
|
+
BuilderDef<any, any, any, boolean> | CommandDef<any, any, boolean, false>
|
|
1325
|
+
? K
|
|
1326
|
+
: never
|
|
1327
|
+
]: G[K] extends BuilderDef<infer A, any, infer Q, boolean>
|
|
1328
|
+
? (...args: A) => Q
|
|
1329
|
+
: G[K] extends CommandDef<infer A, any, boolean>
|
|
1330
|
+
? (...args: A) => Queue<G>
|
|
1331
|
+
: never;
|
|
1095
1332
|
};
|
|
1096
1333
|
|
|
1097
1334
|
/** Commands that work on a key of any type: expiry, deletion, renaming. */
|
|
@@ -1112,6 +1349,8 @@ export type SortedSetCommands = Commands<Groups['sortedSet']>;
|
|
|
1112
1349
|
export type GeoCommands = Commands<Groups['geo']>;
|
|
1113
1350
|
/** Commands on streams. */
|
|
1114
1351
|
export type StreamCommands = Commands<Groups['stream']>;
|
|
1352
|
+
/** Commands on HyperLogLogs: estimates of how many distinct elements were added. */
|
|
1353
|
+
export type HyperLogLogCommands = Commands<Groups['hyperloglog']>;
|
|
1115
1354
|
/** Publishing to channels, and subscribing to them. */
|
|
1116
1355
|
export type PubsubCommands = Commands<Groups['pubsub']>;
|
|
1117
1356
|
|
|
@@ -1131,18 +1370,20 @@ function operation(name: string): string {
|
|
|
1131
1370
|
return name.replace(/[A-Z]/g, c => `_${c.toLowerCase()}`);
|
|
1132
1371
|
}
|
|
1133
1372
|
|
|
1134
|
-
type AnyDef =
|
|
1373
|
+
type AnyDef =
|
|
1374
|
+
| CommandDef<any[], any, boolean>
|
|
1375
|
+
| BuilderDef<any[], any, any, boolean>
|
|
1376
|
+
| RunDef<any[], any, boolean>;
|
|
1135
1377
|
|
|
1136
1378
|
/** The command `def` builds from `args`, named and marked as it is. */
|
|
1137
1379
|
function built(
|
|
1138
1380
|
op: string,
|
|
1139
|
-
def: CommandDef<any[], any, boolean>,
|
|
1381
|
+
def: CommandDef<any[], any, boolean> | BuilderDef<any[], any, any, boolean>,
|
|
1140
1382
|
args: unknown[],
|
|
1141
1383
|
): Cmd {
|
|
1142
1384
|
const c = def.build(...args);
|
|
1143
1385
|
const out = new Cmd(op, c.name, def.write);
|
|
1144
1386
|
out.args.push(...c.args);
|
|
1145
|
-
out.replyKeys = c.replyKeys;
|
|
1146
1387
|
return out;
|
|
1147
1388
|
}
|
|
1148
1389
|
|
|
@@ -1163,6 +1404,10 @@ function runForms(t: Target, readOnly: boolean) {
|
|
|
1163
1404
|
continue;
|
|
1164
1405
|
}
|
|
1165
1406
|
const op = operation(name);
|
|
1407
|
+
if ('start' in def) {
|
|
1408
|
+
forms[name] = (...args) => def.start(t, built(op, def, args));
|
|
1409
|
+
continue;
|
|
1410
|
+
}
|
|
1166
1411
|
if (def.reply === as.reply) {
|
|
1167
1412
|
// Any error, the command's or that of sending it, is the reply's to
|
|
1168
1413
|
// report when read.
|
|
@@ -1210,6 +1455,11 @@ export function queueGroups(queue: Cmd[]): QueueGroups {
|
|
|
1210
1455
|
for (const [name, def] of Object.entries(group)) {
|
|
1211
1456
|
if (!('build' in def)) continue;
|
|
1212
1457
|
const op = operation(name);
|
|
1458
|
+
if ('queued' in def) {
|
|
1459
|
+
forms[name] = (...args) => def.queued(queue, built(op, def, args));
|
|
1460
|
+
continue;
|
|
1461
|
+
}
|
|
1462
|
+
if (def.blocking) continue;
|
|
1213
1463
|
forms[name] = (...args) => {
|
|
1214
1464
|
queue.push(built(op, def, args));
|
|
1215
1465
|
return forms;
|
|
@@ -9,30 +9,16 @@ import {
|
|
|
9
9
|
type QueueGroups,
|
|
10
10
|
type ReadCommandGroups,
|
|
11
11
|
} from './commands';
|
|
12
|
+
import {
|
|
13
|
+
CommandInvocation,
|
|
14
|
+
QueuedCommandInvocation,
|
|
15
|
+
rawCommand,
|
|
16
|
+
} from './command';
|
|
12
17
|
import {BatchError, Reply} from './reply';
|
|
13
18
|
import {Invocation, QueuedInvocation, Script} from './script';
|
|
14
19
|
import {ConnTarget, PoolTarget, type Target} from './target';
|
|
15
20
|
import {encodeList, type Cmd, type Value} from './wire';
|
|
16
21
|
|
|
17
|
-
/** What a database evicts when it runs out of memory. */
|
|
18
|
-
export type EvictionPolicy =
|
|
19
|
-
/** Evict nothing: a write that needs memory fails. */
|
|
20
|
-
| 'noeviction'
|
|
21
|
-
/** The least recently used key, of all keys. */
|
|
22
|
-
| 'allkeys-lru'
|
|
23
|
-
/** The least frequently used key, of all keys. */
|
|
24
|
-
| 'allkeys-lfu'
|
|
25
|
-
/** A random key, of all keys. */
|
|
26
|
-
| 'allkeys-random'
|
|
27
|
-
/** The least recently used key, of those with an expiry. */
|
|
28
|
-
| 'volatile-lru'
|
|
29
|
-
/** The least frequently used key, of those with an expiry. */
|
|
30
|
-
| 'volatile-lfu'
|
|
31
|
-
/** The key closest to expiring. */
|
|
32
|
-
| 'volatile-ttl'
|
|
33
|
-
/** A random key, of those with an expiry. */
|
|
34
|
-
| 'volatile-random';
|
|
35
|
-
|
|
36
22
|
/**
|
|
37
23
|
* A database's configuration. Encore reads it from the declaration, so its
|
|
38
24
|
* fields must be literals.
|
|
@@ -45,11 +31,12 @@ export interface DatabaseConfig {
|
|
|
45
31
|
persistent?: boolean;
|
|
46
32
|
|
|
47
33
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
34
|
+
* Tags that classify the database, for policies to read: written out as
|
|
35
|
+
* string literals, as in `{data: "pci"}`. Keys and values are lowercase
|
|
36
|
+
* letters, digits, `_` and `-`, at most 63 characters; a key starts with a
|
|
37
|
+
* letter, and not with `encore`, which is reserved. At most 32 tags.
|
|
51
38
|
*/
|
|
52
|
-
|
|
39
|
+
tags?: Record<string, string>;
|
|
53
40
|
}
|
|
54
41
|
|
|
55
42
|
/** The replies of a batch, or the error some of its commands failed with. */
|
|
@@ -89,6 +76,15 @@ export class ReadOnlyDatabaseRef {
|
|
|
89
76
|
script(script: Script): Invocation {
|
|
90
77
|
return new Invocation(this.t, script, true);
|
|
91
78
|
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A command the command groups lack, by its name, as
|
|
82
|
+
* {@link DatabaseRef.command} sends one. Only a command Redis says doesn't
|
|
83
|
+
* write is sent.
|
|
84
|
+
*/
|
|
85
|
+
command<N extends string>(name: StringLiteral<N>): CommandInvocation {
|
|
86
|
+
return new CommandInvocation(this.t, rawCommand(name, true));
|
|
87
|
+
}
|
|
92
88
|
}
|
|
93
89
|
|
|
94
90
|
/**
|
|
@@ -197,6 +193,26 @@ export class DatabaseRef {
|
|
|
197
193
|
return new Invocation(this.t, script, false);
|
|
198
194
|
}
|
|
199
195
|
|
|
196
|
+
/**
|
|
197
|
+
* A command the command groups lack, by its name, which must be a string
|
|
198
|
+
* literal: give its arguments in order, marking the keys, then invoke it.
|
|
199
|
+
*
|
|
200
|
+
* ```ts
|
|
201
|
+
* const freq = await SESSIONS.command("OBJECT").arg("FREQ").key("hot").invoke().number();
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* Encore reads the name to grant the access the command needs. Before it is
|
|
205
|
+
* sent, the runtime checks it against Redis's command table, and fails it
|
|
206
|
+
* with a `TypeError` if a key it takes isn't passed with `key`, which gives
|
|
207
|
+
* it the database's prefix, or if it is one that would reach past the
|
|
208
|
+
* database, change a connection other calls share, or has a call of its own
|
|
209
|
+
* here (`MULTI`, `SUBSCRIBE`, `EVAL`, `SCAN`, `FLUSHALL`, …). A command the
|
|
210
|
+
* table doesn't know, such as a module's, is sent with its keys as marked.
|
|
211
|
+
*/
|
|
212
|
+
command<N extends string>(name: StringLiteral<N>): CommandInvocation {
|
|
213
|
+
return new CommandInvocation(this.t, rawCommand(name, false));
|
|
214
|
+
}
|
|
215
|
+
|
|
200
216
|
/**
|
|
201
217
|
* The connection string to connect to this database with, for a client
|
|
202
218
|
* other than this SDK.
|
|
@@ -308,6 +324,16 @@ export class Pipeline {
|
|
|
308
324
|
return new QueuedInvocation(this.queued, script);
|
|
309
325
|
}
|
|
310
326
|
|
|
327
|
+
/**
|
|
328
|
+
* Queues a command the command groups lack, by its name: see
|
|
329
|
+
* {@link DatabaseRef.command}. Finish it with
|
|
330
|
+
* {@link QueuedCommandInvocation.queue}. A command that blocks can't be
|
|
331
|
+
* queued: the batch fails.
|
|
332
|
+
*/
|
|
333
|
+
command<N extends string>(name: StringLiteral<N>): QueuedCommandInvocation {
|
|
334
|
+
return new QueuedCommandInvocation(this.queued, rawCommand(name, false));
|
|
335
|
+
}
|
|
336
|
+
|
|
311
337
|
/**
|
|
312
338
|
* Sends the queued commands and returns their replies, in order. If the
|
|
313
339
|
* server rejected any, fails with a {@link BatchError} holding them all.
|
|
@@ -346,6 +372,16 @@ export class Transaction {
|
|
|
346
372
|
return new QueuedInvocation(this.queued, script);
|
|
347
373
|
}
|
|
348
374
|
|
|
375
|
+
/**
|
|
376
|
+
* Queues a command the command groups lack, by its name: see
|
|
377
|
+
* {@link DatabaseRef.command}. Finish it with
|
|
378
|
+
* {@link QueuedCommandInvocation.queue}. A command that blocks can't be
|
|
379
|
+
* queued: the batch fails.
|
|
380
|
+
*/
|
|
381
|
+
command<N extends string>(name: StringLiteral<N>): QueuedCommandInvocation {
|
|
382
|
+
return new QueuedCommandInvocation(this.queued, rawCommand(name, false));
|
|
383
|
+
}
|
|
384
|
+
|
|
349
385
|
/**
|
|
350
386
|
* Runs the queued commands as one transaction and returns their replies, as
|
|
351
387
|
* {@link Pipeline.exec} does. A command the server rejects when it runs does
|
|
@@ -391,6 +427,16 @@ export class WatchedTransaction {
|
|
|
391
427
|
return new QueuedInvocation(this.queued, script);
|
|
392
428
|
}
|
|
393
429
|
|
|
430
|
+
/**
|
|
431
|
+
* Queues a command the command groups lack, by its name: see
|
|
432
|
+
* {@link DatabaseRef.command}. Finish it with
|
|
433
|
+
* {@link QueuedCommandInvocation.queue}. A command that blocks can't be
|
|
434
|
+
* queued: the batch fails.
|
|
435
|
+
*/
|
|
436
|
+
command<N extends string>(name: StringLiteral<N>): QueuedCommandInvocation {
|
|
437
|
+
return new QueuedCommandInvocation(this.queued, rawCommand(name, false));
|
|
438
|
+
}
|
|
439
|
+
|
|
394
440
|
/**
|
|
395
441
|
* Runs the queued commands as one transaction and returns their replies, as
|
|
396
442
|
* {@link Transaction.exec} does, or `null` if a watched key changed, in
|
|
@@ -452,6 +498,14 @@ export class Connection implements AsyncDisposable {
|
|
|
452
498
|
return new Invocation(this.t, script, false);
|
|
453
499
|
}
|
|
454
500
|
|
|
501
|
+
/**
|
|
502
|
+
* A command the command groups lack, on this connection: see
|
|
503
|
+
* {@link DatabaseRef.command}. One that blocks is refused here.
|
|
504
|
+
*/
|
|
505
|
+
command<N extends string>(name: StringLiteral<N>): CommandInvocation {
|
|
506
|
+
return new CommandInvocation(this.t, rawCommand(name, false));
|
|
507
|
+
}
|
|
508
|
+
|
|
455
509
|
/**
|
|
456
510
|
* Returns the connection to its pool. Keys it still watches are unwatched
|
|
457
511
|
* first.
|
package/storage/redis/mod.ts
CHANGED
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
*
|
|
21
21
|
* Commands are grouped by the data type they work on, each group a property of
|
|
22
22
|
* the database: `string`, `hash`, `list`, `set`, `sortedSet`, `stream`, `geo`,
|
|
23
|
-
* `bitmap`, `pubsub`, and `generic` for the ones that work on
|
|
23
|
+
* `bitmap`, `hyperloglog`, `pubsub`, and `generic` for the ones that work on
|
|
24
|
+
* any key. Within a
|
|
24
25
|
* group a command is named after the Redis command it runs — `get`, `hset`,
|
|
25
26
|
* `zadd`, `xadd` — with words of its own for its variants: `setEx`,
|
|
26
27
|
* `zrangeWithscores`.
|
|
@@ -43,6 +44,28 @@
|
|
|
43
44
|
* stored or passed on instead says nothing about what it will be used for, and
|
|
44
45
|
* is reported as an error — to do that, start from a handle.
|
|
45
46
|
*
|
|
47
|
+
* A command that waits for something to pop — `list.blpop`,
|
|
48
|
+
* `sortedSet.bzpopmin`, `stream.xreadBlock` and the like — runs on a
|
|
49
|
+
* connection of its own, so it holds up no other call. A timeout resolves to
|
|
50
|
+
* `null`. These can't be queued, and don't run on an acquired connection.
|
|
51
|
+
*
|
|
52
|
+
* ## Any command
|
|
53
|
+
*
|
|
54
|
+
* {@link DatabaseRef.command} sends a command the groups lack, by its name,
|
|
55
|
+
* with the arguments that are keys marked:
|
|
56
|
+
*
|
|
57
|
+
* ```ts
|
|
58
|
+
* const freq = await SESSIONS.command("OBJECT").arg("FREQ").key("hot").invoke().number();
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* The name must be a string literal, which Encore reads to grant the access
|
|
62
|
+
* the command needs. Before it is sent, the runtime checks it against Redis's
|
|
63
|
+
* command table: each key it takes must be passed with `key`, and the commands
|
|
64
|
+
* that would reach past the database, change a connection other calls share,
|
|
65
|
+
* or have a call of their own here (`MULTI`, `SUBSCRIBE`, `EVAL`, `SCAN`,
|
|
66
|
+
* `FLUSHALL`, …) fail with a `TypeError`. A handle that can only read sends
|
|
67
|
+
* only the commands Redis says don't write.
|
|
68
|
+
*
|
|
46
69
|
* ## Handles
|
|
47
70
|
*
|
|
48
71
|
* A database cannot be passed around as a value. To hand it to other code,
|
|
@@ -86,7 +109,7 @@ export {
|
|
|
86
109
|
WatchedTransaction,
|
|
87
110
|
Connection,
|
|
88
111
|
} from './database';
|
|
89
|
-
export type {DatabaseConfig
|
|
112
|
+
export type {DatabaseConfig} from './database';
|
|
90
113
|
export type {
|
|
91
114
|
BitmapCommands,
|
|
92
115
|
CommandGroups,
|
|
@@ -94,6 +117,7 @@ export type {
|
|
|
94
117
|
GenericCommands,
|
|
95
118
|
GeoCommands,
|
|
96
119
|
HashCommands,
|
|
120
|
+
HyperLogLogCommands,
|
|
97
121
|
ListCommands,
|
|
98
122
|
PubsubCommands,
|
|
99
123
|
Queue,
|
|
@@ -128,8 +152,20 @@ export type {
|
|
|
128
152
|
StreamEntry,
|
|
129
153
|
StreamInfo,
|
|
130
154
|
StreamPending,
|
|
155
|
+
Popped,
|
|
156
|
+
PoppedMany,
|
|
157
|
+
PoppedScored,
|
|
158
|
+
PoppedScoredMany,
|
|
131
159
|
} from './reply';
|
|
132
160
|
export {Script, Invocation, QueuedInvocation} from './script';
|
|
161
|
+
export {CommandInvocation, QueuedCommandInvocation} from './command';
|
|
162
|
+
export {
|
|
163
|
+
Bitfield,
|
|
164
|
+
BitfieldRo,
|
|
165
|
+
QueuedBitfield,
|
|
166
|
+
QueuedBitfieldRo,
|
|
167
|
+
} from './bitfield';
|
|
168
|
+
export type {BitOffset, BitfieldType, Overflow} from './bitfield';
|
|
133
169
|
export {Message, Subscription} from './pubsub';
|
|
134
170
|
export {ServerError} from './wire';
|
|
135
171
|
export type {Pairs, RedisArg} from './wire';
|
package/storage/redis/native.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as runtime from '../../internal/runtime/mod';
|
|
2
|
+
import {currentScope} from '../../internal/testing/scope';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* The native handle of the database `name`: where the SDK meets the runtime,
|
|
@@ -9,3 +10,13 @@ import * as runtime from '../../internal/runtime/mod';
|
|
|
9
10
|
export function openDatabase(name: string): runtime.RedisDatabase {
|
|
10
11
|
return runtime.RT.redisDatabase(name);
|
|
11
12
|
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The current test's instance of the database `name`, in test mode; `null`
|
|
16
|
+
* for the process's own.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export function testDatabase(name: string): runtime.RedisDatabase | null {
|
|
21
|
+
return currentScope()?.redisDatabase(name) ?? null;
|
|
22
|
+
}
|