@opra/elastic 1.0.0-beta.2 → 1.0.0-beta.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/cjs/elastic-adapter.js
CHANGED
|
@@ -13,65 +13,69 @@ var ElasticAdapter;
|
|
|
13
13
|
ElasticAdapter.prepareProjection = prepare_projection_js_1.default;
|
|
14
14
|
ElasticAdapter.prepareSort = prepare_sort_js_1.default;
|
|
15
15
|
async function parseRequest(context) {
|
|
16
|
-
|
|
16
|
+
if (context.protocol !== 'http') {
|
|
17
|
+
throw new TypeError('ElasticAdapter can parse only HttpContext');
|
|
18
|
+
}
|
|
19
|
+
const ctx = context;
|
|
20
|
+
const { operation } = ctx;
|
|
17
21
|
if (operation?.composition?.startsWith('Entity.') && operation.compositionOptions?.type) {
|
|
18
22
|
const controller = operation.owner;
|
|
19
23
|
switch (operation.composition) {
|
|
20
24
|
case 'Entity.Create': {
|
|
21
|
-
const data = await
|
|
25
|
+
const data = await ctx.getBody();
|
|
22
26
|
const options = {
|
|
23
|
-
projection:
|
|
27
|
+
projection: ctx.queryParams.projection,
|
|
24
28
|
};
|
|
25
29
|
return { method: 'create', data, options };
|
|
26
30
|
}
|
|
27
31
|
case 'Entity.Delete': {
|
|
28
32
|
const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
|
|
29
|
-
const key = keyParam &&
|
|
33
|
+
const key = keyParam && ctx.pathParams[String(keyParam.name)];
|
|
30
34
|
const options = {
|
|
31
|
-
filter:
|
|
35
|
+
filter: ctx.queryParams.filter,
|
|
32
36
|
};
|
|
33
37
|
return { method: 'delete', key, options };
|
|
34
38
|
}
|
|
35
39
|
case 'Entity.DeleteMany': {
|
|
36
40
|
const options = {
|
|
37
|
-
filter:
|
|
41
|
+
filter: ctx.queryParams.filter,
|
|
38
42
|
};
|
|
39
43
|
return { method: 'deleteMany', options };
|
|
40
44
|
}
|
|
41
45
|
case 'Entity.FindMany': {
|
|
42
46
|
const options = {
|
|
43
|
-
filter:
|
|
44
|
-
projection:
|
|
45
|
-
count:
|
|
46
|
-
limit:
|
|
47
|
-
skip:
|
|
48
|
-
sort:
|
|
47
|
+
filter: ctx.queryParams.filter,
|
|
48
|
+
projection: ctx.queryParams.projection,
|
|
49
|
+
count: ctx.queryParams.count,
|
|
50
|
+
limit: ctx.queryParams.limit,
|
|
51
|
+
skip: ctx.queryParams.skip,
|
|
52
|
+
sort: ctx.queryParams.sort,
|
|
49
53
|
};
|
|
50
54
|
return { method: 'findMany', options };
|
|
51
55
|
}
|
|
52
56
|
case 'Entity.Get': {
|
|
53
57
|
const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
|
|
54
|
-
const key = keyParam &&
|
|
58
|
+
const key = keyParam && ctx.pathParams[String(keyParam.name)];
|
|
55
59
|
const options = {
|
|
56
|
-
projection:
|
|
57
|
-
filter:
|
|
60
|
+
projection: ctx.queryParams.projection,
|
|
61
|
+
filter: ctx.queryParams.filter,
|
|
58
62
|
};
|
|
59
63
|
return { method: 'get', key, options };
|
|
60
64
|
}
|
|
61
65
|
case 'Entity.Update': {
|
|
62
|
-
const data = await
|
|
66
|
+
const data = await ctx.getBody();
|
|
63
67
|
const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
|
|
64
|
-
const key = keyParam &&
|
|
68
|
+
const key = keyParam && ctx.pathParams[String(keyParam.name)];
|
|
65
69
|
const options = {
|
|
66
|
-
projection:
|
|
67
|
-
filter:
|
|
70
|
+
projection: ctx.queryParams.projection,
|
|
71
|
+
filter: ctx.queryParams.filter,
|
|
68
72
|
};
|
|
69
73
|
return { method: 'update', key, data, options };
|
|
70
74
|
}
|
|
71
75
|
case 'Entity.UpdateMany': {
|
|
72
|
-
const data = await
|
|
76
|
+
const data = await ctx.getBody();
|
|
73
77
|
const options = {
|
|
74
|
-
filter:
|
|
78
|
+
filter: ctx.queryParams.filter,
|
|
75
79
|
};
|
|
76
80
|
return { method: 'updateMany', data, options };
|
|
77
81
|
}
|
package/esm/elastic-adapter.js
CHANGED
|
@@ -9,65 +9,69 @@ export var ElasticAdapter;
|
|
|
9
9
|
ElasticAdapter.prepareProjection = _prepareProjection;
|
|
10
10
|
ElasticAdapter.prepareSort = _prepareSort;
|
|
11
11
|
async function parseRequest(context) {
|
|
12
|
-
|
|
12
|
+
if (context.protocol !== 'http') {
|
|
13
|
+
throw new TypeError('ElasticAdapter can parse only HttpContext');
|
|
14
|
+
}
|
|
15
|
+
const ctx = context;
|
|
16
|
+
const { operation } = ctx;
|
|
13
17
|
if (operation?.composition?.startsWith('Entity.') && operation.compositionOptions?.type) {
|
|
14
18
|
const controller = operation.owner;
|
|
15
19
|
switch (operation.composition) {
|
|
16
20
|
case 'Entity.Create': {
|
|
17
|
-
const data = await
|
|
21
|
+
const data = await ctx.getBody();
|
|
18
22
|
const options = {
|
|
19
|
-
projection:
|
|
23
|
+
projection: ctx.queryParams.projection,
|
|
20
24
|
};
|
|
21
25
|
return { method: 'create', data, options };
|
|
22
26
|
}
|
|
23
27
|
case 'Entity.Delete': {
|
|
24
28
|
const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
|
|
25
|
-
const key = keyParam &&
|
|
29
|
+
const key = keyParam && ctx.pathParams[String(keyParam.name)];
|
|
26
30
|
const options = {
|
|
27
|
-
filter:
|
|
31
|
+
filter: ctx.queryParams.filter,
|
|
28
32
|
};
|
|
29
33
|
return { method: 'delete', key, options };
|
|
30
34
|
}
|
|
31
35
|
case 'Entity.DeleteMany': {
|
|
32
36
|
const options = {
|
|
33
|
-
filter:
|
|
37
|
+
filter: ctx.queryParams.filter,
|
|
34
38
|
};
|
|
35
39
|
return { method: 'deleteMany', options };
|
|
36
40
|
}
|
|
37
41
|
case 'Entity.FindMany': {
|
|
38
42
|
const options = {
|
|
39
|
-
filter:
|
|
40
|
-
projection:
|
|
41
|
-
count:
|
|
42
|
-
limit:
|
|
43
|
-
skip:
|
|
44
|
-
sort:
|
|
43
|
+
filter: ctx.queryParams.filter,
|
|
44
|
+
projection: ctx.queryParams.projection,
|
|
45
|
+
count: ctx.queryParams.count,
|
|
46
|
+
limit: ctx.queryParams.limit,
|
|
47
|
+
skip: ctx.queryParams.skip,
|
|
48
|
+
sort: ctx.queryParams.sort,
|
|
45
49
|
};
|
|
46
50
|
return { method: 'findMany', options };
|
|
47
51
|
}
|
|
48
52
|
case 'Entity.Get': {
|
|
49
53
|
const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
|
|
50
|
-
const key = keyParam &&
|
|
54
|
+
const key = keyParam && ctx.pathParams[String(keyParam.name)];
|
|
51
55
|
const options = {
|
|
52
|
-
projection:
|
|
53
|
-
filter:
|
|
56
|
+
projection: ctx.queryParams.projection,
|
|
57
|
+
filter: ctx.queryParams.filter,
|
|
54
58
|
};
|
|
55
59
|
return { method: 'get', key, options };
|
|
56
60
|
}
|
|
57
61
|
case 'Entity.Update': {
|
|
58
|
-
const data = await
|
|
62
|
+
const data = await ctx.getBody();
|
|
59
63
|
const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
|
|
60
|
-
const key = keyParam &&
|
|
64
|
+
const key = keyParam && ctx.pathParams[String(keyParam.name)];
|
|
61
65
|
const options = {
|
|
62
|
-
projection:
|
|
63
|
-
filter:
|
|
66
|
+
projection: ctx.queryParams.projection,
|
|
67
|
+
filter: ctx.queryParams.filter,
|
|
64
68
|
};
|
|
65
69
|
return { method: 'update', key, data, options };
|
|
66
70
|
}
|
|
67
71
|
case 'Entity.UpdateMany': {
|
|
68
|
-
const data = await
|
|
72
|
+
const data = await ctx.getBody();
|
|
69
73
|
const options = {
|
|
70
|
-
filter:
|
|
74
|
+
filter: ctx.queryParams.filter,
|
|
71
75
|
};
|
|
72
76
|
return { method: 'updateMany', data, options };
|
|
73
77
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/elastic",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.4",
|
|
4
4
|
"description": "Opra Elastic Search adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"lodash.omit": "^4.5.0",
|
|
9
9
|
"putil-isplainobject": "^1.1.5",
|
|
10
10
|
"tslib": "^2.7.0",
|
|
11
|
-
"valgen": "^5.
|
|
11
|
+
"valgen": "^5.10.0"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"@elastic/elasticsearch": ">=8.7.0",
|
|
15
|
-
"@opra/common": "^1.0.0-beta.
|
|
16
|
-
"@opra/core": "^1.0.0-beta.
|
|
15
|
+
"@opra/common": "^1.0.0-beta.4",
|
|
16
|
+
"@opra/core": "^1.0.0-beta.4"
|
|
17
17
|
},
|
|
18
18
|
"type": "module",
|
|
19
19
|
"exports": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types.js';
|
|
2
2
|
import { OpraFilter } from '@opra/common';
|
|
3
|
-
import {
|
|
3
|
+
import type { ExecutionContext } from '@opra/core';
|
|
4
4
|
import _prepareFilter from './adapter-utils/prepare-filter.js';
|
|
5
5
|
import _preparePatch from './adapter-utils/prepare-patch.js';
|
|
6
6
|
import _prepareProjection from './adapter-utils/prepare-projection.js';
|
|
@@ -17,5 +17,5 @@ export declare namespace ElasticAdapter {
|
|
|
17
17
|
data?: any;
|
|
18
18
|
options: any;
|
|
19
19
|
}
|
|
20
|
-
function parseRequest(context:
|
|
20
|
+
function parseRequest(context: ExecutionContext): Promise<TransformedRequest>;
|
|
21
21
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as elastic from '@elastic/elasticsearch/lib/api/types';
|
|
2
|
-
import {
|
|
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';
|
|
5
5
|
import { ElasticEntityService } from './elastic-entity-service.js';
|
|
@@ -51,7 +51,7 @@ export declare class ElasticCollectionService<T extends object = any> extends El
|
|
|
51
51
|
* @constructor
|
|
52
52
|
*/
|
|
53
53
|
constructor(dataType: Type | string, options?: ElasticCollectionService.Options);
|
|
54
|
-
for<C extends
|
|
54
|
+
for<C extends ExecutionContext, P extends Partial<this>>(context: C | ServiceBase, overwriteProperties?: Nullish<P>, overwriteContext?: Partial<C>): this & Required<P>;
|
|
55
55
|
/**
|
|
56
56
|
* Asserts the existence of a resource with the given ID.
|
|
57
57
|
* Throws a ResourceNotFoundError if the resource does not exist.
|