@ti-engine/core 1.12.2 → 1.13.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.
@@ -0,0 +1,327 @@
1
+ export = RedisCacheProvider;
2
+ import CacheProvider = require("#cache-provider");
3
+ import type ConnectionObserver from "#connection-observer";
4
+ /**
5
+ * A {@link CacheProvider} backed by Redis, optionally with the RedisJSON module.
6
+ * <br/>
7
+ * NOTE: This holds every Redis-specific detail in the engine's cache path — the command names, the
8
+ * '[ error, value ]' result shape, and the JSONPath encoding. Nothing above it should know that Redis is what is
9
+ * storing the values.
10
+ *
11
+ * @class RedisCacheProvider
12
+ * @extends CacheProvider
13
+ * @public
14
+ */
15
+ declare class RedisCacheProvider extends CacheProvider {
16
+ #private;
17
+ /**
18
+ * @constructor
19
+ * @param {string} connectionIdentifier The identifier under which this backend's connection is observed.
20
+ */
21
+ constructor(connectionIdentifier: string);
22
+ /**
23
+ * Decodes one entry of a `multi(...).exec()` result into the value it carries.
24
+ * <br/>
25
+ * NOTE: Exposed for testing. The provider builds its own Redis client in its constructor, so `getValues` cannot be
26
+ * driven without a live server — this is one of the pure halves of it, and it is where the defect was.
27
+ *
28
+ * @method
29
+ * @param {Array} [result] One `[ error, value ]` entry.
30
+ * @returns {*} The parsed value, or `undefined` when there is none.
31
+ * @public
32
+ */
33
+ static decodeCommandValue(result?: any[]): any;
34
+ /**
35
+ * Maps a set of requested keys onto the values a `multi(...).exec()` returned for them, using `null` for a miss.
36
+ * <br/>
37
+ * NOTE: Exposed for testing, for the same reason as {@link RedisCacheProvider.decodeCommandValue}.
38
+ *
39
+ * @method
40
+ * @param {string[]} keys The keys that were requested, in command order.
41
+ * @param {Array} [rawResults] The `multi(...).exec()` result.
42
+ * @returns {Object} A null-prototype map of key to value, `null` where the key was absent.
43
+ * @public
44
+ */
45
+ static mapCommandValues(keys: string[], rawResults?: any[]): Object;
46
+ /**
47
+ * Property returning the connection identifier of this backend.
48
+ *
49
+ * @property
50
+ * @returns {string}
51
+ * @public
52
+ */
53
+ get connectionIdentifier(): string;
54
+ /**
55
+ * Property returning the optional behaviors this backend provides.
56
+ * <br/>
57
+ * NOTE: The JSON capabilities depend on the RedisJSON module being installed on the server, which is only known
58
+ * after the client has connected — so this is accurate from {@link RedisCacheProvider#initialize} onward and
59
+ * reports no JSON support before that.
60
+ *
61
+ * @property
62
+ * @returns {string[]}
63
+ * @override
64
+ * @public
65
+ */
66
+ get capabilities(): string[];
67
+ /**
68
+ * Used to initialize the backend and connect to the Redis server.
69
+ *
70
+ * @method
71
+ * @returns {Promise}
72
+ * @override
73
+ * @public
74
+ */
75
+ initialize(): Promise<any>;
76
+ /**
77
+ * Used to gracefully shut the Redis connection down.
78
+ *
79
+ * @method
80
+ * @returns {Promise}
81
+ * @override
82
+ * @public
83
+ */
84
+ shutDown(): Promise<any>;
85
+ /**
86
+ * Used to register a new {@link ConnectionObserver} for events related to the underlying Redis connection state.
87
+ *
88
+ * @method
89
+ * @param {ConnectionObserver} connectionObserver The {@link ConnectionObserver} that will be notified of any changes.
90
+ * @override
91
+ * @public
92
+ */
93
+ addConnectionObserver(connectionObserver: ConnectionObserver): void;
94
+ /**
95
+ * Used to search for keys by a given pattern.
96
+ *
97
+ * @method
98
+ * @param {string} pattern
99
+ * @returns {Promise<Array>}
100
+ * @public
101
+ */
102
+ matchKeys(pattern: string): Promise<any[]>;
103
+ /**
104
+ * Used to set a specific string value.
105
+ *
106
+ * @method
107
+ * @param {string} key
108
+ * @param {string} value
109
+ * @param {number} [expiration] Expiration value is in seconds.
110
+ * @return {Promise<string>}
111
+ * @public
112
+ */
113
+ setValue(key: string, value: string, expiration?: number): Promise<string>;
114
+ /**
115
+ * Used to set multiple string values.
116
+ *
117
+ * @method
118
+ * @param {Object} keyValues
119
+ * @param {string} [prefix]
120
+ * @param {number} [expiration]
121
+ * @return {Promise}
122
+ * @public
123
+ */
124
+ setValues(keyValues: Object, prefix?: string, expiration?: number): Promise<any>;
125
+ /**
126
+ * Used to get a string value.
127
+ *
128
+ * @method
129
+ * @param {string} key
130
+ * @return {Promise}
131
+ * @public
132
+ */
133
+ getValue(key: string): Promise<any>;
134
+ /**
135
+ * Used to get multiple string values.
136
+ *
137
+ * @method
138
+ * @param {string[]} keys
139
+ * @param {string} [prefix]
140
+ * @return {Promise}
141
+ * @public
142
+ */
143
+ getValues(keys: string[], prefix?: string): Promise<any>;
144
+ /**
145
+ * Used to delete a value / item.
146
+ *
147
+ * @method
148
+ * @param {string} key
149
+ * @returns {Promise<boolean>}
150
+ * @public
151
+ */
152
+ deleteValue(key: string): Promise<boolean>;
153
+ /**
154
+ * Used to set expiration in seconds to an existing key.
155
+ * <br/>
156
+ * NOTE: For performance optimization reasons, only use this only if the Redis command does not itself support the 'EX' argument.
157
+ *
158
+ * @method
159
+ * @param {string} key
160
+ * @param {number} seconds
161
+ * @param {string} [name] If you need to expire a field in a hash set instead, provide the name of the set here.
162
+ * @returns {Promise<number>} This will resolve with the seconds as provided initially by the caller.
163
+ * @public
164
+ */
165
+ expireValue(key: string, seconds: number, name?: string): Promise<number>;
166
+ /**
167
+ * Used to add the specified values to a list.
168
+ *
169
+ * @method
170
+ * @param {string} listName
171
+ * @param {Object[]} values
172
+ * @returns {Promise<number>}
173
+ * @public
174
+ */
175
+ listPushValue(listName: string, values: Object[]): Promise<number>;
176
+ /**
177
+ * Used to add the specified value to a set.
178
+ *
179
+ * @method
180
+ * @param {string} key
181
+ * @param {string|Object} value
182
+ * @returns {Promise}
183
+ * @public
184
+ */
185
+ addToSet(key: string, value: string | Object): Promise<any>;
186
+ /**
187
+ * Used to add multiple values to multiple sets in one transactional request.
188
+ * <br/>
189
+ * NOTE: The two arrays of keys and values must have correct index relations (i.e., first pair on keys[0] and values[0] and so on)!
190
+ *
191
+ * @method
192
+ * @param {string[]} keys
193
+ * @param {string[]} values
194
+ * @returns {Promise}
195
+ * @public
196
+ */
197
+ addToSetMulti(keys: string[], values: string[]): Promise<any>;
198
+ /**
199
+ * Used to check if the provided value is a member of the specified set.
200
+ *
201
+ * @method
202
+ * @param {string} setName
203
+ * @param {string} value
204
+ * @returns {Promise<boolean>}
205
+ * @public
206
+ */
207
+ isSetMember(setName: string, value: string): Promise<boolean>;
208
+ /**
209
+ * Used to get all elements of a set.
210
+ *
211
+ * @method
212
+ * @param {string} key
213
+ * @returns {Promise<Object[]>}
214
+ * @public
215
+ */
216
+ membersOfSet(key: string): Promise<Object[]>;
217
+ /**
218
+ * Used to get a union of all elements in the list of sets.
219
+ *
220
+ * @method
221
+ * @param {string[]} keys
222
+ * @returns {Promise<Object[]>}
223
+ * @public
224
+ */
225
+ unionOfSets(keys: string[]): Promise<Object[]>;
226
+ /**
227
+ * Used to set a single hash field.
228
+ *
229
+ * @method
230
+ * @deprecated
231
+ * @param {string} key
232
+ * @param {string} name
233
+ * @param {*} value
234
+ * @returns {Promise}
235
+ * @public
236
+ */
237
+ hashSetField(key: string, name: string, value: any): Promise<any>;
238
+ /**
239
+ * Used to set multiple hash fields.
240
+ *
241
+ * @method
242
+ * @deprecated
243
+ * @param {string} key
244
+ * @param {Object[]} fields
245
+ * @param {string} fields[].name
246
+ * @param {*} fields[].value
247
+ * @returns {Promise}
248
+ * @public
249
+ */
250
+ hashSetFields(key: string, fields: {
251
+ name: string;
252
+ value: any;
253
+ }[]): Promise<any>;
254
+ /**
255
+ * Used to get a single field from a hash.
256
+ *
257
+ * @method
258
+ * @param {string} key
259
+ * @param {string} field
260
+ * @return {Promise}
261
+ * @public
262
+ */
263
+ hashGetField(key: string, field: string): Promise<any>;
264
+ /**
265
+ * Used to remove a single field from a hash.
266
+ *
267
+ * @method
268
+ * @param {string} key
269
+ * @param {string} field
270
+ * @return {Promise<boolean>} Will return 'true' if the field was removed, 'false' otherwise.
271
+ * @public
272
+ */
273
+ hashDeleteField(key: string, field: string): Promise<boolean>;
274
+ /**
275
+ * Used to store a JSON variable.
276
+ * <br/>
277
+ * NOTE: Requires ReJSON module installed on server to work.
278
+ *
279
+ * @method
280
+ * @param {string} key
281
+ * @param {Object} value
282
+ * @param {string|string[]} [path="$"] A dot-separated JSONPath string, or an array of literal key segments (use the array form when key names may contain dots or other special characters).
283
+ * @param {number} [overrideMode=0] By default this allows full override for existing keys.
284
+ * Option 1 will set the key only if it doesn't already exist. Option 2 will set it only if it already exists.
285
+ * @returns {Promise}
286
+ * @public
287
+ */
288
+ setJSON(key: string, value: Object, path?: string | string[], overrideMode?: number): Promise<any>;
289
+ /**
290
+ * Used to fetch a JSON variable.
291
+ * <br/>
292
+ * NOTE: Requires ReJSON module installed on server to work.
293
+ *
294
+ * @method
295
+ * @param {string} key
296
+ * @param {string|string[]} [path="$"] A dot-separated JSONPath string, or an array of literal key segments (use the array form when key names may contain dots or other special characters).
297
+ * @returns {Promise<Object>}
298
+ * @public
299
+ */
300
+ getJSON(key: string, path?: string | string[]): Promise<Object>;
301
+ /**
302
+ * Used to update/edit an existing JSON variable.
303
+ * <br/>
304
+ * NOTE: Requires ReJSON module installed on server to work.
305
+ *
306
+ * @method
307
+ * @param {string} key
308
+ * @param {Object} value
309
+ * @param {string|string[]} [path="$"] A dot-separated JSONPath string, or an array of literal key segments (use the array form when key names may contain dots or other special characters).
310
+ * @returns {Promise}
311
+ * @public
312
+ */
313
+ editJSON(key: string, value: Object, path?: string | string[]): Promise<any>;
314
+ /**
315
+ * Used to add an item to a JSON array. That array needs to exist already.
316
+ * <br/>
317
+ * NOTE: Requires ReJSON module installed on server to work.
318
+ *
319
+ * @method
320
+ * @param {string} key
321
+ * @param {Object} value
322
+ * @param {string|string[]} [path="$"] A dot-separated JSONPath string, or an array of literal key segments (use the array form when key names may contain dots or other special characters).
323
+ * @returns {Promise}
324
+ * @public
325
+ */
326
+ arrayAppendJSON(key: string, value: Object, path?: string | string[]): Promise<any>;
327
+ }
@@ -1,44 +1,32 @@
1
1
  declare const _exported: Readonly<CommonMemoryCache>;
