@opensearch-project/opensearch 2.3.0 → 2.3.1

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/CHANGELOG.md CHANGED
@@ -11,6 +11,16 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
11
11
  ### Fixed
12
12
  ### Security
13
13
 
14
+ ## [2.3.1]
15
+ ### Added
16
+ ### Dependencies
17
+ ### Changed
18
+ - Made the new Long Number logic added in 2.3.0 optional and disabled by default ([561](https://github.com/opensearch-project/opensearch-js/pull/561)
19
+ ### Deprecated
20
+ ### Removed
21
+ ### Fixed
22
+ ### Security
23
+
14
24
  ## [2.3.0]
15
25
 
16
26
  ### Added
@@ -155,4 +165,5 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
155
165
 
156
166
  [2.1.0]: https://github.com/opensearch-project/opensearch-js/releases/tag/2.1.0
157
167
  [2.2.0]: https://github.com/opensearch-project/opensearch-js/releases/tag/2.2.0
158
- [Unreleased]: https://github.com/opensearch-project/opensearch-js/compare/2.2.0...HEAD
168
+ [2.3.0]: https://github.com/opensearch-project/opensearch-js/releases/tag/2.3.0
169
+ [Unreleased]: https://github.com/opensearch-project/opensearch-js/compare/2.3.0...HEAD
package/USER_GUIDE.md CHANGED
@@ -5,6 +5,7 @@
5
5
  - [Authenticate with Amazon OpenSearch Service](#authenticate-with-amazon-opensearch-service)
6
6
  - [Using AWS V2 SDK](#using-aws-v2-sdk)
7
7
  - [Using AWS V3 SDK](#using-aws-v3-sdk)
8
+ - [Enable Handling of Long Numerals](#enable-handling-of-long-numerals)
8
9
  - [Create an Index](#create-an-index)
9
10
  - [Add a Document to the Index](#add-a-document-to-the-index)
10
11
  - [Search for the Document](#search-for-the-document)
@@ -107,6 +108,21 @@ const client = new Client({
107
108
  });
108
109
  ```
109
110
 
111
+ ### Enable Handling of Long Numerals
112
+
113
+ JavaScript can safely work with integers from -(2<sup>53</sup> - 1) to 2<sup>53</sup> - 1. However,
114
+ serialized JSON texts from other languages can potentially have numeric values beyond that range and the native
115
+ serialization and deserialization methods of JavaScript's JSON, incapable of parsing them with precision; these
116
+ values get rounded to fit the IEEE-754 representation.
117
+
118
+ The `Client` can be configured to appropriately deserialize long numerals as `BigInt` values and vice versa:
119
+
120
+ ```javascript
121
+ const client = new Client({
122
+ enableLongNumeralSupport: true,
123
+ });
124
+ ```
125
+
110
126
  ## Create an Index
111
127
 
112
128
  ```javascript
package/index.js CHANGED
@@ -128,6 +128,7 @@ class Client extends OpenSearchAPI {
128
128
  proxy: null,
129
129
  enableMetaHeader: true,
130
130
  disablePrototypePoisoningProtection: false,
131
+ enableLongNumeralSupport: false,
131
132
  },
132
133
  opts
133
134
  );
@@ -151,6 +152,7 @@ class Client extends OpenSearchAPI {
151
152
  this[kEventEmitter] = new EventEmitter();
152
153
  this.serializer = new options.Serializer({
153
154
  disablePrototypePoisoningProtection: options.disablePrototypePoisoningProtection,
155
+ enableLongNumeralSupport: options.enableLongNumeralSupport,
154
156
  });
155
157
  this.connectionPool = new options.ConnectionPool({
156
158
  pingTimeout: options.pingTimeout,
@@ -29,6 +29,7 @@
29
29
 
30
30
  export interface SerializerOptions {
31
31
  disablePrototypePoisoningProtection: boolean | 'proto' | 'constructor';
32
+ enableLongNumeralSupport: boolean;
32
33
  }
33
34
 
34
35
  export default class Serializer {
package/lib/Serializer.js CHANGED
@@ -95,6 +95,7 @@ class Serializer {
95
95
  this[kJsonOptions] = {
96
96
  protoAction: disable === true || disable === 'proto' ? 'ignore' : 'error',
97
97
  constructorAction: disable === true || disable === 'constructor' ? 'ignore' : 'error',
98
+ enableLongNumeralSupport: opts.enableLongNumeralSupport === true,
98
99
  };
99
100
  }
100
101
 
@@ -258,10 +259,12 @@ class Serializer {
258
259
  }
259
260
  return val;
260
261
  };
262
+ const shouldHandleLongNumerals =
263
+ isBigIntSupported && this[kJsonOptions].enableLongNumeralSupport;
261
264
  try {
262
- json = JSON.stringify(object, isBigIntSupported ? checkForBigInts : null);
265
+ json = JSON.stringify(object, shouldHandleLongNumerals ? checkForBigInts : null);
263
266
 
264
- if (isBigIntSupported && !numeralsAreNumbers) {
267
+ if (shouldHandleLongNumerals && !numeralsAreNumbers) {
265
268
  const temp = this._stringifyWithBigInt(object, json);
266
269
  if (temp) json = temp;
267
270
  }
@@ -286,14 +289,16 @@ class Serializer {
286
289
 
287
290
  return val;
288
291
  };
292
+ const shouldHandleLongNumerals =
293
+ isBigIntSupported && this[kJsonOptions].enableLongNumeralSupport;
289
294
  try {
290
295
  object = sjson.parse(
291
296
  json,
292
- isBigIntSupported ? checkForLargeNumerals : null,
297
+ shouldHandleLongNumerals ? checkForLargeNumerals : null,
293
298
  this[kJsonOptions]
294
299
  );
295
300
 
296
- if (isBigIntSupported && !numeralsAreNumbers) {
301
+ if (shouldHandleLongNumerals && !numeralsAreNumbers) {
297
302
  const temp = this._parseWithBigInt(json);
298
303
  if (temp) {
299
304
  object = temp;
package/package.json CHANGED
@@ -23,7 +23,7 @@
23
23
  }
24
24
  },
25
25
  "homepage": "https://www.opensearch.org/",
26
- "version": "2.3.0",
26
+ "version": "2.3.1",
27
27
  "versionCanary": "7.10.0-canary.6",
28
28
  "keywords": [
29
29
  "opensearch",