@xnestjs/elasticsearch 1.12.3 → 1.13.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.
@@ -9,6 +9,9 @@ import { ELASTICSEARCH_CONNECTION_OPTIONS, ELASTICSEARCH_MODULE_ID, } from './co
9
9
  import { getElasticsearchConfig } from './get-elasticsearch-config.js';
10
10
  const CLIENT_TOKEN = Symbol('CLIENT_TOKEN');
11
11
  let ElasticsearchCoreModule = ElasticsearchCoreModule_1 = class ElasticsearchCoreModule {
12
+ client;
13
+ logger;
14
+ connectionOptions;
12
15
  /**
13
16
  *
14
17
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xnestjs/elasticsearch",
3
- "version": "1.12.3",
3
+ "version": "1.13.0",
4
4
  "description": "NestJS extension library for ElasticSearch",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -17,38 +17,22 @@
17
17
  "@nestjs/elasticsearch": "^10.0.0 || ^11.0.0"
18
18
  },
19
19
  "type": "module",
20
+ "module": "./index.js",
21
+ "types": "./index.d.ts",
20
22
  "exports": {
21
23
  ".": {
22
- "import": {
23
- "types": "./types/index.d.ts",
24
- "default": "./esm/index.js"
25
- },
26
- "require": {
27
- "types": "./types/index.d.cts",
28
- "default": "./cjs/index.js"
29
- },
30
- "default": "./esm/index.js"
24
+ "types": "./index.d.ts",
25
+ "default": "./index.js"
31
26
  },
32
27
  "./package.json": "./package.json"
33
28
  },
34
- "main": "./cjs/index.js",
35
- "module": "./esm/index.js",
36
- "types": "./types/index.d.ts",
29
+ "engines": {
30
+ "node": ">=20.0"
31
+ },
37
32
  "repository": {
38
33
  "registry": "https://github.com/panates/xnestjs.git",
39
34
  "directory": "packages/elasticsearch"
40
35
  },
41
- "engines": {
42
- "node": ">=16.0",
43
- "npm": ">=7.0.0"
44
- },
45
- "files": [
46
- "cjs/",
47
- "esm/",
48
- "types/",
49
- "LICENSE",
50
- "README.md"
51
- ],
52
36
  "keywords": [
53
37
  "nestjs",
54
38
  "elasticsearch"
package/cjs/constants.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ELASTICSEARCH_MODULE_ID = exports.ELASTICSEARCH_CONNECTION_OPTIONS = void 0;
4
- exports.ELASTICSEARCH_CONNECTION_OPTIONS = Symbol('ELASTICSEARCH_CONNECTION_OPTIONS');
5
- exports.ELASTICSEARCH_MODULE_ID = Symbol('ELASTICSEARCH_MODULE_ID');
@@ -1,134 +0,0 @@
1
- "use strict";
2
- var ElasticsearchCoreModule_1;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ElasticsearchCoreModule = void 0;
5
- const tslib_1 = require("tslib");
6
- const node_assert_1 = tslib_1.__importDefault(require("node:assert"));
7
- const crypto = tslib_1.__importStar(require("node:crypto"));
8
- const common_1 = require("@nestjs/common");
9
- const elasticsearch_1 = require("@nestjs/elasticsearch");
10
- const ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
11
- const constants_js_1 = require("./constants.js");
12
- const get_elasticsearch_config_js_1 = require("./get-elasticsearch-config.js");
13
- const CLIENT_TOKEN = Symbol('CLIENT_TOKEN');
14
- let ElasticsearchCoreModule = ElasticsearchCoreModule_1 = class ElasticsearchCoreModule {
15
- /**
16
- *
17
- */
18
- static forRoot(moduleOptions) {
19
- const connectionOptions = (0, get_elasticsearch_config_js_1.getElasticsearchConfig)(moduleOptions.useValue || {}, moduleOptions.envPrefix);
20
- return this._createDynamicModule(moduleOptions, {
21
- providers: [
22
- {
23
- provide: constants_js_1.ELASTICSEARCH_CONNECTION_OPTIONS,
24
- useValue: connectionOptions,
25
- },
26
- ],
27
- });
28
- }
29
- /**
30
- *
31
- */
32
- static forRootAsync(asyncOptions) {
33
- node_assert_1.default.ok(asyncOptions.useFactory, 'useFactory is required');
34
- return this._createDynamicModule(asyncOptions, {
35
- providers: [
36
- {
37
- provide: constants_js_1.ELASTICSEARCH_CONNECTION_OPTIONS,
38
- inject: asyncOptions.inject,
39
- useFactory: async (...args) => {
40
- const opts = await asyncOptions.useFactory(...args);
41
- return (0, get_elasticsearch_config_js_1.getElasticsearchConfig)(opts, asyncOptions.envPrefix);
42
- },
43
- },
44
- ],
45
- });
46
- }
47
- static _createDynamicModule(opts, metadata) {
48
- const token = opts.token ?? elasticsearch_1.ElasticsearchService;
49
- const logger = typeof opts.logger === 'string' ? new common_1.Logger(opts.logger) : opts.logger;
50
- const exports = [
51
- constants_js_1.ELASTICSEARCH_CONNECTION_OPTIONS,
52
- ...(metadata.exports ?? []),
53
- ];
54
- const providers = [
55
- ...(metadata.providers ?? []),
56
- {
57
- provide: common_1.Logger,
58
- useValue: logger,
59
- },
60
- {
61
- provide: CLIENT_TOKEN,
62
- useExisting: elasticsearch_1.ElasticsearchService,
63
- },
64
- {
65
- provide: constants_js_1.ELASTICSEARCH_MODULE_ID,
66
- useValue: crypto.randomUUID(),
67
- },
68
- ];
69
- if (token !== elasticsearch_1.ElasticsearchService) {
70
- exports.push(token);
71
- providers.push({
72
- provide: token,
73
- useExisting: elasticsearch_1.ElasticsearchService,
74
- });
75
- }
76
- else
77
- exports.push(elasticsearch_1.ElasticsearchModule);
78
- class InnerProvidersModule {
79
- }
80
- return {
81
- global: opts.global,
82
- module: ElasticsearchCoreModule_1,
83
- providers,
84
- imports: [
85
- ...(metadata.imports ?? []),
86
- elasticsearch_1.ElasticsearchModule.registerAsync({
87
- imports: [
88
- {
89
- module: InnerProvidersModule,
90
- providers: metadata.providers,
91
- exports: metadata.providers,
92
- },
93
- ],
94
- inject: [constants_js_1.ELASTICSEARCH_CONNECTION_OPTIONS],
95
- useFactory: async (connectionOptions) => {
96
- return connectionOptions;
97
- },
98
- }),
99
- ],
100
- exports,
101
- };
102
- }
103
- /**
104
- *
105
- * @constructor
106
- */
107
- constructor(client, logger, connectionOptions) {
108
- this.client = client;
109
- this.logger = logger;
110
- this.connectionOptions = connectionOptions;
111
- }
112
- async onApplicationBootstrap() {
113
- const options = this.connectionOptions;
114
- if (options.lazyConnect)
115
- return;
116
- const nodes = options.node || options.nodes;
117
- this.logger?.log(`Connecting to ElasticSearch at ${ansi_colors_1.default.blue(String(nodes))}`);
118
- common_1.Logger.flush();
119
- await this.client.ping({}).catch(e => {
120
- this.logger.error('ElasticSearch connection failed: ' + e.message);
121
- throw e;
122
- });
123
- }
124
- onApplicationShutdown() {
125
- return this.client.close();
126
- }
127
- };
128
- exports.ElasticsearchCoreModule = ElasticsearchCoreModule;
129
- exports.ElasticsearchCoreModule = ElasticsearchCoreModule = ElasticsearchCoreModule_1 = tslib_1.__decorate([
130
- tslib_1.__param(0, (0, common_1.Inject)(CLIENT_TOKEN)),
131
- tslib_1.__param(2, (0, common_1.Inject)(constants_js_1.ELASTICSEARCH_CONNECTION_OPTIONS)),
132
- tslib_1.__metadata("design:paramtypes", [elasticsearch_1.ElasticsearchService,
133
- common_1.Logger, Object])
134
- ], ElasticsearchCoreModule);
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ElasticsearchModule = void 0;
4
- const elasticsearch_core_module_js_1 = require("./elasticsearch-core.module.js");
5
- /**
6
- * The ElasticsearchModule class is responsible for providing integration with Elasticsearch
7
- * through dynamic module configurations. It allows synchronous and asynchronous setup of
8
- * Elasticsearch configurations for use in a Node.js application.
9
- */
10
- class ElasticsearchModule {
11
- /**
12
- * Configures and returns the dynamic module for the Elasticsearch integration.
13
- *
14
- */
15
- static forRoot(options) {
16
- return {
17
- module: ElasticsearchModule,
18
- imports: [elasticsearch_core_module_js_1.ElasticsearchCoreModule.forRoot(options || {})],
19
- };
20
- }
21
- /**
22
- * Configures and returns the async dynamic module for the Elasticsearch integration.
23
- *
24
- */
25
- static forRootAsync(options) {
26
- return {
27
- module: ElasticsearchModule,
28
- imports: [elasticsearch_core_module_js_1.ElasticsearchCoreModule.forRootAsync(options)],
29
- };
30
- }
31
- }
32
- exports.ElasticsearchModule = ElasticsearchModule;
@@ -1,78 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getElasticsearchConfig = getElasticsearchConfig;
4
- const tslib_1 = require("tslib");
5
- const node_process_1 = tslib_1.__importDefault(require("node:process"));
6
- const objects_1 = require("@jsopen/objects");
7
- const putil_varhelpers_1 = require("putil-varhelpers");
8
- function getElasticsearchConfig(moduleOptions, prefix = 'ELASTIC_') {
9
- const options = (0, objects_1.clone)(moduleOptions);
10
- const env = node_process_1.default.env;
11
- options.node = options.node || env[prefix + 'NODE'];
12
- if (options.node) {
13
- if (typeof options.node === 'string' && options.node.includes(','))
14
- options.node.split(/\s*,\s*/);
15
- }
16
- else {
17
- options.nodes = options.nodes || env[prefix + 'NODES'];
18
- if (options.nodes) {
19
- if (typeof options.nodes === 'string' && options.nodes.includes(','))
20
- options.nodes.split(/\s*,\s*/);
21
- }
22
- }
23
- if (!(options.node || options.nodes))
24
- options.node = 'http://localhost:9200';
25
- options.maxRetries = options.maxRetries ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_RETRIES']);
26
- options.requestTimeout =
27
- options.requestTimeout ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'REQUEST_TIMEOUT']);
28
- options.pingTimeout =
29
- options.pingTimeout ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'PING_TIMEOUT']);
30
- if (options.tls == null && (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS'])) {
31
- options.tls = {
32
- ca: [env[prefix + 'TLS_CA_CERT'] || ''],
33
- cert: env[prefix + 'TLS_CERT_FILE'],
34
- key: env[prefix + 'TLS_KEY_FILE'],
35
- passphrase: env[prefix + 'TLS_KEY_PASSPHRASE'],
36
- rejectUnauthorized: (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS_REJECT_UNAUTHORIZED']),
37
- checkServerIdentity: (host, cert) => {
38
- if (cert.subject.CN !== host) {
39
- return new Error(`Certificate CN (${cert.subject.CN}) does not match host (${host})`);
40
- }
41
- },
42
- };
43
- }
44
- options.name = options.name ?? env[prefix + 'NAME'];
45
- if (!options.auth) {
46
- if (env[prefix + 'AUTH_USERNAME']) {
47
- options.auth = {
48
- username: env[prefix + 'AUTH_USERNAME'],
49
- password: env[prefix + 'AUTH_PASSWORD'] || '',
50
- };
51
- }
52
- else if (env[prefix + 'AUTH_BEARER']) {
53
- options.auth = {
54
- bearer: env[prefix + 'AUTH_BEARER'],
55
- };
56
- }
57
- else if (env[prefix + 'AUTH_API_KEY']) {
58
- if (env[prefix + 'API_KEY_ID'])
59
- options.auth = {
60
- apiKey: {
61
- id: env[prefix + 'API_KEY_ID'],
62
- api_key: env[prefix + 'API_KEY'],
63
- },
64
- };
65
- options.auth = {
66
- apiKey: env[prefix + 'API_KEY'],
67
- };
68
- }
69
- }
70
- options.caFingerprint =
71
- options.caFingerprint ?? env[prefix + 'CA_FINGERPRINT'];
72
- options.maxResponseSize =
73
- options.maxResponseSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_RESPONSE_SIZE']);
74
- options.maxCompressedResponseSize =
75
- options.maxCompressedResponseSize ??
76
- (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_COMPRESSED_RESPONSE_SIZE']);
77
- return options;
78
- }
package/cjs/index.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ElasticsearchService = void 0;
4
- const tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./constants.js"), exports);
6
- tslib_1.__exportStar(require("./elasticsearch.module.js"), exports);
7
- tslib_1.__exportStar(require("./get-elasticsearch-config.js"), exports);
8
- tslib_1.__exportStar(require("./types.js"), exports);
9
- var elasticsearch_1 = require("@nestjs/elasticsearch");
10
- Object.defineProperty(exports, "ElasticsearchService", { enumerable: true, get: function () { return elasticsearch_1.ElasticsearchService; } });
package/cjs/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
package/cjs/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/esm/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
package/types/index.d.cts DELETED
@@ -1,5 +0,0 @@
1
- export * from './constants.js';
2
- export * from './elasticsearch.module.js';
3
- export * from './get-elasticsearch-config.js';
4
- export * from './types.js';
5
- export { ElasticsearchService } from '@nestjs/elasticsearch';
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes