@encore.dev/sdk 0.0.0 → 2.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +362 -0
- package/README.md +122 -2
- package/app_meta.test.ts +134 -0
- package/app_meta.ts +186 -0
- package/config/config.test.ts +381 -0
- package/config/config.ts +178 -0
- package/config/mod.ts +14 -0
- package/config/secrets.ts +147 -0
- package/config/value.ts +243 -0
- package/cron/mod.ts +23 -0
- package/dist/app_meta.d.ts +93 -0
- package/dist/app_meta.js +65 -0
- package/dist/app_meta.js.map +1 -0
- package/dist/config/config.d.ts +105 -0
- package/dist/config/config.js +87 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/mod.d.ts +4 -0
- package/dist/config/mod.js +3 -0
- package/dist/config/mod.js.map +1 -0
- package/dist/config/secrets.d.ts +92 -0
- package/dist/config/secrets.js +80 -0
- package/dist/config/secrets.js.map +1 -0
- package/dist/config/value.d.ts +51 -0
- package/dist/config/value.js +178 -0
- package/dist/config/value.js.map +1 -0
- package/dist/cron/mod.d.ts +22 -0
- package/dist/cron/mod.js +9 -0
- package/dist/cron/mod.js.map +1 -0
- package/dist/internal/otel/backend.d.ts +50 -0
- package/dist/internal/otel/backend.js +2 -0
- package/dist/internal/otel/backend.js.map +1 -0
- package/dist/internal/otel/context.d.ts +10 -0
- package/dist/internal/otel/context.js +34 -0
- package/dist/internal/otel/context.js.map +1 -0
- package/dist/internal/otel/context_manager.d.ts +22 -0
- package/dist/internal/otel/context_manager.js +120 -0
- package/dist/internal/otel/context_manager.js.map +1 -0
- package/dist/internal/otel/encode.d.ts +112 -0
- package/dist/internal/otel/encode.js +290 -0
- package/dist/internal/otel/encode.js.map +1 -0
- package/dist/internal/otel/index.d.ts +9 -0
- package/dist/internal/otel/index.js +9 -0
- package/dist/internal/otel/index.js.map +1 -0
- package/dist/internal/otel/meter.d.ts +73 -0
- package/dist/internal/otel/meter.js +265 -0
- package/dist/internal/otel/meter.js.map +1 -0
- package/dist/internal/otel/propagator.d.ts +14 -0
- package/dist/internal/otel/propagator.js +61 -0
- package/dist/internal/otel/propagator.js.map +1 -0
- package/dist/internal/otel/provider.d.ts +9 -0
- package/dist/internal/otel/provider.js +19 -0
- package/dist/internal/otel/provider.js.map +1 -0
- package/dist/internal/otel/request_context.d.ts +11 -0
- package/dist/internal/otel/request_context.js +20 -0
- package/dist/internal/otel/request_context.js.map +1 -0
- package/dist/internal/otel/span.d.ts +61 -0
- package/dist/internal/otel/span.js +206 -0
- package/dist/internal/otel/span.js.map +1 -0
- package/dist/internal/otel/tracer.d.ts +15 -0
- package/dist/internal/otel/tracer.js +65 -0
- package/dist/internal/otel/tracer.js.map +1 -0
- package/dist/internal/reqtrack/mod.d.ts +6 -0
- package/dist/internal/reqtrack/mod.js +28 -0
- package/dist/internal/reqtrack/mod.js.map +1 -0
- package/dist/internal/runtime/meter.d.ts +11 -0
- package/dist/internal/runtime/meter.js +22 -0
- package/dist/internal/runtime/meter.js.map +1 -0
- package/dist/internal/runtime/mod.d.ts +12 -0
- package/dist/internal/runtime/mod.js +28 -0
- package/dist/internal/runtime/mod.js.map +1 -0
- package/dist/internal/runtime/napi/napi.cjs +122 -0
- package/dist/internal/runtime/napi/napi.d.cts +601 -0
- package/dist/internal/runtime/shutdown.d.ts +13 -0
- package/dist/internal/runtime/shutdown.js +56 -0
- package/dist/internal/runtime/shutdown.js.map +1 -0
- package/dist/internal/utils/constraints.d.ts +9 -0
- package/dist/internal/utils/constraints.js +2 -0
- package/dist/internal/utils/constraints.js.map +1 -0
- package/dist/log/index.d.ts +39 -0
- package/dist/log/index.js +44 -0
- package/dist/log/index.js.map +1 -0
- package/dist/log/logger.d.ts +123 -0
- package/dist/log/logger.js +203 -0
- package/dist/log/logger.js.map +1 -0
- package/dist/log/runtime.d.ts +19 -0
- package/dist/log/runtime.js +22 -0
- package/dist/log/runtime.js.map +1 -0
- package/dist/log/stderr.d.ts +9 -0
- package/dist/log/stderr.js +25 -0
- package/dist/log/stderr.js.map +1 -0
- package/dist/metrics/mod.d.ts +315 -0
- package/dist/metrics/mod.js +488 -0
- package/dist/metrics/mod.js.map +1 -0
- package/dist/mod.d.ts +6 -0
- package/dist/mod.js +4 -0
- package/dist/mod.js.map +1 -0
- package/dist/otel.d.ts +9 -0
- package/dist/otel.js +13 -0
- package/dist/otel.js.map +1 -0
- package/dist/pubsub/encoding.d.ts +3 -0
- package/dist/pubsub/encoding.js +10 -0
- package/dist/pubsub/encoding.js.map +1 -0
- package/dist/pubsub/mod.d.ts +6 -0
- package/dist/pubsub/mod.js +3 -0
- package/dist/pubsub/mod.js.map +1 -0
- package/dist/pubsub/refs.d.ts +12 -0
- package/dist/pubsub/refs.js +11 -0
- package/dist/pubsub/refs.js.map +1 -0
- package/dist/pubsub/subscription.d.ts +128 -0
- package/dist/pubsub/subscription.js +39 -0
- package/dist/pubsub/subscription.js.map +1 -0
- package/dist/pubsub/topic.d.ts +148 -0
- package/dist/pubsub/topic.js +164 -0
- package/dist/pubsub/topic.js.map +1 -0
- package/dist/req_meta.d.ts +47 -0
- package/dist/req_meta.js +26 -0
- package/dist/req_meta.js.map +1 -0
- package/dist/services/index.d.ts +7 -0
- package/dist/services/index.js +17 -0
- package/dist/services/index.js.map +1 -0
- package/dist/shutdown/mod.d.ts +23 -0
- package/dist/shutdown/mod.js +24 -0
- package/dist/shutdown/mod.js.map +1 -0
- package/dist/storage/objects/bucket.d.ts +216 -0
- package/dist/storage/objects/bucket.js +123 -0
- package/dist/storage/objects/bucket.js.map +1 -0
- package/dist/storage/objects/error.d.ts +14 -0
- package/dist/storage/objects/error.js +81 -0
- package/dist/storage/objects/error.js.map +1 -0
- package/dist/storage/objects/mod.d.ts +4 -0
- package/dist/storage/objects/mod.js +3 -0
- package/dist/storage/objects/mod.js.map +1 -0
- package/dist/storage/objects/refs.d.ts +31 -0
- package/dist/storage/objects/refs.js +20 -0
- package/dist/storage/objects/refs.js.map +1 -0
- package/dist/storage/postgres/database.d.ts +295 -0
- package/dist/storage/postgres/database.js +378 -0
- package/dist/storage/postgres/database.js.map +1 -0
- package/dist/storage/postgres/mod.d.ts +2 -0
- package/dist/storage/postgres/mod.js +2 -0
- package/dist/storage/postgres/mod.js.map +1 -0
- package/dist/storage/redis/commands.d.ts +573 -0
- package/dist/storage/redis/commands.js +637 -0
- package/dist/storage/redis/commands.js.map +1 -0
- package/dist/storage/redis/database.d.ts +302 -0
- package/dist/storage/redis/database.js +336 -0
- package/dist/storage/redis/database.js.map +1 -0
- package/dist/storage/redis/mod.d.ts +88 -0
- package/dist/storage/redis/mod.js +84 -0
- package/dist/storage/redis/mod.js.map +1 -0
- package/dist/storage/redis/native.d.ts +8 -0
- package/dist/storage/redis/native.js +11 -0
- package/dist/storage/redis/native.js.map +1 -0
- package/dist/storage/redis/options.d.ts +89 -0
- package/dist/storage/redis/options.js +53 -0
- package/dist/storage/redis/options.js.map +1 -0
- package/dist/storage/redis/pubsub.d.ts +53 -0
- package/dist/storage/redis/pubsub.js +88 -0
- package/dist/storage/redis/pubsub.js.map +1 -0
- package/dist/storage/redis/reply.d.ts +256 -0
- package/dist/storage/redis/reply.js +572 -0
- package/dist/storage/redis/reply.js.map +1 -0
- package/dist/storage/redis/scan.d.ts +11 -0
- package/dist/storage/redis/scan.js +76 -0
- package/dist/storage/redis/scan.js.map +1 -0
- package/dist/storage/redis/script.d.ts +91 -0
- package/dist/storage/redis/script.js +143 -0
- package/dist/storage/redis/script.js.map +1 -0
- package/dist/storage/redis/target.d.ts +47 -0
- package/dist/storage/redis/target.js +82 -0
- package/dist/storage/redis/target.js.map +1 -0
- package/dist/storage/redis/wire.d.ts +105 -0
- package/dist/storage/redis/wire.js +333 -0
- package/dist/storage/redis/wire.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/mod.d.ts +42 -0
- package/dist/types/mod.js +65 -0
- package/dist/types/mod.js.map +1 -0
- package/internal/otel/backend.ts +60 -0
- package/internal/otel/context.test.ts +70 -0
- package/internal/otel/context.ts +48 -0
- package/internal/otel/context_manager.test.ts +154 -0
- package/internal/otel/context_manager.ts +141 -0
- package/internal/otel/encode.test.ts +266 -0
- package/internal/otel/encode.ts +408 -0
- package/internal/otel/index.ts +20 -0
- package/internal/otel/meter.test.ts +231 -0
- package/internal/otel/meter.ts +332 -0
- package/internal/otel/propagator.test.ts +105 -0
- package/internal/otel/propagator.ts +68 -0
- package/internal/otel/provider.ts +23 -0
- package/internal/otel/request_context.ts +32 -0
- package/internal/otel/span.ts +252 -0
- package/internal/otel/tracer.test.ts +352 -0
- package/internal/otel/tracer.ts +104 -0
- package/internal/reqtrack/mod.ts +39 -0
- package/internal/runtime/meter.ts +26 -0
- package/internal/runtime/mod.ts +41 -0
- package/internal/runtime/napi/napi.cjs +122 -0
- package/internal/runtime/napi/napi.d.cts +601 -0
- package/internal/runtime/shutdown.test.ts +248 -0
- package/internal/runtime/shutdown.ts +64 -0
- package/internal/utils/constraints.ts +12 -0
- package/log/index.ts +107 -0
- package/log/logger.test.ts +194 -0
- package/log/logger.ts +308 -0
- package/log/runtime.test.ts +65 -0
- package/log/runtime.ts +40 -0
- package/log/stderr.test.ts +23 -0
- package/log/stderr.ts +24 -0
- package/metrics/export.test.ts +337 -0
- package/metrics/mod.test.ts +180 -0
- package/metrics/mod.ts +619 -0
- package/mod.ts +22 -0
- package/otel.test.ts +84 -0
- package/otel.ts +17 -0
- package/package.json +121 -5
- package/pubsub/encoding.ts +8 -0
- package/pubsub/mod.ts +14 -0
- package/pubsub/pubsub.test.ts +186 -0
- package/pubsub/refs.ts +22 -0
- package/pubsub/subscription.ts +180 -0
- package/pubsub/topic.test.ts +121 -0
- package/pubsub/topic.ts +212 -0
- package/req_meta.ts +75 -0
- package/services/index.test.ts +30 -0
- package/services/index.ts +16 -0
- package/shutdown/mod.ts +24 -0
- package/storage/objects/bucket.ts +338 -0
- package/storage/objects/error.ts +94 -0
- package/storage/objects/mod.ts +35 -0
- package/storage/objects/refs.ts +69 -0
- package/storage/postgres/database.integration.test.ts +175 -0
- package/storage/postgres/database.test.ts +241 -0
- package/storage/postgres/database.ts +497 -0
- package/storage/postgres/mod.ts +15 -0
- package/storage/redis/commands.ts +1221 -0
- package/storage/redis/database.ts +466 -0
- package/storage/redis/mod.ts +135 -0
- package/storage/redis/native.ts +11 -0
- package/storage/redis/options.ts +119 -0
- package/storage/redis/pubsub.ts +92 -0
- package/storage/redis/redis.test.ts +706 -0
- package/storage/redis/reply.ts +705 -0
- package/storage/redis/runtime.test.ts +233 -0
- package/storage/redis/scan.ts +125 -0
- package/storage/redis/script.ts +162 -0
- package/storage/redis/target.ts +131 -0
- package/storage/redis/wire.ts +369 -0
- package/types/mod.ts +92 -0
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The command groups: one per Redis data type, each holding the commands on
|
|
3
|
+
* it in three forms: the ones that run now, the ones of those that only read,
|
|
4
|
+
* and the ones that queue on a pipeline or a transaction.
|
|
5
|
+
*
|
|
6
|
+
* All three come from one list per group, below, after the Rust SDK's
|
|
7
|
+
* (`sdk/rs/encore/src/storage/redis/commands.rs`): the same commands, named in
|
|
8
|
+
* TypeScript's casing. A command is written once: whether it reads or writes,
|
|
9
|
+
* its parameters, the Redis command it builds, with the arguments that are
|
|
10
|
+
* keys marked, and what its reply is read as. Encore's parser holds the same
|
|
11
|
+
* list (`TS_TABLES.families` in `encore_parser`), which is how it knows what
|
|
12
|
+
* each call needs to be granted; a test there reads this file and fails when
|
|
13
|
+
* the two differ.
|
|
14
|
+
*
|
|
15
|
+
* Two are TypeScript's own, as they are Go's: `incrFloat` and `hincrFloat`,
|
|
16
|
+
* where Rust picks `INCRBY` or `INCRBYFLOAT` by the type of the amount.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
import { directionArg, expiryArgs, maxlenArgs, radiusArgs, setArgs, } from './options.js';
|
|
21
|
+
import { as, Reply, ReplyPromise } from './reply.js';
|
|
22
|
+
import { scanFields, scanKeys, scanMembers, scanScored } from './scan.js';
|
|
23
|
+
import { subscribe } from './pubsub.js';
|
|
24
|
+
import { Cmd } from './wire.js';
|
|
25
|
+
/** A command that only reads. */
|
|
26
|
+
function read(build, reply) {
|
|
27
|
+
return { write: false, build, reply };
|
|
28
|
+
}
|
|
29
|
+
/** A command that writes. */
|
|
30
|
+
function write(build, reply) {
|
|
31
|
+
return { write: true, build, reply };
|
|
32
|
+
}
|
|
33
|
+
/** What runs now and only reads. */
|
|
34
|
+
function readRun(run) {
|
|
35
|
+
return { write: false, run };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The command Redis calls `name`. Its trace name and whether it writes are
|
|
39
|
+
* the definition's, filled in as the group is put together.
|
|
40
|
+
*/
|
|
41
|
+
function cmd(name) {
|
|
42
|
+
return new Cmd('', name, false);
|
|
43
|
+
}
|
|
44
|
+
/** A bit as Redis takes one. */
|
|
45
|
+
const bitArg = (b) => (b ? 1 : 0);
|
|
46
|
+
const generic = {
|
|
47
|
+
/** Whether the key exists. */
|
|
48
|
+
exists: read((key) => cmd('EXISTS').key(key), as.bool),
|
|
49
|
+
/**
|
|
50
|
+
* The seconds until the key expires: -1 if it never does, -2 if it does not
|
|
51
|
+
* exist.
|
|
52
|
+
*/
|
|
53
|
+
ttl: read((key) => cmd('TTL').key(key), as.number),
|
|
54
|
+
/**
|
|
55
|
+
* The milliseconds until the key expires: -1 if it never does, -2 if it does
|
|
56
|
+
* not exist.
|
|
57
|
+
*/
|
|
58
|
+
pttl: read((key) => cmd('PTTL').key(key), as.number),
|
|
59
|
+
/**
|
|
60
|
+
* The type of the value at the key: `string`, `list`, `set`, `zset`, `hash`,
|
|
61
|
+
* `stream`, or `none` if it does not exist.
|
|
62
|
+
*/
|
|
63
|
+
keyType: read((key) => cmd('TYPE').key(key), as.text),
|
|
64
|
+
/**
|
|
65
|
+
* The Unix time, in seconds, the key expires at: -1 if it never does, -2 if
|
|
66
|
+
* it does not exist.
|
|
67
|
+
*/
|
|
68
|
+
expireTime: read((key) => cmd('EXPIRETIME').key(key), as.number),
|
|
69
|
+
/** Iterates over the database's keys. */
|
|
70
|
+
scan: readRun((t, options) => scanKeys(t, options)),
|
|
71
|
+
/** Deletes the keys, returning how many existed. */
|
|
72
|
+
del: write((...keys) => cmd('DEL').keys(keys), as.number),
|
|
73
|
+
/**
|
|
74
|
+
* Deletes the keys, reclaiming their memory in the background. Returns how
|
|
75
|
+
* many existed.
|
|
76
|
+
*/
|
|
77
|
+
unlink: write((...keys) => cmd('UNLINK').keys(keys), as.number),
|
|
78
|
+
/** Has the key expire in `seconds`. `false` if it does not exist. */
|
|
79
|
+
expire: write((key, seconds) => cmd('EXPIRE').key(key).arg(seconds), as.bool),
|
|
80
|
+
/** Has the key expire in `milliseconds`. `false` if it does not exist. */
|
|
81
|
+
pexpire: write((key, milliseconds) => cmd('PEXPIRE').key(key).arg(milliseconds), as.bool),
|
|
82
|
+
/**
|
|
83
|
+
* Has the key expire at a Unix time, in seconds. `false` if it does not
|
|
84
|
+
* exist.
|
|
85
|
+
*/
|
|
86
|
+
expireAt: write((key, timestamp) => cmd('EXPIREAT').key(key).arg(timestamp), as.bool),
|
|
87
|
+
/** Removes the key's expiry. `false` if it had none, or does not exist. */
|
|
88
|
+
persist: write((key) => cmd('PERSIST').key(key), as.bool),
|
|
89
|
+
/** Renames the key, replacing `newKey` if it exists. */
|
|
90
|
+
rename: write((key, newKey) => cmd('RENAME').key(key).key(newKey), as.none),
|
|
91
|
+
/** Renames the key unless `newKey` exists. `false` if it does. */
|
|
92
|
+
renameNx: write((key, newKey) => cmd('RENAMENX').key(key).key(newKey), as.bool),
|
|
93
|
+
/**
|
|
94
|
+
* Copies the value at `source` to `destination`. `false` if `destination`
|
|
95
|
+
* exists.
|
|
96
|
+
*/
|
|
97
|
+
copy: write((source, destination) => cmd('COPY').key(source).key(destination), as.bool),
|
|
98
|
+
/** Marks the keys as used just now, returning how many exist. */
|
|
99
|
+
touch: write((...keys) => cmd('TOUCH').keys(keys), as.number),
|
|
100
|
+
};
|
|
101
|
+
const string = {
|
|
102
|
+
/** The value at the key: nil if it does not exist. */
|
|
103
|
+
get: read((key) => cmd('GET').key(key), as.reply),
|
|
104
|
+
/**
|
|
105
|
+
* The values at the keys, in order, each missing one as nil: read it with
|
|
106
|
+
* {@link Reply.optionalTexts}.
|
|
107
|
+
*/
|
|
108
|
+
mget: read((...keys) => cmd('MGET').keys(keys), as.reply),
|
|
109
|
+
/** The length of the value at the key, in bytes. */
|
|
110
|
+
strlen: read((key) => cmd('STRLEN').key(key), as.number),
|
|
111
|
+
/**
|
|
112
|
+
* The part of the value from byte `from` to byte `to`, inclusive. Negative
|
|
113
|
+
* offsets count from the end.
|
|
114
|
+
*/
|
|
115
|
+
getrange: read((key, from, to) => cmd('GETRANGE').key(key).arg(from).arg(to), as.reply),
|
|
116
|
+
/** Sets the key to the value. */
|
|
117
|
+
set: write((key, value) => cmd('SET').key(key).arg(value), as.none),
|
|
118
|
+
/** Sets the key to the value, expiring in `seconds`. */
|
|
119
|
+
setEx: write((key, value, seconds) => cmd('SETEX').key(key).arg(seconds).arg(value), as.none),
|
|
120
|
+
/** Sets the key to the value unless the key exists. `false` if it does. */
|
|
121
|
+
setNx: write((key, value) => cmd('SETNX').key(key).arg(value), as.bool),
|
|
122
|
+
/**
|
|
123
|
+
* Sets the key to the value as `options` say: only if it exists or does
|
|
124
|
+
* not, with an expiry, replying the old value.
|
|
125
|
+
*/
|
|
126
|
+
setOptions: write((key, value, options) => cmd('SET').key(key).arg(value).argsOf(setArgs(options)), as.reply),
|
|
127
|
+
/** Sets each key to its value, all at once. */
|
|
128
|
+
mset: write((items) => cmd('MSET').pairs(items), as.none),
|
|
129
|
+
/**
|
|
130
|
+
* Sets each key to its value unless any of the keys exists. `false` if one
|
|
131
|
+
* does, in which case none is set.
|
|
132
|
+
*/
|
|
133
|
+
msetNx: write((items) => cmd('MSETNX').pairs(items), as.bool),
|
|
134
|
+
/** The value at the key, which is deleted. */
|
|
135
|
+
getDel: write((key) => cmd('GETDEL').key(key), as.reply),
|
|
136
|
+
/** The value at the key, whose expiry is set as `expiry` says. */
|
|
137
|
+
getEx: write((key, expiry) => cmd('GETEX').key(key).argsOf(expiryArgs(expiry)), as.reply),
|
|
138
|
+
/** Appends to the value at the key, returning its new length. */
|
|
139
|
+
append: write((key, value) => cmd('APPEND').key(key).arg(value), as.number),
|
|
140
|
+
/** Overwrites the value from byte `offset`, returning its new length. */
|
|
141
|
+
setrange: write((key, offset, value) => cmd('SETRANGE').key(key).arg(offset).arg(value), as.number),
|
|
142
|
+
/**
|
|
143
|
+
* Adds `delta` to the integer at the key, returning the result. A missing
|
|
144
|
+
* key counts as 0.
|
|
145
|
+
*/
|
|
146
|
+
incr: write((key, delta) => cmd('INCRBY').key(key).arg(delta), as.number),
|
|
147
|
+
/**
|
|
148
|
+
* Adds `delta` to the number at the key, returning the result. A missing key
|
|
149
|
+
* counts as 0.
|
|
150
|
+
*/
|
|
151
|
+
incrFloat: write((key, delta) => cmd('INCRBYFLOAT').key(key).arg(delta), as.number),
|
|
152
|
+
/** Subtracts `delta` from the integer at the key, returning the result. */
|
|
153
|
+
decr: write((key, delta) => cmd('DECRBY').key(key).arg(delta), as.number),
|
|
154
|
+
};
|
|
155
|
+
const bitmap = {
|
|
156
|
+
/** The bit at `offset`. */
|
|
157
|
+
getbit: read((key, offset) => cmd('GETBIT').key(key).arg(offset), as.bool),
|
|
158
|
+
/** How many bits are set. */
|
|
159
|
+
bitcount: read((key) => cmd('BITCOUNT').key(key), as.number),
|
|
160
|
+
/** How many bits are set from byte `start` to byte `end`, inclusive. */
|
|
161
|
+
bitcountRange: read((key, start, end) => cmd('BITCOUNT').key(key).arg(start).arg(end), as.number),
|
|
162
|
+
/** The position of the first bit that is `bit`, or -1 if there is none. */
|
|
163
|
+
bitpos: read((key, bit) => cmd('BITPOS').key(key).arg(bitArg(bit)), as.number),
|
|
164
|
+
/** Sets the bit at `offset`, returning what it was. */
|
|
165
|
+
setbit: write((key, offset, value) => cmd('SETBIT').key(key).arg(offset).arg(bitArg(value)), as.bool),
|
|
166
|
+
/**
|
|
167
|
+
* Stores the AND of the sources at `destination`, returning its length in
|
|
168
|
+
* bytes.
|
|
169
|
+
*/
|
|
170
|
+
bitAnd: write((destination, ...sources) => cmd('BITOP').arg('AND').key(destination).keys(sources), as.number),
|
|
171
|
+
/**
|
|
172
|
+
* Stores the OR of the sources at `destination`, returning its length in
|
|
173
|
+
* bytes.
|
|
174
|
+
*/
|
|
175
|
+
bitOr: write((destination, ...sources) => cmd('BITOP').arg('OR').key(destination).keys(sources), as.number),
|
|
176
|
+
/**
|
|
177
|
+
* Stores the XOR of the sources at `destination`, returning its length in
|
|
178
|
+
* bytes.
|
|
179
|
+
*/
|
|
180
|
+
bitXor: write((destination, ...sources) => cmd('BITOP').arg('XOR').key(destination).keys(sources), as.number),
|
|
181
|
+
/**
|
|
182
|
+
* Stores the inverse of the source at `destination`, returning its length in
|
|
183
|
+
* bytes.
|
|
184
|
+
*/
|
|
185
|
+
bitNot: write((destination, source) => cmd('BITOP').arg('NOT').key(destination).key(source), as.number),
|
|
186
|
+
};
|
|
187
|
+
const hash = {
|
|
188
|
+
/** The value of a field: nil if it does not exist. */
|
|
189
|
+
hget: read((key, field) => cmd('HGET').key(key).arg(field), as.reply),
|
|
190
|
+
/**
|
|
191
|
+
* The values of the fields, in order, each missing one as nil: read it with
|
|
192
|
+
* {@link Reply.optionalTexts}.
|
|
193
|
+
*/
|
|
194
|
+
hmget: read((key, ...fields) => cmd('HMGET').key(key).argsOf(fields), as.reply),
|
|
195
|
+
/** Every field and its value: read it with {@link Reply.textMap}. */
|
|
196
|
+
hgetall: read((key) => cmd('HGETALL').key(key), as.reply),
|
|
197
|
+
/** Whether the field exists. */
|
|
198
|
+
hexists: read((key, field) => cmd('HEXISTS').key(key).arg(field), as.bool),
|
|
199
|
+
/** How many fields the hash has. */
|
|
200
|
+
hlen: read((key) => cmd('HLEN').key(key), as.number),
|
|
201
|
+
/** The names of the fields. */
|
|
202
|
+
hkeys: read((key) => cmd('HKEYS').key(key), as.reply),
|
|
203
|
+
/** The values of the fields. */
|
|
204
|
+
hvals: read((key) => cmd('HVALS').key(key), as.reply),
|
|
205
|
+
/** The name of a field chosen at random. */
|
|
206
|
+
hrandfield: read((key) => cmd('HRANDFIELD').key(key), as.reply),
|
|
207
|
+
/** Iterates over the hash's fields, each with its value. */
|
|
208
|
+
hscan: readRun((t, key, options) => scanFields(t, key, options)),
|
|
209
|
+
/** Sets a field, returning 1 if it is new and 0 if it was replaced. */
|
|
210
|
+
hset: write((key, field, value) => cmd('HSET').key(key).arg(field).arg(value), as.number),
|
|
211
|
+
/** Sets several fields, returning how many are new. */
|
|
212
|
+
hsetMultiple: write((key, items) => cmd('HSET').key(key).fields(items), as.number),
|
|
213
|
+
/** Sets a field unless it exists. `false` if it does. */
|
|
214
|
+
hsetNx: write((key, field, value) => cmd('HSETNX').key(key).arg(field).arg(value), as.bool),
|
|
215
|
+
/** Deletes the fields, returning how many existed. */
|
|
216
|
+
hdel: write((key, ...fields) => cmd('HDEL').key(key).argsOf(fields), as.number),
|
|
217
|
+
/** Adds `delta` to the integer in a field, returning the result. */
|
|
218
|
+
hincr: write((key, field, delta) => cmd('HINCRBY').key(key).arg(field).arg(delta), as.number),
|
|
219
|
+
/** Adds `delta` to the number in a field, returning the result. */
|
|
220
|
+
hincrFloat: write((key, field, delta) => cmd('HINCRBYFLOAT').key(key).arg(field).arg(delta), as.number),
|
|
221
|
+
};
|
|
222
|
+
const list = {
|
|
223
|
+
/**
|
|
224
|
+
* The elements from index `start` to index `stop`, inclusive. Negative
|
|
225
|
+
* indexes count from the end: `0, -1` is the whole list.
|
|
226
|
+
*/
|
|
227
|
+
lrange: read((key, start, stop) => cmd('LRANGE').key(key).arg(start).arg(stop), as.reply),
|
|
228
|
+
/** The element at an index. */
|
|
229
|
+
lindex: read((key, index) => cmd('LINDEX').key(key).arg(index), as.reply),
|
|
230
|
+
/** How many elements the list has. */
|
|
231
|
+
llen: read((key) => cmd('LLEN').key(key), as.number),
|
|
232
|
+
/** The index of the first element equal to `value`: `null` if there is none. */
|
|
233
|
+
lpos: read((key, value) => cmd('LPOS').key(key).arg(value), as.optionalNumber),
|
|
234
|
+
/** Prepends the values, returning the list's new length. */
|
|
235
|
+
lpush: write((key, ...values) => cmd('LPUSH').key(key).argsOf(values), as.number),
|
|
236
|
+
/** Appends the values, returning the list's new length. */
|
|
237
|
+
rpush: write((key, ...values) => cmd('RPUSH').key(key).argsOf(values), as.number),
|
|
238
|
+
/** Prepends the values if the list exists, returning its length. */
|
|
239
|
+
lpushExists: write((key, ...values) => cmd('LPUSHX').key(key).argsOf(values), as.number),
|
|
240
|
+
/** Appends the values if the list exists, returning its length. */
|
|
241
|
+
rpushExists: write((key, ...values) => cmd('RPUSHX').key(key).argsOf(values), as.number),
|
|
242
|
+
/**
|
|
243
|
+
* Removes and returns the first element, or with a `count`, that many, as a
|
|
244
|
+
* list.
|
|
245
|
+
*/
|
|
246
|
+
lpop: write((key, count) => cmd('LPOP')
|
|
247
|
+
.key(key)
|
|
248
|
+
.argsOf(count === undefined ? [] : [count]), as.reply),
|
|
249
|
+
/**
|
|
250
|
+
* Removes and returns the last element, or with a `count`, that many, as a
|
|
251
|
+
* list.
|
|
252
|
+
*/
|
|
253
|
+
rpop: write((key, count) => cmd('RPOP')
|
|
254
|
+
.key(key)
|
|
255
|
+
.argsOf(count === undefined ? [] : [count]), as.reply),
|
|
256
|
+
/** Replaces the element at an index. */
|
|
257
|
+
lset: write((key, index, value) => cmd('LSET').key(key).arg(index).arg(value), as.none),
|
|
258
|
+
/** Keeps only the elements from index `start` to index `stop`, inclusive. */
|
|
259
|
+
ltrim: write((key, start, stop) => cmd('LTRIM').key(key).arg(start).arg(stop), as.none),
|
|
260
|
+
/**
|
|
261
|
+
* Inserts the value before the first element equal to `pivot`, returning
|
|
262
|
+
* the list's new length, or -1 if there is no such element.
|
|
263
|
+
*/
|
|
264
|
+
linsertBefore: write((key, pivot, value) => cmd('LINSERT').key(key).arg('BEFORE').arg(pivot).arg(value), as.number),
|
|
265
|
+
/**
|
|
266
|
+
* Inserts the value after the first element equal to `pivot`, returning the
|
|
267
|
+
* list's new length, or -1 if there is no such element.
|
|
268
|
+
*/
|
|
269
|
+
linsertAfter: write((key, pivot, value) => cmd('LINSERT').key(key).arg('AFTER').arg(pivot).arg(value), as.number),
|
|
270
|
+
/**
|
|
271
|
+
* Removes elements equal to `value`: the first `count` of them, the last
|
|
272
|
+
* `-count` if it is negative, or all if it is 0. Returns how many.
|
|
273
|
+
*/
|
|
274
|
+
lrem: write((key, count, value) => cmd('LREM').key(key).arg(count).arg(value), as.number),
|
|
275
|
+
/**
|
|
276
|
+
* Moves an element from one end of `source` to one end of `destination`,
|
|
277
|
+
* returning it.
|
|
278
|
+
*/
|
|
279
|
+
lmove: write((source, destination, from, to) => cmd('LMOVE')
|
|
280
|
+
.key(source)
|
|
281
|
+
.key(destination)
|
|
282
|
+
.arg(directionArg(from))
|
|
283
|
+
.arg(directionArg(to)), as.reply),
|
|
284
|
+
};
|
|
285
|
+
const set = {
|
|
286
|
+
/** Every member. */
|
|
287
|
+
smembers: read((key) => cmd('SMEMBERS').key(key), as.reply),
|
|
288
|
+
/** Whether the value is a member. */
|
|
289
|
+
sismember: read((key, member) => cmd('SISMEMBER').key(key).arg(member), as.bool),
|
|
290
|
+
/** Whether each of the values is a member, in order. */
|
|
291
|
+
smismember: read((key, ...members) => cmd('SMISMEMBER').key(key).argsOf(members), as.bools),
|
|
292
|
+
/** How many members the set has. */
|
|
293
|
+
scard: read((key) => cmd('SCARD').key(key), as.number),
|
|
294
|
+
/** A member chosen at random. */
|
|
295
|
+
srandmember: read((key) => cmd('SRANDMEMBER').key(key), as.reply),
|
|
296
|
+
/**
|
|
297
|
+
* `count` distinct members chosen at random, or with a negative `count` that
|
|
298
|
+
* many, possibly repeated.
|
|
299
|
+
*/
|
|
300
|
+
srandmemberMultiple: read((key, count) => cmd('SRANDMEMBER').key(key).arg(count), as.reply),
|
|
301
|
+
/** The members of the first set that are in none of the others. */
|
|
302
|
+
sdiff: read((...keys) => cmd('SDIFF').keys(keys), as.reply),
|
|
303
|
+
/** The members that are in every one of the sets. */
|
|
304
|
+
sinter: read((...keys) => cmd('SINTER').keys(keys), as.reply),
|
|
305
|
+
/** The members that are in any of the sets. */
|
|
306
|
+
sunion: read((...keys) => cmd('SUNION').keys(keys), as.reply),
|
|
307
|
+
/** Iterates over the set's members. */
|
|
308
|
+
sscan: readRun((t, key, options) => scanMembers(t, key, options)),
|
|
309
|
+
/** Adds the members, returning how many are new. */
|
|
310
|
+
sadd: write((key, ...members) => cmd('SADD').key(key).argsOf(members), as.number),
|
|
311
|
+
/** Removes the members, returning how many there were. */
|
|
312
|
+
srem: write((key, ...members) => cmd('SREM').key(key).argsOf(members), as.number),
|
|
313
|
+
/** Removes and returns a member chosen at random. */
|
|
314
|
+
spop: write((key) => cmd('SPOP').key(key), as.reply),
|
|
315
|
+
/**
|
|
316
|
+
* Moves a member from one set to another. `false` if it is not in `source`.
|
|
317
|
+
*/
|
|
318
|
+
smove: write((source, destination, member) => cmd('SMOVE').key(source).key(destination).arg(member), as.bool),
|
|
319
|
+
/** Stores `sdiff` of the sets at `destination`, returning its size. */
|
|
320
|
+
sdiffstore: write((destination, ...keys) => cmd('SDIFFSTORE').key(destination).keys(keys), as.number),
|
|
321
|
+
/** Stores `sinter` of the sets at `destination`, returning its size. */
|
|
322
|
+
sinterstore: write((destination, ...keys) => cmd('SINTERSTORE').key(destination).keys(keys), as.number),
|
|
323
|
+
/** Stores `sunion` of the sets at `destination`, returning its size. */
|
|
324
|
+
sunionstore: write((destination, ...keys) => cmd('SUNIONSTORE').key(destination).keys(keys), as.number),
|
|
325
|
+
};
|
|
326
|
+
const sortedSet = {
|
|
327
|
+
/**
|
|
328
|
+
* The members ranked `start` to `stop`, inclusive, lowest score first.
|
|
329
|
+
* Negative ranks count from the highest: `0, -1` is every member.
|
|
330
|
+
*/
|
|
331
|
+
zrange: read((key, start, stop) => cmd('ZRANGE').key(key).arg(start).arg(stop), as.reply),
|
|
332
|
+
/**
|
|
333
|
+
* `zrange`, each member with its score: read it with
|
|
334
|
+
* {@link Reply.scoredMembers}.
|
|
335
|
+
*/
|
|
336
|
+
zrangeWithscores: read((key, start, stop) => cmd('ZRANGE').key(key).arg(start).arg(stop).arg('WITHSCORES'), as.reply),
|
|
337
|
+
/** The members ranked `start` to `stop`, inclusive, highest score first. */
|
|
338
|
+
zrevrange: read((key, start, stop) => cmd('ZREVRANGE').key(key).arg(start).arg(stop), as.reply),
|
|
339
|
+
/**
|
|
340
|
+
* `zrevrange`, each member with its score: read it with
|
|
341
|
+
* {@link Reply.scoredMembers}.
|
|
342
|
+
*/
|
|
343
|
+
zrevrangeWithscores: read((key, start, stop) => cmd('ZREVRANGE').key(key).arg(start).arg(stop).arg('WITHSCORES'), as.reply),
|
|
344
|
+
/** The members with a score from `min` to `max`, lowest first. */
|
|
345
|
+
zrangebyscore: read((key, min, max) => cmd('ZRANGEBYSCORE').key(key).arg(min).arg(max), as.reply),
|
|
346
|
+
/**
|
|
347
|
+
* `zrangebyscore`, each member with its score: read it with
|
|
348
|
+
* {@link Reply.scoredMembers}.
|
|
349
|
+
*/
|
|
350
|
+
zrangebyscoreWithscores: read((key, min, max) => cmd('ZRANGEBYSCORE').key(key).arg(min).arg(max).arg('WITHSCORES'), as.reply),
|
|
351
|
+
/** A member's score: `null` if it is not a member. */
|
|
352
|
+
zscore: read((key, member) => cmd('ZSCORE').key(key).arg(member), as.optionalNumber),
|
|
353
|
+
/**
|
|
354
|
+
* A member's rank, lowest score first, from 0: `null` if it is not a
|
|
355
|
+
* member.
|
|
356
|
+
*/
|
|
357
|
+
zrank: read((key, member) => cmd('ZRANK').key(key).arg(member), as.optionalNumber),
|
|
358
|
+
/**
|
|
359
|
+
* A member's rank, highest score first, from 0: `null` if it is not a
|
|
360
|
+
* member.
|
|
361
|
+
*/
|
|
362
|
+
zrevrank: read((key, member) => cmd('ZREVRANK').key(key).arg(member), as.optionalNumber),
|
|
363
|
+
/** How many members the set has. */
|
|
364
|
+
zcard: read((key) => cmd('ZCARD').key(key), as.number),
|
|
365
|
+
/** How many members have a score from `min` to `max`. */
|
|
366
|
+
zcount: read((key, min, max) => cmd('ZCOUNT').key(key).arg(min).arg(max), as.number),
|
|
367
|
+
/** A member chosen at random. */
|
|
368
|
+
zrandmember: read((key) => cmd('ZRANDMEMBER').key(key), as.reply),
|
|
369
|
+
/** Iterates over the sorted set's members, each with its score. */
|
|
370
|
+
zscan: readRun((t, key, options) => scanScored(t, key, options)),
|
|
371
|
+
/**
|
|
372
|
+
* Adds a member with a score, or updates its score. Returns 1 if it is new.
|
|
373
|
+
*/
|
|
374
|
+
zadd: write((key, member, score) => cmd('ZADD').key(key).arg(score).arg(member), as.number),
|
|
375
|
+
/**
|
|
376
|
+
* Adds several members, each with its score, returning how many are new.
|
|
377
|
+
*/
|
|
378
|
+
zaddMultiple: write((key, items) => cmd('ZADD').key(key).scores(items), as.number),
|
|
379
|
+
/** Removes the members, returning how many there were. */
|
|
380
|
+
zrem: write((key, ...members) => cmd('ZREM').key(key).argsOf(members), as.number),
|
|
381
|
+
/** Adds `delta` to a member's score, returning the result. */
|
|
382
|
+
zincr: write((key, member, delta) => cmd('ZINCRBY').key(key).arg(delta).arg(member), as.number),
|
|
383
|
+
/**
|
|
384
|
+
* Removes and returns the `count` members with the lowest scores, each with
|
|
385
|
+
* its score: read it with {@link Reply.scoredMembers}.
|
|
386
|
+
*/
|
|
387
|
+
zpopmin: write((key, count) => cmd('ZPOPMIN').key(key).arg(count), as.reply),
|
|
388
|
+
/**
|
|
389
|
+
* Removes and returns the `count` members with the highest scores, each
|
|
390
|
+
* with its score: read it with {@link Reply.scoredMembers}.
|
|
391
|
+
*/
|
|
392
|
+
zpopmax: write((key, count) => cmd('ZPOPMAX').key(key).arg(count), as.reply),
|
|
393
|
+
/**
|
|
394
|
+
* Removes the members with a score from `min` to `max`, returning how many.
|
|
395
|
+
*/
|
|
396
|
+
zrembyscore: write((key, min, max) => cmd('ZREMRANGEBYSCORE').key(key).arg(min).arg(max), as.number),
|
|
397
|
+
/** Removes the members ranked `start` to `stop`, returning how many. */
|
|
398
|
+
zremrangebyrank: write((key, start, stop) => cmd('ZREMRANGEBYRANK').key(key).arg(start).arg(stop), as.number),
|
|
399
|
+
/**
|
|
400
|
+
* Stores at `destination` the members in every one of the sets, their
|
|
401
|
+
* scores summed. Returns its size.
|
|
402
|
+
*/
|
|
403
|
+
zinterstore: write((destination, ...keys) => cmd('ZINTERSTORE').key(destination).numkeys(keys), as.number),
|
|
404
|
+
/**
|
|
405
|
+
* Stores at `destination` the members in any of the sets, their scores
|
|
406
|
+
* summed. Returns its size.
|
|
407
|
+
*/
|
|
408
|
+
zunionstore: write((destination, ...keys) => cmd('ZUNIONSTORE').key(destination).numkeys(keys), as.number),
|
|
409
|
+
};
|
|
410
|
+
const geo = {
|
|
411
|
+
/**
|
|
412
|
+
* The positions of the members, each missing one as nil: read it with
|
|
413
|
+
* {@link Reply.geoPositions}.
|
|
414
|
+
*/
|
|
415
|
+
geoPos: read((key, ...members) => cmd('GEOPOS').key(key).argsOf(members), as.reply),
|
|
416
|
+
/** The distance between two members: `null` if either is not a member. */
|
|
417
|
+
geoDist: read((key, from, to, unit) => cmd('GEODIST').key(key).arg(from).arg(to).arg(unit), as.optionalNumber),
|
|
418
|
+
/** The geohash of each member. */
|
|
419
|
+
geoHash: read((key, ...members) => cmd('GEOHASH').key(key).argsOf(members), as.reply),
|
|
420
|
+
/**
|
|
421
|
+
* The members within `radius` of a position: read it with
|
|
422
|
+
* {@link Reply.geoRadius}.
|
|
423
|
+
*/
|
|
424
|
+
geoRadius: read((key, longitude, latitude, radius, unit, options) => cmd('GEORADIUS_RO')
|
|
425
|
+
.key(key)
|
|
426
|
+
.arg(longitude)
|
|
427
|
+
.arg(latitude)
|
|
428
|
+
.arg(radius)
|
|
429
|
+
.arg(unit)
|
|
430
|
+
.argsOf(radiusArgs(options)), as.reply),
|
|
431
|
+
/**
|
|
432
|
+
* The members within `radius` of another member: read it with
|
|
433
|
+
* {@link Reply.geoRadius}.
|
|
434
|
+
*/
|
|
435
|
+
geoRadiusByMember: read((key, member, radius, unit, options) => cmd('GEORADIUSBYMEMBER_RO')
|
|
436
|
+
.key(key)
|
|
437
|
+
.arg(member)
|
|
438
|
+
.arg(radius)
|
|
439
|
+
.arg(unit)
|
|
440
|
+
.argsOf(radiusArgs(options)), as.reply),
|
|
441
|
+
/** Adds a member at a position, or moves it there. Returns 1 if it is new. */
|
|
442
|
+
geoAdd: write((key, longitude, latitude, member) => cmd('GEOADD').key(key).arg(longitude).arg(latitude).arg(member), as.number),
|
|
443
|
+
};
|
|
444
|
+
const stream = {
|
|
445
|
+
/**
|
|
446
|
+
* The entries with an id from `start` to `end`, oldest first. `"-"` and
|
|
447
|
+
* `"+"` are the lowest and highest ids. Read it with
|
|
448
|
+
* {@link Reply.streamEntries}.
|
|
449
|
+
*/
|
|
450
|
+
xrange: read((key, start, end) => cmd('XRANGE').key(key).arg(start).arg(end), as.reply),
|
|
451
|
+
/** `xrange`, at most `count` entries. */
|
|
452
|
+
xrangeCount: read((key, start, end, count) => cmd('XRANGE').key(key).arg(start).arg(end).arg('COUNT').arg(count), as.reply),
|
|
453
|
+
/** The entries with an id from `end` down to `start`, newest first. */
|
|
454
|
+
xrevrange: read((key, end, start) => cmd('XREVRANGE').key(key).arg(end).arg(start), as.reply),
|
|
455
|
+
/** `xrevrange`, at most `count` entries. */
|
|
456
|
+
xrevrangeCount: read((key, end, start, count) => cmd('XREVRANGE').key(key).arg(end).arg(start).arg('COUNT').arg(count), as.reply),
|
|
457
|
+
/** How many entries the stream has. */
|
|
458
|
+
xlen: read((key) => cmd('XLEN').key(key), as.number),
|
|
459
|
+
/**
|
|
460
|
+
* The entries after an id in each of the streams, `ids` giving the id for
|
|
461
|
+
* each of `keys` in order. Returns at once with what is there. Read it with
|
|
462
|
+
* {@link Reply.streams}.
|
|
463
|
+
*/
|
|
464
|
+
xread: read((keys, ids) => cmd('XREAD').arg('STREAMS').keys(keys).argsOf(ids).withReplyKeys(), as.reply),
|
|
465
|
+
/**
|
|
466
|
+
* A summary of the entries a consumer group has been given and not
|
|
467
|
+
* acknowledged: read it with {@link Reply.streamPending}.
|
|
468
|
+
*/
|
|
469
|
+
xpending: read((key, group) => cmd('XPENDING').key(key).arg(group), as.reply),
|
|
470
|
+
/**
|
|
471
|
+
* What the server knows about the stream: read it with
|
|
472
|
+
* {@link Reply.streamInfo}.
|
|
473
|
+
*/
|
|
474
|
+
xinfoStream: read((key) => cmd('XINFO').arg('STREAM').key(key), as.reply),
|
|
475
|
+
/**
|
|
476
|
+
* Appends an entry with the given fields, replying its id. Pass `"*"` as
|
|
477
|
+
* the id to have the server choose it.
|
|
478
|
+
*/
|
|
479
|
+
xadd: write((key, id, fields) => cmd('XADD').key(key).arg(id).fields(fields), as.reply),
|
|
480
|
+
/** `xadd`, trimming the stream to a maximum length. */
|
|
481
|
+
xaddMaxlen: write((key, maxlen, id, fields) => cmd('XADD').key(key).argsOf(maxlenArgs(maxlen)).arg(id).fields(fields), as.reply),
|
|
482
|
+
/** Deletes the entries with the given ids, returning how many existed. */
|
|
483
|
+
xdel: write((key, ...ids) => cmd('XDEL').key(key).argsOf(ids), as.number),
|
|
484
|
+
/**
|
|
485
|
+
* Trims the stream to a maximum length, returning how many entries were
|
|
486
|
+
* removed.
|
|
487
|
+
*/
|
|
488
|
+
xtrim: write((key, maxlen) => cmd('XTRIM').key(key).argsOf(maxlenArgs(maxlen)), as.number),
|
|
489
|
+
/**
|
|
490
|
+
* Creates a consumer group that starts reading after `id`: `"$"` for only
|
|
491
|
+
* new entries, `"0"` for all. The stream must exist.
|
|
492
|
+
*/
|
|
493
|
+
xgroupCreate: write((key, group, id) => cmd('XGROUP').arg('CREATE').key(key).arg(group).arg(id), as.none),
|
|
494
|
+
/** `xgroupCreate`, creating the stream if it does not exist. */
|
|
495
|
+
xgroupCreateMkstream: write((key, group, id) => cmd('XGROUP').arg('CREATE').key(key).arg(group).arg(id).arg('MKSTREAM'), as.none),
|
|
496
|
+
/** Deletes a consumer group. `false` if there was none. */
|
|
497
|
+
xgroupDestroy: write((key, group) => cmd('XGROUP').arg('DESTROY').key(key).arg(group), as.bool),
|
|
498
|
+
/**
|
|
499
|
+
* Reads entries as `consumer` of a group: `">"` as the id for the ones no
|
|
500
|
+
* consumer has been given yet. With a `count`, at most that many per
|
|
501
|
+
* stream. A write: it records them as given to the consumer. Read it with
|
|
502
|
+
* {@link Reply.streams}.
|
|
503
|
+
*/
|
|
504
|
+
xreadGroup: write((group, consumer, keys, ids, count) => cmd('XREADGROUP')
|
|
505
|
+
.arg('GROUP')
|
|
506
|
+
.arg(group)
|
|
507
|
+
.arg(consumer)
|
|
508
|
+
.argsOf(count === undefined ? [] : ['COUNT', count])
|
|
509
|
+
.arg('STREAMS')
|
|
510
|
+
.keys(keys)
|
|
511
|
+
.argsOf(ids)
|
|
512
|
+
.withReplyKeys(), as.reply),
|
|
513
|
+
/**
|
|
514
|
+
* Acknowledges entries a consumer group was given, returning how many were
|
|
515
|
+
* pending.
|
|
516
|
+
*/
|
|
517
|
+
xack: write((key, group, ...ids) => cmd('XACK').key(key).arg(group).argsOf(ids), as.number),
|
|
518
|
+
/**
|
|
519
|
+
* Takes over pending entries that have been idle for `minIdleMs`, for
|
|
520
|
+
* `consumer`: read it with {@link Reply.streamEntries}.
|
|
521
|
+
*/
|
|
522
|
+
xclaim: write((key, group, consumer, minIdleMs, ...ids) => cmd('XCLAIM')
|
|
523
|
+
.key(key)
|
|
524
|
+
.arg(group)
|
|
525
|
+
.arg(consumer)
|
|
526
|
+
.arg(minIdleMs)
|
|
527
|
+
.argsOf(ids), as.reply),
|
|
528
|
+
/**
|
|
529
|
+
* Takes over the pending entries from id `start` that have been idle for
|
|
530
|
+
* `minIdleMs`, for `consumer`: read it with {@link Reply.streamAutoClaim}.
|
|
531
|
+
*/
|
|
532
|
+
xautoclaim: write((key, group, consumer, minIdleMs, start) => cmd('XAUTOCLAIM')
|
|
533
|
+
.key(key)
|
|
534
|
+
.arg(group)
|
|
535
|
+
.arg(consumer)
|
|
536
|
+
.arg(minIdleMs)
|
|
537
|
+
.arg(start), as.reply),
|
|
538
|
+
};
|
|
539
|
+
const pubsub = {
|
|
540
|
+
/** Subscribes to one or more channels, on a connection of its own. */
|
|
541
|
+
subscribe: readRun((t, ...channels) => subscribe(t, channels, [])),
|
|
542
|
+
/**
|
|
543
|
+
* Subscribes to the channels matching one or more glob-style patterns, on a
|
|
544
|
+
* connection of its own.
|
|
545
|
+
*/
|
|
546
|
+
psubscribe: readRun((t, ...patterns) => subscribe(t, [], patterns)),
|
|
547
|
+
/**
|
|
548
|
+
* Publishes a message to a channel, returning how many subscribers received
|
|
549
|
+
* it. A channel is prefixed like a key, so only this database's subscribers
|
|
550
|
+
* hear it.
|
|
551
|
+
*/
|
|
552
|
+
publish: write((channel, message) => cmd('PUBLISH').key(channel).arg(message), as.number),
|
|
553
|
+
};
|
|
554
|
+
/** Every group, by the name it has on a database. */
|
|
555
|
+
const groups = {
|
|
556
|
+
generic,
|
|
557
|
+
string,
|
|
558
|
+
bitmap,
|
|
559
|
+
hash,
|
|
560
|
+
list,
|
|
561
|
+
set,
|
|
562
|
+
sortedSet,
|
|
563
|
+
geo,
|
|
564
|
+
stream,
|
|
565
|
+
pubsub,
|
|
566
|
+
};
|
|
567
|
+
/** `setEx` as a trace names it, after the Rust SDK: `set_ex`. */
|
|
568
|
+
function operation(name) {
|
|
569
|
+
return name.replace(/[A-Z]/g, c => `_${c.toLowerCase()}`);
|
|
570
|
+
}
|
|
571
|
+
/** The command `def` builds from `args`, named and marked as it is. */
|
|
572
|
+
function built(op, def, args) {
|
|
573
|
+
const c = def.build(...args);
|
|
574
|
+
const out = new Cmd(op, c.name, def.write);
|
|
575
|
+
out.args.push(...c.args);
|
|
576
|
+
out.replyKeys = c.replyKeys;
|
|
577
|
+
return out;
|
|
578
|
+
}
|
|
579
|
+
function runForms(t, readOnly) {
|
|
580
|
+
const out = {};
|
|
581
|
+
for (const [groupName, group] of Object.entries(groups)) {
|
|
582
|
+
const forms = {};
|
|
583
|
+
for (const [name, def] of Object.entries(group)) {
|
|
584
|
+
if (readOnly && def.write)
|
|
585
|
+
continue;
|
|
586
|
+
if ('run' in def) {
|
|
587
|
+
forms[name] = (...args) => def.run(t, ...args);
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
const op = operation(name);
|
|
591
|
+
if (def.reply === as.reply) {
|
|
592
|
+
// Any error, the command's or that of sending it, is the reply's to
|
|
593
|
+
// report when read.
|
|
594
|
+
forms[name] = (...args) => new ReplyPromise((async () => {
|
|
595
|
+
try {
|
|
596
|
+
return new Reply(await t.run(built(op, def, args)));
|
|
597
|
+
}
|
|
598
|
+
catch (err) {
|
|
599
|
+
return Reply.failed(err);
|
|
600
|
+
}
|
|
601
|
+
})());
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
forms[name] = async (...args) => def.reply(await t.run(built(op, def, args)));
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
out[groupName] = Object.freeze(forms);
|
|
608
|
+
}
|
|
609
|
+
return Object.freeze(out);
|
|
610
|
+
}
|
|
611
|
+
/** The command groups of `t`, each running its commands as they are called. */
|
|
612
|
+
export function commandGroups(t) {
|
|
613
|
+
return runForms(t, false);
|
|
614
|
+
}
|
|
615
|
+
/** The command groups of `t` that only read. */
|
|
616
|
+
export function readCommandGroups(t) {
|
|
617
|
+
return runForms(t, true);
|
|
618
|
+
}
|
|
619
|
+
/** The command groups of a pipeline or a transaction, queueing on `queue`. */
|
|
620
|
+
export function queueGroups(queue) {
|
|
621
|
+
const out = {};
|
|
622
|
+
for (const [groupName, group] of Object.entries(groups)) {
|
|
623
|
+
const forms = {};
|
|
624
|
+
for (const [name, def] of Object.entries(group)) {
|
|
625
|
+
if (!('build' in def))
|
|
626
|
+
continue;
|
|
627
|
+
const op = operation(name);
|
|
628
|
+
forms[name] = (...args) => {
|
|
629
|
+
queue.push(built(op, def, args));
|
|
630
|
+
return forms;
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
out[groupName] = Object.freeze(forms);
|
|
634
|
+
}
|
|
635
|
+
return Object.freeze(out);
|
|
636
|
+
}
|
|
637
|
+
//# sourceMappingURL=commands.js.map
|