@opra/elastic 1.11.1 → 1.12.1

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.
@@ -102,7 +102,9 @@ class ElasticEntityService extends elastic_service_js_1.ElasticService {
102
102
  document: doc,
103
103
  };
104
104
  const client = this.getClient();
105
- const r = await client.create(request, options?.transport);
105
+ const r = options?.replaceIfExists
106
+ ? await client.index(request, options?.transport)
107
+ : await client.create(request, options?.transport);
106
108
  /* istanbul ignore next */
107
109
  if (!(r._id && (r.result === 'created' || r.result === 'updated'))) {
108
110
  throw new common_1.InternalServerError(`Unknown error while creating document for "${this.getResourceName()}"`);
@@ -99,7 +99,9 @@ export class ElasticEntityService extends ElasticService {
99
99
  document: doc,
100
100
  };
101
101
  const client = this.getClient();
102
- const r = await client.create(request, options?.transport);
102
+ const r = options?.replaceIfExists
103
+ ? await client.index(request, options?.transport)
104
+ : await client.create(request, options?.transport);
103
105
  /* istanbul ignore next */
104
106
  if (!(r._id && (r.result === 'created' || r.result === 'updated'))) {
105
107
  throw new InternalServerError(`Unknown error while creating document for "${this.getResourceName()}"`);
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@opra/elastic",
3
- "version": "1.11.1",
3
+ "version": "1.12.1",
4
4
  "description": "Opra Elastic Search adapter package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "@jsopen/objects": "^1.5.0",
8
+ "@jsopen/objects": "^1.5.2",
9
9
  "tslib": "^2.8.1",
10
10
  "valgen": "^5.13.0"
11
11
  },
12
12
  "peerDependencies": {
13
13
  "@elastic/elasticsearch": ">=8.7.0 <9",
14
- "@opra/common": "^1.11.1",
15
- "@opra/core": "^1.11.1"
14
+ "@opra/common": "^1.12.1",
15
+ "@opra/core": "^1.12.1"
16
16
  },
17
17
  "type": "module",
18
18
  "exports": {
@@ -30,8 +30,9 @@ export declare namespace ElasticEntityService {
30
30
  * @interface
31
31
  */
32
32
  interface CreateOptions {
33
- request?: estypes.CreateRequest;
33
+ request?: CreateRequest;
34
34
  transport?: TransportRequestOptions;
35
+ replaceIfExists?: boolean;
35
36
  }
36
37
  /**
37
38
  * Represents options for "count" operation
@@ -41,7 +42,7 @@ export declare namespace ElasticEntityService {
41
42
  */
42
43
  interface CountOptions {
43
44
  filter?: ElasticAdapter.FilterInput;
44
- request?: estypes.CountRequest;
45
+ request?: CountRequest;
45
46
  transport?: TransportRequestOptions;
46
47
  }
47
48
  /**
@@ -52,7 +53,7 @@ export declare namespace ElasticEntityService {
52
53
  */
53
54
  interface DeleteOptions {
54
55
  filter?: ElasticAdapter.FilterInput;
55
- request?: estypes.DeleteByQueryRequest;
56
+ request?: DeleteByQueryRequest;
56
57
  transport?: TransportRequestOptions;
57
58
  }
58
59
  /**
@@ -63,7 +64,7 @@ export declare namespace ElasticEntityService {
63
64
  */
64
65
  interface DeleteManyOptions {
65
66
  filter?: ElasticAdapter.FilterInput;
66
- request?: estypes.DeleteByQueryRequest;
67
+ request?: DeleteByQueryRequest;
67
68
  transport?: TransportRequestOptions;
68
69
  }
69
70
  /**
@@ -86,7 +87,7 @@ export declare namespace ElasticEntityService {
86
87
  sort?: string[];
87
88
  limit?: number;
88
89
  skip?: number;
89
- request?: estypes.SearchRequest;
90
+ request?: SearchRequest;
90
91
  transport?: TransportRequestOptions;
91
92
  noDecode?: boolean;
92
93
  }
@@ -107,7 +108,7 @@ export declare namespace ElasticEntityService {
107
108
  */
108
109
  interface UpdateOneOptions {
109
110
  filter?: ElasticAdapter.FilterInput;
110
- request?: estypes.UpdateByQueryRequest;
111
+ request?: UpdateByQueryRequest;
111
112
  transport?: TransportRequestOptions;
112
113
  }
113
114
  /**
@@ -118,7 +119,7 @@ export declare namespace ElasticEntityService {
118
119
  */
119
120
  interface UpdateManyOptions {
120
121
  filter?: ElasticAdapter.FilterInput;
121
- request?: estypes.UpdateByQueryRequest;
122
+ request?: UpdateByQueryRequest;
122
123
  transport?: TransportRequestOptions;
123
124
  }
124
125
  interface CreateCommand extends StrictOmit<RequiredSome<CommandInfo, 'input'>, 'documentId'> {
@@ -143,7 +144,7 @@ export declare namespace ElasticEntityService {
143
144
  }
144
145
  interface SearchCommand extends StrictOmit<CommandInfo, 'input'> {
145
146
  crud: 'read';
146
- request: estypes.SearchRequest;
147
+ request: SearchRequest;
147
148
  options?: SearchOptions;
148
149
  }
149
150
  interface UpdateCommand<T> extends CommandInfo {
@@ -151,7 +152,18 @@ export declare namespace ElasticEntityService {
151
152
  input: PatchDTO<T>;
152
153
  options?: UpdateOneOptions;
153
154
  }
155
+ type CreateRequest = estypes.CreateRequest;
156
+ type CreateResponse = estypes.CreateResponse;
157
+ type CountRequest = estypes.CountRequest;
158
+ type CountResponse = estypes.CountResponse;
159
+ type DeleteByQueryRequest = estypes.DeleteByQueryRequest;
160
+ type DeleteByQueryResponse = estypes.DeleteByQueryResponse;
161
+ type SearchRequest = estypes.SearchRequest;
154
162
  type SearchResponse<T> = estypes.SearchResponse<T>;
163
+ type UpdateByQueryRequest = estypes.UpdateByQueryRequest;
164
+ type UpdateByQueryResponse = estypes.UpdateByQueryResponse;
165
+ type QueryDslQueryContainer = estypes.QueryDslQueryContainer;
166
+ type Script = estypes.Script;
155
167
  }
156
168
  /**
157
169
  * @class ElasticEntityService
@@ -219,28 +231,28 @@ export declare class ElasticEntityService<T extends object = any> extends Elasti
219
231
  * @param {ElasticEntityService.CreateCommand} command
220
232
  * @protected
221
233
  */
222
- protected _create(command: ElasticEntityService.CreateCommand): Promise<estypes.CreateResponse>;
234
+ protected _create(command: ElasticEntityService.CreateCommand): Promise<ElasticEntityService.CreateResponse>;
223
235
  /**
224
236
  * Returns the count of documents in the collection based on the provided options.
225
237
  *
226
238
  * @param {ElasticEntityService.CountCommand} command
227
239
  * @protected
228
240
  */
229
- protected _count(command: ElasticEntityService.CountCommand): Promise<estypes.CountResponse>;
241
+ protected _count(command: ElasticEntityService.CountCommand): Promise<ElasticEntityService.CountResponse>;
230
242
  /**
231
243
  * Deletes a document from the collection.
232
244
  *
233
245
  * @param {ElasticEntityService.DeleteCommand} command
234
246
  * @protected
235
247
  */
236
- protected _delete(command: ElasticEntityService.DeleteCommand): Promise<estypes.DeleteByQueryResponse>;
248
+ protected _delete(command: ElasticEntityService.DeleteCommand): Promise<ElasticEntityService.DeleteByQueryResponse>;
237
249
  /**
238
250
  * Deletes multiple documents from the collection that meet the specified filter criteria.
239
251
  *
240
252
  * @param {ElasticEntityService.DeleteManyCommand} command
241
253
  * @protected
242
254
  */
243
- protected _deleteMany(command: ElasticEntityService.DeleteManyCommand): Promise<estypes.DeleteByQueryResponse>;
255
+ protected _deleteMany(command: ElasticEntityService.DeleteManyCommand): Promise<ElasticEntityService.DeleteByQueryResponse>;
244
256
  /**
245
257
  * Returns search hits that match the query defined in the request
246
258
  *
@@ -259,7 +271,7 @@ export declare class ElasticEntityService<T extends object = any> extends Elasti
259
271
  *
260
272
  * @param {ElasticEntityService.UpdateCommand<T>} command
261
273
  */
262
- protected _updateMany(command: ElasticEntityService.UpdateCommand<T>): Promise<estypes.UpdateByQueryResponse>;
274
+ protected _updateMany(command: ElasticEntityService.UpdateCommand<T>): Promise<ElasticEntityService.UpdateByQueryResponse>;
263
275
  /**
264
276
  * Generates an ID.
265
277
  *
@@ -278,7 +290,7 @@ export declare class ElasticEntityService<T extends object = any> extends Elasti
278
290
  */
279
291
  getOutputCodec(operation: string): IsObject.Validator<T>;
280
292
  protected _executeCommand(command: ElasticEntityService.CommandInfo, commandFn: () => any): Promise<any>;
281
- protected _mergeQueries(requestQuery?: estypes.QueryDslQueryContainer, filterQuery?: estypes.QueryDslQueryContainer): estypes.QueryDslQueryContainer | undefined;
293
+ protected _mergeQueries(requestQuery?: ElasticEntityService.QueryDslQueryContainer, filterQuery?: ElasticEntityService.QueryDslQueryContainer): ElasticEntityService.QueryDslQueryContainer | undefined;
282
294
  protected _beforeCreate(command: ElasticEntityService.CreateCommand): Promise<void>;
283
295
  protected _beforeUpdate(command: ElasticEntityService.UpdateCommand<T>): Promise<void>;
284
296
  protected _beforeUpdateMany(command: ElasticEntityService.UpdateCommand<T>): Promise<void>;