infinispan 0.13.0 → 0.15.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/lib/utils.js CHANGED
@@ -15,9 +15,9 @@
15
15
  exports.context = function(size) {
16
16
  return {buf: Buffer.alloc(size), offset: 0, id: parseInt(_.uniqueId()), triedAddrs: []};
17
17
  };
18
- exports.showAddress = function(addr) { return addr.host + ':' + addr.port; };
18
+ exports.showAddress = function(addr) { return `${addr.host }:${ addr.port}`; };
19
19
  exports.showArrayAddress = function(addrs) {
20
- return ["[", _.map(addrs, function(a) { return exports.showAddress(a); }).join(","), "]"].join('');
20
+ return ['[', _.map(addrs, function(a) { return exports.showAddress(a); }).join(','), ']'].join('');
21
21
  };
22
22
 
23
23
  exports.parse = function (chal) {
@@ -89,7 +89,7 @@
89
89
  logger.trace.apply(logger, fun());
90
90
  },
91
91
  error: function() { logger.error.apply(logger, arguments); }
92
- }
92
+ };
93
93
  };
94
94
 
95
95
  var ReplayableBuffer = function() {
@@ -129,42 +129,69 @@
129
129
  buf.copy(b);
130
130
  return b;
131
131
  }
132
- }
132
+ };
133
133
  };
134
134
 
135
135
  var polyToString = f.dispatch(
136
- function(s) { return !f.existy(s) ? 'undefined' : undefined },
137
- function(s) { return _.isString(s) ? (s.length > 1024 ? s.substring(0, 1024) + '...' : s) : undefined},
138
- function(s) { return _.isArray(s) ? stringifyArray(s) : undefined },
139
- function(s) { return _.isObject(s) ? JSON.stringify(s) : undefined },
140
- function(s) { return s.toString() });
141
-
136
+ function(s) { return !f.existy(s) ? 'undefined' : undefined; },
137
+ function(s) { return _.isString(s) ? (s.length > 1024 ? `${s.substring(0, 1024) }...` : s) : undefined;},
138
+ function(s) { return _.isArray(s) ? stringifyArray(s) : undefined; },
139
+ function(s) { return _.isObject(s) ? JSON.stringify(s) : undefined; },
140
+ function(s) { return s.toString(); });
141
+
142
+ /**
143
+ * Converts a value to its string representation using polymorphic dispatch.
144
+ * @param {*} o Value to convert to string.
145
+ * @returns {string} String representation of the value.
146
+ */
142
147
  function str(o) {
143
148
  return polyToString(o);
144
149
  }
145
150
 
151
+ /**
152
+ * Converts an array to a bracketed, comma-separated string.
153
+ * @param {Array} ary Array to stringify.
154
+ * @returns {string} String representation of the array.
155
+ */
146
156
  function stringifyArray(ary) {
147
- return ["[", _.map(ary, polyToString).join(","), "]"].join('');
157
+ return ['[', _.map(ary, polyToString).join(','), ']'].join('');
148
158
  }
149
159
 
160
+ /**
161
+ * Normalizes server address arguments into a uniform array of address objects.
162
+ * @param {Object|Object[]|undefined} args Address object, array of addresses, or undefined.
163
+ * @returns {Object[]} Array of address objects with host and port properties.
164
+ */
150
165
  function normalizeAddresses(args) {
151
166
  var normalizer = f.dispatch(
152
- function(xs) { return _.isArray(xs) ? xs : undefined },
153
- function(x) { return _.isObject(x) ? [x] : undefined },
167
+ function(xs) { return _.isArray(xs) ? xs : undefined; },
168
+ function(x) { return _.isObject(x) ? [x] : undefined; },
154
169
  function(x) {
155
- if (f.existy(x)) throw new Error('Unknown server addresses: ' + x);
156
- return [{port: 11222, host: '127.0.0.1'}]
170
+ if (f.existy(x)) throw new Error(`Unknown server addresses: ${ x}`);
171
+ return [{port: 11222, host: '127.0.0.1'}];
157
172
  });
158
173
  return normalizer(args);
159
174
  }
160
175
 
