@opra/elastic 1.26.2 → 1.26.4
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.
- package/README.md +25 -2
- package/adapter-utils/prepare-filter.d.ts +6 -0
- package/adapter-utils/prepare-filter.js +7 -1
- package/adapter-utils/prepare-patch.d.ts +6 -0
- package/adapter-utils/prepare-patch.js +7 -1
- package/adapter-utils/prepare-projection.d.ts +8 -0
- package/adapter-utils/prepare-projection.js +11 -3
- package/adapter-utils/prepare-sort.d.ts +6 -0
- package/adapter-utils/prepare-sort.js +6 -0
- package/elastic-adapter.d.ts +8 -0
- package/elastic-adapter.js +8 -0
- package/elastic-collection-service.d.ts +72 -82
- package/elastic-collection-service.js +58 -46
- package/elastic-entity-service.d.ts +38 -44
- package/elastic-entity-service.js +32 -27
- package/elastic-service.d.ts +12 -13
- package/elastic-service.js +9 -10
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
-
# @opra/
|
|
1
|
+
# @opra/elastic
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[![NPM Version][npm-image]][npm-url]
|
|
4
|
+
[![NPM Downloads][downloads-image]][downloads-url]
|
|
5
|
+
[![CI Tests][ci-test-image]][ci-test-url]
|
|
6
|
+
[![Test Coverage][coveralls-image]][coveralls-url]
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Support
|
|
10
|
+
You can report bugs and discuss features on the [GitHub issues](https://github.com/panates/opra/issues) page.
|
|
11
|
+
|
|
12
|
+
## Node Compatibility
|
|
13
|
+
- node >= 20.x
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## License
|
|
17
|
+
Available under [MIT](LICENSE) license.
|
|
18
|
+
|
|
19
|
+
[npm-image]: https://img.shields.io/npm/v/@opra/elastic
|
|
20
|
+
[npm-url]: https://npmjs.org/package/@opra/elastic
|
|
21
|
+
[downloads-image]: https://img.shields.io/npm/dm/@opra/elastic.svg
|
|
22
|
+
[downloads-url]: https://npmjs.org/package/@opra/elastic
|
|
23
|
+
[ci-test-image]: https://github.com/panates/opra/actions/workflows/test.yml/badge.svg
|
|
24
|
+
[ci-test-url]: https://github.com/panates/opra/actions/workflows/test.yml
|
|
25
|
+
[coveralls-image]: https://coveralls.io/repos/github/panates/opra/badge.svg?branch=main
|
|
26
|
+
[coveralls-url]: https://coveralls.io/github/panates/opra?branch=main
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import '@opra/core';
|
|
2
2
|
import type { estypes } from '@elastic/elasticsearch';
|
|
3
3
|
import { type ElasticAdapter } from '../elastic-adapter.js';
|
|
4
|
+
/**
|
|
5
|
+
* Prepares an Elasticsearch filter query from the provided input.
|
|
6
|
+
*
|
|
7
|
+
* @param filters - The filter input or an array of filter inputs to prepare.
|
|
8
|
+
* @returns The prepared Elasticsearch query container, or undefined if no filters are provided.
|
|
9
|
+
*/
|
|
4
10
|
export default function prepareFilter(filters: ElasticAdapter.FilterInput | ElasticAdapter.FilterInput[]): estypes.QueryDslQueryContainer | undefined;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import '@opra/core';
|
|
2
2
|
import { OpraFilter } from '@opra/common';
|
|
3
|
+
/**
|
|
4
|
+
* Prepares an Elasticsearch filter query from the provided input.
|
|
5
|
+
*
|
|
6
|
+
* @param filters - The filter input or an array of filter inputs to prepare.
|
|
7
|
+
* @returns The prepared Elasticsearch query container, or undefined if no filters are provided.
|
|
8
|
+
*/
|
|
3
9
|
export default function prepareFilter(filters) {
|
|
4
10
|
const filtersArray = Array.isArray(filters) ? filters : [filters];
|
|
5
11
|
if (!filtersArray.length)
|
|
@@ -36,7 +42,7 @@ function prepareFilterAst(ast, negative) {
|
|
|
36
42
|
if (ast instanceof OpraFilter.LogicalExpression) {
|
|
37
43
|
const items = ast.items
|
|
38
44
|
.map(x => prepareFilterAst(x))
|
|
39
|
-
|
|
45
|
+
/* Filter nullish items */
|
|
40
46
|
.filter(x => x != null);
|
|
41
47
|
const k = (ast.op === 'or' ? 'should' : 'must') + (negative ? '_not' : '');
|
|
42
48
|
return { bool: { [k]: items } };
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import type { Script } from '@elastic/elasticsearch/api/types';
|
|
2
|
+
/**
|
|
3
|
+
* Prepares an Elasticsearch script for a patch operation from the provided document.
|
|
4
|
+
*
|
|
5
|
+
* @param doc - The document containing the changes to prepare as a script.
|
|
6
|
+
* @returns An Elasticsearch script object.
|
|
7
|
+
*/
|
|
2
8
|
export default function preparePatch(doc: any): Script;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prepares an Elasticsearch script for a patch operation from the provided document.
|
|
3
|
+
*
|
|
4
|
+
* @param doc - The document containing the changes to prepare as a script.
|
|
5
|
+
* @returns An Elasticsearch script object.
|
|
6
|
+
*/
|
|
1
7
|
export default function preparePatch(doc) {
|
|
2
8
|
const script = [];
|
|
3
9
|
const params = {};
|
|
@@ -21,7 +27,7 @@ function _preparePatch(src, script, params, path) {
|
|
|
21
27
|
if (v &&
|
|
22
28
|
typeof v === 'object' &&
|
|
23
29
|
!Array.isArray(v) &&
|
|
24
|
-
|
|
30
|
+
/* If field name starts with "*", do "replace" operation except "merge" */
|
|
25
31
|
!k.startsWith('*')) {
|
|
26
32
|
_preparePatch(v, script, params, field);
|
|
27
33
|
continue;
|
|
@@ -3,5 +3,13 @@ export interface ElasticProjection {
|
|
|
3
3
|
includes?: string[];
|
|
4
4
|
excludes?: string[];
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Prepares an Elasticsearch projection object from the provided fields projection.
|
|
8
|
+
*
|
|
9
|
+
* @param dataType - The complex type defining the structure of the data.
|
|
10
|
+
* @param projection - The fields projection to transform.
|
|
11
|
+
* @param scope - The scope to use for field selection.
|
|
12
|
+
* @returns An `ElasticProjection` object containing include and exclude rules, or undefined.
|
|
13
|
+
*/
|
|
6
14
|
export default function prepareProjection(dataType: ComplexType, projection?: string | string[], scope?: string): ElasticProjection | undefined;
|
|
7
15
|
export declare function prepare(dataType: ComplexType, includes: string[], excludes: string[], curPath: string, projection?: FieldsProjection, scope?: string): void;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { ComplexType, parseFieldsProjection, } from '@opra/common';
|
|
2
|
+
/**
|
|
3
|
+
* Prepares an Elasticsearch projection object from the provided fields projection.
|
|
4
|
+
*
|
|
5
|
+
* @param dataType - The complex type defining the structure of the data.
|
|
6
|
+
* @param projection - The fields projection to transform.
|
|
7
|
+
* @param scope - The scope to use for field selection.
|
|
8
|
+
* @returns An `ElasticProjection` object containing include and exclude rules, or undefined.
|
|
9
|
+
*/
|
|
2
10
|
export default function prepareProjection(dataType, projection, scope) {
|
|
3
11
|
const out = {};
|
|
4
12
|
const includes = [];
|
|
@@ -24,7 +32,7 @@ export function prepare(dataType, includes, excludes, curPath, projection, scope
|
|
|
24
32
|
let fieldPath;
|
|
25
33
|
let field;
|
|
26
34
|
let k;
|
|
27
|
-
|
|
35
|
+
/* Add fields from data type */
|
|
28
36
|
for (field of dataType.fields(scope)) {
|
|
29
37
|
fieldName = field.name;
|
|
30
38
|
fieldPath = curPath + (curPath ? '.' : '') + fieldName;
|
|
@@ -32,9 +40,9 @@ export function prepare(dataType, includes, excludes, curPath, projection, scope
|
|
|
32
40
|
projectionKeysSet.delete(k);
|
|
33
41
|
const p = projection?.[k];
|
|
34
42
|
if (
|
|
35
|
-
|
|
43
|
+
/* if field is omitted */
|
|
36
44
|
p?.sign === '-' ||
|
|
37
|
-
|
|
45
|
+
/* if no projection defined for this field and includeDefaultFields is true and the field is exclusive */
|
|
38
46
|
(!p && field.exclusive)) {
|
|
39
47
|
if (!needIncludes)
|
|
40
48
|
excludes.push(fieldPath);
|
|
@@ -1 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prepares an Elasticsearch sort array from the provided sort strings.
|
|
3
|
+
*
|
|
4
|
+
* @param sort - An array of sort strings (e.g., '+field' or '-field').
|
|
5
|
+
* @returns An array of Elasticsearch sort objects, or undefined if no sort is provided.
|
|
6
|
+
*/
|
|
1
7
|
export default function prepareSort(sort?: string[]): any[] | undefined;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
const SIGN_PATTERN = /^([+-])?(.+)$/;
|
|
2
|
+
/**
|
|
3
|
+
* Prepares an Elasticsearch sort array from the provided sort strings.
|
|
4
|
+
*
|
|
5
|
+
* @param sort - An array of sort strings (e.g., '+field' or '-field').
|
|
6
|
+
* @returns An array of Elasticsearch sort objects, or undefined if no sort is provided.
|
|
7
|
+
*/
|
|
2
8
|
export default function prepareSort(sort) {
|
|
3
9
|
if (!(sort && sort.length))
|
|
4
10
|
return;
|
package/elastic-adapter.d.ts
CHANGED
|
@@ -17,5 +17,13 @@ export declare namespace ElasticAdapter {
|
|
|
17
17
|
data?: any;
|
|
18
18
|
options: any;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Parses the execution context and transforms it into an `ElasticAdapter.TransformedRequest`.
|
|
22
|
+
*
|
|
23
|
+
* @param context - The execution context to parse.
|
|
24
|
+
* @returns A promise that resolves to the transformed request.
|
|
25
|
+
* @throws {@link TypeError} if the context is not an `HttpContext`.
|
|
26
|
+
* @throws {@link Error} if the operation is not compatible with the Elastic adapter.
|
|
27
|
+
*/
|
|
20
28
|
function parseRequest(context: ExecutionContext): Promise<TransformedRequest>;
|
|
21
29
|
}
|
package/elastic-adapter.js
CHANGED
|
@@ -8,6 +8,14 @@ export var ElasticAdapter;
|
|
|
8
8
|
ElasticAdapter.preparePatch = _preparePatch;
|
|
9
9
|
ElasticAdapter.prepareProjection = _prepareProjection;
|
|
10
10
|
ElasticAdapter.prepareSort = _prepareSort;
|
|
11
|
+
/**
|
|
12
|
+
* Parses the execution context and transforms it into an `ElasticAdapter.TransformedRequest`.
|
|
13
|
+
*
|
|
14
|
+
* @param context - The execution context to parse.
|
|
15
|
+
* @returns A promise that resolves to the transformed request.
|
|
16
|
+
* @throws {@link TypeError} if the context is not an `HttpContext`.
|
|
17
|
+
* @throws {@link Error} if the operation is not compatible with the Elastic adapter.
|
|
18
|
+
*/
|
|
11
19
|
async function parseRequest(context) {
|
|
12
20
|
if (context.transport !== 'http') {
|
|
13
21
|
throw new TypeError('ElasticAdapter can parse only HttpContext');
|
|
@@ -27,192 +27,182 @@ export declare namespace ElasticCollectionService {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Class representing an Elasticsearch collection service for interacting with an Elasticsearch index.
|
|
31
|
+
*
|
|
31
32
|
* @template T - The type of the documents in the collection.
|
|
32
33
|
*/
|
|
33
34
|
export declare class ElasticCollectionService<T extends object = any> extends ElasticEntityService<T> {
|
|
34
35
|
/**
|
|
35
|
-
* Represents a common filter
|
|
36
|
-
*
|
|
37
|
-
* @type {FilterInput | Function}
|
|
36
|
+
* Represents a common filter for the service.
|
|
38
37
|
*/
|
|
39
38
|
documentFilter?: ElasticCollectionService.DocumentFilter | ElasticCollectionService.DocumentFilter[];
|
|
40
39
|
/**
|
|
41
|
-
* Represents the default limit value for
|
|
42
|
-
*
|
|
43
|
-
* @type {number}
|
|
40
|
+
* Represents the default limit value for find operations.
|
|
44
41
|
*/
|
|
45
42
|
defaultLimit: number;
|
|
46
43
|
/**
|
|
47
|
-
* Constructs a new instance
|
|
44
|
+
* Constructs a new instance.
|
|
48
45
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
51
|
-
* @constructor
|
|
46
|
+
* @param dataType - The data type of the documents.
|
|
47
|
+
* @param options - The options for the collection service.
|
|
52
48
|
*/
|
|
53
49
|
constructor(dataType: Type | string, options?: ElasticCollectionService.Options);
|
|
54
50
|
for<C extends ExecutionContext, P extends Partial<this>>(context: C | ServiceBase, overwriteProperties?: Nullish<P>, overwriteContext?: Partial<C>): this & Required<P>;
|
|
55
51
|
/**
|
|
56
52
|
* Asserts the existence of a resource with the given ID.
|
|
57
|
-
* Throws a ResourceNotFoundError if the resource does not exist.
|
|
58
53
|
*
|
|
59
|
-
* @param
|
|
60
|
-
* @param
|
|
61
|
-
* @returns
|
|
62
|
-
* @throws {ResourceNotAvailableError}
|
|
54
|
+
* @param id - The ID of the resource to assert.
|
|
55
|
+
* @param options - Optional options for checking the existence.
|
|
56
|
+
* @returns A promise that resolves when the resource exists.
|
|
57
|
+
* @throws {@link ResourceNotAvailableError} if the resource does not exist.
|
|
63
58
|
*/
|
|
64
59
|
assert(id: string, options?: ElasticEntityService.FindOneOptions): Promise<void>;
|
|
65
60
|
/**
|
|
66
|
-
* Adds a document to the specified index
|
|
61
|
+
* Adds a document to the specified index.
|
|
67
62
|
*
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
70
|
-
* @returns
|
|
71
|
-
* @throws {Error} if an unknown error occurs while creating the document.
|
|
63
|
+
* @param input - The input data for creating the document.
|
|
64
|
+
* @param options - The options for creating the document.
|
|
65
|
+
* @returns A promise that resolves to the created response.
|
|
66
|
+
* @throws {@link Error} if an unknown error occurs while creating the document.
|
|
72
67
|
*/
|
|
73
68
|
create(input: PartialDTO<T>, options?: ElasticEntityService.CreateOptions): Promise<estypes.CreateResponse>;
|
|
74
69
|
/**
|
|
75
70
|
* Returns the count of documents in the collection based on the provided options.
|
|
76
71
|
*
|
|
77
|
-
* @param
|
|
78
|
-
* @
|
|
72
|
+
* @param options - The options for the count operation.
|
|
73
|
+
* @returns A promise that resolves to the count of documents.
|
|
79
74
|
*/
|
|
80
75
|
count(options?: ElasticEntityService.CountOptions): Promise<number>;
|
|
81
76
|
/**
|
|
82
|
-
* Deletes a document from the collection.
|
|
77
|
+
* Deletes a document from the collection by its ID.
|
|
83
78
|
*
|
|
84
|
-
* @param
|
|
85
|
-
* @param
|
|
86
|
-
* @
|
|
79
|
+
* @param id - The ID of the document to delete.
|
|
80
|
+
* @param options - Optional delete options.
|
|
81
|
+
* @returns A promise that resolves to the delete response.
|
|
87
82
|
*/
|
|
88
83
|
delete(id: string, options?: ElasticEntityService.DeleteOptions): Promise<estypes.DeleteByQueryResponse>;
|
|
89
84
|
/**
|
|
90
85
|
* Deletes multiple documents from the collection that meet the specified filter criteria.
|
|
91
86
|
*
|
|
92
|
-
* @param
|
|
93
|
-
* @
|
|
87
|
+
* @param options - The options for the delete operation.
|
|
88
|
+
* @returns A promise that resolves to the delete response.
|
|
94
89
|
*/
|
|
95
90
|
deleteMany(options?: ElasticEntityService.DeleteManyOptions): Promise<estypes.DeleteByQueryResponse>;
|
|
96
91
|
/**
|
|
97
|
-
* Checks if an object with the given
|
|
92
|
+
* Checks if an object with the given ID exists.
|
|
98
93
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @param
|
|
101
|
-
* @
|
|
94
|
+
* @param id - The ID of the object to check.
|
|
95
|
+
* @param options - The options for the query.
|
|
96
|
+
* @returns A promise that resolves to a boolean indicating whether the object exists.
|
|
102
97
|
*/
|
|
103
98
|
exists(id: string, options?: ElasticEntityService.FindOneOptions): Promise<boolean>;
|
|
104
99
|
/**
|
|
105
|
-
* Checks if
|
|
100
|
+
* Checks if at least one document exists matching the specified criteria.
|
|
106
101
|
*
|
|
107
|
-
* @param
|
|
108
|
-
* @
|
|
102
|
+
* @param options - The options for the query.
|
|
103
|
+
* @returns A promise that resolves to a boolean indicating whether the object exists.
|
|
109
104
|
*/
|
|
110
105
|
existsOne(options?: ElasticEntityService.FindOneOptions): Promise<boolean>;
|
|
111
106
|
/**
|
|
112
107
|
* Finds a document by its ID.
|
|
113
108
|
*
|
|
114
|
-
* @param
|
|
115
|
-
* @param
|
|
116
|
-
* @
|
|
109
|
+
* @param id - The ID of the document.
|
|
110
|
+
* @param options - The options for the find operation.
|
|
111
|
+
* @returns A promise resolving to the found document, or undefined if not found.
|
|
117
112
|
*/
|
|
118
113
|
findById(id: string, options: RequiredSome<ElasticEntityService.FindOneOptions, 'projection'>): Promise<PartialDTO<T> | undefined>;
|
|
119
114
|
/**
|
|
120
115
|
* Finds a document by its ID.
|
|
121
116
|
*
|
|
122
|
-
* @param
|
|
123
|
-
* @param
|
|
124
|
-
* @
|
|
117
|
+
* @param id - The ID of the document.
|
|
118
|
+
* @param options - The options for the find operation.
|
|
119
|
+
* @returns A promise resolving to the found document, or undefined if not found.
|
|
125
120
|
*/
|
|
126
121
|
findById(id: string, options?: ElasticEntityService.FindOneOptions): Promise<T | undefined>;
|
|
127
122
|
/**
|
|
128
|
-
* Finds a document in the collection that matches the specified
|
|
123
|
+
* Finds a document in the collection that matches the specified criteria.
|
|
129
124
|
*
|
|
130
|
-
* @param
|
|
131
|
-
* @
|
|
125
|
+
* @param options - The options for the find operation.
|
|
126
|
+
* @returns A promise that resolves with the found document or undefined if no document is found.
|
|
132
127
|
*/
|
|
133
128
|
findOne(options: RequiredSome<ElasticEntityService.FindOneOptions, 'projection'>): Promise<PartialDTO<T> | undefined>;
|
|
134
129
|
/**
|
|
135
|
-
* Finds a document in the collection that matches the specified
|
|
130
|
+
* Finds a document in the collection that matches the specified criteria.
|
|
136
131
|
*
|
|
137
|
-
* @param
|
|
138
|
-
* @
|
|
132
|
+
* @param options - The options for the find operation.
|
|
133
|
+
* @returns A promise that resolves with the found document or undefined if no document is found.
|
|
139
134
|
*/
|
|
140
135
|
findOne(options?: ElasticEntityService.FindOneOptions): Promise<T | undefined>;
|
|
141
136
|
/**
|
|
142
|
-
* Finds multiple documents in the
|
|
137
|
+
* Finds multiple documents in the Elasticsearch collection.
|
|
143
138
|
*
|
|
144
|
-
* @param
|
|
145
|
-
* @
|
|
139
|
+
* @param options - The options for the find operation.
|
|
140
|
+
* @returns A promise that resolves to an array of partial documents.
|
|
146
141
|
*/
|
|
147
142
|
findMany(options: RequiredSome<ElasticEntityService.FindManyOptions, 'projection'>): Promise<PartialDTO<T>[]>;
|
|
148
143
|
/**
|
|
149
|
-
* Finds multiple documents in the
|
|
144
|
+
* Finds multiple documents in the Elasticsearch collection.
|
|
150
145
|
*
|
|
151
|
-
* @param
|
|
152
|
-
* @
|
|
146
|
+
* @param options - The options for the find operation.
|
|
147
|
+
* @returns A promise that resolves to an array of documents.
|
|
153
148
|
*/
|
|
154
149
|
findMany(options?: ElasticEntityService.FindManyOptions): Promise<T[]>;
|
|
155
150
|
searchRaw(request: estypes.SearchRequest, options?: ElasticEntityService.SearchOptions): Promise<estypes.SearchResponse<PartialDTO<T>>>;
|
|
156
151
|
/**
|
|
157
|
-
* Finds multiple documents
|
|
158
|
-
* and total count that matched the given criteria
|
|
152
|
+
* Finds multiple documents and returns both records and total count.
|
|
159
153
|
*
|
|
160
|
-
* @param
|
|
161
|
-
* @
|
|
154
|
+
* @param options - The options for the find operation.
|
|
155
|
+
* @returns A promise that resolves to an object containing items and count.
|
|
162
156
|
*/
|
|
163
157
|
findManyWithCount(options: RequiredSome<ElasticEntityService.FindManyOptions, 'projection'>): Promise<ElasticCollectionService.FindManyWithCountResult<PartialDTO<T>>>;
|
|
164
158
|
/**
|
|
165
|
-
* Finds multiple documents
|
|
166
|
-
* and total count that matched the given criteria
|
|
159
|
+
* Finds multiple documents and returns both records and total count.
|
|
167
160
|
*
|
|
168
|
-
* @param
|
|
169
|
-
* @
|
|
161
|
+
* @param options - The options for the find operation.
|
|
162
|
+
* @returns A promise that resolves to an object containing items and count.
|
|
170
163
|
*/
|
|
171
164
|
findManyWithCount(options?: ElasticEntityService.FindManyOptions): Promise<ElasticCollectionService.FindManyWithCountResult<T>>;
|
|
172
165
|
/**
|
|
173
166
|
* Retrieves a document from the collection by its ID. Throws error if not found.
|
|
174
167
|
*
|
|
175
|
-
* @param
|
|
176
|
-
* @param
|
|
177
|
-
* @returns
|
|
178
|
-
*
|
|
179
|
-
* @throws {ResourceNotAvailableError} - If the document with the specified ID does not exist.
|
|
168
|
+
* @param id - The ID of the document to retrieve.
|
|
169
|
+
* @param options - Optional options for the operation.
|
|
170
|
+
* @returns A promise that resolves to the retrieved document.
|
|
171
|
+
* @throws {@link ResourceNotAvailableError} if the document with the specified ID does not exist.
|
|
180
172
|
*/
|
|
181
173
|
get(id: string, options: RequiredSome<ElasticEntityService.FindOneOptions, 'projection'>): Promise<PartialDTO<T>>;
|
|
182
174
|
/**
|
|
183
175
|
* Retrieves a document from the collection by its ID. Throws error if not found.
|
|
184
176
|
*
|
|
185
|
-
* @param
|
|
186
|
-
* @param
|
|
187
|
-
* @returns
|
|
188
|
-
*
|
|
189
|
-
* @throws {ResourceNotAvailableError} - If the document with the specified ID does not exist.
|
|
177
|
+
* @param id - The ID of the document to retrieve.
|
|
178
|
+
* @param options - Optional options for the operation.
|
|
179
|
+
* @returns A promise that resolves to the retrieved document.
|
|
180
|
+
* @throws {@link ResourceNotAvailableError} if the document with the specified ID does not exist.
|
|
190
181
|
*/
|
|
191
182
|
get(id: string, options?: ElasticEntityService.FindOneOptions): Promise<T>;
|
|
192
183
|
/**
|
|
193
184
|
* Updates a document in the collection with the specified ID.
|
|
194
185
|
*
|
|
195
|
-
* @param
|
|
196
|
-
* @param
|
|
197
|
-
* @param
|
|
198
|
-
* @returns
|
|
186
|
+
* @param id - The ID of the document to update.
|
|
187
|
+
* @param input - The partial input data to update the document with.
|
|
188
|
+
* @param options - The options for updating the document.
|
|
189
|
+
* @returns A promise that resolves to the update response.
|
|
199
190
|
*/
|
|
200
191
|
update(id: string, input: PatchDTO<T>, options?: ElasticEntityService.UpdateOneOptions): Promise<estypes.UpdateByQueryResponse>;
|
|
201
192
|
/**
|
|
202
193
|
* Updates multiple documents in the collection based on the specified input and options.
|
|
203
194
|
*
|
|
204
|
-
* @param
|
|
205
|
-
* @param
|
|
206
|
-
* @
|
|
195
|
+
* @param input - The partial input to update the documents with.
|
|
196
|
+
* @param options - The options for updating the documents.
|
|
197
|
+
* @returns A promise that resolves to the update response.
|
|
207
198
|
*/
|
|
208
199
|
updateMany(input: PatchDTO<T>, options?: ElasticEntityService.UpdateManyOptions): Promise<estypes.UpdateByQueryResponse>;
|
|
209
200
|
/**
|
|
210
201
|
* Retrieves the common filter used for querying documents.
|
|
211
|
-
* This method is mostly used for security issues like securing multi-tenant applications.
|
|
212
202
|
*
|
|
203
|
+
* @param command - The command information.
|
|
213
204
|
* @protected
|
|
214
|
-
* @returns
|
|
215
|
-
* that resolves to the common filter, or undefined if not available.
|
|
205
|
+
* @returns The common filter or a promise that resolves to the common filter.
|
|
216
206
|
*/
|
|
217
207
|
protected _getDocumentFilter(command: ElasticService.CommandInfo): ElasticAdapter.FilterInput | Promise<ElasticAdapter.FilterInput> | undefined;
|
|
218
208
|
}
|
|
@@ -2,28 +2,24 @@ import { ResourceNotAvailableError } from '@opra/common';
|
|
|
2
2
|
import { ElasticAdapter } from './elastic-adapter.js';
|
|
3
3
|
import { ElasticEntityService } from './elastic-entity-service.js';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Class representing an Elasticsearch collection service for interacting with an Elasticsearch index.
|
|
6
|
+
*
|
|
6
7
|
* @template T - The type of the documents in the collection.
|
|
7
8
|
*/
|
|
8
9
|
export class ElasticCollectionService extends ElasticEntityService {
|
|
9
10
|
/**
|
|
10
|
-
* Represents a common filter
|
|
11
|
-
*
|
|
12
|
-
* @type {FilterInput | Function}
|
|
11
|
+
* Represents a common filter for the service.
|
|
13
12
|
*/
|
|
14
13
|
documentFilter;
|
|
15
14
|
/**
|
|
16
|
-
* Represents the default limit value for
|
|
17
|
-
*
|
|
18
|
-
* @type {number}
|
|
15
|
+
* Represents the default limit value for find operations.
|
|
19
16
|
*/
|
|
20
17
|
defaultLimit;
|
|
21
18
|
/**
|
|
22
|
-
* Constructs a new instance
|
|
19
|
+
* Constructs a new instance.
|
|
23
20
|
*
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @constructor
|
|
21
|
+
* @param dataType - The data type of the documents.
|
|
22
|
+
* @param options - The options for the collection service.
|
|
27
23
|
*/
|
|
28
24
|
constructor(dataType, options) {
|
|
29
25
|
super(dataType, options);
|
|
@@ -45,24 +41,23 @@ export class ElasticCollectionService extends ElasticEntityService {
|
|
|
45
41
|
}
|
|
46
42
|
/**
|
|
47
43
|
* Asserts the existence of a resource with the given ID.
|
|
48
|
-
* Throws a ResourceNotFoundError if the resource does not exist.
|
|
49
44
|
*
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
52
|
-
* @returns
|
|
53
|
-
* @throws {ResourceNotAvailableError}
|
|
45
|
+
* @param id - The ID of the resource to assert.
|
|
46
|
+
* @param options - Optional options for checking the existence.
|
|
47
|
+
* @returns A promise that resolves when the resource exists.
|
|
48
|
+
* @throws {@link ResourceNotAvailableError} if the resource does not exist.
|
|
54
49
|
*/
|
|
55
50
|
async assert(id, options) {
|
|
56
51
|
if (!(await this.exists(id, options)))
|
|
57
52
|
throw new ResourceNotAvailableError(this.getResourceName(), id);
|
|
58
53
|
}
|
|
59
54
|
/**
|
|
60
|
-
* Adds a document to the specified index
|
|
55
|
+
* Adds a document to the specified index.
|
|
61
56
|
*
|
|
62
|
-
* @param
|
|
63
|
-
* @param
|
|
64
|
-
* @returns
|
|
65
|
-
* @throws {Error} if an unknown error occurs while creating the document.
|
|
57
|
+
* @param input - The input data for creating the document.
|
|
58
|
+
* @param options - The options for creating the document.
|
|
59
|
+
* @returns A promise that resolves to the created response.
|
|
60
|
+
* @throws {@link Error} if an unknown error occurs while creating the document.
|
|
66
61
|
*/
|
|
67
62
|
async create(input, options) {
|
|
68
63
|
const command = {
|
|
@@ -81,8 +76,8 @@ export class ElasticCollectionService extends ElasticEntityService {
|
|
|
81
76
|
/**
|
|
82
77
|
* Returns the count of documents in the collection based on the provided options.
|
|
83
78
|
*
|
|
84
|
-
* @param
|
|
85
|
-
* @
|
|
79
|
+
* @param options - The options for the count operation.
|
|
80
|
+
* @returns A promise that resolves to the count of documents.
|
|
86
81
|
*/
|
|
87
82
|
async count(options) {
|
|
88
83
|
const command = {
|
|
@@ -102,11 +97,11 @@ export class ElasticCollectionService extends ElasticEntityService {
|
|
|
102
97
|
});
|
|
103
98
|
}
|
|
104
99
|
/**
|
|
105
|
-
* Deletes a document from the collection.
|
|
100
|
+
* Deletes a document from the collection by its ID.
|
|
106
101
|
*
|
|
107
|
-
* @param
|
|
108
|
-
* @param
|
|
109
|
-
* @
|
|
102
|
+
* @param id - The ID of the document to delete.
|
|
103
|
+
* @param options - Optional delete options.
|
|
104
|
+
* @returns A promise that resolves to the delete response.
|
|
110
105
|
*/
|
|
111
106
|
async delete(id, options) {
|
|
112
107
|
const command = {
|
|
@@ -128,8 +123,8 @@ export class ElasticCollectionService extends ElasticEntityService {
|
|
|
128
123
|
/**
|
|
129
124
|
* Deletes multiple documents from the collection that meet the specified filter criteria.
|
|
130
125
|
*
|
|
131
|
-
* @param
|
|
132
|
-
* @
|
|
126
|
+
* @param options - The options for the delete operation.
|
|
127
|
+
* @returns A promise that resolves to the delete response.
|
|
133
128
|
*/
|
|
134
129
|
async deleteMany(options) {
|
|
135
130
|
const command = {
|
|
@@ -148,11 +143,11 @@ export class ElasticCollectionService extends ElasticEntityService {
|
|
|
148
143
|
});
|
|
149
144
|
}
|
|
150
145
|
/**
|
|
151
|
-
* Checks if an object with the given
|
|
146
|
+
* Checks if an object with the given ID exists.
|
|
152
147
|
*
|
|
153
|
-
* @param
|
|
154
|
-
* @param
|
|
155
|
-
* @
|
|
148
|
+
* @param id - The ID of the object to check.
|
|
149
|
+
* @param options - The options for the query.
|
|
150
|
+
* @returns A promise that resolves to a boolean indicating whether the object exists.
|
|
156
151
|
*/
|
|
157
152
|
async exists(id, options) {
|
|
158
153
|
const command = {
|
|
@@ -180,10 +175,10 @@ export class ElasticCollectionService extends ElasticEntityService {
|
|
|
180
175
|
});
|
|
181
176
|
}
|
|
182
177
|
/**
|
|
183
|
-
* Checks if
|
|
178
|
+
* Checks if at least one document exists matching the specified criteria.
|
|
184
179
|
*
|
|
185
|
-
* @param
|
|
186
|
-
* @
|
|
180
|
+
* @param options - The options for the query.
|
|
181
|
+
* @returns A promise that resolves to a boolean indicating whether the object exists.
|
|
187
182
|
*/
|
|
188
183
|
async existsOne(options) {
|
|
189
184
|
const command = {
|
|
@@ -206,7 +201,11 @@ export class ElasticCollectionService extends ElasticEntityService {
|
|
|
206
201
|
});
|
|
207
202
|
}
|
|
208
203
|
/**
|
|
204
|
+
* Finds a document by its ID.
|
|
209
205
|
*
|
|
206
|
+
* @param id - The ID of the document.
|
|
207
|
+
* @param options - The options for the find operation.
|
|
208
|
+
* @returns A promise resolving to the found document, or undefined if not found.
|
|
210
209
|
*/
|
|
211
210
|
async findById(id, options) {
|
|
212
211
|
const command = {
|
|
@@ -238,7 +237,10 @@ export class ElasticCollectionService extends ElasticEntityService {
|
|
|
238
237
|
});
|
|
239
238
|
}
|
|
240
239
|
/**
|
|
240
|
+
* Finds a document in the collection that matches the specified criteria.
|
|
241
241
|
*
|
|
242
|
+
* @param options - The options for the find operation.
|
|
243
|
+
* @returns A promise that resolves with the found document or undefined if no document is found.
|
|
242
244
|
*/
|
|
243
245
|
async findOne(options) {
|
|
244
246
|
const command = {
|
|
@@ -268,7 +270,10 @@ export class ElasticCollectionService extends ElasticEntityService {
|
|
|
268
270
|
});
|
|
269
271
|
}
|
|
270
272
|
/**
|
|
273
|
+
* Finds multiple documents in the Elasticsearch collection.
|
|
271
274
|
*
|
|
275
|
+
* @param options - The options for the find operation.
|
|
276
|
+
* @returns A promise that resolves to an array of documents.
|
|
272
277
|
*/
|
|
273
278
|
async findMany(options) {
|
|
274
279
|
const command = {
|
|
@@ -299,7 +304,10 @@ export class ElasticCollectionService extends ElasticEntityService {
|
|
|
299
304
|
return this._executeCommand(command, async () => this._searchRaw(command));
|
|
300
305
|
}
|
|
301
306
|
/**
|
|
307
|
+
* Finds multiple documents and returns both records and total count.
|
|
302
308
|
*
|
|
309
|
+
* @param options - The options for the find operation.
|
|
310
|
+
* @returns A promise that resolves to an object containing items and count.
|
|
303
311
|
*/
|
|
304
312
|
async findManyWithCount(options) {
|
|
305
313
|
const command = {
|
|
@@ -341,7 +349,12 @@ export class ElasticCollectionService extends ElasticEntityService {
|
|
|
341
349
|
});
|
|
342
350
|
}
|
|
343
351
|
/**
|
|
352
|
+
* Retrieves a document from the collection by its ID. Throws error if not found.
|
|
344
353
|
*
|
|
354
|
+
* @param id - The ID of the document to retrieve.
|
|
355
|
+
* @param options - Optional options for the operation.
|
|
356
|
+
* @returns A promise that resolves to the retrieved document.
|
|
357
|
+
* @throws {@link ResourceNotAvailableError} if the document with the specified ID does not exist.
|
|
345
358
|
*/
|
|
346
359
|
async get(id, options) {
|
|
347
360
|
const out = await this.findById(id, options);
|
|
@@ -352,10 +365,10 @@ export class ElasticCollectionService extends ElasticEntityService {
|
|
|
352
365
|
/**
|
|
353
366
|
* Updates a document in the collection with the specified ID.
|
|
354
367
|
*
|
|
355
|
-
* @param
|
|
356
|
-
* @param
|
|
357
|
-
* @param
|
|
358
|
-
* @returns
|
|
368
|
+
* @param id - The ID of the document to update.
|
|
369
|
+
* @param input - The partial input data to update the document with.
|
|
370
|
+
* @param options - The options for updating the document.
|
|
371
|
+
* @returns A promise that resolves to the update response.
|
|
359
372
|
*/
|
|
360
373
|
async update(id, input, options) {
|
|
361
374
|
const command = {
|
|
@@ -378,9 +391,9 @@ export class ElasticCollectionService extends ElasticEntityService {
|
|
|
378
391
|
/**
|
|
379
392
|
* Updates multiple documents in the collection based on the specified input and options.
|
|
380
393
|
*
|
|
381
|
-
* @param
|
|
382
|
-
* @param
|
|
383
|
-
* @
|
|
394
|
+
* @param input - The partial input to update the documents with.
|
|
395
|
+
* @param options - The options for updating the documents.
|
|
396
|
+
* @returns A promise that resolves to the update response.
|
|
384
397
|
*/
|
|
385
398
|
async updateMany(input, options) {
|
|
386
399
|
const command = {
|
|
@@ -401,11 +414,10 @@ export class ElasticCollectionService extends ElasticEntityService {
|
|
|
401
414
|
}
|
|
402
415
|
/**
|
|
403
416
|
* Retrieves the common filter used for querying documents.
|
|
404
|
-
* This method is mostly used for security issues like securing multi-tenant applications.
|
|
405
417
|
*
|
|
418
|
+
* @param command - The command information.
|
|
406
419
|
* @protected
|
|
407
|
-
* @returns
|
|
408
|
-
* that resolves to the common filter, or undefined if not available.
|
|
420
|
+
* @returns The common filter or a promise that resolves to the common filter.
|
|
409
421
|
*/
|
|
410
422
|
_getDocumentFilter(command) {
|
|
411
423
|
const commonFilter = Array.isArray(this.documentFilter)
|
|
@@ -25,9 +25,7 @@ export declare namespace ElasticEntityService {
|
|
|
25
25
|
interface CommandInfo extends ElasticService.CommandInfo {
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Represents options for "create" operation
|
|
29
|
-
*
|
|
30
|
-
* @interface
|
|
28
|
+
* Represents options for the "create" operation.
|
|
31
29
|
*/
|
|
32
30
|
interface CreateOptions {
|
|
33
31
|
request?: StrictOmit<CreateRequest, 'id' | 'index' | 'document'>;
|
|
@@ -35,9 +33,8 @@ export declare namespace ElasticEntityService {
|
|
|
35
33
|
replaceIfExists?: boolean;
|
|
36
34
|
}
|
|
37
35
|
/**
|
|
38
|
-
* Represents options for "count" operation
|
|
36
|
+
* Represents options for the "count" operation.
|
|
39
37
|
*
|
|
40
|
-
* @interface
|
|
41
38
|
* @template T - The type of the document.
|
|
42
39
|
*/
|
|
43
40
|
interface CountOptions {
|
|
@@ -46,9 +43,8 @@ export declare namespace ElasticEntityService {
|
|
|
46
43
|
transport?: TransportRequestOptions;
|
|
47
44
|
}
|
|
48
45
|
/**
|
|
49
|
-
* Represents options for "delete" operation
|
|
46
|
+
* Represents options for the "delete" operation.
|
|
50
47
|
*
|
|
51
|
-
* @interface
|
|
52
48
|
* @template T - The type of the document.
|
|
53
49
|
*/
|
|
54
50
|
interface DeleteOptions {
|
|
@@ -57,9 +53,8 @@ export declare namespace ElasticEntityService {
|
|
|
57
53
|
transport?: TransportRequestOptions;
|
|
58
54
|
}
|
|
59
55
|
/**
|
|
60
|
-
* Represents options for "deleteMany" operation
|
|
56
|
+
* Represents options for the "deleteMany" operation.
|
|
61
57
|
*
|
|
62
|
-
* @interface
|
|
63
58
|
* @template T - The type of the document.
|
|
64
59
|
*/
|
|
65
60
|
interface DeleteManyOptions {
|
|
@@ -68,17 +63,15 @@ export declare namespace ElasticEntityService {
|
|
|
68
63
|
transport?: TransportRequestOptions;
|
|
69
64
|
}
|
|
70
65
|
/**
|
|
71
|
-
* Represents options for "findOne" operation
|
|
66
|
+
* Represents options for the "findOne" operation.
|
|
72
67
|
*
|
|
73
|
-
* @interface
|
|
74
68
|
* @template T - The type of the document.
|
|
75
69
|
*/
|
|
76
70
|
interface FindOneOptions extends StrictOmit<FindManyOptions, 'limit'> {
|
|
77
71
|
}
|
|
78
72
|
/**
|
|
79
|
-
* Represents options for "findMany" operation
|
|
73
|
+
* Represents options for the "findMany" operation.
|
|
80
74
|
*
|
|
81
|
-
* @interface
|
|
82
75
|
* @template T - The type of the document.
|
|
83
76
|
*/
|
|
84
77
|
interface FindManyOptions {
|
|
@@ -92,18 +85,15 @@ export declare namespace ElasticEntityService {
|
|
|
92
85
|
noDecode?: boolean;
|
|
93
86
|
}
|
|
94
87
|
/**
|
|
95
|
-
* Represents options for "search" operation
|
|
96
|
-
*
|
|
97
|
-
* @interface
|
|
88
|
+
* Represents options for the "search" operation.
|
|
98
89
|
*/
|
|
99
90
|
interface SearchOptions {
|
|
100
91
|
transport?: TransportRequestOptions;
|
|
101
92
|
noDecode?: boolean;
|
|
102
93
|
}
|
|
103
94
|
/**
|
|
104
|
-
* Represents options for "update" operation
|
|
95
|
+
* Represents options for the "update" operation.
|
|
105
96
|
*
|
|
106
|
-
* @interface
|
|
107
97
|
* @template T - The type of the document.
|
|
108
98
|
*/
|
|
109
99
|
interface UpdateOneOptions {
|
|
@@ -112,9 +102,8 @@ export declare namespace ElasticEntityService {
|
|
|
112
102
|
transport?: TransportRequestOptions;
|
|
113
103
|
}
|
|
114
104
|
/**
|
|
115
|
-
* Represents options for "updateMany" operation
|
|
105
|
+
* Represents options for the "updateMany" operation.
|
|
116
106
|
*
|
|
117
|
-
* @interface
|
|
118
107
|
* @template T - The type of the document.
|
|
119
108
|
*/
|
|
120
109
|
interface UpdateManyOptions {
|
|
@@ -167,7 +156,8 @@ export declare namespace ElasticEntityService {
|
|
|
167
156
|
type ScriptSource = estypes.ScriptSource;
|
|
168
157
|
}
|
|
169
158
|
/**
|
|
170
|
-
*
|
|
159
|
+
* Class representing an Elasticsearch entity service for interacting with an Elasticsearch index.
|
|
160
|
+
*
|
|
171
161
|
* @template T - The type of the documents in the collection.
|
|
172
162
|
*/
|
|
173
163
|
export declare class ElasticEntityService<T extends object = any> extends ElasticService {
|
|
@@ -177,29 +167,26 @@ export declare class ElasticEntityService<T extends object = any> extends Elasti
|
|
|
177
167
|
protected _inputCodecs: Record<string, vg.isObject.Validator<T>>;
|
|
178
168
|
protected _outputCodecs: Record<string, vg.isObject.Validator<T>>;
|
|
179
169
|
/**
|
|
180
|
-
* Defines comma
|
|
170
|
+
* Defines comma-delimited scopes for API document.
|
|
181
171
|
*/
|
|
182
172
|
scope?: string;
|
|
183
173
|
/**
|
|
184
|
-
* Represents the name of
|
|
174
|
+
* Represents the name of an index in Elasticsearch.
|
|
185
175
|
*/
|
|
186
176
|
indexName?: string | ((_this: any) => string);
|
|
187
177
|
/**
|
|
188
178
|
* Represents the name of a resource.
|
|
189
|
-
* @type {string}
|
|
190
179
|
*/
|
|
191
180
|
resourceName?: string | ((_this: any) => string);
|
|
192
181
|
/**
|
|
193
|
-
* Generates a new
|
|
194
|
-
*
|
|
182
|
+
* Generates a new ID for a new document.
|
|
195
183
|
*/
|
|
196
184
|
idGenerator?: (command: ElasticEntityService.CommandInfo, _this: any) => any;
|
|
197
185
|
/**
|
|
198
|
-
* Constructs a new instance
|
|
186
|
+
* Constructs a new instance.
|
|
199
187
|
*
|
|
200
|
-
* @param
|
|
201
|
-
* @param
|
|
202
|
-
* @constructor
|
|
188
|
+
* @param dataType - The data type of the documents.
|
|
189
|
+
* @param options - The options for the entity service.
|
|
203
190
|
*/
|
|
204
191
|
constructor(dataType: Type | string, options?: ElasticEntityService.Options);
|
|
205
192
|
/**
|
|
@@ -207,21 +194,21 @@ export declare class ElasticEntityService<T extends object = any> extends Elasti
|
|
|
207
194
|
*
|
|
208
195
|
* @protected
|
|
209
196
|
* @returns The index name.
|
|
210
|
-
* @throws {Error}
|
|
197
|
+
* @throws {@link Error} if the index name is not defined.
|
|
211
198
|
*/
|
|
212
199
|
getIndexName(): string;
|
|
213
200
|
/**
|
|
214
201
|
* Retrieves the resource name.
|
|
215
202
|
*
|
|
216
203
|
* @protected
|
|
217
|
-
* @returns
|
|
218
|
-
* @throws {Error}
|
|
204
|
+
* @returns The resource name.
|
|
205
|
+
* @throws {@link Error} if the resource name is not defined.
|
|
219
206
|
*/
|
|
220
207
|
getResourceName(): string;
|
|
221
208
|
/**
|
|
222
|
-
* Retrieves the OPRA data type
|
|
209
|
+
* Retrieves the OPRA data type.
|
|
223
210
|
*
|
|
224
|
-
* @throws {NotAcceptableError}
|
|
211
|
+
* @throws {@link NotAcceptableError} if the data type is not a `ComplexType`.
|
|
225
212
|
*/
|
|
226
213
|
get dataType(): ComplexType;
|
|
227
214
|
/**
|
|
@@ -229,52 +216,59 @@ export declare class ElasticEntityService<T extends object = any> extends Elasti
|
|
|
229
216
|
* If the target is an index and the document already exists,
|
|
230
217
|
* the request updates the document and increments its version.
|
|
231
218
|
*
|
|
232
|
-
* @param
|
|
219
|
+
* @param command - The create command.
|
|
233
220
|
* @protected
|
|
221
|
+
* @throws {@link InternalServerError} if an unknown error occurs while creating the document.
|
|
234
222
|
*/
|
|
235
223
|
protected _create(command: ElasticEntityService.CreateCommand): Promise<ElasticEntityService.CreateResponse>;
|
|
236
224
|
protected __create(request: ElasticEntityService.CreateRequest, options?: ElasticEntityService.CreateOptions): Promise<estypes.WriteResponseBase>;
|
|
237
225
|
/**
|
|
238
226
|
* Returns the count of documents in the collection based on the provided options.
|
|
239
227
|
*
|
|
240
|
-
* @param
|
|
228
|
+
* @param command - The count command.
|
|
241
229
|
* @protected
|
|
230
|
+
* @returns A promise that resolves to the count response.
|
|
242
231
|
*/
|
|
243
232
|
protected _count(command: ElasticEntityService.CountCommand): Promise<ElasticEntityService.CountResponse>;
|
|
244
233
|
protected __count(request: ElasticEntityService.CountRequest, options?: ElasticEntityService.CountOptions): Promise<estypes.CountResponse>;
|
|
245
234
|
/**
|
|
246
235
|
* Deletes a document from the collection.
|
|
247
236
|
*
|
|
248
|
-
* @param
|
|
237
|
+
* @param command - The delete command.
|
|
249
238
|
* @protected
|
|
239
|
+
* @returns A promise that resolves to the delete response.
|
|
250
240
|
*/
|
|
251
241
|
protected _delete(command: ElasticEntityService.DeleteCommand): Promise<ElasticEntityService.DeleteByQueryResponse>;
|
|
252
242
|
/**
|
|
253
243
|
* Deletes multiple documents from the collection that meet the specified filter criteria.
|
|
254
244
|
*
|
|
255
|
-
* @param
|
|
245
|
+
* @param command - The deleteMany command.
|
|
256
246
|
* @protected
|
|
247
|
+
* @returns A promise that resolves to the delete response.
|
|
257
248
|
*/
|
|
258
249
|
protected _deleteMany(command: ElasticEntityService.DeleteManyCommand): Promise<ElasticEntityService.DeleteByQueryResponse>;
|
|
259
250
|
protected __delete(request: ElasticEntityService.DeleteByQueryRequest, options?: ElasticEntityService.DeleteOptions): Promise<estypes.DeleteByQueryResponse>;
|
|
260
251
|
/**
|
|
261
|
-
* Returns search hits that match the query defined in the request
|
|
252
|
+
* Returns search hits that match the query defined in the request.
|
|
262
253
|
*
|
|
263
|
-
* @param
|
|
254
|
+
* @param command - The findMany command.
|
|
255
|
+
* @returns A promise that resolves to the search response.
|
|
264
256
|
*/
|
|
265
257
|
protected _findMany(command: ElasticEntityService.FindManyCommand): Promise<ElasticEntityService.SearchResponse<PartialDTO<T>>>;
|
|
266
258
|
protected __findMany(request: ElasticEntityService.SearchRequest, options?: ElasticEntityService.FindManyOptions): Promise<estypes.SearchResponse<T, Record<string, estypes.AggregationsAggregate>>>;
|
|
267
259
|
/**
|
|
268
260
|
* Executes a search operation on the Elasticsearch index using the provided search command.
|
|
269
261
|
*
|
|
270
|
-
* @param
|
|
271
|
-
* @
|
|
262
|
+
* @param command - The search command containing the request configuration and optional transport settings.
|
|
263
|
+
* @returns A promise resolving to the search response from Elasticsearch.
|
|
272
264
|
*/
|
|
273
265
|
protected _searchRaw(command: ElasticEntityService.SearchCommand): Promise<ElasticEntityService.SearchResponse<PartialDTO<T>>>;
|
|
274
266
|
/**
|
|
275
267
|
* Updates multiple documents in the collection based on the specified input and options.
|
|
276
268
|
*
|
|
277
|
-
* @param
|
|
269
|
+
* @param command - The update command.
|
|
270
|
+
* @returns A promise that resolves to the update response.
|
|
271
|
+
* @throws {@link TypeError} if both 'input' and 'script' are provided and the script language is not 'painless'.
|
|
278
272
|
*/
|
|
279
273
|
protected _updateMany(command: ElasticEntityService.UpdateCommand<T>): Promise<ElasticEntityService.UpdateByQueryResponse>;
|
|
280
274
|
protected __update(request: ElasticEntityService.UpdateByQueryRequest, options?: ElasticEntityService.UpdateManyOptions): Promise<estypes.UpdateByQueryResponse>;
|
|
@@ -3,7 +3,8 @@ import { isNotNullish } from 'valgen';
|
|
|
3
3
|
import { ElasticAdapter } from './elastic-adapter.js';
|
|
4
4
|
import { ElasticService } from './elastic-service.js';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Class representing an Elasticsearch entity service for interacting with an Elasticsearch index.
|
|
7
|
+
*
|
|
7
8
|
* @template T - The type of the documents in the collection.
|
|
8
9
|
*/
|
|
9
10
|
export class ElasticEntityService extends ElasticService {
|
|
@@ -13,29 +14,26 @@ export class ElasticEntityService extends ElasticService {
|
|
|
13
14
|
_inputCodecs = {};
|
|
14
15
|
_outputCodecs = {};
|
|
15
16
|
/**
|
|
16
|
-
* Defines comma
|
|
17
|
+
* Defines comma-delimited scopes for API document.
|
|
17
18
|
*/
|
|
18
19
|
scope;
|
|
19
20
|
/**
|
|
20
|
-
* Represents the name of
|
|
21
|
+
* Represents the name of an index in Elasticsearch.
|
|
21
22
|
*/
|
|
22
23
|
indexName;
|
|
23
24
|
/**
|
|
24
25
|
* Represents the name of a resource.
|
|
25
|
-
* @type {string}
|
|
26
26
|
*/
|
|
27
27
|
resourceName;
|
|
28
28
|
/**
|
|
29
|
-
* Generates a new
|
|
30
|
-
*
|
|
29
|
+
* Generates a new ID for a new document.
|
|
31
30
|
*/
|
|
32
31
|
idGenerator;
|
|
33
32
|
/**
|
|
34
|
-
* Constructs a new instance
|
|
33
|
+
* Constructs a new instance.
|
|
35
34
|
*
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
38
|
-
* @constructor
|
|
35
|
+
* @param dataType - The data type of the documents.
|
|
36
|
+
* @param options - The options for the entity service.
|
|
39
37
|
*/
|
|
40
38
|
constructor(dataType, options) {
|
|
41
39
|
super(options);
|
|
@@ -59,7 +57,7 @@ export class ElasticEntityService extends ElasticService {
|
|
|
59
57
|
*
|
|
60
58
|
* @protected
|
|
61
59
|
* @returns The index name.
|
|
62
|
-
* @throws {Error}
|
|
60
|
+
* @throws {@link Error} if the index name is not defined.
|
|
63
61
|
*/
|
|
64
62
|
getIndexName() {
|
|
65
63
|
const out = typeof this.indexName === 'function'
|
|
@@ -73,8 +71,8 @@ export class ElasticEntityService extends ElasticService {
|
|
|
73
71
|
* Retrieves the resource name.
|
|
74
72
|
*
|
|
75
73
|
* @protected
|
|
76
|
-
* @returns
|
|
77
|
-
* @throws {Error}
|
|
74
|
+
* @returns The resource name.
|
|
75
|
+
* @throws {@link Error} if the resource name is not defined.
|
|
78
76
|
*/
|
|
79
77
|
getResourceName() {
|
|
80
78
|
const out = typeof this.resourceName === 'function'
|
|
@@ -85,9 +83,9 @@ export class ElasticEntityService extends ElasticService {
|
|
|
85
83
|
throw new Error('resourceName is not defined');
|
|
86
84
|
}
|
|
87
85
|
/**
|
|
88
|
-
* Retrieves the OPRA data type
|
|
86
|
+
* Retrieves the OPRA data type.
|
|
89
87
|
*
|
|
90
|
-
* @throws {NotAcceptableError}
|
|
88
|
+
* @throws {@link NotAcceptableError} if the data type is not a `ComplexType`.
|
|
91
89
|
*/
|
|
92
90
|
get dataType() {
|
|
93
91
|
if (this._dataType && this._dataTypeScope !== this.scope)
|
|
@@ -102,8 +100,9 @@ export class ElasticEntityService extends ElasticService {
|
|
|
102
100
|
* If the target is an index and the document already exists,
|
|
103
101
|
* the request updates the document and increments its version.
|
|
104
102
|
*
|
|
105
|
-
* @param
|
|
103
|
+
* @param command - The create command.
|
|
106
104
|
* @protected
|
|
105
|
+
* @throws {@link InternalServerError} if an unknown error occurs while creating the document.
|
|
107
106
|
*/
|
|
108
107
|
async _create(command) {
|
|
109
108
|
const input = command.input;
|
|
@@ -135,8 +134,9 @@ export class ElasticEntityService extends ElasticService {
|
|
|
135
134
|
/**
|
|
136
135
|
* Returns the count of documents in the collection based on the provided options.
|
|
137
136
|
*
|
|
138
|
-
* @param
|
|
137
|
+
* @param command - The count command.
|
|
139
138
|
* @protected
|
|
139
|
+
* @returns A promise that resolves to the count response.
|
|
140
140
|
*/
|
|
141
141
|
async _count(command) {
|
|
142
142
|
const { options } = command;
|
|
@@ -164,8 +164,9 @@ export class ElasticEntityService extends ElasticService {
|
|
|
164
164
|
/**
|
|
165
165
|
* Deletes a document from the collection.
|
|
166
166
|
*
|
|
167
|
-
* @param
|
|
167
|
+
* @param command - The delete command.
|
|
168
168
|
* @protected
|
|
169
|
+
* @returns A promise that resolves to the delete response.
|
|
169
170
|
*/
|
|
170
171
|
async _delete(command) {
|
|
171
172
|
isNotNullish(command.documentId, { label: 'documentId' });
|
|
@@ -191,8 +192,9 @@ export class ElasticEntityService extends ElasticService {
|
|
|
191
192
|
/**
|
|
192
193
|
* Deletes multiple documents from the collection that meet the specified filter criteria.
|
|
193
194
|
*
|
|
194
|
-
* @param
|
|
195
|
+
* @param command - The deleteMany command.
|
|
195
196
|
* @protected
|
|
197
|
+
* @returns A promise that resolves to the delete response.
|
|
196
198
|
*/
|
|
197
199
|
async _deleteMany(command) {
|
|
198
200
|
const { options } = command;
|
|
@@ -218,9 +220,10 @@ export class ElasticEntityService extends ElasticService {
|
|
|
218
220
|
return client.deleteByQuery(request, options?.transport);
|
|
219
221
|
}
|
|
220
222
|
/**
|
|
221
|
-
* Returns search hits that match the query defined in the request
|
|
223
|
+
* Returns search hits that match the query defined in the request.
|
|
222
224
|
*
|
|
223
|
-
* @param
|
|
225
|
+
* @param command - The findMany command.
|
|
226
|
+
* @returns A promise that resolves to the search response.
|
|
224
227
|
*/
|
|
225
228
|
async _findMany(command) {
|
|
226
229
|
const { options } = command;
|
|
@@ -267,8 +270,8 @@ export class ElasticEntityService extends ElasticService {
|
|
|
267
270
|
/**
|
|
268
271
|
* Executes a search operation on the Elasticsearch index using the provided search command.
|
|
269
272
|
*
|
|
270
|
-
* @param
|
|
271
|
-
* @
|
|
273
|
+
* @param command - The search command containing the request configuration and optional transport settings.
|
|
274
|
+
* @returns A promise resolving to the search response from Elasticsearch.
|
|
272
275
|
*/
|
|
273
276
|
async _searchRaw(command) {
|
|
274
277
|
const { options } = command;
|
|
@@ -293,7 +296,9 @@ export class ElasticEntityService extends ElasticService {
|
|
|
293
296
|
/**
|
|
294
297
|
* Updates multiple documents in the collection based on the specified input and options.
|
|
295
298
|
*
|
|
296
|
-
* @param
|
|
299
|
+
* @param command - The update command.
|
|
300
|
+
* @returns A promise that resolves to the update response.
|
|
301
|
+
* @throws {@link TypeError} if both 'input' and 'script' are provided and the script language is not 'painless'.
|
|
297
302
|
*/
|
|
298
303
|
async _updateMany(command) {
|
|
299
304
|
if (command.byId)
|
|
@@ -409,7 +414,7 @@ export class ElasticEntityService extends ElasticService {
|
|
|
409
414
|
async _executeCommand(command, commandFn) {
|
|
410
415
|
try {
|
|
411
416
|
const result = await super._executeCommand(command, async () => {
|
|
412
|
-
|
|
417
|
+
/* Call before[X] hooks */
|
|
413
418
|
if (command.crud === 'create')
|
|
414
419
|
await this._beforeCreate(command);
|
|
415
420
|
else if (command.crud === 'update' && command.byId) {
|
|
@@ -424,10 +429,10 @@ export class ElasticEntityService extends ElasticService {
|
|
|
424
429
|
else if (command.crud === 'delete' && !command.byId) {
|
|
425
430
|
await this._beforeDeleteMany(command);
|
|
426
431
|
}
|
|
427
|
-
|
|
432
|
+
/* Call command function */
|
|
428
433
|
return commandFn();
|
|
429
434
|
});
|
|
430
|
-
|
|
435
|
+
/* Call after[X] hooks */
|
|
431
436
|
if (command.crud === 'create')
|
|
432
437
|
await this._afterCreate(command, result);
|
|
433
438
|
else if (command.crud === 'update' && command.byId) {
|
package/elastic-service.d.ts
CHANGED
|
@@ -3,44 +3,43 @@ import { ServiceBase } from '@opra/core';
|
|
|
3
3
|
export interface ElasticService {
|
|
4
4
|
/**
|
|
5
5
|
* Interceptor function for handling callback execution with provided arguments.
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* @param next - The callback function to be intercepted.
|
|
8
|
-
* @param
|
|
8
|
+
* @param command - The command information.
|
|
9
9
|
* @param _this - The reference to the current object.
|
|
10
|
-
* @returns
|
|
10
|
+
* @returns The promise that resolves to the result of the callback execution.
|
|
11
11
|
*/
|
|
12
12
|
interceptor?(next: () => any, command: ElasticService.CommandInfo, _this: any): Promise<any>;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Class representing a
|
|
16
|
-
*
|
|
15
|
+
* Class representing a Elasticsearch service for interacting with a collection.
|
|
16
|
+
*
|
|
17
17
|
* @template T - The type of the documents in the collection.
|
|
18
18
|
*/
|
|
19
19
|
export declare class ElasticService extends ServiceBase {
|
|
20
20
|
/**
|
|
21
|
-
* Represents a
|
|
21
|
+
* Represents an Elasticsearch client instance or a function that returns one.
|
|
22
22
|
*/
|
|
23
23
|
client?: Client | ((_this: any) => Client);
|
|
24
24
|
/**
|
|
25
25
|
* Callback function for handling errors.
|
|
26
26
|
*
|
|
27
|
-
* @param
|
|
27
|
+
* @param error - The error object.
|
|
28
28
|
* @param _this - The context object.
|
|
29
29
|
*/
|
|
30
30
|
onError?: (error: unknown, _this: any) => void | Promise<void>;
|
|
31
31
|
/**
|
|
32
|
-
* Constructs a new instance
|
|
32
|
+
* Constructs a new instance.
|
|
33
33
|
*
|
|
34
|
-
* @param
|
|
35
|
-
* @constructor
|
|
34
|
+
* @param options - The options for the service.
|
|
36
35
|
*/
|
|
37
36
|
constructor(options?: ElasticService.Options);
|
|
38
37
|
/**
|
|
39
|
-
* Retrieves the
|
|
38
|
+
* Retrieves the Elasticsearch client.
|
|
40
39
|
*
|
|
41
40
|
* @protected
|
|
42
|
-
*
|
|
43
|
-
* @throws {Error}
|
|
41
|
+
* @returns The Elasticsearch client.
|
|
42
|
+
* @throws {@link Error} if the client is not set.
|
|
44
43
|
*/
|
|
45
44
|
getClient(): Client;
|
|
46
45
|
protected _executeCommand(command: ElasticService.CommandInfo, commandFn: () => any): Promise<any>;
|
package/elastic-service.js
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import { ServiceBase } from '@opra/core';
|
|
2
2
|
/**
|
|
3
|
-
* Class representing a
|
|
4
|
-
*
|
|
3
|
+
* Class representing a Elasticsearch service for interacting with a collection.
|
|
4
|
+
*
|
|
5
5
|
* @template T - The type of the documents in the collection.
|
|
6
6
|
*/
|
|
7
7
|
export class ElasticService extends ServiceBase {
|
|
8
8
|
/**
|
|
9
|
-
* Represents a
|
|
9
|
+
* Represents an Elasticsearch client instance or a function that returns one.
|
|
10
10
|
*/
|
|
11
11
|
client;
|
|
12
12
|
/**
|
|
13
13
|
* Callback function for handling errors.
|
|
14
14
|
*
|
|
15
|
-
* @param
|
|
15
|
+
* @param error - The error object.
|
|
16
16
|
* @param _this - The context object.
|
|
17
17
|
*/
|
|
18
18
|
onError;
|
|
19
19
|
/**
|
|
20
|
-
* Constructs a new instance
|
|
20
|
+
* Constructs a new instance.
|
|
21
21
|
*
|
|
22
|
-
* @param
|
|
23
|
-
* @constructor
|
|
22
|
+
* @param options - The options for the service.
|
|
24
23
|
*/
|
|
25
24
|
constructor(options) {
|
|
26
25
|
super();
|
|
@@ -29,11 +28,11 @@ export class ElasticService extends ServiceBase {
|
|
|
29
28
|
this.onError = options?.onError;
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
32
|
-
* Retrieves the
|
|
31
|
+
* Retrieves the Elasticsearch client.
|
|
33
32
|
*
|
|
34
33
|
* @protected
|
|
35
|
-
*
|
|
36
|
-
* @throws {Error}
|
|
34
|
+
* @returns The Elasticsearch client.
|
|
35
|
+
* @throws {@link Error} if the client is not set.
|
|
37
36
|
*/
|
|
38
37
|
getClient() {
|
|
39
38
|
// @ts-ignore
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/elastic",
|
|
3
|
-
"version": "1.26.
|
|
3
|
+
"version": "1.26.4",
|
|
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 <10",
|
|
14
|
-
"@opra/common": "^1.26.
|
|
15
|
-
"@opra/core": "^1.26.
|
|
14
|
+
"@opra/common": "^1.26.4",
|
|
15
|
+
"@opra/core": "^1.26.4"
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
|
18
18
|
"module": "./index.js",
|