@openforge/elastic-enterprise-search
Version:
Official Node.js client for Elastic Enterprise Search, App Search, and Workplace Search.
125 lines • 4.9 kB
JavaScript
"use strict";
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var _a, _b, _c, _d, _e;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const transport_1 = require("@elastic/transport");
const EnterpriseSearchClient_1 = tslib_1.__importDefault(require("./EnterpriseSearchClient"));
const AppSearchClient_1 = tslib_1.__importDefault(require("./AppSearchClient"));
const WorkplaceSearchClient_1 = tslib_1.__importDefault(require("./WorkplaceSearchClient"));
const symbols_1 = require("./symbols");
class Client {
constructor(opts, internal) {
var _f;
Object.defineProperty(this, _a, {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, _b, {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, _c, {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, _d, {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, _e, {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "diagnostic", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this[symbols_1.kOptions] = opts;
this.diagnostic = (_f = internal === null || internal === void 0 ? void 0 : internal.diagnostic) !== null && _f !== void 0 ? _f : new transport_1.Diagnostic();
if ((internal === null || internal === void 0 ? void 0 : internal.connectionPool) != null) {
this[symbols_1.kConnectionPool] = internal.connectionPool;
}
else {
this[symbols_1.kConnectionPool] = new transport_1.CloudConnectionPool({
Connection: transport_1.UndiciConnection,
diagnostic: this.diagnostic,
tls: opts.url.startsWith('https://')
? { secureProtocol: 'TLSv1_2_method' }
: undefined
});
this[symbols_1.kConnectionPool].addConnection(opts.url);
}
this[symbols_1.kEnterpriseSearch] = null;
this[symbols_1.kAppSearch] = null;
this[symbols_1.kWorkplaceSearch] = null;
}
get enterprise() {
let client = this[symbols_1.kEnterpriseSearch];
if (client === null) {
client = new EnterpriseSearchClient_1.default(this[symbols_1.kOptions], {
connectionPool: this[symbols_1.kConnectionPool],
diagnostic: this.diagnostic
});
}
return client;
}
get app() {
let client = this[symbols_1.kAppSearch];
if (client === null) {
client = new AppSearchClient_1.default(this[symbols_1.kOptions], {
connectionPool: this[symbols_1.kConnectionPool],
diagnostic: this.diagnostic
});
}
return client;
}
get workplace() {
let client = this[symbols_1.kWorkplaceSearch];
if (client === null) {
client = new WorkplaceSearchClient_1.default(this[symbols_1.kOptions], {
connectionPool: this[symbols_1.kConnectionPool],
diagnostic: this.diagnostic
});
}
return client;
}
withAuth(opts) {
return new Client({ ...this[symbols_1.kOptions], ...opts }, { diagnostic: this.diagnostic, connectionPool: this[symbols_1.kConnectionPool] });
}
async close() {
return await this[symbols_1.kConnectionPool].empty();
}
}
exports.default = Client;
_a = symbols_1.kOptions, _b = symbols_1.kConnectionPool, _c = symbols_1.kEnterpriseSearch, _d = symbols_1.kAppSearch, _e = symbols_1.kWorkplaceSearch;
//# sourceMappingURL=index.js.map