161
176
  var MurmurHash3 = function() {
177
+ /**
178
+ * XORs two 64-bit integers represented as two-element 32-bit int arrays.
179
+ * @param {number[]} m First 64-bit integer as [high, low].
180
+ * @param {number[]} n Second 64-bit integer as [high, low].
181
+ * @returns {number[]} XOR result as [high, low].
182
+ */
162
183
  function x64Xor(m, n) {
163
184
  // Given two 64bit ints (as an array of two 32bit ints) returns the two
164
185
  // xored together as a 64bit int (as an array of two 32bit ints).
165
186
  return [m[0] ^ n[0], m[1] ^ n[1]];
166
187
  }
167
188
 
189
+ /**
190
+ * Multiplies two 64-bit integers represented as two-element 32-bit int arrays.
191
+ * @param {number[]} m First 64-bit integer as [high, low].
192
+ * @param {number[]} n Second 64-bit integer as [high, low].
193
+ * @returns {number[]} Product as [high, low].
194
+ */
168
195
  function x64Multiply(m, n) {
169
196
  // Given two 64bit ints (as an array of two 32bit ints) returns the two
170
197
  // multiplied together as a 64bit int (as an array of two 32bit ints).
@@ -202,6 +229,12 @@
202
229
  return [(o[0] << 16) | o[1], (o[2] << 16) | o[3]];
203
230
  }
204
231
 
232
+ /**
233
+ * Rotates a 64-bit integer left by the given number of bit positions.
234
+ * @param {number[]} m 64-bit integer as [high, low].
235
+ * @param {number} n Number of bit positions to rotate.
236
+ * @returns {number[]} Rotated result as [high, low].
237
+ */
205
238
  function x64Rotl(m, n) {
206
239
  // Given a 64bit int (as an array of two 32bit ints) and an int
207
240
  // representing a number of bit positions, returns the 64bit int (as an
@@ -218,6 +251,12 @@
218
251
  }
219
252
  }
220
253
 
254
+ /**
255
+ * Adds two 64-bit integers represented as two-element 32-bit int arrays.
256
+ * @param {number[]} m First 64-bit integer as [high, low].
257
+ * @param {number[]} n Second 64-bit integer as [high, low].
258
+ * @returns {number[]} Sum as [high, low].
259
+ */
221
260
  function x64Add(m, n) {
222
261
  // Given two 64bit ints (as an array of two 32bit ints) returns the two
223
262
  // added together as a 64bit int (as an array of two 32bit ints).
@@ -243,6 +282,12 @@
243
282
  return [(o[0] << 16) | o[1], (o[2] << 16) | o[3]];
244
283
  }
245
284
 
285
+ /**
286
+ * Shifts a 64-bit integer left by the given number of bit positions.
287
+ * @param {number[]} m 64-bit integer as [high, low].
288
+ * @param {number} n Number of bit positions to shift.
289
+ * @returns {number[]} Shifted result as [high, low].
290
+ */
246
291
  function x64LeftShift(m, n) {
247
292
  // Given a 64bit int (as an array of two 32bit ints) and an int
248
293
  // representing a number of bit positions, returns the 64bit int (as an
@@ -257,6 +302,12 @@
257
302
  return [m[1] << (n - 32), 0];
258
303
  }
259
304
 
305
+ /**
306
+ * Reads a 64-bit block from the key buffer at the given byte index.
307
+ * @param {Buffer} key Key buffer to read from.
308
+ * @param {number} i Byte offset into the key buffer.
309
+ * @returns {number[]} 64-bit block as [high, low].
310
+ */
260
311
  function getblock(key, i) {
261
312
  return [
262
313
  ((key[i + 4] & 0xff))
@@ -270,6 +321,11 @@
270
321
  ];
271
322
  }
272
323
 
324
+ /**
325
+ * Performs the MurmurHash3 block mix operation on the hash state.
326
+ * @param {Object} state Mutable hash state with h1, h2, k1, k2, c1, c2 fields.
327
+ * @returns {void}
328
+ */
273
329
  function bmix(state) {
274
330
  state.k1 = x64Multiply(state.k1, state.c1);
275
331
  state.k1 = x64Rotl(state.k1, 23);
@@ -293,6 +349,11 @@
293
349
  state.c2 = x64Add(x64Multiply(state.c2, [0, 5]), [0, 0x6bce6396]);
294
350
  }
295
351
 
352
+ /**
353
+ * Applies the MurmurHash3 final mix (fmix) to a 64-bit block.
354
+ * @param {number[]} h 64-bit block as [high, low].
355
+ * @returns {number[]} Mixed result as [high, low].
356
+ */
296
357
  function x64Fmix(h) {
297
358
  // Given a block, returns murmurHash3's final x64 mix of that block.
298
359
  // (`[0, h[0] >>> 1]` is a 33 bit unsigned right shift. This is the
@@ -305,17 +366,21 @@
305
366
  return h;
306
367
  }
307
368
 
