@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ti-engine/core",
3
- "version": "1.12.2",
3
+ "version": "1.13.0",
4
4
  "description": "Microservice framework for Node.js: a Redis-backed message exchange with end-to-end call tracing, retries and tamper-evident message envelopes.",
5
5
  "keywords": [
6
6
  "microservices",
@@ -59,10 +59,6 @@
59
59
  "default": "./components/definitions.types.js"
60
60
  }
61
61
  },
62
- "scripts": {
63
- "test": "node --test",
64
- "build:types": "tsc -p tsconfig.types.json"
65
- },
66
62
  "imports": {
67
63
  "#auditing": {
68
64
  "types": "./types/components/auditing.d.ts",
@@ -72,6 +68,14 @@
72
68
  "types": "./types/utils/cache.d.ts",
73
69
  "default": "./utils/cache.js"
74
70
  },
71
+ "#cache-capability": {
72
+ "types": "./types/components/cache/cache-capability.d.ts",
73
+ "default": "./components/cache/cache-capability.js"
74
+ },
75
+ "#cache-provider": {
76
+ "types": "./types/components/cache/cache-provider.d.ts",
77
+ "default": "./components/cache/cache-provider.js"
78
+ },
75
79
  "#config": {
76
80
  "types": "./types/utils/config.d.ts",
77
81
  "default": "./utils/config.js"
@@ -141,6 +145,10 @@
141
145
  "types": "./types/components/exchange/message-tracer.d.ts",
142
146
  "default": "./components/exchange/message-tracer.js"
143
147
  },
148
+ "#redis-cache-provider": {
149
+ "types": "./types/components/cache/redis-cache-provider.d.ts",
150
+ "default": "./components/cache/redis-cache-provider.js"
151
+ },
144
152
  "#redis-integration": {
145
153
  "types": "./types/integrations/redis-integration.d.ts",
146
154
  "default": "./integrations/redis-integration.js"
@@ -202,5 +210,9 @@
202
210
  "homepage": "https://github.com/Belleal/ti-engine/tree/master/packages/core#readme",
203
211
  "engines": {
204
212
  "node": ">=20.12.0"
213
+ },
214
+ "scripts": {
215
+ "test": "node --test",
216
+ "build:types": "tsc -p tsconfig.types.json"
205
217
  }
206
218
  }
@@ -0,0 +1,23 @@
1
+ export { cacheCapabilityEnum as cacheCapability };
2
+ export type TiCacheCapability = string;
3
+ /**
4
+ * Enum for listing the optional behaviors a cache backend may or may not provide.
5
+ * <br/>
6
+ * NOTE: A backend declares what it supports through {@link CacheProvider#capabilities}; an application declares what it
7
+ * requires through the 'memoryCache.requiredCapabilities' setting. The two are reconciled once, during startup, so that
8
+ * a backend which cannot do what the application needs fails where somebody is watching rather than inside a request
9
+ * weeks later.
10
+ *
11
+ * @readonly
12
+ * @enum {string}
13
+ * @typedef {string} TiCacheCapability
14
+ */
15
+ declare const cacheCapabilityEnum: import("../definitions.types").TiEnumOf<{
16
+ KEY_EXPIRY: string[];
17
+ KEY_PATTERN_MATCH: string[];
18
+ LISTS: string[];
19
+ SETS: string[];
20
+ HASH_FIELDS: string[];
21
+ JSON_DOCUMENTS: string[];
22
+ ATOMIC_JSON_EDIT: string[];
23
+ }>;
@@ -0,0 +1,326 @@
1
+ export = CacheProvider;
2
+ import type ConnectionObserver from "#connection-observer";
3
+ /** @import ConnectionObserver from "#connection-observer" */
4
+ /**
5
+ * An abstract class that defines the storage behavior required by the {@link CommonMemoryCache}.
6
+ * <br/>
7
+ * NOTE: This sets the contract between the cache and whatever actually holds the values. It has to be inherited and
8
+ * implemented with the specifics of a given backend. For a working example please see the {@link RedisCacheProvider} class.
9
+ * <br/>
10
+ * NOTE: Implementations must NOT check whether the cache is operational. {@link CommonMemoryCache} performs that check
11
+ * once, before it delegates, so every backend inherits the same guard instead of restating it in each of its methods.
12
+ *
13
+ * @class CacheProvider
14
+ * @abstract
15
+ * @public
16
+ */
17
+ declare class CacheProvider {
18
+ /**
19
+ * @constructor
20
+ * @throws {TiException.E_GEN_ABSTRACT_CLASS_INIT} If this class is instantiated directly.
21
+ */
22
+ constructor();
23
+ /**
24
+ * Property returning the optional behaviors this backend provides.
25
+ * <br/>
26
+ * NOTE: Some capabilities can only be established once a connection exists — RedisJSON, for example, is a server-side
27
+ * module that has to be probed. Read this after {@link CacheProvider#initialize} has resolved, never before.
28
+ *
29
+ * @property
30
+ * @returns {string[]} Values drawn from {@link TiCacheCapability}.
31
+ * @abstract
32
+ * @public
33
+ */
34
+ get capabilities(): string[];
35
+ /**
36
+ * Used to verify whether this backend provides a given capability.
37
+ *
38
+ * @method
39
+ * @param {string} capability A value from {@link TiCacheCapability}.
40
+ * @returns {boolean}
41
+ * @public
42
+ */
43
+ hasCapability(capability: string): boolean;
44
+ /**
45
+ * Used to initialize the backend and establish whatever connection it requires.
46
+ *
47
+ * @method
48
+ * @returns {Promise}
49
+ * @abstract
50
+ * @public
51
+ */
52
+ initialize(): Promise<any>;
53
+ /**
54
+ * Used to gracefully shut the backend down.
55
+ *
56
+ * @method
57
+ * @returns {Promise}
58
+ * @abstract
59
+ * @public
60
+ */
61
+ shutDown(): Promise<any>;
62
+ /**
63
+ * Used to register a new {@link ConnectionObserver} for events related to the backend connection state.
64
+ *
65
+ * @method
66
+ * @param {ConnectionObserver} connectionObserver The {@link ConnectionObserver} that will be notified of any changes.
67
+ * @abstract
68
+ * @public
69
+ */
70
+ addConnectionObserver(connectionObserver: ConnectionObserver): void;
71
+ /**
72
+ * Used to search for keys by a given pattern.
73
+ *
74
+ * @method
75
+ * @param {string} pattern
76
+ * @returns {Promise<Array>}
77
+ * @requires {TiCacheCapability.KEY_PATTERN_MATCH}
78
+ * @abstract
79
+ * @public
80
+ */
81
+ matchKeys(pattern: string): Promise<any[]>;
82
+ /**
83
+ * Used to set a specific string value.
84
+ *
85
+ * @method
86
+ * @param {string} key
87
+ * @param {string} value
88
+ * @param {number} [expiration] Expiration value is in seconds.
89
+ * @returns {Promise<string>}
90
+ * @abstract
91
+ * @public
92
+ */
93
+ setValue(key: string, value: string, expiration?: number): Promise<string>;
94
+ /**
95
+ * Used to set multiple string values.
96
+ *
97
+ * @method
98
+ * @param {Object} keyValues
99
+ * @param {string} [prefix]
100
+ * @param {number} [expiration] Expiration value is in seconds.
101
+ * @returns {Promise}
102
+ * @abstract
103
+ * @public
104
+ */
105
+ setValues(keyValues: Object, prefix?: string, expiration?: number): Promise<any>;
106
+ /**
107
+ * Used to get a string value.
108
+ *
109
+ * @method
110
+ * @param {string} key
111
+ * @returns {Promise}
112
+ * @abstract
113
+ * @public
114
+ */
115
+ getValue(key: string): Promise<any>;
116
+ /**
117
+ * Used to get multiple string values.
118
+ *
119
+ * @method
120
+ * @param {string[]} keys
121
+ * @param {string} [prefix]
122
+ * @returns {Promise}
123
+ * @abstract
124
+ * @public
125
+ */
126
+ getValues(keys: string[], prefix?: string): Promise<any>;
127
+ /**
128
+ * Used to delete a value / item.
129
+ *
130
+ * @method
131
+ * @param {string} key
132
+ * @returns {Promise<boolean>}
133
+ * @abstract
134
+ * @public
135
+ */
136
+ deleteValue(key: string): Promise<boolean>;
137
+ /**
138
+ * Used to set expiration in seconds to an existing key.
139
+ *
140
+ * @method
141
+ * @param {string} key
142
+ * @param {number} seconds
143
+ * @param {string} [name] If a field in a hash set is to be expired instead, the name of that set.
144
+ * @returns {Promise<number>}
145
+ * @requires {TiCacheCapability.KEY_EXPIRY}
146
+ * @abstract
147
+ * @public
148
+ */
149
+ expireValue(key: string, seconds: number, name?: string): Promise<number>;
150
+ /**
151
+ * Used to add the specified values to a list.
152
+ *
153
+ * @method
154
+ * @param {string} listName
155
+ * @param {Object[]} values
156
+ * @returns {Promise<number>}
157
+ * @requires {TiCacheCapability.LISTS}
158
+ * @abstract
159
+ * @public
160
+ */
161
+ listPushValue(listName: string, values: Object[]): Promise<number>;
162
+ /**
163
+ * Used to add the specified value to a set.
164
+ *
165
+ * @method
166
+ * @param {string} key
167
+ * @param {string|Object} value
168
+ * @returns {Promise}
169
+ * @requires {TiCacheCapability.SETS}
170
+ * @abstract
171
+ * @public
172
+ */
173
+ addToSet(key: string, value: string | Object): Promise<any>;
174
+ /**
175
+ * Used to add multiple values to multiple sets in one transactional request.
176
+ *
177
+ * @method
178
+ * @param {string[]} keys
179
+ * @param {string[]} values
180
+ * @returns {Promise}
181
+ * @requires {TiCacheCapability.SETS}
182
+ * @abstract
183
+ * @public
184
+ */
185
+ addToSetMulti(keys: string[], values: string[]): Promise<any>;
186
+ /**
187
+ * Used to verify whether a value is a member of a set.
188
+ *
189
+ * @method
190
+ * @param {string} setName
191
+ * @param {string|Object} value
192
+ * @returns {Promise<boolean>}
193
+ * @requires {TiCacheCapability.SETS}
194
+ * @abstract
195
+ * @public
196
+ */
197
+ isSetMember(setName: string, value: string | Object): Promise<boolean>;
198
+ /**
199
+ * Used to fetch all members of a set.
200
+ *
201
+ * @method
202
+ * @param {string} key
203
+ * @returns {Promise<Array>}
204
+ * @requires {TiCacheCapability.SETS}
205
+ * @abstract
206
+ * @public
207
+ */
208
+ membersOfSet(key: string): Promise<any[]>;
209
+ /**
210
+ * Used to fetch the union of the provided sets.
211
+ *
212
+ * @method
213
+ * @param {string[]} keys
214
+ * @returns {Promise<Array>}
215
+ * @requires {TiCacheCapability.SETS}
216
+ * @abstract
217
+ * @public
218
+ */
219
+ unionOfSets(keys: string[]): Promise<any[]>;
220
+ /**
221
+ * Used to set a single field in a hash set.
222
+ *
223
+ * @method
224
+ * @param {string} key
225
+ * @param {string} name
226
+ * @param {string|Object} value
227
+ * @returns {Promise}
228
+ * @requires {TiCacheCapability.HASH_FIELDS}
229
+ * @abstract
230
+ * @public
231
+ */
232
+ hashSetField(key: string, name: string, value: string | Object): Promise<any>;
233
+ /**
234
+ * Used to set multiple fields in a hash set.
235
+ *
236
+ * @method
237
+ * @param {string} key
238
+ * @param {Object} fields
239
+ * @returns {Promise}
240
+ * @requires {TiCacheCapability.HASH_FIELDS}
241
+ * @abstract
242
+ * @public
243
+ */
244
+ hashSetFields(key: string, fields: Object): Promise<any>;
245
+ /**
246
+ * Used to fetch a single field from a hash set.
247
+ *
248
+ * @method
249
+ * @param {string} key
250
+ * @param {string} field
251
+ * @returns {Promise}
252
+ * @requires {TiCacheCapability.HASH_FIELDS}
253
+ * @abstract
254
+ * @public
255
+ */
256
+ hashGetField(key: string, field: string): Promise<any>;
257
+ /**
258
+ * Used to delete a single field from a hash set.
259
+ *
260
+ * @method
261
+ * @param {string} key
262
+ * @param {string} field
263
+ * @returns {Promise}
264
+ * @requires {TiCacheCapability.HASH_FIELDS}
265
+ * @abstract
266
+ * @public
267
+ */
268
+ hashDeleteField(key: string, field: string): Promise<any>;
269
+ /**
270
+ * Used to store a JSON document, or a branch of one.
271
+ *
272
+ * @method
273
+ * @param {string} key
274
+ * @param {Object} value
275
+ * @param {string|string[]} [path="$"] A dot-separated JSONPath string, or an array of literal key segments.
276
+ * @param {number} [overrideMode=0] 0 allows full override; 1 sets only if absent; 2 sets only if present.
277
+ * @returns {Promise}
278
+ * @requires {TiCacheCapability.JSON_DOCUMENTS}
279
+ * @abstract
280
+ * @public
281
+ */
282
+ setJSON(key: string, value: Object, path?: string | string[], overrideMode?: number): Promise<any>;
283
+ /**
284
+ * Used to fetch a JSON document, or a branch of one.
285
+ *
286
+ * @method
287
+ * @param {string} key
288
+ * @param {string|string[]} [path="$"] A dot-separated JSONPath string, or an array of literal key segments.
289
+ * @returns {Promise<Object>}
290
+ * @requires {TiCacheCapability.JSON_DOCUMENTS}
291
+ * @abstract
292
+ * @public
293
+ */
294
+ getJSON(key: string, path?: string | string[]): Promise<Object>;
295
+ /**
296
+ * Used to merge a value into an existing JSON document at the given path.
297
+ * <br/>
298
+ * NOTE: Callers rely on this being applied atomically by the backend when {@link TiCacheCapability.ATOMIC_JSON_EDIT}
299
+ * is declared — two concurrent edits to different paths of the same document must both survive. A backend that can
300
+ * only read-modify-write must NOT declare that capability, because the loss is silent: nothing throws, and one of
301
+ * the two writes is simply gone.
302
+ *
303
+ * @method
304
+ * @param {string} key
305
+ * @param {Object} value
306
+ * @param {string|string[]} [path="$"] A dot-separated JSONPath string, or an array of literal key segments.
307
+ * @returns {Promise}
308
+ * @requires {TiCacheCapability.JSON_DOCUMENTS}
309
+ * @abstract
310
+ * @public
311
+ */
312
+ editJSON(key: string, value: Object, path?: string | string[]): Promise<any>;
313
+ /**
314
+ * Used to append a value to an array inside a JSON document.
315
+ *
316
+ * @method
317
+ * @param {string} key
318
+ * @param {Object} value
319
+ * @param {string|string[]} [path="$"] A dot-separated JSONPath string, or an array of literal key segments.
320
+ * @returns {Promise}
321
+ * @requires {TiCacheCapability.JSON_DOCUMENTS}
322
+ * @abstract
323
+ * @public
324
+ */
325
+ arrayAppendJSON(key: string, value: Object, path?: string | string[]): Promise<any>;
326
+ }