@terascope/elasticsearch-api 4.0.1 → 4.2.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/index.js +16 -15
- package/jest.config.js +0 -9
- package/package.json +6 -6
- package/test/api-spec.js +14 -14
- package/test/bulk-send-limit-spec.js +3 -1
- package/.eslintrc.json +0 -14
package/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable camelcase */
|
|
2
|
-
|
|
3
1
|
// polyfill because opensearch has references to an api that won't exist
|
|
4
2
|
// on the client side, should be able to remove in the future
|
|
5
3
|
import Promise from 'bluebird';
|
|
@@ -69,13 +67,13 @@ export default function elasticsearchApi(client, logger, _opConfig) {
|
|
|
69
67
|
|
|
70
68
|
function search(query) {
|
|
71
69
|
const {
|
|
72
|
-
_sourceInclude, _source_includes,
|
|
73
|
-
_sourceExclude, _source_excludes,
|
|
70
|
+
_sourceInclude, _source_includes: oldSourIncludes,
|
|
71
|
+
_sourceExclude, _source_excludes: oldSourExcludes,
|
|
74
72
|
...safeQuery
|
|
75
73
|
} = query;
|
|
76
74
|
|
|
77
|
-
const sourceIncludes = _sourceInclude ||
|
|
78
|
-
const sourceExcludes = _sourceExclude ||
|
|
75
|
+
const sourceIncludes = _sourceInclude || oldSourIncludes;
|
|
76
|
+
const sourceExcludes = _sourceExclude || oldSourExcludes;
|
|
79
77
|
|
|
80
78
|
if (sourceIncludes) {
|
|
81
79
|
safeQuery._source_includes = sourceIncludes;
|
|
@@ -354,13 +352,16 @@ export default function elasticsearchApi(client, logger, _opConfig) {
|
|
|
354
352
|
const actionKey = getFirstKey(record.action);
|
|
355
353
|
const { _type, ...withoutTypeAction } = record.action[actionKey];
|
|
356
354
|
// if data is specified return both
|
|
357
|
-
return record.data
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
355
|
+
return record.data
|
|
356
|
+
? [{
|
|
357
|
+
...record.action,
|
|
358
|
+
[actionKey]: withoutTypeAction
|
|
359
|
+
},
|
|
360
|
+
record.data]
|
|
361
|
+
: [{
|
|
362
|
+
...record.action,
|
|
363
|
+
[actionKey]: withoutTypeAction
|
|
364
|
+
}];
|
|
364
365
|
}
|
|
365
366
|
|
|
366
367
|
// if data is specified return both
|
|
@@ -1100,7 +1101,8 @@ export default function elasticsearchApi(client, logger, _opConfig) {
|
|
|
1100
1101
|
});
|
|
1101
1102
|
return Promise.reject(error);
|
|
1102
1103
|
});
|
|
1103
|
-
})
|
|
1104
|
+
})
|
|
1105
|
+
.catch((err) => Promise.reject(err));
|
|
1104
1106
|
}
|
|
1105
1107
|
|
|
1106
1108
|
function _verifyMapping(query, configMapping, recordType) {
|
|
@@ -1177,7 +1179,6 @@ export default function elasticsearchApi(client, logger, _opConfig) {
|
|
|
1177
1179
|
clientName,
|
|
1178
1180
|
_time
|
|
1179
1181
|
) {
|
|
1180
|
-
// eslint-disable-line
|
|
1181
1182
|
const giveupAfter = Date.now() + (_time || 10000);
|
|
1182
1183
|
return new Promise((resolve, reject) => {
|
|
1183
1184
|
const attemptToCreateIndex = () => {
|
package/jest.config.js
CHANGED
|
@@ -8,13 +8,4 @@ const module = await import(configModulePath);
|
|
|
8
8
|
|
|
9
9
|
const config = module.default(dirPath);
|
|
10
10
|
|
|
11
|
-
config.extensionsToTreatAsEsm = ['.ts'];
|
|
12
|
-
config.moduleNameMapper = {
|
|
13
|
-
'^(\\.{1,2}/.*)\\.js$': '$1',
|
|
14
|
-
};
|
|
15
|
-
config.testTimeout = 60 * 1000;
|
|
16
|
-
config.transform = {};
|
|
17
|
-
|
|
18
|
-
config.transform['^.+\\.(t|j)sx?$'] = '@swc/jest';
|
|
19
|
-
|
|
20
11
|
export default config;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terascope/elasticsearch-api",
|
|
3
3
|
"displayName": "Elasticsearch API",
|
|
4
|
-
"version": "4.0
|
|
4
|
+
"version": "4.2.0",
|
|
5
5
|
"description": "Elasticsearch client api used across multiple services, handles retries and exponential backoff",
|
|
6
6
|
"homepage": "https://github.com/terascope/teraslice/tree/master/packages/elasticsearch-api#readme",
|
|
7
7
|
"bugs": {
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"test:watch": "TEST_RESTRAINED_ELASTICSEARCH='true' ts-scripts test --watch . --"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@terascope/types": "^1.
|
|
28
|
-
"@terascope/utils": "^1.
|
|
27
|
+
"@terascope/types": "^1.1.0",
|
|
28
|
+
"@terascope/utils": "^1.2.0",
|
|
29
29
|
"bluebird": "^3.7.2",
|
|
30
30
|
"setimmediate": "^1.0.5"
|
|
31
31
|
},
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"@opensearch-project/opensearch": "^1.2.0",
|
|
34
34
|
"@types/elasticsearch": "^5.0.43",
|
|
35
35
|
"elasticsearch": "^15.4.1",
|
|
36
|
-
"elasticsearch-store": "^1.0
|
|
36
|
+
"elasticsearch-store": "^1.2.0",
|
|
37
37
|
"elasticsearch6": "npm:@elastic/elasticsearch@^6.7.0",
|
|
38
38
|
"elasticsearch7": "npm:@elastic/elasticsearch@^7.0.0",
|
|
39
39
|
"elasticsearch8": "npm:@elastic/elasticsearch@^8.0.0"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
43
|
-
"yarn": ">=1.
|
|
42
|
+
"node": ">=18.18.0",
|
|
43
|
+
"yarn": ">=1.22.19"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public",
|
package/test/api-spec.js
CHANGED
|
@@ -452,7 +452,7 @@ describe('elasticsearch-api', () => {
|
|
|
452
452
|
searchError = { body: { error: { type: 'some_thing_else' } } };
|
|
453
453
|
try {
|
|
454
454
|
await api.search(query);
|
|
455
|
-
} catch (
|
|
455
|
+
} catch (_err) {
|
|
456
456
|
queryFailed = true;
|
|
457
457
|
}
|
|
458
458
|
return expect(queryFailed).toEqual(true);
|
|
@@ -485,7 +485,7 @@ describe('elasticsearch-api', () => {
|
|
|
485
485
|
failures = [];
|
|
486
486
|
})
|
|
487
487
|
]);
|
|
488
|
-
} catch (
|
|
488
|
+
} catch (_err) {
|
|
489
489
|
queryFailed = true;
|
|
490
490
|
}
|
|
491
491
|
return expect(queryFailed).toEqual(true);
|
|
@@ -731,10 +731,10 @@ describe('elasticsearch-api', () => {
|
|
|
731
731
|
return expect(results).toBeTruthy();
|
|
732
732
|
});
|
|
733
733
|
|
|
734
|
-
it('can warn window size with version', () => {
|
|
734
|
+
it('can warn window size with version', async () => {
|
|
735
735
|
const api = esApi(client, logger, { index: 'some_index' });
|
|
736
|
-
|
|
737
|
-
|
|
736
|
+
// FIXME: this test is only really testing a side effect, need a better test
|
|
737
|
+
expect(api.version).toBeFunction();
|
|
738
738
|
});
|
|
739
739
|
|
|
740
740
|
it('can call putTemplate', async () => {
|
|
@@ -1157,7 +1157,7 @@ describe('elasticsearch-api', () => {
|
|
|
1157
1157
|
expect(api.buildQuery(opConfig3, msg4)).toEqual(makeResponse(opConfig3, msg1, response5));
|
|
1158
1158
|
});
|
|
1159
1159
|
|
|
1160
|
-
it('can set up an index', () => {
|
|
1160
|
+
it('can set up an index', async () => {
|
|
1161
1161
|
const api = esApi(client, logger);
|
|
1162
1162
|
const clusterName = 'teracluster';
|
|
1163
1163
|
const newIndex = 'teracluster__state';
|
|
@@ -1165,17 +1165,17 @@ describe('elasticsearch-api', () => {
|
|
|
1165
1165
|
const recordType = 'state';
|
|
1166
1166
|
const clientName = 'default';
|
|
1167
1167
|
|
|
1168
|
-
|
|
1168
|
+
await expect(api.indexSetup(
|
|
1169
1169
|
clusterName,
|
|
1170
1170
|
newIndex,
|
|
1171
1171
|
migrantIndexName,
|
|
1172
1172
|
template,
|
|
1173
1173
|
recordType,
|
|
1174
1174
|
clientName
|
|
1175
|
-
);
|
|
1175
|
+
)).resolves.not.toThrow();
|
|
1176
1176
|
});
|
|
1177
1177
|
|
|
1178
|
-
it('can set up an index and wait for availability', () => {
|
|
1178
|
+
it('can set up an index and wait for availability', async () => {
|
|
1179
1179
|
const api = esApi(client, logger);
|
|
1180
1180
|
const clusterName = 'teracluster';
|
|
1181
1181
|
const newIndex = 'teracluster__state';
|
|
@@ -1185,7 +1185,7 @@ describe('elasticsearch-api', () => {
|
|
|
1185
1185
|
|
|
1186
1186
|
searchError = true;
|
|
1187
1187
|
|
|
1188
|
-
|
|
1188
|
+
await expect(Promise.all([
|
|
1189
1189
|
waitFor(300, () => {
|
|
1190
1190
|
searchError = false;
|
|
1191
1191
|
}),
|
|
@@ -1197,10 +1197,10 @@ describe('elasticsearch-api', () => {
|
|
|
1197
1197
|
recordType,
|
|
1198
1198
|
clientName
|
|
1199
1199
|
)
|
|
1200
|
-
]);
|
|
1200
|
+
])).resolves.not.toThrow();
|
|
1201
1201
|
});
|
|
1202
1202
|
|
|
1203
|
-
it('can wait for elasticsearch availability', () => {
|
|
1203
|
+
it('can wait for elasticsearch availability', async () => {
|
|
1204
1204
|
const api = esApi(client, logger);
|
|
1205
1205
|
const clusterName = 'teracluster';
|
|
1206
1206
|
const newIndex = 'teracluster__state';
|
|
@@ -1211,7 +1211,7 @@ describe('elasticsearch-api', () => {
|
|
|
1211
1211
|
elasticDown = true;
|
|
1212
1212
|
recoverError = true;
|
|
1213
1213
|
|
|
1214
|
-
|
|
1214
|
+
await expect(Promise.all([
|
|
1215
1215
|
api.indexSetup(
|
|
1216
1216
|
clusterName,
|
|
1217
1217
|
newIndex,
|
|
@@ -1227,7 +1227,7 @@ describe('elasticsearch-api', () => {
|
|
|
1227
1227
|
waitFor(1200, () => {
|
|
1228
1228
|
recoverError = false;
|
|
1229
1229
|
})
|
|
1230
|
-
]);
|
|
1230
|
+
])).resolves.not.toThrow();
|
|
1231
1231
|
});
|
|
1232
1232
|
|
|
1233
1233
|
it('can send template on state mapping changes, does not migrate', async () => {
|
|
@@ -41,7 +41,9 @@ describe('bulkSend', () => {
|
|
|
41
41
|
return api.bulkSend(formattedData);
|
|
42
42
|
}, { concurrency: 9 });
|
|
43
43
|
|
|
44
|
-
await
|
|
44
|
+
await expect(
|
|
45
|
+
waitForData(client, index, EvenDateData.data.length, logger, THREE_MINUTES)
|
|
46
|
+
).resolves.not.toThrow();
|
|
45
47
|
});
|
|
46
48
|
});
|
|
47
49
|
});
|
package/.eslintrc.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@terascope",
|
|
3
|
-
"parserOptions": {
|
|
4
|
-
"ecmaVersion": "latest",
|
|
5
|
-
"sourceType": "module"
|
|
6
|
-
},
|
|
7
|
-
"rules": {
|
|
8
|
-
"@typescript-eslint/naming-convention": "off",
|
|
9
|
-
"@typescript-eslint/no-duplicate-enum-values": "warn",
|
|
10
|
-
"import/extensions": "off",
|
|
11
|
-
"import/no-import-module-exports": "off"
|
|
12
|
-
},
|
|
13
|
-
"ignorePatterns":[]
|
|
14
|
-
}
|