308
- // Used for debugging hashing
309
- function toHex(bignum) {
310
- var tmp0 = bignum[0] < 0 ? (bignum[0]>>>0) : bignum[0];
311
- var tmp1 = bignum[1] < 0 ? (bignum[1]>>>0) : bignum[1];
312
- return tmp0.toString(16) + tmp1.toString(16);
313
- }
314
-
369
+ /**
370
+ * Converts a 32-bit integer to a 64-bit representation as a two-element array.
371
+ * @param {number} num 32-bit integer.
372
+ * @returns {number[]} 64-bit representation as [high, low].
373
+ */
315
374
  function _x32tox64(num) {
316
375
  return num < 0 ? [0xffffffff, num] : [0, num];
317
376
  }
318
377
 
378
+ /**
379
+ * Computes the MurmurHash3 x64 128-bit hash and returns the first 64 bits.
380
+ * @param {Buffer} key Key buffer to hash.
381
+ * @param {number[]} seed 64-bit seed as [high, low].
382
+ * @returns {number[]} First 64-bit hash value as [high, low].
383
+ */
319
384
  function murmurHash3_x64_64(key, seed) {
320
385
  var state = {};
321
386
 
@@ -389,7 +454,7 @@
389
454
  var h = murmurHash3_x64_64(key, [0, 9001]);
390
455
  return h[0] >>> 32;
391
456
  }
392
- }
393
- }
457
+ };
458
+ };
394
459
 
395
460
  }.call(this));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "infinispan",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "Infinispan Javascript client",
5
5
  "main": "index",
6
6
  "typings": "./types",
@@ -8,8 +8,14 @@
8
8
  "test": "test"
9
9
  },
10
10
  "scripts": {
11
- "lint": "eslint --ignore-path .gitignore .",
12
- "test": "jasmine"
11
+ "lint": "eslint --ignore-path .gitignore lib spec index.js",
12
+ "test": "jasmine",
13
+ "test:docker": "node scripts/docker-test.js",
14
+ "docker:up": "docker compose -p ispn-test up -d --wait && docker compose -p ispn-test --profile failover create server-failover-one server-failover-two server-failover-three",
15
+ "docker:down": "docker compose -p ispn-test --profile failover down --remove-orphans",
16
+ "ssl:generate": "node scripts/make-ssl.js",
17
+ "docs:api": "jsdoc lib/*.js",
18
+ "docs:user": "node scripts/gen-asciidoc.js"
13
19
  },
14
20
  "author": "Infinispan Community",
15
21
  "license": "Apache-2.0",
@@ -28,7 +34,6 @@
28
34
  },
29
35
  "dependencies": {
30
36
  "buffer-xor": "^2.0.2",
31
- "jsdoc": "^4.0.2",
32
37
  "log4js": "^6.4.6",
33
38
  "protobufjs": "^7.0.0",
34
39
  "underscore": "^1.13.3",
@@ -37,6 +42,7 @@
37
42
  "devDependencies": {
38
43
  "eslint": "^8.26.0",
39
44
  "jasmine": "^6.1.0",
45
+ "jsdoc": "^4.0.2",
40
46
  "long": "^5.2.3"
41
47
  }
42
48
  }