2
2
  export { _exported as instance };
3
- export { decodeCommandValue };
4
- export { mapCommandValues };
3
+ export declare var decodeCommandValue: typeof import("#redis-cache-provider").decodeCommandValue;
4
+ export declare var mapCommandValues: typeof import("#redis-cache-provider").mapCommandValues;
5
+ export { cacheCapability };
6
+ export { findMissingCapabilities };
5
7
  import ConnectionObserver = require("#connection-observer");
8
+ import RedisCacheProvider = require("#redis-cache-provider");
9
+ import { cacheCapability } from "#cache-capability";
6
10
  /**
7
- * Decodes one entry of a `multi(...).exec()` result into the value it carries.
11
+ * Determines which of the required capabilities a backend does not provide.
8
12
  * <br/>
9
- * Each entry is an ioredis `[ error, value ]` pair, so the value sits at index 1 and is a string when the key existed.
10
- * Returns `undefined` for a miss, an error entry, or a malformed entry.
11
- * <br/>
12
- * This lives outside the class, and is shared by {@link CommonMemoryCache#getValue} and
13
- * {@link CommonMemoryCache#getValues}, because it previously existed as two near-identical inline expressions and one
14
- * of them drifted: `getValues` inspected its own accumulator instead of the per-key entry, so `.length` was
15
- * `undefined`, the comparison was always false, and **every key resolved to `null`** whatever Redis returned.
13
+ * NOTE: This lives outside the class, and is exported, for the same reason the Redis decoders are: the cache singleton
14
+ * builds its own backend in its constructor, so the reconciliation cannot be driven without a live server. This is the
15
+ * pure half of it, and it is the half that decides whether an instance starts.
16
16
  *
17
17
  * @method
18
- * @param {Array} [result] One `[ error, value ]` entry.
19
- * @returns {*} The parsed value, or `undefined` when there is none.
20
- * @private
21
- */
22
- declare function decodeCommandValue(result?: any[]): any;
23
- /**
24
- * Maps a set of requested keys onto the values a `multi(...).exec()` returned for them, using `null` for a miss.
25
- * <br/>
26
- * Iterates the requested `keys` rather than the raw results, so a short or absent response still yields one entry per
27
- * requested key instead of silently omitting some — the caller's map always has the shape it asked for.
28
- * <br/>
29
- * The accumulator has no prototype on purpose: the key names come from the caller, and a cache key named `__proto__`
30
- * written by bracket assignment onto an ordinary `{}` would repoint the accumulator's prototype instead of creating
31
- * the entry. Same class as the `decycle` defect fixed in `tools.js`; see the 1.11.0 changelog entry.
32
- *
33
- * @method
34
- * @param {string[]} keys The keys that were requested, in command order.
35
- * @param {Array} [rawResults] The `multi(...).exec()` result.
36
- * @returns {Object} A null-prototype map of key to value, `null` where the key was absent.
37
- * @private
18
+ * @param {string[]} [required] Capabilities the application declared it needs.
19
+ * @param {string[]} [available] Capabilities the backend reports it provides.
20
+ * @returns {string[]} The required capabilities that are absent, in the order they were required.
21
+ * @public
38
22
  */
