@opra/elastic 1.5.7 → 1.6.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,7 +218,7 @@ 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
223
  const outputCodec = this._getOutputCodec('find');
224
224
  return {
@@ -248,7 +248,7 @@ 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
253
  const outputCodec = this._getOutputCodec('find');
254
254
  return {
@@ -275,7 +275,7 @@ 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);
278
+ const r = await this._findMany(command);
279
279
  if (r.hits.hits?.length) {
280
280
  const outputCodec = this._getOutputCodec('find');
281
281
  return r.hits.hits.map((x) => ({
@@ -308,7 +308,7 @@ class ElasticCollectionService extends elastic_entity_service_js_1.ElasticEntity
308
308
  limit,
309
309
  request: { ...command.options?.request, track_total_hits: true },
310
310
  };
311
- const r = await this._search(command);
311
+ const r = await this._findMany(command);
312
312
  const out = {};
313
313
  if (r.hits.hits?.length) {
314
314
  const outputCodec = this._getOutputCodec('find');
@@ -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
@@ -307,8 +307,10 @@ class ElasticEntityService extends elastic_service_js_1.ElasticService {
307
307
  projection: '*',
308
308
  scope: this._dataTypeScope,
309
309
  };
310
- if (operation === 'update')
310
+ if (operation === 'update') {
311
311
  options.partial = 'deep';
312
+ options.keepKeyFields = true;
313
+ }
312
314
  const dataType = this.dataType;
313
315
  validator = dataType.generateCodec('decode', options);
314
316
  this._inputCodecs[cacheKey] = 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,7 +215,7 @@ 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
220
  const outputCodec = this._getOutputCodec('find');
221
221
  return {
@@ -245,7 +245,7 @@ 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
250
  const outputCodec = this._getOutputCodec('find');
251
251
  return {
@@ -272,7 +272,7 @@ 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);
275
+ const r = await this._findMany(command);
276
276
  if (r.hits.hits?.length) {
277
277
  const outputCodec = this._getOutputCodec('find');
278
278
  return r.hits.hits.map((x) => ({
@@ -305,7 +305,7 @@ export class ElasticCollectionService extends ElasticEntityService {
305
305
  limit,
306
306
  request: { ...command.options?.request, track_total_hits: true },
307
307
  };
308
- const r = await this._search(command);
308
+ const r = await this._findMany(command);
309
309
  const out = {};
310
310
  if (r.hits.hits?.length) {
311
311
  const outputCodec = this._getOutputCodec('find');
@@ -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
@@ -304,8 +304,10 @@ export class ElasticEntityService extends ElasticService {
304
304
  projection: '*',
305
305
  scope: this._dataTypeScope,
306
306
  };
307
- if (operation === 'update')
307
+ if (operation === 'update') {
308
308
  options.partial = 'deep';
309
+ options.keepKeyFields = true;
310
+ }
309
311
  const dataType = this.dataType;
310
312
  validator = dataType.generateCodec('decode', options);
311
313
  this._inputCodecs[cacheKey] = validator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/elastic",
3
- "version": "1.5.7",
3
+ "version": "1.6.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.6.0",
15
+ "@opra/core": "^1.6.0"
16
16
  },
17
17
  "type": "module",
18
18
  "exports": {
@@ -141,33 +141,33 @@ 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
155
  /**
156
156
  * Finds multiple documents in the collection and returns both records (max limit)
157
157
  * and total count that matched the given criteria
158
158
  *
159
- * @param {ElasticEntityService.SearchOptions} [options] - The options for the find operation.
159
+ * @param {ElasticEntityService.FindManyOptions} [options] - The options for the find operation.
160
160
  * @return {ElasticCollectionService.FindManyWithCountResult<PartialDTO<T>>} A Promise that resolves to an array of partial outputs of type T.
161
161
  */
162
- findManyWithCount(options: RequiredSome<ElasticEntityService.SearchOptions, 'projection'>): Promise<ElasticCollectionService.FindManyWithCountResult<PartialDTO<T>>>;
162
+ findManyWithCount(options: RequiredSome<ElasticEntityService.FindManyOptions, 'projection'>): Promise<ElasticCollectionService.FindManyWithCountResult<PartialDTO<T>>>;
163
163
  /**
164
164
  * Finds multiple documents in the collection and returns both records (max limit)
165
165
  * and total count that matched the given criteria
166
166
  *
167
- * @param {ElasticEntityService.SearchOptions} [options] - The options for the find operation.
167
+ * @param {ElasticEntityService.FindManyOptions} [options] - The options for the find operation.
168
168
  * @return {ElasticCollectionService.FindManyWithCountResult<T>} A Promise that resolves to an array of partial outputs of type T.
169
169
  */
170
- findManyWithCount(options?: ElasticEntityService.SearchOptions): Promise<ElasticCollectionService.FindManyWithCountResult<T>>;
170
+ findManyWithCount(options?: ElasticEntityService.FindManyOptions): Promise<ElasticCollectionService.FindManyWithCountResult<T>>;
171
171
  /**
172
172
  * Retrieves a document from the collection by its ID. Throws error if not found.
173
173
  *
@@ -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,7 +80,7 @@ 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[];
@@ -127,9 +127,9 @@ export declare namespace ElasticEntityService {
127
127
  crud: 'delete';
128
128
  options?: DeleteManyOptions;
129
129
  }
130
- interface SearchCommand extends StrictOmit<CommandInfo, 'input'> {
130
+ interface FindManyCommand extends StrictOmit<CommandInfo, 'input'> {
131
131
  crud: 'read';
132
- options?: SearchOptions;
132
+ options?: FindManyOptions;
133
133
  }
134
134
  interface UpdateCommand<T> extends CommandInfo {
135
135
  crud: 'update';
@@ -228,9 +228,9 @@ export declare class ElasticEntityService<T extends object = any> extends Elasti
228
228
  /**
229
229
  * Returns search hits that match the query defined in the request
230
230
  *
231
- * @param {ElasticEntityService.SearchCommand} command
231
+ * @param {ElasticEntityService.FindManyCommand} command
232
232
  */
233
- protected _search(command: ElasticEntityService.SearchCommand): Promise<elastic.SearchResponse>;
233
+ protected _findMany(command: ElasticEntityService.FindManyCommand): Promise<elastic.SearchResponse>;
234
234
  /**
235
235
  * Updates multiple documents in the collection based on the specified input and options.
236
236
  *