Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@12stonechurch/omnihive-worker-elastic

Package Overview
Dependencies
Maintainers
2
Versions
169
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@12stonechurch/omnihive-worker-elastic - npm Package Compare versions

Comparing version 1.3.261031 to 1.3.311302

10

index.d.ts

@@ -17,2 +17,3 @@ import { Client } from "@elastic/elasticsearch";

client?: Client;
private validIndexes?;
constructor();

@@ -23,9 +24,6 @@ init(config: HiveWorker): Promise<void>;

update(index: string, id: string, data: any, upsert?: boolean): Promise<void>;
bulkUpdate(index: string, idObject: {
name: string;
values: string[];
}, data: any): Promise<void>;
bulkUpdate(index: string, idKey: string, data: any[]): Promise<void>;
delete(index: string, id: string): Promise<void>;
removeUnused(index: string, fieldName: string, usedKeys: string[]): Promise<void>;
upsert(index: string, idName: string, idList: string[], data: any[]): Promise<void>;
removeUnused(index: string, usedKeys: string[], idKey: string): Promise<void>;
upsert(index: string, idName: string, data: any[]): Promise<void>;
validateIndex(index: string, noCreate?: boolean): Promise<boolean>;

@@ -32,0 +30,0 @@ deleteIndex(index: string): Promise<void>;

87

index.js

@@ -45,2 +45,7 @@ "use strict";

},
maxRetries: 5,
agent: {
keepAlive: true,
keepAliveMsecs: 60000,
},
});

@@ -59,3 +64,3 @@ }

if (this.client && indexExists) {
return (yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.search({
const results = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.search({
index: index,

@@ -74,3 +79,4 @@ body: {

},
}))).body;
}));
return results.body;
}

@@ -124,2 +130,4 @@ else if (!indexExists) {

id: id,
refresh: true,
retry_on_conflict: 5,
body: {

@@ -141,4 +149,3 @@ doc: data,

}
bulkUpdate(index, idObject, data) {
var _a;
bulkUpdate(index, idKey, data) {
return __awaiter(this, void 0, void 0, function* () {

@@ -148,24 +155,10 @@ try {

if (this.client && indexExists) {
const updateQuery = {};
updateQuery[idObject.name] = idObject.values;
(_a = this.client) === null || _a === void 0 ? void 0 : _a.updateByQuery({
index: index,
this.client.helpers.bulk({
datasource: data,
refresh: true,
body: {
doc: data,
query: {
bool: {
must: [
{
terms: { updateQuery },
},
],
},
},
onDocument(doc) {
return [{ update: { _index: index, _id: doc[idKey] } }, { doc_as_upsert: true }];
},
});
}
else if (!indexExists) {
return;
}
else {

@@ -204,3 +197,3 @@ throw new Error("Elastic Client not initialized");

}
removeUnused(index, fieldName, usedKeys) {
removeUnused(index, usedKeys, idKey) {
var _a;

@@ -211,18 +204,19 @@ return __awaiter(this, void 0, void 0, function* () {

if (this.client && indexExists) {
const deleteObject = {};
deleteObject[fieldName] = usedKeys;
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.deleteByQuery({
index: index,
const unusedKeys = (yield this.client.sql.query({
body: {
query: {
bool: {
must_not: [
{
terms: deleteObject,
},
],
query: `Select ${idKey} From \"${index}\" where ${idKey} not in (${usedKeys})`,
},
})).body.rows;
if (unusedKeys && unusedKeys.length > 0) {
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.deleteByQuery({
index: index,
body: {
query: {
ids: {
values: unusedKeys,
},
},
},
},
}));
}));
}
}

@@ -241,11 +235,7 @@ else if (!indexExists) {

}
upsert(index, idName, idList, data) {
upsert(index, idName, data) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (this.client) {
yield this.validateIndex(index);
for (const id of idList) {
const idData = data.find((x) => x[idName].toString() === id);
yield AwaitHelper_1.AwaitHelper.execute(this.update(index, id, idData, true));
}
yield AwaitHelper_1.AwaitHelper.execute(this.bulkUpdate(index, idName, data));
return;

@@ -263,11 +253,18 @@ }

validateIndex(index, noCreate = false) {
var _a;
var _a, _b, _c, _d;
return __awaiter(this, void 0, void 0, function* () {
try {
if ((_a = this.validIndexes) === null || _a === void 0 ? void 0 : _a.find((x) => x === index)) {
return true;
}
if (this.client) {
const indexExists = (yield this.client.indices.exists({ index: index })).body;
if (!indexExists && !noCreate) {
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.indices.create({ index: index }));
yield ((_b = this.client) === null || _b === void 0 ? void 0 : _b.indices.create({ index: index }));
(_c = this.validIndexes) === null || _c === void 0 ? void 0 : _c.push(index);
return true;
}
if (indexExists) {
(_d = this.validIndexes) === null || _d === void 0 ? void 0 : _d.push(index);
}
return indexExists;

@@ -289,3 +286,3 @@ }

if (this.client && indexExists) {
this.client.indices.delete({ index: index });
yield this.client.indices.delete({ index: index });
}

@@ -292,0 +289,0 @@ else if (!indexExists) {

{
"name": "@12stonechurch/omnihive-worker-elastic",
"version": "1.3.261031",
"version": "1.3.311302",
"description": "OmniHive Elastic Search Worker",

@@ -5,0 +5,0 @@ "license": "MIT",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc