@opra/elastic 1.5.7 → 1.7.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.
@@ -164,7 +164,7 @@ class ElasticCollectionService extends elastic_entity_service_js_1.ElasticEntity
164
164
  command.options?.filter,
165
165
  ]);
166
166
  command.options = { ...options, request, filter };
167
- const r = await this._search(command);
167
+ const r = await this._findMany(command);
168
168
  return !!(typeof r.hits.total === 'number'
169
169
  ? r.hits.total
170
170
  : r.hits.total?.value);
@@ -190,7 +190,7 @@ class ElasticCollectionService extends elastic_entity_service_js_1.ElasticEntity
190
190
  size: 0,
191
191
  };
192
192
  command.options = { ...options, request };
193
- const r = await this._search(command);
193
+ const r = await this._findMany(command);
194
194
  return !!(typeof r.hits.total === 'number'
195
195
  ? r.hits.total
196
196
  : r.hits.total?.value);
@@ -218,9 +218,9 @@ class ElasticCollectionService extends elastic_entity_service_js_1.ElasticEntity
218
218
  limit: 1,
219
219
  options: { ...command.options, filter },
220
220
  };
221
- const r = await this._search(newCommand);
221
+ const r = await this._findMany(newCommand);
222
222
  if (r.hits.hits?.length) {
223
- const outputCodec = this._getOutputCodec('find');
223
+ const outputCodec = this.getOutputCodec('find');
224
224
  return {
225
225
  _id: r.hits.hits[0]._id,
226
226
  ...outputCodec(r.hits.hits[0]._source),
@@ -248,9 +248,9 @@ class ElasticCollectionService extends elastic_entity_service_js_1.ElasticEntity
248
248
  limit: 1,
249
249
  options: { ...command.options, filter },
250
250
  };
251
- const r = await this._search(newCommand);
251
+ const r = await this._findMany(newCommand);
252
252
  if (r.hits.hits?.length) {
253
- const outputCodec = this._getOutputCodec('find');
253
+ const outputCodec = this.getOutputCodec('find');
254
254
  return {
255
255
  _id: r.hits.hits[0]._id,
256
256
  ...outputCodec(r.hits.hits[0]._source),
@@ -275,17 +275,20 @@ class ElasticCollectionService extends elastic_entity_service_js_1.ElasticEntity
275
275
  ]);
276
276
  const limit = command.options?.limit || this.defaultLimit;
277
277
  command.options = { ...command.options, filter, limit };
278
- const r = await this._search(command);
279
- if (r.hits.hits?.length) {
280
- const outputCodec = this._getOutputCodec('find');
281
- return r.hits.hits.map((x) => ({
282
- _id: x._id,
283
- ...outputCodec(x._source),
284
- }));
285
- }
286
- return [];
278
+ const r = await this._findMany(command);
279
+ return r.hits?.hits.map((x) => x._source) || [];
287
280
  });
288
281
  }
282
+ async search(request, options) {
283
+ const command = {
284
+ crud: 'read',
285
+ method: 'search',
286
+ byId: false,
287
+ request,
288
+ options,
289
+ };
290
+ return this._executeCommand(command, async () => this._search(command));
291
+ }
289
292
  /**
290
293
  *
291
294
  */
@@ -308,10 +311,10 @@ class ElasticCollectionService extends elastic_entity_service_js_1.ElasticEntity
308
311
  limit,
309
312
  request: { ...command.options?.request, track_total_hits: true },
310
313
  };
311
- const r = await this._search(command);
314
+ const r = await this._findMany(command);
312
315
  const out = {};