package/server/.keep ADDED
File without changes
package/types/index.d.ts CHANGED
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Connect to an Infinispan Server using a Hot Rod URI.
3
+ *
4
+ * URI format: hotrod://[user:pass@]host1[:port1][,host2[:port2]][?params]
5
+ * Use hotrods:// to enable TLS.
6
+ *
7
+ * Supported query parameters:
8
+ * sasl_mechanism, trust_store_file_name (alias trust_ca),
9
+ * key_store_file_name (alias client_cert), key_store_password (alias client_key),
10
+ * sni_host_name (alias sni_host), max_retries, cache_name.
11
+ *
12
+ * @param uri Hot Rod URI string.
13
+ * @param options Optional overrides (take precedence over URI values).
14
+ */
15
+ export function client(uri: string, options?: Record<string, any>): Promise<any>;
16
+
1
17
  export function client(args: {
2
18
  /**
3
19
  * - Server host name.
@@ -20,7 +36,7 @@ export function client(args: {
20
36
  /**
21
37
  * - Version of client/server protocol.
22
38
  */
23
- version?: (2.9 | 2.5 | 2.2) | null;
39
+ version?: ('auto' | '4.1' | '4.0' | '3.1' | '3.0' | '2.9' | '2.5' | '2.2') | null;
24
40
  /**
25
41
  * - Optional cache name.
26
42
  */
@@ -131,6 +147,15 @@ export function client(args: {
131
147
  port: number;
132
148
  }[];
133
149
  }[];
150
+ /**
151
+ * - Near cache configuration. When set, enables client-side caching with server-side invalidation.
152
+ */
153
+ nearCache?: {
154
+ /**
155
+ * - Maximum number of entries to store in the near cache.
156
+ */
157
+ maxEntries: number;
158
+ } | null;
134
159
  }): Promise<ReturnType<{
135
160
  (addrs: any, clientOpts: any): {
136
161
  connect: () => any;
@@ -144,6 +169,14 @@ export function client(args: {
144
169
  * @since 0.3
145
170
  */
146
171
  disconnect: () => Promise<void>;
172
+ /**
173
+ * Returns the active protocol version string (e.g. '3.1', '4.1').
174
+ * When using auto-negotiation, this reflects the negotiated version.
175
+ *
176
+ * @returns {string} Protocol version string.
177
+ * @memberof Client#
178
+ */
179
+ getProtocolVersion: () => string;
147
180
  /**
148
181
  * Get the value associated with the given key parameter.
149
182
  *
@@ -651,6 +684,134 @@ export function client(args: {
651
684
  * @since 0.3
652
685
  */
653
686
  removeListener: (listenerId: string) => Promise<any>;
687
+ /**
688
+ * Register a continuous query that watches for cache changes
689
+ * matching the given Ickle query.
690
+ *
691
+ * @param queryString Ickle query string.
692
+ * @param opts Optional CQ options.
693
+ * @returns A promise completed with a ContinuousQuery handle.
694
+ * @memberof Client#
695
+ * @since 0.16
696
+ */
697
+ addContinuousQuery: (queryString: string, opts?: {
698
+ /** Named parameter bindings for the Ickle query. */
699
+ params?: { [name: string]: string | number | boolean };
700
+ }) => Promise<{
701
+ /** Register a callback for continuous query events. */
702
+ on(event: 'joining' | 'leaving' | 'updated', callback: (key: Buffer, value: Buffer, projection?: any[]) => void): any;
703
+ /** Get the listener ID for this continuous query. */
704
+ getListenerId(): string;
705
+ }>;
706
+ /**
707
+ * Remove a continuous query.
708
+ *
709
+ * @param cq ContinuousQuery handle returned by addContinuousQuery.
710
+ * @returns A promise completed when the continuous query has been removed.
711
+ * @memberof Client#
712
+ * @since 0.16
713
+ */
714
+ removeContinuousQuery: (cq: { getListenerId(): string }) => Promise<any>;
715
+ /**
716
+ * Create a distributed counter.
717
+ *
718
+ * @param {String} name Counter name.
719
+ * @param {CounterConfig} config Counter configuration.
720
+ * @returns {Promise.<Boolean>}
721
+ * @memberof Client#
722
+ * @since 0.14
723
+ */
724
+ counterCreate: (name: string, config: {
725
+ type: 'strong' | 'weak';
726
+ storage?: 'persistent' | 'volatile';
727
+ initialValue?: number;
728
+ lowerBound?: number;
729
+ upperBound?: number;
730
+ concurrencyLevel?: number;
731
+ }) => Promise<boolean>;
732
+ /**
733
+ * Get the current value of a counter.
734
+ *
735
+ * @param {String} name Counter name.
736
+ * @returns {Promise.<?Number>}
737
+ * @memberof Client#
738
+ * @since 0.14
739
+ */
740
+ counterGet: (name: string) => Promise<number | undefined>;
741
+ /**
742
+ * Add a value to the counter and return the new value.
743
+ *
744
+ * @param {String} name Counter name.
745
+ * @param {Number} value Value to add.
746
+ * @returns {Promise.<?Number>}
747
+ * @memberof Client#
748
+ * @since 0.14
749
+ */
750
+ counterAddAndGet: (name: string, value: number) => Promise<number | undefined>;
751
+ /**
752
+ * Reset the counter to its initial value.
753
+ *
754
+ * @param {String} name Counter name.
755
+ * @returns {Promise.<Boolean>}
756
+ * @memberof Client#
757
+ * @since 0.14
758
+ */
759
+ counterReset: (name: string) => Promise<boolean>;
760
+ /**
761
+ * Compare and swap the counter value.
762
+ *
763
+ * @param {String} name Counter name.
764
+ * @param {Number} expect Expected current value.
765
+ * @param {Number} update New value to set.
766
+ * @returns {Promise.<?Number>}
767
+ * @memberof Client#
768
+ * @since 0.14
769
+ */
770
+ counterCompareAndSwap: (name: string, expect: number, update: number) => Promise<number | undefined>;
771
+ /**
772
+ * Check if a counter is defined.
773
+ *
774
+ * @param {String} name Counter name.
775
+ * @returns {Promise.<Boolean>}
776
+ * @memberof Client#
777
+ * @since 0.14
778
+ */
779
+ counterIsDefined: (name: string) => Promise<boolean>;
780
+ /**
781
+ * Get the configuration of a counter.
782
+ *
783
+ * @param {String} name Counter name.
784
+ * @returns {Promise.<?Object>}
785
+ * @memberof Client#
786
+ * @since 0.14
787
+ */
788
+ counterGetConfiguration: (name: string) => Promise<{
789
+ type: 'strong' | 'weak';
790
+ storage: 'persistent' | 'volatile';
791
+ initialValue: number;
792
+ lowerBound?: number;
793
+ upperBound?: number;
794
+ concurrencyLevel?: number;
795
+ } | undefined>;
796
+ /**
797
+ * Remove a counter from the cluster.
798
+ *
799
+ * @param {String} name Counter name.
800
+ * @returns {Promise.<Boolean>}
801
+ * @memberof Client#
802
+ * @since 0.14
803
+ */
804
+ counterRemove: (name: string) => Promise<boolean>;
805
+ /**
806
+ * Set a value to the counter and return the previous value.
807
+ *
808
+ * @param {String} name Counter name.
809
+ * @param {Number} value Value to set.
810
+ * @returns {Promise.<?Number>}
811
+ * @memberof Client#
812
+ * @since 0.14
813
+ */
814
+ counterGetAndSet: (name: string, value: number) => Promise<number | undefined>;
654
815
  /**
655
816
  * Add script to server(s).
656
817
  *
@@ -784,6 +945,80 @@ export function client(args: {
784
945
  toString: () => string;
785
946
  registerProtostreamType: (typeName: any, descriptorId: any) => any;
786
947
  registerProtostreamRoot: (root: any) => any;
948
+ /**
949
+ * Get the number of entries in the near cache.
950
+ *
951
+ * @returns {Number} Number of entries in the near cache, or 0 if near caching is not enabled.
952
+ * @memberof Client#
953
+ * @since 0.14
954
+ */
955
+ nearCacheSize: () => number;
956
+ /**
957
+ * Admin operations for cache lifecycle, schema management, and indexing.
958
+ * @since 0.15
959
+ */
960
+ admin: {
961
+ /**
962
+ * Create a cache with the given configuration.
963
+ * @param name Cache name.
964
+ * @param config Cache configuration (XML or JSON).
965
+ * @param opts Optional settings.
966
+ * @since 0.15
967
+ */
968
+ createCache: (name: string, config?: string, opts?: { template?: string; flags?: string }) => Promise<any>;
969
+ /**
970
+ * Get an existing cache or create it with the given configuration.
971
+ * @param name Cache name.
972
+ * @param config Cache configuration (XML or JSON).
973
+ * @param opts Optional settings.
974
+ * @since 0.15
975
+ */
976
+ getOrCreateCache: (name: string, config?: string, opts?: { template?: string; flags?: string }) => Promise<any>;
977
+ /**
978
+ * Remove a cache.
979
+ * @param name Cache name.
980
+ * @since 0.15
981
+ */
982
+ removeCache: (name: string) => Promise<any>;
983
+ /**
984
+ * List all cache names.
985
+ * @since 0.15
986
+ */
987
+ cacheNames: () => Promise<string[]>;
988
+ /**
989
+ * Update a mutable configuration attribute on a cache.
990
+ * @param name Cache name.
991
+ * @param attribute Attribute path (e.g. 'memory.max-count').
992
+ * @param value New attribute value.
993
+ * @since 0.15
994
+ */
995
+ updateConfigurationAttribute: (name: string, attribute: string, value: string) => Promise<any>;
996
+ /**
997
+ * Rebuild indexes for a cache.
998
+ * @param name Cache name.
999
+ * @since 0.15
1000
+ */
1001
+ reindex: (name: string) => Promise<any>;
1002
+ /**
1003
+ * Update the index schema for a cache.
1004
+ * @param name Cache name.
1005
+ * @since 0.15
1006
+ */
1007
+ updateIndexSchema: (name: string) => Promise<any>;
1008
+ /**
1009
+ * Register (create or update) a Protobuf schema on the server.
1010
+ * @param name Schema name (e.g. 'person.proto').
1011
+ * @param schema Protobuf schema content.
1012
+ * @since 0.15
1013
+ */
1014
+ registerSchema: (name: string, schema: string) => Promise<any>;
1015
+ /**
1016
+ * Remove a registered Protobuf schema.
1017
+ * @param name Schema name.
1018
+ * @since 0.15
1019
+ */
1020
+ removeSchema: (name: string) => Promise<any>;
1021
+ };
787
1022
  };
788
1023
  /**
789
1024
  * Cluster information.