@opra/elastic 0.33.13 → 1.0.0-alpha.18

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.
@@ -1,108 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- require("@opra/core");
4
- const common_1 = require("@opra/common");
5
- const isNil = (v) => v == null;
6
- function transformFilter(ast, negative) {
7
- if (!ast)
8
- return;
9
- if (ast instanceof common_1.OpraFilter.QualifiedIdentifier) {
10
- return ast.value;
11
- }
12
- if (ast instanceof common_1.OpraFilter.NumberLiteral ||
13
- ast instanceof common_1.OpraFilter.StringLiteral ||
14
- ast instanceof common_1.OpraFilter.BooleanLiteral ||
15
- ast instanceof common_1.OpraFilter.NullLiteral ||
16
- ast instanceof common_1.OpraFilter.DateLiteral ||
17
- ast instanceof common_1.OpraFilter.TimeLiteral) {
18
- return ast.value;
19
- }
20
- if (ast instanceof common_1.OpraFilter.ArrayExpression) {
21
- return ast.items
22
- .map(x => transformFilter(x, negative))
23
- .filter(x => !isNil(x));
24
- }
25
- if (ast instanceof common_1.OpraFilter.NegativeExpression) {
26
- return transformFilter(ast.expression, !negative);
27
- }
28
- if (ast instanceof common_1.OpraFilter.LogicalExpression) {
29
- const v = ast.items
30
- .map(x => transformFilter(x))
31
- .filter(x => !isNil(x));
32
- if (ast.op === 'and') {
33
- return {
34
- 'bool': {
35
- [(negative ? 'must_not' : 'must')]: v
36
- }
37
- };
38
- }
39
- return wrapNot({
40
- 'bool': { 'should': v }
41
- }, negative);
42
- }
43
- if (ast instanceof common_1.OpraFilter.ParenthesizedExpression) {
44
- return transformFilter(ast.expression, negative);
45
- }
46
- if (ast instanceof common_1.OpraFilter.ComparisonExpression)
47
- return _transformComparisonExpression(ast, !!negative);
48
- throw new Error(`${ast.kind} is not implemented yet`);
49
- }
50
- exports.default = transformFilter;
51
- function _transformComparisonExpression(ast, negative) {
52
- const left = transformFilter(ast.left, negative);
53
- if (ast.right instanceof common_1.OpraFilter.QualifiedIdentifier) {
54
- throw new TypeError('not implemented yet');
55
- }
56
- const right = transformFilter(ast.right);
57
- if (right == null) {
58
- const op = ast.op === '='
59
- ? (negative ? '!=' : '=')
60
- : (negative ? '=' : '!=');
61
- if (op === '=')
62
- return { 'bool': { 'must_not': { 'exists': { 'field': left } } } };
63
- if (op === '!=')
64
- return { 'bool': { 'exists': { 'field': left } } };
65
- }
66
- switch (ast.op) {
67
- case '=':
68
- return wrapNot({ 'term': { [left]: right } }, negative);
69
- case '!=':
70
- return wrapNot({ 'term': { [left]: right } }, !negative);
71
- case '>':
72
- return wrapNot({ 'range': { [left]: { 'gt': right } } }, negative);
73
- case '>=':
74
- return wrapNot({ 'range': { [left]: { 'gte': right } } }, negative);
75
- case '<':
76
- return wrapNot({ 'range': { [left]: { 'lt': right } } }, negative);
77
- case '<=':
78
- return wrapNot({ 'range': { [left]: { 'lte': right } } }, negative);
79
- case 'in':
80
- return wrapNot({ 'terms': { [left]: Array.isArray(right) ? right : [right] } }, negative);
81
- case '!in':
82
- return wrapNot({ 'terms': { [left]: Array.isArray(right) ? right : [right] } }, !negative);
83
- case 'like':
84
- return wrapNot({ 'wildcard': { [left]: String(right) } }, negative);
85
- case '!like':
86
- return wrapNot({ 'wildcard': { [left]: String(right) } }, !negative);
87
- case 'ilike':
88
- return wrapNot({
89
- 'wildcard': {
90
- [left]: {
91
- 'value': String(right),
92
- "case_insensitive": true
93
- }
94
- }
95
- }, negative);
96
- case '!ilike':
97
- return wrapNot({
98
- 'wildcard': {
99
- [left]: {
100
- 'value': String(right),
101
- "case_insensitive": true
102
- }
103
- }
104
- }, !negative);
105
- }
106
- throw new Error(`ComparisonExpression operator (${ast.op}) not implemented yet`);
107
- }
108
- const wrapNot = (o, negative) => negative ? { 'bool': { 'must_not': o } } : o;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function transformKeyValues(resource, keyValues) {
4
- const { primaryKey } = resource;
5
- if (primaryKey.length > 1) {
6
- const out = {};
7
- primaryKey.forEach((k, i) => {
8
- out[k] = typeof keyValues === 'object' ? keyValues[k] : keyValues[i];
9
- });
10
- return out;
11
- }
12
- return { [primaryKey[0]]: keyValues };
13
- }
14
- exports.default = transformKeyValues;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const common_1 = require("@opra/common");
4
- function transformProjection(dataType, args) {
5
- let includes;
6
- let excludes;
7
- if (args.include && !args.pick) {
8
- includes = includes || [];
9
- for (const [k, f] of dataType.fields) {
10
- if (f.exclusive)
11
- continue;
12
- if (f.type instanceof common_1.ComplexType)
13
- includes.push(k + '.*');
14
- else
15
- includes.push(k);
16
- }
17
- }
18
- if (args.pick) {
19
- includes = includes || [];
20
- for (const k of args.pick) {
21
- const f = dataType.getField(k);
22
- if (f.type instanceof common_1.ComplexType)
23
- includes.push(k + '.*');
24
- else
25
- includes.push(k);
26
- }
27
- }
28
- if (args.include) {
29
- includes = includes || [];
30
- for (const k of args.include) {
31
- const f = dataType.getField(k);
32
- if (f.type instanceof common_1.ComplexType)
33
- includes.push(k + '.*');
34
- else
35
- includes.push(k);
36
- }
37
- }
38
- if (args.omit) {
39
- excludes = excludes || [];
40
- for (const k of args.omit) {
41
- const f = dataType.getField(k);
42
- if (f.type instanceof common_1.ComplexType)
43
- excludes.push(k + '.*');
44
- else
45
- excludes.push(k);
46
- }
47
- }
48
- return (0, common_1.omitNullish)({
49
- includes,
50
- excludes
51
- });
52
- }
53
- exports.default = transformProjection;
@@ -1,105 +0,0 @@
1
- import '@opra/core';
2
- import { OpraFilter } from '@opra/common';
3
- const isNil = (v) => v == null;
4
- export default function transformFilter(ast, negative) {
5
- if (!ast)
6
- return;
7
- if (ast instanceof OpraFilter.QualifiedIdentifier) {
8
- return ast.value;
9
- }
10
- if (ast instanceof OpraFilter.NumberLiteral ||
11
- ast instanceof OpraFilter.StringLiteral ||
12
- ast instanceof OpraFilter.BooleanLiteral ||
13
- ast instanceof OpraFilter.NullLiteral ||
14
- ast instanceof OpraFilter.DateLiteral ||
15
- ast instanceof OpraFilter.TimeLiteral) {
16
- return ast.value;
17
- }
18
- if (ast instanceof OpraFilter.ArrayExpression) {
19
- return ast.items
20
- .map(x => transformFilter(x, negative))
21
- .filter(x => !isNil(x));
22
- }
23
- if (ast instanceof OpraFilter.NegativeExpression) {
24
- return transformFilter(ast.expression, !negative);
25
- }
26
- if (ast instanceof OpraFilter.LogicalExpression) {
27
- const v = ast.items
28
- .map(x => transformFilter(x))
29
- .filter(x => !isNil(x));
30
- if (ast.op === 'and') {
31
- return {
32
- 'bool': {
33
- [(negative ? 'must_not' : 'must')]: v
34
- }
35
- };
36
- }
37
- return wrapNot({
38
- 'bool': { 'should': v }
39
- }, negative);
40
- }
41
- if (ast instanceof OpraFilter.ParenthesizedExpression) {
42
- return transformFilter(ast.expression, negative);
43
- }
44
- if (ast instanceof OpraFilter.ComparisonExpression)
45
- return _transformComparisonExpression(ast, !!negative);
46
- throw new Error(`${ast.kind} is not implemented yet`);
47
- }
48
- function _transformComparisonExpression(ast, negative) {
49
- const left = transformFilter(ast.left, negative);
50
- if (ast.right instanceof OpraFilter.QualifiedIdentifier) {
51
- throw new TypeError('not implemented yet');
52
- }
53
- const right = transformFilter(ast.right);
54
- if (right == null) {
55
- const op = ast.op === '='
56
- ? (negative ? '!=' : '=')
57
- : (negative ? '=' : '!=');
58
- if (op === '=')
59
- return { 'bool': { 'must_not': { 'exists': { 'field': left } } } };
60
- if (op === '!=')
61
- return { 'bool': { 'exists': { 'field': left } } };
62
- }
63
- switch (ast.op) {
64
- case '=':
65
- return wrapNot({ 'term': { [left]: right } }, negative);
66
- case '!=':
67
- return wrapNot({ 'term': { [left]: right } }, !negative);
68
- case '>':
69
- return wrapNot({ 'range': { [left]: { 'gt': right } } }, negative);
70
- case '>=':
71
- return wrapNot({ 'range': { [left]: { 'gte': right } } }, negative);
72
- case '<':
73
- return wrapNot({ 'range': { [left]: { 'lt': right } } }, negative);
74
- case '<=':
75
- return wrapNot({ 'range': { [left]: { 'lte': right } } }, negative);
76
- case 'in':
77
- return wrapNot({ 'terms': { [left]: Array.isArray(right) ? right : [right] } }, negative);
78
- case '!in':
79
- return wrapNot({ 'terms': { [left]: Array.isArray(right) ? right : [right] } }, !negative);
80
- case 'like':
81
- return wrapNot({ 'wildcard': { [left]: String(right) } }, negative);
82
- case '!like':
83
- return wrapNot({ 'wildcard': { [left]: String(right) } }, !negative);
84
- case 'ilike':
85
- return wrapNot({
86
- 'wildcard': {
87
- [left]: {
88
- 'value': String(right),
89
- "case_insensitive": true
90
- }
91
- }
92
- }, negative);
93
- case '!ilike':
94
- return wrapNot({
95
- 'wildcard': {
96
- [left]: {
97
- 'value': String(right),
98
- "case_insensitive": true
99
- }
100
- }
101
- }, !negative);
102
- }
103
- throw new Error(`ComparisonExpression operator (${ast.op}) not implemented yet`);
104
- }
105
- const wrapNot = (o, negative) => negative ? { 'bool': { 'must_not': o } } : o;
@@ -1,11 +0,0 @@
1
- export default function transformKeyValues(resource, keyValues) {
2
- const { primaryKey } = resource;
3
- if (primaryKey.length > 1) {
4
- const out = {};
5
- primaryKey.forEach((k, i) => {
6
- out[k] = typeof keyValues === 'object' ? keyValues[k] : keyValues[i];
7
- });
8
- return out;
9
- }
10
- return { [primaryKey[0]]: keyValues };
11
- }
@@ -1,50 +0,0 @@
1
- import { ComplexType, omitNullish } from '@opra/common';
2
- export default function transformProjection(dataType, args) {
3
- let includes;
4
- let excludes;
5
- if (args.include && !args.pick) {
6
- includes = includes || [];
7
- for (const [k, f] of dataType.fields) {
8
- if (f.exclusive)
9
- continue;
10
- if (f.type instanceof ComplexType)
11
- includes.push(k + '.*');
12
- else
13
- includes.push(k);
14
- }
15
- }
16
- if (args.pick) {
17
- includes = includes || [];
18
- for (const k of args.pick) {
19
- const f = dataType.getField(k);
20
- if (f.type instanceof ComplexType)
21
- includes.push(k + '.*');
22
- else
23
- includes.push(k);
24
- }
25
- }
26
- if (args.include) {
27
- includes = includes || [];
28
- for (const k of args.include) {
29
- const f = dataType.getField(k);
30
- if (f.type instanceof ComplexType)
31
- includes.push(k + '.*');
32
- else
33
- includes.push(k);
34
- }
35
- }
36
- if (args.omit) {
37
- excludes = excludes || [];
38
- for (const k of args.omit) {
39
- const f = dataType.getField(k);
40
- if (f.type instanceof ComplexType)
41
- excludes.push(k + '.*');
42
- else
43
- excludes.push(k);
44
- }
45
- }
46
- return omitNullish({
47
- includes,
48
- excludes
49
- });
50
- }
@@ -1,3 +0,0 @@
1
- import '@opra/core';
2
- import { OpraFilter } from '@opra/common';
3
- export default function transformFilter(ast: OpraFilter.Expression | undefined, negative?: boolean): any;
@@ -1,2 +0,0 @@
1
- import { Collection } from '@opra/common';
2
- export default function transformKeyValues(resource: Collection, keyValues: any): Record<string, any>;
@@ -1,6 +0,0 @@
1
- import { ComplexType } from '@opra/common';
2
- export default function transformProjection(dataType: ComplexType, args: {
3
- pick?: string[];
4
- omit?: string[];
5
- include?: string[];
6
- }): any;
@@ -1 +0,0 @@
1
- export default function transformSort(sort?: string[]): any[] | undefined;