313
316
  if (r.hits.hits?.length) {
314
- const outputCodec = this._getOutputCodec('find');
317
+ const outputCodec = this.getOutputCodec('find');
315
318
  out.items = r.hits.hits.map((x) => ({
316
319
  _id: x._id,
317
320
  ...outputCodec(x._source),
@@ -343,7 +346,7 @@ class ElasticCollectionService extends elastic_entity_service_js_1.ElasticEntity
343
346
  * @param {string} id - The ID of the document to update.
344
347
  * @param {PatchDTO<T>} input - The partial input data to update the document with.
345
348
  * @param {ElasticEntityService.UpdateOneOptions} [options] - The options for updating the document.
346
- * @returns {Promise<elastic.UpdateResponse>} - A promise that resolves to the number of documents modified.
349
+ * @returns {Promise<estypes.UpdateResponse>} - A promise that resolves to the number of documents modified.
347
350
  */
348
351
  async update(id, input, options) {
349
352
  const command = {
@@ -192,9 +192,9 @@ class ElasticEntityService extends elastic_service_js_1.ElasticService {
192
192
  /**
193
193
  * Returns search hits that match the query defined in the request
194
194
  *
195
- * @param {ElasticEntityService.SearchCommand} command
195
+ * @param {ElasticEntityService.FindManyCommand} command
196
196
  */
197
- async _search(command) {
197
+ async _findMany(command) {
198
198
  const { options } = command;
199
199
  const filterQuery = elastic_adapter_js_1.ElasticAdapter.prepareFilter([
200
200
  command.documentId
@@ -221,7 +221,46 @@ class ElasticEntityService extends elastic_service_js_1.ElasticService {
221
221
  query,
222
222
  };
223
223
  const client = this.getClient();
224
- return client.search(request, options?.transport);
224
+ const r = await client.search(request, options?.transport);
225
+ if (options?.noDecode)
226
+ return r;
227
+ if (r.hits.hits?.length) {
228
+ const outputCodec = this.getOutputCodec('find');
229
+ r.hits.hits = r.hits.hits.map((x) => ({
230
+ ...x,
231
+ _source: {
232
+ _id: x._id,
233
+ ...outputCodec(x._source),
234
+ },
235
+ }));
236
+ }
237
+ return r;
238
+ }
239
+ /**
240
+ * Executes a search operation on the Elasticsearch index using the provided search command.
241
+ *
242
+ * @param {ElasticEntityService.SearchCommand} command - The search command containing the request configuration and optional transport settings.
243
+ * @return {Promise<ElasticEntityService.SearchResponse>} A promise resolving to the search response from Elasticsearch.
244
+ */
245
+ async _search(command) {
246
+ const { options } = command;
247
+ const request = {
248
+ index: this.getIndexName(),
249
+ ...command.request,
250
+ };
251
+ const client = this.getClient();
252
+ const r = await client.search(request, options?.transport);
253
+ if (r.hits.hits?.length) {
254
+ const outputCodec = this.getOutputCodec('find');
255
+ r.hits.hits = r.hits.hits.map((x) => ({
256
+ ...x,
257
+ _source: {
258
+ _id: x._id,
259
+ ...outputCodec(x._source),
260
+ },
261
+ }));
262
+ }
263
+ return r;
225
264
  }
226
265
  /**
227
266
  * Updates multiple documents in the collection based on the specified input and options.
@@ -307,8 +346,10 @@ class ElasticEntityService extends elastic_service_js_1.ElasticService {
307
346
  projection: '*',
308
347
  scope: this._dataTypeScope,
309
348
  };
310
- if (operation === 'update')
349
+ if (operation === 'update') {
311
350
  options.partial = 'deep';
351
+ options.keepKeyFields = true;
352
+ }
312
353
  const dataType = this.dataType;
313
354
  validator = dataType.generateCodec('decode', options);
314
355
  this._inputCodecs[cacheKey] = validator;
@@ -317,7 +358,7 @@ class ElasticEntityService extends elastic_service_js_1.ElasticService {
317
358
  /**
318
359
  * Retrieves the codec.
319
360
  */
320
- _getOutputCodec(operation) {
361
+ getOutputCodec(operation) {
321
362
  const cacheKey = operation + (this._dataTypeScope ? ':' + this._dataTypeScope : '');
322
363
  let validator = this._outputCodecs[cacheKey];
323
364
  if (validator)
@@ -161,7 +161,7 @@ export class ElasticCollectionService extends ElasticEntityService {
161
161
  command.options?.filter,
162
162
  ]);
163
163
  command.options = { ...options, request, filter };
164
- const r = await this._search(command);
164
+ const r = await this._findMany(command);
165
165
  return !!(typeof r.hits.total === 'number'
166
166
  ? r.hits.total
167
167
  : r.hits.total?.value);
@@ -187,7 +187,7 @@ export class ElasticCollectionService extends ElasticEntityService {
187
187
  size: 0,
188
188
  };
189
189
  command.options = { ...options, request };
190
- const r = await this._search(command);
190
+ const r = await this._findMany(command);
191
191
  return !!(typeof r.hits.total === 'number'
192
192
  ? r.hits.total
193
193
  : r.hits.total?.value);
@@ -215,9 +215,9 @@ export class ElasticCollectionService extends ElasticEntityService {
215
215
  limit: 1,
216
216
  options: { ...command.options, filter },
217
217
  };
218
- const r = await this._search(newCommand);
218
+ const r = await this._findMany(newCommand);
219
219
  if (r.hits.hits?.length) {
220
- const outputCodec = this._getOutputCodec('find');
220
+ const outputCodec = this.getOutputCodec('find');
221
221
  return {
222
222
  _id: r.hits.hits[0]._id,
223
223
  ...outputCodec(r.hits.hits[0]._source),
@@ -245,9 +245,9 @@ export class ElasticCollectionService extends ElasticEntityService {
245
245
  limit: 1,
246
246
  options: { ...command.options, filter },
247
247
  };
248
- const r = await this._search(newCommand);
248
+ const r = await this._findMany(newCommand);
249
249
  if (r.hits.hits?.length) {
250
- const outputCodec = this._getOutputCodec('find');
250
+ const outputCodec = this.getOutputCodec('find');
251
251
  return {
252
252
  _id: r.hits.hits[0]._id,
253
253
  ...outputCodec(r.hits.hits[0]._source),
@@ -272,17 +272,20 @@ export class ElasticCollectionService extends ElasticEntityService {
272
272
  ]);
273
273
  const limit = command.options?.limit || this.defaultLimit;
274
274
  command.options = { ...command.options, filter, limit };
275
- const r = await this._search(command);
276
- if (r.hits.hits?.length) {
277
- const outputCodec = this._getOutputCodec('find');
278
- return r.hits.hits.map((x) => ({
279
- _id: x._id,
280
- ...outputCodec(x._source),
281
- }));
282
- }
283
- return [];
275
+ const r = await this._findMany(command);
276
+ return r.hits?.hits.map((x) => x._source) || [];
284
277
  });
285
278
  }
279
+ async search(request, options) {
280
+ const command = {
281
+ crud: 'read',
282
+ method: 'search',
283
+ byId: false,
284
+ request,
285
+ options,
286
+ };
287
+ return this._executeCommand(command, async () => this._search(command));
288
+ }
286
289
  /**
287
290
  *
288
291
  */
@@ -305,10 +308,10 @@ export class ElasticCollectionService extends ElasticEntityService {
305
308
  limit,
306
309
  request: { ...command.options?.request, track_total_hits: true },
307
310
  };
308
- const r = await this._search(command);
311
+ const r = await this._findMany(command);
309
312
  const out = {};
310
313
  if (r.hits.hits?.length) {
311
- const outputCodec = this._getOutputCodec('find');
314
+ const outputCodec = this.getOutputCodec('find');
312
315
  out.items = r.hits.hits.map((x) => ({
313
316
  _id: x._id,
314
317
  ...outputCodec(x._source),
@@ -340,7 +343,7 @@ export class ElasticCollectionService extends ElasticEntityService {
340
343
  * @param {string} id - The ID of the document to update.
341
344
  * @param {PatchDTO<T>} input - The partial input data to update the document with.
342
345
  * @param {ElasticEntityService.UpdateOneOptions} [options] - The options for updating the document.
343
- * @returns {Promise<elastic.UpdateResponse>} - A promise that resolves to the number of documents modified.
346
+ * @returns {Promise<estypes.UpdateResponse>} - A promise that resolves to the number of documents modified.
344
347
  */
345
348
  async update(id, input, options) {
346
349
  const command = {
@@ -189,9 +189,9 @@ export class ElasticEntityService extends ElasticService {
189
189
  /**
190
190
  * Returns search hits that match the query defined in the request
191
191
  *
192
- * @param {ElasticEntityService.SearchCommand} command
192
+ * @param {ElasticEntityService.FindManyCommand} command
193
193
  */
194
- async _search(command) {
194
+ async _findMany(command) {
195
195
  const { options } = command;
196
196
  const filterQuery = ElasticAdapter.prepareFilter([
197
197
  command.documentId
@@ -218,7 +218,46 @@ export class ElasticEntityService extends ElasticService {
218
218
  query,
219
219
  };
220
220
  const client = this.getClient();
221
- return client.search(request, options?.transport);
221
+ const r = await client.search(request, options?.transport);
222
+ if (options?.noDecode)
223
+ return r;
224
+ if (r.hits.hits?.length) {
225
+ const outputCodec = this.getOutputCodec('find');
226
+ r.hits.hits = r.hits.hits.map((x) => ({
227
+ ...x,
228
+ _source: {
229
+ _id: x._id,
230
+ ...outputCodec(x._source),
231
+ },
232
+ }));
233
+ }
234
+ return r;
235
+ }
236
+ /**
237
+ * Executes a search operation on the Elasticsearch index using the provided search command.
238
+ *
239
+ * @param {ElasticEntityService.SearchCommand} command - The search command containing the request configuration and optional transport settings.
240
+ * @return {Promise<ElasticEntityService.SearchResponse>} A promise resolving to the search response from Elasticsearch.
241
+ */
242
+ async _search(command) {
243
+ const { options } = command;
244
+ const request = {
245
+ index: this.getIndexName(),
246
+ ...command.request,
247
+ };
248
+ const client = this.getClient();
249
+ const r = await client.search(request, options?.transport);
250
+ if (r.hits.hits?.length) {
251
+ const outputCodec = this.getOutputCodec('find');
252
+ r.hits.hits = r.hits.hits.map((x) => ({
253
+ ...x,
254
+ _source: {
255
+ _id: x._id,
256
+ ...outputCodec(x._source),
257
+ },
258
+ }));
259
+ }
260
+ return r;
222
261
  }
223
262
  /**
224
263
  * Updates multiple documents in the collection based on the specified input and options.
@@ -304,8 +343,10 @@ export class ElasticEntityService extends ElasticService {
304
343
  projection: '*',
305
344
  scope: this._dataTypeScope,
306
345
  };
307
- if (operation === 'update')
346
+ if (operation === 'update') {
308
347
  options.partial = 'deep';
348
+ options.keepKeyFields = true;
349
+ }
309
350
  const dataType = this.dataType;
310
351
  validator = dataType.generateCodec('decode', options);
311
352
  this._inputCodecs[cacheKey] = validator;
@@ -314,7 +355,7 @@ export class ElasticEntityService extends ElasticService {
314
355
  /**
315
356
  * Retrieves the codec.
316
357
  */
317
- _getOutputCodec(operation) {
358
+ getOutputCodec(operation) {
318
359
  const cacheKey = operation + (this._dataTypeScope ? ':' + this._dataTypeScope : '');
319
360
  let validator = this._outputCodecs[cacheKey];
320
361
  if (validator)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/elastic",
3
- "version": "1.5.7",
3
+ "version": "1.7.0",
4
4
  "description": "Opra Elastic Search adapter package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -11,8 +11,8 @@
11
11
  },
12
12
  "peerDependencies": {
13
13
  "@elastic/elasticsearch": ">=8.7.0",
14
- "@opra/common": "^1.5.7",
15
- "@opra/core": "^1.5.7"
14
+ "@opra/common": "^1.7.0",
15
+ "@opra/core": "^1.7.0"
16
16
  },
17
17
  "type": "module",
18
18
  "exports": {
@@ -1,4 +1,4 @@
1
1
  import '@opra/core';
2
- import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
2
+ import type { estypes } from '@elastic/elasticsearch';
3
3
  import { type ElasticAdapter } from '../elastic-adapter.js';
4
- export default function prepareFilter(filters: ElasticAdapter.FilterInput | ElasticAdapter.FilterInput[]): QueryDslQueryContainer | undefined;
4
+ export default function prepareFilter(filters: ElasticAdapter.FilterInput | ElasticAdapter.FilterInput[]): estypes.QueryDslQueryContainer | undefined;
@@ -1,4 +1,4 @@
1
- import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types.js';
1
+ import type { estypes } from '@elastic/elasticsearch';
2
2
  import { OpraFilter } from '@opra/common';
3
3
  import type { ExecutionContext } from '@opra/core';
4
4
  import _prepareFilter from './adapter-utils/prepare-filter.js';
@@ -6,7 +6,7 @@ import _preparePatch from './adapter-utils/prepare-patch.js';
6
6
  import _prepareProjection from './adapter-utils/prepare-projection.js';
7
7
  import _prepareSort from './adapter-utils/prepare-sort.js';
8
8
  export declare namespace ElasticAdapter {
9
- type FilterInput = OpraFilter.Expression | QueryDslQueryContainer | string | undefined;
9
+ type FilterInput = OpraFilter.Expression | estypes.QueryDslQueryContainer | string | undefined;
10
10
  const prepareFilter: typeof _prepareFilter;
11
11
  const preparePatch: typeof _preparePatch;
12
12
  const prepareProjection: typeof _prepareProjection;
@@ -1,4 +1,4 @@
1
- import type * as elastic from '@elastic/elasticsearch/lib/api/types';
1
+ import type { estypes } from '@elastic/elasticsearch';
2
2
  import { ExecutionContext, ServiceBase } from '@opra/core';
3
3
  import type { Nullish, PartialDTO, PatchDTO, RequiredSome, Type } from 'ts-gems';
4
4
  import { ElasticAdapter } from './elastic-adapter.js';
@@ -23,7 +23,7 @@ export declare namespace ElasticCollectionService {
23
23
  interface FindManyWithCountResult<X> {
24
24
  items: X[];
25
25
  count: number;
26
- relation: elastic.SearchTotalHitsRelation;
26
+ relation: estypes.SearchTotalHitsRelation;
27
27
  }
28
28
  }
29
29
  /**
@@ -70,7 +70,7 @@ export declare class ElasticCollectionService<T extends object = any> extends El
70
70
  * @returns {Promise<PartialDTO<T>>} A promise that resolves to the created document.
71
71
  * @throws {Error} if an unknown error occurs while creating the document.
72
72
  */
73
- create(input: PartialDTO<T>, options?: ElasticEntityService.CreateOptions): Promise<elastic.CreateResponse>;
73
+ create(input: PartialDTO<T>, options?: ElasticEntityService.CreateOptions): Promise<estypes.CreateResponse>;
74
74
  /**
75
75
  * Returns the count of documents in the collection based on the provided options.
76
76
  *
@@ -85,14 +85,14 @@ export declare class ElasticCollectionService<T extends object = any> extends El
85
85
  * @param {ElasticEntityService.DeleteOptions} [options] - Optional delete options.
86
86
  * @return {Promise<number>} - A Promise that resolves to the number of documents deleted.
87
87
  */
88
- delete(id: string, options?: ElasticEntityService.DeleteOptions): Promise<elastic.DeleteByQueryResponse>;
88
+ delete(id: string, options?: ElasticEntityService.DeleteOptions): Promise<estypes.DeleteByQueryResponse>;
89
89
  /**
90
90
  * Deletes multiple documents from the collection that meet the specified filter criteria.
91
91
  *
92
92
  * @param {ElasticEntityService.DeleteManyOptions} options - The options for the delete operation.
93
93
  * @return {Promise<number>} - A promise that resolves to the number of documents deleted.
94
94
  */
95
- deleteMany(options?: ElasticEntityService.DeleteManyOptions): Promise<elastic.DeleteByQueryResponse>;
95
+ deleteMany(options?: ElasticEntityService.DeleteManyOptions): Promise<estypes.DeleteByQueryResponse>;
96
96
  /**
97
97
  * Checks if an object with the given id exists.
98
98
  *
@@ -141,33 +141,34 @@ export declare class ElasticCollectionService<T extends object = any> extends El
141
141
  /**
142
142
  * Finds multiple documents in the ElasticDB collection.
143
143
  *
144
- * @param {ElasticEntityService.SearchOptions} options - The options for the find operation.
144
+ * @param {ElasticEntityService.FindManyOptions} options - The options for the find operation.
145
145
  * @return {Promise<PartialDTO<T> | undefined>} A Promise that resolves to an array of partial outputs of type T.
146
146
  */
147
- findMany(options: RequiredSome<ElasticEntityService.SearchOptions, 'projection'>): Promise<PartialDTO<T>[]>;
147
+ findMany(options: RequiredSome<ElasticEntityService.FindManyOptions, 'projection'>): Promise<PartialDTO<T>[]>;
148
148
  /**
149
149
  * Finds multiple documents in the ElasticDB collection.
150
150
  *
151
- * @param {ElasticEntityService.SearchOptions} options - The options for the find operation.
151
+ * @param {ElasticEntityService.FindManyOptions} options - The options for the find operation.
152
152
  * @return {Promise<T | undefined>} A Promise that resolves to an array of partial outputs of type T.
153
153
  */
154
- findMany(options?: ElasticEntityService.SearchOptions): Promise<T[]>;
154
+ findMany(options?: ElasticEntityService.FindManyOptions): Promise<T[]>;
155
+ search(request: estypes.SearchRequest, options?: ElasticEntityService.SearchOptions): Promise<estypes.SearchResponse<PartialDTO<T>>>;
155
156
  /**
156
157
  * Finds multiple documents in the collection and returns both records (max limit)
157
158
  * and total count that matched the given criteria
158
159
  *
159
- * @param {ElasticEntityService.SearchOptions} [options] - The options for the find operation.
160
+ * @param {ElasticEntityService.FindManyOptions} [options] - The options for the find operation.
160
161
  * @return {ElasticCollectionService.FindManyWithCountResult<PartialDTO<T>>} A Promise that resolves to an array of partial outputs of type T.
161
162
  */
162
- findManyWithCount(options: RequiredSome<ElasticEntityService.SearchOptions, 'projection'>): Promise<ElasticCollectionService.FindManyWithCountResult<PartialDTO<T>>>;
163
+ findManyWithCount(options: RequiredSome<ElasticEntityService.FindManyOptions, 'projection'>): Promise<ElasticCollectionService.FindManyWithCountResult<PartialDTO<T>>>;
163
164
  /**
164
165
  * Finds multiple documents in the collection and returns both records (max limit)
165
166
  * and total count that matched the given criteria
166
167
  *
167
- * @param {ElasticEntityService.SearchOptions} [options] - The options for the find operation.
168
+ * @param {ElasticEntityService.FindManyOptions} [options] - The options for the find operation.
168
169
  * @return {ElasticCollectionService.FindManyWithCountResult<T>} A Promise that resolves to an array of partial outputs of type T.
169
170
  */
170
- findManyWithCount(options?: ElasticEntityService.SearchOptions): Promise<ElasticCollectionService.FindManyWithCountResult<T>>;
171
+ findManyWithCount(options?: ElasticEntityService.FindManyOptions): Promise<ElasticCollectionService.FindManyWithCountResult<T>>;
171
172
  /**
172
173
  * Retrieves a document from the collection by its ID. Throws error if not found.
173
174
  *
@@ -194,9 +195,9 @@ export declare class ElasticCollectionService<T extends object = any> extends El
194
195
  * @param {string} id - The ID of the document to update.
195
196
  * @param {PatchDTO<T>} input - The partial input data to update the document with.
196
197
  * @param {ElasticEntityService.UpdateOneOptions} [options] - The options for updating the document.
197
- * @returns {Promise<elastic.UpdateResponse>} - A promise that resolves to the number of documents modified.
198
+ * @returns {Promise<estypes.UpdateResponse>} - A promise that resolves to the number of documents modified.
198
199
  */
199
- update(id: string, input: PatchDTO<T>, options?: ElasticEntityService.UpdateOneOptions): Promise<elastic.UpdateByQueryResponse>;
200
+ update(id: string, input: PatchDTO<T>, options?: ElasticEntityService.UpdateOneOptions): Promise<estypes.UpdateByQueryResponse>;
200
201
  /**
201
202
  * Updates multiple documents in the collection based on the specified input and options.
202
203
  *
@@ -204,7 +205,7 @@ export declare class ElasticCollectionService<T extends object = any> extends El
204
205
  * @param {ElasticEntityService.UpdateManyOptions} options - The options for updating the documents.
205
206
  * @return {Promise<number>} - A promise that resolves to the number of documents matched and modified.
206
207
  */
207
- updateMany(input: PatchDTO<T>, options?: ElasticEntityService.UpdateManyOptions): Promise<elastic.UpdateByQueryResponse>;
208
+ updateMany(input: PatchDTO<T>, options?: ElasticEntityService.UpdateManyOptions): Promise<estypes.UpdateByQueryResponse>;
208
209
  /**
209
210
  * Retrieves the common filter used for querying documents.
210
211
  * This method is mostly used for security issues like securing multi-tenant applications.
@@ -1,4 +1,4 @@
1
- import type * as elastic from '@elastic/elasticsearch/lib/api/types.js';
1
+ import type { estypes } from '@elastic/elasticsearch';
2
2
  import type { TransportRequestOptions } from '@elastic/transport';
3
3
  import { ComplexType } from '@opra/common';
4
4
  import type { PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
@@ -30,7 +30,7 @@ export declare namespace ElasticEntityService {
30
30
  * @interface
31
31
  */
32
32
  interface CreateOptions {
33
- request?: elastic.CreateRequest;
33
+ request?: estypes.CreateRequest;
34
34
  transport?: TransportRequestOptions;
35
35
  }
36
36
  /**
@@ -41,7 +41,7 @@ export declare namespace ElasticEntityService {
41
41
  */
42
42
  interface CountOptions {
43
43
  filter?: ElasticAdapter.FilterInput;
44
- request?: elastic.CountRequest;
44
+ request?: estypes.CountRequest;
45
45
  transport?: TransportRequestOptions;
46
46
  }
47
47
  /**
@@ -52,7 +52,7 @@ export declare namespace ElasticEntityService {
52
52
  */
53
53
  interface DeleteOptions {
54
54
  filter?: ElasticAdapter.FilterInput;
55
- request?: elastic.DeleteByQueryRequest;
55
+ request?: estypes.DeleteByQueryRequest;
56
56
  transport?: TransportRequestOptions;
57
57
  }
58
58
  /**
@@ -63,7 +63,7 @@ export declare namespace ElasticEntityService {
63
63
  */
64
64
  interface DeleteManyOptions {
65
65
  filter?: ElasticAdapter.FilterInput;
66
- request?: elastic.DeleteByQueryRequest;
66
+ request?: estypes.DeleteByQueryRequest;
67
67
  transport?: TransportRequestOptions;
68
68
  }
69
69
  /**
@@ -72,7 +72,7 @@ export declare namespace ElasticEntityService {
72
72
  * @interface
73
73
  * @template T - The type of the document.
74
74
  */
75
- interface FindOneOptions extends StrictOmit<SearchOptions, 'limit'> {
75
+ interface FindOneOptions extends StrictOmit<FindManyOptions, 'limit'> {
76
76
  }
77
77
  /**
78
78
  * Represents options for "findMany" operation
@@ -80,14 +80,24 @@ export declare namespace ElasticEntityService {
80
80
  * @interface
81
81
  * @template T - The type of the document.
82
82
  */
83
- interface SearchOptions {
83
+ interface FindManyOptions {
84
84
  filter?: ElasticAdapter.FilterInput;
85
85
  projection?: string | string[];
86
86
  sort?: string[];
87
87
  limit?: number;
88
88
  skip?: number;
89
- request?: elastic.SearchRequest;
89
+ request?: estypes.SearchRequest;
90
90
  transport?: TransportRequestOptions;
91
+ noDecode?: boolean;
92
+ }
93
+ /**
94
+ * Represents options for "search" operation
95
+ *
96
+ * @interface
97
+ */
98
+ interface SearchOptions {
99
+ transport?: TransportRequestOptions;
100
+ noDecode?: boolean;
91
101
  }
92
102
  /**
93
103
  * Represents options for "update" operation
@@ -97,7 +107,7 @@ export declare namespace ElasticEntityService {
97
107
  */
98
108
  interface UpdateOneOptions {
99
109
  filter?: ElasticAdapter.FilterInput;
100
- request?: elastic.UpdateByQueryRequest;
110
+ request?: estypes.UpdateByQueryRequest;
101
111
  transport?: TransportRequestOptions;
102
112
  }
103
113
  /**
@@ -108,7 +118,7 @@ export declare namespace ElasticEntityService {
108
118
  */
109
119
  interface UpdateManyOptions {
110
120
  filter?: ElasticAdapter.FilterInput;
111
- request?: elastic.UpdateByQueryRequest;
121
+ request?: estypes.UpdateByQueryRequest;
112
122
  transport?: TransportRequestOptions;
113
123
  }
114
124
  interface CreateCommand extends StrictOmit<RequiredSome<CommandInfo, 'input'>, 'documentId'> {
@@ -127,8 +137,13 @@ export declare namespace ElasticEntityService {
127
137
  crud: 'delete';
128
138
  options?: DeleteManyOptions;
129
139
  }
140
+ interface FindManyCommand extends StrictOmit<CommandInfo, 'input'> {
141
+ crud: 'read';
142
+ options?: FindManyOptions;
143
+ }
130
144
  interface SearchCommand extends StrictOmit<CommandInfo, 'input'> {
131
145
  crud: 'read';
146
+ request: estypes.SearchRequest;
132
147
  options?: SearchOptions;
133
148
  }
134
149
  interface UpdateCommand<T> extends CommandInfo {
@@ -136,6 +151,7 @@ export declare namespace ElasticEntityService {
136
151
  input: PatchDTO<T>;
137
152
  options?: UpdateOneOptions;
138
153
  }
154
+ type SearchResponse<T> = estypes.SearchResponse<T>;
139
155
  }
140
156
  /**
141
157
  * @class ElasticEntityService
@@ -203,40 +219,47 @@ export declare class ElasticEntityService<T extends object = any> extends Elasti
203
219
  * @param {ElasticEntityService.CreateCommand} command
204
220
  * @protected
205
221
  */
206
- protected _create(command: ElasticEntityService.CreateCommand): Promise<elastic.CreateResponse>;
222
+ protected _create(command: ElasticEntityService.CreateCommand): Promise<estypes.CreateResponse>;
207
223
  /**
208
224
  * Returns the count of documents in the collection based on the provided options.
209
225
  *
210
226
  * @param {ElasticEntityService.CountCommand} command
211
227
  * @protected
212
228
  */
213
- protected _count(command: ElasticEntityService.CountCommand): Promise<elastic.CountResponse>;
229
+ protected _count(command: ElasticEntityService.CountCommand): Promise<estypes.CountResponse>;
214
230
  /**
215
231
  * Deletes a document from the collection.
216
232
  *
217
233
  * @param {ElasticEntityService.DeleteCommand} command
218
234
  * @protected
219
235
  */
220
- protected _delete(command: ElasticEntityService.DeleteCommand): Promise<elastic.DeleteByQueryResponse>;
236
+ protected _delete(command: ElasticEntityService.DeleteCommand): Promise<estypes.DeleteByQueryResponse>;
221
237
  /**
222
238
  * Deletes multiple documents from the collection that meet the specified filter criteria.
223
239
  *
224
240
  * @param {ElasticEntityService.DeleteManyCommand} command
225
241
  * @protected
226
242
  */
227
- protected _deleteMany(command: ElasticEntityService.DeleteManyCommand): Promise<elastic.DeleteByQueryResponse>;
243
+ protected _deleteMany(command: ElasticEntityService.DeleteManyCommand): Promise<estypes.DeleteByQueryResponse>;
228
244
  /**
229
245
  * Returns search hits that match the query defined in the request
230
246
  *
231
- * @param {ElasticEntityService.SearchCommand} command
247
+ * @param {ElasticEntityService.FindManyCommand} command
248
+ */
249
+ protected _findMany(command: ElasticEntityService.FindManyCommand): Promise<ElasticEntityService.SearchResponse<PartialDTO<T>>>;
250
+ /**
251
+ * Executes a search operation on the Elasticsearch index using the provided search command.
252
+ *
253
+ * @param {ElasticEntityService.SearchCommand} command - The search command containing the request configuration and optional transport settings.
254
+ * @return {Promise<ElasticEntityService.SearchResponse>} A promise resolving to the search response from Elasticsearch.
232
255
  */
233
- protected _search(command: ElasticEntityService.SearchCommand): Promise<elastic.SearchResponse>;
256
+ protected _search(command: ElasticEntityService.SearchCommand): Promise<ElasticEntityService.SearchResponse<PartialDTO<T>>>;
234
257
  /**
235
258
  * Updates multiple documents in the collection based on the specified input and options.
236
259
  *
237
260
  * @param {ElasticEntityService.UpdateCommand<T>} command
238
261
  */
239
- protected _updateMany(command: ElasticEntityService.UpdateCommand<T>): Promise<elastic.UpdateByQueryResponse>;
262
+ protected _updateMany(command: ElasticEntityService.UpdateCommand<T>): Promise<estypes.UpdateByQueryResponse>;
240
263
  /**
241
264
  * Generates an ID.
242
265
  *
@@ -253,7 +276,7 @@ export declare class ElasticEntityService<T extends object = any> extends Elasti
253
276
  /**
254
277
  * Retrieves the codec.
255
278
  */
256
- protected _getOutputCodec(operation: string): IsObject.Validator<T>;
279
+ getOutputCodec(operation: string): IsObject.Validator<T>;
257
280
  protected _executeCommand(command: ElasticEntityService.CommandInfo, commandFn: () => any): Promise<any>;
258
281
  protected _beforeCreate(command: ElasticEntityService.CreateCommand): Promise<void>;
259
282
  protected _beforeUpdate(command: ElasticEntityService.UpdateCommand<T>): Promise<void>;