39
- declare function mapCommandValues(keys: string[], rawResults?: any[]): Object;
23
+ declare function findMissingCapabilities(required?: string[], available?: string[]): string[];
40
24
  /**
41
25
  * Used to create and/or return a Common Memory Cache singleton instance.
26
+ * <br/>
27
+ * NOTE: This owns the cache's operational state and the connection observation around it; where the values actually
28
+ * live is the {@link CacheProvider}'s business. Every method here checks that the cache is usable and then delegates,
29
+ * which is why no provider repeats that check.
42
30
  *
43
31
  * @class CommonMemoryCache
44
32
  * @extends ConnectionObserver
@@ -68,11 +56,31 @@ declare class CommonMemoryCache extends ConnectionObserver {
68
56
  * @public
69
57
  */
70
58
  get connectionIdentifier(): string;
59
+ /**
60
+ * Property returning the optional behaviors the configured backend provides.
61
+ * <br/>
62
+ * NOTE: Accurate only once {@link CommonMemoryCache#initialize} has resolved — some capabilities cannot be
63
+ * established until the backend has connected.
64
+ *
65
+ * @property
66
+ * @returns {string[]} Values drawn from {@link TiCacheCapability}.
67
+ * @public
68
+ */
69
+ get capabilities(): string[];
71
70
  /**
72
71
  * Used to initialize the cache service.
72
+ * <br/>
73
+ * NOTE: Once the backend is connected, the capabilities it reports are reconciled against the
74
+ * 'memoryCache.requiredCapabilities' setting, and startup fails if any of them is missing. That is deliberate: a
75
+ * backend silently lacking a behavior the application depends on is otherwise discovered from inside a request,
76
+ * long after the deployment that introduced it.
77
+ * <br/>
78
+ * NOTE: A failed reconciliation rolls the cache back to non-operational and shuts the backend down before it
79
+ * rejects, so a refused startup never leaves a usable cache behind.
73
80
  *
74
81
  * @method
75
82
  * @returns {Promise}
83
+ * @throws {TiException.E_GEN_FEATURE_UNSUPPORTED} If the backend does not provide every required capability.
76
84
  * @public
77
85
  */
78
86
  initialize(): Promise<any>;
@@ -113,7 +121,7 @@ declare class CommonMemoryCache extends ConnectionObserver {
113
121
  */
114
122
  onConnectionLost(identifier: string): void;
115
123
  /**
116
- * Used to register a new {@link ConnectionObserver} for events related to the underlying Redis connection state.
124
+ * Used to register a new {@link ConnectionObserver} for events related to the underlying backend connection state.
117
125
  *
118
126
  * @method
119
127
  * @param {ConnectionObserver} connectionObserver The {@link ConnectionObserver} that will be notified of any changes.
@@ -21,6 +21,7 @@ declare const settingsEnum: import("../components/definitions.types").TiEnumOf<{
21
21
  MEMORY_CACHE_REDIS_DB: string[];
22
22
  MEMORY_CACHE_REDIS_HOST: string[];
23
23
  MEMORY_CACHE_REDIS_PORT: string[];
24
+ MEMORY_CACHE_REQUIRED_CAPABILITIES: string[];
24
25
  MEMORY_CACHE_RETRY_MAX_ATTEMPTS: string[];
25
26
  MEMORY_CACHE_RETRY_MAX_INTERVAL: string[];
26
27
  MEMORY_CACHE_USER: string[];