encore.dev 1.54.2 → 1.55.0
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/config/secrets.ts +7 -1
- package/dist/config/secrets.js +4 -0
- package/dist/config/secrets.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +3 -1
- package/dist/internal/runtime/napi/napi.d.cts +114 -1
- package/dist/storage/cache/basic.d.ts +268 -0
- package/dist/storage/cache/basic.js +383 -0
- package/dist/storage/cache/basic.js.map +1 -0
- package/dist/storage/cache/cluster.d.ts +48 -0
- package/dist/storage/cache/cluster.js +40 -0
- package/dist/storage/cache/cluster.js.map +1 -0
- package/dist/storage/cache/errors.d.ts +19 -0
- package/dist/storage/cache/errors.js +59 -0
- package/dist/storage/cache/errors.js.map +1 -0
- package/dist/storage/cache/expiry.d.ts +55 -0
- package/dist/storage/cache/expiry.js +74 -0
- package/dist/storage/cache/expiry.js.map +1 -0
- package/dist/storage/cache/keyspace.d.ts +77 -0
- package/dist/storage/cache/keyspace.js +100 -0
- package/dist/storage/cache/keyspace.js.map +1 -0
- package/dist/storage/cache/list.d.ts +249 -0
- package/dist/storage/cache/list.js +376 -0
- package/dist/storage/cache/list.js.map +1 -0
- package/dist/storage/cache/mod.d.ts +10 -0
- package/dist/storage/cache/mod.js +13 -0
- package/dist/storage/cache/mod.js.map +1 -0
- package/dist/storage/cache/set.d.ts +258 -0
- package/dist/storage/cache/set.js +411 -0
- package/dist/storage/cache/set.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/internal/runtime/napi/napi.cjs +3 -1
- package/internal/runtime/napi/napi.d.cts +114 -1
- package/package.json +6 -1
- package/storage/cache/basic.ts +511 -0
- package/storage/cache/cluster.ts +67 -0
- package/storage/cache/errors.ts +66 -0
- package/storage/cache/expiry.ts +98 -0
- package/storage/cache/keyspace.ts +142 -0
- package/storage/cache/list.ts +496 -0
- package/storage/cache/mod.ts +36 -0
- package/storage/cache/set.ts +491 -0
package/config/secrets.ts
CHANGED
|
@@ -48,13 +48,19 @@ export type AnySecret = Secret<string>;
|
|
|
48
48
|
* const foo = secret<"foo">();
|
|
49
49
|
*/
|
|
50
50
|
export function secret<Name extends string>(
|
|
51
|
-
name: StringLiteral<Name
|
|
51
|
+
name: StringLiteral<Name>
|
|
52
52
|
): Secret<Name> {
|
|
53
53
|
// Get the secret implementation from the runtime.
|
|
54
54
|
// It reports null if the secret isn't in the runtime config.
|
|
55
55
|
const impl = runtime.RT.secret(name);
|
|
56
56
|
const secretObj = () => {
|
|
57
57
|
if (impl === null) {
|
|
58
|
+
// During local development we don't consider missing secrets a fatal error.
|
|
59
|
+
if (
|
|
60
|
+
runtime.RT.appMeta().environment.cloud === runtime.CloudProvider.Local
|
|
61
|
+
) {
|
|
62
|
+
return "";
|
|
63
|
+
}
|
|
58
64
|
throw new Error(`secret ${name} is not set`);
|
|
59
65
|
}
|
|
60
66
|
return impl.cached();
|
package/dist/config/secrets.js
CHANGED
|
@@ -14,6 +14,10 @@ export function secret(name) {
|
|
|
14
14
|
const impl = runtime.RT.secret(name);
|
|
15
15
|
const secretObj = () => {
|
|
16
16
|
if (impl === null) {
|
|
17
|
+
// During local development we don't consider missing secrets a fatal error.
|
|
18
|
+
if (runtime.RT.appMeta().environment.cloud === runtime.CloudProvider.Local) {
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
17
21
|
throw new Error(`secret ${name} is not set`);
|
|
18
22
|
}
|
|
19
23
|
return impl.cached();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../config/secrets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AAwCnD;;;;;;;;GAQG;AACH,MAAM,UAAU,MAAM,CACpB,IAAyB;IAEzB,kDAAkD;IAClD,6DAA6D;IAC7D,MAAM,IAAI,GAAG,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,SAAS,GAAG,GAAG,EAAE;QACrB,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,UAAU,IAAI,aAAa,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC,CAAC;IAEF,SAAS,CAAC,QAAQ,GAAG,GAAG,EAAE;QACxB,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,OAAO,UAAU,IAAI,YAAY,CAAC;QACpC,CAAC;QACD,OAAO,UAAU,IAAI,cAAc,CAAC;IACtC,CAAC,CAAC;IACF,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAE1D,OAAO,SAAoC,CAAC;AAC9C,CAAC"}
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../config/secrets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AAwCnD;;;;;;;;GAQG;AACH,MAAM,UAAU,MAAM,CACpB,IAAyB;IAEzB,kDAAkD;IAClD,6DAA6D;IAC7D,MAAM,IAAI,GAAG,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,SAAS,GAAG,GAAG,EAAE;QACrB,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,4EAA4E;YAC5E,IACE,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,KAAK,KAAK,OAAO,CAAC,aAAa,CAAC,KAAK,EACtE,CAAC;gBACD,OAAO,EAAE,CAAC;YACZ,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,UAAU,IAAI,aAAa,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC,CAAC;IAEF,SAAS,CAAC,QAAQ,GAAG,GAAG,EAAE;QACxB,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,OAAO,UAAU,IAAI,YAAY,CAAC;QACpC,CAAC;QACD,OAAO,UAAU,IAAI,cAAc,CAAC;IACtC,CAAC,CAAC;IACF,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAE1D,OAAO,SAAoC,CAAC;AAC9C,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The version of the runtime this JS bundle was generated for.
|
|
2
|
-
const version = "v1.
|
|
2
|
+
const version = "v1.55.0";
|
|
3
3
|
|
|
4
4
|
// Load the native module.
|
|
5
5
|
const nativeModulePath = process.env.ENCORE_RUNTIME_LIB;
|
|
@@ -17,6 +17,7 @@ const {
|
|
|
17
17
|
BodyReader,
|
|
18
18
|
Bucket,
|
|
19
19
|
BucketObject,
|
|
20
|
+
CacheCluster,
|
|
20
21
|
CloudProvider,
|
|
21
22
|
Cursor,
|
|
22
23
|
Decimal,
|
|
@@ -57,6 +58,7 @@ module.exports = {
|
|
|
57
58
|
BodyReader,
|
|
58
59
|
Bucket,
|
|
59
60
|
BucketObject,
|
|
61
|
+
CacheCluster,
|
|
60
62
|
CloudProvider,
|
|
61
63
|
Cursor,
|
|
62
64
|
Decimal,
|
|
@@ -74,6 +74,119 @@ export interface BuildMeta {
|
|
|
74
74
|
uncommittedChanges: boolean
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/** A cache cluster for storing cached data. */
|
|
78
|
+
export class CacheCluster {
|
|
79
|
+
/** Get a value by key. */
|
|
80
|
+
get(key: string, source?: Request | undefined | null): Promise<Buffer | null>
|
|
81
|
+
/** Set a value by key with optional TTL. */
|
|
82
|
+
set(key: string, value: Buffer, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<void>
|
|
83
|
+
/** Set a value only if the key doesn't exist. */
|
|
84
|
+
setIfNotExists(key: string, value: Buffer, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<boolean>
|
|
85
|
+
/** Replace a value only if the key exists. */
|
|
86
|
+
replace(key: string, value: Buffer, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<boolean>
|
|
87
|
+
/** Get old value and set new value atomically. */
|
|
88
|
+
getAndSet(key: string, value: Buffer, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<Buffer | null>
|
|
89
|
+
/** Get value and delete key atomically. */
|
|
90
|
+
getAndDelete(key: string, source?: Request | undefined | null): Promise<Buffer | null>
|
|
91
|
+
/** Delete one or more keys. */
|
|
92
|
+
delete(keys: Array<string>, source?: Request | undefined | null): Promise<number>
|
|
93
|
+
/** Get multiple values. */
|
|
94
|
+
mget(keys: Array<string>, source?: Request | undefined | null): Promise<Array<Buffer | undefined | null>>
|
|
95
|
+
/** Append to a string value. */
|
|
96
|
+
append(key: string, value: Buffer, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
97
|
+
/** Get a substring of a string value. */
|
|
98
|
+
getRange(key: string, start: number, end: number, source?: Request | undefined | null): Promise<Buffer>
|
|
99
|
+
/** Set a substring at a specific offset. */
|
|
100
|
+
setRange(key: string, offset: number, value: Buffer, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
101
|
+
/** Get string length. */
|
|
102
|
+
strlen(key: string, source?: Request | undefined | null): Promise<number>
|
|
103
|
+
/** Increment an integer value. */
|
|
104
|
+
incrBy(key: string, delta: number, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
105
|
+
/** Decrement an integer value. */
|
|
106
|
+
decrBy(key: string, delta: number, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
107
|
+
/** Increment a float value. */
|
|
108
|
+
incrByFloat(key: string, delta: number, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
109
|
+
/** Push values to the left (head) of a list. */
|
|
110
|
+
lpush(key: string, values: Array<Buffer>, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
111
|
+
/** Push values to the right (tail) of a list. */
|
|
112
|
+
rpush(key: string, values: Array<Buffer>, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
113
|
+
/**
|
|
114
|
+
* Pop a value from the left (head) of a list.
|
|
115
|
+
* Returns null if the list is empty or doesn't exist.
|
|
116
|
+
*/
|
|
117
|
+
lpop(key: string, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<Buffer | null>
|
|
118
|
+
/**
|
|
119
|
+
* Pop a value from the right (tail) of a list.
|
|
120
|
+
* Returns null if the list is empty or doesn't exist.
|
|
121
|
+
*/
|
|
122
|
+
rpop(key: string, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<Buffer | null>
|
|
123
|
+
/** Get element at index from a list. */
|
|
124
|
+
lindex(key: string, index: number, source?: Request | undefined | null): Promise<Buffer | null>
|
|
125
|
+
/** Get a range of elements from a list. */
|
|
126
|
+
lrange(key: string, start: number, stop: number, source?: Request | undefined | null): Promise<Array<Buffer>>
|
|
127
|
+
/** Get all elements of a list (traced as "items"). */
|
|
128
|
+
lrangeAll(key: string, source?: Request | undefined | null): Promise<Array<Buffer>>
|
|
129
|
+
/** Get list length. */
|
|
130
|
+
llen(key: string, source?: Request | undefined | null): Promise<number>
|
|
131
|
+
/** Trim a list to the specified range. */
|
|
132
|
+
ltrim(key: string, start: number, stop: number, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<void>
|
|
133
|
+
/** Set element at index in list. */
|
|
134
|
+
lset(key: string, index: number, value: Buffer, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<void>
|
|
135
|
+
/** Insert value before pivot in list. */
|
|
136
|
+
linsertBefore(key: string, pivot: Buffer, value: Buffer, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
137
|
+
/** Insert value after pivot in list. */
|
|
138
|
+
linsertAfter(key: string, pivot: Buffer, value: Buffer, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
139
|
+
/** Remove elements from list. */
|
|
140
|
+
lremAll(key: string, value: Buffer, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
141
|
+
/** Remove elements from list. */
|
|
142
|
+
lremFirst(key: string, count: number, value: Buffer, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
143
|
+
/** Remove elements from list. */
|
|
144
|
+
lremLast(key: string, count: number, value: Buffer, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
145
|
+
/** Move element between lists atomically. */
|
|
146
|
+
lmove(src: string, dst: string, srcDir: string, dstDir: string, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<Buffer | null>
|
|
147
|
+
/** Add members to a set. */
|
|
148
|
+
sadd(key: string, members: Array<Buffer>, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
149
|
+
/** Remove members from a set. */
|
|
150
|
+
srem(key: string, members: Array<Buffer>, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
151
|
+
/** Check if member exists in set. */
|
|
152
|
+
sismember(key: string, member: Buffer, source?: Request | undefined | null): Promise<boolean>
|
|
153
|
+
/** Get all members of a set. */
|
|
154
|
+
smembers(key: string, source?: Request | undefined | null): Promise<Array<Buffer>>
|
|
155
|
+
/** Get set cardinality. */
|
|
156
|
+
scard(key: string, source?: Request | undefined | null): Promise<number>
|
|
157
|
+
/**
|
|
158
|
+
* Pop a single random member from a set.
|
|
159
|
+
* Returns null if the set is empty or doesn't exist.
|
|
160
|
+
*/
|
|
161
|
+
spop(key: string, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<Buffer | null>
|
|
162
|
+
/** Pop random members from a set. */
|
|
163
|
+
spopN(key: string, count: number, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<Array<Buffer>>
|
|
164
|
+
/**
|
|
165
|
+
* Get a single random member from a set (without removing).
|
|
166
|
+
* Returns null if the set is empty or doesn't exist.
|
|
167
|
+
*/
|
|
168
|
+
srandmember(key: string, source?: Request | undefined | null): Promise<Buffer | null>
|
|
169
|
+
/**
|
|
170
|
+
* Get random members from a set (without removing).
|
|
171
|
+
* Positive count returns distinct elements, negative count may return duplicates.
|
|
172
|
+
*/
|
|
173
|
+
srandmemberN(key: string, count: number, source?: Request | undefined | null): Promise<Array<Buffer>>
|
|
174
|
+
/** Get the difference between sets. */
|
|
175
|
+
sdiff(keys: Array<string>, source?: Request | undefined | null): Promise<Array<Buffer>>
|
|
176
|
+
/** Store the difference between sets. */
|
|
177
|
+
sdiffstore(destination: string, keys: Array<string>, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
178
|
+
/** Get the intersection of sets. */
|
|
179
|
+
sinter(keys: Array<string>, source?: Request | undefined | null): Promise<Array<Buffer>>
|
|
180
|
+
/** Store the intersection of sets. */
|
|
181
|
+
sinterstore(destination: string, keys: Array<string>, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
182
|
+
/** Get the union of sets. */
|
|
183
|
+
sunion(keys: Array<string>, source?: Request | undefined | null): Promise<Array<Buffer>>
|
|
184
|
+
/** Store the union of sets. */
|
|
185
|
+
sunionstore(destination: string, keys: Array<string>, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<number>
|
|
186
|
+
/** Move member from one set to another. */
|
|
187
|
+
smove(src: string, dst: string, member: Buffer, ttlMs?: number | undefined | null, source?: Request | undefined | null): Promise<boolean>
|
|
188
|
+
}
|
|
189
|
+
|
|
77
190
|
/** CallOpts can be used to set options for API calls. */
|
|
78
191
|
export interface CallOpts {
|
|
79
192
|
authData?: PVals
|
|
@@ -279,6 +392,7 @@ export class Runtime {
|
|
|
279
392
|
sqlDatabase(encoreName: string): SQLDatabase
|
|
280
393
|
pubsubTopic(encoreName: string): PubSubTopic
|
|
281
394
|
bucket(encoreName: string): Bucket
|
|
395
|
+
cacheCluster(encoreName: string): CacheCluster
|
|
282
396
|
gateway(encoreName: string, cfg: GatewayConfig): Gateway
|
|
283
397
|
/** Gets the root logger from the runtime */
|
|
284
398
|
logger(): Logger
|
|
@@ -307,7 +421,6 @@ export class Runtime {
|
|
|
307
421
|
createMetricsRegistry(buffer: object): void
|
|
308
422
|
/** Get the shared metrics registry (all worker threads use this) */
|
|
309
423
|
getMetricsRegistry(): MetricsRegistry
|
|
310
|
-
|
|
311
424
|
}
|
|
312
425
|
|
|
313
426
|
export interface RuntimeConfig {
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { CacheCluster } from "./cluster.js";
|
|
3
|
+
import { Keyspace, KeyspaceConfig, WriteOptions } from "./keyspace.js";
|
|
4
|
+
/**
|
|
5
|
+
* Base class for basic (scalar value) keyspaces.
|
|
6
|
+
* Provides get/set/replace/etc operations.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
declare abstract class BasicKeyspace<K, V> extends Keyspace<K> {
|
|
10
|
+
constructor(cluster: CacheCluster, config: KeyspaceConfig<K>);
|
|
11
|
+
/**
|
|
12
|
+
* Serializes a value to a Buffer for storage.
|
|
13
|
+
*/
|
|
14
|
+
protected abstract serialize(value: V): Buffer;
|
|
15
|
+
/**
|
|
16
|
+
* Deserializes a Buffer from storage to a value.
|
|
17
|
+
*/
|
|
18
|
+
protected abstract deserialize(data: Buffer): V;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the value stored at key.
|
|
21
|
+
* If the key does not exist, it returns `undefined`.
|
|
22
|
+
*
|
|
23
|
+
* @returns The value, or `undefined` if the key does not exist.
|
|
24
|
+
* @see https://redis.io/commands/get/
|
|
25
|
+
*/
|
|
26
|
+
get(key: K): Promise<V | undefined>;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the values stored at multiple keys.
|
|
29
|
+
*
|
|
30
|
+
* @returns An array of values in the same order as the provided keys.
|
|
31
|
+
* Each element is the value or `undefined` if the key was not found.
|
|
32
|
+
* @see https://redis.io/commands/mget/
|
|
33
|
+
*/
|
|
34
|
+
multiGet(...keys: K[]): Promise<(V | undefined)[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Updates the value stored at key to val.
|
|
37
|
+
*
|
|
38
|
+
* @see https://redis.io/commands/set/
|
|
39
|
+
*/
|
|
40
|
+
set(key: K, value: V, options?: WriteOptions): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Sets the value stored at key to val, but only if the key does not exist beforehand.
|
|
43
|
+
*
|
|
44
|
+
* @throws {CacheKeyExists} If the key already exists.
|
|
45
|
+
* @see https://redis.io/commands/setnx/
|
|
46
|
+
*/
|
|
47
|
+
setIfNotExists(key: K, value: V, options?: WriteOptions): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Replaces the existing value stored at key to val.
|
|
50
|
+
*
|
|
51
|
+
* @throws {CacheMiss} If the key does not already exist.
|
|
52
|
+
* @see https://redis.io/commands/set/
|
|
53
|
+
*/
|
|
54
|
+
replace(key: K, value: V, options?: WriteOptions): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Updates the value of key to val and returns the previously stored value.
|
|
57
|
+
* If the key does not already exist, it sets it and returns `undefined`.
|
|
58
|
+
*
|
|
59
|
+
* @returns The previous value, or `undefined` if the key did not exist.
|
|
60
|
+
* @see https://redis.io/commands/getset/
|
|
61
|
+
*/
|
|
62
|
+
getAndSet(key: K, value: V, options?: WriteOptions): Promise<V | undefined>;
|
|
63
|
+
/**
|
|
64
|
+
* Deletes the key and returns the previously stored value.
|
|
65
|
+
* If the key does not already exist, it returns `undefined`.
|
|
66
|
+
*
|
|
67
|
+
* @returns The previous value, or `undefined` if the key did not exist.
|
|
68
|
+
* @see https://redis.io/commands/getdel/
|
|
69
|
+
*/
|
|
70
|
+
getAndDelete(key: K): Promise<V | undefined>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* StringKeyspace stores string values.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const tokens = new StringKeyspace<string>(cluster, {
|
|
78
|
+
* keyPattern: "token/:id",
|
|
79
|
+
* defaultExpiry: ExpireIn(3600000), // 1 hour
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* await tokens.set("abc123", "user-token-value");
|
|
83
|
+
* const token = await tokens.get("abc123");
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare class StringKeyspace<K> extends BasicKeyspace<K, string> {
|
|
87
|
+
constructor(cluster: CacheCluster, config: KeyspaceConfig<K>);
|
|
88
|
+
protected serialize(value: string): Buffer;
|
|
89
|
+
protected deserialize(data: Buffer): string;
|
|
90
|
+
/**
|
|
91
|
+
* Appends a string to the value stored at key.
|
|
92
|
+
*
|
|
93
|
+
* If the key does not exist it is first created and set as the empty string,
|
|
94
|
+
* causing append to behave like set.
|
|
95
|
+
*
|
|
96
|
+
* @returns The new string length.
|
|
97
|
+
* @see https://redis.io/commands/append/
|
|
98
|
+
*/
|
|
99
|
+
append(key: K, value: string, options?: WriteOptions): Promise<number>;
|
|
100
|
+
/**
|
|
101
|
+
* Returns a substring of the string value stored at key.
|
|
102
|
+
*
|
|
103
|
+
* The `start` and `end` values are zero-based indices, but unlike typical slicing
|
|
104
|
+
* the `end` value is inclusive.
|
|
105
|
+
*
|
|
106
|
+
* Negative values can be used in order to provide an offset starting
|
|
107
|
+
* from the end of the string, so -1 means the last character.
|
|
108
|
+
*
|
|
109
|
+
* If the string does not exist it returns the empty string.
|
|
110
|
+
*
|
|
111
|
+
* @param key - The cache key.
|
|
112
|
+
* @param start - Start index (inclusive, 0-based).
|
|
113
|
+
* @param end - End index (inclusive, 0-based). Use -1 for end of string.
|
|
114
|
+
* @returns The substring.
|
|
115
|
+
* @see https://redis.io/commands/getrange/
|
|
116
|
+
*/
|
|
117
|
+
getRange(key: K, start: number, end: number): Promise<string>;
|
|
118
|
+
/**
|
|
119
|
+
* Overwrites part of the string stored at key, starting at
|
|
120
|
+
* the zero-based `offset` and for the entire length of `value`, extending
|
|
121
|
+
* the string if necessary.
|
|
122
|
+
*
|
|
123
|
+
* If the offset is larger than the current string length stored at key,
|
|
124
|
+
* the string is first padded with zero-bytes to make offset fit.
|
|
125
|
+
*
|
|
126
|
+
* Non-existing keys are considered as empty strings.
|
|
127
|
+
*
|
|
128
|
+
* @param key - The cache key.
|
|
129
|
+
* @param offset - Zero-based byte offset to start writing at.
|
|
130
|
+
* @param value - The string to write.
|
|
131
|
+
* @returns The length of the string after the operation.
|
|
132
|
+
* @see https://redis.io/commands/setrange/
|
|
133
|
+
*/
|
|
134
|
+
setRange(key: K, offset: number, value: string, options?: WriteOptions): Promise<number>;
|
|
135
|
+
/**
|
|
136
|
+
* Returns the length of the string value stored at key.
|
|
137
|
+
*
|
|
138
|
+
* Non-existing keys are considered as empty strings.
|
|
139
|
+
*
|
|
140
|
+
* @returns The string length.
|
|
141
|
+
* @see https://redis.io/commands/strlen/
|
|
142
|
+
*/
|
|
143
|
+
len(key: K): Promise<number>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* IntKeyspace stores 64-bit integer values.
|
|
147
|
+
* Values are floored to integers using `Math.floor`.
|
|
148
|
+
* For fractional values, use {@link FloatKeyspace} instead.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* const counters = new IntKeyspace<string>(cluster, {
|
|
153
|
+
* keyPattern: "counter/:name",
|
|
154
|
+
* });
|
|
155
|
+
*
|
|
156
|
+
* await counters.set("page-views", 0);
|
|
157
|
+
* const newCount = await counters.increment("page-views", 1);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare class IntKeyspace<K> extends BasicKeyspace<K, number> {
|
|
161
|
+
constructor(cluster: CacheCluster, config: KeyspaceConfig<K>);
|
|
162
|
+
protected serialize(value: number): Buffer;
|
|
163
|
+
protected deserialize(data: Buffer): number;
|
|
164
|
+
/**
|
|
165
|
+
* Increments the number stored at key by `delta`.
|
|
166
|
+
*
|
|
167
|
+
* If the key does not exist it is first created with a value of 0
|
|
168
|
+
* before incrementing.
|
|
169
|
+
*
|
|
170
|
+
* Negative values can be used to decrease the value,
|
|
171
|
+
* but typically you want to use {@link decrement} for that.
|
|
172
|
+
*
|
|
173
|
+
* @param key - The cache key.
|
|
174
|
+
* @param delta - The amount to increment by (default 1).
|
|
175
|
+
* @returns The new value after incrementing.
|
|
176
|
+
* @see https://redis.io/commands/incrby/
|
|
177
|
+
*/
|
|
178
|
+
increment(key: K, delta?: number, options?: WriteOptions): Promise<number>;
|
|
179
|
+
/**
|
|
180
|
+
* Decrements the number stored at key by `delta`.
|
|
181
|
+
*
|
|
182
|
+
* If the key does not exist it is first created with a value of 0
|
|
183
|
+
* before decrementing.
|
|
184
|
+
*
|
|
185
|
+
* Negative values can be used to increase the value,
|
|
186
|
+
* but typically you want to use {@link increment} for that.
|
|
187
|
+
*
|
|
188
|
+
* @param key - The cache key.
|
|
189
|
+
* @param delta - The amount to decrement by (default 1).
|
|
190
|
+
* @returns The new value after decrementing.
|
|
191
|
+
* @see https://redis.io/commands/decrby/
|
|
192
|
+
*/
|
|
193
|
+
decrement(key: K, delta?: number, options?: WriteOptions): Promise<number>;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* FloatKeyspace stores 64-bit floating point values.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* const scores = new FloatKeyspace<string>(cluster, {
|
|
201
|
+
* keyPattern: "score/:playerId",
|
|
202
|
+
* });
|
|
203
|
+
*
|
|
204
|
+
* await scores.set("player1", 100.5);
|
|
205
|
+
* const newScore = await scores.increment("player1", 10.25);
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export declare class FloatKeyspace<K> extends BasicKeyspace<K, number> {
|
|
209
|
+
constructor(cluster: CacheCluster, config: KeyspaceConfig<K>);
|
|
210
|
+
protected serialize(value: number): Buffer;
|
|
211
|
+
protected deserialize(data: Buffer): number;
|
|
212
|
+
/**
|
|
213
|
+
* Increments the number stored at key by `delta`.
|
|
214
|
+
*
|
|
215
|
+
* If the key does not exist it is first created with a value of 0
|
|
216
|
+
* before incrementing.
|
|
217
|
+
*
|
|
218
|
+
* Negative values can be used to decrease the value,
|
|
219
|
+
* but typically you want to use {@link decrement} for that.
|
|
220
|
+
*
|
|
221
|
+
* @param key - The cache key.
|
|
222
|
+
* @param delta - The amount to increment by (default 1).
|
|
223
|
+
* @returns The new value after incrementing.
|
|
224
|
+
* @see https://redis.io/commands/incrbyfloat/
|
|
225
|
+
*/
|
|
226
|
+
increment(key: K, delta?: number, options?: WriteOptions): Promise<number>;
|
|
227
|
+
/**
|
|
228
|
+
* Decrements the number stored at key by `delta`.
|
|
229
|
+
*
|
|
230
|
+
* If the key does not exist it is first created with a value of 0
|
|
231
|
+
* before decrementing.
|
|
232
|
+
*
|
|
233
|
+
* Negative values can be used to increase the value,
|
|
234
|
+
* but typically you want to use {@link increment} for that.
|
|
235
|
+
*
|
|
236
|
+
* @param key - The cache key.
|
|
237
|
+
* @param delta - The amount to decrement by (default 1).
|
|
238
|
+
* @returns The new value after decrementing.
|
|
239
|
+
* @see https://redis.io/commands/incrbyfloat/
|
|
240
|
+
*/
|
|
241
|
+
decrement(key: K, delta?: number, options?: WriteOptions): Promise<number>;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* StructKeyspace stores arbitrary objects serialized as JSON.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* interface User {
|
|
249
|
+
* id: string;
|
|
250
|
+
* name: string;
|
|
251
|
+
* email: string;
|
|
252
|
+
* }
|
|
253
|
+
*
|
|
254
|
+
* const users = new StructKeyspace<string, User>(cluster, {
|
|
255
|
+
* keyPattern: "user/:id",
|
|
256
|
+
* defaultExpiry: ExpireIn(3600000),
|
|
257
|
+
* });
|
|
258
|
+
*
|
|
259
|
+
* await users.set("user1", { id: "user1", name: "Alice", email: "alice@example.com" });
|
|
260
|
+
* const user = await users.get("user1");
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
export declare class StructKeyspace<K, V> extends BasicKeyspace<K, V> {
|
|
264
|
+
constructor(cluster: CacheCluster, config: KeyspaceConfig<K>);
|
|
265
|
+
protected serialize(value: V): Buffer;
|
|
266
|
+
protected deserialize(data: Buffer): V;
|
|
267
|
+
}
|
|
268
|
+
export {};
|